Docsity

Floating Point Computer Arithmetic: From Binary to IEEE Standard - Prof. Roger L. Haggard, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Floating Point Computer Arithmetic: From Binary to IEEE Standard - Prof. Roger L. Haggard and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Floating-Point Computer Arithmetic

ECE 4120 – Fundamentals of Computer Design

Dr. Roger L. Haggard, Associate Professor

Department of Electrical and Computer Engineering

Tennessee Technological University

Spring 2004

Floating Point Numbers Systems - Introduction

 Can represent both integers and fractions with much wider range of

values

 N bits still represent up to 2N^ values, but interpret differently

 Scientific notation in base 10 FPNS:

- 2.34 * 10^12 = - 2.34 E

Mantissa Base Exponent sign - 10 sign + mag 2.34 ** mag 12 *radix 10 *radix 10

  • = usually assumed, not written with number ** = can be assumed \ Every number must contain: mantissa sign + mag / - / 2.34 / exponent sign + mag / + / 12 /

FPNS Basics (2)

 Mantissa is fixed point  assume value of p

  • Normalization = convert number so that the msd  0, giving maximum

precision for the number

  • Usually p = m, so mantissa is a pure fraction

\ VMMIN = 0.1000… = 1/ rb

\ VMMax = 0.1111… = 1- rb-m

 Number of legal mantissas = NLM = (rb - 1) * rbm-

possible 1st digit other digits

 Number of legal exponents = NLE = ree^ (code-dependent)

 Number of representable values = NRV = NLM * NLE * 2 (signed!)

 Min FP value = VMIN = VMMIN * rbVE,MIN

 Max FP value = VMAX = VMMAX * rbVE,MAX

so value = (sign) * 0.mmmm * 2ee

  • 7 - Bit Example
  •  FPNS with: rb = 2, re = 2, m = 4, e = 2, p = m = - (S/M) (unsigned) normalized, msd =
  • VMMIN = 0.1000 2 = 1/2 NLM =
  • VMMAX = 0.1111 2 = 15/ - NRV = 8 * 4 * 2 =
  • VEMIN = 00 2 = 0 NLE =
  • VEMAX = 11 2 =
  • VMAX = .1111 2 * 2^112 = 15/16 * 8 = 7 1/ - = .0001 * 2^3 = 1/ VMIN = .1000 2 * 2^002 = 1/2 * 1 = 1/2 IF Ve = 3  Dr

IEEE Floating Point Standard (Std 754)

V = (-1) S^ * 1.mmm… m * 2xxxxxxxx^ SE = VE + 127 V = (-1) S^ * VM * 2 VE

SE = 0  VFPN = 0 if VM = 0 SE = 1  VE = - Normal SE = 127  VE = 0 SE = 254  VE = + SE = 255  VFPN = NaN or infinty

S e e e e e e e e m m m m m m m m m m m m m m m m m m m m m m m

31 30 23 22 1 0

 rb = 2, re = 2, m = 24, e = 8, p = m = 23 (S/M) (unsigned, excess 127) MSB hidden, not stored

VMMIN = 1.00… 0 2 = 1 NLM = 2^23

VMMAX = 1.11… 1 2 = 2-2-23^ NRV = 2^23 * 254 * 2

VEMIN = 1 - 127 = -126 NLE = 2^8 - 2 = 254 = 4.2 * 10^9

VEMAX = 254 - 127 = +

VMIN = 1.00… 0 * 2-126^ @ 1.2 * 10-

VMAX = 1.11… 1 * 2+127^ @ 3.4 * 10+

IEEE Floating Point Standard (Std 754)

 223 @ 8 * 10^6 @ 7 significant decimal digits (Dr = 2-23^ * 2VE)

 Gradual underflow:

  • V < 2-126 (denormalized) when SE = 0, VM  0 (Hidden bit = 0)

 Error reporting:

  • NaN (Not a Number): 0/0,  /, /0, (NaN op X)  SE = 255, VM  0
  • Infinity: when |V| > 2 * 2^127  SE = 255, VM = 0

IEEE FPNS Addition

Floating Point Add (Positive Operands):

\”Align” smaller value

1.2 * 10^2 .12 * 10^3 (Shift Right 1)

+ 2.4 * 10^3 + 2.4 * 10^3

? 2.52 * 10^3

1.01 * 2^3 1.01 * 2^3

+ 1.11 * 2^2 + .111 * 2^3 (SR1)

? 10.001 * 2^3

“Post Normalize” = SR

1.0001 * 2^4

IEEE FPNS Addition Hardware Diagram

EA

Compare

EB

Databus (31:0)

Databus (31:0)

8

8

32 8

32

8 8

Adjust E

D

EY

8

MA MB

23

23

24 24

Normalize M

MY

23

0

SY

Align MA Align MB 24 24 ACout (^) F CinB

1 23

M (^24 24) M23-

SR (n)

SR (1)

Select + Increment for Normalize

Reg3S 3S Reg 3S Reg

1

Version 1 (2)

EA  DB(30:23)

MA  1, DB(22:0), ;hidden bit MSB

EB  DB(30:23)

MB  1, DB(22:0) ;hidden bit MSB

1. Load A + B

D = EA - EB

If D < 0 then --- A smaller

E = EB

Shift Right MA by |D|  MA*

Else (D  0) --- B smaller

E = EA

Shift Right MB by D  MB*

Endif

2. Align

Version 1 (3)

If M 24 = 1 then

Shift Right M by 1

E = E + 1

Endif

MY  M

EY  E

SY  0

4. Normalize

5. Store Y

Version 1S (2)

D = EA - EB

IF D  24 then -- B very small

MB* = 0

E = EA

Elseif D  0 then -- B smaller

Shift Right MB by D  MB*

E = EA

Elseif D -24 then -- A very small

MA* = 0

E = EB

Else (D < 0) -- A smaller

Shift Right MA by |D| MA*

E = EB

Endif

2. Align

IEEE FPNS Addition/Subtraction

Solve:

Need 2 extra bits:

() A 1.10 * 2^2 2’s comp. 001.

 ( ) B - 1.11 * 2^2 + 110.

() Y - .01 * 2^2 111.

Negate Mantissa & Sign

  • 000.01 * 2^2 Normalize (SL2)
  • 1.00 * 2^0

S = 1

IEEE FPNS Addition/Subtraction Algorithm

Version 2 (1)

1. Load A + B

2. Align

3. Add or Sub Mantissas

4. Normalize

5. Store Y

FP ADD/SUB

(overall)

Version 2 (2)

SA  DB(31)

EA  DB(30:23)

MA  1, DB(22:0) ;hidden bit MSB

SB DB(31)

EB DB(30:23)

MB 1, DB(22:0) ;hidden bit MSB

1. Load A + B

2. Align Same as V1S Align