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