- 81335CBF5970684E89C61B7A37BFF32F747027A72251D88F2980D21E52D41B88D05503613E11404D55BE9C5DEA3170A7A069CDD32FC4DF64500164BCEE844AF9
+ 20B94E2B0260DD90AEDA5E987C038348070FA29AFFF8FD41A84BDA53CF6BFC15638809387A6C9C44C6F9FCBDC28C5E5AFD7E1EFA43B0DA72F89B9C198F603670
ffa/libffa/fz_mul.adb
(18 . 8)(18 . 8)
159 ------------------------------------------------------------------------------
160
161 with Words; use Words;
162 with W_Shifts; use W_Shifts;
163 with FZ_Basic; use FZ_Basic;
164 with FZ_Pred; use FZ_Pred;
165 with FZ_Arith; use FZ_Arith;
166 with FZ_Shift; use FZ_Shift;
167
(32 . 15)(32 . 14)
169 XY_Lo : out FZ;
170 XY_Hi : out FZ) is
171
172 L : constant Indices := X'Length;
173
174 -- Register holding running product
175 XY : FZ(1 .. X'Length + Y'Length);
176
177 -- X-Slide
178 XS : FZ(1 .. X'Length + Y'Length);
179
180 -- Y-Slide
181 YS : FZ(Y'Range) := Y;
182
183 begin
184 -- Product register begins empty
185 FZ_Clear(XY);
(49 . 18)(48 . 33)
187 XS(1 .. X'Length) := X;
188 XS(X'Length + 1 .. XS'Last) := (others => 0);
189
190 -- For each bit of Y:
191 for i in 1 .. FZ_Bitness(Y) loop
192
193 -- If lowest bit of Y-Slide is 1, X-Slide is added into XY
194 FZ_Add_Gated(X => XY, Y => XS, Sum => XY,
195 Gate => FZ_OddP(YS));
196
197 -- X-Slide := X-Slide * 2
198 FZ_ShiftLeft(XS, XS, 1);
199 -- For each word of Y:
200 for i in Y'Range loop
201
202 -- Y-Slide := Y-Slide / 2
203 FZ_ShiftRight(YS, YS, 1);
204 declare
205 -- Current word of Y
206 W : Word := Y(i);
207
208 -- Current cut of XY and XS. Stay ahead by a word to handle carry.
209 Cut : constant Indices := L + i;
210 XYc : FZ renames XY(1 .. Cut);
211 XSc : FZ renames XS(1 .. Cut);
212
213 begin
214 for b in 1 .. Bitness loop
215
216 -- If current Y bit is 1, X-Slide Cut is added into XY Cut
217 FZ_Add_Gated(X => XYc, Y => XSc, Sum => XYc,
218 Gate => W and 1);
219
220 -- Crank the next bit of Y into the bottom position of W
221 W := Shift_Right(W, 1);
222
223 -- X-Slide := X-Slide * 2
224 FZ_ShiftLeft(XSc, XSc, 1);
225
226 end loop;
227 end;
228
229 end loop;
230