Skip to content

Commit 880ca33

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: removing log2uint32 function
Just using isUnsignedPowerOfTwo and log32u is enough. Change-Id: I93d49ab71c6245d05f6507adbcb9ef2a696e75d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/691476 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 1513661 commit 880ca33

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/cmd/compile/internal/ssa/_gen/MIPS.rules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@
607607
(Select0 (MULTU (MOVWconst [1]) _ )) => (MOVWconst [0])
608608
(Select1 (MULTU (MOVWconst [-1]) x )) => (NEG <x.Type> x)
609609
(Select0 (MULTU (MOVWconst [-1]) x )) => (CMOVZ (ADDconst <x.Type> [-1] x) (MOVWconst [0]) x)
610-
(Select1 (MULTU (MOVWconst [c]) x )) && isPowerOfTwo(int64(uint32(c))) => (SLLconst [int32(log2uint32(int64(c)))] x)
611-
(Select0 (MULTU (MOVWconst [c]) x )) && isPowerOfTwo(int64(uint32(c))) => (SRLconst [int32(32-log2uint32(int64(c)))] x)
610+
(Select1 (MULTU (MOVWconst [c]) x )) && isUnsignedPowerOfTwo(uint32(c)) => (SLLconst [int32(log32u(uint32(c)))] x)
611+
(Select0 (MULTU (MOVWconst [c]) x )) && isUnsignedPowerOfTwo(uint32(c)) => (SRLconst [int32(32-log32u(uint32(c)))] x)
612612

613613
(MUL (MOVWconst [0]) _ ) => (MOVWconst [0])
614614
(MUL (MOVWconst [1]) x ) => x
615615
(MUL (MOVWconst [-1]) x ) => (NEG x)
616-
(MUL (MOVWconst [c]) x ) && isPowerOfTwo(int64(uint32(c))) => (SLLconst [int32(log2uint32(int64(c)))] x)
616+
(MUL (MOVWconst [c]) x ) && isUnsignedPowerOfTwo(uint32(c)) => (SLLconst [int32(log32u(uint32(c)))] x)
617617

618618
// generic simplifications
619619
(ADD x (NEG y)) => (SUB x y)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,6 @@ func log16u(n uint16) int64 { return int64(bits.Len16(n)) - 1 }
492492
func log32u(n uint32) int64 { return int64(bits.Len32(n)) - 1 }
493493
func log64u(n uint64) int64 { return int64(bits.Len64(n)) - 1 }
494494

495-
// log2uint32 returns logarithm in base 2 of uint32(n), with log2(0) = -1.
496-
// Rounds down.
497-
func log2uint32(n int64) int64 {
498-
return int64(bits.Len32(uint32(n))) - 1
499-
}
500-
501495
// isPowerOfTwoX functions report whether n is a power of 2.
502496
func isPowerOfTwo[T int8 | int16 | int32 | int64](n T) bool {
503497
return n > 0 && n&(n-1) == 0

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

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)