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 <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>
This commit is contained in:
Michael Munday 2023-06-28 23:12:33 +01:00 committed by Gopher Robot
parent d3d78b4bcc
commit 158d11196f
1 changed files with 39 additions and 0 deletions

View 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