aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Munday <mike.munday@lowrisc.org>2023-06-28 23:12:33 +0100
committerGopher Robot <gobot@golang.org>2023-07-07 17:39:26 +0000
commit158d11196f732e4c80b03240548bdd373e6a9eff (patch)
tree082f6b47a4a5dee5fadad7405507fd1021cc8dd1
parentd3d78b4bcc7c4021c4a3a8a3ecdb85ec59bdd58b (diff)
downloadgo-158d11196f732e4c80b03240548bdd373e6a9eff.tar.gz
go-158d11196f732e4c80b03240548bdd373e6a9eff.zip
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>
-rw-r--r--src/math/all_test.go39
1 files changed, 39 insertions, 0 deletions
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