Finite Field Arithmetic

fz_bitop.adb


   1 ------------------------------------------------------------------------------
   2 ------------------------------------------------------------------------------
   3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'.               --
   4 --                                                                          --
   5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org )                      --
   6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html     --
   7 --                                                                          --
   8 -- You do not have, nor can you ever acquire the right to use, copy or      --
   9 -- distribute this software ; Should you use this software for any purpose, --
  10 -- or copy and distribute it to anyone or in any manner, you are breaking   --
  11 -- the laws of whatever soi-disant jurisdiction, and you promise to         --
  12 -- continue doing so for the indefinite future. In any case, please         --
  13 -- always : read and understand any software ; verify any PGP signatures    --
  14 -- that you use - for any purpose.                                          --
  15 --                                                                          --
  16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm .     --
  17 ------------------------------------------------------------------------------
  18 ------------------------------------------------------------------------------
  19 
  20 package body FZ_BitOp is
  21    
  22    -- Result := X & Y
  23    procedure FZ_And(X : in FZ; Y : in FZ; Result : out FZ) is
  24    begin
  25       for i in X'Range loop
  26          Result(i) := X(i) and Y(i);
  27       end loop;
  28    end FZ_And;
  29    
  30    
  31    -- N := N & W, W is a word
  32    procedure FZ_And_W(N : in out FZ; W : in Word) is
  33    begin
  34       N(N'First) := N(N'First) and W;
  35    end FZ_And_W;
  36    
  37    
  38    -- Result := X | Y
  39    procedure FZ_Or(X : in FZ; Y : in FZ; Result : out FZ) is
  40    begin
  41       for i in X'Range loop
  42          Result(i) := X(i) or Y(i);
  43       end loop;
  44    end FZ_Or;
  45    
  46    
  47    -- N := N | W, W is a word
  48    procedure FZ_Or_W(N : in out FZ; W : in Word) is
  49    begin
  50       N(N'First) := N(N'First) or W;
  51    end FZ_Or_W;
  52    
  53    
  54    -- Result := X ^ Y
  55    procedure FZ_Xor(X : in FZ; Y : in FZ; Result : out FZ) is
  56    begin
  57       for i in X'Range loop
  58          Result(i) := X(i) xor Y(i);
  59       end loop;
  60    end FZ_Xor;
  61    
  62    
  63    -- N := N ^ W, W is a word
  64    procedure FZ_Xor_W(N : in out FZ; W : in Word) is
  65    begin
  66       N(N'First) := N(N'First) xor W;
  67    end FZ_Xor_W;
  68    
  69    
  70    -- NotN := ~N
  71    procedure FZ_Not(N    : in FZ;
  72                     NotN : out FZ) is
  73    begin
  74       for i in N'Range loop
  75          NotN(i) := not N(i);
  76       end loop;
  77    end FZ_Not;
  78    
  79 end FZ_BitOp;