Debian Codegraph @

src/cmd/compile/internal/ssa/_gen/MIPS64Ops.go

raw
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 package main
6
7 import "strings"
8
9 // Notes:
10 // - Integer types live in the low portion of registers. Upper portions are junk.
11 // - Boolean types use the low-order byte of a register. 0=false, 1=true.
12 // Upper bytes are junk.
13 // - *const instructions may use a constant larger than the instruction can encode.
14 // In this case the assembler expands to multiple instructions and uses tmp
15 // register (R23).
16
17 // Suffixes encode the bit width of various instructions.
18 // V (vlong) = 64 bit
19 // WU (word) = 32 bit unsigned
20 // W (word) = 32 bit
21 // H (half word) = 16 bit
22 // HU = 16 bit unsigned
23 // B (byte) = 8 bit
24 // BU = 8 bit unsigned
25 // F (float) = 32 bit float
26 // D (double) = 64 bit float
27
28 // Note: registers not used in regalloc are not included in this list,
29 // so that regmask stays within int64
30 // Be careful when hand coding regmasks.
31 var regNamesMIPS64 = []string{
32 "R0", // constant 0
33 "R1",
34 "R2",
35 "R3",
36 "R4",
37 "R5",
38 "R6",
39 "R7",
40 "R8",
41 "R9",
42 "R10",
43 "R11",
44 "R12",
45 "R13",
46 "R14",
47 "R15",
48 "R16",
49 "R17",
50 "R18",
51 "R19",
52 "R20",
53 "R21",
54 "R22",
55 // R23 = REGTMP not used in regalloc
56 "R24",
57 "R25",
58 // R26 reserved by kernel
59 // R27 reserved by kernel
60 // R28 = REGSB not used in regalloc
61 "SP", // aka R29
62 "g", // aka R30
63 "R31", // aka REGLINK
64
65 "F0",
66 "F1",
67 "F2",
68 "F3",
69 "F4",
70 "F5",
71 "F6",
72 "F7",
73 "F8",
74 "F9",
75 "F10",
76 "F11",
77 "F12",
78 "F13",
79 "F14",
80 "F15",
81 "F16",
82 "F17",
83 "F18",
84 "F19",
85 "F20",
86 "F21",
87 "F22",
88 "F23",
89 "F24",
90 "F25",
91 "F26",
92 "F27",
93 "F28",
94 "F29",
95 "F30",
96 "F31",
97
98 "HI", // high bits of multiplication
99 "LO", // low bits of multiplication
100
101 // If you add registers, update asyncPreempt in runtime.
102
103 // pseudo-registers
104 "SB",
105 }
106
107 func init() {
108 // Make map from reg names to reg integers.
109 if len(regNamesMIPS64) > 64 {
110 panic("too many registers")
111 }
112 num := map[string]int{}
113 for i, name := range regNamesMIPS64 {
114 num[name] = i
115 }
116 buildReg := func(s string) regMask {
117 m := regMask(0)
118 for _, r := range strings.Split(s, " ") {
119 if n, ok := num[r]; ok {
120 m |= regMask(1) << uint(n)
121 continue
122 }
123 panic("register " + r + " not found")
124 }
125 return m
126 }
127
128 // Common individual register masks
129 var (
130 gp = buildReg("R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R24 R25 R31")
131 gpg = gp | buildReg("g")
132 gpsp = gp | buildReg("SP")
133 gpspg = gpg | buildReg("SP")
134 gpspsbg = gpspg | buildReg("SB")
135 fp = buildReg("F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31")
136 lo = buildReg("LO")
137 hi = buildReg("HI")
138 callerSave = gp | fp | lo | hi | buildReg("g") // runtime.setg (and anything calling it) may clobber g
139 r1 = buildReg("R1")
140 r2 = buildReg("R2")
141 r3 = buildReg("R3")
142 r4 = buildReg("R4")
143 )
144 // Common regInfo
145 var (
146 gp01 = regInfo{inputs: nil, outputs: []regMask{gp}}
147 gp11 = regInfo{inputs: []regMask{gpg}, outputs: []regMask{gp}}
148 gp11sp = regInfo{inputs: []regMask{gpspg}, outputs: []regMask{gp}}
149 gp21 = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp}}
150 // Multiply/divide move their results out of HI/LO into general
151 // registers as part of the op itself: a value living in HI/LO
152 // cannot be spilled, as spilling needs REGTMP as the data
153 // register, which collides with REGTMP-based address
154 // materialization when the frame is too large for 16-bit offsets.
155 gp22clobbershilo = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp, gp}, clobbers: hi | lo}
156 gpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}
157 gpstore = regInfo{inputs: []regMask{gpspsbg, gpg}}
158 gpstore0 = regInfo{inputs: []regMask{gpspsbg}}
159 gpxchg = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{gp}}
160 gpcas = regInfo{inputs: []regMask{gpspsbg, gpg, gpg}, outputs: []regMask{gp}}
161 fp01 = regInfo{inputs: nil, outputs: []regMask{fp}}
162 fp11 = regInfo{inputs: []regMask{fp}, outputs: []regMask{fp}}
163 //fp1flags = regInfo{inputs: []regMask{fp}}
164 fpgp = regInfo{inputs: []regMask{fp}, outputs: []regMask{gp}}
165 gpfp = regInfo{inputs: []regMask{gp}, outputs: []regMask{fp}}
166 fp21 = regInfo{inputs: []regMask{fp, fp}, outputs: []regMask{fp}}
167 fp2flags = regInfo{inputs: []regMask{fp, fp}}
168 fpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{fp}}
169 fpstore = regInfo{inputs: []regMask{gpspsbg, fp}}
170 readflags = regInfo{inputs: nil, outputs: []regMask{gp}}
171 )
172 ops := []opData{
173 // binary ops
174 {name: "ADDV", argLength: 2, reg: gp21, asm: "ADDVU", commutative: true}, // arg0 + arg1
175 {name: "ADDVconst", argLength: 1, reg: gp11sp, asm: "ADDVU", aux: "Int64"}, // arg0 + auxInt. auxInt is 32-bit, also in other *const ops.
176 {name: "SUBV", argLength: 2, reg: gp21, asm: "SUBVU"}, // arg0 - arg1
177 {name: "SUBVconst", argLength: 1, reg: gp11, asm: "SUBVU", aux: "Int64"}, // arg0 - auxInt
178 {name: "MULV", argLength: 2, reg: gp22clobbershilo, asm: "MULV", commutative: true, typ: "(Int64,Int64)"}, // arg0 * arg1, signed, results high,low
179 {name: "MULVU", argLength: 2, reg: gp22clobbershilo, asm: "MULVU", commutative: true, typ: "(UInt64,UInt64)"}, // arg0 * arg1, unsigned, results high,low
180 {name: "DIVV", argLength: 2, reg: gp22clobbershilo, asm: "DIVV", typ: "(Int64,Int64)"}, // arg0 / arg1, signed, results arg0%arg1,arg0/arg1
181 {name: "DIVVU", argLength: 2, reg: gp22clobbershilo, asm: "DIVVU", typ: "(UInt64,UInt64)"}, // arg0 / arg1, unsigned, results arg0%arg1,arg0/arg1
182
183 {name: "ADDF", argLength: 2, reg: fp21, asm: "ADDF", commutative: true}, // arg0 + arg1
184 {name: "ADDD", argLength: 2, reg: fp21, asm: "ADDD", commutative: true}, // arg0 + arg1
185 {name: "SUBF", argLength: 2, reg: fp21, asm: "SUBF"}, // arg0 - arg1
186 {name: "SUBD", argLength: 2, reg: fp21, asm: "SUBD"}, // arg0 - arg1
187 {name: "MULF", argLength: 2, reg: fp21, asm: "MULF", commutative: true}, // arg0 * arg1
188 {name: "MULD", argLength: 2, reg: fp21, asm: "MULD", commutative: true}, // arg0 * arg1
189 {name: "DIVF", argLength: 2, reg: fp21, asm: "DIVF"}, // arg0 / arg1
190 {name: "DIVD", argLength: 2, reg: fp21, asm: "DIVD"}, // arg0 / arg1
191
192 {name: "AND", argLength: 2, reg: gp21, asm: "AND", commutative: true}, // arg0 & arg1
193 {name: "ANDconst", argLength: 1, reg: gp11, asm: "AND", aux: "Int64"}, // arg0 & auxInt
194 {name: "OR", argLength: 2, reg: gp21, asm: "OR", commutative: true}, // arg0 | arg1
195 {name: "ORconst", argLength: 1, reg: gp11, asm: "OR", aux: "Int64"}, // arg0 | auxInt
196 {name: "XOR", argLength: 2, reg: gp21, asm: "XOR", commutative: true, typ: "UInt64"}, // arg0 ^ arg1
197 {name: "XORconst", argLength: 1, reg: gp11, asm: "XOR", aux: "Int64", typ: "UInt64"}, // arg0 ^ auxInt
198 {name: "NOR", argLength: 2, reg: gp21, asm: "NOR", commutative: true}, // ^(arg0 | arg1)
199 {name: "NORconst", argLength: 1, reg: gp11, asm: "NOR", aux: "Int64"}, // ^(arg0 | auxInt)
200
201 {name: "NEGV", argLength: 1, reg: gp11}, // -arg0
202 {name: "NEGF", argLength: 1, reg: fp11, asm: "NEGF"}, // -arg0, float32
203 {name: "NEGD", argLength: 1, reg: fp11, asm: "NEGD"}, // -arg0, float64
204 {name: "ABSD", argLength: 1, reg: fp11, asm: "ABSD"}, // abs(arg0), float64
205 {name: "SQRTD", argLength: 1, reg: fp11, asm: "SQRTD"}, // sqrt(arg0), float64
206 {name: "SQRTF", argLength: 1, reg: fp11, asm: "SQRTF"}, // sqrt(arg0), float32
207
208 // shifts
209 {name: "SLLV", argLength: 2, reg: gp21, asm: "SLLV"}, // arg0 << arg1, shift amount is mod 64
210 {name: "SLLVconst", argLength: 1, reg: gp11, asm: "SLLV", aux: "Int64"}, // arg0 << auxInt
211 {name: "SRLV", argLength: 2, reg: gp21, asm: "SRLV"}, // arg0 >> arg1, unsigned, shift amount is mod 64
212 {name: "SRLVconst", argLength: 1, reg: gp11, asm: "SRLV", aux: "Int64"}, // arg0 >> auxInt, unsigned
213 {name: "SRAV", argLength: 2, reg: gp21, asm: "SRAV"}, // arg0 >> arg1, signed, shift amount is mod 64
214 {name: "SRAVconst", argLength: 1, reg: gp11, asm: "SRAV", aux: "Int64"}, // arg0 >> auxInt, signed
215
216 // comparisons
217 {name: "SGT", argLength: 2, reg: gp21, asm: "SGT", typ: "Bool"}, // 1 if arg0 > arg1 (signed), 0 otherwise
218 {name: "SGTconst", argLength: 1, reg: gp11, asm: "SGT", aux: "Int64", typ: "Bool"}, // 1 if auxInt > arg0 (signed), 0 otherwise
219 {name: "SGTU", argLength: 2, reg: gp21, asm: "SGTU", typ: "Bool"}, // 1 if arg0 > arg1 (unsigned), 0 otherwise
220 {name: "SGTUconst", argLength: 1, reg: gp11, asm: "SGTU", aux: "Int64", typ: "Bool"}, // 1 if auxInt > arg0 (unsigned), 0 otherwise
221
222 {name: "CMPEQF", argLength: 2, reg: fp2flags, asm: "CMPEQF", typ: "Flags"}, // flags=true if arg0 = arg1, float32
223 {name: "CMPEQD", argLength: 2, reg: fp2flags, asm: "CMPEQD", typ: "Flags"}, // flags=true if arg0 = arg1, float64
224 {name: "CMPGEF", argLength: 2, reg: fp2flags, asm: "CMPGEF", typ: "Flags"}, // flags=true if arg0 >= arg1, float32
225 {name: "CMPGED", argLength: 2, reg: fp2flags, asm: "CMPGED", typ: "Flags"}, // flags=true if arg0 >= arg1, float64
226 {name: "CMPGTF", argLength: 2, reg: fp2flags, asm: "CMPGTF", typ: "Flags"}, // flags=true if arg0 > arg1, float32
227 {name: "CMPGTD", argLength: 2, reg: fp2flags, asm: "CMPGTD", typ: "Flags"}, // flags=true if arg0 > arg1, float64
228
229 // moves
230 {name: "MOVVconst", argLength: 0, reg: gp01, aux: "Int64", asm: "MOVV", typ: "UInt64", rematerializeable: true}, // auxint
231 {name: "MOVFconst", argLength: 0, reg: fp01, aux: "Float64", asm: "MOVF", typ: "Float32", rematerializeable: true}, // auxint as 64-bit float, convert to 32-bit float
232 {name: "MOVDconst", argLength: 0, reg: fp01, aux: "Float64", asm: "MOVD", typ: "Float64", rematerializeable: true}, // auxint as 64-bit float
233
234 {name: "MOVVaddr", argLength: 1, reg: regInfo{inputs: []regMask{buildReg("SP") | buildReg("SB")}, outputs: []regMask{gp}}, aux: "SymOff", asm: "MOVV", rematerializeable: true, symEffect: "Addr"}, // arg0 + auxInt + aux.(*gc.Sym), arg0=SP/SB
235
236 {name: "MOVBload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVB", typ: "Int8", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
237 {name: "MOVBUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVBU", typ: "UInt8", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
238 {name: "MOVHload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVH", typ: "Int16", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
239 {name: "MOVHUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVHU", typ: "UInt16", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
240 {name: "MOVWload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVW", typ: "Int32", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
241 {name: "MOVWUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVWU", typ: "UInt32", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
242 {name: "MOVVload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVV", typ: "UInt64", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
243 {name: "MOVFload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVF", typ: "Float32", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
244 {name: "MOVDload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVD", typ: "Float64", faultOnNilArg0: true, symEffect: "Read", addrSinkArg0: true}, // load from arg0 + auxInt + aux. arg1=mem.
245
246 {name: "MOVBstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 1 byte of arg1 to arg0 + auxInt + aux. arg2=mem.
247 {name: "MOVHstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 2 bytes of arg1 to arg0 + auxInt + aux. arg2=mem.
248 {name: "MOVWstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 4 bytes of arg1 to arg0 + auxInt + aux. arg2=mem.
249 {name: "MOVVstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVV", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 8 bytes of arg1 to arg0 + auxInt + aux. arg2=mem.
250 {name: "MOVFstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVF", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 4 bytes of arg1 to arg0 + auxInt + aux. arg2=mem.
251 {name: "MOVDstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVD", typ: "Mem", faultOnNilArg0: true, symEffect: "Write", addrSinkArg0: true}, // store 8 bytes of arg1 to arg0 + auxInt + aux. arg2=mem.
252
253 {name: "MOVBstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 1 byte of zero to arg0 + auxInt + aux. arg1=mem.
254 {name: "MOVHstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 2 bytes of zero to arg0 + auxInt + aux. arg1=mem.
255 {name: "MOVWstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 4 bytes of zero to arg0 + auxInt + aux. arg1=mem.
256 {name: "MOVVstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVV", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 8 bytes of zero to arg0 + auxInt + aux. ar12=mem.
257
258 // moves (no conversion)
259 {name: "MOVWfpgp", argLength: 1, reg: fpgp, asm: "MOVW"}, // move float32 to int32 (no conversion). MIPS64 will perform sign-extend to 64-bit by default
260 {name: "MOVWgpfp", argLength: 1, reg: gpfp, asm: "MOVW"}, // move int32 to float32 (no conversion). MIPS64 will perform sign-extend to 64-bit by default
261 {name: "MOVVfpgp", argLength: 1, reg: fpgp, asm: "MOVV"}, // move float64 to int64 (no conversion).
262 {name: "MOVVgpfp", argLength: 1, reg: gpfp, asm: "MOVV"}, // move int64 to float64 (no conversion).
263
264 // conversions
265 {name: "MOVBreg", argLength: 1, reg: gp11, asm: "MOVB"}, // move from arg0, sign-extended from byte
266 {name: "MOVBUreg", argLength: 1, reg: gp11, asm: "MOVBU"}, // move from arg0, unsign-extended from byte
267 {name: "MOVHreg", argLength: 1, reg: gp11, asm: "MOVH"}, // move from arg0, sign-extended from half
268 {name: "MOVHUreg", argLength: 1, reg: gp11, asm: "MOVHU"}, // move from arg0, unsign-extended from half
269 {name: "MOVWreg", argLength: 1, reg: gp11, asm: "MOVW"}, // move from arg0, sign-extended from word
270 {name: "MOVWUreg", argLength: 1, reg: gp11, asm: "MOVWU"}, // move from arg0, unsign-extended from word
271 {name: "MOVVreg", argLength: 1, reg: gp11, asm: "MOVV"}, // move from arg0
272
273 {name: "MOVVnop", argLength: 1, reg: regInfo{inputs: []regMask{gp}, outputs: []regMask{gp}}, resultInArg0: true}, // nop, return arg0 in same register
274
275 {name: "MOVWF", argLength: 1, reg: fp11, asm: "MOVWF"}, // int32 -> float32
276 {name: "MOVWD", argLength: 1, reg: fp11, asm: "MOVWD"}, // int32 -> float64
277 {name: "MOVVF", argLength: 1, reg: fp11, asm: "MOVVF"}, // int64 -> float32
278 {name: "MOVVD", argLength: 1, reg: fp11, asm: "MOVVD"}, // int64 -> float64
279 {name: "TRUNCFW", argLength: 1, reg: fp11, asm: "TRUNCFW"}, // float32 -> int32
280 {name: "TRUNCDW", argLength: 1, reg: fp11, asm: "TRUNCDW"}, // float64 -> int32
281 {name: "TRUNCFV", argLength: 1, reg: fp11, asm: "TRUNCFV"}, // float32 -> int64
282 {name: "TRUNCDV", argLength: 1, reg: fp11, asm: "TRUNCDV"}, // float64 -> int64
283 {name: "MOVFD", argLength: 1, reg: fp11, asm: "MOVFD"}, // float32 -> float64
284 {name: "MOVDF", argLength: 1, reg: fp11, asm: "MOVDF"}, // float64 -> float32
285
286 // function calls
287 {name: "CALLstatic", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true}, // call static function aux.(*obj.LSym). arg0=mem, auxint=argsize, returns mem
288 {name: "CALLtail", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true, tailCall: true}, // tail call static function aux.(*obj.LSym). arg0=mem, auxint=argsize, returns mem
289 {name: "CALLclosure", argLength: 3, reg: regInfo{inputs: []regMask{gpsp, buildReg("R22"), 0}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true}, // call function via closure. arg0=codeptr, arg1=closure, arg2=mem, auxint=argsize, returns mem
290 {name: "CALLinter", argLength: 2, reg: regInfo{inputs: []regMask{gp}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true}, // call fn by pointer. arg0=codeptr, arg1=mem, auxint=argsize, returns mem
291
292 // duffzero
293 // arg0 = address of memory to zero
294 // arg1 = mem
295 // auxint = offset into duffzero code to start executing
296 // returns mem
297 // R1 aka mips.REGRT1 changed as side effect
298 {
299 name: "DUFFZERO",
300 aux: "Int64",
301 argLength: 2,
302 reg: regInfo{
303 inputs: []regMask{gp},
304 clobbers: buildReg("R1 R31"),
305 },
306 faultOnNilArg0: true,
307 addrSinkArg0: true,
308 },
309
310 // duffcopy
311 // arg0 = address of dst memory (in R2, changed as side effect)
312 // arg1 = address of src memory (in R1, changed as side effect)
313 // arg2 = mem
314 // auxint = offset into duffcopy code to start executing
315 // returns mem
316 {
317 name: "DUFFCOPY",
318 aux: "Int64",
319 argLength: 3,
320 reg: regInfo{
321 inputs: []regMask{buildReg("R2"), buildReg("R1")},
322 clobbers: buildReg("R1 R2 R31"),
323 },
324 faultOnNilArg0: true,
325 faultOnNilArg1: true,
326 addrSinkArg0: true,
327 addrSinkArg1: true,
328 },
329
330 // large or unaligned zeroing
331 // arg0 = address of memory to zero (in R1, changed as side effect)
332 // arg1 = address of the last element to zero
333 // arg2 = mem
334 // auxint = alignment
335 // returns mem
336 // SUBV $8, R1
337 // MOVV R0, 8(R1)
338 // ADDV $8, R1
339 // BNE Rarg1, R1, -2(PC)
340 {
341 name: "LoweredZero",
342 aux: "Int64",
343 argLength: 3,
344 reg: regInfo{
345 inputs: []regMask{buildReg("R1"), gp},
346 clobbers: buildReg("R1"),
347 },
348 clobberFlags: true,
349 faultOnNilArg0: true,
350 addrSinkArg0: true,
351 addrSinkArg1: true,
352 },
353
354 // large or unaligned move
355 // arg0 = address of dst memory (in R2, changed as side effect)
356 // arg1 = address of src memory (in R1, changed as side effect)
357 // arg2 = address of the last element of src
358 // arg3 = mem
359 // auxint = alignment
360 // returns mem
361 // SUBV $8, R1
362 // MOVV 8(R1), Rtmp
363 // MOVV Rtmp, (R2)
364 // ADDV $8, R1
365 // ADDV $8, R2
366 // BNE Rarg2, R1, -4(PC)
367 {
368 name: "LoweredMove",
369 aux: "Int64",
370 argLength: 4,
371 reg: regInfo{
372 inputs: []regMask{buildReg("R2"), buildReg("R1"), gp},
373 clobbers: buildReg("R1 R2"),
374 },
375 clobberFlags: true,
376 faultOnNilArg0: true,
377 faultOnNilArg1: true,
378 addrSinkArg0: true,
379 addrSinkArg1: true,
380 // TODO: could use addrSinkArg2 here.
381 },
382
383 // atomic and/or.
384 // *arg0 &= (|=) arg1. arg2=mem. returns memory.
385 // SYNC
386 // LL (Rarg0), Rtmp
387 // AND Rarg1, Rtmp
388 // SC Rtmp, (Rarg0)
389 // BEQ Rtmp, -3(PC)
390 // SYNC
391 {name: "LoweredAtomicAnd32", argLength: 3, reg: gpstore, asm: "AND", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
392 {name: "LoweredAtomicOr32", argLength: 3, reg: gpstore, asm: "OR", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
393
394 // atomic loads.
395 // load from arg0. arg1=mem.
396 // returns <value,memory> so they can be properly ordered with other loads.
397 {name: "LoweredAtomicLoad8", argLength: 2, reg: gpload, faultOnNilArg0: true},
398 {name: "LoweredAtomicLoad32", argLength: 2, reg: gpload, faultOnNilArg0: true},
399 {name: "LoweredAtomicLoad64", argLength: 2, reg: gpload, faultOnNilArg0: true},
400
401 // atomic stores.
402 // store arg1 to arg0. arg2=mem. returns memory.
403 {name: "LoweredAtomicStore8", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
404 {name: "LoweredAtomicStore32", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
405 {name: "LoweredAtomicStore64", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
406 // store zero to arg0. arg1=mem. returns memory.
407 {name: "LoweredAtomicStorezero32", argLength: 2, reg: gpstore0, faultOnNilArg0: true, hasSideEffects: true},
408 {name: "LoweredAtomicStorezero64", argLength: 2, reg: gpstore0, faultOnNilArg0: true, hasSideEffects: true},
409
410 // atomic exchange.
411 // store arg1 to arg0. arg2=mem. returns <old content of *arg0, memory>.
412 // SYNC
413 // LL (Rarg0), Rout
414 // MOVV Rarg1, Rtmp
415 // SC Rtmp, (Rarg0)
416 // BEQ Rtmp, -3(PC)
417 // SYNC
418 {name: "LoweredAtomicExchange32", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
419 {name: "LoweredAtomicExchange64", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
420
421 // atomic add.
422 // *arg0 += arg1. arg2=mem. returns <new content of *arg0, memory>.
423 // SYNC
424 // LL (Rarg0), Rout
425 // ADDV Rarg1, Rout, Rtmp
426 // SC Rtmp, (Rarg0)
427 // BEQ Rtmp, -3(PC)
428 // SYNC
429 // ADDV Rarg1, Rout
430 {name: "LoweredAtomicAdd32", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
431 {name: "LoweredAtomicAdd64", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
432 // *arg0 += auxint. arg1=mem. returns <new content of *arg0, memory>. auxint is 32-bit.
433 {name: "LoweredAtomicAddconst32", argLength: 2, reg: regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}, aux: "Int32", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
434 {name: "LoweredAtomicAddconst64", argLength: 2, reg: regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}, aux: "Int64", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
435
436 // atomic compare and swap.
437 // arg0 = pointer, arg1 = old value, arg2 = new value, arg3 = memory.
438 // if *arg0 == arg1 {
439 // *arg0 = arg2
440 // return (true, memory)
441 // } else {
442 // return (false, memory)
443 // }
444 // SYNC
445 // MOVV $0, Rout
446 // LL (Rarg0), Rtmp
447 // BNE Rtmp, Rarg1, 4(PC)
448 // MOVV Rarg2, Rout
449 // SC Rout, (Rarg0)
450 // BEQ Rout, -4(PC)
451 // SYNC
452 {name: "LoweredAtomicCas32", argLength: 4, reg: gpcas, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
453 {name: "LoweredAtomicCas64", argLength: 4, reg: gpcas, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
454
455 // pseudo-ops
456 {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpg}}, nilCheck: true, faultOnNilArg0: true}, // panic if arg0 is nil. arg1=mem.
457
458 {name: "FPFlagTrue", argLength: 1, reg: readflags}, // bool, true if FP flag is true
459 {name: "FPFlagFalse", argLength: 1, reg: readflags}, // bool, true if FP flag is false
460
461 // Scheduler ensures LoweredGetClosurePtr occurs only in entry block,
462 // and sorts it to the very beginning of the block to prevent other
463 // use of R22 (mips.REGCTXT, the closure pointer)
464 {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}, zeroWidth: true},
465
466 // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
467 {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
468
469 // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
470 // I.e., if f calls g "calls" sys.GetCallerPC,
471 // the result should be the PC within f that g will return to.
472 // See runtime/stubs.go for a more detailed discussion.
473 {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},
474
475 // LoweredWB invokes runtime.gcWriteBarrier. arg0=mem, auxint=# of buffer entries needed
476 // It saves all GP registers if necessary,
477 // but clobbers R31 (LR) because it's a call
478 // and R23 (REGTMP).
479 // Returns a pointer to a write barrier buffer in R25.
480 {name: "LoweredWB", argLength: 1, reg: regInfo{clobbers: (callerSave &^ gpg) | buildReg("R31"), outputs: []regMask{buildReg("R25")}}, clobberFlags: true, aux: "Int64"},
481
482 // Do data barrier. arg0=memorys
483 {name: "LoweredPubBarrier", argLength: 1, asm: "SYNC", hasSideEffects: true},
484
485 // There are three of these functions so that they can have three different register inputs.
486 // When we check 0 <= c <= cap (A), then 0 <= b <= c (B), then 0 <= a <= b (C), we want the
487 // default registers to match so we don't need to copy registers around unnecessarily.
488 {name: "LoweredPanicBoundsA", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r3, r4}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in genericOps.go).
489 {name: "LoweredPanicBoundsB", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r2, r3}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in genericOps.go).
490 {name: "LoweredPanicBoundsC", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{r1, r2}}, typ: "Mem", call: true}, // arg0=idx, arg1=len, arg2=mem, returns memory. AuxInt contains report code (see PanicBounds in genericOps.go).
491 }
492
493 blocks := []blockData{
494 {name: "EQ", controls: 1},
495 {name: "NE", controls: 1},
496 {name: "LTZ", controls: 1}, // < 0
497 {name: "LEZ", controls: 1}, // <= 0
498 {name: "GTZ", controls: 1}, // > 0
499 {name: "GEZ", controls: 1}, // >= 0
500 {name: "FPT", controls: 1}, // FP flag is true
501 {name: "FPF", controls: 1}, // FP flag is false
502 }
503
504 archs = append(archs, arch{
505 name: "MIPS64",
506 pkg: "cmd/internal/obj/mips",
507 genfile: "../../mips64/ssa.go",
508 ops: ops,
509 blocks: blocks,
510 regnames: regNamesMIPS64,
511 gpregmask: gp,
512 fpregmask: fp,
513 specialregmask: hi | lo,
514 framepointerreg: -1, // not used
515 linkreg: int8(num["R31"]),
516 })
517 }