diff options
| author | Guoqi Chen <chenguoqi@loongson.cn> | 2023-04-01 08:49:58 +0800 |
|---|---|---|
| committer | abner chenc <chenguoqi@loongson.cn> | 2024-11-11 00:07:51 +0000 |
| commit | 72a92ab5b72680e6e0f8acffcfd62b2c6fd98085 (patch) | |
| tree | a69c32bb0bba9caea79db2fc94aa15d50ba8062c /src/internal/runtime/atomic | |
| parent | 5123f38e050c5ee7130d459ea247d998a838b5a1 (diff) | |
| download | go-72a92ab5b72680e6e0f8acffcfd62b2c6fd98085.tar.xz | |
cmd/compiler,internal/runtime/atomic: optimize xchg{32,64} on loong64
Use Loong64's atomic operation instruction AMSWAPDB{W,V} (full barrier)
to implement atomic.Xchg{32,64}
goos: linux
goarch: loong64
pkg: internal/runtime/atomic
cpu: Loongson-3A5000 @ 2500.00MHz
| old.bench | new.bench |
| sec/op | sec/op vs base |
Xchg 26.44n ± 0% 12.01n ± 0% -54.58% (p=0.000 n=20)
Xchg-2 30.10n ± 0% 25.58n ± 0% -15.02% (p=0.000 n=20)
Xchg-4 30.06n ± 0% 24.82n ± 0% -17.43% (p=0.000 n=20)
Xchg64 26.44n ± 0% 12.02n ± 0% -54.54% (p=0.000 n=20)
Xchg64-2 30.10n ± 0% 25.57n ± 0% -15.05% (p=0.000 n=20)
Xchg64-4 30.05n ± 0% 24.80n ± 0% -17.47% (p=0.000 n=20)
geomean 28.81n 19.68n -31.69%
goos: linux
goarch: loong64
pkg: internal/runtime/atomic
cpu: Loongson-3A6000 @ 2500.00MHz
| old.bench | new.bench |
| sec/op | sec/op vs base |
Xchg 25.62n ± 0% 12.41n ± 0% -51.56% (p=0.000 n=20)
Xchg-2 35.01n ± 0% 20.59n ± 0% -41.19% (p=0.000 n=20)
Xchg-4 34.63n ± 0% 19.59n ± 0% -43.42% (p=0.000 n=20)
Xchg64 25.62n ± 0% 12.41n ± 0% -51.56% (p=0.000 n=20)
Xchg64-2 35.01n ± 0% 20.59n ± 0% -41.19% (p=0.000 n=20)
Xchg64-4 34.67n ± 0% 19.59n ± 0% -43.50% (p=0.000 n=20)
geomean 31.44n 17.11n -45.59%
Updates #59120.
Change-Id: Ied74fc20338b63799c6d6eeb122c31b42cff0f7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/481578
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: WANG Xuerui <git@xen0n.name>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
Diffstat (limited to 'src/internal/runtime/atomic')
| -rw-r--r-- | src/internal/runtime/atomic/atomic_loong64.s | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/internal/runtime/atomic/atomic_loong64.s b/src/internal/runtime/atomic/atomic_loong64.s index 07d0f584b1..6ea162d9da 100644 --- a/src/internal/runtime/atomic/atomic_loong64.s +++ b/src/internal/runtime/atomic/atomic_loong64.s @@ -116,35 +116,33 @@ TEXT ·Xadd64(SB), NOSPLIT, $0-24 MOVV R4, ret+16(FP) RET +// func Xchg(ptr *uint32, new uint32) uint32 TEXT ·Xchg(SB), NOSPLIT, $0-20 MOVV ptr+0(FP), R4 MOVW new+8(FP), R5 - - DBAR - MOVV R5, R6 - LL (R4), R7 - SC R6, (R4) - BEQ R6, -3(PC) - MOVW R7, ret+16(FP) - DBAR + AMSWAPDBW R5, (R4), R6 + MOVW R6, ret+16(FP) RET +// func Xchg64(ptr *uint64, new uint64) uint64 TEXT ·Xchg64(SB), NOSPLIT, $0-24 MOVV ptr+0(FP), R4 MOVV new+8(FP), R5 - - DBAR - MOVV R5, R6 - LLV (R4), R7 - SCV R6, (R4) - BEQ R6, -3(PC) - MOVV R7, ret+16(FP) - DBAR + AMSWAPDBV R5, (R4), R6 + MOVV R6, ret+16(FP) RET TEXT ·Xchguintptr(SB), NOSPLIT, $0-24 JMP ·Xchg64(SB) +// func Xchgint32(ptr *int32, new int32) int32 +TEXT ·Xchgint32(SB), NOSPLIT, $0-20 + JMP ·Xchg(SB) + +// func Xchgint64(ptr *int64, new int64) int64 +TEXT ·Xchgint64(SB), NOSPLIT, $0-24 + JMP ·Xchg64(SB) + TEXT ·StorepNoWB(SB), NOSPLIT, $0-16 JMP ·Store64(SB) |
