-
+ AB686F59589863AB3EFE9E97C9AE2ECC3BE0D3457D010326AFFFEACA6FF42A662F1B05FEB8C08492EF77392EDDE5ABF26E8EE6CABC75BC0F2391663AE77EBB16ffa/ffademo/demo_ch2.adb(0 . 0)(1 . 236)
36 ------------------------------------------------------------------------------
37 ------------------------------------------------------------------------------
38 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
39 -- --
40 -- (C) 2017 Stanislav Datskovskiy ( www.loper-os.org ) --
41 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
42 -- --
43 -- You do not have, nor can you ever acquire the right to use, copy or --
44 -- distribute this software ; Should you use this software for any purpose, --
45 -- or copy and distribute it to anyone or in any manner, you are breaking --
46 -- the laws of whatever soi-disant jurisdiction, and you promise to --
47 -- continue doing so for the indefinite future. In any case, please --
48 -- always : read and understand any software ; verify any PGP signatures --
49 -- that you use - for any purpose. --
50 -- --
51 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
52 ------------------------------------------------------------------------------
53 ------------------------------------------------------------------------------
54
55 -- From Ada:
56 with Ada.Text_IO; use Ada.Text_IO;
57
58 -- From FFA:
59 with Words; use Words;
60 with FZ_Type; use FZ_Type;
61 with FZ_Arith; use FZ_Arith;
62
63 -- FFA Ch. 2
64 with W_Pred; use W_Pred;
65 with FZ_Basic; use FZ_Basic;
66 with FZ_Pred; use FZ_Pred;
67 with FZ_BitOp; use FZ_BitOp;
68 with FZ_Cmp; use FZ_Cmp;
69
70 -- From the Demo:
71 with FFA_IO; use FFA_IO;
72
73
74 package body Demo_Ch2 is
75
76 procedure Demo_Word_Preds is
77
78 begin
79
80 Put_Line("~~~ Ch. 2 : Word Predicates ~~~");
81 New_Line;
82
83 Put_Line("W_ZeroP(0) :");
84 Dump(W_ZeroP(0));
85 New_Line;
86 New_Line;
87
88 Put_Line("W_ZeroP(1) :");
89 Dump(W_ZeroP(1));
90 New_Line;
91 New_Line;
92
93 Put_Line("W_NZeroP(1) :");
94 Dump(W_NZeroP(1));
95 New_Line;
96 New_Line;
97
98 Put_Line("W_OddP(3) :");
99 Dump(W_OddP(3));
100 New_Line;
101 New_Line;
102
103 Put_Line("W_EqP(1, 1) :");
104 Dump(W_EqP(1, 1));
105 New_Line;
106 New_Line;
107
108 Put_Line("W_EqP(1, 0) :");
109 Dump(W_EqP(1, 0));
110 New_Line;
111 New_Line;
112
113 end Demo_Word_Preds;
114
115
116 procedure Demo_FZ_Basics is
117
118 X : FZ(1 .. 4) := ( 0, 0, 0, 0);
119
120 -- Shorthand for 'maxint'
121 Y : FZ(1 .. 4) := (-1, -1, -1, -1);
122
123 Z : FZ(1 .. 4) := ( 0, 0, 0, 0);
124
125 -- Flag.
126 F : WBool := 0;
127
128 begin
129
130 Put_Line("~~~ Ch. 2 : FZ Basics ~~~");
131 New_Line;
132
133 Put_Line("X =");
134 Dump(X);
135 New_Line;
136 New_Line;
137
138 Put_Line("Y =");
139 Dump(Y);
140 New_Line;
141 New_Line;
142
143 Put_Line("FZ_ZeroP(X) :");
144 Dump(FZ_ZeroP(X));
145 New_Line;
146 New_Line;
147
148 Put_Line("FZ_ZeroP(Y) :");
149 Dump(FZ_ZeroP(Y));
150 New_Line;
151 New_Line;
152
153 FZ_Swap(X, Y);
154 Put_Line("After FZ_Swap(X, Y) :");
155 Put_Line("X =");
156 Dump(X);
157 New_Line;
158 New_Line;
159
160 Put_Line("Y =");
161 Dump(Y);
162 New_Line;
163 New_Line;
164
165 F := 0;
166 FZ_Mux(X, Y, Z, F);
167 Put_Line("After F := 0 , FZ_Mux(X, Y, Z, F) : ");
168 Put_Line("Z =");
169 Dump(Z);
170 New_Line;
171 New_Line;
172
173 F := 1;
174 FZ_Mux(X, Y, Z, F);
175 Put_Line("After F := 1 , FZ_Mux(X, Y, Z, F) : ");
176 Put_Line("Z =");
177 Dump(Z);
178 New_Line;
179 New_Line;
180
181 end Demo_FZ_Basics;
182
183
184 procedure Demo_FZ_Various_Ops is
185
186 X : FZ(1 .. 4) := ( 16#083e16f27091f65f#, 16#74c01a9c3ce54f80#,
187 16#9fd0913737c3fcbe#, 16#fa55f3f5459a9e79# );
188
189 Y : FZ(1 .. 4) := ( 16#d16b9d65bf3991d0#, 16#8a509a858786b366#,
190 16#d39d23682728f4f8#, 16#6c571dbc646bf513# );
191
192 Z : FZ(1 .. 4) := ( 0, 0, 0, 0 );
193
194 begin
195
196 Put_Line("~~~ Ch. 2 : FZ Bit Ops ~~~");
197 New_Line;
198 New_Line;
199
200 Put_Line("X =");
201 Dump(X);
202 New_Line;
203 New_Line;
204
205 Put_Line("Y =");
206 Dump(Y);
207 New_Line;
208 New_Line;
209
210 FZ_Neg(X, Z);
211 Put_Line("After FZ_Neg(X, Z):");
212 Put_Line("Z =");
213 Dump(Z);
214 New_Line;
215 New_Line;
216
217 FZ_And(X, Y, Z);
218 Put_Line("After FZ_And(X, Y, Z) :");
219 Put_Line("Z =");
220 Dump(Z);
221 New_Line;
222 New_Line;
223
224 FZ_Or(X, Y, Z);
225 Put_Line("After FZ_Or(X, Y, Z) :");
226 Put_Line("Z =");
227 Dump(Z);
228 New_Line;
229 New_Line;
230
231 FZ_Xor(X, Y, Z);
232 Put_Line("After FZ_Xor(X, Y, Z) :");
233 Put_Line("Z =");
234 Dump(Z);
235 New_Line;
236 New_Line;
237
238 Put_Line("FZ_EqP(X, X) :");
239 Dump(FZ_EqP(X, X));
240 New_Line;
241 New_Line;
242
243 Put_Line("FZ_EqP(X, Y) :");
244 Dump(FZ_EqP(X, Y));
245 New_Line;
246 New_Line;
247
248 Put_Line("FZ_LessThanP(X, Y) :");
249 Dump(FZ_LessThanP(X, Y));
250 New_Line;
251 New_Line;
252
253 Put_Line("FZ_LessThanP(Y, X) :");
254 Dump(FZ_LessThanP(Y, X));
255 New_Line;
256 New_Line;
257
258 Put_Line("FZ_GreaterThanP(X, Y) :");
259 Dump(FZ_GreaterThanP(X, Y));
260 New_Line;
261 New_Line;
262
263 Put_Line("FZ_GreaterThanP(Y, X) :");
264 Dump(FZ_GreaterThanP(Y, X));
265 New_Line;
266 New_Line;
267
268 end Demo_FZ_Various_Ops;
269
270
271 end Demo_Ch2;