ch4b
ch4b
Before, we did Recall decimal multiplication from grammar school (non negative)
• Representation of integers multiplicand 1000 base ten
• Addition/Subtraction
multiplier 1001 base ten
• Logical ops
partial 1000
Forecast
products 0000
• Integer Multiplication
0000
• Integer Division
• Floating-point Numbers 1000
• Floating-point Addition/Multiplication 1001000 base ten
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 1 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 2
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 3 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 4
Example (Fig. 4.26) Integer Multiplication
Multiplier0 = 0
• observation: upper-half of 64 bits are all zero
Yes: 32 repetitions
• use 32-bit ALU and shift product right
32nd repetition?
• instead of multiplicand left (multiplier still goes right)
Multiplier0
Done
• put multiplier in not-yet-used part of product
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 5 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 6
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 7 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 8
Integer Multiplication Booth’s Encoding
Booth encoding -- mind bending like carry-lookahead In binary
Skipping over 9’s in decimal - look for beginning and end of 9’s • works for 1’s - 1 less than 2
• we already are fast on zeroes
12345
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 9 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 10
0 0 -1 0 +1 0 0 -1 +1 -1 0 0 0 11111010 *0 = 0
0 -2 +2 -1 +1 0 1111010_ *- = 00001100
all equivalent
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 11 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 12
Booth Encoding Redundant Representations
negative multiplier Normally
1010 = -6 • d2*b2 + d1*b1 + d0*b0; b base, di usually (0, 1, . . . base-1}
b * a2 a1 a0 = Carry-Save addition
• (a1-a2)*b*22 + (a0-a1)*b*21 + (0-a0)*b*20 • b = 2, di = { 0, 1, 2, 3}
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 13 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 14
1 1 1 0 0 1 1 1 0 1 0 0 “0” -1 - 2’sC
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 15 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 16
Integer Division Integer Division
divisor - 1000 dividend 1001010 - grammar school But hardware can’t inspect to see if divisor fits, so
1000)1001010( 1001 - quotient Subtract
101 Figure
1000
10 - remainder
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 17 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 18
+01000 +divisor*22
00101
+111000 -divisor*22
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 21 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 22
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 23 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 24
Pentium Bug Pentium Bug
Determine next quotient digit Incomplete testing did not expose,
conceptually - a table-lookup into table[partial-remainder, divisor] • since the algorithm self-corrects
• as long as the partial-remainder is “in range”
guess next 2 quotient bits
some part of the table is not “accessible” incorrect quotient for some dividend, divisor pairs
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 25 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 26
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 27 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 28
Non-restoring Division Floating-Point Numbers
Final step may need correction if want to represent real numbers
• remainder and dividend opp signs, correction needed But uncountably infinite
• dividend, divisor same sign, remainder += D, quotient -=ulp
Recall scientific notation
• dividend, divisor opp sign, emainder -= D, quotient +=ulp
• 3.15576 *109 (#seconds in a century!)
convert wierd quotient to 2’sC : 1 is 1, 1 is 0 • 3,155,760,000
shift left by one bit • exponent says where the decimal point “float”
complement MSB Recall normalization
shift 1 into LSB • use 3.14*1010 NOT 0.314*1011 or 31.4*109
• MSD is [1,9] except for 0.0
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 29 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 30
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 31 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 32
Floating-Point Numbers Floating-Point Addition
Exceptions Like scientific notation
•S E F number
9.997 * 102
•0 0 0 0
• 0 max 0 +inf + 4.631 * 10-1
• 1 max 0 -inf First step: align decimal points, second step: add
• x max !=0 NaN 9.997 * 102
•x 0 !=0 denorm f = 0 + F/2n
+ 0.004631 * 102
see book for table
10.001631 * 102
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 33 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 34
1.0001631 * 103
Figure
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 35 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 36
Floating-Point Multiplication Floating-Point Multiplication
Example: Hardware: Figure
• 3.0 * 101 Exponent:
2
• 5.0 * 10 e+ = e1 + e2
• algorithm: multiple mantissas, add exponents E+ = e+ + 1023 = E1 - 1023 + E2 -1023 + 1023
• check exponent in bounds --> exception
E+ = E1 + E2 - 1023
• normalize (and round)
-1023 = -(1111111111) = 0000000000 + 1 = +1
• set sign
With 2’sC E+ = E1 + E2 + carryin!
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 37 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 38
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 39 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 40
Rounding Rounding
6-9 up Need infinite bits? No - hold least significant bits
5 to even to make unbiased • guard bits - used for normalization - one bit right of LSB
• round bit - main round bit - one bit right of guard bit
1-4 down
• sticky - logical OR of all less significant bits
0 unchanged
• round sticky
xxxx.1 . . . 1 .. up •11 round up
xxxxx.10000 to even •10 round even
xxx.0 .. . . 1 .. . down • 0 1 round down
© 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 41 © 2000 by Mark D. Hill CS/ECE 552 Lecture Notes: Chapter 4 42
Rounding
IEEE FP bounds error to 1/2 “units of the last place” ULP