Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mohamed Younis CMCS 411, Computer Architecture 1 CMSC 411-101 Computer Architecture Lecture 11 Performing Division March 5, 2001 www.csee.umbc.edu/~younis/CMSC411/

Similar presentations


Presentation on theme: "Mohamed Younis CMCS 411, Computer Architecture 1 CMSC 411-101 Computer Architecture Lecture 11 Performing Division March 5, 2001 www.csee.umbc.edu/~younis/CMSC411/"— Presentation transcript:

1 Mohamed Younis CMCS 411, Computer Architecture 1 CMSC 411-101 Computer Architecture Lecture 11 Performing Division March 5, 2001 www.csee.umbc.edu/~younis/CMSC411/ CMSC411.htm

2 Mohamed Younis CMCS 411, Computer Architecture 2 Lecture’s Overview q Previous Lecture: Algorithms for multiplying unsigned numbers (Evolution of optimization, complexity) Booth’s algorithm for signed number multiplication (Different approach to multiplying, 2-bit based operation selection) Multiple hardware design for integer multiplier (Hardware cost-driven optimization) q This Lecture: Algorithms for dividing unsigned numbers Handling of sign while performing a division Hardware design for integer division

3 Mohamed Younis CMCS 411, Computer Architecture 3 q Paper and pencil example (unsigned): 1001 Quotient Divisor 1000 1001010 Dividend –1000 10 101 1010 –1000 10 Remainder (or Modulo result) q See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or 0 * divisor q Dividend = Quotient x Divisor + Remainder  3 versions of divide, successive refinement Dividing Unsigned Numbers * Slide is courtesy of Dave Patterson

4 Mohamed Younis CMCS 411, Computer Architecture 4 Divide Hardware (version 1) q 64-bit Divisor register, 64-bit ALU, 64-bit Remainder register, and 32-bit Quotient register q The 32-bit value of the Divisor starts in the left half of the 64-bit register q The Divisor is shifted to the right every step to align with the Dividend q The Remainder register is initialized with the value of the Dividend q Control decides when to shift the Divisor and the Quotient registers and when to write new value into the Remainder register * Figure is courtesy of Dave Patterson Remainder Quotient Divisor 64-bit ALU Shift Right Shift Left Write Control 32 bits 64 bits Subtract

5 Mohamed Younis CMCS 411, Computer Architecture 5 Divide Algorithm Version 1 è If the Remainder is positive, a 1 is generated in the Quotient è A negative Remainder indicates that Divisor did not go into the Dividend è Shifting the Divisor in step 3 aligns the Divisor with the Dividend for next iteration è Repeat for 33 times? (we need a final shift) Dividing two n-bit numbers needs n+1 steps to generate n-bit Quotient and Remainder

6 Mohamed Younis CMCS 411, Computer Architecture 6 An Example Follow the division algorithm (version 1) to divide 7 by 2 using only 4-bit binary representation

7 Mohamed Younis CMCS 411, Computer Architecture 7 Divide Hardware (version 2) * Figure is courtesy of Dave Patterson q In the first version of divide hardware, half the bits in Divisor always 0 => 1/2 of 64-bit adder is wasted & 1/2 of divisor is wasted q Uses only 32-bit Divisor register, 32-bit ALU, 64-bit Remainder register, and 32-bit Quotient register q Since the least significant bits of the product would not change, the Remainder could be shifted to the left instead of shifting the Divisor to the right q1st step cannot produce a 1 in quotient bit (otherwise too big) => switch order to shift first and then subtract, can save 1 iteration q The most significant 32-bits would be used by the ALU as a result register Remainder Quotien t Divisor 32-bit ALU Shift Left Write Control 32 bits 64 bits Shift Left Subtrac t

8 Mohamed Younis CMCS 411, Computer Architecture 8 Divide Algorithm Version 2 Early shifting the remainder register saves one iteration Early shifting the remainder register saves one iteration

9 Mohamed Younis CMCS 411, Computer Architecture 9 An Example Follow the division algorithm (version 2) to divide 7 by 2 using only 4-bit binary representation

10 Mohamed Younis CMCS 411, Computer Architecture 10 Divide Hardware Version 3 * Figure is courtesy of Dave Patterson q Remainder register wastes space that exactly matches size of Quotient  combine Quotient register and Remainder register q Uses only 32-bit Divisor register, 32-bit ALU, 64-bit Remainder register, and 0-bit Quotient register q The same number of shift operations would apply to both the Remainder and the Quotient  the Remainder needs to be corrected at the end q The most significant 32-bits are still being used by ALU as a result register Remainder (Quotient) Divisor 32-bit ALU Write Control 32 bits 64 bits Shift Left “HI”“LO” Subtract

11 Mohamed Younis CMCS 411, Computer Architecture 11 Divide Algorithm Version 3 è Eliminate Quotient register by combining with Remainder and shifted left è Remainder would be shifted an extra time and need to be corrected at the end Dividing 7 by 2

12 Mohamed Younis CMCS 411, Computer Architecture 12 Dividing Signed Numbers Simplest approach is to remember signs, make positive, and complement quotient and remainder if necessary è Rule 1: Dividend and Remainder must have same sign è Rule 2: Quotient negated if Divisor sign & Dividend sign disagree Examples: Dividend = Quotient  Divisor + Remainder 7 ÷ 2 = 3, remainder = 1 –7 ÷ 2 = –3, remainder = –1 7 ÷ – 2 = –3, remainder = 1 –7 ÷ – 2 = 3, remainder = –1

13 Mohamed Younis CMCS 411, Computer Architecture 13 Conclusion q Summary è Algorithms for dividing unsigned numbers (Evolution of optimization, complexity) è Handling of sign while performing a division (Remainder sign matches the dividend’s) è Hardware design for integer division (Same hardware as Multiply) q Next Lecture è Representation of floating point numbers è Floating point arithmetic è Floating point hardware Reading assignment includes section 4.7 in the text book


Download ppt "Mohamed Younis CMCS 411, Computer Architecture 1 CMSC 411-101 Computer Architecture Lecture 11 Performing Division March 5, 2001 www.csee.umbc.edu/~younis/CMSC411/"

Similar presentations


Ads by Google