riscv: don't leak spurious NX from the FMA error-recovery path - #316
Open
carlosqwqqwq wants to merge 1 commit into
Open
riscv: don't leak spurious NX from the FMA error-recovery path#316carlosqwqqwq wants to merge 1 commit into
carlosqwqqwq wants to merge 1 commit into
Conversation
carlosqwqqwq
force-pushed
the
fix/fma-exact-nx
branch
from
September 6, 2026 05:32
7413499 to
a87e232
Compare
carlosqwqqwq
force-pushed
the
fix/fma-exact-nx
branch
from
September 6, 2026 05:47
a87e232 to
76139cb
Compare
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.
riscv: don't leak spurious NX from the FMA error-recovery path
Fixes #310
Commit message
Description
fpu_fma32/fpu_fma64_rawinsrc/util/fpu_lib.hcompute the fused value with host f64 arithmetic plus a TwoSum error-recovery pass. When the exact result is representable in the destination format, the recovery intermediates can still raise the host inexact flag, andfpu_odd_round32/fpu_odd_round64also treat a-0.0error term (returned for an exact sum) as a nonzero negative error, nudging the value off the exact grid point. Both effects produce a spurious guestfflags.NXon exact results.The change masks the sign bit in the odd-round nonzero test and clears only newly raised NX around the single final rounding step of each software fallback. In
fpu_fma32it preserves NX raised by the first f64 sum; infpu_fma64_rawthe final add establishes the instruction's NX, with a residual check covering hosts whose excess precision does not set the host flag. Both paths preserve NX that was already set before the instruction. The host-flag reconciliation is gated to the SSE2 fallback used by the affected x86-64 configuration; the legacy x87 path keeps its existing platform-specific exception handling. Result bits are unchanged in all cases (verified by differential testing).Validation
fmadd.s rdn(exact-2^-46) andfmadd.d/fnmadd.d(exact+/-2^-104): unmodified RVVM reportsfflags=1; the patched build reportsfflags=0with identical result bits, matching native RISC-V hardware and QEMU.fpu_fma64with finite normal-range operands: zero result-bit and zero NX-flag differences.The patch is independently applicable to the
stagingbranch and does notdepend on an unmerged FMA change.