aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime/sys
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2025-12-12 15:32:43 -0800
committerRoland Shoemaker <roland@golang.org>2026-02-24 08:50:23 -0800
commit0bd25dc875a3157974c06ba8d4fb33f95ac2dfdd (patch)
tree311e40ec00fbd9f6f0dd951b175c8dfc0449fa02 /src/internal/runtime/sys
parentb7db3246a691e9d0f506c374559c3f45b932e33e (diff)
downloadgo-0bd25dc875a3157974c06ba8d4fb33f95ac2dfdd.tar.xz
internal/runtime/sys: improve DIT assembly
In EnableDIT, if DIT is already enabled, return early instead of executing MSR and DSB/ISB, since they are not particularly cheap instructions. Also, if we have support for the SB (Speculation Barrier) instruction, use it instead of DSB+ISB when enabling DIT, since SB is cheaper. Change-Id: I1b3ecbd95ed42bfd10d646125704abf4e80b6d2e Reviewed-on: https://go-review.googlesource.com/c/go/+/729800 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal/runtime/sys')
-rw-r--r--src/internal/runtime/sys/dit_arm64.go3
-rw-r--r--src/internal/runtime/sys/dit_arm64.s11
2 files changed, 11 insertions, 3 deletions
diff --git a/src/internal/runtime/sys/dit_arm64.go b/src/internal/runtime/sys/dit_arm64.go
index 643fd770d5..c83df081a0 100644
--- a/src/internal/runtime/sys/dit_arm64.go
+++ b/src/internal/runtime/sys/dit_arm64.go
@@ -8,10 +8,13 @@ package sys
import (
"internal/cpu"
+ "unsafe"
)
var DITSupported = cpu.ARM64.HasDIT
+const offsetARM64HasSB = unsafe.Offsetof(cpu.ARM64.HasSB)
+
func EnableDIT() bool
func DITEnabled() bool
func DisableDIT()
diff --git a/src/internal/runtime/sys/dit_arm64.s b/src/internal/runtime/sys/dit_arm64.s
index 408b60c8c0..cc5642f838 100644
--- a/src/internal/runtime/sys/dit_arm64.s
+++ b/src/internal/runtime/sys/dit_arm64.s
@@ -2,16 +2,21 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+#include "go_asm.h"
#include "textflag.h"
TEXT ·EnableDIT(SB),$0-1
MRS DIT, R0
UBFX $24, R0, $1, R1
MOVB R1, ret+0(FP)
+ TBNZ $0, R1, ret
MSR $1, DIT
- // TODO(roland): the SB instruction is significantly more
- // performant when available. We should detect its availability
- // and use it when we can.
+ MOVBU internal∕cpu·ARM64+const_offsetARM64HasSB(SB), R2
+ TBZ $0, R2, sbFallback
+ SB
+ret:
+ RET
+sbFallback:
DSB $7 // nsh
ISB $15 // sy
RET