FSUB.D

RISC-V FSUB.D Instruction Details

Instruction ManualR-type

Performs double-precision floating-point subtraction: rd = rs1 - rs2, rounded by the rm field or dynamic frm.

Instruction Syntax

fsub.d rd, rs1, rs2, rm
Operand Breakdown
rd: destination floating-point register receiving the formatted result.
rs1/rs2: source floating-point registers; arithmetic/rounding forms with rm use rm or dynamic frm for rounding mode.
DFloating-Point Arithmetic

Instruction Behavior

FSUB.D subtracts the double-precision floating-point value in rs2 from rs1 and writes the result to rd. This R-type OP-FP instruction uses fmt=D(01), with rs2 as the subtrahend; rounding is selected by rm or by frm when rm is DYN, and its applicable exception flags are NV, OF, and NX, accrued in fflags. If FLEN is greater than 64, double-precision inputs are checked using NaN-boxing and inputs whose upper bits are not all 1s are treated as canonical NaN.

FSUB.D Decode And Execute Animation

Shows the D-extension double-precision OP-FP flow: decode fields, read FP operands, perform FSUB semantics, then write rd.

rd
rs1
rs2
rm
fsub.d
,
,
,
Execution Context
FLEN=>=64 / fmt=D (01)
rounding: RNE nearest-even
fflags: initial 0
31..27
26..25
24..20
19..15
14..12
11..7
6..0
00001
FSUB
01
fmt=D
01100
rs2
01011
rs1
000
rm
01010
rd
1010011
OP-FP
Execution Data Path
instruction
0x0AC58553
opcode
1010011 -> OP-FP
funct5/fmt
00001 + D(01) -> FSUB.D
rm
000 -> RNE nearest-even
rd/rs
fa0(f10) / fa1(f11) / fa2(f12)
read
Source registers not read yet
FP op
Awaiting Execute
write
Not written yet; initial fflags=0
Current Step

Fetch: show the 32-bit OP-FP encoding

The word is split as an R-type OP-FP instruction; double-precision OP-FP instructions use opcode 1010011.

encoding: 0x0AC58553
syntax : fsub.d fa0(f10), fa1(f11), fa2(f12), rne
result : Not written yet; initial fflags=0

This animation accepts only finite whitelisted examples whose inputs and result are exactly checkable; this example needs no rounding and sets no FP exception flags. NaN, infinity, overflow, underflow, and inexact paths are covered in static text.

Double-precision Calculation
rs1
fa1(f11) = 7.5
rs2
fa2(f12) = 2.25
result
Awaiting Execute

This animation accepts only finite whitelisted examples whose inputs and result are exactly checkable; this example needs no rounding and sets no FP exception flags. NaN, infinity, overflow, underflow, and inexact paths are covered in static text.

Assumes the extension is available, FS enabled, correctly NaN-boxed inputs, and initial fflags=0. Only nonzero finite exact whitelisted inputs and nonzero whitelisted results are accepted; zero and rounding/exception boundaries are outside this animation. One source register must have one initial value; rd may overlap a source, and f0 accepts writeback. Steps are teaching views.

This animation shows only D-extension ISA-visible OP-FP encoding, example numeric results, and fflags relationship; it does not model FPU pipelines, latency, every IEEE 754 corner case, or microarchitecture.

Quick Understanding & Search Notes

FSUB.D is D-extension double-precision subtraction: the semantic order is rs1 - rs2, not rs2 - rs1; fmt=01 selects D format, and rm/frm controls rounding and may affect fflags.

The OP-FP opcode is 1010011; funct5 selects FADD/FSUB/FMUL, and fmt=01 selects the D double-precision format.
The rm field selects a static rounding mode; rm=111 uses the dynamic rounding mode from fcsr.frm.
FSUB.D has applicable exception flags NV, OF, and NX; it does not produce UF or DZ, and the flags accrue in fflags.
NaN results use the canonical NaN; when FLEN is greater than 64, double-precision values must satisfy NaN-boxing.
Available on RV32 and RV64; D depends on F, and F depends on Zicsr. In a privileged environment, FS=Off makes accesses to FP state raise an illegal-instruction exception.

Common Usage Scenarios

Double-precision numerical computing

Understand this scenario with real code like «fsub.d fa0, fa1, fa2, rne # fa0 = fa1 - fa2».

Floating-point arithmetic

Understand this scenario with real code like «fsub.d fa0, fa1, fa2, rne # fa0 = fa1 - fa2».

Pre-Use Checklist

Syntax Check
  • rd: destination floating-point register receiving the formatted result.
  • rs1/rs2: source floating-point registers; arithmetic/rounding forms with rm use rm or dynamic frm for rounding mode.
Semantic Check
  • Confirm 64-bit D format and FP inputs match, with valid NaN-boxing in wider FLEN.
  • Inspect accrued fflags for NV, OF, NX when needed; setting FP exception flags does not itself trap.

Pitfalls / Common Confusions

rm=111 means the dynamic rounding mode from frm; other reserved rm encodings should not be used as legal examples.
FSUB.D can accrue only NV, OF, and NX, not UF or DZ; the exact example result does not represent every input.
If implemented FLEN is greater than 64, double-precision inputs must be properly NaN-boxed; otherwise they are treated as canonical NaN.

FAQ

What is the main difference between FSUB.D and FSUB.S?

FSUB.D uses the D-extension double-precision format with fmt=01 and operates on 64-bit floating-point values; FSUB.S uses the F-extension single-precision format with fmt=00 and operates on 32-bit values.

When does the rm field affect FSUB.D?

When the difference is not exactly representable in the target double-precision format or overflows, rm or dynamic frm selects rounding; the applicable flags are NX, OF, and NV.

Does FSUB.D modify integer registers?

No. rd, rs1, and rs2 are floating-point register fields; the result is written to FP rd, not to an integer x register.

Can rm be omitted?

Omitting rm in assembly defaults to dyn and uses frm; explicit rne selects static nearest-even rounding. Behavior for static rm=101/110 or dynamic frm=101/110/111 is reserved; a trap is not universally required.

What are the fflags and animation assumptions?

FP exception flags accrue in fflags; the base ISA does not trap on setting them. The animation assumes the extension is available, FP state is enabled, inputs are correctly NaN-boxed, and initial fflags=0. It accepts only nonzero finite exact whitelisted inputs and nonzero whitelisted results, excluding zero, NaN, infinity, overflow, underflow, and inexact paths. With wider FLEN, result upper bits are all 1s for valid NaN-boxing.