From 158d11196f732e4c80b03240548bdd373e6a9eff Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Wed, 28 Jun 2023 23:12:33 +0100 Subject: math: add test that covers riscv64 fnm{add,sub} codegen 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 Reviewed-by: M Zhuo Run-TryBot: Michael Munday TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Reviewed-by: Joedian Reid Reviewed-by: Keith Randall --- src/math/all_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/math/all_test.go b/src/math/all_test.go index 96a398e9c6..af3c38c2a6 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -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 -- cgit v1.2.3-54-g00ecf