cmd/compile: intrinsify Sub64 on mips64

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>
This commit is contained in:
Junxian Zhu 2023-05-26 13:33:45 +08:00 committed by Joel Sing
parent 5f8a2fdf09
commit b1474672c6
4 changed files with 49 additions and 1 deletions

View File

@ -42,6 +42,10 @@
(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 ...)

View 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 {

View 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 {

View 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)
}