Skip to content

fpu: implement Zfa minimum-number-or-NaN operations - #298

Open
carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/zfa-fminm-nan
Open

carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/zfa-fminm-nan

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Sep 5, 2026 •

Copy link
Copy Markdown

fpu: implement Zfa minimum-number-or-NaN operations

Fixes #295

Commit message

fpu: implement Zfa minimum-number-or-NaN operations

Description

The Zfa fminm/fmaxm instructions currently call the IEEE-754-2008 fmin/fmax helpers. Those helpers return the numeric operand when one input is NaN, but the minimum-number-or-NaN instructions must return canonical NaN when either input is NaN. Add precision-specific helpers and preserve the existing numeric ordering and signaling-NaN flag behavior.

The helpers already canonicalize NaN results, so the instruction handlers use riscv_emit_s()/riscv_emit_d() for the final bit-precise writeback instead of canonicalizing the same value a second time.

Validation

  • QEMU (qemu-riscv64, Zfa) returns the canonical qNaN whenever either input is NaN; the patched build matches on the single- and double-precision one-NaN and two-NaN witnesses. The native reference does not implement Zfa and is recorded as a capability boundary.

@LekKit

LekKit commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Nitpick: riscv_write_s() is now redundant on the result since the helper already canonicalizes.

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.

fminm/fmaxm return numeric operand instead of canonical qNaN on NaN input

2 participants