Skip to content

fpu: canonicalize NaN results of fadd/fmul/fdiv and fused ops - #259

Open
carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/fpu-nan-canonicalize
Open

fpu: canonicalize NaN results of fadd/fmul/fdiv and fused ops#259
carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/fpu-nan-canonicalize

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Aug 11, 2026

Copy link
Copy Markdown

Summary

The FP writeback for fadd, fmul, fdiv and the fused fmadd/fmsub/fnmsub/fnmadd family stores the raw host result, which keeps non-canonical NaN payloads. The fsub/fmin/fmax paths already canonicalize through the write helpers; the RISC-V specification requires the canonical NaN bit pattern for arithmetic results. Route the remaining arithmetic writebacks through the same canonicalizing writers.

Signaling-NaN NV flagging is unchanged.

Validation

  • qNaN-payload, inf*0+1 and 0/0 probes match native RISC-V hardware and QEMU after the fix, with the JIT enabled and disabled.
  • Every arithmetic result is the canonical NaN and fflags match the references.

Fixes #254

@LekKit

LekKit commented Aug 11, 2026

Copy link
Copy Markdown
Owner

@SolAstrius please confirm via your out-of-tree test suite and review if possible, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fadd/fmul/fdiv leak qNaN payloads instead of returning canonical NaNs

2 participants