]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: intrinsify math.Sqrt on mips64
authorAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 21 Feb 2018 16:48:33 +0000 (17:48 +0100)
committerCherry Zhang <cherryyz@google.com>
Wed, 21 Feb 2018 17:34:02 +0000 (17:34 +0000)
Fixes #24006

Change-Id: Ic1438b121fe705f9a6e3ed8340882e9dfd26ecf7
Reviewed-on: https://go-review.googlesource.com/95916
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>

src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/mips64/ssa.go
src/cmd/compile/internal/ssa/gen/MIPS64.rules
src/cmd/compile/internal/ssa/gen/MIPS64Ops.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewriteMIPS64.go

index 542acb6da2a8aef3afb0c2d9fe4e8f3d2ea00f0f..a740e455c90640f5c55a7389c12d07c2a253f65b 100644 (file)
@@ -2913,7 +2913,7 @@ func init() {
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue1(ssa.OpSqrt, types.Types[TFLOAT64], args[0])
                },
-               sys.AMD64, sys.ARM, sys.ARM64, sys.MIPS, sys.PPC64, sys.S390X)
+               sys.AMD64, sys.ARM, sys.ARM64, sys.MIPS, sys.MIPS64, sys.PPC64, sys.S390X)
        addF("math", "Trunc",
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue1(ssa.OpTrunc, types.Types[TFLOAT64], args[0])
index ff2f61280f7f8b0b6bd5a902674b663c0f02d94f..8f35fd039ac5a70160a9aedc9ceeb28fd51e5389 100644 (file)
@@ -354,7 +354,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                ssa.OpMIPS64MOVFD,
                ssa.OpMIPS64MOVDF,
                ssa.OpMIPS64NEGF,
-               ssa.OpMIPS64NEGD:
+               ssa.OpMIPS64NEGD,
+               ssa.OpMIPS64SQRTD:
                p := s.Prog(v.Op.Asm())
                p.From.Type = obj.TYPE_REG
                p.From.Reg = v.Args[0].Reg()
index 1834811770cea0aafe08dc1d8a67fcf959a6124d..4f7a54d09cd5d05590d7bcd0e1e166b4e7a210dc 100644 (file)
 
 (Com(64|32|16|8) x) -> (NOR (MOVVconst [0]) x)
 
+(Sqrt x) -> (SQRTD x)
+
 // boolean ops -- booleans are represented with 0=false, 1=true
 (AndB x y) -> (AND x y)
 (OrB x y) -> (OR x y)
index b13ebb434ef47cec6e1193c3f82079deca66832c..163a88c8fecadd54bc9e8528b6bf7977fbed1896 100644 (file)
@@ -189,9 +189,10 @@ func init() {
                {name: "NOR", argLength: 2, reg: gp21, asm: "NOR", commutative: true},                // ^(arg0 | arg1)
                {name: "NORconst", argLength: 1, reg: gp11, asm: "NOR", aux: "Int64"},                // ^(arg0 | auxInt)
 
-               {name: "NEGV", argLength: 1, reg: gp11},              // -arg0
-               {name: "NEGF", argLength: 1, reg: fp11, asm: "NEGF"}, // -arg0, float32
-               {name: "NEGD", argLength: 1, reg: fp11, asm: "NEGD"}, // -arg0, float64
+               {name: "NEGV", argLength: 1, reg: gp11},                // -arg0
+               {name: "NEGF", argLength: 1, reg: fp11, asm: "NEGF"},   // -arg0, float32
+               {name: "NEGD", argLength: 1, reg: fp11, asm: "NEGD"},   // -arg0, float64
+               {name: "SQRTD", argLength: 1, reg: fp11, asm: "SQRTD"}, // sqrt(arg0), float64
 
                // shifts
                {name: "SLLV", argLength: 2, reg: gp21, asm: "SLLV"},                    // arg0 << arg1, shift amount is mod 64
index 95d50c0672c03ebc994579d6fc8c7213b24a526b..ceb57a86ba8eb0c625ab5da2ace623be202c6a3c 100644 (file)
@@ -1272,6 +1272,7 @@ const (
        OpMIPS64NEGV
        OpMIPS64NEGF
        OpMIPS64NEGD
+       OpMIPS64SQRTD
        OpMIPS64SLLV
        OpMIPS64SLLVconst
        OpMIPS64SRLV
@@ -16320,6 +16321,19 @@ var opcodeTable = [...]opInfo{
                        },
                },
        },
+       {
+               name:   "SQRTD",
+               argLen: 1,
+               asm:    mips.ASQRTD,
+               reg: regInfo{
+                       inputs: []inputInfo{
+                               {0, 1152921504338411520}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31
+                       },
+                       outputs: []outputInfo{
+                               {0, 1152921504338411520}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31
+                       },
+               },
+       },
        {
                name:   "SLLV",
                argLen: 2,
index da76c992dd5eced3331e95731e08569caa5160c7..20a84c03d202607d643b860af6ed15bef45baa84 100644 (file)
@@ -551,6 +551,8 @@ func rewriteValueMIPS64(v *Value) bool {
                return rewriteValueMIPS64_OpSignExt8to64_0(v)
        case OpSlicemask:
                return rewriteValueMIPS64_OpSlicemask_0(v)
+       case OpSqrt:
+               return rewriteValueMIPS64_OpSqrt_0(v)
        case OpStaticCall:
                return rewriteValueMIPS64_OpStaticCall_0(v)
        case OpStore:
@@ -9578,6 +9580,17 @@ func rewriteValueMIPS64_OpSlicemask_0(v *Value) bool {
                return true
        }
 }
+func rewriteValueMIPS64_OpSqrt_0(v *Value) bool {
+       // match: (Sqrt x)
+       // cond:
+       // result: (SQRTD x)
+       for {
+               x := v.Args[0]
+               v.reset(OpMIPS64SQRTD)
+               v.AddArg(x)
+               return true
+       }
+}
 func rewriteValueMIPS64_OpStaticCall_0(v *Value) bool {
        // match: (StaticCall [argwid] {target} mem)
        // cond: