Skip to content

Commit 0f19e24

Browse files
committed
cmd/compile: intrinsics for trunc, floor, ceil on ppc64x
This implements trunc, floor, and ceil in the math package as intrinsics on ppc64x. Significant improvement mainly due to avoiding call overhead of args and return value. BenchmarkCeil-16 5.95 0.69 -88.40% BenchmarkFloor-16 5.95 0.69 -88.40% BenchmarkTrunc-16 5.82 0.69 -88.14% Updates #21390 Change-Id: I951e182694f6e0c431da79c577272b81fb0ebad0 Reviewed-on: https://go-review.googlesource.com/54654 Run-TryBot: Lynn Boger <[email protected]> Reviewed-by: Carlos Eduardo Seo <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 3cb41be commit 0f19e24

File tree

7 files changed

+125
-2
lines changed

7 files changed

+125
-2
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,6 +2724,21 @@ func init() {
27242724
return s.newValue1(ssa.OpSqrt, types.Types[TFLOAT64], args[0])
27252725
},
27262726
sys.AMD64, sys.ARM, sys.ARM64, sys.MIPS, sys.PPC64, sys.S390X)
2727+
addF("math", "Trunc",
2728+
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
2729+
return s.newValue1(ssa.OpTrunc, types.Types[TFLOAT64], args[0])
2730+
},
2731+
sys.PPC64)
2732+
addF("math", "Ceil",
2733+
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
2734+
return s.newValue1(ssa.OpCeil, types.Types[TFLOAT64], args[0])
2735+
},
2736+
sys.PPC64)
2737+
addF("math", "Floor",
2738+
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
2739+
return s.newValue1(ssa.OpFloor, types.Types[TFLOAT64], args[0])
2740+
},
2741+
sys.PPC64)
27272742

27282743
/******** math/bits ********/
27292744
addF("math/bits", "TrailingZeros64",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
596596
p.To.Type = obj.TYPE_REG
597597
p.To.Reg = ppc64.REGTMP // Ignored; this is for the carry effect.
598598

599-
case ssa.OpPPC64NEG, ssa.OpPPC64FNEG, ssa.OpPPC64FSQRT, ssa.OpPPC64FSQRTS, ssa.OpPPC64FCTIDZ, ssa.OpPPC64FCTIWZ, ssa.OpPPC64FCFID, ssa.OpPPC64FRSP, ssa.OpPPC64CNTLZD, ssa.OpPPC64CNTLZW, ssa.OpPPC64POPCNTD, ssa.OpPPC64POPCNTW, ssa.OpPPC64POPCNTB:
599+
case ssa.OpPPC64NEG, ssa.OpPPC64FNEG, ssa.OpPPC64FSQRT, ssa.OpPPC64FSQRTS, ssa.OpPPC64FFLOOR, ssa.OpPPC64FTRUNC, ssa.OpPPC64FCEIL, ssa.OpPPC64FCTIDZ, ssa.OpPPC64FCTIWZ, ssa.OpPPC64FCFID, ssa.OpPPC64FRSP, ssa.OpPPC64CNTLZD, ssa.OpPPC64CNTLZW, ssa.OpPPC64POPCNTD, ssa.OpPPC64POPCNTW, ssa.OpPPC64POPCNTB:
600600
r := v.Reg()
601601
p := s.Prog(v.Op.Asm())
602602
p.To.Type = obj.TYPE_REG

src/cmd/compile/internal/ssa/gen/PPC64.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
(Round64F x) -> (LoweredRound64F x)
7575

7676
(Sqrt x) -> (FSQRT x)
77+
(Floor x) -> (FFLOOR x)
78+
(Ceil x) -> (FCEIL x)
79+
(Trunc x) -> (FTRUNC x)
7780

7881
// Lowering constants
7982
(Const8 [val]) -> (MOVDconst [val])

src/cmd/compile/internal/ssa/gen/PPC64Ops.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ func init() {
241241
{name: "FNEG", argLength: 1, reg: fp11, asm: "FNEG"}, // -arg0 (floating point)
242242
{name: "FSQRT", argLength: 1, reg: fp11, asm: "FSQRT"}, // sqrt(arg0) (floating point)
243243
{name: "FSQRTS", argLength: 1, reg: fp11, asm: "FSQRTS"}, // sqrt(arg0) (floating point, single precision)
244+
{name: "FFLOOR", argLength: 1, reg: fp11, asm: "FRIM"}, // floor(arg0), float64
245+
{name: "FCEIL", argLength: 1, reg: fp11, asm: "FRIP"}, // ceil(arg0), float64
246+
{name: "FTRUNC", argLength: 1, reg: fp11, asm: "FRIZ"}, // trunc(arg0), float64
244247

245248
{name: "ORconst", argLength: 1, reg: gp11, asm: "OR", aux: "Int64"}, // arg0|aux
246249
{name: "XORconst", argLength: 1, reg: gp11, asm: "XOR", aux: "Int64"}, // arg0^aux

src/cmd/compile/internal/ssa/gen/genericOps.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ var genericOps = []opData{
255255
{name: "PopCount32", argLength: 1}, // Count bits in arg[0]
256256
{name: "PopCount64", argLength: 1}, // Count bits in arg[0]
257257

258-
{name: "Sqrt", argLength: 1}, // sqrt(arg0), float64 only
258+
{name: "Sqrt", argLength: 1}, // sqrt(arg0), float64 only
259+
{name: "Floor", argLength: 1}, // floor(arg0), float64 only
260+
{name: "Ceil", argLength: 1}, // ceil(arg0), float64 only
261+
{name: "Trunc", argLength: 1}, // trunc(arg0), float64 only
259262

260263
// Data movement, max argument length for Phi is indefinite so just pick
261264
// a really large number

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

Lines changed: 60 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/rewritePPC64.go

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

0 commit comments

Comments
 (0)