rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/cmd/asm/internal/arch/arm64.go (about) 1 // Copyright 2015 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 ARM64 6 // instruction set, to minimize its interaction with the core of the 7 // assembler. 8 9 package arch 10 11 import ( 12 "cmd/internal/obj" 13 "cmd/internal/obj/arm64" 14 ) 15 16 var arm64LS = map[string]uint8{ 17 "P": arm64.C_XPOST, 18 "W": arm64.C_XPRE, 19 } 20 21 var arm64Jump = map[string]bool{ 22 "B": true, 23 "BL": true, 24 "BEQ": true, 25 "BNE": true, 26 "BCS": true, 27 "BHS": true, 28 "BCC": true, 29 "BLO": true, 30 "BMI": true, 31 "BPL": true, 32 "BVS": true, 33 "BVC": true, 34 "BHI": true, 35 "BLS": true, 36 "BGE": true, 37 "BLT": true, 38 "BGT": true, 39 "BLE": true, 40 "CALL": true, 41 "CBZ": true, 42 "CBZW": true, 43 "CBNZ": true, 44 "CBNZW": true, 45 } 46 47 func jumpArm64(word string) bool { 48 return arm64Jump[word] 49 } 50 51 // IsARM64CMP reports whether the op (as defined by an arm.A* constant) is 52 // one of the comparison instructions that require special handling. 53 func IsARM64CMP(op int) bool { 54 switch op { 55 case arm64.ACMN, arm64.ACMP, arm64.ATST, 56 arm64.ACMNW, arm64.ACMPW, arm64.ATSTW: 57 return true 58 } 59 return false 60 } 61 62 // IsARM64STLXR reports whether the op (as defined by an arm64.A* 63 // constant) is one of the STLXR-like instructions that require special 64 // handling. 65 func IsARM64STLXR(op int) bool { 66 switch op { 67 case arm64.ASTLXRB, arm64.ASTLXRH, arm64.ASTLXRW, arm64.ASTLXR: 68 return true 69 } 70 return false 71 } 72 73 // ARM64Suffix handles the special suffix for the ARM64. 74 // It returns a boolean to indicate success; failure means 75 // cond was unrecognized. 76 func ARM64Suffix(prog *obj.Prog, cond string) bool { 77 if cond == "" { 78 return true 79 } 80 bits, ok := ParseARM64Suffix(cond) 81 if !ok { 82 return false 83 } 84 prog.Scond = bits 85 return true 86 } 87 88 // ParseARM64Suffix parses the suffix attached to an ARM64 instruction. 89 // The input is a single string consisting of period-separated condition 90 // codes, such as ".P.W". An initial period is ignored. 91 func ParseARM64Suffix(cond string) (uint8, bool) { 92 if cond == "" { 93 return 0, true 94 } 95 return parseARMCondition(cond, arm64LS, nil) 96 } 97 98 func arm64RegisterNumber(name string, n int16) (int16, bool) { 99 switch name { 100 case "F": 101 if 0 <= n && n <= 31 { 102 return arm64.REG_F0 + n, true 103 } 104 case "R": 105 if 0 <= n && n <= 30 { // not 31 106 return arm64.REG_R0 + n, true 107 } 108 case "V": 109 if 0 <= n && n <= 31 { 110 return arm64.REG_V0 + n, true 111 } 112 } 113 return 0, false 114 }