| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . B I T _ O P S -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 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 3, 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. -- |
| 17 |
-- -- |
| 18 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 19 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 20 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 21 |
-- -- |
| 22 |
-- You should have received a copy of the GNU General Public License and -- |
| 23 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 24 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 25 |
-- <http://www.gnu.org/licenses/>. -- |
| 26 |
-- -- |
| 27 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 28 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 29 |
-- -- |
| 30 |
------------------------------------------------------------------------------ |
| 31 |
|
| 32 |
-- This package provides subprograms on bit strings. The compiler uses these |
| 33 |
-- subprograms for packed array operations. |
| 34 |
|
| 35 |
package System.Bit_Ops is |
| 36 |
|
| 37 |
-- In all the following routines, the System.Address parameters |
| 38 |
-- represent the address of the first byte of an array used to represent |
| 39 |
-- a packed array (of type System.Unsigned_Types.Packed_Bytes{1,2,4}) |
| 40 |
-- The length in bits is passed as a separate parameter. Note that all |
| 41 |
-- addresses must be of byte aligned arrays. |
| 42 |
|
| 43 |
procedure Bit_And |
| 44 |
(Left : System.Address; |
| 45 |
Llen : Natural; |
| 46 |
Right : System.Address; |
| 47 |
Rlen : Natural; |
| 48 |
Result : System.Address); |
| 49 |
-- Bitwise "and" of given bit string with result being placed in |
| 50 |
-- ``Result``. The and operation is allowed to destroy unused bits in |
| 51 |
-- the last byte, i.e. to leave them set in an undefined manner. Note that |
| 52 |
-- ``Left``, ``Right`` and ``Result`` always have the same length in bits. |
| 53 |
-- |
| 54 |
-- The procedure raises Constraint_Error if ``Llen`` and ``Rlen`` are not |
| 55 |
-- equal. |
| 56 |
-- |
| 57 |
-- The bitwise "and" operation is performed byte per byte, where the number |
| 58 |
-- of bytes is the smallest number not less than ``Llen`` (or ``Rlen``) |
| 59 |
-- divided by the 8. |
| 60 |
|
| 61 |
function Bit_Eq |
| 62 |
(Left : System.Address; |
| 63 |
Llen : Natural; |
| 64 |
Right : System.Address; |
| 65 |
Rlen : Natural) return Boolean; |
| 66 |
-- ``Left`` and ``Right`` are the addresses of two bit packed arrays with |
| 67 |
-- ``Llen`` and ``Rlen`` being the respective length in bits. The routine |
| 68 |
-- compares the two bit strings for equality, being careful not to include |
| 69 |
-- the unused bits in the final byte. |
| 70 |
-- |
| 71 |
-- Note that the result is always False if ``Rlen`` is not equal to |
| 72 |
-- ``Llen``. |
| 73 |
-- |
| 74 |
-- Otherwise all the bytes but the last one are compared, and False is |
| 75 |
-- returned if they aren't equal. Only the ``Llen`` mod 8 bits of the last |
| 76 |
-- byte are compared, and false is returned if they aren't equal. |
| 77 |
-- |
| 78 |
-- Otherwise, True is returned. |
| 79 |
|
| 80 |
procedure Bit_Not |
| 81 |
(Opnd : System.Address; |
| 82 |
Len : Natural; |
| 83 |
Result : System.Address); |
| 84 |
-- Bitwise "not" of given bit string with result being placed in |
| 85 |
-- ``Result``. The not operation is allowed to destroy unused bits in the |
| 86 |
-- last byte, i.e. to leave them set in an undefined manner. Note that |
| 87 |
-- ``Result`` and ``Opnd`` always have the same length in bits (``Len``). |
| 88 |
-- |
| 89 |
-- The bitwise "not" operation is performed byte per byte, where the |
| 90 |
-- number of bytes is the smallest number not less that ``Len`` divided by |
| 91 |
-- the number of bits in a byte (8). |
| 92 |
|
| 93 |
procedure Bit_Or |
| 94 |
(Left : System.Address; |
| 95 |
Llen : Natural; |
| 96 |
Right : System.Address; |
| 97 |
Rlen : Natural; |
| 98 |
Result : System.Address); |
| 99 |
-- Bitwise "or" of given bit string with result being placed in ``Result``. |
| 100 |
-- The or operation is allowed to destroy unused bits in the last byte, |
| 101 |
-- i.e. to leave them set in an undefined manner. Note that ``Left``, |
| 102 |
-- ``Right`` and ``Result`` always have the same length in bits. |
| 103 |
-- |
| 104 |
-- The implementation is similar to *Bit_And* but for the bitwise "or" |
| 105 |
-- operation. |
| 106 |
|
| 107 |
procedure Bit_Xor |
| 108 |
(Left : System.Address; |
| 109 |
Llen : Natural; |
| 110 |
Right : System.Address; |
| 111 |
Rlen : Natural; |
| 112 |
Result : System.Address); |
| 113 |
-- Bitwise "xor" of given bit string with result being placed in |
| 114 |
-- ``Result``. The xor operation is allowed to destroy unused bits in the |
| 115 |
-- last byte, i.e. to leave them set in an undefined manner. Note that |
| 116 |
-- ``Left``, ``Right`` and ``Result`` always have the same length in bits. |
| 117 |
-- |
| 118 |
-- The implementation is similar to *Bit_And* but for the bitwise "xor" |
| 119 |
-- operation. |
| 120 |
|
| 121 |
end System.Bit_Ops; |