1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- S Y S T E M . V E C T O R S . B O O L E A N _ O P E R A T I O N S --
9 -- Copyright (C) 2002-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 package body System
.Vectors
.Boolean_Operations
is
36 SU
: constant := Storage_Unit
;
37 -- Convenient short hand, used throughout
39 -- The coding of this unit depends on the fact that the Component_Size
40 -- of a normally declared array of Boolean is equal to Storage_Unit. We
41 -- can't use the Component_Size directly since it is non-static. The
42 -- following declaration checks that this declaration is correct
44 type Boolean_Array
is array (Integer range <>) of Boolean;
45 pragma Compile_Time_Error
46 (Boolean_Array
'Component_Size /= SU
, "run time compile failure");
48 -- NOTE: The boolean literals must be qualified here to avoid visibility
49 -- anomalies when this package is compiled through Rtsfind, in a context
50 -- that includes a user-defined type derived from boolean.
52 True_Val
: constant Vector
:= Standard
.True'Enum_Rep
53 + Standard
.True'Enum_Rep * 2**SU
54 + Standard
.True'Enum_Rep * 2**(SU
* 2)
55 + Standard
.True'Enum_Rep * 2**(SU
* 3)
56 + Standard
.True'Enum_Rep * 2**(SU
* 4)
57 + Standard
.True'Enum_Rep * 2**(SU
* 5)
58 + Standard
.True'Enum_Rep * 2**(SU
* 6)
59 + Standard
.True'Enum_Rep * 2**(SU
* 7);
60 -- This constant represents the bits to be flipped to perform a logical
61 -- "not" on a vector of booleans, independent of the actual
62 -- representation of True.
64 -- The representations of (False, True) are assumed to be zero/one and
65 -- the maximum number of unpacked booleans per Vector is assumed to be 8.
67 pragma Assert
(Standard
.False'Enum_Rep = 0);
68 pragma Assert
(Standard
.True'Enum_Rep = 1);
69 pragma Assert
(Vector
'Size / Storage_Unit
<= 8);
71 -- The reason we need to do these gymnastics is that no call to
72 -- Unchecked_Conversion can be made at the library level since this
73 -- unit is pure. Also a conversion from the array type to the Vector type
74 -- inside the body of "not" is inefficient because of alignment issues.
80 function "not" (Item
: Vectors
.Vector
) return Vectors
.Vector
is
82 return Item
xor True_Val
;
89 function Nand
(Left
, Right
: Boolean) return Boolean is
91 return not (Left
and Right
);
94 function Nand
(Left
, Right
: Vectors
.Vector
) return Vectors
.Vector
is
96 return not (Left
and Right
);
103 function Nor
(Left
, Right
: Boolean) return Boolean is
105 return not (Left
or Right
);
108 function Nor
(Left
, Right
: Vectors
.Vector
) return Vectors
.Vector
is
110 return not (Left
or Right
);
117 function Nxor
(Left
, Right
: Boolean) return Boolean is
119 return not (Left
xor Right
);
122 function Nxor
(Left
, Right
: Vectors
.Vector
) return Vectors
.Vector
is
124 return not (Left
xor Right
);
127 end System
.Vectors
.Boolean_Operations
;