CPE 335 CPE 335 Computer Organization MIPS Arithmetic – Part II
- Dr. Iyad Jafar
Adapted from Dr. Gheith Abandah slides http://www.abandah.com/gheith/Courses/CPE335_S08/index.html
CPE 232 MIPS Arithmetic 1
CPE 335 CPE 335 Computer Organization MIPS Arithmetic Part II - - PowerPoint PPT Presentation
CPE 335 CPE 335 Computer Organization MIPS Arithmetic Part II Dr. Iyad Jafar Adapted from Dr. Gheith Abandah slides http://www.abandah.com/gheith/Courses/CPE335_S08/index.html CPE 232 MIPS Arithmetic 1 Shift Operations Shifts move
CPE 232 MIPS Arithmetic 1
CPE 232 MIPS Arithmetic 2
so sra uses the most significant bit (sign bit) as the bit so sra uses the most significant bit (sign bit) as the bit
note that there is no need for a sla when using two’s
Using a barrel shifter: is a digital circuit that can shift a data
CPE 232 MIPS Arithmetic 3
Simply a set of multiplexers multiplexers !
1
1
CPE 232 MIPS Arithmetic 4
CPE 232 MIPS Arithmetic 5
Hardware implementation of multiplication algorithm Operation
Initialize the lower 32 bits of the multiplicand register with the multiplicand Initialize the product register to 0. If the multiplier LSB is 1 add multiplicand to product If the multiplier LSB is 1, add multiplicand to product If the multiplier LSB is 0, don’t add Shift multiplicand left and multiplier right by one bit
R t 32 ti
Repeat 32 times
CPE 232 MIPS Arithmetic 6
Flowchart for multiplication
If each step takes one
Check the multiplication
CPE 232 MIPS Arithmetic 7
ALU and multiplicand register are both 32 bits wide Multiplier register is omitted and multiplier is placed in the lower 32
The product register is shifted to the right along with the multiplier
CPE 232 MIPS Arithmetic 8
Use 31 32-bit adders to compute
One input is the multiplicand
Example: show the multiplication
CPE 232 MIPS Arithmetic 9
CPE 232 MIPS Arithmetic 10
Low-order word of the product is left in processor register lo
Instructions mfhi rd and mflo rd are provided to move
Both instructions ignore overflow; it is the responsibility of the Both instructions ignore overflow; it is the responsibility of the
For multu, there is no overflow if hi is 0
CPE 232 MIPS Arithmetic 11
For mult, there is no overflow if hi is the replicated sign of lo
CPE 232 MIPS Arithmetic 12
CPE 232 MIPS Arithmetic 13
Instructions mfhi rd and mflo rd are provided to move
As with multiply, divide ignores overflow so software must
CPE 232 MIPS Arithmetic 14
Remember the signs of the dividend and divisor and use to
The sign of the remainder is always the same as the dividend
The Pentium bug in 1994 Cost for recall was about $500M
CPE 232 MIPS Arithmetic 15
How to encode real numbers ?
Still have to fit everything in 32 bits (single precision) Normalized representation (no leading zeros and one bit to the
More bits in the fraction (F) or the exponent (E) is a trade-off
CPE 232 MIPS Arithmetic 16
Smallest number 2.0x10-38 and largest is 2.0x1038
Overflow and underflow ! Double precision format (use 64 bits instead of 32)
Smallest number 2.0x10-308 and largest is 2.0x10308 Most computers these days conform to the IEEE 754 floating point
To pack more bits into the significand, one bit of the normalized
Since 0 has no leading 1, it has a reserved exponent value of 0 so
CPE 232 MIPS Arithmetic 17
CPE 232 MIPS Arithmetic 18
Separate sign bit (sign and magnitude notation) Placing the exponent before the significand
Use of biased exponent notation; add a constant value to
CPE 232 MIPS Arithmetic 19
two
CPE 232 MIPS Arithmetic 20
Single precision Double precision Double precision
CPE 232 MIPS Arithmetic 21
CPE 232 MIPS Arithmetic 22
Step 1: Restore the hidden bit in F1 and in F2
Step 1: Align fractions by right shifting F2 by E1 - E2 positions
Step 2: Add the resulting F2 to F1 to form F3 Step 3: Normalize F3 (so it is in the form 1.XXXXX …) and check
Step 4: Round F3 and possibly normalize F3 again Step 5: Rehide the most significant bit of F3 before storing the
CPE 232 MIPS Arithmetic 23
CPE 232 MIPS Arithmetic 24
In normalized scientific notation this is equivalent
Align exponents
Add significands Add significands
Normalize the sum (if necessary) and check for Normalize the sum (if necessary) and check for
Round the sum and normalize again
CPE 232 MIPS Arithmetic 25
In arithmetic we are restricted with the number of bits. Thus we may
IEEE754 standards define two extra bits to the right of the numbers;
Decimal example: 2.56 x 100 + 2.34 x 102 Assume significand is represented in 3 digits only Without guard and round digits (truncation occurs for two digits)
With guard digit, we don’t have to truncate the small number
CPE 232 MIPS Arithmetic 26
CPE 232 MIPS Arithmetic 27
CPE 232 MIPS Arithmetic 28