github.com/gocuntian/go@v0.0.0-20160610041250-fee02d270bf8/src/cmd/asm/internal/arch/s390x.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This file encapsulates some of the odd characteristics of the
     6  // s390x instruction set, to minimize its interaction
     7  // with the core of the assembler.
     8  
     9  package arch
    10  
    11  import (
    12  	"cmd/internal/obj"
    13  	"cmd/internal/obj/s390x"
    14  )
    15  
    16  func jumpS390x(word string) bool {
    17  	switch word {
    18  	case "BC",
    19  		"BCL",
    20  		"BEQ",
    21  		"BGE",
    22  		"BGT",
    23  		"BL",
    24  		"BLE",
    25  		"BLT",
    26  		"BNE",
    27  		"BR",
    28  		"BVC",
    29  		"BVS",
    30  		"CMPBEQ",
    31  		"CMPBGE",
    32  		"CMPBGT",
    33  		"CMPBLE",
    34  		"CMPBLT",
    35  		"CMPBNE",
    36  		"CMPUBEQ",
    37  		"CMPUBGE",
    38  		"CMPUBGT",
    39  		"CMPUBLE",
    40  		"CMPUBLT",
    41  		"CMPUBNE",
    42  		"CALL",
    43  		"JMP":
    44  		return true
    45  	}
    46  	return false
    47  }
    48  
    49  // IsS390xRLD reports whether the op (as defined by an s390x.A* constant) is
    50  // one of the RLD-like instructions that require special handling.
    51  // The FMADD-like instructions behave similarly.
    52  func IsS390xRLD(op obj.As) bool {
    53  	switch op {
    54  	case s390x.AFMADD,
    55  		s390x.AFMADDS,
    56  		s390x.AFMSUB,
    57  		s390x.AFMSUBS,
    58  		s390x.AFNMADD,
    59  		s390x.AFNMADDS,
    60  		s390x.AFNMSUB,
    61  		s390x.AFNMSUBS:
    62  		return true
    63  	}
    64  	return false
    65  }
    66  
    67  // IsS390xCMP reports whether the op (as defined by an s390x.A* constant) is
    68  // one of the CMP instructions that require special handling.
    69  func IsS390xCMP(op obj.As) bool {
    70  	switch op {
    71  	case s390x.ACMP, s390x.ACMPU, s390x.ACMPW, s390x.ACMPWU:
    72  		return true
    73  	}
    74  	return false
    75  }
    76  
    77  // IsS390xNEG reports whether the op (as defined by an s390x.A* constant) is
    78  // one of the NEG-like instructions that require special handling.
    79  func IsS390xNEG(op obj.As) bool {
    80  	switch op {
    81  	case s390x.AADDME,
    82  		s390x.AADDZE,
    83  		s390x.ANEG,
    84  		s390x.ASUBME,
    85  		s390x.ASUBZE:
    86  		return true
    87  	}
    88  	return false
    89  }
    90  
    91  // IsS390xWithLength reports whether the op (as defined by an s390x.A* constant)
    92  // refers to an instruction which takes a length as its first argument.
    93  func IsS390xWithLength(op obj.As) bool {
    94  	switch op {
    95  	case s390x.AMVC, s390x.ACLC, s390x.AXC, s390x.AOC, s390x.ANC:
    96  		return true
    97  	case s390x.AVLL, s390x.AVSTL:
    98  		return true
    99  	}
   100  	return false
   101  }
   102  
   103  // IsS390xWithIndex reports whether the op (as defined by an s390x.A* constant)
   104  // refers to an instruction which takes an index as its first argument.
   105  func IsS390xWithIndex(op obj.As) bool {
   106  	switch op {
   107  	case s390x.AVSCEG, s390x.AVSCEF, s390x.AVGEG, s390x.AVGEF:
   108  		return true
   109  	case s390x.AVGMG, s390x.AVGMF, s390x.AVGMH, s390x.AVGMB:
   110  		return true
   111  	case s390x.AVLEIG, s390x.AVLEIF, s390x.AVLEIH, s390x.AVLEIB:
   112  		return true
   113  	case s390x.AVPDI:
   114  		return true
   115  	}
   116  	return false
   117  }
   118  
   119  func s390xRegisterNumber(name string, n int16) (int16, bool) {
   120  	switch name {
   121  	case "AR":
   122  		if 0 <= n && n <= 15 {
   123  			return s390x.REG_AR0 + n, true
   124  		}
   125  	case "F":
   126  		if 0 <= n && n <= 15 {
   127  			return s390x.REG_F0 + n, true
   128  		}
   129  	case "R":
   130  		if 0 <= n && n <= 15 {
   131  			return s390x.REG_R0 + n, true
   132  		}
   133  	case "V":
   134  		if 0 <= n && n <= 31 {
   135  			return s390x.REG_V0 + n, true
   136  		}
   137  	}
   138  	return 0, false
   139  }