Webcentive RISC-V Reference

fadd.s

Floating-Point Add Single-Precision

Extension
F
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
fadd.s fd, fs1, fs2, rm
Length
32-bit

Encoding

312726252420191514121176210
0000000rs2rs1rmrd1010011

Match 0x00000053, mask 0xfe00007f. Source: fadd.s rd rs1 rs2 31..27=0x00 rm 26..25=0 6..2=0x14 1..0=3 in riscv-opcodes/extensions/rv_f.

FieldBitsriscv-opcodes name
rs224:20rs2
rs119:15rs1
rm14:12rm
rd11:7rd

Description

The fadd.s instruction performs single-precision floating-point addition of fs1 and fs2 and writes the final result to fd.

Description from riscv-unified-db, reformatted.

Operation

check_f_ok($encoding);
RoundingMode mode = rm_to_mode(rm, $encoding);
Bits<32> a = F[fs1];
Bits<32> b = F[fs2];

if (implemented?(ExtensionName::D)) {
  # check for incorrectly NaN-boxed inputs
  if (F[fs1][63:32] != 32'hffffffff) {
    a = SP_CANONICAL_NAN;
  }
  if (F[fs2][63:32] != 32'hffffffff) {
    b = SP_CANONICAL_NAN;
  }
}

F[fd] = f32_add(a, b, mode);

mark_f_state_dirty();

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages