Repository navigation
arch-riscv: NaN-box finite fminm.s and fmaxm.s results - #3605
Conversation
|
Maybe this is a bug, though I'm not totally clear since this is purely an AI agent. If a human wants to chime in... That said, we don't want to commit a test program to gem5. Test programs go in gem5-resources, but generally we don't have tests in these cases. |
There was a problem hiding this comment.
Review Summary
This is an automated review by gem5's AI reviewer. It is advisory only and does not replace review by a maintainer.
This fixes fminm.s/fmaxm.s (Zfa) writing finite results unboxed with FLEN=64, by routing the selected operand through freg() exactly as the NaN path and the base fmin.s/fmax.s already do. I read the surrounding decode block and the other Zfa single-precision writers (fround.s, froundnx.s, fli.s); they already box, so these two were the only gaps. The change is a two-line, ISA-semantic fix with no timing-model impact. I applied the lower bar (opt-in Zfa instructions) plus a normal check of the test plumbing, which follows the existing riscv-counter-csr layout.
I ran the new bare-metal binary on a build/ALL/gem5.opt built at the PR head with the riscv_baremetal.py config used by the registered test; it exited via semihosting ADP_Stopped_ApplicationExit at tick 19000 with no failure. I did not re-run it against the base to see it fail (that would need a full rebuild), so I'm relying on the author's before/after report for that.
Merge strategy (for the maintainer): Squash and merge (single commit; keep the arch-riscv,tests: tag and a header of 65 characters or fewer).
Takeaway: LGTM -- 0 blocking issues; 1 optional test-coverage nit noted inline.
Detailed feedback is anchored inline on the respective files.
Was this helpful? React with 👍 or 👎 so we can measure how useful these automated reviews are.
| fminm.s f2, f0, f1 | ||
| fmv.x.d a0, f2 | ||
| li a1, 0xffffffff3f800000 | ||
| bne a0, a1, fail | ||
|
|
||
| fmaxm.s f2, f0, f1 | ||
| fmv.x.d a0, f2 | ||
| li a1, 0xffffffff40000000 | ||
| bne a0, a1, fail |
There was a problem hiding this comment.
Nit: with f0=1.0, f1=2.0, fminm.s takes the fs1 arm of the new freg(less ? fs1 : fs2) and fmaxm.s takes the fs2 arm, so the other arm of each ternary (fs2 for fminm.s, fs1 for fmaxm.s) isn't executed. Both arms go through the same freg() wrapper, so this isn't a correctness concern. Adding the swapped-operand cases (fminm.s f2, f1, f0 and fmaxm.s f2, f1, f0, same expected values) would make the regression cover both arms for one extra bne each. Optional.
Was this helpful? React with 👍 or 👎 so we can measure how useful these automated reviews are.
With FLEN=64, a single-precision result must be NaN-boxed. The Zfa `fminm.s` and `fmaxm.s` instructions wrote the selected binary32 value to `Fd_bits` without boxing it, so bits 63:32 of the destination were zero for finite results. A following single-precision instruction then read that register as the canonical NaN. Box the selected value with `freg()`, as the NaN path of these instructions and `fmin.s`/`fmax.s` already do.
a7e7049 to
3b823ba
Compare
|
@powerjg Human here, it's my PR, been around the whole time. Yes it's a real bug, and I dropped the test program so it's just the two decoder lines now. Thanks for the quick review! |
With FLEN=64, the Zfa `fminm.s` and `fmaxm.s` instructions wrote finite results to the destination register without NaN-boxing them, so bits 63:32 were zero. A following single-precision instruction then read the register as the canonical NaN. For example, `fadd.s` of `fminm.s(1.0, 2.0)` and 2.0 returned NaN instead of 3.0. This change boxes the selected value with `freg()`, as the NaN path of these instructions and the base `fmin.s`/`fmax.s` already do. The issue's reproducer and the base FMIN/FMAX controls pass with the fix on Atomic, Timing, Minor and O3. Fixes #3599 — [ChipLab](https://chiplab.donmakino.com/findings#clab-2026-589) (cherry picked from commit b857ae2)
With FLEN=64, the Zfa
fminm.sandfmaxm.sinstructions wrote finite results to the destination register without NaN-boxing them, so bits 63:32 were zero. A following single-precision instruction then read the register as the canonical NaN. For example,fadd.soffminm.s(1.0, 2.0)and 2.0 returned NaN instead of 3.0.This change boxes the selected value with
freg(), as the NaN path of these instructions and the basefmin.s/fmax.salready do. The issue's reproducer and the base FMIN/FMAX controls pass with the fix on Atomic, Timing, Minor and O3.Fixes #3599
— ChipLab