internal/runtime/atomic: add Xchg8 for riscv64

For #69735

Change-Id: I34ca2b027494525ab64f94beee89ca373a5031ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/631615
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Julian Zhu 2024-11-25 22:08:41 +08:00 committed by Meng Zhuo
parent 0d8c512ce9
commit 58083b57d4
3 changed files with 25 additions and 1 deletions

View File

@ -18,6 +18,9 @@ func Xadduintptr(ptr *uintptr, delta uintptr) uintptr
//go:noescape
func Xchg(ptr *uint32, new uint32) uint32
//go:noescape
func Xchg8(ptr *uint8, new uint8) uint8
//go:noescape
func Xchg64(ptr *uint64, new uint64) uint64

View File

@ -199,6 +199,27 @@ TEXT ·Xchg(SB), NOSPLIT, $0-20
MOVW A1, ret+16(FP)
RET
// func Xchg8(ptr *uint8, new uint8) uint8
TEXT ·Xchg8(SB), NOSPLIT, $0-17
MOV ptr+0(FP), A0
MOVBU new+8(FP), A1
AND $3, A0, A2
SLL $3, A2
MOV $255, A4
SLL A2, A4
NOT A4
AND $~3, A0
SLL A2, A1
xchg8_again:
LRW (A0), A5
AND A4, A5, A3
OR A1, A3
SCW A3, (A0), A6
BNEZ A6, xchg8_again
SRL A2, A5
MOVB A5, ret+16(FP)
RET
// func Xchg64(ptr *uint64, new uint64) uint64
TEXT ·Xchg64(SB), NOSPLIT, $0-24
MOV ptr+0(FP), A0

View File

@ -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 386 || amd64 || arm || arm64 || loong64 || ppc64 || ppc64le
//go:build 386 || amd64 || arm || arm64 || loong64 || ppc64 || ppc64le || riscv64
package atomic_test