FCVT.S.W

RISC-V FCVT.S.W Instruction Details

Instruction ManualR-type

Convert signed int32 to SP FP: f[rd] = (float)rs1.

Instruction Syntax

fcvt.s.w rd, rs1, rm
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
FFloating-Point Convert

Instruction Behavior

fcvt.s.w converts a signed 32-bit integer source to a single-precision floating-point result. If the value is not exactly representable, the result is rounded according to rm and written to f[rd].

Quick Understanding & Search Notes

fcvt.s.w converts a signed 32-bit integer source to a single-precision floating-point result. If the value is not exactly representable, the result is rounded according to rm and written to f[rd].

The rs2/fmt encoding selects source and destination formats; the mnemonic suffixes carry the main semantic distinction.
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

Register Operations

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

Type Conversion

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

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • 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

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.s.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.s.w differ from related FCVT instructions?

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