Skip to content

Commit

Permalink
cmd/compile: optimize 386's math.bits.TrailingZeros16
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
benshi001 authored and mvdan committed Aug 30, 2019
1 parent ba068c1 commit 8d5197d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/ssa/gen/386.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions src/cmd/compile/internal/ssa/rewrite386.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/codegen/mathbits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8d5197d

Please sign in to comment.