aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLynn Boger <laboger@linux.vnet.ibm.com>2021-09-27 07:48:33 -0500
committerLynn Boger <laboger@linux.vnet.ibm.com>2021-09-28 18:58:50 +0000
commit9c43872bd831396ccf637f4569a18d784d1e9bce (patch)
tree436a8a312343c15f6f2fe0ec8119beab2417c2ad /src
parent84ba117fd7446030f93ab679d5c819dc028ad881 (diff)
downloadgo-9c43872bd831396ccf637f4569a18d784d1e9bce.tar.xz
reflect,runtime: add reflect support for regabi on PPC64
This adds the regabi support needed for reflect including: - implementation of the makeFuncSub and methodValueCall for reflect - implementations of archFloat32FromReg and archFloat32ToReg needed for PPC64 due to differences in the way float32 are represented in registers as compared to other platforms - change needed to stack.go due to the functions that are changed above Change-Id: Ida40d831370e39b91711ccb9616492b7fad3debf Reviewed-on: https://go-review.googlesource.com/c/go/+/352429 Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/reflect/asm_ppc64x.s74
-rw-r--r--src/reflect/float32reg_generic.go3
-rw-r--r--src/reflect/float32reg_ppc64x.s31
-rw-r--r--src/reflect/stubs_ppc64x.go11
-rw-r--r--src/runtime/stack.go2
5 files changed, 104 insertions, 17 deletions
diff --git a/src/reflect/asm_ppc64x.s b/src/reflect/asm_ppc64x.s
index d955e4110f..1ccfb25b94 100644
--- a/src/reflect/asm_ppc64x.s
+++ b/src/reflect/asm_ppc64x.s
@@ -9,34 +9,76 @@
#include "funcdata.h"
#include "asm_ppc64x.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 32+FIXED_FRAME
+#define LOCAL_REGARGS 40+FIXED_FRAME
+
+// The frame size of the functions below is
+// 32 (args of callReflect) + 8 (bool + padding) + 296 (abi.RegArgs) = 336.
+
// 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),$336
NO_LOCAL_POINTERS
- MOVD R11, FIXED_FRAME+0(R1)
- MOVD $argframe+0(FP), R3
- MOVD R3, FIXED_FRAME+8(R1)
- MOVB R0, FIXED_FRAME+32(R1)
- ADD $FIXED_FRAME+32, R1, R3
- MOVD R3, FIXED_FRAME+16(R1)
- MOVD R0, FIXED_FRAME+24(R1)
+ // NO_LOCAL_POINTERS is a lie. The stack map for the two locals in this
+ // frame is specially handled in the runtime. See the comment above LOCAL_RETVALID.
+ ADD $LOCAL_REGARGS, R1, R20
+ CALL runtime·spillArgs(SB)
+ MOVD R11, FIXED_FRAME+32(R1) // save R11
+ MOVD R11, FIXED_FRAME+0(R1) // arg for moveMakeFuncArgPtrs
+ MOVD R20, FIXED_FRAME+8(R1) // arg for local args
+ CALL ·moveMakeFuncArgPtrs(SB)
+ MOVD FIXED_FRAME+32(R1), R11 // restore R11 ctxt
+ MOVD R11, FIXED_FRAME+0(R1) // ctxt (arg0)
+ MOVD $argframe+0(FP), R3 // save arg to callArg
+ MOVD R3, FIXED_FRAME+8(R1) // frame (arg1)
+ ADD $LOCAL_RETVALID, R1, R3 // addr of return flag
+ MOVB R0, (R3) // clear flag
+ MOVD R3, FIXED_FRAME+16(R1) // addr retvalid (arg2)
+ ADD $LOCAL_REGARGS, R1, R3
+ MOVD R3, FIXED_FRAME+24(R1) // abiregargs (arg3)
BL ·callReflect(SB)
+ ADD $LOCAL_REGARGS, R1, R20 // set address of spill area
+ CALL 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),$336
NO_LOCAL_POINTERS
- MOVD R11, FIXED_FRAME+0(R1)
- MOVD $argframe+0(FP), R3
- MOVD R3, FIXED_FRAME+8(R1)
- MOVB R0, FIXED_FRAME+32(R1)
- ADD $FIXED_FRAME+32, R1, R3
- MOVD R3, FIXED_FRAME+16(R1)
- MOVD R0, FIXED_FRAME+24(R1)
+ // NO_LOCAL_POINTERS is a lie. The stack map for the two locals in this
+ // frame is specially handled in the runtime. See the comment above LOCAL_RETVALID.
+ ADD $LOCAL_REGARGS, R1, R20
+ CALL runtime·spillArgs(SB)
+ MOVD R11, FIXED_FRAME+0(R1) // arg0 ctxt
+ MOVD R11, FIXED_FRAME+32(R1) // save for later
+ MOVD R20, FIXED_FRAME+8(R1) // arg1 abiregargs
+ CALL ·moveMakeFuncArgPtrs(SB)
+ MOVD FIXED_FRAME+32(R1), R11 // restore ctxt
+ MOVD R11, FIXED_FRAME+0(R1) // set as arg0
+ MOVD $argframe+0(FP), R3 // frame pointer
+ MOVD R3, FIXED_FRAME+8(R1) // set as arg1
+ ADD $LOCAL_RETVALID, R1, R3
+ MOVB $0, (R3) // clear ret flag
+ MOVD R3, FIXED_FRAME+16(R1) // addr of return flag
+ ADD $LOCAL_REGARGS, R1, R3 // addr of abiregargs
+ MOVD R3, FIXED_FRAME+24(R1) // set as arg3
BL ·callMethod(SB)
+ ADD $LOCAL_REGARGS, R1, R20
+ CALL runtime·unspillArgs(SB)
RET
diff --git a/src/reflect/float32reg_generic.go b/src/reflect/float32reg_generic.go
index 381d458057..bfceb9ecaa 100644
--- a/src/reflect/float32reg_generic.go
+++ b/src/reflect/float32reg_generic.go
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+//go:build !ppc64 && !ppc64le
+// +build !ppc64,!ppc64le
+
package reflect
import "unsafe"
diff --git a/src/reflect/float32reg_ppc64x.s b/src/reflect/float32reg_ppc64x.s
new file mode 100644
index 0000000000..391edfa7ce
--- /dev/null
+++ b/src/reflect/float32reg_ppc64x.s
@@ -0,0 +1,31 @@
+// Copyright 2021 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 ppc64 || ppc64le
+// +build ppc64 ppc64le
+
+#include "textflag.h"
+
+// On PPC64, the float32 becomes a float64
+// when loaded in a register, different from
+// other platforms. These functions are
+// needed to ensure correct conversions on PPC64.
+
+// 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_ppc64x.go b/src/reflect/stubs_ppc64x.go
new file mode 100644
index 0000000000..dbd3f9e748
--- /dev/null
+++ b/src/reflect/stubs_ppc64x.go
@@ -0,0 +1,11 @@
+// Copyright 2021 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 ppc64le || ppc64
+// +build ppc64le ppc64
+
+package reflect
+
+func archFloat32FromReg(reg uint64) float32
+func archFloat32ToReg(val float32) uint64
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index cccec49f8e..22fff73947 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -1316,7 +1316,7 @@ func getStackMap(frame *stkframe, cache *pcvalueCache, debug bool) (locals, args
}
// stack objects.
- if (GOARCH == "amd64" || GOARCH == "arm64") && unsafe.Sizeof(abi.RegArgs{}) > 0 && frame.argmap != nil {
+ if (GOARCH == "amd64" || GOARCH == "arm64" || GOARCH == "ppc64" || GOARCH == "ppc64le") && unsafe.Sizeof(abi.RegArgs{}) > 0 && frame.argmap != nil {
// argmap is set when the function is reflect.makeFuncStub or reflect.methodValueCall.
// We don't actually use argmap in this case, but we need to fake the stack object
// record for these frames which contain an internal/abi.RegArgs at a hard-coded offset.