raw
ffa_ch11_tuning_a...    1 ------------------------------------------------------------------------------
ffa_ch11_tuning_a... 2 ------------------------------------------------------------------------------
ffa_ch11_tuning_a... 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch11_tuning_a... 4 -- --
ffa_ch11_tuning_a... 5 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch11_tuning_a... 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch11_tuning_a... 7 -- --
ffa_ch11_tuning_a... 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch11_tuning_a... 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch11_tuning_a... 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch11_tuning_a... 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch11_tuning_a... 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch11_tuning_a... 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch11_tuning_a... 14 -- that you use - for any purpose. --
ffa_ch11_tuning_a... 15 -- --
ffa_ch11_tuning_a... 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch11_tuning_a... 17 ------------------------------------------------------------------------------
ffa_ch11_tuning_a... 18 ------------------------------------------------------------------------------
ffa_ch11_tuning_a... 19
ffa_ch11_tuning_a... 20 with FZ_Arith;
ffa_ch11_tuning_a... 21 with FZ_Shift;
ffa_ch11_tuning_a... 22 with FZ_Mul;
ffa_ch11_tuning_a... 23
ffa_ch11_tuning_a... 24
ffa_ch11_tuning_a... 25 -- Wrapper bodies for routines that we inline, but must enforce preconditions
ffa_ch11_tuning_a... 26 -- on when called by FFA user.
ffa_ch11_tuning_a... 27 package body FFA is
ffa_ch11_tuning_a... 28
ffa_ch11_tuning_a... 29 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 30 --- FZ Basics
ffa_ch11_tuning_a... 31 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 32
ffa_ch11_tuning_a... 33 -- Exchange X and Y
ffa_ch11_tuning_a... 34 procedure FFA_FZ_Swap(X : in out FZ; Y : in out FZ) is
ffa_ch11_tuning_a... 35 begin
ffa_ch11_tuning_a... 36 FZ_Basic.FZ_Swap(X => X, Y => Y);
ffa_ch11_tuning_a... 37 end FFA_FZ_Swap;
ffa_ch11_tuning_a... 38
ffa_ch11_tuning_a... 39 -- Constant-time MUX: Sel = 0: Result := X; Sel = 1: Result := Y
ffa_ch11_tuning_a... 40 procedure FFA_FZ_Mux(X : in FZ; Y : in FZ;
ffa_ch11_tuning_a... 41 Result : out FZ; Sel : in WBool) is
ffa_ch11_tuning_a... 42 begin
ffa_ch11_tuning_a... 43 FZ_Basic.FZ_Mux(X => X, Y => Y, Result => Result, Sel => Sel);
ffa_ch11_tuning_a... 44 end FFA_FZ_Mux;
ffa_ch11_tuning_a... 45
ffa_ch11_tuning_a... 46 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 47 --- Bitwise Operations on FZ
ffa_ch11_tuning_a... 48 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 49
ffa_ch11_tuning_a... 50 -- Result := X & Y
ffa_ch11_tuning_a... 51 procedure FFA_FZ_And(X : in FZ; Y : in FZ; Result : out FZ) is
ffa_ch11_tuning_a... 52 begin
ffa_ch11_tuning_a... 53 FZ_BitOp.FZ_And(X => X, Y => Y, Result => Result);
ffa_ch11_tuning_a... 54 end FFA_FZ_And;
ffa_ch11_tuning_a... 55
ffa_ch11_tuning_a... 56 -- Result := X | Y
ffa_ch11_tuning_a... 57 procedure FFA_FZ_Or(X : in FZ; Y : in FZ; Result : out FZ) is
ffa_ch11_tuning_a... 58 begin
ffa_ch11_tuning_a... 59 FZ_BitOp.FZ_Or(X => X, Y => Y, Result => Result);
ffa_ch11_tuning_a... 60 end FFA_FZ_Or;
ffa_ch11_tuning_a... 61
ffa_ch11_tuning_a... 62 -- Result := X ^ Y
ffa_ch11_tuning_a... 63 procedure FFA_FZ_Xor(X : in FZ; Y : in FZ; Result : out FZ) is
ffa_ch11_tuning_a... 64 begin
ffa_ch11_tuning_a... 65 FZ_BitOp.FZ_Xor(X => X, Y => Y, Result => Result);
ffa_ch11_tuning_a... 66 end FFA_FZ_Xor;
ffa_ch11_tuning_a... 67
ffa_ch11_tuning_a... 68 -- NotN := ~N ('ones complement')
ffa_ch11_tuning_a... 69 procedure FFA_FZ_Not(N : in FZ; NotN : out FZ) is
ffa_ch11_tuning_a... 70 begin
ffa_ch11_tuning_a... 71 FZ_BitOp.FZ_Not(N => N, NotN => NotN);
ffa_ch11_tuning_a... 72 end FFA_FZ_Not;
ffa_ch11_tuning_a... 73
ffa_ch11_tuning_a... 74 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 75 --- Arithmetic on FZ
ffa_ch11_tuning_a... 76 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 77
ffa_ch11_tuning_a... 78 -- Sum := X + Y; Overflow := Carry
ffa_ch11_tuning_a... 79 procedure FFA_FZ_Add(X : in FZ;
ffa_ch11_tuning_a... 80 Y : in FZ;
ffa_ch11_tuning_a... 81 Sum : out FZ;
ffa_ch11_tuning_a... 82 Overflow : out WBool) is
ffa_ch11_tuning_a... 83 begin
ffa_ch11_tuning_a... 84 FZ_Arith.FZ_Add(X => X, Y => Y, Sum => Sum, Overflow => Overflow);
ffa_ch11_tuning_a... 85 end FFA_FZ_Add;
ffa_ch11_tuning_a... 86
ffa_ch11_tuning_a... 87 -- Difference := X - Y; Underflow := Borrow
ffa_ch11_tuning_a... 88 procedure FFA_FZ_Subtract(X : in FZ;
ffa_ch11_tuning_a... 89 Y : in FZ;
ffa_ch11_tuning_a... 90 Difference : out FZ;
ffa_ch11_tuning_a... 91 Underflow : out WBool) is
ffa_ch11_tuning_a... 92 begin
ffa_ch11_tuning_a... 93 FZ_Arith.FZ_Sub(X => X, Y => Y, Difference => Difference,
ffa_ch11_tuning_a... 94 Underflow => Underflow);
ffa_ch11_tuning_a... 95 end FFA_FZ_Subtract;
ffa_ch11_tuning_a... 96
ffa_ch11_tuning_a... 97 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 98 --- Multiplication on FZ
ffa_ch11_tuning_a... 99 ----------------------------------------------------------------------------
ffa_ch11_tuning_a... 100
ffa_ch11_tuning_a... 101 procedure FFA_FZ_Multiply(X : in FZ;
ffa_ch11_tuning_a... 102 Y : in FZ;
ffa_ch11_tuning_a... 103 XY_Lo : out FZ;
ffa_ch11_tuning_a... 104 XY_Hi : out FZ) is
ffa_ch11_tuning_a... 105 begin
ffa_ch11_tuning_a... 106 FZ_Mul.FZ_Multiply_Buffered(X => X, Y => Y,
ffa_ch11_tuning_a... 107 XY_Lo => XY_Lo, XY_Hi => XY_Hi);
ffa_ch11_tuning_a... 108 end FFA_FZ_Multiply;
ffa_ch11_tuning_a... 109
ffa_ch11_tuning_a... 110 end FFA;