ffa_ch15_gcd.kv 1
ffa_ch15_gcd.kv 2
ffa_ch15_gcd.kv 3
ffa_ch15_gcd.kv 4
ffa_ch15_gcd.kv 5
ffa_ch15_gcd.kv 6
ffa_ch15_gcd.kv 7
ffa_ch15_gcd.kv 8
ffa_ch15_gcd.kv 9
ffa_ch15_gcd.kv 10
ffa_ch15_gcd.kv 11
ffa_ch15_gcd.kv 12
ffa_ch15_gcd.kv 13
ffa_ch15_gcd.kv 14
ffa_ch15_gcd.kv 15
ffa_ch15_gcd.kv 16
ffa_ch15_gcd.kv 17
ffa_ch15_gcd.kv 18
ffa_ch15_gcd.kv 19 with Words; use Words;
ffa_ch15_gcd.kv 20 with FZ_Basic; use FZ_Basic;
ffa_ch15_gcd.kv 21 with FZ_Shift; use FZ_Shift;
ffa_ch15_gcd.kv 22 with FZ_QShft; use FZ_QShft;
ffa_ch15_gcd.kv 23 with FZ_Arith; use FZ_Arith;
ffa_ch15_gcd.kv 24 with FZ_Pred; use FZ_Pred;
ffa_ch15_gcd.kv 25
ffa_ch15_gcd.kv 26
ffa_ch15_gcd.kv 27 package body FZ_GCD is
ffa_ch15_gcd.kv 28
ffa_ch15_gcd.kv 29
ffa_ch15_gcd.kv 30
ffa_ch15_gcd.kv 31 procedure FZ_Greatest_Common_Divisor(X : in FZ;
ffa_ch15_gcd.kv 32 Y : in FZ;
ffa_ch15_gcd.kv 33 Result : out FZ) is
ffa_ch15_gcd.kv 34
ffa_ch15_gcd.kv 35
ffa_ch15_gcd.kv 36 subtype Width is Word_Index range X'Range;
ffa_ch15_gcd.kv 37
ffa_ch15_gcd.kv 38
ffa_ch15_gcd.kv 39 A : FZ(Width) := X;
ffa_ch15_gcd.kv 40 B : FZ(Width) := Y;
ffa_ch15_gcd.kv 41
ffa_ch15_gcd.kv 42
ffa_ch15_gcd.kv 43 Ae, Be : WBool;
ffa_ch15_gcd.kv 44
ffa_ch15_gcd.kv 45
ffa_ch15_gcd.kv 46 Twos : Word := 0;
ffa_ch15_gcd.kv 47
ffa_ch15_gcd.kv 48
ffa_ch15_gcd.kv 49 D : FZ(Width);
ffa_ch15_gcd.kv 50
ffa_ch15_gcd.kv 51
ffa_ch15_gcd.kv 52 A_lt_B : WBool;
ffa_ch15_gcd.kv 53
ffa_ch15_gcd.kv 54 begin
ffa_ch15_gcd.kv 55
ffa_ch15_gcd.kv 56
ffa_ch15_gcd.kv 57 for i in 1 .. 2 * FZ_Bitness(X) loop
ffa_ch15_gcd.kv 58
ffa_ch15_gcd.kv 59
ffa_ch15_gcd.kv 60 Ae := 1 - FZ_OddP(A);
ffa_ch15_gcd.kv 61 FZ_ShiftRight(A, A, WBit_Index(Ae));
ffa_ch15_gcd.kv 62
ffa_ch15_gcd.kv 63
ffa_ch15_gcd.kv 64 Be := 1 - FZ_OddP(B);
ffa_ch15_gcd.kv 65 FZ_ShiftRight(B, B, WBit_Index(Be));
ffa_ch15_gcd.kv 66
ffa_ch15_gcd.kv 67
ffa_ch15_gcd.kv 68 Twos := Twos + (Ae and Be);
ffa_ch15_gcd.kv 69
ffa_ch15_gcd.kv 70
ffa_ch15_gcd.kv 71 FZ_Sub_Abs(X => A, Y => B, Difference => D, Underflow => A_lt_B);
ffa_ch15_gcd.kv 72
ffa_ch15_gcd.kv 73
ffa_ch15_gcd.kv 74 FZ_Mux(X => B, Y => A, Result => B, Sel => A_lt_B);
ffa_ch15_gcd.kv 75
ffa_ch15_gcd.kv 76
ffa_ch15_gcd.kv 77 A := D;
ffa_ch15_gcd.kv 78
ffa_ch15_gcd.kv 79 end loop;
ffa_ch15_gcd.kv 80
ffa_ch15_gcd.kv 81
ffa_ch15_gcd.kv 82 FZ_Quiet_ShiftLeft(N => A, ShiftedN => A, Count => Indices(Twos));
ffa_ch15_gcd.kv 83
ffa_ch15_gcd.kv 84
ffa_ch15_gcd.kv 85 Result := A;
ffa_ch15_gcd.kv 86
ffa_ch15_gcd.kv 87 end FZ_Greatest_Common_Divisor;
ffa_ch15_gcd.kv 88
ffa_ch15_gcd.kv 89 end FZ_GCD;