CS251 - Computer Organization and Design - Spring 2008

Lecture 13 - Floating Point


Practical Details

  1. Assignment 2, giving back.
  2. Assignment 3
  3. One assignment 1 without a name
  4. Starting to add to `Printed Notes'.

Multiplication

Long multiplication, the algorithm you know and love from grade school

  1. Multiply the right most digit by the multiplicand
  2. Repeat until no more digits
    1. multiply next digit by multiplicant
    2. add one to shifter
    3. shift result left by amount in shifter
    4. add to product

This is hard because multiplying base ten is hard

But we can all multiply by 1 and 0, no problem, so try this algorithm

product is zero

Repeat 32 times

  1. If LSB of multiplier is 1 then
  2. Shift multiplier 1 bit right
  3. 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

  1. If LSB of product is 1 then
  2. 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.

A barrel shifter can be

Once you understand the basic hardware implementation of a barrel shifter the variations are obvious

Implementation

Implement using multiplexors

Example: 4-bit barrel shifter


Floating Point Numbers

Representation

Sign, exponent, significand (mantissa)

Value is sign * (1 + significand) * 2^(exponent - bias)

Distribution

Clustering matters in practice

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

And there is even extended precision

What goes wrong

  1. Addition
  2. Multiplication/division

Importance of NaN.

Where are these problems observed?

Algorithms for Addition and Multiplication

Addition/Subtraction

  1. Equalize exponents
    1. Shift right significand of number with smaller exponent
    2. Add 1 to its exponent
    3. Until exponents are equal
  2. Add/subtract significands
  3. Normalize result
    1. Shift significand left or right
    2. Add 1 to or subtract 1 from exponent
    3. Until significand is normalized

Multiplication (Division)

  1. Add (subtract) exponents
  2. Multiply significands
  3. Normalize result

Pathologies

Exponent can overflow or underflow.

Significand can underflow

NaN (Not a Number)

Possible values

  1. Too large to represent
  2. Too small to represent
  3. Infinity
  4. Underflow

Return to: