This API was added for #25819, where it was discussed as math.FMA.
The commit adding it used math.Fma, presumably for consistency
with the rest of the unusual names in package math
(Sincos, Acosh, Erfcinv, Float32bits, etc).
I believe that using an idiomatic Go name is more important here
than consistency with these other names, most of which are historical
baggage from C's standard library.
Early additions like Float32frombits happened before "uppercase for export"
(so they were originally like "float32frombits") and they were not properly
reconsidered when we uppercased the symbols to export them.
That's a mistake we live with.
The names of functions we have added since then, and even a few
that were legacy, are more properly Go-cased, such as IsNaN, IsInf,
and RoundToEven, rather than Isnan, Isinf, and Roundtoeven.
And also constants like MaxFloat32.
For new API, we should keep using proper Go-cased symbols
instead of minimally-upper-cased-C symbols.
So math.FMA, not math.Fma.
This API has not yet been released, so this change does not break
the compatibility promise.
This CL also modifies cmd/compile, since the compiler knows
the name of the function. I could have stopped at changing the
string constants, but it seemed to make more sense to use a
consistent casing everywhere.
Change-Id: I0f6f3407f41e99bfa8239467345c33945088896e
Reviewed-on: https://go-review.googlesource.com/c/go/+/205317
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
return s.newValue2(ssa.OpCopysign, types.Types[TFLOAT64], args[0], args[1])
},
sys.PPC64, sys.Wasm)
- addF("math", "Fma",
+ addF("math", "FMA",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
- return s.newValue3(ssa.OpFma, types.Types[TFLOAT64], args[0], args[1], args[2])
+ return s.newValue3(ssa.OpFMA, types.Types[TFLOAT64], args[0], args[1], args[2])
},
sys.ARM64, sys.PPC64, sys.S390X)
- addF("math", "Fma",
+ addF("math", "FMA",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
if !s.config.UseFMA {
a := s.call(n, callNormal)
// We have the intrinsic - use it directly.
s.startBlock(bTrue)
- s.vars[n] = s.newValue3(ssa.OpFma, types.Types[TFLOAT64], args[0], args[1], args[2])
+ s.vars[n] = s.newValue3(ssa.OpFMA, types.Types[TFLOAT64], args[0], args[1], args[2])
s.endBlock().AddEdgeTo(bEnd)
// Call the pure Go version.
return s.variable(n, types.Types[TFLOAT64])
},
sys.AMD64)
- addF("math", "Fma",
+ addF("math", "FMA",
func(s *state, n *Node, args []*ssa.Value) *ssa.Value {
if !s.config.UseFMA {
a := s.call(n, callNormal)
// We have the intrinsic - use it directly.
s.startBlock(bTrue)
- s.vars[n] = s.newValue3(ssa.OpFma, types.Types[TFLOAT64], args[0], args[1], args[2])
+ s.vars[n] = s.newValue3(ssa.OpFMA, types.Types[TFLOAT64], args[0], args[1], args[2])
s.endBlock().AddEdgeTo(bEnd)
// Call the pure Go version.
(Floor x) -> (ROUNDSD [1] x)
(Ceil x) -> (ROUNDSD [2] x)
(Trunc x) -> (ROUNDSD [3] x)
-(Fma x y z) -> (VFMADD231SD z x y)
+(FMA x y z) -> (VFMADD231SD z x y)
// Lowering extension
// Note: we always extend to 64 bits even though some ops don't need that many result bits.
(Round(32|64)F x) -> x
// fused-multiply-add
-(Fma x y z) -> (FMULAD z x y)
+(FMA x y z) -> (FMULAD z x y)
// comparisons
(Eq8 x y) -> (Equal (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
(Round x) -> (FRINTAD x)
(RoundToEven x) -> (FRINTND x)
(Trunc x) -> (FRINTZD x)
-(Fma x y z) -> (FMADDD z x y)
+(FMA x y z) -> (FMADDD z x y)
// lowering rotates
(RotateLeft8 <t> x (MOVDconst [c])) -> (Or8 (Lsh8x64 <t> x (MOVDconst [c&7])) (Rsh8Ux64 <t> x (MOVDconst [-c&7])))
(Round x) -> (FROUND x)
(Copysign x y) -> (FCPSGN y x)
(Abs x) -> (FABS x)
-(Fma x y z) -> (FMADD x y z)
+(FMA x y z) -> (FMADD x y z)
// Lowering constants
(Const(64|32|16|8) [val]) -> (MOVDconst [val])
// The 2 byte store appears after the 4 byte store so that the
// match for the 2 byte store is not done first.
-// If the 4 byte store is based on the 2 byte store then there are
+// If the 4 byte store is based on the 2 byte store then there are
// variations on the MOVDaddr subrule that would require additional
// rules to be written.
(Trunc x) -> (FIDBR [5] x)
(RoundToEven x) -> (FIDBR [4] x)
(Round x) -> (FIDBR [1] x)
-(Fma x y z) -> (FMADD z x y)
+(FMA x y z) -> (FMADD z x y)
// Atomic loads and stores.
// The SYNC instruction (fast-BCR-serialization) prevents store-load
//
// When the multiply is an infinity times a zero, the result is NaN.
// See section 7.2 in ieee754.
- {name: "Fma", argLength: 3}, // compute (a*b)+c without intermediate rounding
+ {name: "FMA", argLength: 3}, // compute (a*b)+c without intermediate rounding
// Data movement. Max argument length for Phi is indefinite.
{name: "Phi", argLength: -1, zeroWidth: true}, // select an argument based on which predecessor block we came from
OpRoundToEven
OpAbs
OpCopysign
- OpFma
+ OpFMA
OpPhi
OpCopy
OpConvert
generic: true,
},
{
- name: "Fma",
+ name: "FMA",
argLen: 3,
generic: true,
},
return rewriteValueAMD64_OpEqPtr_0(v)
case OpFloor:
return rewriteValueAMD64_OpFloor_0(v)
- case OpFma:
- return rewriteValueAMD64_OpFma_0(v)
+ case OpFMA:
+ return rewriteValueAMD64_OpFMA_0(v)
case OpGeq16:
return rewriteValueAMD64_OpGeq16_0(v)
case OpGeq16U:
return true
}
}
-func rewriteValueAMD64_OpFma_0(v *Value) bool {
- // match: (Fma x y z)
+func rewriteValueAMD64_OpFMA_0(v *Value) bool {
+ // match: (FMA x y z)
// result: (VFMADD231SD z x y)
for {
z := v.Args[2]
return rewriteValueARM_OpEqB_0(v)
case OpEqPtr:
return rewriteValueARM_OpEqPtr_0(v)
- case OpFma:
- return rewriteValueARM_OpFma_0(v)
+ case OpFMA:
+ return rewriteValueARM_OpFMA_0(v)
case OpGeq16:
return rewriteValueARM_OpGeq16_0(v)
case OpGeq16U:
return true
}
}
-func rewriteValueARM_OpFma_0(v *Value) bool {
- // match: (Fma x y z)
+func rewriteValueARM_OpFMA_0(v *Value) bool {
+ // match: (FMA x y z)
// result: (FMULAD z x y)
for {
z := v.Args[2]
return rewriteValueARM64_OpEqPtr_0(v)
case OpFloor:
return rewriteValueARM64_OpFloor_0(v)
- case OpFma:
- return rewriteValueARM64_OpFma_0(v)
+ case OpFMA:
+ return rewriteValueARM64_OpFMA_0(v)
case OpGeq16:
return rewriteValueARM64_OpGeq16_0(v)
case OpGeq16U:
return true
}
}
-func rewriteValueARM64_OpFma_0(v *Value) bool {
- // match: (Fma x y z)
+func rewriteValueARM64_OpFMA_0(v *Value) bool {
+ // match: (FMA x y z)
// result: (FMADDD z x y)
for {
z := v.Args[2]
return rewriteValuePPC64_OpEqPtr_0(v)
case OpFloor:
return rewriteValuePPC64_OpFloor_0(v)
- case OpFma:
- return rewriteValuePPC64_OpFma_0(v)
+ case OpFMA:
+ return rewriteValuePPC64_OpFMA_0(v)
case OpGeq16:
return rewriteValuePPC64_OpGeq16_0(v)
case OpGeq16U:
return true
}
}
-func rewriteValuePPC64_OpFma_0(v *Value) bool {
- // match: (Fma x y z)
+func rewriteValuePPC64_OpFMA_0(v *Value) bool {
+ // match: (FMA x y z)
// result: (FMADD x y z)
for {
z := v.Args[2]
return rewriteValueS390X_OpEqPtr_0(v)
case OpFloor:
return rewriteValueS390X_OpFloor_0(v)
- case OpFma:
- return rewriteValueS390X_OpFma_0(v)
+ case OpFMA:
+ return rewriteValueS390X_OpFMA_0(v)
case OpGeq16:
return rewriteValueS390X_OpGeq16_0(v)
case OpGeq16U:
return true
}
}
-func rewriteValueS390X_OpFma_0(v *Value) bool {
- // match: (Fma x y z)
+func rewriteValueS390X_OpFMA_0(v *Value) bool {
+ // match: (FMA x y z)
// result: (FMADD z x y)
for {
z := v.Args[2]
}
}
-func TestFma(t *testing.T) {
+func TestFMA(t *testing.T) {
for _, c := range fmaC {
- got := Fma(c.x, c.y, c.z)
+ got := FMA(c.x, c.y, c.z)
if !alike(got, c.want) {
- t.Errorf("Fma(%g,%g,%g) == %g; want %g", c.x, c.y, c.z, got, c.want)
+ t.Errorf("FMA(%g,%g,%g) == %g; want %g", c.x, c.y, c.z, got, c.want)
}
}
}
GlobalF = float64(x)
}
-func BenchmarkFma(b *testing.B) {
+func BenchmarkFMA(b *testing.B) {
x := 0.0
for i := 0; i < b.N; i++ {
- x = Fma(E, Pi, x)
+ x = FMA(E, Pi, x)
}
GlobalF = x
}
return
}
-// Fma returns x * y + z, computed with only one rounding.
-func Fma(x, y, z float64) float64 {
+// FMA returns x * y + z, computed with only one rounding.
+// (That is, FMA returns the fused multiply-add of x, y, and z.)
+func FMA(x, y, z float64) float64 {
bx, by, bz := Float64bits(x), Float64bits(y), Float64bits(z)
// Inf or NaN or zero involved. At most one rounding will occur.
// s390x:"FMADD"
// ppc64:"FMADD"
// ppc64le:"FMADD"
- return math.Fma(x, y, z)
+ return math.FMA(x, y, z)
}
func fromFloat64(f64 float64) uint64 {