Home/Instructions/FCVTMOD-W-D
FCVTMOD.W.D

RISC-V FCVTMOD.W.D Instruction Details

Instruction ManualR-type

Modular convert double-precision float to signed word (mod 2^32)

Instruction Syntax

fcvtmod.w.d rd, rs1, rtz
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
ZfaDFloating-Point Convert

Instruction Behavior

fcvtmod.w.d is a Zfa instruction. It converts a double-precision value toward zero to an unbounded two's-complement integer, takes the low 32 bits, sign-extends to XLEN, and converts NaN and infinities to zero.

FCVTMOD.W.D Decode And Execute Animation

Shows the Zfa + D-extension FCVTMOD flow: decode OP-FP fields, fmt/rs2 conversion selection, fixed rm=001 (RTZ), read the floating-point source, then write the integer destination.

rd
rs1
fcvtmod.w.d
,
Execution Context
fmt=D (01)
rs2=8 (modular W)
rounding: fixed RTZ (001)
fflags: NX
31..27
26..25
24..20
19..15
14..12
11..7
6..0
11000
FCVTMOD
01
fmt=D
01000
rs2=8 (modular W)
01011
rs1
001
rm=001 RTZ
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0xC2859553
opcode
1010011 -> OP-FP
funct5/fmt
11000 + 01 -> FCVTMOD.W.D
rs2
01000 -> 8 (modular W) target
rm
001 -> fixed RTZ; other rm encodings are reserved
rd/rs1
a0(x10) / fa1(f11)
read
fa1(f11) = -42.75
convert
-42.75 -> int32 -42
write
a0(x10) = 0xFFFFFFD6 (-42); NX
Current Step

Fetch: show the 32-bit OP-FP encoding

The word is split as an R-type OP-FP instruction; FCVTMOD uses opcode 1010011.

encoding: 0xC2859553
syntax : fcvtmod.w.d a0(x10), fa1(f11), rtz
result : a0(x10) = 0xFFFFFFD6 (-42); NX

The current example uses fixed RTZ, takes the low 32 bits of the unbounded two's-complement result, and sign-extends them; fflags shows the NX outcome of FCVT.W.D for the same input.

FCVTMOD Conversion View
D FP source
-42.75
conversion
-42.75 -> int32 -42
writeback
a0(x10) = 0xFFFFFFD6 (-42)

The current example uses fixed RTZ, takes the low 32 bits of the unbounded two's-complement result, and sign-extends them; fflags shows the NX outcome of FCVT.W.D for the same input.

This animation shows only Zfa + D-extension FCVTMOD ISA-visible encoding, source/destination register direction, rounding field, and example fflags; it does not model FPU pipelines, exception handling, NaN payloads, or microarchitecture.

Quick Understanding & Search Notes

fcvtmod.w.d is a Zfa instruction. It converts a double-precision value toward zero to an unbounded two's-complement integer, takes the low 32 bits, sign-extends to XLEN, and converts NaN and infinities to zero.

It is encoded like FCVT.W.D but with rs2=8 and rm=RTZ.
Assembly syntax must explicitly write rtz; other rm encodings are reserved.
It is a modulo 2^32 conversion, not the saturating/clipping conversion of FCVT.W.D.
NaN and positive or negative infinity produce zero, a special rule for this Zfa instruction.
fflags is the same as FCVT.W.D for the same input; an invalid conversion sets NV.

Common Usage Scenarios

JavaScript Engines

Understand this scenario with real code like «fcvtmod.w.d x10, f0, rtz # RTZ, take low 32 bits, then sign-extend to XLEN».

WebAssembly

Understand this scenario with real code like «fcvtmod.w.d x10, f0, rtz # RTZ, take low 32 bits, then sign-extend to XLEN».

Modular Arithmetic

Understand this scenario with real code like «fcvtmod.w.d x10, f0, rtz # RTZ, take low 32 bits, then sign-extend to XLEN».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

Assembly syntax must explicitly write rtz; other rm encodings are reserved.
It is a modulo 2^32 conversion, not the saturating/clipping conversion of FCVT.W.D.
NaN and positive or negative infinity produce zero, a special rule for this Zfa instruction.

FAQ

How is fcvtmod.w.d different from fcvt.w.d?

fcvtmod.w.d takes the low 32 bits of the unbounded RTZ conversion result modulo 2^32; fcvt.w.d uses the official invalid-conversion result for out-of-range integer conversion.

Why does fcvtmod.w.d require rtz?

Zfa requires assembly syntax to explicitly specify RTZ; other rm encodings are reserved.