------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. -- -- -- -- (C) 2017 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 . -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- From Ada: with Ada.Text_IO; use Ada.Text_IO; -- From FFA: with Words; use Words; with FZ_Type; use FZ_Type; with FZ_Arith; use FZ_Arith; -- FFA Ch. 2 with W_Pred; use W_Pred; with FZ_Basic; use FZ_Basic; with FZ_Pred; use FZ_Pred; with FZ_BitOp; use FZ_BitOp; with FZ_Cmp; use FZ_Cmp; -- From the Demo: with FFA_IO; use FFA_IO; package body Demo_Ch2 is procedure Demo_Word_Preds is begin Put_Line("~~~ Ch. 2 : Word Predicates ~~~"); New_Line; Put_Line("W_ZeroP(0) :"); Dump(W_ZeroP(0)); New_Line; New_Line; Put_Line("W_ZeroP(1) :"); Dump(W_ZeroP(1)); New_Line; New_Line; Put_Line("W_NZeroP(1) :"); Dump(W_NZeroP(1)); New_Line; New_Line; Put_Line("W_OddP(3) :"); Dump(W_OddP(3)); New_Line; New_Line; Put_Line("W_EqP(1, 1) :"); Dump(W_EqP(1, 1)); New_Line; New_Line; Put_Line("W_EqP(1, 0) :"); Dump(W_EqP(1, 0)); New_Line; New_Line; end Demo_Word_Preds; procedure Demo_FZ_Basics is X : FZ(1 .. 4) := ( 0, 0, 0, 0); -- Shorthand for 'maxint' Y : FZ(1 .. 4) := (-1, -1, -1, -1); Z : FZ(1 .. 4) := ( 0, 0, 0, 0); -- Flag. F : WBool := 0; begin Put_Line("~~~ Ch. 2 : FZ Basics ~~~"); New_Line; Put_Line("X ="); Dump(X); New_Line; New_Line; Put_Line("Y ="); Dump(Y); New_Line; New_Line; Put_Line("FZ_ZeroP(X) :"); Dump(FZ_ZeroP(X)); New_Line; New_Line; Put_Line("FZ_ZeroP(Y) :"); Dump(FZ_ZeroP(Y)); New_Line; New_Line; FZ_Swap(X, Y); Put_Line("After FZ_Swap(X, Y) :"); Put_Line("X ="); Dump(X); New_Line; New_Line; Put_Line("Y ="); Dump(Y); New_Line; New_Line; F := 0; FZ_Mux(X, Y, Z, F); Put_Line("After F := 0 , FZ_Mux(X, Y, Z, F) : "); Put_Line("Z ="); Dump(Z); New_Line; New_Line; F := 1; FZ_Mux(X, Y, Z, F); Put_Line("After F := 1 , FZ_Mux(X, Y, Z, F) : "); Put_Line("Z ="); Dump(Z); New_Line; New_Line; end Demo_FZ_Basics; procedure Demo_FZ_Various_Ops is X : FZ(1 .. 4) := ( 16#083e16f27091f65f#, 16#74c01a9c3ce54f80#, 16#9fd0913737c3fcbe#, 16#fa55f3f5459a9e79# ); Y : FZ(1 .. 4) := ( 16#d16b9d65bf3991d0#, 16#8a509a858786b366#, 16#d39d23682728f4f8#, 16#6c571dbc646bf513# ); Z : FZ(1 .. 4) := ( 0, 0, 0, 0 ); begin Put_Line("~~~ Ch. 2 : FZ Bit Ops ~~~"); New_Line; New_Line; Put_Line("X ="); Dump(X); New_Line; New_Line; Put_Line("Y ="); Dump(Y); New_Line; New_Line; FZ_Neg(X, Z); Put_Line("After FZ_Neg(X, Z):"); Put_Line("Z ="); Dump(Z); New_Line; New_Line; FZ_And(X, Y, Z); Put_Line("After FZ_And(X, Y, Z) :"); Put_Line("Z ="); Dump(Z); New_Line; New_Line; FZ_Or(X, Y, Z); Put_Line("After FZ_Or(X, Y, Z) :"); Put_Line("Z ="); Dump(Z); New_Line; New_Line; FZ_Xor(X, Y, Z); Put_Line("After FZ_Xor(X, Y, Z) :"); Put_Line("Z ="); Dump(Z); New_Line; New_Line; Put_Line("FZ_EqP(X, X) :"); Dump(FZ_EqP(X, X)); New_Line; New_Line; Put_Line("FZ_EqP(X, Y) :"); Dump(FZ_EqP(X, Y)); New_Line; New_Line; Put_Line("FZ_LessThanP(X, Y) :"); Dump(FZ_LessThanP(X, Y)); New_Line; New_Line; Put_Line("FZ_LessThanP(Y, X) :"); Dump(FZ_LessThanP(Y, X)); New_Line; New_Line; Put_Line("FZ_GreaterThanP(X, Y) :"); Dump(FZ_GreaterThanP(X, Y)); New_Line; New_Line; Put_Line("FZ_GreaterThanP(Y, X) :"); Dump(FZ_GreaterThanP(Y, X)); New_Line; New_Line; end Demo_FZ_Various_Ops; end Demo_Ch2;