From: Cuong Manh Le Date: Mon, 4 Aug 2025 11:59:17 +0000 (+0700) Subject: cmd/compile: simplify isUintXPowerOfTwo implementation X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=72147ffa7556b2cd694a58ab562cb7e5b5c0514e;p=gostls13.git cmd/compile: simplify isUintXPowerOfTwo implementation 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 Reviewed-by: Dmitri Shuralyov Reviewed-by: Keith Randall Auto-Submit: Cuong Manh Le LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 5edcc86a42..0d000370d5 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -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 {