Finite Field Arithmetic

fz_pred.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 with W_Pred; use W_Pred;
  21 
  22 
  23 package body FZ_Pred is
  24    
  25    ---------------------------------------------------------------------------
  26    -- Fundamental Predicate Operations on FZ (finite integers)
  27    ---------------------------------------------------------------------------
  28    
  29    -- 1 iff N == 0 (branch-free); else 0
  30    function FZ_ZeroP(N : in FZ) return WBool is
  31       A : WBool := 1;
  32    begin
  33       for i in N'Range loop
  34          A := A and W_ZeroP(N(i));
  35       end loop;
  36       return A;
  37    end FZ_ZeroP;
  38    
  39    
  40    -- 1 iff N != 0 (branch-free); else 0
  41    function FZ_NZeroP(N : in FZ) return WBool is
  42    begin
  43       return 1 xor FZ_ZeroP(N);
  44    end FZ_NZeroP;
  45    
  46    
  47    -- 1 iff N is odd
  48    function FZ_OddP(N : in FZ) return WBool is
  49    begin
  50       return W_OddP(N(N'First));
  51    end FZ_OddP;
  52    
  53    
  54    -- 1 iff N fits inside one Word
  55    function FZ_OneWordP(N : in FZ) return WBool is
  56    begin
  57       return FZ_ZeroP(N(N'First + 1 .. N'Last));
  58    end FZ_OneWordP;
  59    
  60 end FZ_Pred;