Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.

Similar presentations


Presentation on theme: "ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations."— Presentation transcript:

1 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations

2 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 2 Floating-Point Hardware Older computer systems included hardware support for integer arithmetic operations only. –For floating-point operations, they relied on software libraries for simulating the floating-point operations using the hardware’s integer units. Including floating-point hardware is quite expensive. However, it is much more efficient than the software method. This is why almost all modern computers have hardware that is specifically designed for performing floating-point arithmetic operations.

3 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 3 Range of Representation Floating-point representation increases the range of values that can be stored in a given register. Consider a 48-bit register: –The range of signed integers that can be stored is: -2 47  2 47 –1 2 47 because one bit must be reserved for the sign.

4 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 4 Range of Representation Assuming 36 bits for a fractional mantissa and 12 bits for the exponent, calculate the range of floating-point numbers that can be stored: –One bit for the mantissa sign  35 bits for the mantissa. –Fractional mantissa  1 – 2 -35 –One bit for the exponent sign  11 bits for the exponent. –Integer exponent  2 2047 ±(1 – 2 -35 ) x 2 2047

5 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 5 Alignment Consider the following operation: 123 X 10 0 + 456 X 10 -2 –How can we add these two numbers? Before floating-point numbers can be added or subtracted, their exponents must be made equal. This process is called alignment.

6 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 6 Aligning the Mantissas To align floating-point numbers: –Determine which has the smaller exponent. –Shift the mantissa of the number with the smaller exponent (the smaller number) to the right and increment its exponent by 1. –Repeat until the two exponents become equal. Shifting the smaller number to the right will discard lesser significant bits. –If the shifting results in a 0 mantissa, stop.

7 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 7 Biased Exponent A “biased” exponent is an exponent to which a value has been added to make it always positive. –This makes it easier to compare exponents and determine which is larger. Very useful during alignment. Using 8 bits for the exponent we can represent values from –128 up to 127. –If we add 128 to these values, we would end up with exponents in the range of 0 to 255. –Deciding that 129 is larger than 126 is much easier than deciding whether 1 is larger than –2.

8 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 8 Addition and Subtraction There are 4 main steps to adding or subtracting floating-point numbers: –Check for zeros. –Align the mantissas. –Add or subtract the mantissas. Since the exponents are now equal, the mantissas can be added/subtracted following the regular rules of addition/subtraction. –Normalize the result.

9 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 9 Examples Represent 0.5 and 0.25 using the following floating point representation:  6 bit normalized signed 2’s complement fraction mantissa, including the sign. 1 bit for the sign, 5 bits for the mantissa.  3 bit biased exponent. Range of representation is -4 to 3.  Add 4 to bias it. Follow the steps of floating point addition to find the sum of the two numbers.

10 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 10 Examples (Contd.)  0.5  0.1 X 2 0 0 10000 100 (Already normalized).  0.25  0.01 X 2 0 0 01000 100 0 10000 011 (After normalization). 0 10000 100 0 10000 011 +

11 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 11 Examples (Contd.) 1. Check for Zero. –None of the numbers is 0. 2. Align Mantissas 3. Add 4. Normalize –Already normalized. 0 10000 100 0 10000 011 + 0 10000 100 0 01000 100 + 0 10000 0 01000 + 0 11000 0 11000 100 The result is

12 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 12 Examples (Contd.) Add 0.5 to –0.25 1. Check for zeros. None. 2. Align Mantissas. Already Aligned. 3. Add Mantissas. 4. Normalize the result. 0.50.1 X 2 0 0 10000 100 -0.25-0.01 X 2 0 - 0 01000 100 1 11000 100 0 10000 1 11000 + 1 0 01000 0 10000 011 0 01000 100 Preliminary Result Final Result

13 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 13 Examples (Contd.) Add -0.5 to 0.25 1. Check for zeros. None. 2. Align Mantissas. 0 10000 011 3. Add Mantissas. 4. Normalize the result. Already Normalized. -0.5-0.1 X 2 0 - 0 10000 100 0.250.01 X 2 0 0 01000 100 1 10000 100 1 10000 0 01000 + 1 11000 1 11000 100 Preliminary Result 0 10000 011 0 01000 100

14 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 14 Overflow in Floating-Point Operations What about overflow? –If adding the mantissas produces an overflow, we shift the result’s mantissa to the right 1 position and increment the exponent by 1. –If incrementing the exponent produces and exponent overflow, the operation is terminated and an overflow error is reported.

15 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 15 Examples (Contd.) Add 0.5 to 0.5 1. Check for zeros. None. 2. Align Mantissas. Already Aligned. 3. Add Mantissas. 4. Normalize the result. Already Normalized. 0.50.1 X 2 0 0 10000 100 0.50.1 X 2 0 0 10000 100 0 10000 + 1 00000 0 10000 101 Overflow Correction

16 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 16 Examples (Contd.) Add 4 to 4 1. Check for zeros. None. 2. Align Mantissas. Already Aligned. 3. Add Mantissas. Attempting to correct the overflow will cause the exponent to exceed its limit. –Cannot correct this overflow. 40.1 X 2 3 0 10000 111 40.1 X 2 3 0 10000 111 0 10000 + 1 00000 Overflow

17 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 17 Multiplication of Floating-Point Numbers Multiplication of floating-point numbers is a four step process: –Check for zeros. –Add the exponents. –Multiply the mantissas. –Normalize the product.

18 ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 18 Division of Floating-Point Numbers Division is done by: –Check for zeros. –Align the dividend. –Subtract the exponents. –Divide the mantissas. All of the operations on floating-point numbers have been simplified so that the same hardware can be used for floating-point numbers and integers.


Download ppt "ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations."

Similar presentations


Ads by Google