]> Cypherpunks repositories - gostls13.git/commitdiff
math: add test that covers riscv64 fnm{add,sub} codegen
authorMichael Munday <mike.munday@lowrisc.org>
Wed, 28 Jun 2023 22:12:33 +0000 (23:12 +0100)
committerGopher Robot <gobot@golang.org>
Fri, 7 Jul 2023 17:39:26 +0000 (17:39 +0000)
Adds a test that triggers the RISC-V fused multiply-add code
generation bug fixed by CL 506575.

Change-Id: Ia3a55a68b48c5cc6beac4e5235975dea31f3faf2
Reviewed-on: https://go-review.googlesource.com/c/go/+/507035
Auto-Submit: M Zhuo <mzh@golangcn.org>
Reviewed-by: M Zhuo <mzh@golangcn.org>
Run-TryBot: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/math/all_test.go

index 96a398e9c6f3c214496ef48651d49c5d476a151f..af3c38c2a690dda7da30e189bc58861c7c737849 100644 (file)
@@ -3106,6 +3106,45 @@ func TestFMA(t *testing.T) {
        }
 }
 
+//go:noinline
+func fmsub(x, y, z float64) float64 {
+       return FMA(x, y, -z)
+}
+
+//go:noinline
+func fnmsub(x, y, z float64) float64 {
+       return FMA(-x, y, z)
+}
+
+//go:noinline
+func fnmadd(x, y, z float64) float64 {
+       return FMA(-x, y, -z)
+}
+
+func TestFMANegativeArgs(t *testing.T) {
+       // Some architectures have instructions for fused multiply-subtract and
+       // also negated variants of fused multiply-add and subtract. This test
+       // aims to check that the optimizations that generate those instructions
+       // are applied correctly, if they exist.
+       for _, c := range fmaC {
+               want := PortableFMA(c.x, c.y, -c.z)
+               got := fmsub(c.x, c.y, c.z)
+               if !alike(got, want) {
+                       t.Errorf("FMA(%g, %g, -(%g)) == %g, want %g", c.x, c.y, c.z, got, want)
+               }
+               want = PortableFMA(-c.x, c.y, c.z)
+               got = fnmsub(c.x, c.y, c.z)
+               if !alike(got, want) {
+                       t.Errorf("FMA(-(%g), %g, %g) == %g, want %g", c.x, c.y, c.z, got, want)
+               }
+               want = PortableFMA(-c.x, c.y, -c.z)
+               got = fnmadd(c.x, c.y, c.z)
+               if !alike(got, want) {
+                       t.Errorf("FMA(-(%g), %g, -(%g)) == %g, want %g", c.x, c.y, c.z, got, want)
+               }
+       }
+}
+
 // Check that math functions of high angle values
 // return accurate results. [Since (vf[i] + large) - large != vf[i],
 // testing for Trig(vf[i] + large) == Trig(vf[i]), where large is