- DBD50A883D03E0FA142CC64DFE52D846C5280F1A1A533A2DE47D2448DFBC5713D52635E2DC59DD85EF7DDBB104DC051F88296E394B059CEC88E4E99AA1C2EC9B
+ 2EB5684E04AB18696A4A448543B48445BC8E89BDC116B4BB2A25E761AD0E697959EBD8B48DFB51465751AAEB1D5AFD973D55DD55D7A075DBFCD0F56E540BFF32
ffa/libffa/fz_divis.adb
(69 . 6)(69 . 7)
1028
1029 end FZ_IDiv;
1030
1031
1032 -- Exactly same thing as IDiv, but keep only the Quotient
1033 procedure FZ_Div(Dividend : in FZ;
1034 Divisor : in FZ;
(79 . 6)(80 . 7)
1036 FZ_IDiv(Dividend, Divisor, Quotient, Remainder);
1037 end FZ_Div;
1038
1039
1040 -- Modulus. Permits the asymmetric Dividend and Divisor in FZ_Mod_Exp.
1041 procedure FZ_Mod(Dividend : in FZ;
1042 Divisor : in FZ;
(99 . 48)(101 . 43)
1044 -- Performs Restoring Division on a given segment of Dividend:Divisor
1045 procedure Slice(Index : Dividend_Index;
1046 Cut : Divisor_Cuts) is
1047
1048 -- Borrow, from comparator
1049 C : WBool;
1050
1051 -- Left-Shift Overflow
1052 LsO : WBool;
1053
1054 -- Current cut of Remainder register
1055 Rs : FZ renames R(1 .. Cut);
1056
1057 -- Current cut of Divisor
1058 Ds : FZ renames Divisor(1 .. Cut);
1059
1060 -- Current word of Dividend, starting from the highest
1061 W : Word := Dividend(Dividend'Last + 1 - Index);
1062
1063 begin
1064
1065 declare
1066
1067 -- Borrow, from comparator
1068 C : WBool;
1069
1070 -- Left-Shift Overflow
1071 LsO : WBool;
1072
1073 -- Current cut of Remainder register
1074 Rs : FZ renames R(1 .. Cut);
1075 -- For each bit in the current Dividend word:
1076 for b in 1 .. Bitness loop
1077
1078 -- Current cut of Divisor
1079 Ds : FZ renames Divisor(1 .. Cut);
1080 -- Send top bit of current Dividend word to the bottom of W
1081 W := Rotate_Left(W, 1);
1082
1083 -- Current word of Dividend, starting from the highest
1084 W : Word := Dividend(Dividend'Last + 1 - Index);
1085 -- Advance Rs, shifting in the current Dividend bit
1086 FZ_ShiftLeft_O_I(N => Rs, ShiftedN => Rs, Count => 1,
1087 OF_In => W and 1,
1088 Overflow => LsO);
1089
1090 begin
1091 -- Subtract Divisor-Cut from R-Cut; Underflow goes into C
1092 FZ_Sub(X => Rs, Y => Ds, Difference => Rs, Underflow => C);
1093
1094 -- For each bit in the current Dividend word:
1095 for b in 1 .. Bitness loop
1096
1097 -- Send top bit of current Dividend word to the bottom of W
1098 W := Rotate_Left(W, 1);
1099
1100 -- Advance Rs, shifting in the current Dividend bit
1101 FZ_ShiftLeft_O_I(N => Rs, ShiftedN => Rs, Count => 1,
1102 OF_In => W and 1,
1103 Overflow => LsO);
1104
1105 -- Subtract Divisor-Cut from R-Cut; Underflow goes into C
1106 FZ_Sub(X => Rs, Y => Ds, Difference => Rs, Underflow => C);
1107
1108 -- If C=1, subtraction underflowed, and we must undo it:
1109 FZ_Add_Gated(X => Rs, Y => Ds, Sum => Rs,
1110 Gate => C and W_Not(LsO));
1111
1112 end loop;
1113 -- If C=1, subtraction underflowed, and we must undo it:
1114 FZ_Add_Gated(X => Rs, Y => Ds, Sum => Rs,
1115 Gate => C and W_Not(LsO));
1116
1117 end;
1118 end loop;
1119
1120 end Slice;
1121