cmd/compile: move more generic rewrites to the typed version

Change-Id: I22d0644710d12c7efc509fd2a15789e2e073e6a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/227869
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Keith Randall 2020-04-11 10:32:21 -07:00
parent fb16f4b82e
commit 7580937524
3 changed files with 482 additions and 379 deletions

View file

@ -374,6 +374,21 @@ func log2(n int64) int64 {
return int64(bits.Len64(uint64(n))) - 1
}
// logX returns logarithm of n base 2.
// n must be a positive power of 2 (isPowerOfTwoX returns true).
func log8(n int8) int64 {
return int64(bits.Len8(uint8(n))) - 1
}
func log16(n int16) int64 {
return int64(bits.Len16(uint16(n))) - 1
}
func log32(n int32) int64 {
return int64(bits.Len32(uint32(n))) - 1
}
func log64(n int64) int64 {
return int64(bits.Len64(uint64(n))) - 1
}
// log2uint32 returns logarithm in base 2 of uint32(n), with log2(0) = -1.
// Rounds down.
func log2uint32(n int64) int64 {
@ -384,6 +399,18 @@ func log2uint32(n int64) int64 {
func isPowerOfTwo(n int64) bool {
return n > 0 && n&(n-1) == 0
}
func isPowerOfTwo8(n int8) bool {
return n > 0 && n&(n-1) == 0
}
func isPowerOfTwo16(n int16) bool {
return n > 0 && n&(n-1) == 0
}
func isPowerOfTwo32(n int32) bool {
return n > 0 && n&(n-1) == 0
}
func isPowerOfTwo64(n int64) bool {
return n > 0 && n&(n-1) == 0
}
// isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
func isUint64PowerOfTwo(in int64) bool {