github.com/zebozhuang/go@v0.0.0-20200207033046-f8a98f6f5c5d/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 "JMP": true, 46 "TBNZ": true, 47 "TBZ": true, 48 } 49 50 func jumpArm64(word string) bool { 51 return arm64Jump[word] 52 } 53 54 // IsARM64CMP reports whether the op (as defined by an arm.A* constant) is 55 // one of the comparison instructions that require special handling. 56 func IsARM64CMP(op obj.As) bool { 57 switch op { 58 case arm64.ACMN, arm64.ACMP, arm64.ATST, 59 arm64.ACMNW, arm64.ACMPW, arm64.ATSTW: 60 return true 61 } 62 return false 63 } 64 65 // IsARM64STLXR reports whether the op (as defined by an arm64.A* 66 // constant) is one of the STLXR-like instructions that require special 67 // handling. 68 func IsARM64STLXR(op obj.As) bool { 69 switch op { 70 case arm64.ASTLXRB, arm64.ASTLXRH, arm64.ASTLXRW, arm64.ASTLXR: 71 return true 72 } 73 return false 74 } 75 76 // ARM64Suffix handles the special suffix for the ARM64. 77 // It returns a boolean to indicate success; failure means 78 // cond was unrecognized. 79 func ARM64Suffix(prog *obj.Prog, cond string) bool { 80 if cond == "" { 81 return true 82 } 83 bits, ok := ParseARM64Suffix(cond) 84 if !ok { 85 return false 86 } 87 prog.Scond = bits 88 return true 89 } 90 91 // ParseARM64Suffix parses the suffix attached to an ARM64 instruction. 92 // The input is a single string consisting of period-separated condition 93 // codes, such as ".P.W". An initial period is ignored. 94 func ParseARM64Suffix(cond string) (uint8, bool) { 95 if cond == "" { 96 return 0, true 97 } 98 return parseARMCondition(cond, arm64LS, nil) 99 } 100 101 func arm64RegisterNumber(name string, n int16) (int16, bool) { 102 switch name { 103 case "F": 104 if 0 <= n && n <= 31 { 105 return arm64.REG_F0 + n, true 106 } 107 case "R": 108 if 0 <= n && n <= 30 { // not 31 109 return arm64.REG_R0 + n, true 110 } 111 case "V": 112 if 0 <= n && n <= 31 { 113 return arm64.REG_V0 + n, true 114 } 115 } 116 return 0, false 117 }