aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime/atomic
diff options
context:
space:
mode:
authorMauri de Souza Meneguzzo <mauri870@gmail.com>2024-10-07 20:53:01 +0000
committerKeith Randall <khr@golang.org>2024-10-08 22:06:50 +0000
commit3aa71c12eacd68ec16e7172d92aa5c6af32f0c3b (patch)
tree662bd12188b4bdecfb2ca40bb3d018caf876c26c /src/internal/runtime/atomic
parent0733682e5ff4cd294f5eccb31cbe87a543147bc6 (diff)
downloadgo-3aa71c12eacd68ec16e7172d92aa5c6af32f0c3b.tar.xz
cmd/compile, internal/runtime/atomic: add Xchg8 for arm64
For #69735 Change-Id: I61a2e561684c538eea705e60c8ebda6be3ef31a7 GitHub-Last-Rev: 3c7f4ec845182d3ef1a007319d91027433163db3 GitHub-Pull-Request: golang/go#69751 Reviewed-on: https://go-review.googlesource.com/c/go/+/617595 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/internal/runtime/atomic')
-rw-r--r--src/internal/runtime/atomic/atomic_arm64.go3
-rw-r--r--src/internal/runtime/atomic/atomic_arm64.s24
-rw-r--r--src/internal/runtime/atomic/xchg8_test.go2
3 files changed, 28 insertions, 1 deletions
diff --git a/src/internal/runtime/atomic/atomic_arm64.go b/src/internal/runtime/atomic/atomic_arm64.go
index c4c56ae895..f4aef19388 100644
--- a/src/internal/runtime/atomic/atomic_arm64.go
+++ b/src/internal/runtime/atomic/atomic_arm64.go
@@ -25,6 +25,9 @@ func Xadd64(ptr *uint64, delta int64) uint64
func Xadduintptr(ptr *uintptr, delta uintptr) uintptr
//go:noescape
+func Xchg8(ptr *uint8, new uint8) uint8
+
+//go:noescape
func Xchg(ptr *uint32, new uint32) uint32
//go:noescape
diff --git a/src/internal/runtime/atomic/atomic_arm64.s b/src/internal/runtime/atomic/atomic_arm64.s
index ede56538b8..09f3b53c5c 100644
--- a/src/internal/runtime/atomic/atomic_arm64.s
+++ b/src/internal/runtime/atomic/atomic_arm64.s
@@ -120,6 +120,30 @@ TEXT ·Store64(SB), NOSPLIT, $0-16
STLR R1, (R0)
RET
+// uint8 Xchg(ptr *uint8, new uint8)
+// Atomically:
+// old := *ptr;
+// *ptr = new;
+// return old;
+TEXT ·Xchg8(SB), NOSPLIT, $0-17
+ MOVD ptr+0(FP), R0
+ MOVB new+8(FP), R1
+#ifndef GOARM64_LSE
+ MOVBU internal∕cpu·ARM64+const_offsetARM64HasATOMICS(SB), R4
+ CBZ R4, load_store_loop
+#endif
+ SWPALB R1, (R0), R2
+ MOVB R2, ret+16(FP)
+ RET
+#ifndef GOARM64_LSE
+load_store_loop:
+ LDAXRB (R0), R2
+ STLXRB R1, (R0), R3
+ CBNZ R3, load_store_loop
+ MOVB R2, ret+16(FP)
+ RET
+#endif
+
// uint32 Xchg(ptr *uint32, new uint32)
// Atomically:
// old := *ptr;
diff --git a/src/internal/runtime/atomic/xchg8_test.go b/src/internal/runtime/atomic/xchg8_test.go
index b0b39c2dd7..a04fcfc4bd 100644
--- a/src/internal/runtime/atomic/xchg8_test.go
+++ b/src/internal/runtime/atomic/xchg8_test.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build amd64 || ppc64 || ppc64le
+//go:build amd64 || arm64 || ppc64 || ppc64le
package atomic_test