]> Cypherpunks repositories - gostls13.git/commit
math: optimize Signbit implementation slightly
authorMichael Munday <mike.munday@lowrisc.org>
Fri, 12 Jul 2024 21:00:01 +0000 (22:00 +0100)
committerGopher Robot <gobot@golang.org>
Mon, 25 Aug 2025 19:35:20 +0000 (12:35 -0700)
commit1eed4f32a06ac1083120663a8451cb9cfeb7b496
treed84e909590b3d8e129a3ae9746ca1865d2cd9468
parentbd71b9465948ec523c26dd2d9fea888bd83a2e6c
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>
src/math/signbit.go