]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: intrinsify Sub64 on mips64
authorJunxian Zhu <zhujunxian@oss.cipunited.com>
Fri, 26 May 2023 05:33:45 +0000 (13:33 +0800)
committerJoel Sing <joel@sing.id.au>
Mon, 31 Jul 2023 03:59:48 +0000 (03:59 +0000)
This CL intrinsify Sub64 on mips64.

pkg: math/bits
                  _   sec/op    _   sec/op     vs base               _
Sub-4               2.849n _ 0%   1.948n _ 0%  -31.64% (p=0.000 n=8)
Sub32-4             3.447n _ 0%   3.446n _ 0%        ~ (p=0.982 n=8)
Sub64-4             2.815n _ 0%   1.948n _ 0%  -30.78% (p=0.000 n=8)
Sub64multiple-4     6.124n _ 0%   3.340n _ 0%  -45.46% (p=0.000 n=8)

Change-Id: Ibba91a4350e4a549ae0b60d8cafc4bca05034b84
Reviewed-on: https://go-review.googlesource.com/c/go/+/498497
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
src/cmd/compile/internal/ssa/_gen/MIPS64.rules
src/cmd/compile/internal/ssa/rewriteMIPS64.go
src/cmd/compile/internal/ssagen/ssa.go
test/codegen/mathbits.go

index 5c07abc79b36e348fff8b91a439e686a453ee5ca..cabc7c652dff6ce4d8157ce10c25f947c5261802 100644 (file)
 (Select1 <t> (Add64carry x y c)) =>
        (OR (SGTU <t> x s:(ADDV <t> x y)) (SGTU <t> s (ADDV <t> s c)))
 
+(Select0 <t> (Sub64borrow x y c)) => (SUBV (SUBV <t> x y) c)
+(Select1 <t> (Sub64borrow x y c)) =>
+       (OR (SGTU <t> s:(SUBV <t> x y) x) (SGTU <t> (SUBV <t> s c) s))
+
 // math package intrinsics
 (Abs ...) => (ABSD ...)
 
index 4e7b51b351422887d48978fc23480f682330f42e..764465d0b726044c422919baefaf529c9339f7fb 100644 (file)
@@ -7353,6 +7353,22 @@ func rewriteValueMIPS64_OpSelect0(v *Value) bool {
                v.AddArg2(v0, c)
                return true
        }
+       // match: (Select0 <t> (Sub64borrow x y c))
+       // result: (SUBV (SUBV <t> x y) c)
+       for {
+               t := v.Type
+               if v_0.Op != OpSub64borrow {
+                       break
+               }
+               c := v_0.Args[2]
+               x := v_0.Args[0]
+               y := v_0.Args[1]
+               v.reset(OpMIPS64SUBV)
+               v0 := b.NewValue0(v.Pos, OpMIPS64SUBV, t)
+               v0.AddArg2(x, y)
+               v.AddArg2(v0, c)
+               return true
+       }
        // match: (Select0 (DIVVU _ (MOVVconst [1])))
        // result: (MOVVconst [0])
        for {
@@ -7487,6 +7503,28 @@ func rewriteValueMIPS64_OpSelect1(v *Value) bool {
                v.AddArg2(v0, v2)
                return true
        }
+       // match: (Select1 <t> (Sub64borrow x y c))
+       // result: (OR (SGTU <t> s:(SUBV <t> x y) x) (SGTU <t> (SUBV <t> s c) s))
+       for {
+               t := v.Type
+               if v_0.Op != OpSub64borrow {
+                       break
+               }
+               c := v_0.Args[2]
+               x := v_0.Args[0]
+               y := v_0.Args[1]
+               v.reset(OpMIPS64OR)
+               v0 := b.NewValue0(v.Pos, OpMIPS64SGTU, t)
+               s := b.NewValue0(v.Pos, OpMIPS64SUBV, t)
+               s.AddArg2(x, y)
+               v0.AddArg2(s, x)
+               v2 := b.NewValue0(v.Pos, OpMIPS64SGTU, t)
+               v3 := b.NewValue0(v.Pos, OpMIPS64SUBV, t)
+               v3.AddArg2(s, c)
+               v2.AddArg2(v3, s)
+               v.AddArg2(v0, v2)
+               return true
+       }
        // match: (Select1 (MULVU x (MOVVconst [-1])))
        // result: (NEGV x)
        for {
index 09b20b726e90dff62c918e8db5ead83cde18e5e5..03f9958098249aaff36b6dd871331c24e3e6aaeb 100644 (file)
@@ -4849,7 +4849,7 @@ func InitTables() {
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
                        return s.newValue3(ssa.OpSub64borrow, types.NewTuple(types.Types[types.TUINT64], types.Types[types.TUINT64]), args[0], args[1], args[2])
                },
-               sys.AMD64, sys.ARM64, sys.PPC64, sys.S390X, sys.RISCV64, sys.Loong64)
+               sys.AMD64, sys.ARM64, sys.PPC64, sys.S390X, sys.RISCV64, sys.Loong64, sys.MIPS64)
        alias("math/bits", "Sub", "math/bits", "Sub64", p8...)
        addF("math/bits", "Div64",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
index 85c7d24f7de7121d785cd9b45f37323ea309a241..797aa23b678733284e8c05576109966262211e6a 100644 (file)
@@ -636,6 +636,7 @@ func Sub(x, y, ci uint) (r, co uint) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", "SUBE", "SUBZE", "NEG"
        // s390x:"SUBE"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub(x, y, ci)
 }
@@ -646,6 +647,7 @@ func SubC(x, ci uint) (r, co uint) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", "SUBE", "SUBZE", "NEG"
        // s390x:"SUBE"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub(x, 7, ci)
 }
@@ -656,6 +658,7 @@ func SubZ(x, y uint) (r, co uint) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", -"SUBE", "SUBZE", "NEG"
        // s390x:"SUBC"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub(x, y, 0)
 }
@@ -687,6 +690,7 @@ func Sub64(x, y, ci uint64) (r, co uint64) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", "SUBE", "SUBZE", "NEG"
        // s390x:"SUBE"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub64(x, y, ci)
 }
@@ -697,6 +701,7 @@ func Sub64C(x, ci uint64) (r, co uint64) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", "SUBE", "SUBZE", "NEG"
        // s390x:"SUBE"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub64(x, 7, ci)
 }
@@ -707,6 +712,7 @@ func Sub64Z(x, y uint64) (r, co uint64) {
        // loong64:"SUBV","SGTU"
        // ppc64x:"SUBC", -"SUBE", "SUBZE", "NEG"
        // s390x:"SUBC"
+       // mips64:"SUBV","SGTU"
        // riscv64: "SUB","SLTU"
        return bits.Sub64(x, y, 0)
 }