FCVT.H.W

RISC-V FCVT.H.W Instruction Details

Instruction ManualR-type

Convert a signed 32-bit integer to half-precision FP, rounding according to rm or frm.

Instruction Syntax

fcvt.h.w rd, rs1, rm
Operand Breakdown
rd: destination half-precision FP register; rs1: source signed 32-bit integer register.
rm: rounding-mode operand; rm=111 uses frm. Encoded funct5=11010 and fmt=10 select target H, while rs2=00000 selects signed W integer source.
rs2 selects integer source width and signedness, not a second assembly source register; integer-to-H conversion rounds according to rm/frm.
ZfhFloating-Point Convert

Instruction Behavior

fcvt.h.w converts the signed 32-bit integer in x[rs1] to a half-precision result in f[rd]. Its OP-FP encoding uses funct5=11010, fmt=H (10), and rs2=W (00000); an inexact result rounds according to rm or dynamic frm and records applicable fflags.

FCVT.H.W Decode And Execute Animation

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

rd
rs1
rm
fcvt.h.w
,
,
Execution Context
fmt=H (10)
rs2=W
rounding: RNE nearest-even
fflags: 0
31..27
26..25
24..20
19..15
14..12
11..7
6..0
11010
FCVT.H
10
fmt=H
00000
rs2=W
01011
rs1
000
rm
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0xD4058553
opcode
1010011 -> OP-FP
funct5/fmt
11010 + 10 -> FCVT.H.W
rs2
00000 -> W source
rm
000 -> RNE nearest-even
rd/rs1
fa0(f10) / a1(x11)
read
a1(x11) = -42
convert
int32 -42 -> H -42.0
write
fa0(f10) = -42.0; 0
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: 0xD4058553
syntax : fcvt.h.w fa0(f10), a1(x11), rne
result : fa0(f10) = -42.0; 0

The current 32-bit integer example is exactly representable as H format, so example fflags remains 0.

FCVT Conversion View
W source
-42
conversion
int32 -42 -> H -42.0
writeback
fa0(f10) = -42.0

The current 32-bit integer example is exactly representable as H format, so example fflags remains 0.

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.h.w converts a signed 32-bit integer source to a half-precision floating-point result. If the value is not exactly representable, the result is rounded according to rm and written to f[rd].

OP-FP funct5=11010, fmt=H (10), and rs2=W (00000) select FCVT.H.W; rs2 is an integer width/signedness selector, not a register operand.
W/WU forms read a 32-bit signed or unsigned integer source value.
The integer source operand comes from x[rs1], not a floating-point register, so there is no source NaN-boxing requirement.
The floating-point result is NaN-boxed in wider FLEN registers according to the destination format.

Common Usage Scenarios

Type Conversion

Understand this scenario with real code like «fcvt.h.w f10, x11, rne ; f10 = (half)x11».

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

W/WU forms read a 32-bit signed or unsigned integer source value.
The integer source operand comes from x[rs1], not a floating-point register, so there is no source NaN-boxing requirement.
The floating-point result is NaN-boxed in wider FLEN registers according to the destination format.

FAQ

When does rm matter for fcvt.h.w?

When the integer value cannot be exactly represented in the destination floating-point format, rm or dynamic frm selects the rounding direction.

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

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