mirror of
https://github.com/golang/go
synced 2024-09-29 01:34:32 -06:00
cmd/compile: optimize 386's math.bits.TrailingZeros16
This CL reverts CL 192097 and fixes the issue in CL 189277. Change-Id: Icd271262e1f5019a8e01c91f91c12c1261eeb02b Reviewed-on: https://go-review.googlesource.com/c/go/+/192519 Run-TryBot: Ben Shi <powerman1st@163.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
ba068c1a6f
commit
8d5197d818
@ -3370,7 +3370,7 @@ func init() {
|
||||
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
|
||||
return s.newValue1(ssa.OpCtz16, types.Types[TINT], args[0])
|
||||
},
|
||||
sys.AMD64, sys.ARM, sys.ARM64, sys.Wasm)
|
||||
sys.AMD64, sys.I386, sys.ARM, sys.ARM64, sys.Wasm)
|
||||
addF("math/bits", "TrailingZeros16",
|
||||
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
|
||||
x := s.newValue1(ssa.OpZeroExt16to64, types.Types[TUINT64], args[0])
|
||||
|
@ -66,6 +66,9 @@
|
||||
|
||||
(Sqrt x) -> (SQRTSD x)
|
||||
|
||||
(Ctz16 x) -> (BSFL (ORLconst <typ.UInt32> [0x10000] x))
|
||||
(Ctz16NonZero x) -> (BSFL x)
|
||||
|
||||
// Lowering extension
|
||||
(SignExt8to16 x) -> (MOVBLSX x)
|
||||
(SignExt8to32 x) -> (MOVBLSX x)
|
||||
|
@ -360,6 +360,10 @@ func rewriteValue386(v *Value) bool {
|
||||
return rewriteValue386_OpConstBool_0(v)
|
||||
case OpConstNil:
|
||||
return rewriteValue386_OpConstNil_0(v)
|
||||
case OpCtz16:
|
||||
return rewriteValue386_OpCtz16_0(v)
|
||||
case OpCtz16NonZero:
|
||||
return rewriteValue386_OpCtz16NonZero_0(v)
|
||||
case OpCvt32Fto32:
|
||||
return rewriteValue386_OpCvt32Fto32_0(v)
|
||||
case OpCvt32Fto64F:
|
||||
@ -20783,6 +20787,33 @@ func rewriteValue386_OpConstNil_0(v *Value) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
func rewriteValue386_OpCtz16_0(v *Value) bool {
|
||||
b := v.Block
|
||||
typ := &b.Func.Config.Types
|
||||
// match: (Ctz16 x)
|
||||
// cond:
|
||||
// result: (BSFL (ORLconst <typ.UInt32> [0x10000] x))
|
||||
for {
|
||||
x := v.Args[0]
|
||||
v.reset(Op386BSFL)
|
||||
v0 := b.NewValue0(v.Pos, Op386ORLconst, typ.UInt32)
|
||||
v0.AuxInt = 0x10000
|
||||
v0.AddArg(x)
|
||||
v.AddArg(v0)
|
||||
return true
|
||||
}
|
||||
}
|
||||
func rewriteValue386_OpCtz16NonZero_0(v *Value) bool {
|
||||
// match: (Ctz16NonZero x)
|
||||
// cond:
|
||||
// result: (BSFL x)
|
||||
for {
|
||||
x := v.Args[0]
|
||||
v.reset(Op386BSFL)
|
||||
v.AddArg(x)
|
||||
return true
|
||||
}
|
||||
}
|
||||
func rewriteValue386_OpCvt32Fto32_0(v *Value) bool {
|
||||
// match: (Cvt32Fto32 x)
|
||||
// cond:
|
||||
|
@ -298,6 +298,7 @@ func TrailingZeros32(n uint32) int {
|
||||
|
||||
func TrailingZeros16(n uint16) int {
|
||||
// amd64:"BSFL","BTSL\\t\\$16"
|
||||
// 386:"BSFL\t"
|
||||
// arm:"ORR\t\\$65536","CLZ",-"MOVHU\tR"
|
||||
// arm64:"ORR\t\\$65536","RBITW","CLZW",-"MOVHU\tR",-"RBIT\t",-"CLZ\t"
|
||||
// s390x:"FLOGR","OR\t\\$65536"
|
||||
|
Loading…
Reference in New Issue
Block a user