From 3aa71c12eacd68ec16e7172d92aa5c6af32f0c3b Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Mon, 7 Oct 2024 20:53:01 +0000 Subject: 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 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Michael Knyszek --- src/internal/runtime/atomic/atomic_arm64.go | 3 +++ src/internal/runtime/atomic/atomic_arm64.s | 24 ++++++++++++++++++++++++ src/internal/runtime/atomic/xchg8_test.go | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/internal/runtime/atomic') 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 @@ -24,6 +24,9 @@ func Xadd64(ptr *uint64, delta int64) uint64 //go:noescape 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 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 -- cgit v1.3-5-g45d5