ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic...
-
Upload
darrell-dean -
Category
Documents
-
view
222 -
download
0
Transcript of ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic...
![Page 1: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/1.jpg)
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU
1
Floating-Point Arithmetic Operations
![Page 2: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/2.jpg)
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.
![Page 3: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/3.jpg)
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:
-247 247–1• 247 because one bit must be reserved for the sign.
![Page 4: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/4.jpg)
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 22047
±(1 – 2-35) x 22047
![Page 5: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/5.jpg)
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU
5
Alignment
• Consider the following operation:
123 X 100 + 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.
![Page 6: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/6.jpg)
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.
![Page 7: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/7.jpg)
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.
![Page 8: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/8.jpg)
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.
![Page 9: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/9.jpg)
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.
![Page 10: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/10.jpg)
ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU
10
Examples (Contd.)0.5 0.1 X 20
• 0 10000 100 (Already normalized).
0.25 0.01 X 20 • 0 01000 100 • 0 10000 011 (After normalization).
0 10000 100
0 10000 011+
![Page 11: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/11.jpg)
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 1000 10000 011+
0 10000 1000 01000 100+
0 100000 01000+0 11000 0 11000 100
The result is
![Page 12: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/12.jpg)
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.5 0.1 X 20 0 10000 100
-0.25 -0.01 X 20 - 0 01000 100 1 11000 100
0 100001 11000+
1 0 01000
0 10000 011
0 01000 100Preliminary
Result
Final Result
![Page 13: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/13.jpg)
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 20 - 0 10000 100
0.25 0.01 X 20 0 01000 100
1 10000 100
1 100000 01000+1 11000 1 11000 100
Preliminary
Result
0 10000 011
0 01000 100
![Page 14: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/14.jpg)
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.
![Page 15: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/15.jpg)
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.5 0.1 X 20 0 10000 100
0.5 0.1 X 20 0 10000 100
0 100000 10000+1 00000 0 10000 101
Overflow
Correction
![Page 16: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/16.jpg)
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.
4 0.1 X 23 0 10000 111
4 0.1 X 23 0 10000 111
0 100000 10000+1 00000 Overflow
![Page 17: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/17.jpg)
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.
![Page 18: ECEG-3202: Computer Architecture and Organization, Dept of ECE, AAU 1 Floating-Point Arithmetic Operations.](https://reader036.fdocuments.us/reader036/viewer/2022082411/56649ec05503460f94bcaf1a/html5/thumbnails/18.jpg)
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.