Webcentive RISC-V Reference

Zfhmin instructions

Minimal half-precision floating-point

Zfhmin provides minimal support for 16-bit half-precision binary floating-point instructions. The Zfhmin extension is a subset of the Zfh extension, consisting only of data transfer and conversion instructions. Like Zfh, the Zfhmin extension depends on the single-precision floating-point extension, F. The expectation is that Zfhmin software primarily uses the half-precision format for storage, performing most computation in higher precision.

The Zfhmin extension includes the following instructions from the Zfh extension: flh, fsh, fmv.x.h, fmv.h.x, fcvt.s.h, and fcvt.h.s. If the D extension is present, the fcvt.d.h and fcvt.h.d instructions are also included. If the Q extension is present, the fcvt.q.h and fcvt.h.q instructions are additionally included.

Note

Zfhmin does not include the fsgnj.h instruction, because it suffices to instead use the fsgnj.s instruction to move half-precision values between floating-point registers.

Half-precision addition, subtraction, multiplication, division, and square-root operations can be faithfully emulated by converting the half-precision operands to single-precision, performing the operation using single-precision arithmetic, then converting back to half-precision. cite:[roux:hal-01091186] Performing half-precision fused multiply-addition using this method incurs a 1-ulp error on some inputs for the RNE and RMM rounding modes.

Conversion from 8- or 16-bit integers to half-precision can be emulated by first converting to single-precision, then converting to half-precision. Conversion from 32-bit integer can be emulated by first converting to double-precision. If the D extension is not present and a 1-ulp error under RNE or RMM is tolerable, 32-bit integers can be first converted to single-precision instead. The same remark applies to conversions from 64-bit integers without the Q extension.

Extension description from riscv-unified-db, reformatted.

Specification chapter: The RISC-V Instruction Set Manual, src/unpriv/zfhmin.adoc.

Instructions (10)

MnemonicName (riscv-unified-db)XLEN
fcvt.d.hFloating-Point Convert Half-Precision to Double-PrecisionRV32 and RV64
fcvt.h.dFloating-point Convert Double-precision to Half-precisionRV32 and RV64
fcvt.h.qFloating-point Convert Quad-precision to Half-precisionRV32 and RV64
fcvt.h.sConvert single-precision float to a half-precision floatRV32 and RV64
fcvt.q.hFloating-point Convert Half-precision to Quad-precisionRV32 and RV64
fcvt.s.hConvert half-precision float to a single-precision floatRV32 and RV64
flhHalf-precision floating-point loadRV32 and RV64
fmv.h.xHalf-precision floating-point move from integerRV32 and RV64
fmv.x.hMove half-precision value from floating-point to integer registerRV32 and RV64
fshHalf-precision floating-point storeRV32 and RV64