Webcentive RISC-V Reference

D instructions

Double-precision floating-point

The D extension adds double-precision floating-point computational instructions compliant with the IEEE 754-2008 arithmetic standard. The D extension depends on the base single-precision instruction subset F.

D Register State

The D extension widens the 32 floating-point registers, f0-f31, to 64 bits (FLEN=64 in fprs. The f registers can now hold either 32-bit or 64-bit floating-point values as described below in nanboxing.

Note

FLEN can be 32, 64, or 128 depending on which of the F, D, and Q extensions are supported. There can be up to four different floating-point precisions supported, including H, F, D, and Q.

NaN Boxing of Narrower Values

When multiple floating-point precisions are supported, then valid values of narrower n-bit types, n<FLEN, are represented in the lower n bits of an FLEN-bit NaN value, in a process termed NaN-boxing. The upper bits of a valid NaN-boxed value must be all 1s. Valid NaN-boxed n-bit values therefore appear as negative quiet NaNs (qNaNs) when viewed as any wider m-bit value, n < m ≤ FLEN. Any operation that writes a narrower result to an 'f' register must write all 1s to the uppermost FLEN-n bits to yield a legal NaN-boxedvalue.

Note

Software might not know the current type of data stored in a floating-point register but has to be able to save and restore the register values, hence the result of using wider operations to transfer narrower values has to be defined. A common case is for callee-saved registers, but a standard convention is also desirable for features including varargs, user-level threading libraries, virtual machine migration, and debugging.

Floating-point n-bit transfer operations move external values held in IEEE standard formats into and out of the f registers, and comprise floating-point loads and stores (FLn/FSn) and floating-point move instructions (FMV.n.X/FMV.X.n). A narrower n-bit transfer, n<FLEN, into the f registers will create a valid NaN-boxed value. A narrower n-bit transfer out of the floating-point registers will transfer the lower n bits of the register ignoring the upper FLEN-n bits.

Apart from transfer operations described in the previous paragraph, all other floating-point operations on narrower n-bit operations, n<FLEN, check if the input operands are correctly NaN-boxed, i.e., all upper FLEN-n bits are 1. If so, the n least-significant bits of the input are used as the input value, otherwise the input value is treated as an n-bit canonical NaN.

Tip

Earlier versions of this document did not define the behavior of feeding the results of narrower or wider operands into an operation, except to require that wider saves and restores would preserve the value of a narrower operand. The new definition removes this implementation-specific behavior, while still accommodating both non-recoded and recoded implementations of the floating-point unit. The new definition also helps catch software errors by propagating NaNs if values are used incorrectly.

Non-recoded implementations unpack and pack the operands to IEEE standard format on the input and output of every floating-point operation. The NaN-boxing cost to a non-recoded implementation is primarily in checking if the upper bits of a narrower operation represent a legal NaN-boxed value, and in writing all 1s to the upper bits of a result.

Recoded implementations use a more convenient internal format to represent floating-point values, with an added exponent bit to allow all values to be held normalized. The cost to the recoded implementation is primarily the extra tagging needed to track the internal types and sign bits, but this can be done without adding new state bits by recoding NaNs internally in the exponent field. Small modifications are needed to the pipelines used to transfer values in and out of the recoded format, but the datapath and latency costs are minimal. The recoding process has to handle shifting of input subnormal values for wide operands in any case, and extracting the NaN-boxed value is a similar process to normalization except for skipping over leading-1 bits instead of skipping over leading-0 bits, allowing the datapath muxing to be shared.

Extension description from riscv-unified-db, reformatted.

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

Instructions (51)

MnemonicName (riscv-unified-db)XLEN
c.fldLoad double-precisionRV32 and RV64
c.fldspLoad doubleword into floating-point register from stackRV32 and RV64
c.fsdStore double-precisionRV32 and RV64
c.fsdspStore double-precision value to stackRV32 and RV64
fabs.d (pseudo-op)RV32 and RV64
fadd.dFloating-Point Add Double-PrecisionRV32 and RV64
fclass.dFloating-Point Classify Double-PrecisionRV32 and RV64
fcvt.d.hFloating-Point Convert Half-Precision to Double-PrecisionRV32 and RV64
fcvt.d.lFloating-Point Convert Long to Double-PrecisionRV64 only
fcvt.d.luFloating-Point Convert Unsigned Long to Double-PrecisionRV64 only
fcvt.d.sFloating-Point Convert Single-Precision to Double-PrecisionRV32 and RV64
fcvt.d.wFloating-Point Convert Word to Double-PrecisionRV32 and RV64
fcvt.d.wuFloating-Point Convert Unsigned Word to Double-PrecisionRV32 and RV64
fcvt.h.dFloating-point Convert Double-precision to Half-precisionRV32 and RV64
fcvt.l.dFloating-Point Convert Double-Precision to LongRV64 only
fcvt.lu.dFloating-Point Convert Double-Precision to Unsigned LongRV64 only
fcvt.s.dFloating-Point Convert Double-Precision to Single-PrecisionRV32 and RV64
fcvt.w.dFloating-Point Convert Double-Precision to WordRV32 and RV64
fcvt.wu.dFloating-Point Convert Double-Precision to Unsigned WordRV32 and RV64
fcvtmod.w.dFloating-Point Convert Double-Precision to Word with ModuloRV32 and RV64
fdiv.dFloating-Point Divide Double-PrecisionRV32 and RV64
feq.dFloating-Point Equal Double-PrecisionRV32 and RV64
fldFloating-Point Load Double-PrecisionRV32 and RV64
fle.dFloating-Point Less Than or Equal Double-PrecisionRV32 and RV64
fleq.dFloating-Point Less Than or Equal Quiet Double-PrecisionRV32 and RV64
fli.dFloating-Point Load Immediate Double-PrecisionRV32 and RV64
flt.dFloating-Point Less Than Double-PrecisionRV32 and RV64
fltq.dFloating-Point Less Than Quiet Double-PrecisionRV32 and RV64
fmadd.dFloating-Point Multiply-Add Double-PrecisionRV32 and RV64
fmax.dFloating-Point Maximum-Number Double-PrecisionRV32 and RV64
fmaxm.dFloating-Point Maximum-Number NaN Double-PrecisionRV32 and RV64
fmin.dFloating-Point Minimum-Number Double-PrecisionRV32 and RV64
fminm.dFloating-Point Minimum-Number NaN Double-PrecisionRV32 and RV64
fmsub.dFloating-Point Multiply-Subtract Double-PrecisionRV32 and RV64
fmul.dFloating-Point Multiply Double-PrecisionRV32 and RV64
fmv.d (pseudo-op)RV32 and RV64
fmv.d.xFloating-Point Move Double-Precision from Integer RegisterRV64 only
fmv.x.dFloating-Point Move Double-Precision to Integer RegisterRV64 only
fmvh.x.dFloating-Point Move High Half from Double-Precision Register to Integer RegisterRV32 only
fmvp.d.xFloating-Point Move Pair from Integer Registers to Double-Precision RegisterRV32 only
fneg.d (pseudo-op)RV32 and RV64
fnmadd.dFloating-Point Negate-Multiply-Add Double-PrecisionRV32 and RV64
fnmsub.dFloating-Point Negate-Multiply-Subtract Double-PrecisionRV32 and RV64
fround.dFloating-Point Round Double-PrecisionRV32 and RV64
froundnx.dFloating-Point Round-to-Integer Inexact Double-PrecisionRV32 and RV64
fsdFloating-Point Store Double-PrecisionRV32 and RV64
fsgnj.dFloating-Point Sign-Inject Double-PrecisionRV32 and RV64
fsgnjn.dFloating-Point Sign-Inject Negate Double-PrecisionRV32 and RV64
fsgnjx.dFloating-Point Sign-Inject XOR Double-PrecisionRV32 and RV64
fsqrt.dFloating-Point Square Root Double-PrecisionRV32 and RV64
fsub.dFloating-Point Subtract Double-PrecisionRV32 and RV64