risc-v

Definition

Floating-Point Instruction (RISC-V)

A floating-point instruction is a RISC-V instruction that operates on floating-point values in floating-point registers.

RISC-V offers three floating-point extensions:

  • RVF: single precision (32-bit)
    • 8 exponent bits
    • 23 fraction bits
  • RVD: double precision (64-bit)
    • 11 exponent bits
    • 52 fraction bits
  • RVQ: quad precision (128-bit)
    • 15 exponent bits
    • 112 fraction bits

List

Examples

Loop over an array

Consider the following C code:

int i;
float scores[200];
 
for (i = 0; i < 200; i = i + 1)
    scores[i] = scores[i] + 10;

One possible RISC-V translation is:

# s0 = scores base address, s1 = i
addi s1, zero, 0     # i = 0
addi t2, zero, 200   # t2 = 200
addi t0, zero, 10    # ft0 = 10.0
fcvt.s.w ft0, t0
 
for:
    bge s1, t2, done      # i >= 200? done
    slli t0, s1, 2
    add t0, t0, s0        # scores[i] address
    flw ft1, 0(t0)
    fadd.s ft1, ft1, ft0   # ft1 = scores[i] + 10
    fsw ft1, 0(t0)         # scores[i] = ft1
    addi s1, s1, 1         # i = i + 1
    j for                  # repeat
done:

Used instructions: