-
+ 81335CBF5970684E89C61B7A37BFF32F747027A72251D88F2980D21E52D41B88D05503613E11404D55BE9C5DEA3170A7A069CDD32FC4DF64500164BCEE844AF9
ffa/libffa/fz_mul.adb
(0 . 0)(1 . 74)
351 ------------------------------------------------------------------------------
352 ------------------------------------------------------------------------------
353 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
354 -- --
355 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
356 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
357 -- --
358 -- You do not have, nor can you ever acquire the right to use, copy or --
359 -- distribute this software ; Should you use this software for any purpose, --
360 -- or copy and distribute it to anyone or in any manner, you are breaking --
361 -- the laws of whatever soi-disant jurisdiction, and you promise to --
362 -- continue doing so for the indefinite future. In any case, please --
363 -- always : read and understand any software ; verify any PGP signatures --
364 -- that you use - for any purpose. --
365 -- --
366 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
367 ------------------------------------------------------------------------------
368 ------------------------------------------------------------------------------
369
370 with Words; use Words;
371 with FZ_Basic; use FZ_Basic;
372 with FZ_Pred; use FZ_Pred;
373 with FZ_Arith; use FZ_Arith;
374 with FZ_Shift; use FZ_Shift;
375
376
377 package body FZ_Mul is
378
379 -- 'Egyptological' multiplier. XY_Lo and XY_Hi hold result of X*Y.
380 procedure FZ_Mul_Egyptian(X : in FZ;
381 Y : in FZ;
382 XY_Lo : out FZ;
383 XY_Hi : out FZ) is
384
385 -- Register holding running product
386 XY : FZ(1 .. X'Length + Y'Length);
387
388 -- X-Slide
389 XS : FZ(1 .. X'Length + Y'Length);
390
391 -- Y-Slide
392 YS : FZ(Y'Range) := Y;
393
394 begin
395 -- Product register begins empty
396 FZ_Clear(XY);
397
398 -- X-Slide initially equals X:
399 XS(1 .. X'Length) := X;
400 XS(X'Length + 1 .. XS'Last) := (others => 0);
401
402 -- For each bit of Y:
403 for i in 1 .. FZ_Bitness(Y) loop
404
405 -- If lowest bit of Y-Slide is 1, X-Slide is added into XY
406 FZ_Add_Gated(X => XY, Y => XS, Sum => XY,
407 Gate => FZ_OddP(YS));
408
409 -- X-Slide := X-Slide * 2
410 FZ_ShiftLeft(XS, XS, 1);
411
412 -- Y-Slide := Y-Slide / 2
413 FZ_ShiftRight(YS, YS, 1);
414
415 end loop;
416
417 -- Write out the Product's lower and upper FZs:
418 XY_Lo := XY(1 .. XY_Lo'Length);
419 XY_Hi := XY(XY_Lo'Length + 1 .. XY'Last);
420
421 end FZ_Mul_Egyptian;
422 pragma Inline_Always(FZ_Mul_Egyptian);
423
424 end FZ_Mul;