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
31 var regNamesMIPS64 = []string{
32 "R0",
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
56 "R24",
57 "R25",
58
59
60
61 "SP",
62 "g",
63 "R31",
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",
99 "LO",
100
101
102
103
104 "SB",
105 }
106
107 func init() {
108
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
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")
139 first16 = buildReg("R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16")
140 )
141
142 var (
143 gp01 = regInfo{inputs: nil, outputs: []regMask{gp}}
144 gp11 = regInfo{inputs: []regMask{gpg}, outputs: []regMask{gp}}
145 gp11sp = regInfo{inputs: []regMask{gpspg}, outputs: []regMask{gp}}
146 gp21 = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp}}
147 gp2hilo = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{hi, lo}}
148 gpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}
149 gpstore = regInfo{inputs: []regMask{gpspsbg, gpg}}
150 gpstore0 = regInfo{inputs: []regMask{gpspsbg}}
151 gpxchg = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{gp}}
152 gpcas = regInfo{inputs: []regMask{gpspsbg, gpg, gpg}, outputs: []regMask{gp}}
153 fp01 = regInfo{inputs: nil, outputs: []regMask{fp}}
154 fp11 = regInfo{inputs: []regMask{fp}, outputs: []regMask{fp}}
155
156 fpgp = regInfo{inputs: []regMask{fp}, outputs: []regMask{gp}}
157 gpfp = regInfo{inputs: []regMask{gp}, outputs: []regMask{fp}}
158 fp21 = regInfo{inputs: []regMask{fp, fp}, outputs: []regMask{fp}}
159 fp2flags = regInfo{inputs: []regMask{fp, fp}}
160 fpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{fp}}
161 fpstore = regInfo{inputs: []regMask{gpspsbg, fp}}
162 readflags = regInfo{inputs: nil, outputs: []regMask{gp}}
163 )
164 ops := []opData{
165
166 {name: "ADDV", argLength: 2, reg: gp21, asm: "ADDVU", commutative: true},
167 {name: "ADDVconst", argLength: 1, reg: gp11sp, asm: "ADDVU", aux: "Int64"},
168 {name: "SUBV", argLength: 2, reg: gp21, asm: "SUBVU"},
169 {name: "SUBVconst", argLength: 1, reg: gp11, asm: "SUBVU", aux: "Int64"},
170 {name: "MULV", argLength: 2, reg: gp2hilo, asm: "MULV", commutative: true, typ: "(Int64,Int64)"},
171 {name: "MULVU", argLength: 2, reg: gp2hilo, asm: "MULVU", commutative: true, typ: "(UInt64,UInt64)"},
172 {name: "DIVV", argLength: 2, reg: gp2hilo, asm: "DIVV", typ: "(Int64,Int64)"},
173 {name: "DIVVU", argLength: 2, reg: gp2hilo, asm: "DIVVU", typ: "(UInt64,UInt64)"},
174
175 {name: "ADDF", argLength: 2, reg: fp21, asm: "ADDF", commutative: true},
176 {name: "ADDD", argLength: 2, reg: fp21, asm: "ADDD", commutative: true},
177 {name: "SUBF", argLength: 2, reg: fp21, asm: "SUBF"},
178 {name: "SUBD", argLength: 2, reg: fp21, asm: "SUBD"},
179 {name: "MULF", argLength: 2, reg: fp21, asm: "MULF", commutative: true},
180 {name: "MULD", argLength: 2, reg: fp21, asm: "MULD", commutative: true},
181 {name: "DIVF", argLength: 2, reg: fp21, asm: "DIVF"},
182 {name: "DIVD", argLength: 2, reg: fp21, asm: "DIVD"},
183
184 {name: "AND", argLength: 2, reg: gp21, asm: "AND", commutative: true},
185 {name: "ANDconst", argLength: 1, reg: gp11, asm: "AND", aux: "Int64"},
186 {name: "OR", argLength: 2, reg: gp21, asm: "OR", commutative: true},
187 {name: "ORconst", argLength: 1, reg: gp11, asm: "OR", aux: "Int64"},
188 {name: "XOR", argLength: 2, reg: gp21, asm: "XOR", commutative: true, typ: "UInt64"},
189 {name: "XORconst", argLength: 1, reg: gp11, asm: "XOR", aux: "Int64", typ: "UInt64"},
190 {name: "NOR", argLength: 2, reg: gp21, asm: "NOR", commutative: true},
191 {name: "NORconst", argLength: 1, reg: gp11, asm: "NOR", aux: "Int64"},
192
193 {name: "NEGV", argLength: 1, reg: gp11},
194 {name: "NEGF", argLength: 1, reg: fp11, asm: "NEGF"},
195 {name: "NEGD", argLength: 1, reg: fp11, asm: "NEGD"},
196 {name: "ABSD", argLength: 1, reg: fp11, asm: "ABSD"},
197 {name: "SQRTD", argLength: 1, reg: fp11, asm: "SQRTD"},
198 {name: "SQRTF", argLength: 1, reg: fp11, asm: "SQRTF"},
199
200
201 {name: "SLLV", argLength: 2, reg: gp21, asm: "SLLV"},
202 {name: "SLLVconst", argLength: 1, reg: gp11, asm: "SLLV", aux: "Int64"},
203 {name: "SRLV", argLength: 2, reg: gp21, asm: "SRLV"},
204 {name: "SRLVconst", argLength: 1, reg: gp11, asm: "SRLV", aux: "Int64"},
205 {name: "SRAV", argLength: 2, reg: gp21, asm: "SRAV"},
206 {name: "SRAVconst", argLength: 1, reg: gp11, asm: "SRAV", aux: "Int64"},
207
208
209 {name: "SGT", argLength: 2, reg: gp21, asm: "SGT", typ: "Bool"},
210 {name: "SGTconst", argLength: 1, reg: gp11, asm: "SGT", aux: "Int64", typ: "Bool"},
211 {name: "SGTU", argLength: 2, reg: gp21, asm: "SGTU", typ: "Bool"},
212 {name: "SGTUconst", argLength: 1, reg: gp11, asm: "SGTU", aux: "Int64", typ: "Bool"},
213
214 {name: "CMPEQF", argLength: 2, reg: fp2flags, asm: "CMPEQF", typ: "Flags"},
215 {name: "CMPEQD", argLength: 2, reg: fp2flags, asm: "CMPEQD", typ: "Flags"},
216 {name: "CMPGEF", argLength: 2, reg: fp2flags, asm: "CMPGEF", typ: "Flags"},
217 {name: "CMPGED", argLength: 2, reg: fp2flags, asm: "CMPGED", typ: "Flags"},
218 {name: "CMPGTF", argLength: 2, reg: fp2flags, asm: "CMPGTF", typ: "Flags"},
219 {name: "CMPGTD", argLength: 2, reg: fp2flags, asm: "CMPGTD", typ: "Flags"},
220
221
222 {name: "MOVVconst", argLength: 0, reg: gp01, aux: "Int64", asm: "MOVV", typ: "UInt64", rematerializeable: true},
223 {name: "MOVFconst", argLength: 0, reg: fp01, aux: "Float64", asm: "MOVF", typ: "Float32", rematerializeable: true},
224 {name: "MOVDconst", argLength: 0, reg: fp01, aux: "Float64", asm: "MOVD", typ: "Float64", rematerializeable: true},
225
226 {name: "MOVVaddr", argLength: 1, reg: regInfo{inputs: []regMask{buildReg("SP") | buildReg("SB")}, outputs: []regMask{gp}}, aux: "SymOff", asm: "MOVV", rematerializeable: true, symEffect: "Addr"},
227
228 {name: "MOVBload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVB", typ: "Int8", faultOnNilArg0: true, symEffect: "Read"},
229 {name: "MOVBUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVBU", typ: "UInt8", faultOnNilArg0: true, symEffect: "Read"},
230 {name: "MOVHload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVH", typ: "Int16", faultOnNilArg0: true, symEffect: "Read"},
231 {name: "MOVHUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVHU", typ: "UInt16", faultOnNilArg0: true, symEffect: "Read"},
232 {name: "MOVWload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVW", typ: "Int32", faultOnNilArg0: true, symEffect: "Read"},
233 {name: "MOVWUload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVWU", typ: "UInt32", faultOnNilArg0: true, symEffect: "Read"},
234 {name: "MOVVload", argLength: 2, reg: gpload, aux: "SymOff", asm: "MOVV", typ: "UInt64", faultOnNilArg0: true, symEffect: "Read"},
235 {name: "MOVFload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVF", typ: "Float32", faultOnNilArg0: true, symEffect: "Read"},
236 {name: "MOVDload", argLength: 2, reg: fpload, aux: "SymOff", asm: "MOVD", typ: "Float64", faultOnNilArg0: true, symEffect: "Read"},
237
238 {name: "MOVBstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
239 {name: "MOVHstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
240 {name: "MOVWstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
241 {name: "MOVVstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVV", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
242 {name: "MOVFstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVF", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
243 {name: "MOVDstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVD", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
244
245 {name: "MOVBstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
246 {name: "MOVHstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
247 {name: "MOVWstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVW", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
248 {name: "MOVVstorezero", argLength: 2, reg: gpstore0, aux: "SymOff", asm: "MOVV", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"},
249
250
251 {name: "MOVWfpgp", argLength: 1, reg: fpgp, asm: "MOVW"},
252 {name: "MOVWgpfp", argLength: 1, reg: gpfp, asm: "MOVW"},
253 {name: "MOVVfpgp", argLength: 1, reg: fpgp, asm: "MOVV"},
254 {name: "MOVVgpfp", argLength: 1, reg: gpfp, asm: "MOVV"},
255
256
257 {name: "MOVBreg", argLength: 1, reg: gp11, asm: "MOVB"},
258 {name: "MOVBUreg", argLength: 1, reg: gp11, asm: "MOVBU"},
259 {name: "MOVHreg", argLength: 1, reg: gp11, asm: "MOVH"},
260 {name: "MOVHUreg", argLength: 1, reg: gp11, asm: "MOVHU"},
261 {name: "MOVWreg", argLength: 1, reg: gp11, asm: "MOVW"},
262 {name: "MOVWUreg", argLength: 1, reg: gp11, asm: "MOVWU"},
263 {name: "MOVVreg", argLength: 1, reg: gp11, asm: "MOVV"},
264
265 {name: "MOVVnop", argLength: 1, reg: regInfo{inputs: []regMask{gp}, outputs: []regMask{gp}}, resultInArg0: true},
266
267 {name: "MOVWF", argLength: 1, reg: fp11, asm: "MOVWF"},
268 {name: "MOVWD", argLength: 1, reg: fp11, asm: "MOVWD"},
269 {name: "MOVVF", argLength: 1, reg: fp11, asm: "MOVVF"},
270 {name: "MOVVD", argLength: 1, reg: fp11, asm: "MOVVD"},
271 {name: "TRUNCFW", argLength: 1, reg: fp11, asm: "TRUNCFW"},
272 {name: "TRUNCDW", argLength: 1, reg: fp11, asm: "TRUNCDW"},
273 {name: "TRUNCFV", argLength: 1, reg: fp11, asm: "TRUNCFV"},
274 {name: "TRUNCDV", argLength: 1, reg: fp11, asm: "TRUNCDV"},
275 {name: "MOVFD", argLength: 1, reg: fp11, asm: "MOVFD"},
276 {name: "MOVDF", argLength: 1, reg: fp11, asm: "MOVDF"},
277
278
279 {name: "CALLstatic", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
280 {name: "CALLtail", argLength: 1, reg: regInfo{clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true, tailCall: true},
281 {name: "CALLclosure", argLength: 3, reg: regInfo{inputs: []regMask{gpsp, buildReg("R22"), 0}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
282 {name: "CALLinter", argLength: 2, reg: regInfo{inputs: []regMask{gp}, clobbers: callerSave}, aux: "CallOff", clobberFlags: true, call: true},
283
284
285
286
287
288
289
290 {
291 name: "DUFFZERO",
292 aux: "Int64",
293 argLength: 2,
294 reg: regInfo{
295 inputs: []regMask{gp},
296 clobbers: buildReg("R1 R31"),
297 },
298 faultOnNilArg0: true,
299 },
300
301
302
303
304
305
306
307 {
308 name: "DUFFCOPY",
309 aux: "Int64",
310 argLength: 3,
311 reg: regInfo{
312 inputs: []regMask{buildReg("R2"), buildReg("R1")},
313 clobbers: buildReg("R1 R2 R31"),
314 },
315 faultOnNilArg0: true,
316 faultOnNilArg1: true,
317 },
318
319
320
321
322
323
324
325
326
327
328
329 {
330 name: "LoweredZero",
331 aux: "Int64",
332 argLength: 3,
333 reg: regInfo{
334 inputs: []regMask{buildReg("R1"), gp},
335 clobbers: buildReg("R1"),
336 },
337 clobberFlags: true,
338 faultOnNilArg0: true,
339 },
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354 {
355 name: "LoweredMove",
356 aux: "Int64",
357 argLength: 4,
358 reg: regInfo{
359 inputs: []regMask{buildReg("R2"), buildReg("R1"), gp},
360 clobbers: buildReg("R1 R2"),
361 },
362 clobberFlags: true,
363 faultOnNilArg0: true,
364 faultOnNilArg1: true,
365 },
366
367
368
369
370
371
372
373
374
375 {name: "LoweredAtomicAnd32", argLength: 3, reg: gpstore, asm: "AND", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
376 {name: "LoweredAtomicOr32", argLength: 3, reg: gpstore, asm: "OR", faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
377
378
379
380
381 {name: "LoweredAtomicLoad8", argLength: 2, reg: gpload, faultOnNilArg0: true},
382 {name: "LoweredAtomicLoad32", argLength: 2, reg: gpload, faultOnNilArg0: true},
383 {name: "LoweredAtomicLoad64", argLength: 2, reg: gpload, faultOnNilArg0: true},
384
385
386
387 {name: "LoweredAtomicStore8", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
388 {name: "LoweredAtomicStore32", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
389 {name: "LoweredAtomicStore64", argLength: 3, reg: gpstore, faultOnNilArg0: true, hasSideEffects: true},
390
391 {name: "LoweredAtomicStorezero32", argLength: 2, reg: gpstore0, faultOnNilArg0: true, hasSideEffects: true},
392 {name: "LoweredAtomicStorezero64", argLength: 2, reg: gpstore0, faultOnNilArg0: true, hasSideEffects: true},
393
394
395
396
397
398
399
400
401
402 {name: "LoweredAtomicExchange32", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
403 {name: "LoweredAtomicExchange64", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
404
405
406
407
408
409
410
411
412
413
414 {name: "LoweredAtomicAdd32", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
415 {name: "LoweredAtomicAdd64", argLength: 3, reg: gpxchg, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
416
417 {name: "LoweredAtomicAddconst32", argLength: 2, reg: regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}, aux: "Int32", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
418 {name: "LoweredAtomicAddconst64", argLength: 2, reg: regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{gp}}, aux: "Int64", resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 {name: "LoweredAtomicCas32", argLength: 4, reg: gpcas, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
437 {name: "LoweredAtomicCas64", argLength: 4, reg: gpcas, resultNotInArgs: true, faultOnNilArg0: true, hasSideEffects: true, unsafePoint: true},
438
439
440 {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpg}}, nilCheck: true, faultOnNilArg0: true},
441
442 {name: "FPFlagTrue", argLength: 1, reg: readflags},
443 {name: "FPFlagFalse", argLength: 1, reg: readflags},
444
445
446
447
448 {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}, zeroWidth: true},
449
450
451 {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
452
453
454
455
456
457 {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},
458
459
460
461
462
463
464 {name: "LoweredWB", argLength: 1, reg: regInfo{clobbers: (callerSave &^ gpg) | buildReg("R31"), outputs: []regMask{buildReg("R25")}}, clobberFlags: true, aux: "Int64"},
465
466
467 {name: "LoweredPubBarrier", argLength: 1, asm: "SYNC", hasSideEffects: true},
468
469
470
471
472
473
474 {name: "LoweredPanicBoundsRR", argLength: 3, aux: "Int64", reg: regInfo{inputs: []regMask{first16, first16}}, typ: "Mem", call: true},
475 {name: "LoweredPanicBoundsRC", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{first16}}, typ: "Mem", call: true},
476 {name: "LoweredPanicBoundsCR", argLength: 2, aux: "PanicBoundsC", reg: regInfo{inputs: []regMask{first16}}, typ: "Mem", call: true},
477 {name: "LoweredPanicBoundsCC", argLength: 1, aux: "PanicBoundsCC", reg: regInfo{}, typ: "Mem", call: true},
478 }
479
480 blocks := []blockData{
481 {name: "EQ", controls: 1},
482 {name: "NE", controls: 1},
483 {name: "LTZ", controls: 1},
484 {name: "LEZ", controls: 1},
485 {name: "GTZ", controls: 1},
486 {name: "GEZ", controls: 1},
487 {name: "FPT", controls: 1},
488 {name: "FPF", controls: 1},
489 }
490
491 archs = append(archs, arch{
492 name: "MIPS64",
493 pkg: "cmd/internal/obj/mips",
494 genfile: "../../mips64/ssa.go",
495 ops: ops,
496 blocks: blocks,
497 regnames: regNamesMIPS64,
498 gpregmask: gp,
499 fpregmask: fp,
500 specialregmask: hi | lo,
501 framepointerreg: -1,
502 linkreg: int8(num["R31"]),
503 })
504 }
505
View as plain text