github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/internal/obj/ppc64/asm9.go (about) 1 // cmd/9l/optab.c, cmd/9l/asmout.c from Vita Nuova. 2 // 3 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. 4 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) 5 // Portions Copyright © 1997-1999 Vita Nuova Limited 6 // Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com) 7 // Portions Copyright © 2004,2006 Bruce Ellis 8 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) 9 // Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others 10 // Portions Copyright © 2009 The Go Authors. All rights reserved. 11 // 12 // Permission is hereby granted, free of charge, to any person obtaining a copy 13 // of this software and associated documentation files (the "Software"), to deal 14 // in the Software without restriction, including without limitation the rights 15 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 // copies of the Software, and to permit persons to whom the Software is 17 // furnished to do so, subject to the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be included in 20 // all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 // THE SOFTWARE. 29 30 package ppc64 31 32 import ( 33 "github.com/shogo82148/std/cmd/internal/obj" 34 ) 35 36 const ( 37 // R bit option in prefixed load/store/add D-form operations 38 PFX_R_ABS = 0 39 PFX_R_PCREL = 1 40 ) 41 42 const ( 43 // The preferred hardware nop instruction. 44 NOP = 0x60000000 45 ) 46 47 type Optab struct { 48 as obj.As 49 a1 uint8 50 a2 uint8 51 a3 uint8 52 a4 uint8 53 a5 uint8 54 a6 uint8 55 type_ int8 56 size int8 57 58 // A prefixed instruction is generated by this opcode. This cannot be placed 59 // across a 64B PC address. Opcodes should not translate to more than one 60 // prefixed instruction. The prefixed instruction should be written first 61 // (e.g when Optab.size > 8). 62 ispfx bool 63 64 asmout func(*ctxt9, *obj.Prog, *Optab, *[5]uint32) 65 } 66 67 // These are opcodes above which may generate different sequences depending on whether prefix opcode support 68 // is available 69 type PrefixableOptab struct { 70 Optab 71 minGOPPC64 int 72 pfxsize int8 73 } 74 75 // Determine if the build configuration requires a TOC pointer. 76 // It is assumed this always called after buildop. 77 func NeedTOCpointer(ctxt *obj.Link) bool 78 79 func OPVXX1(o uint32, xo uint32, oe uint32) uint32 80 81 func OPVXX2(o uint32, xo uint32, oe uint32) uint32 82 83 func OPVXX2VA(o uint32, xo uint32, oe uint32) uint32 84 85 func OPVXX3(o uint32, xo uint32, oe uint32) uint32 86 87 func OPVXX4(o uint32, xo uint32, oe uint32) uint32 88 89 func OPDQ(o uint32, xo uint32, oe uint32) uint32 90 91 func OPVX(o uint32, xo uint32, oe uint32, rc uint32) uint32 92 93 func OPVC(o uint32, xo uint32, oe uint32, rc uint32) uint32 94 95 func OPVCC(o uint32, xo uint32, oe uint32, rc uint32) uint32 96 97 func OPCC(o uint32, xo uint32, rc uint32) uint32 98 99 /* Generate MD-form opcode */ 100 func OPMD(o, xo, rc uint32) uint32 101 102 /* the order is dest, a/s, b/imm for both arithmetic and logical operations. */ 103 func AOP_RRR(op uint32, d uint32, a uint32, b uint32) uint32 104 105 /* VX-form 2-register operands, r/none/r */ 106 func AOP_RR(op uint32, d uint32, a uint32) uint32 107 108 /* VA-form 4-register operands */ 109 func AOP_RRRR(op uint32, d uint32, a uint32, b uint32, c uint32) uint32 110 111 func AOP_IRR(op uint32, d uint32, a uint32, simm uint32) uint32 112 113 /* VX-form 2-register + UIM operands */ 114 func AOP_VIRR(op uint32, d uint32, a uint32, simm uint32) uint32 115 116 /* VX-form 2-register + ST + SIX operands */ 117 func AOP_IIRR(op uint32, d uint32, a uint32, sbit uint32, simm uint32) uint32 118 119 /* VA-form 3-register + SHB operands */ 120 func AOP_IRRR(op uint32, d uint32, a uint32, b uint32, simm uint32) uint32 121 122 /* VX-form 1-register + SIM operands */ 123 func AOP_IR(op uint32, d uint32, simm uint32) uint32 124 125 /* XX1-form 3-register operands, 1 VSR operand */ 126 func AOP_XX1(op uint32, r uint32, a uint32, b uint32) uint32 127 128 /* XX2-form 3-register operands, 2 VSR operands */ 129 func AOP_XX2(op uint32, xt uint32, a uint32, xb uint32) uint32 130 131 /* XX3-form 3 VSR operands */ 132 func AOP_XX3(op uint32, xt uint32, xa uint32, xb uint32) uint32 133 134 /* XX3-form 3 VSR operands + immediate */ 135 func AOP_XX3I(op uint32, xt uint32, xa uint32, xb uint32, c uint32) uint32 136 137 /* XX4-form, 4 VSR operands */ 138 func AOP_XX4(op uint32, xt uint32, xa uint32, xb uint32, xc uint32) uint32 139 140 /* DQ-form, VSR register, register + offset operands */ 141 func AOP_DQ(op uint32, xt uint32, a uint32, b uint32) uint32 142 143 /* Z23-form, 3-register operands + CY field */ 144 func AOP_Z23I(op uint32, d uint32, a uint32, b uint32, c uint32) uint32 145 146 /* X-form, 3-register operands + EH field */ 147 func AOP_RRRI(op uint32, d uint32, a uint32, b uint32, c uint32) uint32 148 149 func LOP_RRR(op uint32, a uint32, s uint32, b uint32) uint32 150 151 func LOP_IRR(op uint32, a uint32, s uint32, uimm uint32) uint32 152 153 func OP_BR(op uint32, li uint32, aa uint32) uint32 154 155 func OP_BC(op uint32, bo uint32, bi uint32, bd uint32, aa uint32) uint32 156 157 func OP_BCR(op uint32, bo uint32, bi uint32) uint32 158 159 func OP_RLW(op uint32, a uint32, s uint32, sh uint32, mb uint32, me uint32) uint32 160 161 func AOP_EXTSWSLI(op uint32, a uint32, s uint32, sh uint32) uint32 162 163 func AOP_ISEL(op uint32, t uint32, a uint32, b uint32, bc uint32) uint32 164 165 /* MD-form 2-register, 2 6-bit immediate operands */ 166 func AOP_MD(op uint32, a uint32, s uint32, sh uint32, m uint32) uint32 167 168 /* MDS-form 3-register, 1 6-bit immediate operands. rsh argument is a register. */ 169 func AOP_MDS(op, to, from, rsh, m uint32) uint32 170 171 func AOP_PFX_00_8LS(r, ie uint32) uint32 172 173 func AOP_PFX_10_MLS(r, ie uint32) uint32 174 175 const ( 176 /* each rhs is OPVCC(_, _, _, _) */ 177 OP_ADD = 31<<26 | 266<<1 | 0<<10 | 0 178 OP_ADDI = 14<<26 | 0<<1 | 0<<10 | 0 179 OP_ADDIS = 15<<26 | 0<<1 | 0<<10 | 0 180 OP_ANDI = 28<<26 | 0<<1 | 0<<10 | 0 181 OP_EXTSB = 31<<26 | 954<<1 | 0<<10 | 0 182 OP_EXTSH = 31<<26 | 922<<1 | 0<<10 | 0 183 OP_EXTSW = 31<<26 | 986<<1 | 0<<10 | 0 184 OP_ISEL = 31<<26 | 15<<1 | 0<<10 | 0 185 OP_MCRF = 19<<26 | 0<<1 | 0<<10 | 0 186 OP_MCRFS = 63<<26 | 64<<1 | 0<<10 | 0 187 OP_MCRXR = 31<<26 | 512<<1 | 0<<10 | 0 188 OP_MFCR = 31<<26 | 19<<1 | 0<<10 | 0 189 OP_MFFS = 63<<26 | 583<<1 | 0<<10 | 0 190 OP_MFSPR = 31<<26 | 339<<1 | 0<<10 | 0 191 OP_MFSR = 31<<26 | 595<<1 | 0<<10 | 0 192 OP_MFSRIN = 31<<26 | 659<<1 | 0<<10 | 0 193 OP_MTCRF = 31<<26 | 144<<1 | 0<<10 | 0 194 OP_MTFSF = 63<<26 | 711<<1 | 0<<10 | 0 195 OP_MTFSFI = 63<<26 | 134<<1 | 0<<10 | 0 196 OP_MTSPR = 31<<26 | 467<<1 | 0<<10 | 0 197 OP_MTSR = 31<<26 | 210<<1 | 0<<10 | 0 198 OP_MTSRIN = 31<<26 | 242<<1 | 0<<10 | 0 199 OP_MULLW = 31<<26 | 235<<1 | 0<<10 | 0 200 OP_MULLD = 31<<26 | 233<<1 | 0<<10 | 0 201 OP_OR = 31<<26 | 444<<1 | 0<<10 | 0 202 OP_ORI = 24<<26 | 0<<1 | 0<<10 | 0 203 OP_ORIS = 25<<26 | 0<<1 | 0<<10 | 0 204 OP_XORI = 26<<26 | 0<<1 | 0<<10 | 0 205 OP_XORIS = 27<<26 | 0<<1 | 0<<10 | 0 206 OP_RLWINM = 21<<26 | 0<<1 | 0<<10 | 0 207 OP_RLWNM = 23<<26 | 0<<1 | 0<<10 | 0 208 OP_SUBF = 31<<26 | 40<<1 | 0<<10 | 0 209 OP_RLDIC = 30<<26 | 4<<1 | 0<<10 | 0 210 OP_RLDICR = 30<<26 | 2<<1 | 0<<10 | 0 211 OP_RLDICL = 30<<26 | 0<<1 | 0<<10 | 0 212 OP_RLDCL = 30<<26 | 8<<1 | 0<<10 | 0 213 OP_EXTSWSLI = 31<<26 | 445<<2 214 OP_SETB = 31<<26 | 128<<1 215 ) 216 217 const ( 218 D_FORM = iota 219 DS_FORM 220 )