riscv: resolve frm for dynamic rounding of fcvt float-to-int - #260
riscv: resolve frm for dynamic rounding of fcvt float-to-int#260carlosqwqqwq wants to merge 1 commit into
Conversation
|
@SolAstrius please review, thank you |
|
This is not an isolated problem, if we don't handle this more generally it's going to surface again. The root issue is that fpu_lib assumes DYN denotes the current host mode, while in reality we pretty much always want the current emulated mode. I think every function in fpu_lib needs to have a contract that the passed rounding mode is never DYN, it should never try to default to the host mode, and that logic needs to be moved to the caller that knows what the state of the emulated FPU is. |
|
Technically the host rounding mode is the guest However, this comes with two important exceptions:
|
I think we're in agreement, but to elaborate: in most instruction handlers, like addition, which don't normally need to bother with the rounding mode, it is indeed a good idea to mostly ignore it and special-case RMM separately. In functions like |
|
Agreed with the discussion outcome. This PR resolves DYN at the caller (eff_rm = frm CSR when rm==DYN) and passes a concrete mode into fpu_round_*; the helpers never see DYN on the fcvt path, and a guest frm=RMM is honored by the software rounding path. That matches the proposal to move DYN resolution to the caller and keep fpu_lib's contract mode != DYN. No changes needed from the discussion; happy to adjust if you prefer the resolution in a shared helper. |
|
The reason I wrote that comment is that |
bc5f5e4 to
c3001be
Compare
|
Verified the remaining callers: fround.s/fround.d now also resolve RM_DYN before calling the helpers. With all callers passing concrete modes, the unreachable fallback was removed and the helper contract was updated. The branch was rebuilt successfully. |
|
Updated the effective-mode extraction to use fcsr[7:5] and apply RMM consistently for static and dynamic cases. The helper contract now states that callers resolve RM_DYN. The branch was rebuilt and the existing regression check passed. Please re-review. |
|
Good catch about |
ce19f13 to
a49b011
Compare
riscv: resolve frm for dynamic rounding of fcvt float-to-int
Fixes #255
Description
The float-to-integer conversions (
fcvt.w.s,fcvt.wu.s,fcvt.l.s,fcvt.lu.sand the.dsiblings) pass the rawrmfield to the rounding helpers. Forrm=dynthe helper falls back to the host-tracked mode, but RMM has no host equivalent and is mapped to RNE, sofrm=RMMcollapses to round-to-nearest-even instead of round-to-nearest-ties-away.Resolve the effective mode from
frmwhen the field isdynand pass it to the rounding helpers; staticrmvalues, including RMM, are unchanged.Validation
+2.5/-2.5) under static RMM anddyn + frm=RMMfor all eight conversion forms match native RISC-V hardware and QEMU.RNE/RDN/RUPcontrols are unchanged.