Skip to content

Commit

Permalink
cmd/compile: coalesce a few shift rules for wasm
Browse files Browse the repository at this point in the history
Change-Id: I1b76daba90afd474390db8d9c238445abaac7ca6
Reviewed-on: https://go-review.googlesource.com/c/go/+/182557
Run-TryBot: Agniva De Sarker <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Richard Musiol <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
agnivade committed Aug 28, 2019
1 parent 3d48ae3 commit b9ef4c0
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions src/cmd/compile/internal/ssa/gen/Wasm.rules
Original file line number Diff line number Diff line change
Expand Up @@ -103,67 +103,43 @@
// Unsigned shifts need to return 0 if shift amount is >= width of shifted value.

(Lsh64x64 x y) -> (Select (I64Shl x y) (I64Const [0]) (I64LtU y (I64Const [64])))
(Lsh64x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y))
(Lsh64x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y))
(Lsh64x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y))
(Lsh64x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y))

(Lsh32x64 x y) -> (Lsh64x64 x y)
(Lsh32x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y))
(Lsh32x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y))
(Lsh32x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y))
(Lsh32x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y))

(Lsh16x64 x y) -> (Lsh64x64 x y)
(Lsh16x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y))
(Lsh16x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y))
(Lsh16x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y))
(Lsh16x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y))

(Lsh8x64 x y) -> (Lsh64x64 x y)
(Lsh8x32 x y) -> (Lsh64x64 x (ZeroExt32to64 y))
(Lsh8x16 x y) -> (Lsh64x64 x (ZeroExt16to64 y))
(Lsh8x8 x y) -> (Lsh64x64 x (ZeroExt8to64 y))
(Lsh8x(32|16|8) x y) -> (Lsh64x64 x (ZeroExt(32|16|8)to64 y))

(Rsh64Ux64 x y) -> (Select (I64ShrU x y) (I64Const [0]) (I64LtU y (I64Const [64])))
(Rsh64Ux32 x y) -> (Rsh64Ux64 x (ZeroExt32to64 y))
(Rsh64Ux16 x y) -> (Rsh64Ux64 x (ZeroExt16to64 y))
(Rsh64Ux8 x y) -> (Rsh64Ux64 x (ZeroExt8to64 y))
(Rsh64Ux(32|16|8) x y) -> (Rsh64Ux64 x (ZeroExt(32|16|8)to64 y))

(Rsh32Ux64 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) y)
(Rsh32Ux32 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt32to64 y))
(Rsh32Ux16 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt16to64 y))
(Rsh32Ux8 x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt8to64 y))
(Rsh32Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt32to64 x) (ZeroExt(32|16|8)to64 y))

(Rsh16Ux64 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) y)
(Rsh16Ux32 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt32to64 y))
(Rsh16Ux16 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt16to64 y))
(Rsh16Ux8 x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt8to64 y))
(Rsh16Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt16to64 x) (ZeroExt(32|16|8)to64 y))

(Rsh8Ux64 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) y)
(Rsh8Ux32 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt32to64 y))
(Rsh8Ux16 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt16to64 y))
(Rsh8Ux8 x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt8to64 y))
(Rsh8Ux(32|16|8) x y) -> (Rsh64Ux64 (ZeroExt8to64 x) (ZeroExt(32|16|8)to64 y))

// Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value.
// We implement this by setting the shift value to (width - 1) if the shift value is >= width.

(Rsh64x64 x y) -> (I64ShrS x (Select <typ.Int64> y (I64Const [63]) (I64LtU y (I64Const [64]))))
(Rsh64x32 x y) -> (Rsh64x64 x (ZeroExt32to64 y))
(Rsh64x16 x y) -> (Rsh64x64 x (ZeroExt16to64 y))
(Rsh64x8 x y) -> (Rsh64x64 x (ZeroExt8to64 y))
(Rsh64x(32|16|8) x y) -> (Rsh64x64 x (ZeroExt(32|16|8)to64 y))

(Rsh32x64 x y) -> (Rsh64x64 (SignExt32to64 x) y)
(Rsh32x32 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt32to64 y))
(Rsh32x16 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt16to64 y))
(Rsh32x8 x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt8to64 y))
(Rsh32x(32|16|8) x y) -> (Rsh64x64 (SignExt32to64 x) (ZeroExt(32|16|8)to64 y))

(Rsh16x64 x y) -> (Rsh64x64 (SignExt16to64 x) y)
(Rsh16x32 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt32to64 y))
(Rsh16x16 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt16to64 y))
(Rsh16x8 x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt8to64 y))
(Rsh16x(32|16|8) x y) -> (Rsh64x64 (SignExt16to64 x) (ZeroExt(32|16|8)to64 y))

(Rsh8x64 x y) -> (Rsh64x64 (SignExt8to64 x) y)
(Rsh8x32 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt32to64 y))
(Rsh8x16 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt16to64 y))
(Rsh8x8 x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt8to64 y))
(Rsh8x(32|16|8) x y) -> (Rsh64x64 (SignExt8to64 x) (ZeroExt(32|16|8)to64 y))

// Lowering rotates
(RotateLeft8 <t> x (I64Const [c])) -> (Or8 (Lsh8x64 <t> x (I64Const [c&7])) (Rsh8Ux64 <t> x (I64Const [-c&7])))
Expand Down

0 comments on commit b9ef4c0

Please sign in to comment.