Skip to content

riscv: implement fcvtmod.w.d with modulo-2^32 semantics - #304

Open
carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/zfa-fcvtmod-modulo
Open

riscv: implement fcvtmod.w.d with modulo-2^32 semantics#304
carlosqwqqwq wants to merge 1 commit into
LekKit:stagingfrom
carlosqwqqwq:fix/zfa-fcvtmod-modulo

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Sep 5, 2026

Copy link
Copy Markdown

riscv: implement fcvtmod.w.d with modulo-2^32 semantics

Commit message

riscv: implement fcvtmod.w.d with modulo-2^32 semantics

fcvtmod.w.d (Zfa) converts its double operand with round-towards-zero
and returns the low 32 bits of the rounded two's-complement result
(modulo 2^32, no saturation); NaN and infinity convert to 0.
The previous handler reused the saturating fpu_fcvt_f64_to_i32,
which yields 0x7fffffff/0x80000000 for out-of-range inputs and
saturates NaN/infinity.

Add fpu_fcvtmod_f64_to_i32 implementing the modulo semantics with
NV on NaN/inf/overflow and NX on inexact rounding, and use it from the
fcvtmod.w.d case. The separate architectural writeback control-flow fix is
tracked by PR #303.

Description

fpu_lib.h: new fpu_fcvtmod_f64_to_i32 performs RTZ rounding on the raw double bits, extracts the low 32 bits of the rounded value, and applies the sign; NV is raised for NaN/infinity/out-of-range, NX for inexact truncation. The in-range path uses direct bit-level extraction for the common case (|x| < 2^31).

riscv_fpu.c: case 0x08 calls the new routine; reserved rounding-mode
encodings retain the existing illegal path. The separate fall-through defect
is handled by PR #303, and this semantic patch remains independently
applicable to the same staging baseline.

Validation

Fixes #297

@carlosqwqqwq
carlosqwqqwq force-pushed the fix/zfa-fcvtmod-modulo branch from 79b70dc to f8a02b2 Compare September 6, 2026 07:11
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.

fcvtmod.w.d uses saturating conversion instead of modulo-2^32 semantics

1 participant