------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. -- -- -- -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) -- -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- -- -- -- You do not have, nor can you ever acquire the right to use, copy or -- -- distribute this software ; Should you use this software for any purpose, -- -- or copy and distribute it to anyone or in any manner, you are breaking -- -- the laws of whatever soi-disant jurisdiction, and you promise to -- -- continue doing so for the indefinite future. In any case, please -- -- always : read and understand any software ; verify any PGP signatures -- -- that you use - for any purpose. -- -- -- -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Words; use Words; with FZ_Type; use FZ_Type; -- Fundamental Arithmetic operators on FZ: package FZ_Arith is pragma Pure; -- Destructive Add: X := X + Y; Overflow := Carry; optional OF_In procedure FZ_Add_D(X : in out FZ; Y : in FZ; Overflow : out WBool; OF_In : in WBool := 0); pragma Inline_Always(FZ_Add_D); -- Destructive Add: X := X + W; Overflow := Carry procedure FZ_Add_D_W(X : in out FZ; W : in Word; Overflow : out WBool); pragma Inline_Always(FZ_Add_D_W); -- Sum := X + Y; Overflow := Carry procedure FZ_Add(X : in FZ; Y : in FZ; Sum : out FZ; Overflow : out WBool); pragma Inline_Always(FZ_Add); -- Gate = 1: Sum := X + Y; Overflow := Carry -- Gate = 0: Sum := X; Overflow := 0 procedure FZ_Add_Gated_O(X : in FZ; Y : in FZ; Gate : in WBool; Sum : out FZ; Overflow : out WBool); pragma Inline_Always(FZ_Add_Gated_O); -- Same as FZ_Add_Gated_O, but without Overflow output procedure FZ_Add_Gated(X : in FZ; Y : in FZ; Gate : in WBool; Sum : out FZ); pragma Inline_Always(FZ_Add_Gated); -- Destructive Subtract: X := X - Y; Underflow := Borrow procedure FZ_Sub_D(X : in out FZ; Y : in FZ; Underflow : out WBool); pragma Inline_Always(FZ_Sub_D); -- Difference := X - W; Underflow := Borrow procedure FZ_Sub_W(X : in FZ; W : in Word; Difference : out FZ; Underflow : out WBool); pragma Inline_Always(FZ_Sub_W); -- Difference := X - Y; Underflow := Borrow procedure FZ_Sub(X : in FZ; Y : in FZ; Difference : out FZ; Underflow : out WBool); pragma Inline_Always(FZ_Sub); -- Destructive: If Cond is 1, NotN := ~N; otherwise NotN := N. procedure FZ_Not_Cond_D(N : in out FZ; Cond : in WBool); pragma Inline_Always(FZ_Not_Cond_D); -- Subtractor that gets absolute value if underflowed, in const. time procedure FZ_Sub_Abs(X : in FZ; Y : in FZ; Difference : out FZ; Underflow : out WBool); pragma Inline_Always(FZ_Sub_Abs); end FZ_Arith;