]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: make math/bits.RotateLeft{32,64} intrinsics on s390x
authorMichael Munday <mike.munday@ibm.com>
Mon, 3 Sep 2018 14:47:58 +0000 (10:47 -0400)
committerMichael Munday <mike.munday@ibm.com>
Wed, 5 Sep 2018 08:29:02 +0000 (08:29 +0000)
Extends CL 132435 to s390x. s390x has 32- and 64-bit variable
rotate left instructions.

Change-Id: Ic4f1ebb0e0543207ed2fc8c119e0163b428138a5
Reviewed-on: https://go-review.googlesource.com/133035
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/s390x/ssa.go
src/cmd/compile/internal/ssa/gen/S390X.rules
src/cmd/compile/internal/ssa/gen/S390XOps.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewriteS390X.go
test/codegen/mathbits.go

index 3aef7e6b6d92725ffe428927fe70599ef993f2ed..00ff7d4bd56bcd912e9179baec81687e8ec4d4a5 100644 (file)
@@ -3361,12 +3361,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.AMD64, sys.S390X)
        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.AMD64, sys.S390X)
        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 90e61c34fd35cda8c7b9337bddf54ed387609b8f..be48e1b23efe5ff553d14412b0371cda14593cb8 100644 (file)
@@ -160,7 +160,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        switch v.Op {
        case ssa.OpS390XSLD, ssa.OpS390XSLW,
                ssa.OpS390XSRD, ssa.OpS390XSRW,
-               ssa.OpS390XSRAD, ssa.OpS390XSRAW:
+               ssa.OpS390XSRAD, ssa.OpS390XSRAW,
+               ssa.OpS390XRLLG, ssa.OpS390XRLL:
                r := v.Reg()
                r1 := v.Args[0].Reg()
                r2 := v.Args[1].Reg()
index 4fbdef38e7d108e2fcaa9e9b1d088cb644c4a55c..47766fa77dd850671af0b79cd233e48b88e21220 100644 (file)
 (Rsh(16|8)x16 x y) -> (SRAW (MOV(H|B)reg x) (MOVDGE <y.Type> y (MOVDconst <y.Type> [63]) (CMPWUconst (MOVHZreg y) [64])))
 (Rsh(16|8)x8  x y) -> (SRAW (MOV(H|B)reg x) (MOVDGE <y.Type> y (MOVDconst <y.Type> [63]) (CMPWUconst (MOVBZreg y) [64])))
 
+// Lowering rotates
+(RotateLeft32 x y) -> (RLL  x y)
+(RotateLeft64 x y) -> (RLLG x y)
+
 // Lowering comparisons
 (Less64      x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
 (Less32      x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
 (SRW  x (MOV(D|W|H|B|WZ|HZ|BZ)reg y)) -> (SRW  x y)
 (SRAW x (MOV(D|W|H|B|WZ|HZ|BZ)reg y)) -> (SRAW x y)
 
-// Rotate generation
+// Constant rotate generation
+(RLL  x (MOVDconst [c])) -> (RLLconst  x [c&31])
+(RLLG x (MOVDconst [c])) -> (RLLGconst x [c&63])
+
 (ADD (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x)
 ( OR (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x)
 (XOR (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x)
index 9b5f525531a6e600cf67dae232242f652bf46f0f..19cb4be41c067c96469902e378c494efdb8be610 100644 (file)
@@ -321,6 +321,8 @@ func init() {
                {name: "SRADconst", argLength: 1, reg: gp11, asm: "SRAD", aux: "Int8", clobberFlags: true}, // signed arg0 >> auxint, shift amount 0-63
                {name: "SRAWconst", argLength: 1, reg: gp11, asm: "SRAW", aux: "Int8", clobberFlags: true}, // signed int32(arg0) >> auxint, shift amount 0-31
 
+               {name: "RLLG", argLength: 2, reg: sh21, asm: "RLLG"},                   // arg0 rotate left arg1, rotate amount 0-63
+               {name: "RLL", argLength: 2, reg: sh21, asm: "RLL"},                     // arg0 rotate left arg1, rotate amount 0-31
                {name: "RLLGconst", argLength: 1, reg: gp11, asm: "RLLG", aux: "Int8"}, // arg0 rotate left auxint, rotate amount 0-63
                {name: "RLLconst", argLength: 1, reg: gp11, asm: "RLL", aux: "Int8"},   // arg0 rotate left auxint, rotate amount 0-31
 
index 0ff15db91484214f7b7d5fb4286b6803b6a1c575..5bf7021432699773a101bdd7a72b1580e0367e4c 100644 (file)
@@ -1794,6 +1794,8 @@ const (
        OpS390XSRAW
        OpS390XSRADconst
        OpS390XSRAWconst
+       OpS390XRLLG
+       OpS390XRLL
        OpS390XRLLGconst
        OpS390XRLLconst
        OpS390XNEG
@@ -23989,6 +23991,34 @@ var opcodeTable = [...]opInfo{
                        },
                },
        },
+       {
+               name:   "RLLG",
+               argLen: 2,
+               asm:    s390x.ARLLG,
+               reg: regInfo{
+                       inputs: []inputInfo{
+                               {1, 23550}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                               {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                       },
+                       outputs: []outputInfo{
+                               {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                       },
+               },
+       },
+       {
+               name:   "RLL",
+               argLen: 2,
+               asm:    s390x.ARLL,
+               reg: regInfo{
+                       inputs: []inputInfo{
+                               {1, 23550}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                               {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                       },
+                       outputs: []outputInfo{
+                               {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14
+                       },
+               },
+       },
        {
                name:    "RLLGconst",
                auxType: auxInt8,
index 768b802ec1f22c6c2aa31121e95676f77422001c..95c9a0d0fc78ea79b74f49e3a32b50176a73d025 100644 (file)
@@ -391,6 +391,10 @@ func rewriteValueS390X(v *Value) bool {
                return rewriteValueS390X_OpPopCount64_0(v)
        case OpPopCount8:
                return rewriteValueS390X_OpPopCount8_0(v)
+       case OpRotateLeft32:
+               return rewriteValueS390X_OpRotateLeft32_0(v)
+       case OpRotateLeft64:
+               return rewriteValueS390X_OpRotateLeft64_0(v)
        case OpRound:
                return rewriteValueS390X_OpRound_0(v)
        case OpRound32F:
@@ -665,6 +669,10 @@ func rewriteValueS390X(v *Value) bool {
                return rewriteValueS390X_OpS390XORconst_0(v)
        case OpS390XORload:
                return rewriteValueS390X_OpS390XORload_0(v)
+       case OpS390XRLL:
+               return rewriteValueS390X_OpS390XRLL_0(v)
+       case OpS390XRLLG:
+               return rewriteValueS390X_OpS390XRLLG_0(v)
        case OpS390XSLD:
                return rewriteValueS390X_OpS390XSLD_0(v) || rewriteValueS390X_OpS390XSLD_10(v)
        case OpS390XSLW:
@@ -5399,6 +5407,34 @@ func rewriteValueS390X_OpPopCount8_0(v *Value) bool {
                return true
        }
 }
+func rewriteValueS390X_OpRotateLeft32_0(v *Value) bool {
+       // match: (RotateLeft32 x y)
+       // cond:
+       // result: (RLL x y)
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               y := v.Args[1]
+               v.reset(OpS390XRLL)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
+}
+func rewriteValueS390X_OpRotateLeft64_0(v *Value) bool {
+       // match: (RotateLeft64 x y)
+       // cond:
+       // result: (RLLG x y)
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               y := v.Args[1]
+               v.reset(OpS390XRLLG)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
+}
 func rewriteValueS390X_OpRound_0(v *Value) bool {
        // match: (Round x)
        // cond:
@@ -38644,6 +38680,44 @@ func rewriteValueS390X_OpS390XORload_0(v *Value) bool {
        }
        return false
 }
+func rewriteValueS390X_OpS390XRLL_0(v *Value) bool {
+       // match: (RLL x (MOVDconst [c]))
+       // cond:
+       // result: (RLLconst x [c&31])
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpS390XMOVDconst {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpS390XRLLconst)
+               v.AuxInt = c & 31
+               v.AddArg(x)
+               return true
+       }
+       return false
+}
+func rewriteValueS390X_OpS390XRLLG_0(v *Value) bool {
+       // match: (RLLG x (MOVDconst [c]))
+       // cond:
+       // result: (RLLGconst x [c&63])
+       for {
+               _ = v.Args[1]
+               x := v.Args[0]
+               v_1 := v.Args[1]
+               if v_1.Op != OpS390XMOVDconst {
+                       break
+               }
+               c := v_1.AuxInt
+               v.reset(OpS390XRLLGconst)
+               v.AuxInt = c & 63
+               v.AddArg(x)
+               return true
+       }
+       return false
+}
 func rewriteValueS390X_OpS390XSLD_0(v *Value) bool {
        b := v.Block
        _ = b
index ad2c5abb029f6272c2c53e45c4a607c4c3505742..b8844c518f1a0cf655d0eb9497b084faec62fc2d 100644 (file)
@@ -171,6 +171,7 @@ func RotateLeft64(n uint64) uint64 {
        // amd64:"ROLQ"
        // arm64:"ROR"
        // ppc64:"ROTL"
+       // s390x:"RLLG"
        return bits.RotateLeft64(n, 37)
 }
 
@@ -178,6 +179,7 @@ func RotateLeft32(n uint32) uint32 {
        // amd64:"ROLL" 386:"ROLL"
        // arm64:"RORW"
        // ppc64:"ROTLW"
+       // s390x:"RLL"
        return bits.RotateLeft32(n, 9)
 }
 
@@ -191,6 +193,27 @@ func RotateLeft8(n uint8) uint8 {
        return bits.RotateLeft8(n, 5)
 }
 
+func RotateLeftVariable(n uint, m int) uint {
+       // amd64:"ROLQ"
+       // ppc64:"ROTL"
+       // s390x:"RLLG"
+       return bits.RotateLeft(n, m)
+}
+
+func RotateLeftVariable64(n uint64, m int) uint64 {
+       // amd64:"ROLQ"
+       // ppc64:"ROTL"
+       // s390x:"RLLG"
+       return bits.RotateLeft64(n, m)
+}
+
+func RotateLeftVariable32(n uint32, m int) uint32 {
+       // amd64:"ROLL"
+       // ppc64:"ROTLW"
+       // s390x:"RLL"
+       return bits.RotateLeft32(n, m)
+}
+
 // ------------------------ //
 //    bits.TrailingZeros    //
 // ------------------------ //