File : words.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 Iron;
21
22 package Words is
23
24 pragma Pure;
25
26 -- The most fundamental fact about Word: width.
27 Bitness : constant Positive := Iron.MachineBitness;
28
29 -- It is possible to calculate BitnessLog2 at elaboration time,
30 -- but we will avoid having ~any~ elaboration at all in FFA.
31 BitnessLog2 : constant Positive := Iron.MachineBitnessLog2;
32
33 -- The Word width, expressed in ~bytes~:
34 Byteness : constant Positive := Bitness / Iron.ByteBits;
35
36 -- Nibbles per Word:
37 Nibbleness : constant Positive := Byteness * 2;
38
39 -- What kind of words to use. Must be machine-word or smaller.
40 type Word is mod 2**Bitness;
41 for Word'Size use Bitness;
42
43 -- The very same Word, but its only legal values are 0 and 1.
44 subtype WBool is Word range 0 .. 1;
45
46 -- Word, restricted to Nibble range.
47 subtype Nibble is Word range 0 .. 16#F#;
48
49 -- When we must refer to individual bit positions of a machine word:
50 subtype WBit_Index is Natural range 0 .. Bitness - 1;
51
52 end Words;