diff options
| author | Xiaolin Zhao <zhaoxiaolin@loongson.cn> | 2024-04-10 11:48:11 +0800 |
|---|---|---|
| committer | abner chenc <chenguoqi@loongson.cn> | 2024-08-07 01:16:28 +0000 |
| commit | ff14e08cd3c4423ae6c243ef20a3b9b4c04335ed (patch) | |
| tree | c707cbdbf2f3c2b5331e68e7922a6f2a8617d94e /src/math | |
| parent | 36e5c84ffa8b64727b01f056b550c235636c123a (diff) | |
| download | go-ff14e08cd3c4423ae6c243ef20a3b9b4c04335ed.tar.xz | |
cmd/compile, math: improve implementation of math.{Max,Min} on loong64
Make math.{Min,Max} intrinsics and implement math.{archMax,archMin}
in hardware.
goos: linux
goarch: loong64
pkg: math
cpu: Loongson-3A6000 @ 2500.00MHz
│ old.bench │ new.bench │
│ sec/op │ sec/op vs base │
Max 7.606n ± 0% 3.087n ± 0% -59.41% (p=0.000 n=20)
Min 7.205n ± 0% 2.904n ± 0% -59.69% (p=0.000 n=20)
MinFloat 37.220n ± 0% 4.802n ± 0% -87.10% (p=0.000 n=20)
MaxFloat 33.620n ± 0% 4.802n ± 0% -85.72% (p=0.000 n=20)
geomean 16.18n 3.792n -76.57%
goos: linux
goarch: loong64
pkg: runtime
cpu: Loongson-3A5000 @ 2500.00MHz
│ old.bench │ new.bench │
│ sec/op │ sec/op vs base │
Max 10.010n ± 0% 7.196n ± 0% -28.11% (p=0.000 n=20)
Min 8.806n ± 0% 7.155n ± 0% -18.75% (p=0.000 n=20)
MinFloat 60.010n ± 0% 7.976n ± 0% -86.71% (p=0.000 n=20)
MaxFloat 56.410n ± 0% 7.980n ± 0% -85.85% (p=0.000 n=20)
geomean 23.37n 7.566n -67.63%
Updates #59120.
Change-Id: I6815d20bc304af3cbf5d6ca8fe0ca1c2ddebea2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/580283
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/dim_asm.go | 2 | ||||
| -rw-r--r-- | src/math/dim_loong64.s | 77 | ||||
| -rw-r--r-- | src/math/dim_noasm.go | 2 |
3 files changed, 79 insertions, 2 deletions
diff --git a/src/math/dim_asm.go b/src/math/dim_asm.go index f4adbd0ae5..a1d23dd096 100644 --- a/src/math/dim_asm.go +++ b/src/math/dim_asm.go @@ -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 amd64 || arm64 || riscv64 || s390x +//go:build amd64 || arm64 || loong64 || riscv64 || s390x package math diff --git a/src/math/dim_loong64.s b/src/math/dim_loong64.s new file mode 100644 index 0000000000..1484bf7638 --- /dev/null +++ b/src/math/dim_loong64.s @@ -0,0 +1,77 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +#define PosInf 0x7FF0000000000000 +#define NaN 0x7FF8000000000001 +#define NegInf 0xFFF0000000000000 + +TEXT ·archMax(SB),NOSPLIT,$0 + MOVD x+0(FP), F0 + MOVD y+8(FP), F1 + FCLASSD F0, F2 + FCLASSD F1, F3 + + // combine x and y categories together to judge + MOVV F2, R4 + MOVV F3, R5 + OR R5, R4 + + // +Inf special cases + AND $64, R4, R5 + BNE R5, isPosInf + + // NaN special cases + AND $2, R4, R5 + BNE R5, isMaxNaN + + // normal case + FMAXD F0, F1, F0 + MOVD F0, ret+16(FP) + RET + +isMaxNaN: + MOVV $NaN, R6 + MOVV R6, ret+16(FP) + RET + +isPosInf: + MOVV $PosInf, R6 + MOVV R6, ret+16(FP) + RET + +TEXT ·archMin(SB),NOSPLIT,$0 + MOVD x+0(FP), F0 + MOVD y+8(FP), F1 + FCLASSD F0, F2 + FCLASSD F1, F3 + + // combine x and y categories together to judge + MOVV F2, R4 + MOVV F3, R5 + OR R5, R4 + + // -Inf special cases + AND $4, R4, R5 + BNE R5, isNegInf + + // NaN special cases + AND $2, R4, R5 + BNE R5, isMinNaN + + // normal case + FMIND F0, F1, F0 + MOVD F0, ret+16(FP) + RET + +isMinNaN: + MOVV $NaN, R6 + MOVV R6, ret+16(FP) + RET + +isNegInf: + MOVV $NegInf, R6 + MOVV R6, ret+16(FP) + RET diff --git a/src/math/dim_noasm.go b/src/math/dim_noasm.go index 5b9e06fed3..6f4917b8e8 100644 --- a/src/math/dim_noasm.go +++ b/src/math/dim_noasm.go @@ -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 !amd64 && !arm64 && !riscv64 && !s390x +//go:build !amd64 && !arm64 && !loong64 && !riscv64 && !s390x package math |
