From: Cherry Mui Date: Wed, 26 Nov 2025 15:56:15 +0000 (-0500) Subject: cmd/compile, runtime: guard X15 zeroing with GOEXPERIMENT=simd X-Git-Tag: go1.26rc1~75 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=de392823326ab3b572a8a493b813123381c15be9;p=gostls13.git 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index a4676cd0a9..9a0fa27470 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -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 diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 7c746803a8..ed46ad4a28 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif XORQ R14, R14 MOVQ $runtime·needAndBindM(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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif JMP ·sigpanic(SB) // gcWriteBarrier informs the GC about heap pointer writes. diff --git a/src/runtime/race_amd64.s b/src/runtime/race_amd64.s index 23f2e59e3d..ade29bc5f1 100644 --- a/src/runtime/race_amd64.s +++ b/src/runtime/race_amd64.s @@ -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 internal∕cpu·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. diff --git a/src/runtime/sys_darwin_amd64.s b/src/runtime/sys_darwin_amd64.s index e4e1216d56..e033e8b702 100644 --- a/src/runtime/sys_darwin_amd64.s +++ b/src/runtime/sys_darwin_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_dragonfly_amd64.s b/src/runtime/sys_dragonfly_amd64.s index 84bf326aad..e417d4b8a8 100644 --- a/src/runtime/sys_dragonfly_amd64.s +++ b/src/runtime/sys_dragonfly_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_freebsd_amd64.s b/src/runtime/sys_freebsd_amd64.s index a1fa3a6fa2..bab275cc72 100644 --- a/src/runtime/sys_freebsd_amd64.s +++ b/src/runtime/sys_freebsd_amd64.s @@ -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 internal∕cpu·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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 02505c2fb0..e252a4b914 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -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 internal∕cpu·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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_netbsd_amd64.s b/src/runtime/sys_netbsd_amd64.s index edc7f3d6ee..946b1fbe22 100644 --- a/src/runtime/sys_netbsd_amd64.s +++ b/src/runtime/sys_netbsd_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s index 734dfe6478..7766fa5194 100644 --- a/src/runtime/sys_openbsd_amd64.s +++ b/src/runtime/sys_openbsd_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif // Reserve space for spill slots. NOP SP // disable vet stack checking diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index b0b4d3cce6..52a21ba89b 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -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 internal∕cpu·X86+const_offsetX86HasAVX(SB), $1 JNE 2(PC) VXORPS X15, X15, X15 +#endif XORQ R14, R14 get_tls(AX)