Skip to content

Commit

Permalink
runtime/internal/atomic: add loong64 operators for And/Or
Browse files Browse the repository at this point in the history
These primitives will be used by the new And/Or sync/atomic apis.

For #61395

Change-Id: I64b2e599e4f91412e0342aa01f5fd53271e9a333
GitHub-Last-Rev: 9755db5
GitHub-Pull-Request: #63314
Reviewed-on: https://go-review.googlesource.com/c/go/+/531895
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
  • Loading branch information
mauri870 authored and randall77 committed Feb 5, 2024
1 parent e8d8772 commit 76ff0ca
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runtime/internal/atomic/atomic_andor_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 || loong64 || mips || mipsle || mips64 || mips64le || wasm
//go:build arm || s390x || mips || mipsle || mips64 || mips64le || wasm

package atomic

Expand Down
18 changes: 18 additions & 0 deletions src/runtime/internal/atomic/atomic_loong64.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ func Or8(ptr *uint8, val uint8)
//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

// NOTE: Do not add atomicxor8 (XOR is not idempotent).

//go:noescape
Expand Down
60 changes: 60 additions & 0 deletions src/runtime/internal/atomic/atomic_loong64.s
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,66 @@ TEXT ·And(SB), NOSPLIT, $0-12
DBAR
RET

// func Or32(addr *uint32, v uint32) old uint32
TEXT ·Or32(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R4
MOVW val+8(FP), R5
DBAR
LL (R4), R6
OR R5, R6, R7
SC R7, (R4)
BEQ R7, -4(PC)
DBAR
MOVW R6, ret+16(FP)
RET

// func And32(addr *uint32, v uint32) old uint32
TEXT ·And32(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R4
MOVW val+8(FP), R5
DBAR
LL (R4), R6
AND R5, R6, R7
SC R7, (R4)
BEQ R7, -4(PC)
DBAR
MOVW R6, ret+16(FP)
RET

// func Or64(addr *uint64, v uint64) old uint64
TEXT ·Or64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R4
MOVV val+8(FP), R5
DBAR
LLV (R4), R6
OR R5, R6, R7
SCV R7, (R4)
BEQ R7, -4(PC)
DBAR
MOVV R6, ret+16(FP)
RET

// func And64(addr *uint64, v uint64) old uint64
TEXT ·And64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R4
MOVV val+8(FP), R5
DBAR
LLV (R4), R6
AND R5, R6, R7
SCV R7, (R4)
BEQ R7, -4(PC)
DBAR
MOVV R6, ret+16(FP)
RET

// func Anduintptr(addr *uintptr, v uintptr) old uintptr
TEXT ·Anduintptr(SB), NOSPLIT, $0-24
JMP ·And64(SB)

// func Oruintptr(addr *uintptr, v uintptr) old uintptr
TEXT ·Oruintptr(SB), NOSPLIT, $0-24
JMP ·Or64(SB)

// uint32 runtime∕internal∕atomic·Load(uint32 volatile* ptr)
TEXT ·Load(SB),NOSPLIT|NOFRAME,$0-12
MOVV ptr+0(FP), R19
Expand Down

0 comments on commit 76ff0ca

Please sign in to comment.