cmd/compile, runtime: guard X15 zeroing with GOEXPERIMENT=simd

If simd experiment is not enabled, the compiler doesn't use the
AVX part of the register. So only zero it with the SSE instruction.

Change-Id: Ia3bdf34a9ed273128db2ee0f4f5db6f7cc76a975
Reviewed-on: https://go-review.googlesource.com/c/go/+/724720
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Cherry Mui 2025-11-26 10:56:15 -05:00
parent 86bbea0cfa
commit de39282332
10 changed files with 28 additions and 0 deletions

View file

@ -1871,6 +1871,10 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
// zeroX15 zeroes the X15 register.
func zeroX15(s *ssagen.State) {
if !buildcfg.Experiment.SIMD {
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
return
}
vxorps := func(s *ssagen.State) {
p := s.Prog(x86.AVXORPS)
p.From.Type = obj.TYPE_REG

View file

@ -1049,9 +1049,11 @@ needm:
// there's no need to handle that. Clear R14 so that there's
// a bad value in there, in case needm tries to use it.
XORPS X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
XORQ R14, R14
MOVQ $runtime·needAndBindM<ABIInternal>(SB), AX
CALL AX
@ -1749,9 +1751,11 @@ TEXT ·sigpanic0(SB),NOSPLIT,$0-0
get_tls(R14)
MOVQ g(R14), R14
XORPS X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
JMP ·sigpanic<ABIInternal>(SB)
// gcWriteBarrier informs the GC about heap pointer writes.

View file

@ -456,9 +456,11 @@ call:
// Back to Go world, set special registers.
// The g register (R14) is preserved in C.
XORPS X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
RET
// C->Go callback thunk that allows to call runtime·racesymbolize from C code.

View file

@ -177,9 +177,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -228,9 +228,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -265,9 +265,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking
@ -293,9 +295,11 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -340,9 +340,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking
@ -368,9 +370,11 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -310,9 +310,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -64,9 +64,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
get_tls(R12)
MOVQ g(R12), R14
PXOR X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
// Reserve space for spill slots.
NOP SP // disable vet stack checking

View file

@ -32,9 +32,11 @@ TEXT sigtramp<>(SB),NOSPLIT,$0-0
// R14 is cleared in case there's a non-zero value in there
// if called from a non-go thread.
XORPS X15, X15
#ifdef GOEXPERIMENT_simd
CMPB internalcpu·X86+const_offsetX86HasAVX(SB), $1
JNE 2(PC)
VXORPS X15, X15, X15
#endif
XORQ R14, R14
get_tls(AX)