Skip to content

Commit a6d4692

Browse files
committed
cmd/internal/obj/loong64, cmd/compile, runtime: move the loong64 G to R31
R22 is traditionally the frame pointer on loong64, so while we aren't necessarily using it like so, it's probably better to move G elsewhere. Moving it to the end of the GPR sequence seems cleaner in that it makes the reserved GPRs more contiguous. Breakage is not expected, given that no code should rely on the actual register number of g, and the port is still relatively young. Change-Id: I2e03b736f61567f3321a479da991e7ca552f3e73
1 parent ce2b6da commit a6d4692

File tree

12 files changed

+273
-274
lines changed

12 files changed

+273
-274
lines changed

src/cmd/asm/internal/arch/arch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ func archLoong64(linkArch *obj.LinkArch) *Arch {
533533
register["SB"] = RSB
534534
register["FP"] = RFP
535535
register["PC"] = RPC
536-
// Avoid unintentionally clobbering g using R22.
537-
delete(register, "R22")
538-
register["g"] = loong64.REG_R22
536+
// Avoid unintentionally clobbering g using R31.
537+
delete(register, "R31")
538+
register["g"] = loong64.REG_R31
539539
registerPrefix := map[string]bool{
540540
"F": true,
541541
"FCSR": true,

src/cmd/asm/internal/asm/operand_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ var loong64OperandTests = []operandTest{
908908
{"R2", "R2"},
909909
{"R20", "R20"},
910910
{"R21", "R21"},
911+
{"R22", "R22"},
911912
{"R23", "R23"},
912913
{"R24", "R24"},
913914
{"R25", "R25"},
@@ -917,7 +918,6 @@ var loong64OperandTests = []operandTest{
917918
{"R29", "R29"},
918919
{"R3", "R3"},
919920
{"R30", "R30"},
920-
{"R31", "R31"},
921921
{"R4", "R4"},
922922
{"R5", "R5"},
923923
{"R6", "R6"},

src/cmd/compile/internal/loong64/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
748748
p4 := s.Prog(obj.ANOP) // not a machine instruction, for branch to land
749749
p2.To.SetTarget(p4)
750750
case ssa.OpLOONG64LoweredGetClosurePtr:
751-
// Closure pointer is R22 (loong64.REGCTXT).
751+
// Closure pointer is R29 (loong64.REGCTXT).
752752
ssagen.CheckLoweredGetClosurePtr(v)
753753
case ssa.OpLOONG64LoweredGetCallerSP:
754754
// caller's SP is FixedFrameSize below the address of the first arg

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var regNamesLOONG64 = []string{
5050
"R19",
5151
"R20",
5252
"R21",
53-
"g", // aka R22
53+
"R22",
5454
"R23",
5555
"R24",
5656
"R25",
@@ -59,7 +59,7 @@ var regNamesLOONG64 = []string{
5959
"R28",
6060
"R29",
6161
// R30 is REGTMP not used in regalloc
62-
"R31",
62+
"g", // aka R31
6363

6464
"F0",
6565
"F1",
@@ -123,8 +123,8 @@ func init() {
123123

124124
// Common individual register masks
125125
var (
126-
gp = buildReg("R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R23 R24 R25 R26 R27 R28 R29 R31") // R1 is LR, R2 is thread pointer, R3 is stack pointer, R21-unused, R22 is g, R30 is REGTMP
127-
gps = buildReg("R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R19 R20 R23 R24 R25 R26 R27 R28 R29 R31") | buildReg("g")
126+
gp = buildReg("R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R22 R23 R24 R25 R26 R27 R28 R29") // R1 is LR, R2 is thread pointer, R3 is stack pointer, R21-unused, R30 is REGTMP, R31 is g
127+
gps = buildReg("R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R19 R20 R22 R23 R24 R25 R26 R27 R28 R29") | buildReg("g")
128128
gpg = gp | buildReg("g")
129129
gpsp = gp | buildReg("SP")
130130
gpspg = gpg | buildReg("SP")
@@ -430,7 +430,7 @@ func init() {
430430

431431
// Scheduler ensures LoweredGetClosurePtr occurs only in entry block,
432432
// and sorts it to the very beginning of the block to prevent other
433-
// use of R22 (loong64.REGCTXT, the closure pointer)
433+
// use of R29 (loong64.REGCTXT, the closure pointer)
434434
{name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R29")}}, zeroWidth: true},
435435

436436
// LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 204 additions & 204 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/internal/obj/loong64/a.out.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ const (
162162
REGRT1 = REG_R19 // reserved for runtime, duffzero and duffcopy
163163
REGRT2 = REG_R20 // reserved for runtime, duffcopy
164164
REGCTXT = REG_R29 // context for closures
165-
REGG = REG_R22 // G in loong64
166165
REGTMP = REG_R30 // used by the assembler
166+
REGG = REG_R31 // G in loong64
167167
FREGRET = REG_F0
168168
)
169169

src/runtime/asm_loong64.s

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ TEXT runtime·return0(SB), NOSPLIT, $0
597597
// Called from cgo wrappers, this function returns g->m->curg.stack.hi.
598598
// Must obey the gcc calling convention.
599599
TEXT _cgo_topofstack(SB),NOSPLIT,$16
600-
// g (R22) and REGTMP (R30) might be clobbered by load_g. They
600+
// REGTMP (R30) and g (R31) might be clobbered by load_g. They
601601
// are callee-save in the gcc calling convention, so save them.
602602
MOVV R30, savedREGTMP-16(SP)
603603
MOVV g, savedG-8(SP)
@@ -681,16 +681,16 @@ flush:
681681
// R19 already saved
682682
MOVV R20, 144(R3)
683683
MOVV R21, 152(R3)
684-
// R22 is g.
685-
MOVV R23, 160(R3)
686-
MOVV R24, 168(R3)
687-
MOVV R25, 176(R3)
688-
MOVV R26, 184(R3)
684+
MOVV R22, 160(R3)
685+
MOVV R23, 168(R3)
686+
MOVV R24, 176(R3)
687+
MOVV R25, 184(R3)
688+
MOVV R26, 192(R3)
689689
// R27 already saved
690-
// R28 already saved.
691-
MOVV R29, 192(R3)
690+
// R28 already saved
691+
MOVV R29, 200(R3)
692692
// R30 is tmp register.
693-
MOVV R31, 200(R3)
693+
// R31 is g.
694694

695695
CALL runtime·wbBufFlush(SB)
696696

@@ -713,12 +713,12 @@ flush:
713713
MOVV 136(R3), R18
714714
MOVV 144(R3), R20
715715
MOVV 152(R3), R21
716-
MOVV 160(R3), R23
717-
MOVV 168(R3), R24
718-
MOVV 176(R3), R25
719-
MOVV 184(R3), R26
720-
MOVV 192(R3), R29
721-
MOVV 200(R3), R31
716+
MOVV 160(R3), R22
717+
MOVV 168(R3), R23
718+
MOVV 176(R3), R24
719+
MOVV 184(R3), R25
720+
MOVV 192(R3), R26
721+
MOVV 200(R3), R29
722722
JMP retry
723723

724724
TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0

src/runtime/cgo/asm_loong64.s

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
1616
* first arg.
1717
*/
1818

19-
ADDV $(-8*22), R3
19+
ADDV $(-8*24), R3
2020
MOVV R4, (8*1)(R3) // fn unsafe.Pointer
2121
MOVV R5, (8*2)(R3) // a unsafe.Pointer
2222
MOVV R7, (8*3)(R3) // ctxt uintptr
@@ -29,15 +29,16 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
2929
MOVV R29, (8*10)(R3)
3030
MOVV R30, (8*11)(R3)
3131
MOVV g, (8*12)(R3)
32-
MOVV R1, (8*13)(R3)
33-
MOVD F24, (8*14)(R3)
34-
MOVD F25, (8*15)(R3)
35-
MOVD F26, (8*16)(R3)
36-
MOVD F27, (8*17)(R3)
37-
MOVD F28, (8*18)(R3)
38-
MOVD F29, (8*19)(R3)
39-
MOVD F30, (8*20)(R3)
40-
MOVD F31, (8*21)(R3)
32+
MOVV R22, (8*13)(R3)
33+
MOVV R1, (8*14)(R3)
34+
MOVD F24, (8*15)(R3)
35+
MOVD F25, (8*16)(R3)
36+
MOVD F26, (8*17)(R3)
37+
MOVD F27, (8*18)(R3)
38+
MOVD F28, (8*19)(R3)
39+
MOVD F29, (8*20)(R3)
40+
MOVD F30, (8*21)(R3)
41+
MOVD F31, (8*22)(R3)
4142

4243
// Initialize Go ABI environment
4344
JAL runtime·load_g(SB)
@@ -53,15 +54,16 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
5354
MOVV (8*10)(R3), R29
5455
MOVV (8*11)(R3), R30
5556
MOVV (8*12)(R3), g
56-
MOVV (8*13)(R3), R1
57-
MOVD (8*14)(R3), F24
58-
MOVD (8*15)(R3), F25
59-
MOVD (8*16)(R3), F26
60-
MOVD (8*17)(R3), F27
61-
MOVD (8*18)(R3), F28
62-
MOVD (8*19)(R3), F29
63-
MOVD (8*20)(R3), F30
64-
MOVD (8*21)(R3), F31
65-
ADDV $(8*22), R3
57+
MOVV (8*13)(R3), R22
58+
MOVV (8*14)(R3), R1
59+
MOVD (8*15)(R3), F24
60+
MOVD (8*16)(R3), F25
61+
MOVD (8*17)(R3), F26
62+
MOVD (8*18)(R3), F27
63+
MOVD (8*19)(R3), F28
64+
MOVD (8*20)(R3), F29
65+
MOVD (8*21)(R3), F30
66+
MOVD (8*22)(R3), F31
67+
ADDV $(8*24), R3
6668

6769
RET

src/runtime/mkpreempt.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,11 @@ func genLoong64() {
464464
sub := "SUBV"
465465
regsize := 8
466466

467-
// Add integer registers r4-r21 r23-r29 r31
468-
// R0 (zero), R30 (REGTMP), R2 (tp), R3 (SP), R22 (g), R1 (LR) are special,
467+
// Add integer registers r4-r29
468+
// R0 (zero), R1 (LR), R2 (tp), R3 (SP), R30 (REGTMP) and R31 (g) are
469+
// special and not saved here.
469470
var l = layout{sp: "R3", stack: regsize} // add slot to save PC of interrupted instruction (in LR)
470-
for i := 4; i <= 31; i++ {
471-
if i == 22 || i == 30 {
472-
continue
473-
}
471+
for i := 4; i <= 29; i++ {
474472
reg := fmt.Sprintf("R%d", i)
475473
l.add(mov, reg, regsize)
476474
}

src/runtime/preempt_loong64.s

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
2424
MOVV R19, 128(R3)
2525
MOVV R20, 136(R3)
2626
MOVV R21, 144(R3)
27-
MOVV R23, 152(R3)
28-
MOVV R24, 160(R3)
29-
MOVV R25, 168(R3)
30-
MOVV R26, 176(R3)
31-
MOVV R27, 184(R3)
32-
MOVV R28, 192(R3)
33-
MOVV R29, 200(R3)
34-
MOVV R31, 208(R3)
27+
MOVV R22, 152(R3)
28+
MOVV R23, 160(R3)
29+
MOVV R24, 168(R3)
30+
MOVV R25, 176(R3)
31+
MOVV R26, 184(R3)
32+
MOVV R27, 192(R3)
33+
MOVV R28, 200(R3)
34+
MOVV R29, 208(R3)
3535
MOVD F0, 216(R3)
3636
MOVD F1, 224(R3)
3737
MOVD F2, 232(R3)
@@ -97,14 +97,14 @@ TEXT ·asyncPreempt(SB),NOSPLIT|NOFRAME,$0-0
9797
MOVD 232(R3), F2
9898
MOVD 224(R3), F1
9999
MOVD 216(R3), F0
100-
MOVV 208(R3), R31
101-
MOVV 200(R3), R29
102-
MOVV 192(R3), R28
103-
MOVV 184(R3), R27
104-
MOVV 176(R3), R26
105-
MOVV 168(R3), R25
106-
MOVV 160(R3), R24
107-
MOVV 152(R3), R23
100+
MOVV 208(R3), R29
101+
MOVV 200(R3), R28
102+
MOVV 192(R3), R27
103+
MOVV 184(R3), R26
104+
MOVV 176(R3), R25
105+
MOVV 168(R3), R24
106+
MOVV 160(R3), R23
107+
MOVV 152(R3), R22
108108
MOVV 144(R3), R21
109109
MOVV 136(R3), R20
110110
MOVV 128(R3), R19

src/runtime/signal_linux_loong64.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ func (c *sigctxt) sigcode() uint32 { return uint32(c.info.si_code) }
6464
func (c *sigctxt) sigaddr() uint64 { return c.info.si_addr }
6565

6666
func (c *sigctxt) set_r31(x uint64) { c.regs().sc_regs[31] = x }
67-
func (c *sigctxt) set_r22(x uint64) { c.regs().sc_regs[22] = x }
6867
func (c *sigctxt) set_pc(x uint64) { c.regs().sc_pc = x }
6968
func (c *sigctxt) set_sp(x uint64) { c.regs().sc_regs[3] = x }
7069
func (c *sigctxt) set_link(x uint64) { c.regs().sc_regs[1] = x }

src/runtime/signal_loong64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *sigctxt) preparePanic(sig uint32, gp *g) {
7777
}
7878

7979
// In case we are panicking from external C code
80-
c.set_r22(uint64(uintptr(unsafe.Pointer(gp))))
80+
c.set_r31(uint64(uintptr(unsafe.Pointer(gp))))
8181
c.set_pc(uint64(abi.FuncPCABIInternal(sigpanic)))
8282
}
8383

0 commit comments

Comments
 (0)