aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSrinivas Pokala <Pokala.Srinivas@ibm.com>2025-11-11 05:07:49 +0100
committerKeith Randall <khr@golang.org>2025-11-24 10:22:03 -0800
commit2a185fae7e9a3905ff9a96c44a0d6aac6c8aeb03 (patch)
treec2bc914d7e3007a4b0884300444977e9229741d1 /src
parente92d2964fa5beb678ecd97036eb732c9f885cf63 (diff)
downloadgo-2a185fae7e9a3905ff9a96c44a0d6aac6c8aeb03.tar.xz
reflect, runtime: add reflect support for regabi on s390x
This adds the regabi support needed for reflect calls makeFuncSub and methodValueCall. Also, It add's archFloat32FromReg and archFloat32ToReg. Update #40724 Change-Id: Ic4b9e30c82f292a24fd2c2b9796cd80a58cecf77 Reviewed-on: https://go-review.googlesource.com/c/go/+/719480 Reviewed-by: Vishwanatha HD <vishwanatha.hd@ibm.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
-rw-r--r--src/reflect/asm_s390x.s76
-rw-r--r--src/reflect/float32reg_generic.go2
-rw-r--r--src/reflect/float32reg_s390x.s30
-rw-r--r--src/reflect/stubs_s390x.go10
-rw-r--r--src/runtime/stkframe.go2
5 files changed, 104 insertions, 16 deletions
diff --git a/src/reflect/asm_s390x.s b/src/reflect/asm_s390x.s
index 4bd6613004..22cbd38ee5 100644
--- a/src/reflect/asm_s390x.s
+++ b/src/reflect/asm_s390x.s
@@ -5,34 +5,82 @@
#include "textflag.h"
#include "funcdata.h"
+// The frames of each of the two functions below contain two locals, at offsets
+// that are known to the runtime.
+//
+// The first local is a bool called retValid with a whole pointer-word reserved
+// for it on the stack. The purpose of this word is so that the runtime knows
+// whether the stack-allocated return space contains valid values for stack
+// scanning.
+//
+// The second local is an abi.RegArgs value whose offset is also known to the
+// runtime, so that a stack map for it can be constructed, since it contains
+// pointers visible to the GC.
+
+#define LOCAL_RETVALID 40
+#define LOCAL_REGARGS 48
+
+// The frame size of the functions below is
+// 32 (args of callReflect/callMethod) + 8 (bool + padding) + 264 (abi.RegArgs) = 304.
+
// makeFuncStub is the code half of the function returned by MakeFunc.
// See the comment on the declaration of makeFuncStub in makefunc.go
// for more details.
// No arg size here, runtime pulls arg map out of the func value.
-TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$304
NO_LOCAL_POINTERS
+ ADD $LOCAL_REGARGS, R15, R10 // spillArgs using R10
+ BL runtime·spillArgs(SB)
+ MOVD R12, 32(R15) // save context reg R12 > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
+#ifdef GOEXPERIMENT_regabiargs
+ MOVD R12, R2
+ MOVD R10, R3
+#else
MOVD R12, 8(R15)
- MOVD $argframe+0(FP), R3
- MOVD R3, 16(R15)
- MOVB $0, 40(R15)
- ADD $40, R15, R3
- MOVD R3, 24(R15)
- MOVD $0, 32(R15)
+ MOVD R10, 16(R15)
+#endif
+ BL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
+ MOVD 32(R15), R12 // restore context reg R12
+ MOVD R12, 8(R15)
+ MOVD $argframe+0(FP), R1
+ MOVD R1, 16(R15)
+ MOVB $0, LOCAL_RETVALID(R15)
+ ADD $LOCAL_RETVALID, R15, R1
+ MOVD R1, 24(R15)
+ ADD $LOCAL_REGARGS, R15, R1
+ MOVD R1, 32(R15)
BL ·callReflect(SB)
+ ADD $LOCAL_REGARGS, R15, R10 // unspillArgs using R10
+ BL runtime·unspillArgs(SB)
RET
// methodValueCall is the code half of the function returned by makeMethodValue.
// See the comment on the declaration of methodValueCall in makefunc.go
// for more details.
// No arg size here; runtime pulls arg map out of the func value.
-TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$40
+TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$304
NO_LOCAL_POINTERS
+ ADD $LOCAL_REGARGS, R15, R10 // spillArgs using R10
+ BL runtime·spillArgs(SB)
+ MOVD R12, 32(R15) // save context reg R12 > args of moveMakeFuncArgPtrs < LOCAL_REGARGS
+#ifdef GOEXPERIMENT_regabiargs
+ MOVD R12, R2
+ MOVD R10, R3
+#else
+ MOVD R12, 8(R15)
+ MOVD R10, 16(R15)
+#endif
+ BL ·moveMakeFuncArgPtrs<ABIInternal>(SB)
+ MOVD 32(R15), R12 // restore context reg R12
MOVD R12, 8(R15)
- MOVD $argframe+0(FP), R3
- MOVD R3, 16(R15)
- MOVB $0, 40(R15)
- ADD $40, R15, R3
- MOVD R3, 24(R15)
- MOVD $0, 32(R15)
+ MOVD $argframe+0(FP), R1
+ MOVD R1, 16(R15)
+ MOVB $0, LOCAL_RETVALID(R15)
+ ADD $LOCAL_RETVALID, R15, R1
+ MOVD R1, 24(R15)
+ ADD $LOCAL_REGARGS, R15, R1
+ MOVD R1, 32(R15)
BL ·callMethod(SB)
+ ADD $LOCAL_REGARGS, R15, R10 // unspillArgs using R10
+ BL runtime·unspillArgs(SB)
RET
diff --git a/src/reflect/float32reg_generic.go b/src/reflect/float32reg_generic.go
index 23ad4bf285..efbc3edc3d 100644
--- a/src/reflect/float32reg_generic.go
+++ b/src/reflect/float32reg_generic.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build !ppc64 && !ppc64le && !riscv64
+//go:build !ppc64 && !ppc64le && !riscv64 && !s390x
package reflect
diff --git a/src/reflect/float32reg_s390x.s b/src/reflect/float32reg_s390x.s
new file mode 100644
index 0000000000..bcf5582326
--- /dev/null
+++ b/src/reflect/float32reg_s390x.s
@@ -0,0 +1,30 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build s390x
+
+#include "textflag.h"
+
+// On s390x, the float32 becomes a float64
+// when loaded in a register, different from
+// other platforms. These functions are
+// needed to ensure correct conversions on s390x.
+
+// Convert float32->uint64
+TEXT ·archFloat32ToReg(SB),NOSPLIT,$0-16
+ FMOVS val+0(FP), F1
+ FMOVD F1, ret+8(FP)
+ RET
+
+// Convert uint64->float32
+TEXT ·archFloat32FromReg(SB),NOSPLIT,$0-12
+ FMOVD reg+0(FP), F1
+ // Normally a float64->float32 conversion
+ // would need rounding, but that is not needed
+ // here since the uint64 was originally converted
+ // from float32, and should be avoided to
+ // preserve SNaN values.
+ FMOVS F1, ret+8(FP)
+ RET
+
diff --git a/src/reflect/stubs_s390x.go b/src/reflect/stubs_s390x.go
new file mode 100644
index 0000000000..03504d7904
--- /dev/null
+++ b/src/reflect/stubs_s390x.go
@@ -0,0 +1,10 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build s390x
+
+package reflect
+
+func archFloat32FromReg(reg uint64) float32
+func archFloat32ToReg(val float32) uint64
diff --git a/src/runtime/stkframe.go b/src/runtime/stkframe.go
index 819b7f6c7d..d6e7e0371c 100644
--- a/src/runtime/stkframe.go
+++ b/src/runtime/stkframe.go
@@ -234,7 +234,7 @@ func (frame *stkframe) getStackMap(debug bool) (locals, args bitvector, objs []s
}
// stack objects.
- if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64") &&
+ if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "loong64" || GOARCH == "ppc64" || GOARCH == "ppc64le" || GOARCH == "riscv64" || GOARCH == "s390x") &&
unsafe.Sizeof(abi.RegArgs{}) > 0 && isReflect {
// For reflect.makeFuncStub and reflect.methodValueCall,
// we need to fake the stack object record.