File : fz_cmp.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 with FZ_Arith; use FZ_Arith;
  22 with FZ_Pred;  use FZ_Pred;
  23 
  24 
  25 package body FZ_Cmp is
  26    
  27    ---------------------------------------------
  28    -- Arithmetical Predicate Operations on FZ --
  29    ---------------------------------------------
  30    
  31    -- 1 iff X == Y (branch-free); else 0
  32    function FZ_EqP(X : in FZ; Y : in FZ) return WBool is
  33       A : WBool := 1;
  34    begin
  35       for i in X'Range loop
  36          A := A and W_EqP(X(i), Y(i));
  37       end loop;
  38       return A;
  39    end FZ_EqP;
  40    
  41    
  42    -- 1 iff X == W (branch-free); else 0
  43    function FZ_EqP_W(X : in FZ; W : in Word) return WBool is
  44    begin
  45       return FZ_OneWordP(X) and W_EqP(X(X'First), W);
  46    end FZ_EqP_W;
  47    
  48    
  49    -- 1 iff X < Y (branch-free); else 0
  50    function FZ_LessThanP(X : in FZ; Y : in FZ) return WBool is
  51       Scratch : FZ(X'Range);
  52       Borrow  : WBool := 0;
  53    begin
  54       FZ_Sub(X, Y, Scratch, Borrow);
  55       return Borrow;
  56    end FZ_LessThanP;
  57    
  58    
  59    -- 1 iff X > Y (branch-free); else 0
  60    function FZ_GreaterThanP(X : in FZ; Y: in FZ) return WBool is
  61       Scratch : FZ(X'Range);
  62       Borrow  : WBool := 0;
  63    begin
  64       FZ_Sub(Y, X, Scratch, Borrow);
  65       return Borrow;
  66    end FZ_GreaterThanP;
  67    
  68 end FZ_Cmp;