]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make math/bits.RotateLeft{32,64} intrinsics on ppc64x
authorCarlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Fri, 22 Feb 2019 19:12:37 +0000 (16:12 -0300)
committerCarlos Eduardo Seo <cseo@linux.vnet.ibm.com>
Thu, 14 Mar 2019 14:13:34 +0000 (14:13 +0000)
Extends CL 132435 to ppc64x. ppc64x has 32- and 64-bit variable
rotate left instructions.

name             old time/op  new time/op  delta
RotateLeft32-16  1.39ns ± 0%  1.37ns ± 0%  -1.44%  (p=0.008 n=5+5)
RotateLeft64-16  1.35ns ± 0%  1.32ns ± 0%  -2.22%  (p=0.008 n=5+5)

Updates #17566

Change-Id: I567f634ff90d0691db45df0a25c99fcdfe10ca00
Reviewed-on: https://go-review.googlesource.com/c/go/+/163760
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/gen/PPC64.rules
src/cmd/compile/internal/ssa/rewritePPC64.go

index ecc449114d83eae2d629b12c9226314562ca7d6a..d61f463ccfdba1eac0cef1fab1c19a3660626b4c 100644 (file)
@@ -3427,12 +3427,12 @@ func init() {
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue2(ssa.OpRotateLeft32, types.Types[TUINT32], args[0], args[1])
                },
-               sys.AMD64, sys.ARM64, sys.S390X)
+               sys.AMD64, sys.ARM64, sys.S390X, sys.PPC64)
        addF("math/bits", "RotateLeft64",
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue2(ssa.OpRotateLeft64, types.Types[TUINT64], args[0], args[1])
                },
-               sys.AMD64, sys.ARM64, sys.S390X)
+               sys.AMD64, sys.ARM64, sys.S390X, sys.PPC64)
        alias("math/bits", "RotateLeft", "math/bits", "RotateLeft64", p8...)
 
        makeOnesCountAMD64 := func(op64 ssa.Op, op32 ssa.Op) func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
index e5d5295908aabe7e2d69bfed2f2ef427655e49dd..8dee5a1cbad2ea6d12f3096e1622646843405c29 100644 (file)
 ( OR (SLW x (ANDconst <typ.Int32> [31] y)) (SRW x (SUB <typ.UInt> (MOVDconst [32]) (ANDconst <typ.UInt> [31] y)))) -> (ROTLW x y)
 (XOR (SLW x (ANDconst <typ.Int32> [31] y)) (SRW x (SUB <typ.UInt> (MOVDconst [32]) (ANDconst <typ.UInt> [31] y)))) -> (ROTLW x y)
 
+// Lowering rotates
+(RotateLeft32 x y) -> (ROTLW x y)
+(RotateLeft64 x y) -> (ROTL x y)
+
+// Constant rotate generation
+(ROTLW  x (MOVDconst [c])) -> (ROTLWconst  x [c&31])
+(ROTL   x (MOVDconst [c])) -> (ROTLconst   x [c&63])
+
 (Lsh64x64  x (Const64 [c])) && uint64(c) < 64 -> (SLDconst x [c])
 (Rsh64x64  x (Const64 [c])) && uint64(c) < 64 -> (SRADconst x [c])
 (Rsh64Ux64 x (Const64 [c])) && uint64(c) < 64 -> (SRDconst x [c])
index 302b785f6195df8277fc57495b14246d60e8735f..9245f403b879a2d28599f9deab84a12772005014 100644 (file)
@@ -537,6 +537,10 @@ func rewriteValuePPC64(v *Value) bool {
                return rewriteValuePPC64_OpPPC64ORN_0(v)
        case OpPPC64ORconst:
                return rewriteValuePPC64_OpPPC64ORconst_0(v)
+       case OpPPC64ROTL:
+               return rewriteValuePPC64_OpPPC64ROTL_0(v)
+       case OpPPC64ROTLW:
+               return rewriteValuePPC64_OpPPC64ROTLW_0(v)
        case OpPPC64SUB:
                return rewriteValuePPC64_OpPPC64SUB_0(v)
        case OpPPC64XOR:
@@ -551,6 +555,10 @@ func rewriteValuePPC64(v *Value) bool {
                return rewriteValuePPC64_OpPopCount64_0(v)
        case OpPopCount8:
                return rewriteValuePPC64_OpPopCount8_0(v)
+       case OpRotateLeft32:
+               return rewriteValuePPC64_OpRotateLeft32_0(v)
+       case OpRotateLeft64:
+               return rewriteValuePPC64_OpRotateLeft64_0(v)
        case OpRound:
                return rewriteValuePPC64_OpRound_0(v)
        case OpRound32F:
@@ -25533,6 +25541,44 @@ func rewriteValuePPC64_OpPPC64ORconst_0(v *Value) bool {
        }
        return false
 }
+func rewriteValuePPC64_OpPPC64ROTL_0(v *Value) bool {
+       // match: (ROTL x (MOVDconst [c]))
+       // cond:
+       // result: (ROTLconst x [c&63])
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpPPC64MOVDconst {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpPPC64ROTLconst)
+               v.AuxInt = c & 63
+               v.AddArg(x)
+               return true
+       }
+       return false
+}
+func rewriteValuePPC64_OpPPC64ROTLW_0(v *Value) bool {
+       // match: (ROTLW x (MOVDconst [c]))
+       // cond:
+       // result: (ROTLWconst x [c&31])
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpPPC64MOVDconst {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpPPC64ROTLWconst)
+               v.AuxInt = c & 31
+               v.AddArg(x)
+               return true
+       }
+       return false
+}
 func rewriteValuePPC64_OpPPC64SUB_0(v *Value) bool {
        // match: (SUB x (MOVDconst [c]))
        // cond: is32Bit(-c)
@@ -26086,6 +26132,34 @@ func rewriteValuePPC64_OpPopCount8_0(v *Value) bool {
                return true
        }
 }
+func rewriteValuePPC64_OpRotateLeft32_0(v *Value) bool {
+       // match: (RotateLeft32 x y)
+       // cond:
+       // result: (ROTLW x y)
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               y := v.Args[1]
+               v.reset(OpPPC64ROTLW)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
+}
+func rewriteValuePPC64_OpRotateLeft64_0(v *Value) bool {
+       // match: (RotateLeft64 x y)
+       // cond:
+       // result: (ROTL x y)
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               y := v.Args[1]
+               v.reset(OpPPC64ROTL)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
+}
 func rewriteValuePPC64_OpRound_0(v *Value) bool {
        // match: (Round x)
        // cond: