1
2
3
4
5 package main
6
7 import "strings"
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 var regNamesMIPS = []string{
31 "R0",
32 "R1",
33 "R2",
34 "R3",
35 "R4",
36 "R5",
37 "R6",
38 "R7",
39 "R8",
40 "R9",
41 "R10",
42 "R11",
43 "R12",
44 "R13",
45 "R14",
46 "R15",
47 "R16",
48 "R17",
49 "R18",
50 "R19",
51 "R20",
52 "R21",
53 "R22",
54
55 "R24",
56 "R25",
57
58
59 "R28",
60 "SP",
61 "g",
62 "R31",
63
64
65 "F0",
66 "F2",
67 "F4",
68 "F6",
69 "F8",
70 "F10",
71 "F12",
72 "F14",
73 "F16",
74 "F18",
75 "F20",
76 "F22",
77 "F24",
78 "F26",
79 "F28",
80 "F30",
81
82 "HI",
83 "LO",
84
85
86
87
88 "SB",
89 }
90
91 func init() {
92
93 if len(regNamesMIPS) > 64 {
94 panic("too many registers")
95 }
96 num := map[string]int{}
97 for i, name := range regNamesMIPS {
98 num[name] = i
99 }
100 buildReg := func(s string) regMask {
101 m := regMask(0)
102 for _, r := range strings.Split(s, " ") {
103 if n, ok := num[r]; ok {
104 m |= regMask(1) << uint(n)
105 continue
106 }
107 panic("register " + r + " not found")
108 }
109 return m
110 }
111
112
113 var (
114 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 R28 R31")
115 gpg = gp | buildReg("g")
116 gpsp = gp | buildReg("SP")
117 gpspg = gpg | buildReg("SP")
118 gpspsbg = gpspg | buildReg("SB")
119 fp = buildReg("F0 F2 F4 F6 F8 F10 F12 F14 F16 F18 F20 F22 F24 F26 F28 F30")
120 lo = buildReg("LO")
121 hi = buildReg("HI")
122 callerSave = gp | fp | lo | hi | buildReg("g")
123 first16 = buildReg("R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16")
124 first4 = buildReg("R1 R2 R3 R4")
125 )
126
127 var (
128 gp01 = regInfo{inputs: nil, outputs: []regMask{gp}}
129 gp11 = regInfo{inputs: []regMask{gpg}, outputs: []regMask{gp}}
130 gp11sp = regInfo{inputs: []regMask{gpspg}, outputs: []regMask{gp}}
131 gp21 = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp}}
132 gp31 = regInfo{inputs: []regMask{gp, gp, gp}, outputs: []regMask{gp}}
133 gp2hilo = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{hi, lo}}
134 gpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}
135 gpstore = regInfo{inputs: []regMask{gpspsbg, gpg}}
136 gpxchg = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{gp}}
137 gpcas = regInfo{inputs: []regMask{gpspsbg, gpg, gpg}, outputs: []regMask{gp}}
138 gpstore0 = regInfo{inputs: []regMask{gpspsbg}}
139 fpgp = regInfo{inputs: []regMask{fp}, outputs: []regMask{gp}}
140 gpfp = regInfo{inputs: []regMask{gp}, outputs: []regMask{fp}}
141 fp01 = regInfo{inputs: nil, outputs: []regMask{fp}}
142 fp11 = regInfo{inputs: []regMask{fp}, outputs: []regMask{fp}}
143 fp21 = regInfo{inputs: []regMask{fp, fp}, outputs: []regMask{fp}}
144 fp2flags = regInfo{inputs: []regMask{fp, fp}}
145 fpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{fp}}
146 fpstore = regInfo{inputs: []regMask{gpspsbg, fp}}
147 readflags = regInfo{inputs: nil, outputs: []regMask{gp}}
148 )
149 ops := []opData{
150 {name: "ADD", argLength: 2, reg: gp21, asm: "ADDU", commutative: true},
151 {name: "ADDconst", argLength: 1, reg: gp11sp, asm: "ADDU", aux: "Int32"},
152 {name: "SUB", argLength: 2, reg: gp21, asm: "SUBU"},
153 {name: "SUBconst", argLength: 1, reg: gp11, asm: "SUBU", aux: "Int32"},
154 {name: "MUL", argLength: 2, reg: regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp}, clobbers: hi | lo}, asm: "MUL", commutative: true},
155 {name: "MULT", argLength: 2, reg: gp2hilo, asm: "MUL", commutative: true, typ: "(Int32,Int32)"},
156 {name: "MULTU", argLength: 2, reg: gp2hilo, asm: "MULU", commutative: true, typ: "(UInt32,UInt32)"},
157 {name: "DIV", argLength: 2, reg: gp2hilo, asm: "DIV", typ: "(Int32,Int32)"},
158 {name: "DIVU", argLength: 2, reg: gp2hilo, asm: "DIVU", typ: "(UInt32,UInt32)"},
159
160 {name: "ADDF", argLength: 2, reg: fp21, asm: "ADDF", commutative: true},
161 {name: "ADDD", argLength: 2, reg: fp21, asm: "ADDD", commutative: true},
162 {name: "SUBF", argLength: 2, reg: fp21, asm: "SUBF"},
163 {name: "SUBD", argLength: 2, reg: fp21, asm: "SUBD"},
164 {name: "MULF", argLength: 2, reg: fp21, asm: "MULF", commutative: true},
165 {name: "MULD", argLength: 2, reg: fp21, asm: "MULD", commutative: true},
166 {name: "DIVF", argLength: 2, reg: fp21, asm: "DIVF"},
167 {name: "DIVD", argLength: 2, reg: fp21, asm: "DIVD"},
168
169 {name: "AND", argLength: 2, reg: gp21, asm: "AND", commutative: true},
170 {name: "ANDconst", argLength: 1, reg: gp11, asm: "AND", aux: "Int32"},
171 {name: "OR", argLength: 2, reg: gp21, asm: "OR", commutative: true},
172 {name: "ORconst", argLength: 1, reg: gp11, asm: "OR", aux: "Int32"},
173 {name: "XOR", argLength: 2, reg: gp21, asm: "XOR", commutative: true, typ: "UInt32"},
174 {name: "XORconst", argLength: 1, reg: gp11, asm: "XOR", aux: "Int32", typ: "UInt32"},
175 {name: "NOR", argLength: 2, reg: gp21, asm: "NOR", commutative: true},
176 {name: "NORconst", argLength: 1, reg: gp11, asm: "NOR", aux: "Int32"},
177
178 {name: "NEG", argLength: 1, reg: gp11},
179 {name: "NEGF", argLength: 1, reg: fp11, asm: "NEGF"},
180 {name: "NEGD", argLength: 1, reg: fp11, asm: "NEGD"},
181 {name: "ABSD", argLength: 1, reg: fp11, asm: "ABSD"},
182 {name: "SQRTD", argLength: 1, reg: fp11, asm: "SQRTD"},
183 {name: "SQRTF", argLength: 1, reg: fp11, asm: "SQRTF"},
184
185
186 {name: "SLL", argLength: 2, reg: gp21, asm: "SLL"},
187 {name: "SLLconst", argLength: 1, reg: gp11, asm: "SLL", aux: "Int32"},
188 {name: "SRL", argLength: 2, reg: gp21, asm: "SRL"},
189 {name: "SRLconst", argLength: 1, reg: gp11, asm: "SRL", aux: "Int32"},
190 {name: "SRA", argLength: 2, reg: gp21, asm: "SRA"},
191 {name: "SRAconst", argLength: 1, reg: gp11, asm: "SRA", aux: "Int32"},
192
193 {name: "CLZ", argLength: 1, reg: gp11, asm: "CLZ"},
194
195
196 {name: "SGT", argLength: 2, reg: gp21, asm: "SGT", typ: "Bool"},
197 {name: "SGTconst", argLength: 1, reg: gp11, asm: "SGT", aux: "Int32", typ: "Bool"},
198 {name: "SGTzero", argLength: 1, reg: gp11, asm: "SGT", typ: "Bool"},
199 {name: "SGTU", argLength: 2, reg: gp21, asm: "SGTU", typ: "Bool"},
200 {name: "SGTUconst", argLength: 1, reg: gp11, asm: "SGTU", aux: "Int32", typ: "Bool"},
201 {name: "SGTUzero", argLength: 1, reg: gp11, asm: "SGTU", typ: "Bool"},
202
203 {name: "CMPEQF", argLength: 2, reg: fp2flags, asm: "CMPEQF", typ: "Flags"},
204 {name: "CMPEQD", argLength: 2, reg: fp2flags, asm: "CMPEQD", typ: "Flags"},
205 {name: "CMPGEF", argLength: 2, reg: fp2flags, asm: "CMPGEF", typ: "Flags"},
206 {name: "CMPGED", argLength: 2, reg: fp2flags, asm: "CMPGED", typ: "Flags"},
207 {name: "CMPGTF", argLength: 2, reg: fp2flags, asm: "CMPGTF", typ: "Flags"},
208 {name: "CMPGTD", argLength: 2, reg: fp2flags, asm: "CMPGTD", typ: "Flags"},
209
210
211 {name: "MOVWconst", argLength: 0, reg: gp01, aux: "Int32", asm: "MOVW", typ: "UInt32", rematerializeable: true},
212 {name: "MOVFconst", argLength: 0, reg: fp01, aux: "Float32", asm: "MOVF", typ: "Float32", rematerializeable: true},
213 {name: "MOVDconst", argLength: 0, reg: fp01, aux: "Float64", asm: "MOVD", typ: "Float64", rematerializeable: true},
214
215 {name: "MOVWaddr", argLength: 1, reg: regInfo{inputs: []regMask{buildReg("SP") | buildReg("SB")}, outputs: []regMask{gp}}, aux: "SymOff", asm: "MOVW", rematerializeable: true, symEffect: "Addr"},
216
217 {name: "MOVBload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVB", typ: "Int8", faultOnNilArg0: true, symEffect: "Read"},
218 {name: "MOVBUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVBU", typ: "UInt8", faultOnNilArg0: true, symEffect: "Read"},
219 {name: "MOVHload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVH", typ: "Int16", faultOnNilArg0: true, symEffect: "Read"},
220 {name: "MOVHUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVHU", typ: "UInt16", faultOnNilArg0: true, symEffect: "Read"},
221 {name: "MOVWload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVW", typ: "UInt32", faultOnNilArg0: true, symEffect: "Read"},
222 {name: "MOVFload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVF", typ: "Float32", faultOnNilArg0: true, symEffect: "Read"},
223 {name: "MOVDload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVD", typ: "Float64", faultOnNilArg0: true, symEffect: "Read"},
224
225 {name: "MOVBstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
226 {name: "MOVHstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
227 {name: "MOVWstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
228 {name: "MOVFstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVF", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
229 {name: "MOVDstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVD", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
230
231 {name: "MOVBstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
232 {name: "MOVHstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
233 {name: "MOVWstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
234
235
236 {name: "MOVWfpgp", argLength: 1, reg: fpgp, asm: "MOVW"},
237 {name: "MOVWgpfp", argLength: 1, reg: gpfp, asm: "MOVW"},
238
239
240 {name: "MOVBreg", argLength: 1, reg: gp11, asm: "MOVB"},
241 {name: "MOVBUreg", argLength: 1, reg: gp11, asm: "MOVBU"},
242 {name: "MOVHreg", argLength: 1, reg: gp11, asm: "MOVH"},
243 {name: "MOVHUreg", argLength: 1, reg: gp11, asm: "MOVHU"},
244 {name: "MOVWreg", argLength: 1, reg: gp11, asm: "MOVW"},
245
246 {name: "MOVWnop", argLength: 1, reg: regInfo{inputs: []regMask{gp}, outputs: []regMask{gp}}, resultInArg0: true},
247
248
249
250 {name: "CMOVZ", argLength: 3, reg: gp31, asm: "CMOVZ", resultInArg0: true},
251 {name: "CMOVZzero", argLength: 2, reg: regInfo{inputs: []regMask{gp, gpg}, outputs: []regMask{gp}}, asm: "CMOVZ", resultInArg0: true},
252
253 {name: "MOVWF", argLength: 1, reg: fp11, asm: "MOVWF"},
254 {name: "MOVWD", argLength: 1, reg: fp11, asm: "MOVWD"},
255 {name: "TRUNCFW", argLength: 1, reg: fp11, asm: "TRUNCFW"},
256 {name: "TRUNCDW", argLength: 1, reg: fp11, asm: "TRUNCDW"},
257 {name: "MOVFD", argLength: 1, reg: fp11, asm: "MOVFD"},
258 {name: "MOVDF", argLength: 1, reg: fp11, asm: "MOVDF"},
259
260
261 {name: "CALLstatic", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
262 {name: "CALLtail", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true, tailCall: true},
263 {name: "CALLclosure", argLength: 3, reg: regInfo{inputs: []regMask{gpsp, buildReg("R22"), 0}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
264 {name: "CALLinter", argLength: 2, reg: regInfo{inputs: []regMask{gp}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
265
266
267
268
269
270
271
272
273 {name: "LoweredAtomicLoad8", argLength: 2, reg: gpload, faultOnNilArg0: true},
274 {name: "LoweredAtomicLoad32", argLength: 2, reg: gpload, faultOnNilArg0: true},
275
276
277
278
279
280 {name: "LoweredAtomicStore8", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
281 {name: "LoweredAtomicStore32", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
282 {name: "LoweredAtomicStorezero", argLength: 2, reg: gpstore0, faultOnNilArg0: true, hasSideEffects: true},
283
284
285
286
287
288
289
290
291
292 {name: "LoweredAtomicExchange", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
293
294
295
296
297
298
299
300
301
302
303 {name: "LoweredAtomicAdd", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
304 {name: "LoweredAtomicAddconst", argLength: 2, reg: regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}, aux: "Int32", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 {name: "LoweredAtomicCas", argLength: 4, reg: gpcas, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
323
324
325
326
327
328
329
330
331
332 {name: "LoweredAtomicAnd", argLength: 3, reg: gpstore, asm: "AND", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
333 {name: "LoweredAtomicOr", argLength: 3, reg: gpstore, asm: "OR", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
334
335
336
337
338
339
340
341
342
343
344
345 {
346 name: "LoweredZero",
347 aux: "Int32",
348 argLength: 3,
349 reg: regInfo{
350 inputs: []regMask{buildReg("R1"), gp},
351 clobbers: buildReg("R1"),
352 },
353 faultOnNilArg0: true,
354 },
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369 {
370 name: "LoweredMove",
371 aux: "Int32",
372 argLength: 4,
373 reg: regInfo{
374 inputs: []regMask{buildReg("R2"), buildReg("R1"), gp},
375 clobbers: buildReg("R1 R2"),
376 },
377 faultOnNilArg0: true,
378 faultOnNilArg1: true,
379 },
380
381
382 {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpg}}, nilCheck: true, faultOnNilArg0: true},
383
384 {name: "FPFlagTrue", argLength: 1, reg: readflags},
385 {name: "FPFlagFalse", argLength: 1, reg: readflags},
386
387
388
389
390 {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}, zeroWidth: true},
391
392
393 {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
394
395
396
397
398
399 {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},
400
401
402
403
404
405
406 {name: "LoweredWB", argLength: 1, reg: regInfo{clobbers: (callerSave &^ gpg) | buildReg("R31"), outputs: []regMask{buildReg("R25")}}, clobberFlags: true, aux: "Int64"},
407
408
409 {name: "LoweredPubBarrier", argLength: 1, asm: "SYNC", hasSideEffects: true},
410
411
412
413
414
415
416 {name: "LoweredPanicBoundsRR", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{first16, first16}}, typ: "Mem", call: true},
417 {name: "LoweredPanicBoundsRC", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{first16}}, typ: "Mem", call: true},
418 {name: "LoweredPanicBoundsCR", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{first16}}, typ: "Mem", call: true},
419 {name: "LoweredPanicBoundsCC", argLength: 1, aux: "PanicBoundsCC", reg: regInfo{}, typ: "Mem", call: true},
420
421
422 {name: "LoweredPanicExtendRR", argLength: 4, aux: "Int64", reg: regInfo{inputs: []regMask{first4, first4, first16}}, typ: "Mem", call: true},
423 {name: "LoweredPanicExtendRC", argLength: 3, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{first4, first4}}, typ: "Mem", call: true},
424 }
425
426 blocks := []blockData{
427 {name: "EQ", controls: 1},
428 {name: "NE", controls: 1},
429 {name: "LTZ", controls: 1},
430 {name: "LEZ", controls: 1},
431 {name: "GTZ", controls: 1},
432 {name: "GEZ", controls: 1},
433 {name: "FPT", controls: 1},
434 {name: "FPF", controls: 1},
435 }
436
437 archs = append(archs, arch{
438 name: "MIPS",
439 pkg: "cmd/internal/obj/mips",
440 genfile: "../../mips/ssa.go",
441 ops: ops,
442 blocks: blocks,
443 regnames: regNamesMIPS,
444 gpregmask: gp,
445 fpregmask: fp,
446 specialregmask: hi | lo,
447 framepointerreg: -1,
448 linkreg: int8(num["R31"]),
449 })
450 }
451
View as plain text