FCVT.W.D

RISC-V FCVT.W.D Instruction Details

Instruction ManualOP-FP conversion fields

Convert double to signed int32: rd = (int32_t)f[rs1].

Instruction Syntax

fcvt.w.d rd, rs1, rm
Operand Breakdown
This is a OP-FP conversion fields-format instruction. Confirm operand positions based on the assembly syntax.
DFloating-Point Convert

Instruction Behavior

fcvt.w.d converts a double-precision source operand to a signed 32-bit integer result. Floating-point-to-integer conversion rounds according to rm and writes integer register rd.

FCVT.W.D Decode And Execute Animation

Shows the D-extension FCVT flow: decode OP-FP fields, fmt/rs2 conversion selection, the rm rounding field, read the floating-point source, then write the integer destination.

rd
rs1
rm
fcvt.w.d
,
,
Execution Context
fmt=D (01)
rs2=W
rounding: RNE nearest-even
fflags: NX
31..27
26..25
24..20
19..15
14..12
11..7
6..0
11000
FCVT.W
01
fmt=D
00000
rs2=W
01011
rs1
000
rm
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0xC2058553
opcode
1010011 -> OP-FP
funct5/fmt
11000 + 01 -> FCVT.W.D
rs2
00000 -> W target
rm
000 -> RNE nearest-even
rd/rs1
a0(x10) / fa1(f11)
read
fa1(f11) = -42.75
convert
-42.75 -> int32 -43
write
a0(x10) = 0xFFFFFFD5 (-43); NX
Current Step

Fetch: show the 32-bit OP-FP encoding

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

encoding: 0xC2058553
syntax : fcvt.w.d a0(x10), fa1(f11), rne
result : a0(x10) = 0xFFFFFFD5 (-43); NX

The current example rounds to a 32-bit integer according to rm and shows NX because the source has a fractional part.

FCVT Conversion View
D FP source
-42.75
conversion
-42.75 -> int32 -43
writeback
a0(x10) = 0xFFFFFFD5 (-43)

The current example rounds to a 32-bit integer according to rm and shows NX because the source has a fractional part.

This animation shows only D-extension FCVT 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

fcvt.w.d reads a double-precision FP source in rs1, rounds it according to rm to a signed 32-bit integer, and writes integer register rd; NaN or out-of-range inputs follow the official invalid-conversion rule and set NV.

OP-FP opcode is 1010011; funct5=11000 denotes FP-to-integer FCVT and fmt=01 denotes D source format.
rs2=00000 selects the W signed 32-bit integer target; rm selects the rounding mode or DYN/frm.
rd is an integer register and rs1 is a double-precision FP register; do not treat rd as an f register.
Inexact conversion sets NX; NaN or out-of-range integer targets follow the official invalid-conversion rule and set NV.
W/WU results are extended to XLEN on RV64 according to the official rule.

Common Usage Scenarios

Type Conversion

Understand this scenario with real code like «fcvt.w.d x10, f0, rtz # x10 = (int)f0».

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is OP-FP conversion fields.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

Pitfalls / Common Confusions

On RV64, the W 32-bit result is sign-extended to XLEN in the integer register.
For signed W, negative out-of-range inputs or -infinity write -2^31; positive out-of-range inputs, +infinity, or NaN write 2^31-1 and set NV.
A D source is narrower only when FLEN exceeds 64; it must then be NaN-boxed or is treated as a canonical D NaN.

FAQ

Which register classes do rd and rs1 use in fcvt.w.d?

This is a floating-point-to-integer conversion: rs1 is a floating-point register and rd is an integer register.

When does rm affect fcvt.w.d?

When the FP source is not integral and must be rounded to an integer, rm affects the 32-bit integer written to rd; inexact conversion sets NX. NaN or out-of-range inputs follow the official invalid-conversion rule and set NV.

What does the rs2 field select in fcvt.w.d?

rs2 is not an ordinary source register; in the FCVT encoding it selects the W signed 32-bit integer format.