]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/abi-internal: declare X15 scratch in function bodies
authorAustin Clements <austin@google.com>
Thu, 8 Apr 2021 21:38:25 +0000 (17:38 -0400)
committerAustin Clements <austin@google.com>
Fri, 9 Apr 2021 17:56:50 +0000 (17:56 +0000)
X15 must be zero at function calls and returns, but can be used as
scratch in the middle of a function. This allows things like memmove
and the hashing functions to use X15 temporarily, as long as they set
it back to 0 before returning.

This CL also clarifies the distinction between register meanings on
function call versus function return, since some of them have fixed
meanings at both call and return, while others only have a fixed
meaning at calls.

Updates #40724.

Change-Id: I9dad3abde42cd4d2788e8435cde6d55073dd75a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/308929
Trust: Austin Clements <austin@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/abi-internal.md

index b457f6ee746d4c6c0cf1b46525efddf8d543e8bf..aa61fcc5441757d7b67242649ad64c79d789fa83 100644 (file)
@@ -401,16 +401,16 @@ without corrupting arguments or results.
 
 Special-purpose registers are as follows:
 
-| Register | Call meaning | Body meaning |
+| Register | Call meaning | Return meaning | Body meaning |
 | --- | --- | --- |
-| RSP | Stack pointer | Fixed |
-| RBP | Frame pointer | Fixed |
-| RDX | Closure context pointer | Scratch |
-| R12 | None | Scratch |
-| R13 | None | Scratch |
-| R14 | Current goroutine | Scratch |
-| R15 | GOT reference temporary | Fixed if dynlink |
-| X15 | Zero value | Fixed |
+| RSP | Stack pointer | Same | Same |
+| RBP | Frame pointer | Same | Same |
+| RDX | Closure context pointer | Scratch | Scratch |
+| R12 | Scratch | Scratch | Scratch |
+| R13 | Scratch | Scratch | Scratch |
+| R14 | Current goroutine | Same | Scratch |
+| R15 | GOT reference temporary if dynlink | Same | Same |
+| X15 | Zero value | Same | Scratch |
 
 *Rationale*: These register meanings are compatible with Go’s
 stack-based calling convention except for R14 and X15, which will have
@@ -428,6 +428,10 @@ single-byte registers available to be a net win.
 functions often have to bulk zero their stack frames, and this is more
 efficient with a designated zero register.
 
+*Implementation note*: Registers with fixed meaning at calls but not
+in function bodies must be initialized by "injected" calls such as
+signal-based panics.
+
 #### Stack layout
 
 The stack pointer, RSP, grows down and is always aligned to 8 bytes.