mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
math: optimize Signbit implementation slightly
This small tweak to Signbit improves code generation on riscv64 and
possibly other architectures by removing the need to apply a 64 bit
mask.
Before:
MOV $-9223372036854775808, X6
AND X6, X5, X5
SNEZ X5, X10
After:
SLTI $0, X5, X10
This transformation could also be added to the optimization rules
but it is quite a special case.
goos: linux
goarch: riscv64
pkg: math
cpu: Spacemit(R) X60
│ sec/op │ sec/op vs base │
Signbit 13.05n ± 0% 11.42n ± 0% -12.49% (p=0.000 n=10)
Change-Id: Ic218017c5bbb720ec24c6fe7cc230df539b2630c
Reviewed-on: https://go-review.googlesource.com/c/go/+/698419
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
parent
bd71b94659
commit
1eed4f32a0
1 changed files with 1 additions and 1 deletions
|
|
@ -6,5 +6,5 @@ package math
|
||||||
|
|
||||||
// Signbit reports whether x is negative or negative zero.
|
// Signbit reports whether x is negative or negative zero.
|
||||||
func Signbit(x float64) bool {
|
func Signbit(x float64) bool {
|
||||||
return Float64bits(x)&(1<<63) != 0
|
return int64(Float64bits(x)) < 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue