1
0
mirror of https://github.com/golang/go synced 2024-11-17 03:04:44 -07:00

runtime/internal/atomic: add s390x operators for And/Or

These primitives will be used by the new And/Or sync/atomic apis.

For #61395

Change-Id: Ia9b4877048002d3d7d1dffa2311d0ec5f38e4ee5
GitHub-Last-Rev: 20dea110c8
GitHub-Pull-Request: golang/go#63318
Reviewed-on: https://go-review.googlesource.com/c/go/+/531678
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Mauri de Souza Meneguzzo <mauri870@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Mauri de Souza Meneguzzo 2024-02-17 10:30:01 +00:00 committed by Keith Randall
parent 2908352980
commit 1a8ee033f8
3 changed files with 75 additions and 1 deletions

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 arm || s390x || mips || mipsle || mips64 || mips64le || wasm
//go:build arm || mips || mipsle || mips64 || mips64le || wasm
package atomic

View File

@ -98,6 +98,24 @@ func And(ptr *uint32, val uint32)
//go:noescape
func Or(ptr *uint32, val uint32)
//go:noescape
func And32(ptr *uint32, val uint32) uint32
//go:noescape
func Or32(ptr *uint32, val uint32) uint32
//go:noescape
func And64(ptr *uint64, val uint64) uint64
//go:noescape
func Or64(ptr *uint64, val uint64) uint64
//go:noescape
func Anduintptr(ptr *uintptr, val uintptr) uintptr
//go:noescape
func Oruintptr(ptr *uintptr, val uintptr) uintptr
//go:noescape
func Xadd(ptr *uint32, delta int32) uint32

View File

@ -246,3 +246,59 @@ TEXT ·And(SB), NOSPLIT, $0-12
MOVW val+8(FP), R4
LAN R4, R6, 0(R3) // R6 = *R3; *R3 &= R4; (atomic)
RET
// func Or32(addr *uint32, v uint32) old uint32
TEXT ·Or32(SB), NOSPLIT, $0-20
MOVD ptr+0(FP), R4
MOVW val+8(FP), R5
MOVW (R4), R3
repeat:
OR R5, R3, R6
CS R3, R6, (R4) // if R3==(R4) then (R4)=R6 else R3=(R4)
BNE repeat
MOVW R3, ret+16(FP)
RET
// func And32(addr *uint32, v uint32) old uint32
TEXT ·And32(SB), NOSPLIT, $0-20
MOVD ptr+0(FP), R4
MOVW val+8(FP), R5
MOVW (R4), R3
repeat:
AND R5, R3, R6
CS R3, R6, (R4) // if R3==(R4) then (R4)=R6 else R3=(R4)
BNE repeat
MOVW R3, ret+16(FP)
RET
// func Or64(addr *uint64, v uint64) old uint64
TEXT ·Or64(SB), NOSPLIT, $0-24
MOVD ptr+0(FP), R4
MOVD val+8(FP), R5
MOVD (R4), R3
repeat:
OR R5, R3, R6
CSG R3, R6, (R4) // if R3==(R4) then (R4)=R6 else R3=(R4)
BNE repeat
MOVD R3, ret+16(FP)
RET
// func And64(addr *uint64, v uint64) old uint64
TEXT ·And64(SB), NOSPLIT, $0-24
MOVD ptr+0(FP), R4
MOVD val+8(FP), R5
MOVD (R4), R3
repeat:
AND R5, R3, R6
CSG R3, R6, (R4) // if R3==(R4) then (R4)=R6 else R3=(R4)
BNE repeat
MOVD R3, ret+16(FP)
RET
// func Anduintptr(addr *uintptr, v uintptr) old uintptr
TEXT ·Anduintptr(SB), NOSPLIT, $0-24
BR ·And64(SB)
// func Oruintptr(addr *uintptr, v uintptr) old uintptr
TEXT ·Oruintptr(SB), NOSPLIT, $0-24
BR ·Or64(SB)