raw
ffa_ch5_egypt.kv        1 ------------------------------------------------------------------------------
ffa_ch5_egypt.kv 2 ------------------------------------------------------------------------------
ffa_ch5_egypt.kv 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch5_egypt.kv 4 -- --
ffa_ch5_egypt.kv 5 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch5_egypt.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch5_egypt.kv 7 -- --
ffa_ch5_egypt.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch5_egypt.kv 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch5_egypt.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch5_egypt.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch5_egypt.kv 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch5_egypt.kv 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch5_egypt.kv 14 -- that you use - for any purpose. --
ffa_ch5_egypt.kv 15 -- --
ffa_ch5_egypt.kv 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch5_egypt.kv 17 ------------------------------------------------------------------------------
ffa_ch5_egypt.kv 18 ------------------------------------------------------------------------------
ffa_ch5_egypt.kv 19
ffa_ch5_egypt.kv 20 with Words; use Words;
ffa_ch5_egypt.kv 21 with FZ_Basic; use FZ_Basic;
ffa_ch5_egypt.kv 22 with FZ_Pred; use FZ_Pred;
ffa_ch5_egypt.kv 23 with FZ_Arith; use FZ_Arith;
ffa_ch5_egypt.kv 24 with FZ_Shift; use FZ_Shift;
ffa_ch5_egypt.kv 25
ffa_ch5_egypt.kv 26
ffa_ch5_egypt.kv 27 package body FZ_Mul is
ffa_ch5_egypt.kv 28
ffa_ch5_egypt.kv 29 -- 'Egyptological' multiplier. XY_Lo and XY_Hi hold result of X*Y.
ffa_ch5_egypt.kv 30 procedure FZ_Mul_Egyptian(X : in FZ;
ffa_ch5_egypt.kv 31 Y : in FZ;
ffa_ch5_egypt.kv 32 XY_Lo : out FZ;
ffa_ch5_egypt.kv 33 XY_Hi : out FZ) is
ffa_ch5_egypt.kv 34
ffa_ch5_egypt.kv 35 -- Register holding running product
ffa_ch5_egypt.kv 36 XY : FZ(1 .. X'Length + Y'Length);
ffa_ch5_egypt.kv 37
ffa_ch5_egypt.kv 38 -- X-Slide
ffa_ch5_egypt.kv 39 XS : FZ(1 .. X'Length + Y'Length);
ffa_ch5_egypt.kv 40
ffa_ch5_egypt.kv 41 -- Y-Slide
ffa_ch5_egypt.kv 42 YS : FZ(Y'Range) := Y;
ffa_ch5_egypt.kv 43
ffa_ch5_egypt.kv 44 begin
ffa_ch5_egypt.kv 45 -- Product register begins empty
ffa_ch5_egypt.kv 46 FZ_Clear(XY);
ffa_ch5_egypt.kv 47
ffa_ch5_egypt.kv 48 -- X-Slide initially equals X:
ffa_ch5_egypt.kv 49 XS(1 .. X'Length) := X;
ffa_ch5_egypt.kv 50 XS(X'Length + 1 .. XS'Last) := (others => 0);
ffa_ch5_egypt.kv 51
ffa_ch5_egypt.kv 52 -- For each bit of Y:
ffa_ch5_egypt.kv 53 for i in 1 .. FZ_Bitness(Y) loop
ffa_ch5_egypt.kv 54
ffa_ch5_egypt.kv 55 -- If lowest bit of Y-Slide is 1, X-Slide is added into XY
ffa_ch5_egypt.kv 56 FZ_Add_Gated(X => XY, Y => XS, Sum => XY,
ffa_ch5_egypt.kv 57 Gate => FZ_OddP(YS));
ffa_ch5_egypt.kv 58
ffa_ch5_egypt.kv 59 -- X-Slide := X-Slide * 2
ffa_ch5_egypt.kv 60 FZ_ShiftLeft(XS, XS, 1);
ffa_ch5_egypt.kv 61
ffa_ch5_egypt.kv 62 -- Y-Slide := Y-Slide / 2
ffa_ch5_egypt.kv 63 FZ_ShiftRight(YS, YS, 1);
ffa_ch5_egypt.kv 64
ffa_ch5_egypt.kv 65 end loop;
ffa_ch5_egypt.kv 66
ffa_ch5_egypt.kv 67 -- Write out the Product's lower and upper FZs:
ffa_ch5_egypt.kv 68 XY_Lo := XY(1 .. XY_Lo'Length);
ffa_ch5_egypt.kv 69 XY_Hi := XY(XY_Lo'Length + 1 .. XY'Last);
ffa_ch5_egypt.kv 70
ffa_ch5_egypt.kv 71 end FZ_Mul_Egyptian;
ffa_ch5_egypt.kv 72 pragma Inline_Always(FZ_Mul_Egyptian);
ffa_ch5_egypt.kv 73
ffa_ch5_egypt.kv 74 end FZ_Mul;