Skip to content

Commit e705a2d

Browse files
sophie-zhaoabner-chenc
authored andcommitted
cmd/compile, math: make math.{Abs,Copysign} intrinsics on loong64
goos: linux goarch: loong64 pkg: math cpu: Loongson-3A6000 @ 2500.00MHz │ old.bench │ new.bench │ │ sec/op │ sec/op vs base │ Copysign 1.9710n ± 0% 0.8006n ± 0% -59.38% (p=0.000 n=10) Abs 1.8745n ± 0% 0.8006n ± 0% -57.29% (p=0.000 n=10) geomean 1.922n 0.8006n -58.35% goos: linux goarch: loong64 pkg: math cpu: Loongson-3A5000 @ 2500.00MHz │ old.bench │ new.bench │ │ sec/op │ sec/op vs base │ Copysign 2.4020n ± 0% 0.9006n ± 0% -62.51% (p=0.000 n=10) Abs 2.4020n ± 0% 0.8005n ± 0% -66.67% (p=0.000 n=10) geomean 2.402n 0.8491n -64.65% Updates #59120. Change-Id: Ic409e1f4d15ad15cb3568a5aaa100046e9302842 Reviewed-on: https://go-review.googlesource.com/c/go/+/580280 Reviewed-by: Qiqi Huang <[email protected]> Reviewed-by: Meidan Li <[email protected]> Reviewed-by: abner chenc <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent ff14e08 commit e705a2d

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

src/cmd/compile/internal/loong64/ssa.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
177177
ssa.OpLOONG64DIVF,
178178
ssa.OpLOONG64DIVD,
179179
ssa.OpLOONG64MULV, ssa.OpLOONG64MULHV, ssa.OpLOONG64MULHVU,
180-
ssa.OpLOONG64DIVV, ssa.OpLOONG64REMV, ssa.OpLOONG64DIVVU, ssa.OpLOONG64REMVU:
180+
ssa.OpLOONG64DIVV, ssa.OpLOONG64REMV, ssa.OpLOONG64DIVVU, ssa.OpLOONG64REMVU,
181+
ssa.OpLOONG64FCOPYSGD:
181182
p := s.Prog(v.Op.Asm())
182183
p.From.Type = obj.TYPE_REG
183184
p.From.Reg = v.Args[1].Reg()
@@ -420,7 +421,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
420421
ssa.OpLOONG64NEGF,
421422
ssa.OpLOONG64NEGD,
422423
ssa.OpLOONG64SQRTD,
423-
ssa.OpLOONG64SQRTF:
424+
ssa.OpLOONG64SQRTF,
425+
ssa.OpLOONG64ABSD:
424426
p := s.Prog(v.Op.Asm())
425427
p.From.Type = obj.TYPE_REG
426428
p.From.Reg = v.Args[0].Reg()

src/cmd/compile/internal/ssa/_gen/LOONG64.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@
129129

130130
(Com(64|32|16|8) x) => (NOR (MOVVconst [0]) x)
131131

132+
// math package intrinsics
132133
(Sqrt ...) => (SQRTD ...)
133134
(Sqrt32 ...) => (SQRTF ...)
135+
(Abs ...) => (ABSD ...)
136+
(Copysign ...) => (FCOPYSGD ...)
134137

135138
(Min(64|32)F ...) => (FMIN(D|F) ...)
136139
(Max(64|32)F ...) => (FMAX(D|F) ...)

src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ func init() {
201201
{name: "MASKEQZ", argLength: 2, reg: gp21, asm: "MASKEQZ"}, // returns 0 if arg1 == 0, otherwise returns arg0
202202
{name: "MASKNEZ", argLength: 2, reg: gp21, asm: "MASKNEZ"}, // returns 0 if arg1 != 0, otherwise returns arg0
203203

204+
{name: "ABSD", argLength: 1, reg: fp11, asm: "ABSD"}, // abs(arg0), float64
205+
{name: "FCOPYSGD", argLength: 2, reg: fp21, asm: "FCOPYSGD"}, // float64
206+
204207
// shifts
205208
{name: "SLLV", argLength: 2, reg: gp21, asm: "SLLV"}, // arg0 << arg1, shift amount is mod 64
206209
{name: "SLLVconst", argLength: 1, reg: gp11, asm: "SLLV", aux: "Int64"}, // arg0 << auxInt

src/cmd/compile/internal/ssa/opGen.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssa/rewriteLOONG64.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/compile/internal/ssagen/ssa.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4721,12 +4721,12 @@ func InitTables() {
47214721
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
47224722
return s.newValue1(ssa.OpAbs, types.Types[types.TFLOAT64], args[0])
47234723
},
4724-
sys.ARM64, sys.ARM, sys.PPC64, sys.RISCV64, sys.Wasm, sys.MIPS, sys.MIPS64)
4724+
sys.ARM64, sys.ARM, sys.Loong64, sys.PPC64, sys.RISCV64, sys.Wasm, sys.MIPS, sys.MIPS64)
47254725
addF("math", "Copysign",
47264726
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
47274727
return s.newValue2(ssa.OpCopysign, types.Types[types.TFLOAT64], args[0], args[1])
47284728
},
4729-
sys.PPC64, sys.RISCV64, sys.Wasm)
4729+
sys.Loong64, sys.PPC64, sys.RISCV64, sys.Wasm)
47304730
addF("math", "FMA",
47314731
func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
47324732
return s.newValue3(ssa.OpFMA, types.Types[types.TFLOAT64], args[0], args[1], args[2])

0 commit comments

Comments
 (0)