riscv_fpu: honor the rounding mode in the FMA ops#237
Closed
SolAstrius wants to merge 5 commits into
Closed
Conversation
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Contributor
Author
|
Closing in favor of a single consolidated patch, per the maintainer's request to submit this as one patch rather than a stacked-PR series. The combined FPU work (RMM rounding, static rounding modes, NaN canonicalization, FMA rounding/ties/underflow, fmul ties, fcvt-to-int flags) now passes the riscv-arch-test F/D/I/M suites 260/260. Rebased onto current staging (which already includes #219). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the fused-multiply-add family honor the rounding mode. Two issues:
frmCSR.fpu_fmarounds in the host mode (which only tracksfrm), so a staticrmfield on an FMA (fmadd.s …,rtzetc.) was computed in whateverfrmleft set, and RMM had no host mode at all. A small wrapper (riscv_fma_round_f32/64, mirroring the OP-FP dispatch in riscv_fpu: correct RMM rounding, honor static rounding modes, optimize FP dispatch #233) applies the effective mode around the op: static host-native modes are set/restored, RMM runs in RNE.fnmaddrounded the wrong value. It computed-(fma(a,b,c))— roundinga*b+cand then negating, which flips the rounding direction under the directed modes.fnmadd = -(rs1*rs2) - rs3must befma(-a, b, -c)so the single rounding sees the correctly-signed result. (fmsub/fnmsubalready negated operands, not the result — onlyfnmaddwas wrong.)Validation
stagingis 101).__builtin_fma(used on aarch64/riscv/ppc) respects the host mode for every rounding mode, so the wrapper is exact there; the software fallback rounds via round-to-odd, which is also mode-correct.Out of scope (pre-existing, separate)
UFon a few near-underflow FMAs (0x03vs0x01): an FMA exception-flag bug, not a rounding bug.