1 / 25

A Redundant Binary Euclidean GCD Algorithm

A Redundant Binary Euclidean GCD Algorithm. S. N. Parikh, D. W. Matula Computer Arithmetic 10th IEEE Symposium pp.220-225 1991 陳正昇. Outline. Binary Euclidean Algorithm Redundant Binary Representation and normalization Redundant Binary Euclidean Algorithm. Binary Euclidean Algorithm.

cleave
Download Presentation

A Redundant Binary Euclidean GCD Algorithm

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. A Redundant Binary Euclidean GCD Algorithm S. N. Parikh, D. W. Matula Computer Arithmetic 10th IEEE Symposium pp.220-225 1991 陳正昇 1

  2. Outline • Binary Euclidean Algorithm • Redundant Binary Representation and normalization • Redundant Binary Euclidean Algorithm 2

  3. Binary Euclidean Algorithm • Normalized • 數字介於[1/2,1),(-1,-1/2]之間 • Time complexity • O(nlogn) with O(n) hardware 3

  4. Binary Euclidean Algorithm • 1. While P and Q not normalized do //normalize P and Q • 2. leftshift P,Q,Up,Uq; • 3. While Q != 0 do begin //find GCD(P,Q) , terminates when Q=0 • 4. While Q not normalized do //normalize Q • 5. leftshift Q and Uq; • 6. Loop //find the remainder of P/Q • 7. While P not normailzed do //normalize P • 8. Exit Loop if Uq=Up; • 9. Leftshift P and Up; • 10. End; • 11. If sign(P)=sign(Q) then //find the difference of P and Q • 12. P=P-Q • 13. else P=P+Q; • 14. EndLoop; • 15. Swap(P,Q);Swap(Up,Uq); //interchange of divisor and remainder • 16. End; • 17. While Up != 1 do rightshift P and Up; //shift back the P 4

  5. Binary Euclidean Algorithm • 1. While P and Q not normalized do //normalize P and Q • 2. leftshift P,Q,Up,Uq; • 3. While Q != 0 do begin //find GCD(P,Q) • 4. While Q not normalized do //normalize Q • 5. leftshift Q and Uq; • 6. Loop //find the remainder of P/Q • 7. While P not normailzed do //normalize P • 8. Exit Loop if Uq=Up; • 9. Leftshift P and Up; • 10. End; 5

  6. Binary Euclidean Algorithm • 11. If sign(P)=sign(Q) then //find the difference of P and Q • 12. P=P-Q • 13. else P=P+Q; • 14. EndLoop; • 15. Swap(P,Q);Swap(Up,Uq); //interchange of divisor and remainder • 16. End; • 17. While Up != 1 do rightshift P and Up; //shift back the P 6

  7. EX. of Binary Euclidean Algorithm • P = 27(dec) = 11011(bin)  27/32 = 0.11011(bf) • Q = -12(dec) = -1100(bin)  -12/32 = -0.011(bf) • GCD(P,Q) = 3(dec) = 11(bin)  3/32 = 0.00011(bf) 7

  8. EX. of Binary Euclidean Algorithm 8

  9. EX. of Binary Euclidean Algorithm 9

  10. EX. of Binary Euclidean Algorithm 3/32 = 0.00011(bf) GCD(P,Q) = 11(bin) = 3(dec) 10

  11. Redundant Binary Representation and normalization • Binary redundant representation • (b = 2, -1  aj 1 ) • n = (1864)10 = (11101001000)2= (100101001000)2 • 1 = -1 11

  12. Redundant Binary Representation and normalization • Signed bit fraction • b0.b1b3b4```bk , bi = 1,0,1 for all i • 1 = -1 • Normalized standard form : b0=0 , b1!=0 and b2!=-b1 • Complement standard form : b0!=0 , b1=0 12

  13. Redundant Binary Representation and normalization • Normalized • 數字介於(1/4,1),(-1,-1/4)之間 13

  14. Redundant Binary Representation and normalization • Simshift(P)= • 0.b1b3b4```bk , if b1!=0 and b1=-b2 • 0.b2b3b4```bk , if b1=0 • 在Redundant Binary形式下的leftshift (*2) 14

  15. Redundant Binary Representation and normalization • decomp(P)= • 0.b0b2b3```bk , if b0=-b1!=0 • P , if b0=0 • 轉成 Normalized standard form 15

  16. Redundant Binary Representation and normalization • a diff b= • a-b for ab >= 0 (a,b同號) • a+b for ab < 0 (a,b不同號) • 求a和b的差 16

  17. Redundant Binary Euclidean Algorithm • 1. While P and Q not normalized do • 2. Simshift P,Q and leftshift Up,Uq //Simshift P and Q • 3. LoopA • 4. While Q not normalized do //Simshift P • 5. Simshift Q and leftshift Uq; • 6. Exit LoopA if Uq overflows; • 7. LoopB //find the remainder of P/Q • 8. While P not normalized do //Simshift Q • 9. Exit LoopB if Up=Uq; • 10. Simshift P and leftshift Up; • 11. If(P diff Q) is normalized then //find the difference of P and Q • 12. If sign(P diff q) != sign(P) then • 13. If Up != Uq then • 14. leftshift Up; P = 2P diff Q; • 15. Else exit LoopB; • 16. Else P = P diff 2Q; • 17. Else P = P diff Q; • 18. P = decomp(P); //transform p to normalized standard form • 19. Simshift P; //Simshift P • 20. If Up != Uq then leftshift Up; • 21. Else leftshift Up and exit LoopB; • 22. End LoopB; • 23. Swap(P,Q);Swap(Up,Uq); //interchange of divisor and remainder • 24. End LoopA; • 25. While Up != 1 do rightshift P,Up //shift back the P 17

  18. Redundant Binary Euclidean Algorithm • 1. While P and Q not normalized do • 2. Simshift P,Q and leftshift Up,Uq //Simshift P and Q • 3. LoopA • 4. While Q not normalized do //Simshift P • 5. Simshift Q and leftshift Uq; • 6. Exit LoopA if Uq overflows; • 7. LoopB //find the remainder of P/Q • 8. While P not normalized do //Simshift Q • 9. Exit LoopB if Up=Uq; • 10. Simshift P and leftshift Up; //find the difference of P and Q • 11. If(P diff Q) is normalized then • 12. If sign(P diff q) != sign(P) then • 13. If Up != Uq then • 14. leftshift Up; P = 2P diff Q; • 15. Else exit LoopB; 18

  19. Redundant Binary Euclidean Algorithm • 16. Else P = P diff 2Q; • 17. Else P = P diff Q; //transform p to normalized standard form • 18. P = decomp(P); • 19. Simshift P; //Simshift P • 20. If Up != Uq then leftshift Up; • 21. Else leftshift Up and exit LoopB; • 22. End LoopB; //interchange of divisor and remainder • 23. Swap(P,Q);Swap(Up,Uq); • 24. End LoopA; • 25. While Up != 1 do rightshift P,Up //shift back the P 19

  20. Redundant Binary Euclidean Algorithm • Time complexity • Addition is O(n) 4-2 signed 1-bit adders • O(n) with O(n) bit level processors 20

  21. EX. of Redundant Binary Euclidean Algorithm • P = 27(dec) = 011011(bin)  27/32 = 0.11011(sbf) • Q = -12(dec) = 111001(1`sc)  -12/32 = 0.011(sbf) GCD(P,Q) = 3(dec) = 000011(bin) 0.00011 (sbf) = 3/32 21

  22. EX. of Redundant Binary Euclidean Algorithm 22

  23. EX. of Redundant Binary Euclidean Algorithm 23

  24. EX. of Redundant Binary Euclidean Algorithm 24

  25. EX. of Redundant Binary Euclidean Algorithm • 3/32 = 0.00011(bf) GCD(P,Q) = 011(bin) = 3(dec) 25

More Related