1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44:43 -07:00

cmd/compile: intrinsify math.RoundToEven on amd64

We already do this for floor/ceil, but RoundToEven was added later.
Intrinsify it also.

name           old time/op  new time/op  delta
RoundToEven-8  3.00ns ± 1%  0.68ns ± 2%  -77.34%  (p=0.000 n=10+10)

Change-Id: Ib158cbceb436c6725b2d9353a526c5c4be19bcad
Reviewed-on: https://go-review.googlesource.com/74852
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Ilya Tocar 2017-10-31 16:49:27 -05:00
parent 6128ff84f1
commit 2f1f607b21
4 changed files with 23 additions and 5 deletions

View File

@ -855,8 +855,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
case ssa.OpAMD64ROUNDSD: case ssa.OpAMD64ROUNDSD:
p := s.Prog(v.Op.Asm()) p := s.Prog(v.Op.Asm())
val := v.AuxInt val := v.AuxInt
// 1 means math.Floor, 2 Ceil, 3 Trunc // 0 means math.RoundToEven, 1 Floor, 2 Ceil, 3 Trunc
if val != 1 && val != 2 && val != 3 { if val != 0 && val != 1 && val != 2 && val != 3 {
v.Fatalf("Invalid rounding mode") v.Fatalf("Invalid rounding mode")
} }
p.From.Offset = val p.From.Offset = val

View File

@ -2860,6 +2860,9 @@ func init() {
return s.variable(n, types.Types[TFLOAT64]) return s.variable(n, types.Types[TFLOAT64])
} }
} }
addF("math", "RoundToEven",
makeRoundAMD64(ssa.OpRoundToEven),
sys.AMD64)
addF("math", "Floor", addF("math", "Floor",
makeRoundAMD64(ssa.OpFloor), makeRoundAMD64(ssa.OpFloor),
sys.AMD64) sys.AMD64)

View File

@ -113,9 +113,10 @@
(Sqrt x) -> (SQRTSD x) (Sqrt x) -> (SQRTSD x)
(Floor x) -> (ROUNDSD [1] x) (RoundToEven x) -> (ROUNDSD [0] x)
(Ceil x) -> (ROUNDSD [2] x) (Floor x) -> (ROUNDSD [1] x)
(Trunc x) -> (ROUNDSD [3] x) (Ceil x) -> (ROUNDSD [2] x)
(Trunc x) -> (ROUNDSD [3] x)
// Lowering extension // Lowering extension
// Note: we always extend to 64 bits even though some ops don't need that many result bits. // Note: we always extend to 64 bits even though some ops don't need that many result bits.

View File

@ -795,6 +795,8 @@ func rewriteValueAMD64(v *Value) bool {
return rewriteValueAMD64_OpRound32F_0(v) return rewriteValueAMD64_OpRound32F_0(v)
case OpRound64F: case OpRound64F:
return rewriteValueAMD64_OpRound64F_0(v) return rewriteValueAMD64_OpRound64F_0(v)
case OpRoundToEven:
return rewriteValueAMD64_OpRoundToEven_0(v)
case OpRsh16Ux16: case OpRsh16Ux16:
return rewriteValueAMD64_OpRsh16Ux16_0(v) return rewriteValueAMD64_OpRsh16Ux16_0(v)
case OpRsh16Ux32: case OpRsh16Ux32:
@ -45652,6 +45654,18 @@ func rewriteValueAMD64_OpRound64F_0(v *Value) bool {
return true return true
} }
} }
func rewriteValueAMD64_OpRoundToEven_0(v *Value) bool {
// match: (RoundToEven x)
// cond:
// result: (ROUNDSD [0] x)
for {
x := v.Args[0]
v.reset(OpAMD64ROUNDSD)
v.AuxInt = 0
v.AddArg(x)
return true
}
}
func rewriteValueAMD64_OpRsh16Ux16_0(v *Value) bool { func rewriteValueAMD64_OpRsh16Ux16_0(v *Value) bool {
b := v.Block b := v.Block
_ = b _ = b