File : fz_arith.ads
1 ------------------------------------------------------------------------------
2 ------------------------------------------------------------------------------
3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
4 -- --
5 -- (C) 2017 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 Words; use Words;
21 with FZ_Type; use FZ_Type;
22
23
24 -- Fundamental Arithmetic operators on FZ:
25 package FZ_Arith is
26
27 pragma Pure;
28
29 -- Destructive Add: X := X + Y; Overflow := Carry; optional OF_In
30 procedure FZ_Add_D(X : in out FZ;
31 Y : in FZ;
32 Overflow : out WBool;
33 OF_In : in WBool := 0);
34 pragma Inline_Always(FZ_Add_D);
35
36 -- Destructive Add: X := X + W; Overflow := Carry
37 procedure FZ_Add_D_W(X : in out FZ;
38 W : in Word;
39 Overflow : out WBool);
40 pragma Inline_Always(FZ_Add_D_W);
41
42 -- Sum := X + Y; Overflow := Carry
43 procedure FZ_Add(X : in FZ;
44 Y : in FZ;
45 Sum : out FZ;
46 Overflow : out WBool);
47 pragma Inline_Always(FZ_Add);
48
49 -- Gate = 1: Sum := X + Y; Overflow := Carry
50 -- Gate = 0: Sum := X; Overflow := 0
51 procedure FZ_Add_Gated_O(X : in FZ;
52 Y : in FZ;
53 Gate : in WBool;
54 Sum : out FZ;
55 Overflow : out WBool);
56 pragma Inline_Always(FZ_Add_Gated_O);
57
58 -- Same as FZ_Add_Gated_O, but without Overflow output
59 procedure FZ_Add_Gated(X : in FZ;
60 Y : in FZ;
61 Gate : in WBool;
62 Sum : out FZ);
63 pragma Inline_Always(FZ_Add_Gated);
64
65 -- Difference := X - Y; Underflow := Borrow
66 procedure FZ_Sub(X : in FZ;
67 Y : in FZ;
68 Difference : out FZ;
69 Underflow : out WBool);
70 pragma Inline_Always(FZ_Sub);
71
72 -- Destructive: If Cond is 1, NotN := ~N; otherwise NotN := N.
73 procedure FZ_Not_Cond_D(N : in out FZ;
74 Cond : in WBool);
75 pragma Inline_Always(FZ_Not_Cond_D);
76
77 -- Subtractor that gets absolute value if underflowed, in const. time
78 procedure FZ_Sub_Abs(X : in FZ;
79 Y : in FZ;
80 Difference : out FZ;
81 Underflow : out WBool);
82 pragma Inline_Always(FZ_Sub_Abs);
83
84 end FZ_Arith;