Skip to content

Commit 266b0cf

Browse files
HeliC829gopherbot
authored andcommitted
internal/runtime/atomic: add Xchg8 for mips64x
For #69735 Change-Id: Ide6b3077768a96b76078e5d4f6460596b8ff1560 Reviewed-on: https://go-review.googlesource.com/c/go/+/631756 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]>
1 parent 00635de commit 266b0cf

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/internal/runtime/atomic/atomic_mips64x.go

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func Xadduintptr(ptr *uintptr, delta uintptr) uintptr
2020
//go:noescape
2121
func Xchg(ptr *uint32, new uint32) uint32
2222

23+
//go:noescape
24+
func Xchg8(ptr *uint8, new uint8) uint8
25+
2326
//go:noescape
2427
func Xchg64(ptr *uint64, new uint64) uint64
2528

src/internal/runtime/atomic/atomic_mips64x.s

+33
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,39 @@ TEXT ·Xadd64(SB), NOSPLIT, $0-24
147147
SYNC
148148
RET
149149

150+
// uint8 Xchg(ptr *uint8, new uint8)
151+
// Atomically:
152+
// old := *ptr;
153+
// *ptr = new;
154+
// return old;
155+
TEXT ·Xchg8(SB), NOSPLIT, $0-17
156+
MOVV ptr+0(FP), R2
157+
MOVBU new+8(FP), R5
158+
#ifdef GOARCH_mips64
159+
// Big endian. ptr = ptr ^ 3
160+
XOR $3, R2
161+
#endif
162+
// R4 = ((ptr & 3) * 8)
163+
AND $3, R2, R4
164+
SLLV $3, R4
165+
// Shift val for aligned ptr. R7 = (0xFF << R4) ^ (-1)
166+
MOVV $0xFF, R7
167+
SLLV R4, R7
168+
XOR $-1, R7
169+
AND $~3, R2
170+
SLLV R4, R5
171+
172+
SYNC
173+
LL (R2), R9
174+
AND R7, R9, R8
175+
OR R5, R8
176+
SC R8, (R2)
177+
BEQ R8, -5(PC)
178+
SYNC
179+
SRLV R4, R9
180+
MOVBU R9, ret+16(FP)
181+
RET
182+
150183
// uint32 Xchg(ptr *uint32, new uint32)
151184
// Atomically:
152185
// old := *ptr;

src/internal/runtime/atomic/xchg8_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build 386 || amd64 || arm || arm64 || loong64 || ppc64 || ppc64le || riscv64
5+
//go:build 386 || amd64 || arm || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64
66

77
package atomic_test
88

0 commit comments

Comments
 (0)