]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify isUintXPowerOfTwo implementation
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 4 Aug 2025 11:59:17 +0000 (18:59 +0700)
committerGopher Robot <gobot@golang.org>
Tue, 5 Aug 2025 15:34:05 +0000 (08:34 -0700)
By calling isUnsignedPowerOfTwo instead of duplicating the same ones.

Change-Id: I1e29d3b7eda1bc8773fcd25728d8f508ae633ac9
Reviewed-on: https://go-review.googlesource.com/c/go/+/692916
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/ssa/rewrite.go

index 5edcc86a4265d04c582f49649b2506670e7fedfa..0d000370d53d9003080ebd9e439dc34411ebe2f0 100644 (file)
@@ -505,16 +505,10 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool {
 }
 
 // isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
-func isUint64PowerOfTwo(in int64) bool {
-       n := uint64(in)
-       return n != 0 && n&(n-1) == 0
-}
+func isUint64PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint64(in)) }
 
 // isUint32PowerOfTwo reports whether uint32(n) is a power of 2.
-func isUint32PowerOfTwo(in int64) bool {
-       n := uint64(uint32(in))
-       return n != 0 && n&(n-1) == 0
-}
+func isUint32PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint32(in)) }
 
 // is32Bit reports whether n can be represented as a signed 32 bit integer.
 func is32Bit(n int64) bool {