FCVT.W.H

RISC-V FCVT.W.H Instruction Details

Instruction ManualOP-FP conversion fields

Convert half-precision float to signed 32-bit integer

Instruction Syntax

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

Instruction Behavior

fcvt.w.h converts a half-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.H Decode And Execute Animation

Shows the Zfh-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.h
,
,
Execution Context
fmt=H (10)
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
10
fmt=H
00000
rs2=W
01011
rs1
000
rm
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0xC4058553
opcode
1010011 -> OP-FP
funct5/fmt
11000 + 10 -> FCVT.W.H
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: 0xC4058553
syntax : fcvt.w.h 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
H 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 Zfh-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.h converts a half-precision source operand to a signed 32-bit integer result. Floating-point-to-integer conversion rounds according to rm and writes integer register rd.

The OP-FP opcode is 1010011; funct5=11000 denotes FP-to-integer FCVT and fmt=10 denotes the H source format.
rs2=00000 selects the W signed 32-bit integer target; rm selects static rounding or DYN/frm.
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.
The W 32-bit result is sign-extended to XLEN on RV64; when FLEN exceeds 16, an H source must be recursively NaN-boxed.

Common Usage Scenarios

Type Conversion

Understand this scenario with real code like «fcvt.w.h x10, f11, rtz ; x10 = (int32_t)f11».

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.
An H source in an FP register wider than 16 bits must be recursively NaN-boxed under Zfh or is treated as a canonical H NaN.

FAQ

When does rm matter for fcvt.w.h?

When conversion requires rounding, rm or dynamic frm selects the rounding direction; out-of-range or NaN inputs follow the official invalid-conversion rule.

How does fcvt.w.h differ from related FCVT instructions?

It differs by source/destination format, integer signedness, RV64 restrictions, and whether rounding or invalid conversion can occur.