Skip to content

Commit 72147ff

Browse files
cuonglmgopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 26da119 commit 72147ff

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,10 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool {
505505
}
506506

507507
// isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
508-
func isUint64PowerOfTwo(in int64) bool {
509-
n := uint64(in)
510-
return n != 0 && n&(n-1) == 0
511-
}
508+
func isUint64PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint64(in)) }
512509

513510
// isUint32PowerOfTwo reports whether uint32(n) is a power of 2.
514-
func isUint32PowerOfTwo(in int64) bool {
515-
n := uint64(uint32(in))
516-
return n != 0 && n&(n-1) == 0
517-
}
511+
func isUint32PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint32(in)) }
518512

519513
// is32Bit reports whether n can be represented as a signed 32 bit integer.
520514
func is32Bit(n int64) bool {

0 commit comments

Comments
 (0)