diff options
| author | Julian Zhu <jz531210@gmail.com> | 2025-02-21 16:48:07 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-02-21 18:57:27 -0800 |
| commit | e15d14873f3e73fa82d1e3242113182035c135ba (patch) | |
| tree | 211ecad047d2c122c7bafd8956dae37d7c8e2db1 /src/internal/runtime/atomic | |
| parent | 17762557421b912490498b815f28f71646b411fe (diff) | |
| download | go-e15d14873f3e73fa82d1e3242113182035c135ba.tar.xz | |
internal/runtime/atomic: add Xchg8 for mipsx
For #69735
Change-Id: I2a0336214786e14b9a37834d81a0a0d14231451c
Reviewed-on: https://go-review.googlesource.com/c/go/+/651315
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
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/atomic')
| -rw-r--r-- | src/internal/runtime/atomic/atomic_mipsx.go | 3 | ||||
| -rw-r--r-- | src/internal/runtime/atomic/atomic_mipsx.s | 33 | ||||
| -rw-r--r-- | src/internal/runtime/atomic/xchg8_test.go | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/internal/runtime/atomic/atomic_mipsx.go b/src/internal/runtime/atomic/atomic_mipsx.go index aba4143ea6..bf3578734a 100644 --- a/src/internal/runtime/atomic/atomic_mipsx.go +++ b/src/internal/runtime/atomic/atomic_mipsx.go @@ -136,6 +136,9 @@ func Xadduintptr(ptr *uintptr, delta uintptr) uintptr func Xchg(ptr *uint32, new uint32) uint32 //go:noescape +func Xchg8(ptr *uint8, new uint8) uint8 + +//go:noescape func Xchguintptr(ptr *uintptr, new uintptr) uintptr //go:noescape diff --git a/src/internal/runtime/atomic/atomic_mipsx.s b/src/internal/runtime/atomic/atomic_mipsx.s index 4ccc0a363b..b725016f7b 100644 --- a/src/internal/runtime/atomic/atomic_mipsx.s +++ b/src/internal/runtime/atomic/atomic_mipsx.s @@ -100,6 +100,39 @@ try_xchg: MOVW R1, ret+8(FP) RET +// uint8 Xchg(ptr *uint8, new uint8) +// Atomically: +// old := *ptr; +// *ptr = new; +// return old; +TEXT ·Xchg8(SB), NOSPLIT, $0-9 + MOVW ptr+0(FP), R2 + MOVBU new+4(FP), R5 +#ifdef GOARCH_mips + // Big endian. ptr = ptr ^ 3 + XOR $3, R2 +#endif + // R4 = ((ptr & 3) * 8) + AND $3, R2, R4 + SLL $3, R4 + // Shift val for aligned ptr. R7 = (0xFF << R4) ^ (-1) + MOVW $0xFF, R7 + SLL R4, R7 + XOR $-1, R7 + AND $~3, R2 + SLL R4, R5 + + SYNC + LL (R2), R9 + AND R7, R9, R8 + OR R5, R8 + SC R8, (R2) + BEQ R8, -5(PC) + SYNC + SRL R4, R9 + MOVBU R9, ret+8(FP) + RET + TEXT ·Casint32(SB),NOSPLIT,$0-13 JMP ·Cas(SB) diff --git a/src/internal/runtime/atomic/xchg8_test.go b/src/internal/runtime/atomic/xchg8_test.go index d62f3dc73a..952dfe4aad 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 386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 +//go:build 386 || amd64 || arm || arm64 || loong64 || mips || mipsle || mips64 || mips64le || ppc64 || ppc64le || riscv64 package atomic_test |
