From: Josh Bleecher Snyder Date: Mon, 20 Apr 2020 22:40:38 +0000 (-0700) Subject: cmd/compile: use cheaper implementation of oneBit X-Git-Tag: go1.15beta1~477 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=066c47ca5fac1c49f754029f1e61323f74f6d93d;p=gostls13.git cmd/compile: use cheaper implementation of oneBit Updates #38547 file before after Δ % compile 19678112 19669808 -8304 -0.042% total 113143160 113134856 -8304 -0.007% Change-Id: I5f8afe17401dbdb7c7b3d66d95fe40821c499a92 Reviewed-on: https://go-review.googlesource.com/c/go/+/229127 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index ca327c9f0f..9644042fe6 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -395,11 +395,11 @@ func ntz32(x int32) int { return bits.TrailingZeros32(uint32(x)) } func ntz16(x int16) int { return bits.TrailingZeros16(uint16(x)) } func ntz8(x int8) int { return bits.TrailingZeros8(uint8(x)) } -func oneBit(x int64) bool { return bits.OnesCount64(uint64(x)) == 1 } -func oneBit8(x int8) bool { return bits.OnesCount8(uint8(x)) == 1 } -func oneBit16(x int16) bool { return bits.OnesCount16(uint16(x)) == 1 } -func oneBit32(x int32) bool { return bits.OnesCount32(uint32(x)) == 1 } -func oneBit64(x int64) bool { return bits.OnesCount64(uint64(x)) == 1 } +func oneBit(x int64) bool { return x&(x-1) == 0 } +func oneBit8(x int8) bool { return x&(x-1) == 0 } +func oneBit16(x int16) bool { return x&(x-1) == 0 } +func oneBit32(x int32) bool { return x&(x-1) == 0 } +func oneBit64(x int64) bool { return x&(x-1) == 0 } // nlo returns the number of leading ones. func nlo(x int64) int64 {