ECE 645 – Computer Arithmetic Lecture 9: Basic Dividers ECE 645—Computer Arithmetic 4/1/08.

Slides:



Advertisements
Similar presentations
ECE 645 – Computer Arithmetic Lecture 11: Advanced Topics and Final Review ECE 645—Computer Arithmetic 4/22/08.
Advertisements

Division Circuits Jan 2013 Shmuel Wimer Bar Ilan University, Engineering Faculty Technion, EE Faculty 1.
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Computer ArchitectureFall 2007 © September 5, 2007 Karem Sakallah CS 447 – Computer Architecture.
Booth’s Algorithm.
Chapter 6 Arithmetic. Addition Carry in Carry out
UNIVERSITY OF MASSACHUSETTS Dept
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
CSE 246: Computer Arithmetic Algorithms and Hardware Design Instructor: Prof. Chung-Kuan Cheng Winter 2004 Lecture 7.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Computer ArchitectureFall 2008 © August 27, CS 447 – Computer Architecture Lecture 4 Computer Arithmetic (2)
Ch. 21. Square-rootingSlide 1 VI Function Evaluation Topics in This Part Chapter 21 Square-Rooting Methods Chapter 22 The CORDIC Algorithms Chapter 23.
ECE 645 – Computer Arithmetic Lecture 10: Fast Dividers ECE 645—Computer Arithmetic 4/15/08.
Lecture 10 Fast Dividers.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Multiplication of signed-operands
July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.
Division Harder Than Multiplication Because Quotient Digit Selection/Estimation Can Have Overflow Condition – Divide by Small Number OR even Worse – Divide.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
1 Dividers Lecture 10. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
1 Basic Dividers Lecture 10. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Advanced Dividers Lecture 10. Required Reading Chapter 13, Basic Division Schemes 13.4, Non-Restoring and Signed Division Chapter 15 Variation in Dividers.
Basic Dividers Lecture 10. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
1 Basic Dividers Lecture 9. Required Reading Chapter 13, Basic Division Schemes 13.1, Shift/Subtract Division Algorithms 13.3, Restoring Hardware Dividers.
CDA 3101 Spring 2016 Introduction to Computer Organization
Integer Operations Computer Organization and Assembly Language: Module 5.
Ch. 4 Computer Arithmetic
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
1. Copyright  2005 by Oxford University Press, Inc. Computer Architecture Parhami2 Figure 11.1 Multiplication of 4-bit numbers in dot notation.
Arithmetic for Computers Chapter 3 1. Arithmetic for Computers  Operations on integers  Addition and subtraction  Multiplication and division  Dealing.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
More Binary Arithmetic - Multiplication
CHAPTER 18 Circuits for Arithmetic Operations
Morgan Kaufmann Publishers
William Stallings Computer Organization and Architecture 7th Edition
Lecture 9 Basic Dividers.
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
ECEG-3202 Computer Architecture and Organization
12/7/
Chapter 8 Computer Arithmetic
CHAPTER 18 Circuits for Arithmetic Operations
Lecture 9 Basic Dividers.
Presentation transcript:

ECE 645 – Computer Arithmetic Lecture 9: Basic Dividers ECE 645—Computer Arithmetic 4/1/08

2 Lecture Roadmap Division Notation Sequential Division Sequential Integer Unsigned Division Sequential Fractional Unsigned Division Restoring Division Restoring Unsigned Division Restoring Signed Division Non-Restoring Division Non-Restoring Unsigned Division Non-Restoring Signed Division

3 Required Reading B. Parhami, Computer Arithmetic: Algorithms and Hardware Design Chapter 13, Basic Division Schemes Note errata at:

Division Notation ECE 645 – Computer Arithmetic

5 z Dividend z 2k-1 z 2k-2... z 2 z 1 z 0 d Divisor d k-1 d k-2... d 1 d 0 q Quotient q k-1 q k-2... q 1 q 0 s Remainder s k-1 s k-2... s 1 s 0 (s = z - dq) Notation

6 Division of 8-bit number by 4-bit number in dot notation

7 Example: Unsigned Integer Division Quotient Remainder Decimal: 117/10 = 11 remainder 7

8 Note: Subtracting Unsigned Binary Example: Two methods: 1) Convert to two's complement, and add the complement (preferred). Must first add extra MSB of '0' 2) Direct unsigned subtraction (shown below) "borrow term"

9 z = d q + s sign(s) = sign(z) | s | < | d | z > 0 0  s < | d | z < 0 - | d | < s  0 Basic Equations of Division

10 Examples of Proper Signs to Fulfill Basic Division Equation Examples of division with signed operands z = 5d = 3  q = 1s = 2 z = 5d = –3  q = –1s = 2 z = –5d = 3  q = –1s = –2 z = –5d = –3  q = 1s = –2 Magnitudes of q and s are unaffected by input signs Signs of q and s are derivable from signs of z and d

11 z = z H 2 k + z L < d 2 k z = q d + s < (2 k -1) d + d = d 2 k z H < d Unsigned Integer Division Overflow Must check overflow because obviously the quotient q can also be 2k bits. For example, if the divisor d is 1, then the quotient q is the dividend z, which is 2k bits Condition for no overflow (i.e. q fits in k bits):

Sequential Division ECE 645 – Computer Arithmetic

13 s (0) = z s (j) = 2 s (j-1) - q k-j (2 k d) s (k) = 2 k s Sequential Integer Unsigned Division Basic Equations Division with left shifts There is no corresponding version with right shifts shift subtract

14 s (1) = 2 z - q k-1 (2 k d) s (2) = 2(2 z - q k-1 (2 k d)) - q k-2 (2 k d) s (3) = 2(2(2 z - q k-1 (2 k d)) - q k-2 (2 k d)) - q k-3 (2 k d)... s (k) = 2(... 2(2(2 z - q k-1 (2 k d)) - q k-2 (2 k d)) - q k-3 (2 k d)... - q 0 (2 k d) = = 2 k z - (2 k d) (q k-1 2 k-1 + q k-2 2 k-2 + q k-3 2 k-3 + … + q ) = = 2 k z - (2 k d) q = 2 k (z - d q) = 2 k s Sequential Integer Division Justification

15 Examples of Sequential Division with Integer and Fractional Operands

16 z frac Dividend.z -1 z z -(2k-1) z -2k d frac Divisor.d -1 d d -(k-1) d -k q frac Quotient.q -1 q q -(k-1) q -k s frac Remainder.000…0s -(k+1)... s -(2k-1) s -2k k bits Unsigned Fractional Division Notation

17 For Integers: z = q d + s  2 -2k z 2 -2k = (q 2 -k ) (d 2 -k ) + s (2 -2k ) z frac = q frac d frac + s frac For Fractions: where z frac = z 2 -2k d frac = d 2 -k q frac = q 2 -k s frac = s 2 -2k Integer versus Fractional Division

18 Condition for no overflow: z frac < d frac Unsigned Fractional Division Overflow

19 s (0) = z frac s (j) = 2 s (j-1) - q -j d frac 2 k · s frac = s (k) s frac = 2 -k · s (k) Sequential Fractional Unsigned Division Basic Equations

20 s (1) = 2 z frac - q -1 d frac s (2) = 2(2 z frac - q -1 d frac ) - q -2 d frac s (3) = 2(2(2 z frac - q -1 d frac ) - q -2 d frac ) - q -3 d frac... s (k) = 2(... 2(2(2 z frac - q -1 d frac ) - q -2 d frac ) - q -3 d frac... - q -k d frac = = 2 k z frac - d frac (q -1 2 k-1 + q -2 2 k-2 + q -3 2 k-3 + … + q -k 2 0 ) = = 2 k z frac - d frac 2 k (q q q … + q -k 2 -k ) = = 2 k z frac - (2 k d frac ) q frac = 2 k (z frac - d frac q frac ) = 2 k s frac Sequential Fractional Division Justification

Restoring Division ECE 645 – Computer Arithmetic

22 s (0) = z for j = 1 to k if 2 s (j-1) - 2 k d > 0 q k-j = 1 s (j) = 2 s (j-1) - 2 k d else q k-j = 0 s (j) = 2 s (j-1) Restoring Unsigned Integer Division

23 Shift/Subtract Sequential Restoring Divider

24 Example of Restoring Unsigned Division cout = 1, so set q 3 =11 cout 1 cout = 0, so set q 2 =0 and restore 0 MSB of 2s (2) = 1, so set q 1 =1 MSB of 2s (3) = 1, so set q 0 =1 ALGORITHM: if MSB of 2s (j-1) = 1 or cout = 1 then set q k-j =1 cout

25 Restoring Signed Division First convert the divisor and dividend into their equivalent unsigned binary values Then apply the correct sign values after the division is finished We will see "direct" methods of signed division later

26 z d | z || d |sign(z)sign(d) | q || s | sign(s) = sign(z) sign(q) = + - Unsigned division sign(z) = sign(d) sign(z)  sign(d) qs Restoring Signed Integer Division

27 Examples Examples of division with signed operands z = 5d = 3  q = 1s = 2 z = 5d = –3  q = –1s = 2 z = –5d = 3  q = –1s = –2 z = –5d = –3  q = 1s = –2 Magnitudes of q and s are unaffected by input signs Signs of q and s are derivable from signs of z and d

Non-Restoring Division ECE 645 – Computer Arithmetic

29 Non-Restoring and Signed Division The cycle time in restoring division must accommodate: Shifting the registers Allowing signals to propagate through the adder Determining and storing the next quotient digit Storing the trial difference, if required Later events depend on earlier ones in the same cycle, causing a lengthening of the clock cycle Nonrestoring division to the rescue! Assume q k–j = 1 and subtract Store the result as the new PR (the partial remainder can become incorrect, hence the name “nonrestoring”)

30 Why it is acceptable to store an incorrect value in the partial-remainder register? Shifted partial remainder at start of the cycle is u Suppose subtraction yields the negative result u – 2 k d Option 1: Restore the partial remainder to correct value u, shift left, and subtract to get 2u – 2 k d Option 2: Keep the incorrect partial remainder u – 2 k d, shift left, and add to get 2(u – 2 k d) + 2 k d = 2u – 2 k d Justification for Non-Restoring Division

31 s (1) = 2z-2 4 d for j = 2 to k if s (j-1)  0 q k-(j-1) = 1 s (j) = 2 s (j-1) - 2 k d else q k-(j-1) = 0 s (j) = 2 s (j-1) + 2 k d end for if s (k)  0 q 0 = 1 else q 0 = 0 if s (k) < 0 Correction step for remainder Non-Restoring Unsigned Division

32 Non-Restoring Unsigned Division Always Set q 0 =1

33 Partial Remainder Variations for Restoring and Non-Restoring Division

34 s (j) = 2 s (j-1) s (j+1) = 2 s (j) - 2 k d = = 4 s (j-1) - 2 k d s (j) = 2 s (j-1) - 2 k d s (j+1) = 2 s (j) + 2 k d = = 2 (2 s (j-1) - 2 k d) + 2 k d = = 4 s (j-1) - 2 k d Restoring division Non-Restoring division Justification Non-Restoring Unsigned Division

35 Correction step z = q d + s z = (q-1) d + (s+d) z = q’ d + s’ z = (q+1) d + (s-d) z = q” d + s” Non-Restoring Signed Integer Division

36 Shift/Subtract Sequential Non-Restoring Divider NOTE: 1. q k-j and add/subtract control determined by both divisor sign and sign of new partial remainder (via an XOR operation). Divisor sign is 0 for unsigned division. 2. note that cout is the complement of the sign of the new partial remainder, i.e. if new partial remainder = 0, then cout = 1; if new partial remainder = 1, then cout=0 +1

37 Restoring division q k–j = 0 means no subtraction (or subtraction of 0) q k–j = 1 means subtraction of d Nonrestoring division We always subtract or add It is as if quotient digits are selected from the set {1,  1}: 1 corresponds to subtraction  1 corresponds to addition Our goal is to end up with a remainder that matches the sign of the dividend This idea of trying to match the sign of s with the sign z, leads to a direct signed division algorithm if sign(s) = sign(d) then q k–j = 1 else q k–j =  1 Example: q =  1  1  1... Non-Restoring Division with Signed Operands

38 s (0) = z for j = 1 to k if sign(s (j-1) ) == sign(d) q k-j = 1 s (j) = 2 s (j-1) - 2 k d = 2 s (j-1) - q k-j (2 k d) else q k-j = -1 s (j) = 2 s (j-1) + 2 k d = 2 s (j-1) - q k-j (2 k d) Correction_step q = BSD_2’s_comp_conversion(q); Non-Restoring Signed Integer Division

39 q = (q k-1 q k-2... q 1 q 0 ) BSD = = (p k-1 p k-2... p 1 p 0 1) 2’s complement where pipi qiqi Example: q BSD p q 2’scomp = no overflow if p k-2 = p k-1 (q k-1  q k-2 ) BSD  2’s Complement Conversion

40 Partial remainder variation and selected quotient digits during nonrestoring division with d > 0 d 0  d +d+d dd dd dd +d+d +d+d 22 22 22 22 22  1 1  1  z   0 1  0   1 1  0  Quotient with digits  1 and 1 Final correction step if sign(s)  sign(z): Add d to, or subtract d from, s; subtract 1 from, or add 1 to, q Check:  – 8 – =  25 =  Replace  1s with 0s Shift left, complement MSB, and set LSB to 1 to get the 2’s-complement quotient  1 1  0  Quotient Conversion and Final Correction

41 Example of Nonrestoring Signed Division Fig Example of nonrestoring signed division. ======================== z d –2 4 d ======================== s (0) s (0) sign(s (0) )  sign(d), +2 4 d so set q 3 =  1 and add –––––––––––––––––––––––– s (1) s (1) sign(s (1) ) = sign(d), +(–2 4 d) so set q 2 = 1 and subtract –––––––––––––––––––––––– s (2) s (2) sign(s (2) )  sign(d), +2 4 d so set q 1 =  1 and add –––––––––––––––––––––––– s (3) s (3) sign(s (3) ) = sign(d), +(–2 4 d) so set q 0 = 1 and subtract –––––––––––––––––––––––– s (4) sign(s (4) )  sign(z), +(–2 4 d) so perform corrective subtraction –––––––––––––––––––––––– s (4) s q  1 1  1 1 ======================== p = Shift, compl MSB Add 1 to correct Check: 33/(  7) =  4