Skip to content

fsgnj / fsgnjn / fsgnjx set fflags.NV when an operand is a signaling NaN #444

Closed

Description

@Risid

Environment Setup

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

  • 20_fsgnj_fflags_nv.S clears fflags, sets an inexact baseline flag with a prior FP op, then runs fsgnj.s / fsgnjn.s / fsgnjx.s with a signaling NaN operand (0x7f800001) and reads fflags after each.
  • Prebuilt prebuilt/20_dut.elf / prebuilt/20_ref.elf are attached.
# rtlsim built DEBUG=1 from the commit above (XLEN=32, F on, C off).
# Binary used for these measurements:
# sha256 7781afec22ac961b5151f336f91592e17a9da160b2517526c9b27f21342c83d7
spike -l --log-commits --isa=rv32imaf -m128 prebuilt/20_ref.elf
./rtlsim prebuilt/20_dut.elf

Both exits clean (spike_rc=0, dut_rc=0).

Expected behavior

Per the RISC-V Unprivileged ISA, F extension ("Sign Injection Instructions", section on fsgnj/fsgnjn/fsgnjx): these are sign-bit manipulations that raise no exception and set no accrued exception flag, whatever the operand class.

Observed results

DUT (logs/rev20_dut.dbg.log, commits of csrr ...,fflags at the four readback PCs):

455: ...-commit commit: ... PC=0x8000002c, ex=SFU, rd=8, ... data={0x1, ...} (#11)
469: ...-commit commit: ... PC=0x80000034, ex=SFU, rd=9, ... data={0x11, ...} <-- NV set
505: ...-commit commit: ... PC=0x8000003c, ex=SFU, rd=18, ... data={0x11, ...} <--
599: ...-commit commit: ... PC=0x80000044, ex=SFU, rd=19, ... data={0x11, ...} <--

fflags is 0x1 before the sign-injection instructions and 0x11 afterwards (NV = bit 4 = 0x10).

Spike (logs/rev20_ref.commits):

core 0: 3 0x8000002c (0x00102473) x8 0x00000001
core 0: 3 0x80000034 (0x001024f3) x9 0x00000001 <--
core 0: 3 0x8000003c (0x00102973) x18 0x00000001 <--
core 0: 3 0x80000044 (0x001029f3) x19 0x00000001 <--

Spike keeps fflags at 0x1 throughout. The numeric sign-injection result is not the issue here; only the NV bit differs.

The sign-injection cases appear to share a mux arm with the compare cases in VX_fncp_unit.sv and to inherit the NV verdict produced by the compare path.

Affected revision and environment

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

Minimal RTL reproducer

Attachment: testcase.zip contains 20_fsgnj_fflags_nv.S, its prelinked prebuilt/20_dut.elf / prebuilt/20_ref.elf, link.ld and probe_macros.h, plus the full DUT (logs/rev20_dut.dbg.log) and Spike (logs/rev20_ref.commits) logs. The excerpts above are from runs of the attached ELFs on that rtlsim and on Spike with the flags above. The FP writes show up in the raw logs (logs/rev20_dut.dbg.log, logs/rev20_ref.commits), both in the attachment.

The leading comments in the .S were shortened after the runs; the assembled .text is unchanged — reassembling the attached .S reproduces the .text of the attached ELFs byte for byte.

The DPI backend and the ASIC/FPGA backends disagree here, so one of them is wrong on NV. Only the DPI backend was checked end to end.

testcase.zip

Activity

  1. 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