]> Cypherpunks repositories - gostls13.git/commitdiff
math, cmd/compile: rename Fma to FMA
authorRuss Cox <rsc@golang.org>
Tue, 5 Nov 2019 00:43:45 +0000 (19:43 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 7 Nov 2019 14:51:06 +0000 (14:51 +0000)
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>
16 files changed:
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/gen/ARM.rules
src/cmd/compile/internal/ssa/gen/ARM64.rules
src/cmd/compile/internal/ssa/gen/PPC64.rules
src/cmd/compile/internal/ssa/gen/S390X.rules
src/cmd/compile/internal/ssa/gen/genericOps.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewriteAMD64.go
src/cmd/compile/internal/ssa/rewriteARM.go
src/cmd/compile/internal/ssa/rewriteARM64.go
src/cmd/compile/internal/ssa/rewritePPC64.go
src/cmd/compile/internal/ssa/rewriteS390X.go
src/math/all_test.go
src/math/fma.go
test/codegen/math.go

index f76b6d4c021dbb98a79b173fce6aded203f6d57f..6b5a6a3bdf27c2e0f95c8dd5d1bc5b4d1f0d39ae 100644 (file)
@@ -3561,12 +3561,12 @@ func init() {
                        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)
@@ -3587,7 +3587,7 @@ func init() {
 
                        // 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.
@@ -3601,7 +3601,7 @@ func init() {
                        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)
@@ -3622,7 +3622,7 @@ func init() {
 
                        // 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.
index 65f229169a78b41d20386df440d006ee87121ec4..2d662d5ae681d0eed704853bd615ecb709a02fbd 100644 (file)
 (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.
index c1c73e23ec2f5fa55126efb99cdfbf522306ac81..160545e02b802c8e6866e5ec9fede5e44ddb2258 100644 (file)
 (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)))
index f0033a052698a14c1fa37b3bd9c0ea7ef90fda58..a9bf64488e1860aca59ab2b109cedf5e574a0e03 100644 (file)
@@ -90,7 +90,7 @@
 (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])))
index 13fe1ab2e917b1d0e8ecf2a0097a5f99c64ed70a..fc370741176b23bf0557947f7e2904ddf5a69f8a 100644 (file)
@@ -68,7 +68,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.
 
index 2c56c66581444139dd000debb41cf849ec72aa72..3635aeb91547cf6a23bb0b4891dc48a2f98d9e71 100644 (file)
 (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
index 1ffca8118fe3e014c7102a4b9ac737a2a4ae4ddf..aa9d5703963aeb0ecb56bb4acde022a3dd95807d 100644 (file)
@@ -314,7 +314,7 @@ var genericOps = []opData{
        //
        // 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
index e9a709467ec1ecb54929231b0d912fbf1587cfbf..f4370bc38d124a1ca3a9027adcb8d24e7629222f 100644 (file)
@@ -2428,7 +2428,7 @@ const (
        OpRoundToEven
        OpAbs
        OpCopysign
-       OpFma
+       OpFMA
        OpPhi
        OpCopy
        OpConvert
@@ -30743,7 +30743,7 @@ var opcodeTable = [...]opInfo{
                generic: true,
        },
        {
-               name:    "Fma",
+               name:    "FMA",
                argLen:  3,
                generic: true,
        },
index 4f02554e1a62187924673d83b7c80c99178c99cc..4945d1974e9594ceda5a9b4b3ca48cb5b273f36d 100644 (file)
@@ -770,8 +770,8 @@ func rewriteValueAMD64(v *Value) bool {
                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:
@@ -52222,8 +52222,8 @@ func rewriteValueAMD64_OpFloor_0(v *Value) bool {
                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]
index 8cb534d8f622225c2ad63025d9f9f5478eb0a47d..fb7a7570f2d5d04c0e467558298046eddb4a8578 100644 (file)
@@ -538,8 +538,8 @@ func rewriteValueARM(v *Value) bool {
                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:
@@ -17161,8 +17161,8 @@ func rewriteValueARM_OpEqPtr_0(v *Value) bool {
                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]
index e9bde5ec8a27ee94afd7f78cf9f3e9b4427c08d6..c372865d0aa3bfe60d1da85a2fbad8dfe546705c 100644 (file)
@@ -573,8 +573,8 @@ func rewriteValueARM64(v *Value) bool {
                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:
@@ -28583,8 +28583,8 @@ func rewriteValueARM64_OpFloor_0(v *Value) bool {
                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]
index a95364ece495cb6020bc1396687fa105702d4ebf..4d282a6730bd5b8003bbae1bf9aea84c448d87f7 100644 (file)
@@ -183,8 +183,8 @@ func rewriteValuePPC64(v *Value) bool {
                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:
@@ -2007,8 +2007,8 @@ func rewriteValuePPC64_OpFloor_0(v *Value) bool {
                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]
index 645e8f2d9afa4c775e3c5a80ea7cef8200a9a74f..429e3d5be041d5ef75c4c8d48c2635030a644599 100644 (file)
@@ -168,8 +168,8 @@ func rewriteValueS390X(v *Value) bool {
                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:
@@ -1939,8 +1939,8 @@ func rewriteValueS390X_OpFloor_0(v *Value) bool {
                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]
index e8fa2b8b66adb994f02c4ff0bc53da8ec2666aba..e9621e6dc979958cf0ee113b5ce0e02339d3170a 100644 (file)
@@ -3053,11 +3053,11 @@ func TestYn(t *testing.T) {
        }
 }
 
-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)
                }
        }
 }
@@ -3793,10 +3793,10 @@ func BenchmarkFloat32frombits(b *testing.B) {
        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
 }
index 76249229b2bc5e67e8b33f65595db4b81bd03014..db78dfa5e15ccfe413ba39a99e4cb70f5a9e89fa 100644 (file)
@@ -90,8 +90,9 @@ func split(b uint64) (sign uint32, exp int32, mantissa uint64) {
        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.
index 751406d732e39c0eacb56696366b8323b07b01fc..80e5d60d963a080bc7706d2035412d27482a6387 100644 (file)
@@ -114,7 +114,7 @@ func fma(x, y, z float64) float64 {
        // s390x:"FMADD"
        // ppc64:"FMADD"
        // ppc64le:"FMADD"
-       return math.Fma(x, y, z)
+       return math.FMA(x, y, z)
 }
 
 func fromFloat64(f64 float64) uint64 {