Skip to content

Commit 4e6bbbe

Browse files
abner-chencsophie-zhao
authored andcommitted
reflect, runtime: add reflect support for regABI on loong64
Update #40724 Co-authored-by: Xiaolin Zhao <[email protected]> Change-Id: I0549fd1a2192ffb041034ff41bf0cc4be0b1662c Reviewed-on: https://go-review.googlesource.com/c/go/+/521784 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Meidan Li <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: David Chase <[email protected]> Run-TryBot: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent f6f141a commit 4e6bbbe

File tree

2 files changed

+64
-15
lines changed

2 files changed

+64
-15
lines changed

src/reflect/asm_loong64.s

+63-14
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,83 @@
77

88
#define REGCTXT R29
99

10+
// The frames of each of the two functions below contain two locals, at offsets
11+
// that are known to the runtime.
12+
//
13+
// The first local is a bool called retValid with a whole pointer-word reserved
14+
// for it on the stack. The purpose of this word is so that the runtime knows
15+
// whether the stack-allocated return space contains valid values for stack
16+
// scanning.
17+
//
18+
// The second local is an abi.RegArgs value whose offset is also known to the
19+
// runtime, so that a stack map for it can be constructed, since it contains
20+
// pointers visible to the GC.
21+
#define LOCAL_RETVALID 40
22+
#define LOCAL_REGARGS 48
23+
24+
// The frame size of the functions below is
25+
// 32 (args of callReflect) + 8 (bool + padding) + 392 (abi.RegArgs) = 432.
26+
1027
// makeFuncStub is the code half of the function returned by MakeFunc.
1128
// See the comment on the declaration of makeFuncStub in makefunc.go
1229
// for more details.
1330
// No arg size here, runtime pulls arg map out of the func value.
14-
TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$40
31+
TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$432
1532
NO_LOCAL_POINTERS
33+
ADDV $LOCAL_REGARGS, R3, R25 // spillArgs using R25
34+
JAL runtime·spillArgs(SB)
35+
MOVV REGCTXT, 32(R3) // save REGCTXT > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
36+
37+
#ifdef GOEXPERIMENT_regabiargs
38+
MOVV REGCTXT, R4
39+
MOVV R25, R5
40+
#else
1641
MOVV REGCTXT, 8(R3)
17-
MOVV $argframe+0(FP), R19
18-
MOVV R19, 16(R3)
19-
MOVB R0, 40(R3)
20-
ADDV $40, R3, R19
21-
MOVV R19, 24(R3)
22-
MOVV R0, 32(R3)
42+
MOVV R25, 16(R3)
43+
#endif
44+
JAL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
45+
MOVV 32(R3), REGCTXT // restore REGCTXT
46+
47+
MOVV REGCTXT, 8(R3)
48+
MOVV $argframe+0(FP), R20
49+
MOVV R20, 16(R3)
50+
MOVV R0, LOCAL_RETVALID(R3)
51+
ADDV $LOCAL_RETVALID, R3, R20
52+
MOVV R20, 24(R3)
53+
ADDV $LOCAL_REGARGS, R3, R20
54+
MOVV R20, 32(R3)
2355
JAL ·callReflect(SB)
56+
ADDV $LOCAL_REGARGS, R3, R25 //unspillArgs using R25
57+
JAL runtime·unspillArgs(SB)
2458
RET
2559

2660
// methodValueCall is the code half of the function returned by makeMethodValue.
2761
// See the comment on the declaration of methodValueCall in makefunc.go
2862
// for more details.
2963
// No arg size here; runtime pulls arg map out of the func value.
30-
TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$40
64+
TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$432
3165
NO_LOCAL_POINTERS
66+
ADDV $LOCAL_REGARGS, R3, R25 // spillArgs using R25
67+
JAL runtime·spillArgs(SB)
68+
MOVV REGCTXT, 32(R3) // save REGCTXT > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
69+
#ifdef GOEXPERIMENT_regabiargs
70+
MOVV REGCTXT, R4
71+
MOVV R25, R5
72+
#else
73+
MOVV REGCTXT, 8(R3)
74+
MOVV R25, 16(R3)
75+
#endif
76+
JAL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
77+
MOVV 32(R3), REGCTXT // restore REGCTXT
3278
MOVV REGCTXT, 8(R3)
33-
MOVV $argframe+0(FP), R19
34-
MOVV R19, 16(R3)
35-
MOVB R0, 40(R3)
36-
ADDV $40, R3, R19
37-
MOVV R19, 24(R3)
38-
MOVV R0, 32(R3)
79+
MOVV $argframe+0(FP), R20
80+
MOVV R20, 16(R3)
81+
MOVB R0, LOCAL_RETVALID(R3)
82+
ADDV $LOCAL_RETVALID, R3, R20
83+
MOVV R20, 24(R3)
84+
ADDV $LOCAL_REGARGS, R3, R20
85+
MOVV R20, 32(R3) // frame size to 32+SP as callreflect args)
3986
JAL ·callMethod(SB)
87+
ADDV $LOCAL_REGARGS, R3, R25 // unspillArgs using R25
88+
JAL runtime·unspillArgs(SB)
4089
RET

src/runtime/stkframe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (frame *stkframe) getStackMap(debug bool) (locals, args bitvector, objs []s
234234
}
235235

236236
// stack objects.
237-
if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
237+
if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
238238
unsafe.Sizeof(abi.RegArgs{}) > 0 && isReflect {
239239
// For reflect.makeFuncStub and reflect.methodValueCall,
240240
// we need to fake the stack object record.

0 commit comments

Comments
 (0)