Skip to content

riscv_fpu: honor static RMM rounding-mode field#235

Closed
SolAstrius wants to merge 2 commits into
LekKit:stagingfrom
pufit:fix/rmm-static-rm
Closed

riscv_fpu: honor static RMM rounding-mode field#235
SolAstrius wants to merge 2 commits into
LekKit:stagingfrom
pufit:fix/rmm-static-rm

Conversation

@SolAstrius

Copy link
Copy Markdown
Contributor

Summary

Extends #233 so that RMM (IEEE 754 roundTiesToAway) is honored when it is selected by the static rm field of an instruction (e.g. fadd.s …,rmm), not only by the dynamic frm CSR.

Draft / stacked on #233. This branch builds on the #233 commit, so until that merges this PR shows both commits; the new work is the top commit, "riscv_fpu: honor static RMM rounding-mode field." Please review/merge #233 first.

Background

#233 fixes RMM but only triggers on frm == RMM (dynamic rounding). The RISC-V spec also allows RMM to be encoded statically in the instruction's rm field; RVVM previously ignored a static rm for arithmetic ops entirely (only frm drove the host mode). So fadd.s rd,rs1,rs2,rmm under the default frm was computed as round-to-nearest-even.

Change

  • Detect RMM from either source: rm == 0b100 (static) or rm == DYN && frm == RMM (dynamic). funct3 == 0b100 only ever appears on rounding-capable ops, so the static check can't misfire on fsgnj/fcmp/fclass/etc.
  • The error-free transforms (TwoSum / TwoProduct) used for the ties-away fixup require the base op to be in round-to-nearest. A static ,rmm under a directed frm is the only case where the host (which tracks frm) isn't already nearest, so the fixup helpers wrap the op in a self-eliminating guard: it reads the host mode and only switches to RNE (restoring after) when it isn't already RNE. For the common cases (dynamic RMM, or static ,rmm under the default frm) it's a no-op, so the hot path is untouched.

Validation

  • The regression harness now runs every vector twice — dynamic frm=RMM and static ,rmm — plus a dedicated check that a directed frm (e.g. RTZ) survives a static-,rmm op (host mode restored). All pass (3006 vector-checks + restore), MPFR-oracle expected values, f32+f64, incl. subnormals/boundary.
  • No performance regression: this is implemented in a single dispatch function (an earlier wrapper-based version that added a per-op call was reworked out); FP throughput matches baseline.

Out of scope (same as #233)

  • Static rm for the other directed modes (rtz/rdn/rup) on arithmetic is still not honored — only RMM is addressed here.
  • fcvt-to-integer under RMM still rounds ties-to-even.

Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
Signed-off-by: Sol Astrius Phoenix <sol@astrius.ink>
@SolAstrius

Copy link
Copy Markdown
Contributor Author

Superseded by #233, which now carries static rounding-mode support as its own commit ("honor the static rounding-mode field") and generalizes it to all static modes (rtz/rdn/rup/rmm), not just RMM.

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.

1 participant