# Microprocessor Design/FPU

Similar to the ALU is the Floating-Point Unit, or FPU. The FPU performs arithmetic operations on floating point numbers.

An FPU is complicated to design, although the IEEE 754 standard helps to answer some of the specific questions about implementation. It isn't always necessary to follow the IEEE standard when designing an FPU, but it certainly does help.

## Floating point numbers

This section is just going to serve as a brief refresher on floating point numbers. For more information, see the Floating Point book.

Floating point numbers are specified in two parts: the exponent (e), and the mantissa (m). The value of a floating point number, v, is generally calculated as:

${\displaystyle v=m\times 2^{e}}$

### IEEE 754

IEEE 754 format numbers are calculated as:

${\displaystyle v=(1+m)\times 2^{e}}$

The mantissa, m, is "normalized" in this standard, so that it falls between the numbers 1.0 and 2.0.

### Floating Point Multiplication

Multiplying two floating point numbers is done as such:

${\displaystyle v_{1}\times v_{2}=(m_{1}\times m_{2})\times 2^{(e_{1}+e_{2})}}$

Likewise, division can be performed by:

${\displaystyle {\frac {v_{1}}{v_{2}}}={\frac {m_{1}}{m_{2}}}\times 2^{(e_{1}-e_{2})}}$

To perform floating point multiplication then, we can follow these steps:

1. Separate out the mantissa from the exponent
2. Multiply (or divide) the mantissa parts together
3. Add (or subtract) the exponents together
4. Combine the two results into the new value
5. Normalize the result value (optional).

Floating point addition—and by extension, subtraction— is more difficult than multiplication. The only way that floating point numbers can be added together is if the exponents of both numbers are the same. This means that when we add two numbers together, we need first to scale the numbers so that they have the same exponent. Here is the algorithm:

1. Separate the mantissa from the exponent of each number
2. Compare the two exponents, and determine the difference between them.
3. Add the difference to the smaller exponent, to make both exponents the same.
4. Logically right-shift the mantissa of the number with the smaller exponent a number of spaces equal to the difference.
5. Add the two mantissas together
6. Normalize the result value (optional).

## Floating Point Unit Design

As we have seen from the two algorithms above, an FPU needs the following components:

• A comparator (subtractor) to determine the difference between exponents, and to determine the smaller of the two exponents.
• An adder unit to add that difference to the smaller exponent.
• A shift unit, to shift the mantissa the specified number of spaces.