ECE4680 Computer Organization & Architecture Divide, Floating Point, Pentium Bug
ECE4680 Computer Organization & Architecture Divide, Floating Point, Pentium Bug
ECE468 ALU-III.1
2002-2-27
Multiplicand 64 bits
Shift Left
64-bit ALU
Product 64 bits
Write
Control
ECE468 ALU-III.2
2002-2-27
Multiplicand 32 bits
32-bit ALU
Product 64 bits
Control
ECE468 ALU-III.3
2002-2-27
end of run
Current Bit 1 1 0 0
middle of run
beginning of run
Example 0001111000 0001111000 0001111000 0001111000
0 1 1 1 1 0
Bit to the Right 0 1 1 0 Explanation Beginning of a run of 1s Middle of a run of 1s End of a run of 1s Middle of a run of 0s
Originally for Speed since shift faster than add for his machine
ECE468 ALU-III.4
2002-2-27
1. Depending on the current and previous bits, do one of the following: 00: 01: 10: 11: a. Middle of a string of 0s, so no arithmetic operations. b. End of a string of 1s, so add the multiplicand to the left half of the product. c. Beginning of a string of 1s, so subtract the multiplicand from the left half of the product. d. Middle of a string of 1s, so no arithmetic operation.
2.As in the previous algorithm, shift the Product register right (arith) 1 bit.
ECE468 ALU-III.5
2002-2-27
Quotient Dividend
Remainder
See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or 0 * divisor Dividend = Quotient x Divisor + Remainder 3 versions of divide, successive refinement
ECE468 ALU-III.6
2002-2-27
Shift Left
32 bits
Remainder 64 bits
Write
Control
ECE468 ALU-III.7
2002-2-27
Start
1. Subtract the Divisor register from the Remainder register, and place the result in the Remainder register.
2a. Shift the Quotient register to the left setting the new rightmost bit to 1.
2b. Restore the original value by adding the Divisor reg to the Remainder reg and place the sum in the Remainder reg. Also shift the Quotient register to the left, setting the new LSB to 0
ECE468 ALU-III.8
2002-2-27
ECE468 ALU-III.9
2002-2-27
Remainder 64 bits
Control
ECE468 ALU-III.10
2002-2-27
Start
Remainder < 0
3a. Shift the Quotient register to the . Left setting the new rightmost bit to 1.
3b. Restore the original value by adding the Divisor reg to the left half of the Remainder reg and place the sum in the left half of the Remainder reg. Also, shift the Quotient reg to the left, setting the new LSB to 0.
32nd repetition?
ECE468 ALU-III.12
2002-2-27
Divisor 32 bits
32-bit ALU
Remainder 64 bits
Control
ECE468 ALU-III.13
2002-2-27
Start
Remainder < 0
3a. Shift the Remainder . register to the Left setting the new rightmost bit to 1
3b. Restore the original value by adding the Divisor reg to the left half of the Remainder reg and place the sum in the left half of the Remainder reg. Also, shift the Remainder reg to the left, setting the new rightmost to 0
32nd repetition?
ECE468 ALU-III.15
2002-2-27
Floating-Point
What can be represented in N bits? Unsigned 2s Complement 1s Complement Excess M BCD 0 N-1 -2
N-1
to to
2 -1 N-1 2 -1 2 -1 N 2-M-1
N-1
-2 + 1 to -M to
But, what about? very large numbers? very small number? rationals irrationals transcendentals 9,349,398,989,787,762,244,859,087,678 0.0000000000000000000000045691 2/3
2
e,
ECE468 ALU-III.16
2002-2-27
Mantissa
Sign, magnitude IEEE F.P. Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors Properties ( negation, inversion, if A > B then A - B > 0 )
ECE468 ALU-III.17 2002-2-27
E - 127 1.M x 2
Floating-Point Arithmetic
Representation of floating point numbers in IEEE 754 standard: 1 8 23 single precision S E sign M mantissa: Exponent: Sign + Magnitude, normalized excess 127 binary integer binary significand w/ hidden integer bit: 1.M
0 < E < 255, not 0 E 255 127 < e < 128, not 127 e 128 00000000 is reserved for 0; 11111111 is reserved for infinity.
-1.5 = 1 01111111 10 . . . 0
Magnitude of numbers that can be represented is in the range: 2 -126 (1.0) to 2 127 (2 - 2 23 ) 38
2002-2-27
3.40 x 10
Normalized Numbers
Significand is left adjusted --> as large as possible, exponent is as small as possible 4 E.g., B = 2 , p = 3: (once used in IBM 360/370, p.280) 0 0110 0000 . 0110 1100 = 0.6C denormalized 0 0101 0110 . 1100 0000 = 6.C0 normalized
In B = 2, the significand MSB is always 1 when the significand is left adjusted. So not necessary to store this "hidden" bit in memory. 0 011 1.01 1 w/o hidden bit 0 011 .011 w/ hidden bit = improved precision
Within the FPU, the hidden bit is inserted because of the denormalization step that precedes FP add/subtract. -bias 2 must distinguish from Smallest normal #: 0 0 ... 0 .0 ... 01 hidden bit zero with special form 0 00 .000, no hidden bit "1" 0 0 ... 0 1.0 ... 00
ECE468 ALU-III.19
no hidden bit
2002-2-27
-1.5 = 1 01111111 10 . . . 0
Questions:
Why is FP number normalized? (for accuracy) Why is FP not accurate for large numbers? Why is S put on leftmost? (P.278) Why is E represented by biased notation? (P.278) Why is E put before M? (P.278)
ECE468 ALU-III.20
2002-2-27
ECE468 ALU-III.21
2002-2-27
1. Compare the exponents of the two numbers. Shift the smaller number to the right until its expone nt would match the larger exponent
Step1: -1.110x2-2
-0.111x2-1
3. Normalize the sum, either shifting right and incrementing the exponent or shifting left and decreme nting the expone nt
Y es
Exception
No
ECE468 ALU-III.22
2002-2-27
adder E
adder
Mantissa Unit
Data Out Data In Addition Algorithm: AC<n m -1:0>, DR<nm -1:0>, E1<n m -1:0>, E2<n m -1:0>, E<n m -1:0>, AC_OVERFLOW, ERROR Begin: Load:
ECE468 ALU-III.23
Extra Bits
"Floating Point numbers are like piles of sand; every time you move one you lose a little sand, but you pick up a little dirt." How many extra bits? IEEE: As if computed the result exactly and rounded. Addition: 1.xxxxx + 1.xxxxx 1.xxxxx 0.001xxxxx 1.xxxxx 0.01xxxxx
1x.xxxxy 1.xxxxxyyy 1x.xxxxyyy post-normalization pre-normalization pre and post Guard Digits: digits to the right of the first p digits of significand to guard against loss of digits can later be shifted left into first P places during normalization. Addition: carry-out shifted in Subtraction: borrow digit and guard Multiplication: carry and guard, division requires guard
ECE468 ALU-III.24 2002-2-27
Rounding Digits
normalized result, but some non-zero digits to the right of the significand --> the number should be rounded E.g., B = 10, p = 3: 2-bias 0 2 1.69 = 1.6900 * 10 0 0 7.85 = - .0785 * 10 2-bias 0 2 1.61 = 1.6115 * 10 2-bias
one round digit must be carried to the right of the guard digit so that after a normalizing left shift, the result can be rounded, according to the value of the round digit IEEE Standard: (p. 300) four rounding modes: round to nearest (default) round towards plus infinity (always round up) round towards minus infinity(always round down) round towards 0 round to nearest: round digit < B/2 then truncate > B/2 then round up (add 1 to ULP) = B/2 then round to nearest even digit it can be shown that this strategy minimizes the mean error introduced by rounding
ECE468 ALU-III.25 2002-2-27
It may make sense to do further computations with infinity e.g., X/0 > Y may be a valid comparison
Not a number, but not infinity (e.q. sqrt(-4)) invalid operation exception (unless operation is = or =) NaN S 1 . . . 1 non-zero HW decides what goes here
ECE468 ALU-III.26
2002-2-27
Exceptions
Invalid operation: result of operation is a NaN (except = or =) inf. +/- inf.; 0 * inf; 0/0; inf./inf.; x remainder y where y = 0; sqrt(x) where x < 0, x+/- inf. Overflow: result of operation is larger than largest representable # flushed to +/- inf. if overflow exception is not enabled Divide by 0: x/0 where x = 0, +/- inf.; flushed to +/- inf. if divide by zero exception not enabled Underflow: subnormal result(see p300) OR non-zero result underflows to 0 Inexact: rounded result not the actual result (rounding error = 0) IEEE Standard --> specifies defaults and allows traps to permit user to handle the exception contrast with the more usual result of aborting the computation altogether!
ECE468 ALU-III.27 2002-2-27
Pentium Bug
Pentium FP Divider uses algorithm to generate multiple bits per steps FPU uses most significant bits of divisor & dividend/remainder to guess next 2 bits of quotient Guess is taken from lookup table: -2, -1,0,+1,+2 (if previous guess too large a reminder, quotient is adjusted in subsequent pass of -2) Guess is multiplied by divisor and subtracted from remainder to generate a new remainder Called SRT division after 3 people who came up with idea Pentium table uses 7 bits of remainder + 4 bits of divisor = 211 entries 5 entries of divisors omitted: 1.0001, 1.0100, 1.0111, 1.1010, 1.1101 from PLA (fix is just add 5 entries back into PLA: cost $200,000) Self correcting nature of SRT => string of 1s must follow error e.g., 1011 1111 1111 1111 1111 1011 1000 0010 0011 0111 1011 0100 (2.99999892918) Since indexed also by divisor/remainder bits, sometimes bug doesnt show even with dangerous divisor value
ECE468 ALU-III.28 2002-2-27
0.333333 x 9 could be problem In Microsoft Excel, try (4,195,835 / 3,145,727) * 3,145,727 = 4,195,835 => not a Pentium with bug = 4,195,579 => Pentium with bug (assuming Excel doesnt already have SW bug patch) Rare since error in 5th significant digit
ECE468 ALU-III.29
2002-2-27
Pentium jokes
Q: What's another name for the "Intel Inside" sticker they put on Pentiums? A: Warning label. Q: Have you heard the new name Intel has chosen for the Pentium? A: the Intel Inacura. Q: According to Intel, the Pentium conforms to the IEEE standards for floating point arithmetic. If you fly in aircraft designed using a Pentium, what is the correct pronunciation of "IEEE"? A: Aaaaaaaiiiiiiiiieeeeeeeeeeeee! TWO OF TOP TEN NEW INTEL SLOGANS FOR THE PENTIUM 9.9999973251 It's a FLAW, Dammit, not a Bug 7.9999414610 Nearly 300 Correct Opcodes
ECE468 ALU-III.31
2002-2-27
Summary
Bits have no inherent meaning: operations determine whether they are really ASCII characters, integers, floating point numbers Divide can use same hardware as multiply: Hi & Lo registers in MIPS Floating point basically follows paper and pencil method of scientific notation using integer algorithms for multiply and divide of significands IEEE 754 requires good rounding; special values for NaN, Infinity Pentium: Difference between bugs that board designers must know about and bugs that potentially affect all users Why not make public complete description of bugs in later category? $200,000 cost in June to repair design $500,000,000 loss in December in profits to replace bad parts How much to repair Intels reputation? What is technologists responsibility in disclosing bugs?
ECE468 ALU-III.33
2002-2-27