ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 913 microarchs · 15,555 chips · 105 sources
Arch:
Tier:

fcvt.w.s

T1 riscv fp insn
Floating-Point Convert Single-Precision to Word
SourceRISC-V Official Unified Database (riscv-unified-db) (riscv_unified_db)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeRV32/RV64 F
RV32 / RV64 (Ratified & Standard Extensions)
License & VersionApache-2.0 / CC-BY-4.0
main
Upstreamhttps://github.com/riscv/riscv-unified-db
Privilegeuser
ExtensionsF

Summary

The fcvt.w.s instruction converts a floating-point number in floating-point register fs1 to a signed 32-bit integer in integer register xd. For XLEN >32, fcvt.w.s sign-extends the 32-bit result to the destination register width.

Syntax / Encoding

fcvt.w.s xd, fs1, rm | 110000000000xxxxxxxxxxxxx1010011 (mask=0xfff0007f match=0xc0000053)

Cross-Chip Latency & Throughput (11 cores)

MicroarchitectureLatency (cycles)Recip. TPuopsPortsSource
Tenstorrent Ascalon-X111AscalonFXAllvm_sched_models
Andes 45-Series211Andes45FMISCllvm_sched_models
SiFive P670 / P600211SiFiveP600F2Illvm_sched_models
SiFive P870 / P800211SiFiveP800F2Illvm_sched_models
SiFive 7-Series (U74)311PipeBllvm_sched_models
SpacemiT X10030.51SMTX100_FQ1llvm_sched_models
XiangShan KunMingHu311XSPipeFEX0llvm_sched_models
XiangShan NanHu30.251XS2FMACllvm_sched_models
MIPS P8700 (RISC-V)412p8700IssueFPUL+p8700FpuApullvm_sched_models
Syntacore SCR7412FPU_IS+FALUllvm_sched_models
SpacemiT X60 (K1)60.51SMX60_IEUllvm_sched_models

Binary Encodings (1)

WidthFormatBit PatternMask / Match
32RV110000000000xxxxxxxxxxxxx10100110xfff0007f / 0xc0000053

Operands

NameDescription
fs1bits [19:15]
rmbits [14:12]
xdbits [11:7]

Reference Notes

The `fcvt.w.s` instruction converts a floating-point number in floating-point register `fs1` to a
signed 32-bit integer in integer register `xd`. For XLEN >32, `fcvt.w.s` sign-extends the 32-bit
result to the destination register width.

If the rounded result is not representable as a 32-bit signed integer, it is clipped to the
nearest value and the invalid flag is set.

The range of valid inputs and behavior for invalid inputs are:

[separator="!"]
!===
! ! Value

h! Minimum valid input (after rounding) ! `-2^31`
h! Maximum valid input (after rounding) ! `2^31 - 1`
h! Output for out-of-range negative input ! `-2^31`
h! Output for `-∞` ! `-2^31`
h! Output for out-of-range positive input ! `2^31 - 1`
h! Output for `+∞` for `NaN` ! `2^31 - 1`
!===

All floating-point to integer and integer to floating-point conversion instructions round
according to the `rm` field.

A floating-point register can be initialized to floating-point positive zero using
`fcvt.s.w xd, x0`, which will never set any exception flags.

All floating-point conversion instructions set the Inexact exception flag if the rounded
result differs from the operand value and the Invalid exception flag is not set.