Skip to content

Commit 26da119

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: make isUint{32,64}PowerOfTwo implementations clearer
Since these functions cast the input to uint64, so the result always non-negative. The condition should be changed to comparing with zero, thus maaking it clearer to reader, and open room for simplifying in the future by using the generic isUnsignedPowerOfTwo function. Separated this change, so it's easier to do bisecting if there's any problems happened. Change-Id: Ibec28c2590f4c52caa36384b710d526459725e49 Reviewed-on: https://go-review.googlesource.com/c/go/+/692915 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 5ab9f23 commit 26da119

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,13 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool {
507507
// isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
508508
func isUint64PowerOfTwo(in int64) bool {
509509
n := uint64(in)
510-
return n > 0 && n&(n-1) == 0
510+
return n != 0 && n&(n-1) == 0
511511
}
512512

513513
// isUint32PowerOfTwo reports whether uint32(n) is a power of 2.
514514
func isUint32PowerOfTwo(in int64) bool {
515515
n := uint64(uint32(in))
516-
return n > 0 && n&(n-1) == 0
516+
return n != 0 && n&(n-1) == 0
517517
}
518518

519519
// is32Bit reports whether n can be represented as a signed 32 bit integer.

0 commit comments

Comments
 (0)