]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add math/bits.Mul64 intrinsic on mips64x
authorMeng Zhuo <mengzhuo1203@gmail.com>
Sun, 13 Oct 2019 10:51:49 +0000 (18:51 +0800)
committerCherry Zhang <cherryyz@google.com>
Mon, 14 Oct 2019 21:23:34 +0000 (21:23 +0000)
Benchmark:
name   old time/op  new time/op  delta
Mul    36.0ns ± 1%   2.8ns ± 0%  -92.31%  (p=0.000 n=10+10)
Mul32  4.37ns ± 0%  4.37ns ± 0%     ~     (p=0.429 n=6+10)
Mul64  36.4ns ± 0%   2.8ns ± 0%  -92.37%  (p=0.000 n=10+9)

Change-Id: Ic4f4e5958adbf24999abcee721d0180b5413fca7
Reviewed-on: https://go-review.googlesource.com/c/go/+/200582
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/gen/MIPS64.rules
src/cmd/compile/internal/ssa/rewriteMIPS64.go
test/codegen/mathbits.go

index c833d8eff2cefc32ccb133d7acadd366c787af60..c7805a7419dfbec4a496a9b5a35955c0c5df1ab7 100644 (file)
@@ -3600,8 +3600,8 @@ func init() {
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue2(ssa.OpMul64uhilo, types.NewTuple(types.Types[TUINT64], types.Types[TUINT64]), args[0], args[1])
                },
-               sys.AMD64, sys.ARM64, sys.PPC64, sys.S390X)
-       alias("math/bits", "Mul", "math/bits", "Mul64", sys.ArchAMD64, sys.ArchARM64, sys.ArchPPC64, sys.ArchS390X)
+               sys.AMD64, sys.ARM64, sys.PPC64, sys.S390X, sys.MIPS64)
+       alias("math/bits", "Mul", "math/bits", "Mul64", sys.ArchAMD64, sys.ArchARM64, sys.ArchPPC64, sys.ArchS390X, sys.ArchMIPS64, sys.ArchMIPS64LE)
        addF("math/bits", "Add64",
                func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
                        return s.newValue3(ssa.OpAdd64carry, types.NewTuple(types.Types[TUINT64], types.Types[TUINT64]), args[0], args[1], args[2])
index a39241d160fa00152a131418d98e4d9cbdb9140f..f3d0a08e2899edb35131eda8fbfd166462a201ed 100644 (file)
@@ -10,6 +10,7 @@
 
 (Mul(64|32|16|8) x y) -> (Select1 (MULVU x y))
 (Mul(32|64)F x y) -> (MUL(F|D) x y)
+(Mul64uhilo x y) -> (MULVU x y)
 
 (Hmul64 x y) -> (Select0 (MULV x y))
 (Hmul64u x y) -> (Select0 (MULVU x y))
index c9cc5ce4f9da58782fe80a03a709f55d00c8cc4b..08b1f4384171eeee9f397c252b834e838dac920f 100644 (file)
@@ -415,6 +415,8 @@ func rewriteValueMIPS64(v *Value) bool {
                return rewriteValueMIPS64_OpMul64_0(v)
        case OpMul64F:
                return rewriteValueMIPS64_OpMul64F_0(v)
+       case OpMul64uhilo:
+               return rewriteValueMIPS64_OpMul64uhilo_0(v)
        case OpMul8:
                return rewriteValueMIPS64_OpMul8_0(v)
        case OpNeg16:
@@ -6796,6 +6798,18 @@ func rewriteValueMIPS64_OpMul64F_0(v *Value) bool {
                return true
        }
 }
+func rewriteValueMIPS64_OpMul64uhilo_0(v *Value) bool {
+       // match: (Mul64uhilo x y)
+       // result: (MULVU x y)
+       for {
+               y := v.Args[1]
+               x := v.Args[0]
+               v.reset(OpMIPS64MULVU)
+               v.AddArg(x)
+               v.AddArg(y)
+               return true
+       }
+}
 func rewriteValueMIPS64_OpMul8_0(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
index 5adf7f5fcdf95524ee753f6eabf98f9e4535b0d2..e405d6b1d2e40359cc1544a089ae9692a80318d9 100644 (file)
@@ -558,6 +558,7 @@ func Mul(x, y uint) (hi, lo uint) {
        // ppc64:"MULHDU","MULLD"
        // ppc64le:"MULHDU","MULLD"
        // s390x:"MLGR"
+       // mips64: "MULVU"
        return bits.Mul(x, y)
 }
 
@@ -567,6 +568,7 @@ func Mul64(x, y uint64) (hi, lo uint64) {
        // ppc64:"MULHDU","MULLD"
        // ppc64le:"MULHDU","MULLD"
        // s390x:"MLGR"
+       // mips64: "MULVU"
        return bits.Mul64(x, y)
 }