simd: use fused multiply-add in emulated MulAdd#80355
Conversation
The emulated MulAdd computed x*y+z with a plain expression, which rounds twice and is not guaranteed to fuse. The operation is documented as a fused multiply-add (amd64 VFMADD213, arm64 VFMLA), and the arch conformance tests use math.FMA as the reference. Use math.FMA so the emulated path matches the fused, single-rounding semantics on all architectures.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: c0654d5) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/799281. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/799281. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/799281. |
The emulated MulAdd (used on architectures other than amd64, arm64,
and wasm) computed xy+z with a plain expression. Whether the gc
compiler contracts xy+z into a hardware FMA is architecture
dependent, so on targets without FMA contraction (for example 386)
the result is double-rounded and disagrees with the arch
implementations.
MulAdd is documented as a fused multiply-add (amd64 VFMADD213PS/PD,
arm64 VFMLA), and the arch conformance tests use math.FMA as the
reference oracle. Use math.FMA in the emulated path so it produces
the fused, single-rounding result on all architectures.
Verified with GOARCH=386 GOEXPERIMENT=simd: the simd test package
passes, and over 800k random float32 triples the updated MulAdd
matches math.FMA on every element, while plain x*y+z diverged on
about 27% of them.