CS304PC:Computer Organization and Architecture session 22 floating point arithmetic operations.pptx
1. CS304PC:Computer Organization
and Architecture (R18 II(I sem))
Department of computer science and engineering
(AI/ML)
Session 22
by
Asst.Prof.M.Gokilavani
VITS
2/18/2023 Department of CSE (AI/ML) 1
2. TEXTBOOK:
• 1. Computer System Architecture – M. Moris Mano, Third Edition,
Pearson/PHI.
REFERENCES:
• Computer Organization – Car Hamacher, Zvonks Vranesic, Safea
Zaky, Vth Edition, McGraw Hill.
• Computer Organization and Architecture – William Stallings Sixth
Edition, Pearson/PHI.
• Structured Computer Organization – Andrew S. Tanenbaum, 4th
Edition, PHI/Pearson.
2/18/2023 Department of CSE (AI/ML) 2
3. Unit III
Data Representation: Data types ,Complements, fixed point
Representations, Floating point representation.
Computer Arithmetic: Addition and subtraction,
multiplication Algorithms, Division Algorithms, Floating-point
Arithmetic operations, Decimal Arithmetic unit, Decimal
Arithmetic operations.
2/18/2023 Department of CSE (AI/ML) 3
4. Topics covered in session 22
2/18/2023 Department of CSE (AI/ML) 4
• Addition and subtraction
• Multiplication Algorithms
• Division Algorithms
• Floating-point Arithmetic operations
• Decimal Arithmetic unit
• Decimal Arithmetic operations.
5. Floating-point Arithmetic operations
• Floating point arithmetic
• Representation of floating point arithmetic
• Operations
• Normalization
• Pit-Falls of floating point arithmetic
2/18/2023 Department of CSE (AI/ML) 5
6. Floating-point Arithmetic operations
There are two types of arithmetic operations :-
• Integer Arithmetic
• Real – floating point arithmetic
• Integer Arithmetic :- deals with integer operands.
• i.e. - num without fractional parts
• Real Arithmetic :- use number with fractional parts as operands and is
use.
• Real no. = mantissa * 10^exponent
2/18/2023 Department of CSE (AI/ML) 6
7. COMPUTER REPRESENTATION OF FLOATING
POINT NUMBERS
• In the CPU, a 32-bit floating point number is represented using IEEE
standard format as follows:
S | EXPONENT | MANTISSA
• where S is one bit, the EXPONENT is 8 bits, and the MANTISSA is 23 bits.
• The mantissa
• Represents the leading significant bits in the number.
• It is made less than 1 and greater than or equal to 0.1.
• The exponent
• is used to adjust the position of the binary point (as opposed to a
"decimal" point).
• In power of 10 and multiplies with mantissa
2/18/2023 Department of CSE (AI/ML) 7
8. Normalization
• Mantissa and Exponent have their own independent signs.
• While storing no. of the leading digit in the mantissa, mantissa is
always made non- zero by appropriately shifting it and adjusting the
value of the exponent.
• The shifting of mantissa to the left till its most significant digit is non-
zero is called normalization.
Example:
• 350->normalized
• 00035-> not normalized.
• Can be normalized by shifting it 3 positions to the left and discarding the
leading zeros.(10^3)
• Zero cannot be normalized bcoz it does not have a nonzero digit. –
Denoted by all zeros at mantissa and exponent.
2/18/2023 Department of CSE (AI/ML) 8
9. Arithmetic operations with normalized floating
point numbers
• Addition
• Subtraction
• Multiplication
• Division
2/18/2023 Department of CSE (AI/ML) 9
10. Basic Considerations
• Operations on fp numbers requires complex hardware and takes more time.
• Addition or subtraction requires:
• Alignment of radix point(exponents must be equal).
• Done by shifting mantissa and adjust exponent accordingly.
• Example: 0.5372400*10^2+ 0.1580000*10^-1
• Either shift the 1st no 3 positions to the left or shift the 2nd by 3 position to
the right.
• 2nd method is more preferable.
• Normalized addition will cause an overflow and can be corrected by
shifting the sum once to the right and incrementing the exponent.
2/18/2023 Department of CSE (AI/ML) 10
11. • Underflow
• Floating point number has a 0 in the MSB of the mantissa.
• Shift the mantissa to the left and decrement the exponent(normalization)
• Multiplication and division does not require alignment.
• Result(multiply mantissa and add the exponent for multiplication).
• Divide the mantissa and subtract the exponent for division.
• The operation performed with exponent are:
• Compare &increment(align mantissa)
• Add &subtract(multiplication and division)
• Decrement ( normalization )
• Exponent representation
• Signed magnitude
• Signed 2’s complement
• Signed 1’s complement
• Biased exponent
2/18/2023 Department of CSE (AI/ML) 11
12. • In biased exponent
• Sign bit is not taken as separate entity.
• Is a +ve number that is added to each exponent as the floating point number is
formed.
• Internally all exponents are +ve.
• The bias, is subtracted from the field to get the true exponent value.
• Bias=(2k-1-1), where k is the number of bits in the binary exponent.
• Advantages
• They contain only positive numbers(easy to compare)
• The smallest possible biased exponent contains all zeros
2/18/2023 Department of CSE (AI/ML) 12
15. Register Configuration
• The same registers & adders are in the case of fixed point arithmetic
are used for processing mantissa.
• Differs the way in which exponents are handled.
2/18/2023 Department of CSE (AI/ML) 15
16. 2/18/2023 Department of CSE (AI/ML) 16
• BR,AC,QR(divided into 2 parts).
• Mantissa is stored in B,A and Q registers
• Exponent in b,a,q registers.
• Mantissa in signed magnitude in A and sign in As and MSB in A1.
• Biased exponent in a.
• A1->1 if the no. Has to be normalized
• Similarly for other registers
• 2Parallel adders
• 1 ,Adds two mantissas and sum stores in A, Carry to E.
• 2nd adds the exponents(don’t have distinct sign bit, but taken as +ve).
• Exponent overflow is neglected.
• Exponents are connected to comparator that provides 3 binary outputs to indicate their
relative magnitude.
• The number in the mantissa is taken as a fraction, so binary point resides to the left of the
magnitude part.
• Numbers are normalized both during initial and after the operation.
18. Addition and Subtraction
1. Check for zeros.
2. Align the mantissas.
3. Add or subtract the mantissas.
4. Normalize the result.
2/18/2023 Department of CSE (AI/ML) 18
20. Multiplication
• Multiply the mantissas and add the exponents.
• No comparison of exponents or alignment of mantissas is necessary.
• Four components:
1. Check for zeros.
2. Add the exponents.
3. Multiply the mantissas.
4. Normalize the product.
2/18/2023 Department of CSE (AI/ML) 20
22. Division
• Floating-point division requires that the exponents be subtracted and
the mantissas divided.
• The mantissa division is done as in fixed-point except that the
dividend has a single-precision mantissa that is placed in the AC.
• Check for zeros.
• Initialize registers and evaluate the sign
• Align the dividend(divide overflow check in fixp).
• Subtract the exponents.
• Divide the mantissas.
2/18/2023 Department of CSE (AI/ML) 22