Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 12: Integer Arithmetic and Floating Point CS 2011 Fall 2014, Dr. Rozier.

Similar presentations


Presentation on theme: "Lecture 12: Integer Arithmetic and Floating Point CS 2011 Fall 2014, Dr. Rozier."— Presentation transcript:

1 Lecture 12: Integer Arithmetic and Floating Point CS 2011 Fall 2014, Dr. Rozier

2 FULL ADDER SOLUTIONS

3 INTEGER ARITHMETIC

4 Putting Together Multiple Bits

5 Making it Faster Carry Look Ahead Adder

6 Making it Even Faster Carry-Select Adder Kogge-Stone Adder

7 How do we get subtraction? XB2T(X)B2U(X) 00000 00011 00102 00113 01004 01015 01106 01117 –88 –79 –610 –511 –412 –313 –214 –115 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7

8 How do we get subtraction? XB2T(X)B2U(X) 00000 00011 00102 00113 01004 01015 01106 01117 –88 –79 –610 –511 –412 –313 –214 –115 1000 1001 1010 1011 1100 1101 1110 1111 0 1 2 3 4 5 6 7 10010111 x 01101000 ~x+ 11111111

9 FLOATING POINT

10 Carnegie Mellon Fractional binary numbers What is 1011.101 2 ?

11 2i2i 2 i-1 4 2 1 1/2 1/4 1/8 2 -j bibi b i-1 b2b2 b1b1 b0b0 b -1 b -2 b -3 b -j Carnegie Mellon Fractional Binary Numbers Representation – Bits to right of “binary point” represent fractional powers of 2 – Represents rational number:

12 Carnegie Mellon Fractional Binary Numbers: Examples ValueRepresentation 5 3/4101.11 2 2 7/8010.111 2 63/64001.0111 2 Observations  Divide by 2 by shifting right  Multiply by 2 by shifting left  Numbers of form 0.111111… 2 are just below 1.0  1/2 + 1/4 + 1/8 + … + 1/2 i + … ➙ 1.0  Use notation 1.0 – ε

13 Carnegie Mellon Representable Numbers Limitation – Can only exactly represent numbers of the form x/2 k – Other rational numbers have repeating bit representations ValueRepresentation – 1/3 0.0101010101[01]… 2 – 1/5 0.001100110011[0011]… 2 – 1/10 0.0001100110011[0011]… 2

14 Floating Point Standard Defined by IEEE Std 754-1985 Developed in response to divergence of representations – Portability issues for scientific code Now almost universally adopted Two representations – Single precision (32-bit) – Double precision (64-bit)

15 IEEE Floating-Point Format S: sign bit (0  non-negative, 1  negative) Normalize significand: 1.0 ≤ |significand| < 2.0 – Always has a leading pre-binary-point 1 bit, so no need to represent it explicitly (hidden bit) – Significand is Fraction with the “1.” restored Exponent: excess representation: actual exponent + Bias – Ensures exponent is unsigned – Single: Bias = 127; Double: Bias = 1203 SExponentFraction single: 8 bits double: 11 bits single: 23 bits double: 52 bits

16 Floating-Point Addition Consider a 4-digit decimal example – 9.999 × 10 1 + 1.610 × 10 –1 1. Align decimal points – Shift number with smaller exponent – 9.999 × 10 1 + 0.016 × 10 1 2. Add significands – 9.999 × 10 1 + 0.016 × 10 1 = 10.015 × 10 1 3. Normalize result & check for over/underflow – 1.0015 × 10 2 4. Round and renormalize if necessary – 1.002 × 10 2

17 Floating-Point Addition Now consider a 4-digit binary example – 1.000 2 × 2 –1 + –1.110 2 × 2 –2 (0.5 + –0.4375) 1. Align binary points – Shift number with smaller exponent – 1.000 2 × 2 –1 + –0.111 2 × 2 –1 2. Add significands – 1.000 2 × 2 –1 + –0.111 2 × 2 –1 = 0.001 2 × 2 –1 3. Normalize result & check for over/underflow – 1.000 2 × 2 –4, with no over/underflow 4. Round and renormalize if necessary – 1.000 2 × 2 –4 (no change) = 0.0625

18 FP Adder Hardware Much more complex than integer adder Doing it in one clock cycle would take too long – Much longer than integer operations – Slower clock would penalize all instructions FP adder usually takes several cycles – Can be pipelined

19 FP Adder Hardware Step 1 Step 2 Step 3 Step 4

20 FP Arithmetic Hardware FP multiplier is of similar complexity to FP adder – But uses a multiplier for significands instead of an adder FP arithmetic hardware usually does – Addition, subtraction, multiplication, division, reciprocal, square-root – FP  integer conversion Operations usually takes several cycles – Can be pipelined

21 Floating Point Floating Point is handled by a FPU, floating point unit.

22 Pentium FDIV Bug Intel’s Pentium 5 – Professor Thomas Nicely noticed inconsistencies in calculations when adding Pentiums to his cluster – Floating-point division operations didn’t quite come out right. Off by 61 parts per million

23 Pentium FDIV Bug Intel acknowledged the flaw, but claimed it wasn’t serious. Wouldn’t affect most users. Byte magazine estimated only 1 in 9 billion floating point operations would suffer the error.

24 Pentium FDIV Bug Total cost to Intel? $450 million

25 WRAP UP

26 For next time Read Chapter 4.1-4.4

27 For next time Read Chapter 3 Sections 3.1 – 3.5


Download ppt "Lecture 12: Integer Arithmetic and Floating Point CS 2011 Fall 2014, Dr. Rozier."

Similar presentations


Ads by Google