Floating point hardware implementation

Now when we compared FP and integer arithmetics one would expect hardware implementation to also be vastly different. Let’s take a closer look at what instructions are available for floating point data in MIPS and discuss some important implementation details.

FP arithmetics is performed by a compute logic, separate from ALU, called Floating Point Processor or Floating Point Unit - FPU (Coprocessor 1).

FPU contains 32 single precision FP registers: $f0, $f1 … $f31. The same registers can also act as 16 double precision FP registers: [$f0, $f1]…[$f30, $f31]. Only first registered is specified in the instruction.

Floating point arithmetics cannot be performed in a single cycle, unlike integer arithmetics.

You cannot mix FP registers and Integer registers in the same instruction, except for load instruction.

Instruction set

Instruction set for FP is very similar to its Integer counterparts, but usually ends with s for single precision number or d for double precision ones.

Single precision arithmetic [+, -, *, /]:
add.s, sub.s, mul.s, div.s
Example: add.s $f0, $f1, $f2

Double precision arithmetic [+, -, *, /]:
add.d, sub.d, mul.d, div.d
Example: add.d $f0, $f2, $f4

Single precision comparison [==, <, <=]:
c.eq.s, c.lt.s, c.le.s,
Example: c.eq.s $f0, $f1
Note: There are no not equal, greater than, or greater equal FP instructions

Double precision comparison [==, <, <=]:
c.eq.d, c.lt.d, c.le.d,
Example: c.eq.d $f0, $f2
Note: There are no not equal, greater than, or greater equal FP instructions

Branch of FP condition [true, false]:
bc1t, bc1f
Example: bc1t label_1

Load and store word to/from coprocessor 1:
lwc1, swc1 OR l.s, s.s Example: lwc1 $f0, 0($t1)

Load and store double to/from coprocessor 1:
ldc1, sdc1 OR l.d, s.d Example: ldc1 $f0, 0($t1)

Move to/from coprocessor 1:
mtc1, mfc1
Example: mtc1 $f0 $r0

Convert between integer and floating point (word and single precision fp):
word -> single precision: cvt.s.w
single precision -> word: cvt.w.s
Example: cvt.s.w $f0 $f1

Convert between integer and floating point (word and double precision fp):
word -> single precision: cvt.d.w
single precision -> word: cvt.w.d
Example: cvt.d.w $f0 $f2

Other single precision operations [move, negate, absolute]:
mov.s, neg.s, abs.s
Example: mov.s $f0 $f1

Other double precision operations [move, negate, absolute]:
mov.d, neg.d, abs.d
Example: mov.d $f0 $f2

Sources

MIPS Assembly Programmming by Robert Winkler
SNS Institutions: MIPS Registers
University of Pittsburgh: MIPS Floating Point Instructions
The MIPS R4000 by Raymond C
MIPS Floating Point Architecture using PCSPIM by MicrocontrollersLab
Florida State University: MIPS floating point instructions
Wikipedia: x86 instruction listings
Wikipedia: Word (computer architecture)

28 Mar 2022 - Hasan Al-Ammori