raw
ffa_ch1_genesis.kv      1 ------------------------------------------------------------------------------
ffa_ch1_genesis.kv 2 ------------------------------------------------------------------------------
ffa_ch1_genesis.kv 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch1_genesis.kv 4 -- --
ffa_ch1_genesis.kv 5 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch1_genesis.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch1_genesis.kv 7 -- --
ffa_ch1_genesis.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch1_genesis.kv 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch1_genesis.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch1_genesis.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch1_genesis.kv 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch1_genesis.kv 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch1_genesis.kv 14 -- that you use - for any purpose. --
ffa_ch1_genesis.kv 15 -- --
ffa_ch1_genesis.kv 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch1_genesis.kv 17 ------------------------------------------------------------------------------
ffa_ch1_genesis.kv 18 ------------------------------------------------------------------------------
ffa_ch1_genesis.kv 19
ffa_ch1_genesis.kv 20 with Word_Ops; use Word_Ops;
ffa_ch1_genesis.kv 21
ffa_ch1_genesis.kv 22 -- Fundamental Arithmetic operators on FZ:
ffa_ch1_genesis.kv 23 package body FZ_Arith is
ffa_ch1_genesis.kv 24
ffa_ch1_genesis.kv 25 -- Sum := X + Y; Overflow := Carry
ffa_ch1_genesis.kv 26 procedure FZ_Add(X : in FZ;
ffa_ch1_genesis.kv 27 Y : in FZ;
ffa_ch1_genesis.kv 28 Sum : out FZ;
ffa_ch1_genesis.kv 29 Overflow : out WBool) is
ffa_ch1_genesis.kv 30 Carry : WBool := 0;
ffa_ch1_genesis.kv 31 begin
ffa_ch1_genesis.kv 32 for i in X'Range loop
ffa_ch1_genesis.kv 33 declare
ffa_ch1_genesis.kv 34 A : constant Word := X(I);
ffa_ch1_genesis.kv 35 B : constant Word := Y(I);
ffa_ch1_genesis.kv 36 S : constant Word := A + B + Carry;
ffa_ch1_genesis.kv 37 begin
ffa_ch1_genesis.kv 38 Sum(i) := S;
ffa_ch1_genesis.kv 39 Carry := W_Carry(A, B, S);
ffa_ch1_genesis.kv 40 end;
ffa_ch1_genesis.kv 41 end loop;
ffa_ch1_genesis.kv 42 Overflow := Carry;
ffa_ch1_genesis.kv 43 end FZ_Add;
ffa_ch1_genesis.kv 44 pragma Inline_Always(FZ_Add);
ffa_ch1_genesis.kv 45
ffa_ch1_genesis.kv 46
ffa_ch5_egypt.kv 47 -- Gate = 1: Sum := X + Y; Overflow := Carry
ffa_ch5_egypt.kv 48 -- Gate = 0: Sum := X; Overflow := 0
ffa_ch5_egypt.kv 49 procedure FZ_Add_Gated_O(X : in FZ;
ffa_ch5_egypt.kv 50 Y : in FZ;
ffa_ch5_egypt.kv 51 Gate : in WBool;
ffa_ch5_egypt.kv 52 Sum : out FZ;
ffa_ch5_egypt.kv 53 Overflow : out WBool) is
ffa_ch5_egypt.kv 54 Carry : WBool := 0;
ffa_ch5_egypt.kv 55 Mask : constant Word := 0 - Gate;
ffa_ch5_egypt.kv 56 begin
ffa_ch5_egypt.kv 57 for i in 0 .. Word_Index(X'Length - 1) loop
ffa_ch5_egypt.kv 58 declare
ffa_ch5_egypt.kv 59 A : constant Word := X(X'First + i);
ffa_ch5_egypt.kv 60 B : constant Word := Y(Y'First + i) and Mask;
ffa_ch5_egypt.kv 61 S : constant Word := A + B + Carry;
ffa_ch5_egypt.kv 62 begin
ffa_ch5_egypt.kv 63 Sum(Sum'First + i) := S;
ffa_ch5_egypt.kv 64 Carry := W_Carry(A, B, S);
ffa_ch5_egypt.kv 65 end;
ffa_ch5_egypt.kv 66 end loop;
ffa_ch5_egypt.kv 67 Overflow := Carry;
ffa_ch5_egypt.kv 68 end FZ_Add_Gated_O;
ffa_ch5_egypt.kv 69 pragma Inline_Always(FZ_Add_Gated_O);
ffa_ch5_egypt.kv 70
ffa_ch5_egypt.kv 71
ffa_ch5_egypt.kv 72 -- Same as FZ_Add_Gated_O, but without Overflow output
ffa_ch5_egypt.kv 73 procedure FZ_Add_Gated(X : in FZ;
ffa_ch5_egypt.kv 74 Y : in FZ;
ffa_ch5_egypt.kv 75 Gate : in WBool;
ffa_ch5_egypt.kv 76 Sum : out FZ) is
ffa_ch5_egypt.kv 77 Overflow : Word;
ffa_ch5_egypt.kv 78 pragma Unreferenced(Overflow);
ffa_ch5_egypt.kv 79 begin
ffa_ch5_egypt.kv 80 FZ_Add_Gated_O(X, Y, Gate, Sum, Overflow);
ffa_ch5_egypt.kv 81 end FZ_Add_Gated;
ffa_ch5_egypt.kv 82 pragma Inline_Always(FZ_Add_Gated);
ffa_ch5_egypt.kv 83
ffa_ch5_egypt.kv 84
ffa_ch1_genesis.kv 85 -- Difference := X - Y; Underflow := Borrow
ffa_ch1_genesis.kv 86 procedure FZ_Sub(X : in FZ;
ffa_ch1_genesis.kv 87 Y : in FZ;
ffa_ch1_genesis.kv 88 Difference : out FZ;
ffa_ch1_genesis.kv 89 Underflow : out WBool) is
ffa_ch1_genesis.kv 90 Borrow : WBool := 0;
ffa_ch1_genesis.kv 91 begin
ffa_ch1_genesis.kv 92 for i in 0 .. Word_Index(X'Length - 1) loop
ffa_ch1_genesis.kv 93 declare
ffa_ch1_genesis.kv 94 A : constant Word := X(X'First + i);
ffa_ch1_genesis.kv 95 B : constant Word := Y(Y'First + i);
ffa_ch1_genesis.kv 96 S : constant Word := A - B - Borrow;
ffa_ch1_genesis.kv 97 begin
ffa_ch1_genesis.kv 98 Difference(Difference'First + i) := S;
ffa_ch1_genesis.kv 99 Borrow := W_Borrow(A, B, S);
ffa_ch1_genesis.kv 100 end;
ffa_ch1_genesis.kv 101 end loop;
ffa_ch1_genesis.kv 102 Underflow := Borrow;
ffa_ch1_genesis.kv 103 end FZ_Sub;
ffa_ch1_genesis.kv 104 pragma Inline_Always(FZ_Sub);
ffa_ch1_genesis.kv 105
ffa_ch1_genesis.kv 106 end FZ_Arith;