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