Skip to content

Floating-point instructions execute with mstatus.FS=Off, and FS never becomes Dirty #446

Closed

Description

@Risid

Environment Setup

Stock XLEN=32 configuration, F enabled, C disabled, IALIGN=32. Tested at commit b447578d9f3bb116d658c614cf3407153f0536da (MUFU + Zfhmin merge). Driver: rtlsim built DEBUG=1; the tests are bare-metal ELFs.

  • f1_fs_state/30_fs0_fp_executes/30_fs0_fp_executes.S leaves FS at its reset value and executes fmv.w.x (FMV.S.X).
  • f1_fs_state/29_fs_dirty_transition/29_fs_dirty_transition.S writes FS=Initial (mstatus bit field 0x2000), executes fmv.w.x, then reads mstatus.

Each test has its own directory under f1_fs_state/ (29_fs_dirty_transition/, 30_fs0_fp_executes/). In each one, dut.elf has no tohost symbol and ref.elf is the same source built with -DPROBE_REF=1 and HTIF tohost=0x80100000.

# rtlsim built DEBUG=1 from the commit above (XLEN=32, F on, C off).
P=f1_fs_state/29_fs_dirty_transition # or f1_fs_state/30_fs0_fp_executes
spike -l --log-commits --isa=rv32imaf -m128 $P/ref.elf
./rtlsim $P/dut.elf

Actual result: spike_rc=1 for the FS-Off test (its reference ELF traps into the local illegal-instruction handler and exits 1), dut_rc=0 for both; the FS-Dirty test reported spike_rc=0 dut_rc=0.

Expected behavior

With F implemented and mstatus.FS not hardwired to 0, an FP instruction while FS=Off must raise illegal-instruction. An instruction that writes FP state must move FS from Initial to Dirty, and SD follows.

Per the RISC-V Privileged Specification, machine.adoc, in the mstatus FS field text:

When an extension's status is set to Off, any instruction that attempts to read or write the corresponding state will cause an illegal-instruction exception.

and in the FS/VS/XS state-transition table, under "Execute instruction that possibly modifies state, including configuration", the next state is Dirty for a current state of Initial, Clean or Dirty. SD is defined as:

The SD bit is read-only and is set when either the FS, VS, or XS bits encode a Dirty state (i.e., SD=(FS==0b11 OR XS==0b11 OR VS==0b11)).

Observed results

FS-Off test (30_fs0_fp_executes), FP instruction at PC 0x80000014:

Engine Result
Vortex commits FMV.S.X (op=FMV.S.X, rd=32) with data=0x3f800000, no trap
Spike exception trap_illegal_instruction, epc 0x80000014

DUT trace (logs/30_fs0_fp_executes_dut.dbg.log, divergence marked):

301: ...-decode decode: ... PC=0x80000014, ex=FPU, op=FMV.S.X, ... rd=32, ...
321: ...-commit commit: ... PC=0x80000014, ex=FPU, wb=1, rd=32, ... data={0x0, 0x0, 0x0, 0x3f800000} <--

Spike (logs/*_ref.commits):

core 0: 0x80000010 (0x3f800437) lui s0, 0x3f800
core 0: exception trap_illegal_instruction, epc 0x80000014 <--
core 0: >>>> illegal_handler

FS-Dirty test (29_fs_dirty_transition), mstatus read after fmv.w.x (csrr t3, mstatus at PC 0x80000014):

Engine subsequent mstatus
Vortex 0x2000 (still Initial)
Spike 0x80006000 (Dirty, SD=1)

DUT (logs/29_fs_dirty_transition_dut.dbg.log, commit of csrr t3,mstatus at PC 0x80000014):

325: ...-commit commit: ... PC=0x80000014, ex=SFU, rd=28, ... data={0x2000, 0x2000, 0x2000, 0x2000} <--

Spike (logs/*_ref.commits):

core 0: 3 0x80000010 (0xf0040053) c768_mstatus 0x80006000 f0 0x3f800000 <--
core 0: 0x80000014 (0x30002e73) csrr t3, mstatus
core 0: 3 0x80000014 (0x30002e73) x28 0x80006000

The FS-Off test has a local illegal-instruction handler so Spike can exit.

Both results are what you get if the FPU path neither checks FS before issuing nor updates FS on an FP write.

Affected revision and environment

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

Minimal RTL reproducer

The log excerpts are from logs/29_fs_dirty_transition_dut.dbg.log and logs/30_fs0_fp_executes_dut.dbg.log in the attachment.

Attachment: testcase.zip contains the two .S sources, their prelinked dut.elf / ref.elf, link.ld and probe_macros.h, plus the full DUT (*_dut.dbg.log) and Spike (*_ref.commits) logs for both tests.

testcase.zip

Activity

  1. tinebp commented on Nov 19, 2026

    @tinebp
    Collaborator

    Fixed by #487.

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