ECE331: Hardware Organization and Design Lecture 10: Multiplication & Floating Point Representation Adapted from Computer Organization and Design, Patterson & Hennessy, UCB
MIPS Division Two 32-bit registers for product HI: most-significant 32 bits LO: least-significant 32-bits Instructions div rs, rt / divu rs, rt 32-bit result in LO, 32-bit remainder in HI mfhi rd / mflo rd Moves data from hi and lo registers Example mfhi $s0 -> move remainder to register $s0 mflo $s0 -> move result of division to register $s0 ECE331: Floating Point 2
MULTIPLY Paper and pencil example (unsigned): Multiplicand 1000 Multiplier 1001 1000 0000 0000 1000 Product 1001000 m bits x n bits = m+n bit product Issues to note: The number of partial products is equal to the number of bits in the multiplier The partial products are added together A total of n-1 adders could be used to generate the result ECE331: Floating Point 3
MULTIPLY Paper and pencil example (unsigned): Multiplicand 1000 Multiplier 11 1000 1000 Product 11000 Need one adder ECE331: Floating Point 4
MULTIPLY Paper and pencil example (unsigned): Multiplicand 1000 Multiplier 11 1000 1000 Product 11000 Need one adder ECE331: Floating Point 5
MULTIPLY Paper and pencil example Multiplicand 1000 Multiplier 1001 1000 0000 0000 three additions 1000 Product 1001000 B 3 B 2 B 1 B 0 -> Multiplicand A 3 A 2 A 1 A 0 -> Multiplier ECE331: Floating Point 6
What is the Delay Through the Multiplier? x3,x2,x1,x0=1111 y3,y2,y1,y0=0001 ΔFA - operation time - delay Assuming equal delays for sum and carry-out Longest carry propagation chain when adding two 4-bit numbers In synchronous arithmetic units - time allowed for adder's operation is worst-case delay - nδfa ECE331: Floating Point 7
Multiplier Delay ΔFA - operation time delay through each adder bit Ignore AND gate delay For 4-bit adder, delay is 4*ΔFA Second adder (controlled by A2) can t generate its last add bit until second sum bit of first adder propagates through second adder So, extra delay of 2*ΔFA for second adder. Third adder (controlled by A3) can t generate its last add bit until second sum bit for second adder propagates through third adder So, extra delay of 2*ΔFA for third adder. Total delay is 2*ΔFA + 2*ΔFA + 4*ΔFA = 8*ΔFA What s the delay for n bits? ECE331: Floating Point 8
Multiplier Delay Critical paths C0 delay = 0 C1 delay = ΔFA C2 delay = 3ΔFA C3 delay = 5ΔFA C4 delay = 6ΔFA C5 delay = 7ΔFA C6 delay = 8ΔFA C7 delay = 8ΔFA What s the delay for n bits? (n-2) * (2ΔFA) + nδfa = (3n-4)ΔFA ECE331: Floating Point 9 Critical path for c7
Floating Point Representation for non-integral numbers Including very small and very large numbers Like scientific notation 2.34 10 56 +0.002 10 4 +987.02 10 9 In binary ±1.xxxxxxx 2 2 yyyy Types float and double in C normalized ECE331: Floating Point 10
Floating Point Numbers The largest 32 bit unsigned integer number is 1111 1111 1111 1111 1111 1111 1111 1111 = 4,294,967,295 What if we want to encode the approx. age of the earth? 4,600,000,000 or 4.6 x 10 9 or the weight in kg of one a.m.u. (atomic mass unit) 0.0000000000000000000000000166 or 1.6 x 10-27 There is no way we can encode either of the above in a 32- bit integer. ECE331: Floating Point 11
Exponential Notation The following are equivalent representations of 1,234 123,400.0 x 10-2 12,340.0 x 10-1 1,234.0 x 10 0 123.4 x 10 1 12.34 x 10 2 1.234 x 10 3 0.1234 x 10 4 0.01234x 10 5 The representations differ in that the decimal place the point - floats to the left or right (with the appropriate adjustment in the exponent). ECE331: Floating Point 12
Parts of a Floating Point Number -0.9876 x 10-3 Exponent Sign of mantissa Location of decimal point Mantissa Sign of exponent Base Mantissa is also called Significand ECE331: Floating Point 13
Single Precision Format Note that the exponent has no explicit sign bit Base? 32 bits M: Mantissa (23 bits) E: Exponent (8 bits) S: Sign of mantissa (1 bit) ECE331: Floating Point 14
Normalization The mantissa M is a normalized fraction Has an implied decimal place on left Has an implied (hidden) 1 on left of the decimal place E.g., Fraction 10100000000000000000000 Represents 1.101 2 = 1.625 10 The significand=1.f is in the range [1, 2-ulp] ulp unit in the last position (what remains to reach a whole number when all bits are set to one) F ECE331: Floating Point 15 S = ( 1) 1. f 2 E Bias Value of exponent (unsigned integer) Bias value (known; set by convention)
Binary Fractions To convert binary fractions to floating point 0.1110 0010 2-1 2-2 2-3 2-7 = 1*(0.5) + 1*(0.25) + 1*(0.125) + 0*(0.0625) + 0*(0.03125) + 0*(0.015625) + 1*(0.0078125) + 0*(0.00390625) = 0.8828125000 ECE331: Floating Point 16
Binary Fractions To convert floating point to binary 9.625 whole number fraction 9 à 1001 2 0.625 1*(0.5) = 0.125 0.125 1*(0.25) = neg. num. 0.125 1*(0.125) = 0 X 1 0 1 9.625 à 1001.1010 0000 2 = 0.1001 1010 0000 x 2 4 = 1.0011 0100 0000 x 2 3 Note that we can shift positions left and right of the decimal point by multiplying by different powers of 2 ECE331: Floating Point 17
Working with normalization (single precision) S {0,1} (1-bit) 1 E 254 (8-bits unsigned integer); Bias = 127 0.0000 0000 0000 0000 0000 000 f base-2 < 0.1111 1111 1111 1111 1111 111 Formula provides for the full range of possible floating point numbers. F S = ( 1) 1. f 2 E Bias 2-2 2-1 2 0 2 1 2 2 2 3 0.25 0.5 1.0 2.0 4.0 8.0 ECE331: Floating Point 18
IEEE Floating-Point Format single: 8 bits double: 11 bits S Exponent single: 23 bits double: 52 bits Fraction x = ( 1) S (1+ Fraction) 2 (Exponent Bias) 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 = 1023 ECE331: Floating Point 19
Single-Precision Range Exponents 00000000 and 11111111 reserved Smallest value Exponent: 00000001 actual exponent = 1 127 = 126 Fraction: 000 00 significand = 1.0 ±1.0 2 126 ±1.2 10 38 Largest value exponent: 11111110 actual exponent = 254 127 = +127 Fraction: 111 11 significand 2.0 ±2.0 2 +127 ±3.4 10 +38 ECE331: Floating Point 20
Floating-Point Example To convert floating point number to binary Represent 0.75 0.75 = 0.11 2 = ( 1) 1 1.1 2 2 1 S = 1 Fraction = 1000 00 2 Exponent = 1 + Bias Single: 1 + 127 = 126 = 01111110 2 Double: 1 + 1023 = 1022 = 01111111110 2 Single: 1 01111110 1000 00 fraction sign exponent and bias Double: 1 01111111110 1000 00 ECE331: Floating Point 21
Floating-Point Example To convert from binary to floating point What number is represented by the single-precision float? 1 10000001 01000 00 Identify the components S = 1 Fraction = 01000 00 2 Exponent = 10000001 2 = 129 Calculate the value x = ( 1) 1 (1 + 0.01 2 ) 2 (129 127) = ( 1) 1.25 2 2 = 5.0 ECE331: Floating Point 22