CS251 - Computer Organization and Design - Spring 2008
Lecture 13 - Floating Point
Practical Details
- Assignment 2, giving back.
- Assignment 3
- One assignment 1 without a name
- Starting to add to `Printed Notes'.
Multiplication
Long multiplication, the algorithm you know and love from grade school
- Multiply the right most digit by the multiplicand
- result is first step toward product
- Repeat until no more digits
- multiply next digit by multiplicant
- add one to shifter
- shift result left by amount in shifter
- add to product
This is hard because multiplying base ten is hard
- What is 7 times 8?
- Was I carrying five or six?
But we can all multiply by 1 and 0, no problem, so try this algorithm
product is zero
Repeat 32 times
- If LSB of multiplier is 1 then
- add multiplicand to product
- Shift multiplier 1 bit right
- Shift multiplicand 1 bit left
Version 2
Shift product register instead of multiplicand register
Version 3
High word of product is zero; low word of product is multiplier
Repeat 32 times
- If LSB of product is 1 then
- add multiplicand to high word of product
- Shift product 1 bit right.
Barrel shifter
I hope that you (not equal to `You may have') noticed that a lot of
shifting is done.
- For this reason the barrel shifter is just as
important as the ALU in making a CPU fast.
A barrel shifter can be
- left/right shifting (LS/RS)
- cyclic:
- RS: low order bits fill in high order bits
- LS: high order bits fill in low order bits
- sign-extending:
- RS: ones or zeros fill in high order bits
- LS: ones or zeros fill in low order bits
- etc.
Once you understand the basic hardware implementation of a barrel shifter
the variations are obvious
Implementation
Implement using multiplexors
Example: 4-bit barrel shifter
- from 4to1 multiplexors
- from 2 to 1 multiplexors
Floating Point Numbers
Representation
Sign, exponent, significand (mantissa)
- 1 bit for sign
- 8 bits for exponent (7 bit bias in representation)
- 23 bits for significand
- the fractional part of a binary number between 1 and 2:
1.xxxxxxxxxxxx (23 x's)
- Store only the x's
- This is what it means for the significand to be normalized.
Value is sign * (1 + significand) * 2^(exponent - bias)
Distribution
Clustering matters in practice
- smallest significant: ss = 1
- largest significand: ls = 2^(23)
Exponent | smallest | largest | delta
================================================
bias | -2 | 2 | 2^(-23)
0 | -2^(-127) | 2^(-127) | 2^(-151)
256 | -2^(129) | 2^(129) | 2^(105)
================================================
Double Precision
64 bit number
- 1 bit for sign
- 11 bits for exponent
- 52 bits for significand
And there is even extended precision
What goes wrong
- Addition
- Multiplication/division
Importance of NaN.
Where are these problems observed?
- Computer graphics
- Statistics
Algorithms for Addition and Multiplication
Addition/Subtraction
- Equalize exponents
- Shift right significand of number with smaller exponent
- Add 1 to its exponent
- Until exponents are equal
- Add/subtract significands
- Normalize result
- Shift significand left or right
- Add 1 to or subtract 1 from exponent
- Until significand is normalized
Multiplication (Division)
- Add (subtract) exponents
- Multiply significands
- Normalize result
Pathologies
Exponent can overflow or underflow.
Significand can underflow
NaN (Not a Number)
Possible values
- Too large to represent
- Too small to represent
- Infinity
- Underflow
Return to: