diff options
| author | eric fang <eric.fang@arm.com> | 2021-12-23 06:53:50 +0000 |
|---|---|---|
| committer | Eric Fang <eric.fang@arm.com> | 2022-03-30 01:28:43 +0000 |
| commit | eee6f9f825596a769ff163e098d2656cbed09d4f (patch) | |
| tree | c29366047ae3a2e380580ae2513042cf1eac7e08 /src/runtime/cgo | |
| parent | 63169c8bdf3e7ac5006c8976b0631b281eb49394 (diff) | |
| download | go-eee6f9f825596a769ff163e098d2656cbed09d4f.tar.xz | |
runtime: unify C->Go ABI transitions on arm64
There are several of places that save and restore the C callee-saved registers,
the operation is the same everywhere, so this CL defines several macros
to do this, which will help reduce code redundancy and unify the operation.
This CL also replaced consecutive MOVD instructions with STP and LDP instructions
in several places where these macros do not apply.
Change-Id: I815f39fe484a9ab9b6bd157dfcbc8ad99c1420fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/374397
Trust: Eric Fang <eric.fang@arm.com>
Run-TryBot: Eric Fang <eric.fang@arm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime/cgo')
| -rw-r--r-- | src/runtime/cgo/abi_arm64.h | 43 | ||||
| -rw-r--r-- | src/runtime/cgo/asm_arm64.s | 55 |
2 files changed, 54 insertions, 44 deletions
diff --git a/src/runtime/cgo/abi_arm64.h b/src/runtime/cgo/abi_arm64.h new file mode 100644 index 0000000000..e2b5e6d0be --- /dev/null +++ b/src/runtime/cgo/abi_arm64.h @@ -0,0 +1,43 @@ +// 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. + +// Macros for transitioning from the host ABI to Go ABI0. +// +// These macros save and restore the callee-saved registers +// from the stack, but they don't adjust stack pointer, so +// the user should prepare stack space in advance. +// SAVE_R19_TO_R28(offset) saves R19 ~ R28 to the stack space +// of ((offset)+0*8)(RSP) ~ ((offset)+9*8)(RSP). +// +// SAVE_F8_TO_F15(offset) saves F8 ~ F15 to the stack space +// of ((offset)+0*8)(RSP) ~ ((offset)+7*8)(RSP). +// +// R29 is not saved because Go will save and restore it. + +#define SAVE_R19_TO_R28(offset) \ + STP (R19, R20), ((offset)+0*8)(RSP) \ + STP (R21, R22), ((offset)+2*8)(RSP) \ + STP (R23, R24), ((offset)+4*8)(RSP) \ + STP (R25, R26), ((offset)+6*8)(RSP) \ + STP (R27, g), ((offset)+8*8)(RSP) + +#define RESTORE_R19_TO_R28(offset) \ + LDP ((offset)+0*8)(RSP), (R19, R20) \ + LDP ((offset)+2*8)(RSP), (R21, R22) \ + LDP ((offset)+4*8)(RSP), (R23, R24) \ + LDP ((offset)+6*8)(RSP), (R25, R26) \ + LDP ((offset)+8*8)(RSP), (R27, g) /* R28 */ + +#define SAVE_F8_TO_F15(offset) \ + FSTPD (F8, F9), ((offset)+0*8)(RSP) \ + FSTPD (F10, F11), ((offset)+2*8)(RSP) \ + FSTPD (F12, F13), ((offset)+4*8)(RSP) \ + FSTPD (F14, F15), ((offset)+6*8)(RSP) + +#define RESTORE_F8_TO_F15(offset) \ + FLDPD ((offset)+0*8)(RSP), (F8, F9) \ + FLDPD ((offset)+2*8)(RSP), (F10, F11) \ + FLDPD ((offset)+4*8)(RSP), (F12, F13) \ + FLDPD ((offset)+6*8)(RSP), (F14, F15) + diff --git a/src/runtime/cgo/asm_arm64.s b/src/runtime/cgo/asm_arm64.s index 1cb25cf89e..e808dedcfc 100644 --- a/src/runtime/cgo/asm_arm64.s +++ b/src/runtime/cgo/asm_arm64.s @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "textflag.h" +#include "abi_arm64.h" // Called by C code generated by cmd/cgo. // func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr) @@ -14,57 +15,23 @@ TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0 * push 3 args for fn (R0, R1, R3), skipping R2. * Also note that at procedure entry in gc world, 8(RSP) will be the * first arg. - * TODO(minux): use LDP/STP here if it matters. */ SUB $(8*24), RSP - MOVD R0, (8*1)(RSP) - MOVD R1, (8*2)(RSP) + STP (R0, R1), (8*1)(RSP) MOVD R3, (8*3)(RSP) - MOVD R19, (8*4)(RSP) - MOVD R20, (8*5)(RSP) - MOVD R21, (8*6)(RSP) - MOVD R22, (8*7)(RSP) - MOVD R23, (8*8)(RSP) - MOVD R24, (8*9)(RSP) - MOVD R25, (8*10)(RSP) - MOVD R26, (8*11)(RSP) - MOVD R27, (8*12)(RSP) - MOVD g, (8*13)(RSP) - MOVD R29, (8*14)(RSP) - MOVD R30, (8*15)(RSP) - FMOVD F8, (8*16)(RSP) - FMOVD F9, (8*17)(RSP) - FMOVD F10, (8*18)(RSP) - FMOVD F11, (8*19)(RSP) - FMOVD F12, (8*20)(RSP) - FMOVD F13, (8*21)(RSP) - FMOVD F14, (8*22)(RSP) - FMOVD F15, (8*23)(RSP) + + SAVE_R19_TO_R28(8*4) + SAVE_F8_TO_F15(8*14) + STP (R29, R30), (8*22)(RSP) + // Initialize Go ABI environment BL runtimeĀ·load_g(SB) - BL runtimeĀ·cgocallback(SB) - MOVD (8*4)(RSP), R19 - MOVD (8*5)(RSP), R20 - MOVD (8*6)(RSP), R21 - MOVD (8*7)(RSP), R22 - MOVD (8*8)(RSP), R23 - MOVD (8*9)(RSP), R24 - MOVD (8*10)(RSP), R25 - MOVD (8*11)(RSP), R26 - MOVD (8*12)(RSP), R27 - MOVD (8*13)(RSP), g - MOVD (8*14)(RSP), R29 - MOVD (8*15)(RSP), R30 - FMOVD (8*16)(RSP), F8 - FMOVD (8*17)(RSP), F9 - FMOVD (8*18)(RSP), F10 - FMOVD (8*19)(RSP), F11 - FMOVD (8*20)(RSP), F12 - FMOVD (8*21)(RSP), F13 - FMOVD (8*22)(RSP), F14 - FMOVD (8*23)(RSP), F15 + RESTORE_R19_TO_R28(8*4) + RESTORE_F8_TO_F15(8*14) + LDP (8*22)(RSP), (R29, R30) + ADD $(8*24), RSP RET |
