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_ch7_turbo_egy... 21 with W_Shifts; use W_Shifts;
ffa_ch5_egypt.kv 22 with FZ_Basic; use FZ_Basic;
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_ch7_turbo_egy... 35 L : constant Indices := X'Length;
ffa_ch7_turbo_egy... 36
ffa_ch5_egypt.kv 37 -- Register holding running product
ffa_ch5_egypt.kv 38 XY : FZ(1 .. X'Length + Y'Length);
ffa_ch5_egypt.kv 39
ffa_ch5_egypt.kv 40 -- X-Slide
ffa_ch5_egypt.kv 41 XS : FZ(1 .. X'Length + Y'Length);
ffa_ch5_egypt.kv 42
ffa_ch5_egypt.kv 43 begin
ffa_ch5_egypt.kv 44 -- Product register begins empty
ffa_ch5_egypt.kv 45 FZ_Clear(XY);
ffa_ch5_egypt.kv 46
ffa_ch5_egypt.kv 47 -- X-Slide initially equals X:
ffa_ch5_egypt.kv 48 XS(1 .. X'Length) := X;
ffa_ch5_egypt.kv 49 XS(X'Length + 1 .. XS'Last) := (others => 0);
ffa_ch5_egypt.kv 50
ffa_ch7_turbo_egy... 51 -- For each word of Y:
ffa_ch7_turbo_egy... 52 for i in Y'Range loop
ffa_ch5_egypt.kv 53
ffa_ch7_turbo_egy... 54 declare
ffa_ch7_turbo_egy... 55 -- Current word of Y
ffa_ch7_turbo_egy... 56 W : Word := Y(i);
ffa_ch7_turbo_egy... 57
ffa_ch7_turbo_egy... 58 -- Current cut of XY and XS. Stay ahead by a word to handle carry.
ffa_ch7_turbo_egy... 59 Cut : constant Indices := L + i;
ffa_ch7_turbo_egy... 60 XYc : FZ renames XY(1 .. Cut);
ffa_ch7_turbo_egy... 61 XSc : FZ renames XS(1 .. Cut);
ffa_ch7_turbo_egy... 62
ffa_ch7_turbo_egy... 63 begin
ffa_ch7_turbo_egy... 64 for b in 1 .. Bitness loop
ffa_ch7_turbo_egy... 65
ffa_ch7_turbo_egy... 66 -- If current Y bit is 1, X-Slide Cut is added into XY Cut
ffa_ch7_turbo_egy... 67 FZ_Add_Gated(X => XYc, Y => XSc, Sum => XYc,
ffa_ch7_turbo_egy... 68 Gate => W and 1);
ffa_ch7_turbo_egy... 69
ffa_ch7_turbo_egy... 70 -- Crank the next bit of Y into the bottom position of W
ffa_ch7_turbo_egy... 71 W := Shift_Right(W, 1);
ffa_ch7_turbo_egy... 72
ffa_ch7_turbo_egy... 73 -- X-Slide := X-Slide * 2
ffa_ch7_turbo_egy... 74 FZ_ShiftLeft(XSc, XSc, 1);
ffa_ch7_turbo_egy... 75
ffa_ch7_turbo_egy... 76 end loop;
ffa_ch7_turbo_egy... 77 end;
ffa_ch5_egypt.kv 78
ffa_ch5_egypt.kv 79 end loop;
ffa_ch5_egypt.kv 80
ffa_ch5_egypt.kv 81 -- Write out the Product's lower and upper FZs:
ffa_ch5_egypt.kv 82 XY_Lo := XY(1 .. XY_Lo'Length);
ffa_ch5_egypt.kv 83 XY_Hi := XY(XY_Lo'Length + 1 .. XY'Last);
ffa_ch5_egypt.kv 84
ffa_ch5_egypt.kv 85 end FZ_Mul_Egyptian;
ffa_ch5_egypt.kv 86 pragma Inline_Always(FZ_Mul_Egyptian);
ffa_ch5_egypt.kv 87
ffa_ch5_egypt.kv 88 end FZ_Mul;