Home/Instructions/Fused Neg Multiply-Add Double
FNMADD.D

RISC-V FNMADD.D Instruction Details

Instruction ManualR4-type

double-precision negated fused multiply-add: rd = -(rs1 * rs2) - rs3, with one final rounding according to rm.

Instruction Syntax

fnmadd.d rd, rs1, rs2, rs3[, rm]
Operand Breakdown
rd, rs1, rs2, rs3: FP f0–f31 or ABI names; f0 is writable, rd may overlap a source, and equal sources read one initial value.
Optional lowercase rm defaults to dyn; rm=111 uses frm. Static 101/110 and dynamic frm=101–111 have reserved behavior.
DFloating-Point Arithmetic

Instruction Behavior

FNMADD.D uses R4 to compute -(rs1×rs2)-rs3. The product is not separately rounded; rm rounds the final fused expression once to a 64-bit double-precision result in FP register rd. It supports RV32/RV64 with D and enabled FP state.

FNMADD.D Decode And Execute Animation

Shows the D-extension double-precision R4 fused multiply-add flow: decode fields, read FP operands, perform FNMADD semantics, then write rd.

rd
rs1
rs2
rs3
rm
fnmadd.d
,
,
,
,

Leave rm empty to use the assembly default dyn encoding and fcsr.frm below.

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
01101
rs3
01
fmt=D
01100
rs2
01011
rs1
000
rm
01010
rd
1001111
NMADD
Execution Data Path
instruction
0x6AC5854F
opcode
1001111 -> NMADD
rs3/fmt
fa3(f13) + D(01) -> R4 FNMADD
rm
000 -> RNE nearest-even
rd/rs
fa0(f10) / fa1(f11) / fa2(f12) / fa3(f13)
read
Source registers not read yet
fused op
Awaiting Execute
write
Not written yet; initial fflags=0
Current Step

Fetch: show the 32-bit R4 encoding

The word is split as an R4-type instruction; FNMADD.D uses its dedicated major opcode 1001111, not the ordinary OP-FP opcode.

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

The default example -(1.5 * 2.0) - 0.5 = -3.5 is exactly checkable; the fused operation rounds once at the end, so example fflags remains 0.

Double-precision Calculation
rs1
fa1(f11) = 1.5
rs2
fa2(f12) = 2.0
rs3
fa3(f13) = 0.5
result
Awaiting Execute

The default example -(1.5 * 2.0) - 0.5 = -3.5 is exactly checkable; the fused operation rounds once at the end, so example fflags remains 0.

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 R4 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

FNMADD.D's key points are R4 encoding and fused semantics: rs3 is a real third source register, and the product plus/minus term forms one exact intermediate expression that is rounded only once.

Requires RV32/RV64 D and enabled FP state, with 64-bit double-precision operands and results. D depends on F.
32-bit R4: rs3[31:27] | fmt=01[26:25] | rs2[24:20] | rs1[19:15] | rm[14:12] | rd[11:7] | opcode=1001111[6:0].
rd, rs1, rs2 and rs3 select FP registers f0–f31; f0 is writable. rs3 is a third source, not an implicit old value of rd.
Optional rm defaults to dyn: 000/001/010/011/100 select rne/rtz/rdn/rup/rmm; 111 uses frm. Static 101/110 and dynamic frm=101–111 have reserved behavior.
Operands narrower than FLEN must be correctly NaN-boxed; otherwise they are treated as canonical NaNs in their format. Narrower results get upper FLEN bits set to ones.
Applicable NV, OF, UF and NX accrue in fflags; setting a flag does not itself cause an FP exception trap. Infinity times zero must set NV even if rs3 is a quiet NaN; NaN results use canonical NaN by default.
Negate the product, then subtract rs3. Do not infer signed-zero or directed-rounding results by separately fusing an addition and then negating it. The animation accepts only finite exact-whitelist inputs and nonzero exact-whitelist results, assuming valid NaN-boxing and initial fflags=0.

Common Usage Scenarios

Fused Floating Point

Assume required extensions and FP state enabled, f1=1.5, f2=2 and f3=0.5 in this format (validly NaN-boxed when narrower than FLEN), and initial fflags=0: the example writes the exact result f0=-(1.5×2)-0.5=-3.5; fflags remains 0.

Numerical Computing

Assume required extensions and FP state enabled, f1=1.5, f2=2 and f3=0.5 in this format (validly NaN-boxed when narrower than FLEN), and initial fflags=0: the example writes the exact result f0=-(1.5×2)-0.5=-3.5; fflags remains 0.

Pre-Use Checklist

Syntax Check
  • rd, rs1, rs2, rs3: FP f0–f31 or ABI names; f0 is writable, rd may overlap a source, and equal sources read one initial value.
  • Optional lowercase rm defaults to dyn; rm=111 uses frm. Static 101/110 and dynamic frm=101–111 have reserved behavior.
Semantic Check
  • Confirm rs3 participates in the fused operation and the result is rounded only once at the end.
  • Confirm the sign rules for FNMADD/FNMSUB match the intended operation.

Pitfalls / Common Confusions

FNMADD.D is a fused operation, not the same as FMUL followed by FADD/FSUB with two roundings.
In the R4 encoding, bits 31..27 are the rs3 field; do not decode them as an ordinary OP-FP R-type funct5 field.
rm controls the single final rounding; inexact, overflow, underflow, invalid-operation, and special-value paths are recorded by the official FP exception-flag rules.
The FNMSUB/FNMADD sign rules are easy to confuse: FNMSUB is -(rs1*rs2)+rs3, while FNMADD is -(rs1*rs2)-rs3.

FAQ

How is FNMADD.D different from FMUL plus add/subtract?

FNMADD.D is fused: the product is not first rounded into an intermediate FP result; the whole expression is rounded once at the end according to rm.

Why is FNMADD.D R4-type?

It needs rd, rs1, rs2, rs3, and rm fields; bits 31..27 hold rs3, not an ordinary R-type funct5 field.

Can FNMADD.D set fflags?

It can accrue NV, OF, UF and NX without clearing existing flags. Infinity times zero sets NV even with a quiet-NaN third source. The exact default example assumes initial fflags=0, so it remains 0.