aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/runtime/atomic/atomic_loong64.go1
-rw-r--r--src/internal/runtime/atomic/atomic_loong64.s50
2 files changed, 43 insertions, 8 deletions
diff --git a/src/internal/runtime/atomic/atomic_loong64.go b/src/internal/runtime/atomic/atomic_loong64.go
index a362628323..6586ad2f6c 100644
--- a/src/internal/runtime/atomic/atomic_loong64.go
+++ b/src/internal/runtime/atomic/atomic_loong64.go
@@ -12,6 +12,7 @@ import (
)
const (
+ offsetLOONG64HasLAMCAS = unsafe.Offsetof(cpu.Loong64.HasLAMCAS)
offsetLoong64HasLAM_BH = unsafe.Offsetof(cpu.Loong64.HasLAM_BH)
)
diff --git a/src/internal/runtime/atomic/atomic_loong64.s b/src/internal/runtime/atomic/atomic_loong64.s
index 60741a23c2..d67300afc4 100644
--- a/src/internal/runtime/atomic/atomic_loong64.s
+++ b/src/internal/runtime/atomic/atomic_loong64.s
@@ -16,18 +16,32 @@ TEXT ·Cas(SB), NOSPLIT, $0-17
MOVV ptr+0(FP), R4
MOVW old+8(FP), R5
MOVW new+12(FP), R6
- DBAR
+
+ MOVBU internal∕cpu·Loong64+const_offsetLOONG64HasLAMCAS(SB), R8
+ BEQ R8, cas_again
+ MOVV R5, R7 // backup old value
+ AMCASDBW R6, (R4), R5
+ BNE R7, R5, cas_fail0
+ MOVV $1, R4
+ MOVB R4, ret+16(FP)
+ RET
+cas_fail0:
+ MOVB R0, ret+16(FP)
+ RET
+
+ // Implemented using the ll-sc instruction pair
+ DBAR $0x14 // LoadAcquire barrier
cas_again:
MOVV R6, R7
LL (R4), R8
- BNE R5, R8, cas_fail
+ BNE R5, R8, cas_fail1
SC R7, (R4)
BEQ R7, cas_again
MOVV $1, R4
MOVB R4, ret+16(FP)
- DBAR
+ DBAR $0x12 // StoreRelease barrier
RET
-cas_fail:
+cas_fail1:
MOVV $0, R4
JMP -4(PC)
@@ -43,21 +57,41 @@ TEXT ·Cas64(SB), NOSPLIT, $0-25
MOVV ptr+0(FP), R4
MOVV old+8(FP), R5
MOVV new+16(FP), R6
- DBAR
+
+ MOVBU internal∕cpu·Loong64+const_offsetLOONG64HasLAMCAS(SB), R8
+ BEQ R8, cas64_again
+ MOVV R5, R7 // backup old value
+ AMCASDBV R6, (R4), R5
+ BNE R7, R5, cas64_fail0
+ MOVV $1, R4
+ MOVB R4, ret+24(FP)
+ RET
+cas64_fail0:
+ MOVB R0, ret+24(FP)
+ RET
+
+ // Implemented using the ll-sc instruction pair
+ DBAR $0x14
cas64_again:
MOVV R6, R7
LLV (R4), R8
- BNE R5, R8, cas64_fail
+ BNE R5, R8, cas64_fail1
SCV R7, (R4)
BEQ R7, cas64_again
MOVV $1, R4
MOVB R4, ret+24(FP)
- DBAR
+ DBAR $0x12
RET
-cas64_fail:
+cas64_fail1:
MOVV $0, R4
JMP -4(PC)
+TEXT ·Casint32(SB),NOSPLIT,$0-17
+ JMP ·Cas(SB)
+
+TEXT ·Casint64(SB),NOSPLIT,$0-25
+ JMP ·Cas64(SB)
+
TEXT ·Casuintptr(SB), NOSPLIT, $0-25
JMP ·Cas64(SB)