| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S Y S T E M . U N S I G N E D _ T Y P E 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 contains definitions of standard unsigned types that |
| 33 |
-- correspond in size to the standard signed types declared in Standard, |
| 34 |
-- and (unlike the types in Interfaces) have corresponding names. It |
| 35 |
-- also contains some related definitions for other specialized types |
| 36 |
-- used by the compiler in connection with packed array types. |
| 37 |
|
| 38 |
package System.Unsigned_Types is |
| 39 |
pragma Pure; |
| 40 |
pragma No_Elaboration_Code_All; |
| 41 |
|
| 42 |
type Short_Short_Unsigned is mod 2 ** Short_Short_Integer'Size; |
| 43 |
type Short_Unsigned is mod 2 ** Short_Integer'Size; |
| 44 |
type Unsigned is mod 2 ** Integer'Size; |
| 45 |
type Long_Unsigned is mod 2 ** Long_Integer'Size; |
| 46 |
type Long_Long_Unsigned is mod 2 ** Long_Long_Integer'Size; |
| 47 |
type Long_Long_Long_Unsigned is mod Max_Binary_Modulus; |
| 48 |
-- These are modular types that correspon in size to the standard signed |
| 49 |
-- types declared in Standard. |
| 50 |
|
| 51 |
type Packed_Byte is mod 2 ** 8; |
| 52 |
for Packed_Byte'Size use 8; |
| 53 |
pragma Universal_Aliasing (Packed_Byte); |
| 54 |
-- Component type for Packed_Bytes1, Packed_Bytes2 and Packed_Byte4 arrays. |
| 55 |
-- As this type is used by the compiler to implement operations on user |
| 56 |
-- packed array, it needs to be able to alias any type. |
| 57 |
|
| 58 |
type Packed_Bytes1 is array (Natural range <>) of aliased Packed_Byte; |
| 59 |
for Packed_Bytes1'Alignment use 1; |
| 60 |
for Packed_Bytes1'Component_Size use Packed_Byte'Size; |
| 61 |
pragma Suppress_Initialization (Packed_Bytes1); |
| 62 |
-- This is the type used to implement packed arrays where no alignment |
| 63 |
-- is required. This includes the cases of 1,2,4 (where we use direct |
| 64 |
-- masking operations), and all odd component sizes (where the clusters |
| 65 |
-- are not aligned anyway, see, e.g. System.Pack_07 in file s-pack07 |
| 66 |
-- for details. |
| 67 |
|
| 68 |
type Packed_Bytes2 is new Packed_Bytes1; |
| 69 |
for Packed_Bytes2'Alignment use Integer'Min (2, Standard'Maximum_Alignment); |
| 70 |
pragma Suppress_Initialization (Packed_Bytes2); |
| 71 |
-- This is the type used to implement packed arrays where an alignment |
| 72 |
-- of 2 (is possible) is helpful for maximum efficiency of the get and |
| 73 |
-- set routines in the corresponding library unit. This is true of all |
| 74 |
-- component sizes that are even but not divisible by 4 (other than 2 for |
| 75 |
-- which we use direct masking operations). In such cases, the clusters |
| 76 |
-- can be assumed to be 2-byte aligned if the array is aligned. See for |
| 77 |
-- example System.Pack_10 in file s-pack10). |
| 78 |
|
| 79 |
type Packed_Bytes4 is new Packed_Bytes1; |
| 80 |
for Packed_Bytes4'Alignment use Integer'Min (4, Standard'Maximum_Alignment); |
| 81 |
pragma Suppress_Initialization (Packed_Bytes4); |
| 82 |
-- This is the type used to implement packed arrays where an alignment |
| 83 |
-- of 4 (if possible) is helpful for maximum efficiency of the get and |
| 84 |
-- set routines in the corresponding library unit. This is true of all |
| 85 |
-- component sizes that are divisible by 4 (other than powers of 2, which |
| 86 |
-- are either handled by direct masking or not packed at all). In such |
| 87 |
-- cases the clusters can be assumed to be 4-byte aligned if the array |
| 88 |
-- is aligned (see System.Pack_12 in file s-pack12 as an example). |
| 89 |
|
| 90 |
type Rev_Packed_Bytes1 is new Packed_Bytes1; |
| 91 |
pragma Suppress_Initialization (Rev_Packed_Bytes1); |
| 92 |
-- This is equivalent to Packed_Bytes1, but for packed arrays with reverse |
| 93 |
-- scalar storage order. But the Scalar_Storage_Order attribute cannot be |
| 94 |
-- set directly here, see Exp_Pakd for more details. |
| 95 |
|
| 96 |
type Rev_Packed_Bytes2 is new Packed_Bytes2; |
| 97 |
pragma Suppress_Initialization (Rev_Packed_Bytes2); |
| 98 |
-- This is equivalent to Packed_Bytes2, but for packed arrays with reverse |
| 99 |
-- scalar storage order. But the Scalar_Storage_Order attribute cannot be |
| 100 |
-- set directly here, see Exp_Pakd for more details. |
| 101 |
|
| 102 |
type Rev_Packed_Bytes4 is new Packed_Bytes4; |
| 103 |
pragma Suppress_Initialization (Rev_Packed_Bytes4); |
| 104 |
-- This is equivalent to Packed_Bytes4, but for packed arrays with reverse |
| 105 |
-- scalar storage order. But the Scalar_Storage_Order attribute cannot be |
| 106 |
-- set directly here, see Exp_Pakd for more details. |
| 107 |
|
| 108 |
-- Various aligned arrays of bytes. Those types may be unused on limited |
| 109 |
-- run-times, but are still present for compatibility between run-times. |
| 110 |
|
| 111 |
type Bits_1 is mod 2**1; |
| 112 |
type Bits_2 is mod 2**2; |
| 113 |
type Bits_4 is mod 2**4; |
| 114 |
-- Types used for packed array conversions |
| 115 |
|
| 116 |
subtype Bytes_F is Packed_Bytes4 (1 .. Float'Size / 8); |
| 117 |
-- Type used in implementation of Is_Negative intrinsic (see Exp_Intr) |
| 118 |
|
| 119 |
function Shift_Left |
| 120 |
(Value : Short_Short_Unsigned; |
| 121 |
Amount : Natural) return Short_Short_Unsigned; |
| 122 |
|
| 123 |
function Shift_Right |
| 124 |
(Value : Short_Short_Unsigned; |
| 125 |
Amount : Natural) return Short_Short_Unsigned; |
| 126 |
|
| 127 |
function Shift_Right_Arithmetic |
| 128 |
(Value : Short_Short_Unsigned; |
| 129 |
Amount : Natural) return Short_Short_Unsigned; |
| 130 |
|
| 131 |
function Rotate_Left |
| 132 |
(Value : Short_Short_Unsigned; |
| 133 |
Amount : Natural) return Short_Short_Unsigned; |
| 134 |
|
| 135 |
function Rotate_Right |
| 136 |
(Value : Short_Short_Unsigned; |
| 137 |
Amount : Natural) return Short_Short_Unsigned; |
| 138 |
|
| 139 |
function Shift_Left |
| 140 |
(Value : Short_Unsigned; |
| 141 |
Amount : Natural) return Short_Unsigned; |
| 142 |
|
| 143 |
function Shift_Right |
| 144 |
(Value : Short_Unsigned; |
| 145 |
Amount : Natural) return Short_Unsigned; |
| 146 |
|
| 147 |
function Shift_Right_Arithmetic |
| 148 |
(Value : Short_Unsigned; |
| 149 |
Amount : Natural) return Short_Unsigned; |
| 150 |
|
| 151 |
function Rotate_Left |
| 152 |
(Value : Short_Unsigned; |
| 153 |
Amount : Natural) return Short_Unsigned; |
| 154 |
|
| 155 |
function Rotate_Right |
| 156 |
(Value : Short_Unsigned; |
| 157 |
Amount : Natural) return Short_Unsigned; |
| 158 |
|
| 159 |
function Shift_Left |
| 160 |
(Value : Unsigned; |
| 161 |
Amount : Natural) return Unsigned; |
| 162 |
|
| 163 |
function Shift_Right |
| 164 |
(Value : Unsigned; |
| 165 |
Amount : Natural) return Unsigned; |
| 166 |
|
| 167 |
function Shift_Right_Arithmetic |
| 168 |
(Value : Unsigned; |
| 169 |
Amount : Natural) return Unsigned; |
| 170 |
|
| 171 |
function Rotate_Left |
| 172 |
(Value : Unsigned; |
| 173 |
Amount : Natural) return Unsigned; |
| 174 |
|
| 175 |
function Rotate_Right |
| 176 |
(Value : Unsigned; |
| 177 |
Amount : Natural) return Unsigned; |
| 178 |
|
| 179 |
function Shift_Left |
| 180 |
(Value : Long_Unsigned; |
| 181 |
Amount : Natural) return Long_Unsigned; |
| 182 |
|
| 183 |
function Shift_Right |
| 184 |
(Value : Long_Unsigned; |
| 185 |
Amount : Natural) return Long_Unsigned; |
| 186 |
|
| 187 |
function Shift_Right_Arithmetic |
| 188 |
(Value : Long_Unsigned; |
| 189 |
Amount : Natural) return Long_Unsigned; |
| 190 |
|
| 191 |
function Rotate_Left |
| 192 |
(Value : Long_Unsigned; |
| 193 |
Amount : Natural) return Long_Unsigned; |
| 194 |
|
| 195 |
function Rotate_Right |
| 196 |
(Value : Long_Unsigned; |
| 197 |
Amount : Natural) return Long_Unsigned; |
| 198 |
|
| 199 |
function Shift_Left |
| 200 |
(Value : Long_Long_Unsigned; |
| 201 |
Amount : Natural) return Long_Long_Unsigned; |
| 202 |
|
| 203 |
function Shift_Right |
| 204 |
(Value : Long_Long_Unsigned; |
| 205 |
Amount : Natural) return Long_Long_Unsigned; |
| 206 |
|
| 207 |
function Shift_Right_Arithmetic |
| 208 |
(Value : Long_Long_Unsigned; |
| 209 |
Amount : Natural) return Long_Long_Unsigned; |
| 210 |
|
| 211 |
function Rotate_Left |
| 212 |
(Value : Long_Long_Unsigned; |
| 213 |
Amount : Natural) return Long_Long_Unsigned; |
| 214 |
|
| 215 |
function Rotate_Right |
| 216 |
(Value : Long_Long_Unsigned; |
| 217 |
Amount : Natural) return Long_Long_Unsigned; |
| 218 |
|
| 219 |
function Shift_Left |
| 220 |
(Value : Long_Long_Long_Unsigned; |
| 221 |
Amount : Natural) return Long_Long_Long_Unsigned; |
| 222 |
|
| 223 |
function Shift_Right |
| 224 |
(Value : Long_Long_Long_Unsigned; |
| 225 |
Amount : Natural) return Long_Long_Long_Unsigned; |
| 226 |
|
| 227 |
function Shift_Right_Arithmetic |
| 228 |
(Value : Long_Long_Long_Unsigned; |
| 229 |
Amount : Natural) return Long_Long_Long_Unsigned; |
| 230 |
|
| 231 |
function Rotate_Left |
| 232 |
(Value : Long_Long_Long_Unsigned; |
| 233 |
Amount : Natural) return Long_Long_Long_Unsigned; |
| 234 |
|
| 235 |
function Rotate_Right |
| 236 |
(Value : Long_Long_Long_Unsigned; |
| 237 |
Amount : Natural) return Long_Long_Long_Unsigned; |
| 238 |
-- The shift and rotate primitives for the unsigned types are intrinsic, |
| 239 |
-- fully implemented by the compiler. |
| 240 |
|
| 241 |
pragma Import (Intrinsic, Shift_Left); |
| 242 |
pragma Import (Intrinsic, Shift_Right); |
| 243 |
pragma Import (Intrinsic, Shift_Right_Arithmetic); |
| 244 |
pragma Import (Intrinsic, Rotate_Left); |
| 245 |
pragma Import (Intrinsic, Rotate_Right); |
| 246 |
|
| 247 |
-- The following definitions are obsolescent. They were needed by the |
| 248 |
-- previous version of the compiler and runtime, but are not needed |
| 249 |
-- by the current version. We retain them to help with bootstrap path |
| 250 |
-- problems. Also they seem harmless, and if any user programs have |
| 251 |
-- been using these types, why discombobulate them? |
| 252 |
|
| 253 |
subtype Packed_Bytes is Packed_Bytes4; |
| 254 |
subtype Packed_Bytes_Unaligned is Packed_Bytes1; |
| 255 |
|
| 256 |
end System.Unsigned_Types; |