Skip to content

DPI FPU fmin.s / fmax.s drop fflags.NV when both inputs are NaN #449

Closed

Description

@Risid

Environment Setup

Stock XLEN=32 configuration, F enabled, C disabled, IALIGN=32, shipped DPI FPU backend. Tested at commit b447578d9f3bb116d658c614cf3407153f0536da. Driver: rtlsim built DEBUG=1; test is a bare-metal ELF.

  • 01_fminmax_nan_fflags.S clears fflags, runs fmin.s / fmax.s with both operands NaN (at least one signaling NaN), and reads fflags after each.
  • Prebuilt dut.elf / ref.elf are attached.
# rtlsim built DEBUG=1 from the commit above (XLEN=32, F on, C off).
spike -l --log-commits --isa=rv32imaf -m128 ref.elf
./rtlsim dut.elf

Both runs exited cleanly (spike_rc=0, dut_rc=0).

Expected behavior

Per the RISC-V Unprivileged ISA, F extension (FMIN.S/FMAX.S):

Signaling NaN inputs set the invalid operation exception flag, even when the result is not NaN.

Observed results

Both engines produce the canonical qNaN result. The accrued flag differs.

DUT (dut.dbg.log, commits of csrr t1,fflags after the both-NaN cases):

 693: ...-commit commit: ... PC=0x80000058, ex=SFU, rd=6, ... data={0x0, ...} (#22) <--
 837: ...-commit commit: ... PC=0x80000078, ex=SFU, rd=6, ... data={0x0, ...} (#30) <--
1027: ...-commit commit: ... PC=0x80000098, ex=SFU, rd=6, ... data={0x0, ...} (#38) <--
1171: ...-commit commit: ... PC=0x800000b8, ex=SFU, rd=6, ... data={0x0, ...} (#46) <--

Spike (ref.commits):

core 0: 3 0x80000054 (0x28100153) c1_fflags 0x00000010 f2 0x7fc00000 <--
core 0: 0x80000058 (0x00102373) csrr t1, fflags
core 0: 3 0x80000074 (0x28100153) c1_fflags 0x00000010 f2 0x7fc00000 <--
core 0: 0x80000078 (0x00102373) csrr t1, fflags

Comparing the two commit logs (compare.json in the attachment, 90 checks) gives 8 differences, all of the form dut 0x00000000 / ref 0x00000010 at the fflags readbacks (PCs 0x80000058, 0x80000078, 0x80000098, 0x800000b8) and their companion stores. Controls in the same run where only one operand is NaN do set NV on the DUT (e.g. commit at PC 0x800000fc reads 0x10), so the missing flag is specific to the both-NaN early-return path.

I suspect an early return in the DPI FPU backend skips the NV flag when both inputs are NaN, but I have not traced it. The RTL FNCP min/max path was not run.

Affected revision and environment

  • Tested at commit b447578d9f3bb116d658c614cf3407153f0536da
  • VERSION: VORTEX_VERSION=3.0, TOOLCHAIN_REV=v3.0.1
  • DUT simulator: rtlsim DEBUG=1 (shipped DPI backend)
  • Reference: Spike --isa=rv32imaf -m128
  • OS: Linux 6.8.0-90-generic x86_64.

Minimal RTL reproducer

Attached: 01_fminmax_nan_fflags.S, dut.elf, ref.elf, probe_macros.h, link.ld, compare.json (n_checks=90, n_divergences=8), dut.dbg.log, ref.commits.

testcase.zip

Activity

  1. changed the title [-]DPI FPU fmin.s/fmax.sdropfflags.NV when both inputs are NaN[/-] [+]DPI FPU fmin.s / fmax.s drop fflags.NV when both inputs are NaN[/+] on Nov 5, 2026
  2. tinebp commented on Nov 19, 2026

    @tinebp
    Collaborator

    Fixed by #485.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions