1 / 42

Lecture 4 Calculations in Computers

Lecture 4 Calculations in Computers. Lecture 4: Calculations in Computer. In this lecture, we will study Nonnumeric calculations Logical calculations Logical Shift, Rotate Numeric calculations Calculations with Fixed Point Numbers Arithmetic Shift Addition and Subtraction

Download Presentation

Lecture 4 Calculations in Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 4Calculations in Computers Calculations in Computers

  2. Lecture 4:Calculations in Computer In this lecture, we will study • Nonnumeric calculations • Logical calculations • Logical Shift, Rotate • Numeric calculations • Calculations with Fixed Point Numbers • Arithmetic Shift • Addition and Subtraction • Multiplication • Division • Calculations with Floating Point Numbers • Conditional Sum Adder Calculations in Computers

  3. A B A nul = A nul = 10100001 00000000 nul B = 00000000 10100010 A nul v nul B A B = Calculations With Nonnumeric Data:Logical Calculations • Complement • Logical complement, Complement of numbers • AND • Masking out bits = 10100001 10100010 10100001 10100010 ^ 1111111100000000 = 10100001 00000000 Mask • OR • Merging data = 10100001 10100010 Calculations in Computers

  4. 0 0 0 x 0 x 110000011100001 1 100000111000010 0 0 0 1 0 0 110000011100001 100000111000010 0 Calculations With Nonnumeric Data:Logical Shifts Logical shifts • Change the location of data within a register • Moving a particular bit to the carry flag for the purpose of test • Shift Right/Left with/without Carry - always 0 bit is shifted in Shift Right with Carry Shift Left with Carry C Register x1100000111000010 C Register x 1100000111000010 Shift Right Shift Left 1100000111000010 1100000111000010 Always lost a bit by shifting a data, i.e., data cannot be preserved Calculations in Computers

  5. x 110000011100001 1 100000011100010 110000011100001 100000111000010 Calculations With Nonnumeric Data: Rotation Rotate • Similar to Logical Shift • Data cannot be restored after Logical Shifts, but data can be restored after Rotate • Rotate Right/Left with/without Carry Rotate Right with Carry Rotate Left with Carry C x1100000111000010 C x1100000111000010 0 x Rotate Right Rotate Left 1100000111000010 1100000111000010 0 1 Data is preserved Calculations in Computers

  6. A = an-1 an-2 … a1 a0 n-1 V(A) = S ai x 2i i=0 Generalization(n bits): V(ARm) = 2-m x V(A) V(ALm) = 2m x V(A) Calculations With Numeric Data: Arithmetic Shifts Arithmetic Shifts • Arithmetic Shift Right n bits is equivalent to division by 2n • Arithmetic Shift Left n bits is equivalent to multiplication by 2n • The bit shifted in is not always 0 A: an unsigned positive integer Right Shift: AR1 =0an-1 an-2 … a1 n-1 V(AR1) = 2-1 ( S ai x 2i ) = 2-1 x V(A) i=1 Left Shift: AL1 = an-2 … a1 a00 n-2 V(AL1) = 21 ( S ai x 2i ) = 21 x V(A) i=0 Calculations in Computers

  7. 1 0 0 01101000 Arithmetic Shift:Shift RightUnsigned Integer A = an-1 an-2 … a1 a0 n-1 V(A) = S ai x 2i i=0 AR1 =0an-1 an-2 … a1 n-1 V(AR1) = 2-1 ( S ai x 2i ) = 2-1 x V(A) i=1 Generalization: Right shift p bits AR1 =00…0an-1 an-2 … ap n-1 V(AR1) = 2-p ( S ai x 2i ) = 2-p x V(A) i=1 A = 011010001 Shift Right A 1 bit 011010001 Calculations in Computers

  8. 0 0 0 11010001 Arithmetic Shift:Shift Left Unsigned Integer A = an-1 an-2 … a1 a0 n-1 V(A) = S ai x 2i i=0 AL1 =an-2 … a1a00 n-1 V(AL1) = 21 ( S ai x 2i ) = 21 x V(A) i=1 Generalization: Left shift p bits AR1 =an-p-1 … a000…0 n-1 V(AR1) = 2-p ( S ai x 2i ) = 2-p x V(A) i=1 A = 011010001 Shift Left A 1 bit 011010001 Calculations in Computers

  9. Representation Direction After Shift Comment 2’s Complement R AR1 = ban an-1 an-2 … a1b=an (if a0=1, truncation) L AL1 = an-1 an-2 … a1 a0b b=0 (if an-1=an, overflow) 1’s complement R AR1 = banan-1 an-2 … a1b=an (if a0=an, truncation) L AL1 = an-1 an-2 … a1 a0b b=an (if an-1=an, overflow) Calculations With Numeric Data:Arithmetic Shifts Arithmetic Shifts of a Signed Integer A A = an an-1 an-2 … a1 a0 with an: sign bit Sign plus Magnitude R AR1 = anb an-1 an-2 … a1b=0 (if a0=1, truncation) LAL1 = an an-2 … a1 a0bb=0 (if an-1=1, overflow) Calculations in Computers

  10. = +37/2 = +101/2 0 0 0 0 0 010010 0 0 100100 0 0 0 1 1 0 0 010010 0 100101 0 Arithmetic Shifts:Sign + Magnitude Shift R 1 bit: AR1 = anb an-1 an-2 … a1AR1 = A/2: b=0 (if a0=1, truncation) Shift L 1 bit: AL1 = an an-2 … a1 a0b AL1 = 2A: b=0 (if an-1=1, overflow) A = 0 0100100 = +36(a0=0 and an-1=0) Shift A 1 bit to the Right: Shift A 1 bit to the Left: 0 0100100 00100100 = +18 = A/2 = +72 = 2 x A C = 0 1100101 = +101(an-1=1) B = 0 0100101 = +37(b0=1) Shift B 1 bit to the Right: Shift C 1 bit to the Left: 0 0100101 01100101 = +18 = +74 Truncation Overflow Calculations in Computers

  11. Shift R 1 bit: AR1 = ban an-1 an-2 … a1A = A/2: b=an (if a0=1, truncation) Shift L 1 bit: AL1 = an-1 an-2 … a1 a0b A = 2A: b=0 (if an-1=an, overflow) 0 0 0 0 010110 0 101100 0 C = 0 1101101 = +109(an-1= an) 0 0 1 0 0 0 010110 1 101101 0 = B/2 = 2 x C Arithmetic Shifts:2’s Complement A = 0 0101100 = +44(a0=0 and an-1 = an) Shift A 1 bit to the Right: 00101100 Shift A 1 bit to the Left: 00101100 = +22 = A/2 = +88 = 2A B = 0 0101101 = +45(a0=1) Shift B to the Right 1 bit: Shift C to the Left 1 bit: 0 0101101 0 1101101 = +22 = - 22 Truncation Overflow Calculations in Computers

  12. 0 0 0 0 010110 0 101100 0 C = 0 1101101 = +109(an-1= an) B = 0 0101101 = +45(a0= an) Shift R 1 bit: AR1 = banan-1 an-2 … a1AR1= A/2:b=an (if a0=an, truncation) Shift L 1 bit: AL1 = an-1 an-2 … a1 a0b AL1 = 2A: b=an (if an-1=an, overflow) 0 0 1 0 0 0 010110 1 101101 0 = B/2 = 2 x C Arithmetic Shifts:1’s Complement A = 0 0101100 = +44(a0=an and an-1 = an) Shift A 1 bit to the Right: 00101100 Shift A 1 bit to the Left: 00101100 = +22 = A/2 = +88 = 2A Shift C to the Left 1 bit: Shift B to the Right 1 bit: 0 0101101 0 1101101 = +22 = - 37 Truncation Overflow Calculations in Computers

  13. 01101101 +) 00010110 10000011 carry bits 1 carry propagation xi yi ci-1 si ci 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 Calculation With Fixed Point Numbers: Addition X = xn xn-1 … x1 x0,Y = yn yn-1 … y1 y0 X + Y = S + cn Calculations in Computers

  14. If xn = yn then subtract the magnitudes If xn = yn, no overflow but if cn=1 then end-around carry Calculation With Fixed Point Numbers: Addition • Sign plus Magnitude • If xn = yn then add the magnitudes • 2’s complement • Add including sign bit • If xn = yn = 0 and cn-1 =1 then sn=1 thus overflow • If xn = yn = 1 and cn-1 =0 then sn=0 thus overflow • 1’s Complement • Add including sign bit • If xn = yn = 0 and cn-1 =1 then sn=1 thus overflow • If xn = yn = 1 and cn-1 =0 then sn=0 thus overflow , but if cn-1 = 1 no overflow • but if cn = 1 we need to add 1 to the result - end-around-carry Calculations in Computers

  15. +) X = 00100101 +) Y =00010011 +) X = 10111101 +) Y =11010011 +) X = 10100101 +) Y =10010011 +) X = 00111101 +) Y =01010011 cn-1 = 1 cn-1 = 1 Addition:Sign + Magnitude S = 0111000 0 S = 0111000 1 Overflow if cn-1=1 S = 0010000 1 S = 0010000 0 Calculations in Computers

  16. +) X = 00111101 = +61 +) Y = 01010011 = +83 +) X = 10101101 = -83 +) Y = 11000011 = -61 sn = 1 cn-1 = 1 sn = 0 cn-1 = 0 Addition:2’s Complement • Add including sign bit • If xn = yn = 0 and cn-1 =1 then sn=1 thus overflow • If xn = yn = 1 and cn-1 =0 then sn=0 thus overflow = -112 S = 10010000 = +112 S = 01110000 Overflow Overflow Calculations in Computers

  17. +) X = 10101101 = -82 +) Y = 11010011 = -44 +) X = 00010101 = +21 +) Y = 11010011 = -44 +) X = 00010101 = +21 +) Y = 11110011 = -12 +) X = 00111101 = +61 +) Y = 01010011 = +83 +) X = 10101101 = -82 +) Y = 11000011 = -60 • If xn = yn, no overflow but if cn=1 then end-around carry sn = 1 cn-1 = 1 sn = 0 cn-1 = 0 cn=1 cn=1 cn=0 End-around carry cn-1 = 1 Addition:1’s Complement • Add including sign bit • If xn = yn = 0 and cn-1 =1 then sn=1 thus overflow • If xn = yn = 1 and cn-1 =0 then sn=0 thus overflow , but if cn-1 = 1 no overflow • but if cn = 1 we need to add 1 to the result - end-around-carry = +112 S = 01110000 = -111 S = 10010000 Overflow Overflow S = 1 1101000 = -23 S = 00001000 S = 10000000 +) 1 Not overflow +) 1 1 0000001 = -126 0 0001001 = +9 Not overflow Not overflow Calculations in Computers

  18. Summer in Lake Powell, Arizona Calculations in Computers

  19. X - Y = D + bn xi yi bi-1 di bi 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 Calculation With Fixed Point Numbers: Subtraction Calculations in Computers

  20. Size of Z: (2n-1) x (2n-1) = 22n - 2n+1 + 1 22n-1 < Z < (22n - 1) 2n bits (n-1)-bit SL(X) (n-2)-bit SL(X) X Calculation With Fixed Point Numbers:Multiplication - Unsigned Numbers X(Multiplicand), Y(Multiplier) : Positive unsigned numbers X = xn-1 … x1 x0,Y = yn-1 … y1 y0 Z(Product) = X . Y We need a product register whose length is 2 times longer than the multiplicand and the multiplier. n-1 n-1 Z = X . Y = X. ( S yi . 2i) = S yi [ X . 2i] i=0 i=0 = yn-1 [ X . 2n-1 ] + yn-2 [ X . 2n-2 ] + … + y0 [ X . 20] Calculations in Computers

  21. (22n-1 - 1) < (22n - 2n+1 + 1) < (22n - 1) Calculation With Fixed Point Numbers:Size of the Register for Product • Size of registers for multiplicand and multiplier = n bits • Largest integer multiplicand and multiplier = 2n-1 • Largest product • (2n-1) x (2n-1) = 22n - 2 x 2n + 1 • = 22n - 2n+1 + 1 • Therefore, product register size must be 2n bits Calculations in Computers

  22. Add if X y0=1 X.21 y1=1 X.22 y2=1 … … X.2n-2 yn-2=1 +) X.2n-1 yn-1=1 Z Calculation With Fixed Point Numbers:Multiplication - Unsigned Numbers Example - Unsigned positive integer Multiplication Rule X = 01101010 = +106 Y = 00100101 = +37 X +) 01101010 y0=1 X.21+) 011010100y1=0 X.22 +) 0110101000 y2=1 +) 1010010010 X.23+) 01101010000 y3=0 X.24+)011010100000 y4=0 X.25+) 0110101000000 y5=1 a+). 0111101010010 X.26+) 01101010000000y6=0 X.27+) 011010100000000y7=0 Z +) 0111101010010 =+3922 Calculations in Computers

  23. n-bit SL(X) (n-1)-bit SL(X) (n-2)-bit SL(X) X X.20 y0 X . 21 y1 … … X . 2n-2 yn-2 +) X . 2n-1 yn-1 - ) X . 2n yn Z Calculation With Fixed Point Numbers:Multiplication - Signed 2’s Complement X = xn xn-1 … x1 x0,Y = yn yn-1 … y1 y0 n-1 Z = X . Y = X [ - yn . 2n + S yi . 2i] i=0 = - yn .[X . 2n ]+ yn-1[ X . 2n-1 ] + yn-2[ X . 2n-2 ] + … + y0[ X . 20] Calculations in Computers

  24. X.20 y0 X . 21 y1 … … X . 2n-2 yn-2 +) X . 2n-1 yn-1 - ) X . 2n yn Z Calculation With Fixed Point Numbers:Multiplication - Signed 2’s Complement X = 0 0101010 = +42 Y = 1 1110101 = - 11 X.20+)00101010 y0=1:Add X.21+)001010100y1=0 X.22+) 0010101000 y2=1:Add X.20+)0011010010 X.23+)00101010000y3=0 X.24+) 001010100000 y4=1:Add X.23+)001101110010 y3=0 X.25+) 0010101000000 y5=1:Add X.23+)0100010110010 y3=0 X.26+) 00101010000000y6=1 X.23+)01001100110010 y3=0 X.27-) 001010100000000y7=1:Sub X.2)=+) 110101100000000 + 2’s Compl X.27-) 111111000110010 =- 462 y7=1 Calculations in Computers

  25. n-bit SL(X) (n-1)-bit SL(X) (n-2)-bit SL(X) X X X.20 yn X.20 y0 X . 21 y1 … … X . 2n-2 yn-2 +) X . 2n-1 yn-1 - ) X . 2n yn Z Calculation With Fixed Point Numbers:Multiplication - Signed 1’s Complement X = xn xn-1 … x1 x0,Y = yn yn-1 … y1 y0 n-1 Z = X . Y = X [ yn . (1 - 2n )+ S yi . 2i] i=0 = - yn .[X . 2n ]+ yn-1[ X . 2n-1 ]+ yn-2[ X . 2n-2 ]+ … + y0[ X . 20]+ yn .[ X ] Calculations in Computers

  26. X.20 yn X.20 y0 X . 21 y1 … … X . 2n-2 yn-2 +) X . 2n-1 yn-1 - ) X . 2n yn Z Calculation With Fixed Point Numbers:Multiplication - Signed 1’s Complement X = 0 0101010 = +42 Y = 1 1110101 = - 10 X.20 +) 00101010 y7=1:Add X.20+) 00101010 y0=1:Add X.20+)01010100 y0=1 X.21+)001010100y1=0 X.22+) 0010101000 y2=1:Add X.20+)0011111100 X.23+)00101010000 y3=0 X.24+) 001010100000 y4=1:Add X.23+)001110011100 y3=0 X.25+) 0010101000000 y5=1:Add X.23+)0100011011100 y3=0 X.26+) 00101010000000y6=1 X.23+)01001101011100 y3=0 X.27-) 001010100000000y7=1:Sub X.2)=+) 110101011111111 + 1’s Comp X.27-) 111111001011011 =- 420 y7=1 Calculations in Computers

  27. Time Out • 매 주말 만사 제쳐 놓고 등산을 즐기는 초등학교 때부터 단짝으로 지내는 중년 신사 두 사람이 있는데, 이번 주말에도 어김없이 등산을 하고 있었다. • 이 때 저 아래 산을 끼고 도는 국도에는 하나의 장례차 행렬이 지나가고 있었다. • 이를 본 이들 중 한 사람이 등산모를 벗어 가슴에 얹고 정중하게 예의를 갖추었다. • 장례 행렬이 산 모퉁이를 사라지자 이를 보고 있던 다른 신사가 말했다. “ 우리가 지금까지 오랫동안 절친한 친구로 지내 왔는데, 자네가 그렇게 예의 바른 사람인줄은 몰랐네” • “자네는 모르겠지만 저 장례 행렬은 40년을 같이 살아 온 우리 집사람의 장례 행렬인데 그 정도의 예의는 갖추어야 하지 않겠는가?” 예의 바른 신사가 대답했다. Calculations in Computers

  28. Calculation With Fixed Point Numbers: Division 125 - ) 7 118 1 -) 7 111 2 -) 7 104 3 -) 7 97 4 -) 7 90 5 … 20 -) 7 13 16 -) 7 6 17 -) 7 - 1 +) 7restore 6 remainder Addition(+,-) 19 times -) 00125 -) 00700 -- 00575 00000 +) 00700restore -) 00125 -) 00070 -) 00055 00010 -) 00070 -- 00025 00010 +) 00070restore -)00055 -) 00007 -) 00048 00011 ... -) 00013 -) 00007 00017 -) 00006 -) 00007 -- 00001 00017 +) 00007 restore -) 00006 remainder Addition(+,-) 14 times 125 / 7 Calculations in Computers

  29. Calculation With Fixed Point Numbers:Division - Unsigned Numbers X, Y : Positive unsigned numbers X = xn-1 … x1 x0,Y = yn-1 … y1 y0 X(Dividend) / Y(Divisor) = Q(Quotient) + R(Remainder) Size of Q: Initial subtraction after aligning the MSB of Dividend with the LSB of Divisor. Size of Q is 2n-1 bits. However, if we want to deal with signed numbers, the size of Q should be 2n bits. Calculations in Computers

  30. Calculation With Fixed Point Numbers:Division - Unsigned Numbers 10 / 5 = 2(q3q2q1q0) + 0 Restoring Division X = 1010, Y = 0101 Initial X = X(4)0001010 0001010 X(4) -) 0101000 -Y.23 1100010 X(3) <0 q3 = 0 +) 0101000 Restore X(3) 0001010 X(3) -) 0010100 -Y.22 1110110 X(2) < 0 q2 = 0 +) 0010100 Restore X(2) 0001010 X(2) -) 0001010 -Y.21 0000000 X(1) > 0 q1 = 1 -) 0000101 -Y.20 1111011 X(0) < 0 q0 = 0 +) 0000101 +Y.20 Restore 0000000 X(0) R Non-restoring Division X = 1010, Y = 0101 Initial X=X(4) = 0001010 0001010 X(4) -) 0101000 -Y.23 1100010 X(3) < 0 q3 = 0 +) 0010100 +Y.22 1110110 X(2) < 0 q2 = 0 +) 0001010 +Y.21 0000000 X(1) > 0 q1 = 1 -) 0000101 -Y.20 1111011 X(0) < 0 q0 = 0 +) 0000101 +Y.20Restore 0000000 X(0) R Calculations in Computers

  31. Calculation With Fixed Point Numbers:Division - 2’s Complement 10 / 5 = 2(q4 q3q2q1q0) + 0 Instead of subtraction, 2’s compliment of addition Non-restoring Division X = 10 = 01010>0, Y = - 5 = 11011<0 Initial X = 00001010 000001010 X(5) +) 110110000 +Y.24 110111010 X(4) < 0 q4 = 1 sign bit +) 000101000 -Y.23 + 2’s complement of Y.23 111100010 X(3) < 0 q3 = 1 +) 000010100 -Y.22 + 2’s complement of Y.22 111110110 X(2) < 0 q2 = 1 +) 000001010 -Y.21 + 2’s complement of Y.21 000000000 X(1) > 0 q1 = 0 +) 111111011 +Y.20 111111011 X(0) < 0 q0 =1 +) 000000101 -Y.20 + 2’s complement of Y 000000000 X(0) R = 0 Q = 1 1101 + 0 0001 = 1 1110 (since q4 is 1, i.e. Q is negative add 1 to the resulting Q) Calculations in Computers

  32. Calculation With Fixed Point Numbers:Division - 1’s Complement 10 / 5 = 2(q4 q3q2q1q0) + 0 Instead of subtraction, 1’s compliment of addition Non-restoring Division X = 10 = 01010, Y = - 5 = 11010 Initial X = 00001010 000001010 X(5) +) 110101111 +Y.24 110111001 X(4) < 0 q4 = 1 sign bit +) 000101000 -Y.23 111100001 X(3) < 0 q3 = 1 +) 000010100 -Y.22 111110101 X(2) < 0 q2 = 1 +) 000001010 -Y.21 111111111 X(1) = 0 q1 = 0 +) 111111010 +Y.20 1 111111001 end-around carry +) 000000001 111111010 X(0) < 0 q0 = 1 +) 000000101 -Y.20 111111111 X(0) R = 0 Q = 1 1101 Calculations in Computers

  33. Calculations in Computers

  34. Calculation With Floating Point Numbers F1 = A1 . B1 , F2 = A2 . B2, #: add or subtract, !: multiply or divide F1 # F2 = [B1 . RA1] # [B2 . RA2] = [B1 # B2 . RA2-A1 ] . RA1 (A1 > A2) or = [B1 . RA1-A2 # B2 ] . RA2 (A1 < A2) F1 ! F2 = [B1! B2] . RA1 #A2 Calculations in Computers

  35. No need to worry about carry propagation between code symbols, simply add code symbols. |1/2|7 = |2/4|7 = |3/6|7 = |4/8|7 = |5/10|7 = |6/12|7 = |7/14|7 2/4 3/6 4/1 5/3 6/5 0/0 Chinese Remainder Representation: Addition M1=2, m2=3, m3=5, m4=7 M=210 si = | ai + bi |mi 3: 1 0 3 3 +) 12: 0 0 2 5 15: |1|2 |0|3 |5|5 |8|7 = (1 0 0 1) Verification: N1=105, N2=70, N3=42, N4=30 | (105|1/105|2) + (70|0/70|3) + (42|0/42|5) + (30|1/30|7) |210 = |(105|1/1|2) + 0 + 0 + (30 |1/2|7 ) |210 = | 105 + (30|4/1|7) |210 = | 105 + 120 | 210 = | 225 |210 = 15 Calculations in Computers

  36. Subtraction by Adding mi-complement: di = | ai + bi’ |mi bi’ = mi - bi if bi = 0 = 0 if bi = 0 (1 0 4 2) = | (|105|1/105|2+0 + (42|4/42|5) + (30|2/30|7) |210 = | 105 + 0 + (42|2/1|5) + (30|2/2|7) |210 = |105 + 84 + 30 |210 = |219|210 = 9 Chinese Remainder Representation: Subtraction Subtraction of a positive number: di = | ai - bi |mi 12: 0 0 2 5 -) 3: 1 0 3 3 |-1|2 |0|3 |-1|5 |2|7 = (1 0 4 2) 12: 0 0 2 5 +) -3: 1 0 2 4 |1|2 |0|3 |4|5 |9|7 = (1 0 4 2) Calculations in Computers

  37. mi-complement (0 0 2 5) (0 0 2 5) = | (105|0/105|2 + (70|0/70|3) + (42|2/42|5) + (30|5/30|7) |210 = | 0 + 0 + 42 + (30|5/2|7) |210 = | 42 + (30|6/1|7) |210 = | 222 |210 =12 Chinese Remainder Representation: Multiplication Product P: pi = | ai x bi |mi 3: 1 0 3 3 x) 4: 0 1 4 4 0 0 |12|5 |12|7 = (0 0 2 5) Multiplication of a negative number by mi-complement 4: 0 1 4 4 x) -3: 1 0 2 4 |0|2 |0|3 |8|5 |16|7 = (0 0 3 2) Calculations in Computers

  38. Calculation With Chinese Remainder Representations • Very compact code - mi-remainders • Allows to calculate with smaller numbers • Faster with smaller numbers • mi-complement arithmetic is possible • Difficult to compare values of numbers • No carries to propagate between mi-remainders (although we have to consider the carry propagation within an mi-remainder) • Division is extremely difficult Calculations in Computers

  39. log2n selection time 30 0 0 0 1 1 1 1 0 c level +) 177 1 0 1 1 0 0 0 1 c s c s c s c s c s c s c s c s 0 1 00 0 1 1 00 1 010 1 0 1 0 1001 101 1 10 1 0 10 10 1 1 Conditional Sum Adder • Generate 2 pairs of sum and carry bits for each bit with 1 and 0 carry-in • 1 bit Add time • Results are examined to select the correct sum and carry bits by examining • in the 2nd level, adjacent bit pairs, • in the 3rd level, adjacent 2-bit pairs, • in the 4th level, adjacent 4-bit pairs, and so on to select correct sum and carry bits => 0 10 0 1 1 1 0 0 10 1 0 1 1 10 0 01 1 2 0 1 1 0 0 0 1 1 0 1 01 1 1 1 3 0 1 1 0 0 1 1 1 1 4 Calculations in Computers

  40. a0 b0 a1 b1 a2 b2 an bn . . . CSA CSA CSA CSA s0 s1 s2 sn Addition with CR RepresentationUsing CSA S = A + B A = (a0, a1, a2, … , an) and B = (b0, b1, b2, … , bn) • Each of ai’s and bi’s is represented with p bits, where p is the number of bits needed to represent Max{mi} • Thus if q is the number of bits required to represent A or B, where q>>p which makes the CR representation faster • Each of ai’s and bi’s is represented in any binary number representation Calculations in Computers

  41. r=2 • 1964 S. Winograd(IBM) • Fan-in must be considered: Fan-in = r • Number of levels = logr 2n • Theoritical lower bound T = logr 2n t, t=block processing delay r=4 • Theoritical Lower bound for CR representation • A(N): largest remainder • d: base used for representing remainders • n: number of digit when representing A(N) in base d n = logd A(N) • add time T = logr 2 logd A(N) t Theoritical Lower Bound of Add Time • 1962 U. Offman(USSR) • For n-bit numbers, T = f(log2 n) Calculations in Computers

  42. Fan-in = r, but each processing block must take a pair of r/2 digits from both operands } r T > 1-bit add time + log r/2 logd A(N) t r/2 r/2 r/2 . . . . . . For n-bit binary remainder T > 1-bit add time + log r/2 (n/ r/2 ) t Binary n=32, r=3 r=5 r=7 CSA 6t 4t 3t Winograd(LB) 4t 3t 3t Achievable Speed of Addition Conditional Sum Adder with Chinese Remainder representation A(N) = Max {mi} i Calculations in Computers

More Related