1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 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. 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Support for universal integer arithmetic
28 -- WARNING: There is a C version of this package. Any changes to this
29 -- source file must be properly reflected in the C header file uintp.h
33 pragma Elaborate_All
(Table
);
34 with Types
; use Types
;
38 -------------------------------------------------
39 -- Basic Types and Constants for Uintp Package --
40 -------------------------------------------------
43 -- The basic universal integer type
45 No_Uint
: constant Uint
;
46 -- A constant value indicating a missing or unset Uint value
48 Uint_0
: constant Uint
;
49 Uint_1
: constant Uint
;
50 Uint_2
: constant Uint
;
51 Uint_3
: constant Uint
;
52 Uint_4
: constant Uint
;
53 Uint_5
: constant Uint
;
54 Uint_6
: constant Uint
;
55 Uint_7
: constant Uint
;
56 Uint_8
: constant Uint
;
57 Uint_9
: constant Uint
;
58 Uint_10
: constant Uint
;
59 Uint_11
: constant Uint
;
60 Uint_12
: constant Uint
;
61 Uint_13
: constant Uint
;
62 Uint_14
: constant Uint
;
63 Uint_15
: constant Uint
;
64 Uint_16
: constant Uint
;
65 Uint_24
: constant Uint
;
66 Uint_31
: constant Uint
;
67 Uint_32
: constant Uint
;
68 Uint_63
: constant Uint
;
69 Uint_64
: constant Uint
;
70 Uint_80
: constant Uint
;
71 Uint_127
: constant Uint
;
72 Uint_128
: constant Uint
;
73 Uint_256
: constant Uint
;
75 Uint_Minus_1
: constant Uint
;
76 Uint_Minus_2
: constant Uint
;
77 Uint_Minus_3
: constant Uint
;
78 Uint_Minus_4
: constant Uint
;
79 Uint_Minus_5
: constant Uint
;
80 Uint_Minus_6
: constant Uint
;
81 Uint_Minus_7
: constant Uint
;
82 Uint_Minus_8
: constant Uint
;
83 Uint_Minus_9
: constant Uint
;
84 Uint_Minus_12
: constant Uint
;
85 Uint_Minus_18
: constant Uint
;
86 Uint_Minus_31
: constant Uint
;
87 Uint_Minus_36
: constant Uint
;
88 Uint_Minus_63
: constant Uint
;
89 Uint_Minus_76
: constant Uint
;
90 Uint_Minus_80
: constant Uint
;
91 Uint_Minus_127
: constant Uint
;
92 Uint_Minus_128
: constant Uint
;
94 -- Functions for detecting No_Uint. Note that clients of this package
95 -- cannot use "=" and "/=" to compare with No_Uint; they must use No
96 -- and Present instead.
98 function No
(X
: Uint
) return Boolean is (X
= No_Uint
);
99 -- Note that this is using the predefined "=", not the "=" declared below,
100 -- which would blow up on No_Uint.
102 function Present
(X
: Uint
) return Boolean is (not No
(X
));
104 subtype Valid_Uint
is Uint
with Predicate
=> Present
(Valid_Uint
);
105 subtype Unat
is Valid_Uint
with Predicate
=> Unat
>= Uint_0
; -- natural
106 subtype Upos
is Valid_Uint
with Predicate
=> Upos
>= Uint_1
; -- positive
107 subtype Nonzero_Uint
is Valid_Uint
with Predicate
=> Nonzero_Uint
/= Uint_0
;
108 subtype Unegative
is Valid_Uint
with Predicate
=> Unegative
< Uint_0
;
109 subtype Ubool
is Valid_Uint
with
110 Predicate
=> Ubool
= Uint_0
or else Ubool
= Uint_1
;
111 subtype Opt_Ubool
is Uint
with
112 Predicate
=> No
(Opt_Ubool
) or else Opt_Ubool
in Ubool
;
118 procedure Initialize
;
119 -- Initialize Uint tables. Note also that there is no lock routine in this
120 -- unit, these are among the few tables that can be expanded during
123 function UI_Abs
(Right
: Valid_Uint
) return Unat
;
124 pragma Inline
(UI_Abs
);
125 -- Returns abs function of universal integer
127 function UI_Add
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
128 function UI_Add
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
129 function UI_Add
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
130 -- Returns sum of two integer values
132 function UI_Decimal_Digits_Hi
(U
: Valid_Uint
) return Nat
;
133 -- Returns an estimate of the number of decimal digits required to
134 -- represent the absolute value of U. This estimate is correct or high,
135 -- i.e. it never returns a value that is too low. The accuracy of the
136 -- estimate affects only the effectiveness of comparison optimizations
139 function UI_Decimal_Digits_Lo
(U
: Valid_Uint
) return Nat
;
140 -- Returns an estimate of the number of decimal digits required to
141 -- represent the absolute value of U. This estimate is correct or low,
142 -- i.e. it never returns a value that is too high. The accuracy of the
143 -- estimate affects only the effectiveness of comparison optimizations
146 function UI_Div
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
147 function UI_Div
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
148 function UI_Div
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
149 -- Returns quotient of two integer values. Fatal error if Right = 0
151 function UI_Eq
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
152 function UI_Eq
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
153 function UI_Eq
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
154 pragma Inline
(UI_Eq
);
155 -- Compares integer values for equality
157 function UI_Expon
(Left
: Valid_Uint
; Right
: Unat
) return Valid_Uint
;
158 function UI_Expon
(Left
: Int
; Right
: Unat
) return Valid_Uint
;
159 function UI_Expon
(Left
: Valid_Uint
; Right
: Nat
) return Valid_Uint
;
160 function UI_Expon
(Left
: Int
; Right
: Nat
) return Valid_Uint
;
161 -- Returns result of exponentiating two integer values.
162 -- Fatal error if Right is negative.
164 function UI_GCD
(Uin
, Vin
: Valid_Uint
) return Valid_Uint
;
165 -- Computes GCD of input values. Assumes Uin >= Vin >= 0
167 function UI_Ge
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
168 function UI_Ge
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
169 function UI_Ge
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
170 pragma Inline
(UI_Ge
);
171 -- Compares integer values for greater than or equal
173 function UI_Gt
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
174 function UI_Gt
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
175 function UI_Gt
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
176 pragma Inline
(UI_Gt
);
177 -- Compares integer values for greater than
179 function UI_Is_In_Int_Range
(Input
: Valid_Uint
) return Boolean;
180 pragma Inline
(UI_Is_In_Int_Range
);
181 -- Determines if universal integer is in Int range.
183 function UI_Le
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
184 function UI_Le
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
185 function UI_Le
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
186 pragma Inline
(UI_Le
);
187 -- Compares integer values for less than or equal
189 function UI_Lt
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
190 function UI_Lt
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
191 function UI_Lt
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
192 -- Compares integer values for less than
194 function UI_Max
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
195 function UI_Max
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
196 function UI_Max
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
197 -- Returns maximum of two integer values
199 function UI_Min
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
200 function UI_Min
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
201 function UI_Min
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
202 -- Returns minimum of two integer values
204 function UI_Mod
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
205 function UI_Mod
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
206 function UI_Mod
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
207 pragma Inline
(UI_Mod
);
208 -- Returns mod function of two integer values
210 function UI_Mul
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
211 function UI_Mul
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
212 function UI_Mul
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
213 -- Returns product of two integer values
215 function UI_Ne
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
216 function UI_Ne
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
217 function UI_Ne
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
218 pragma Inline
(UI_Ne
);
219 -- Compares integer values for inequality
221 function UI_Negate
(Right
: Valid_Uint
) return Valid_Uint
;
222 pragma Inline
(UI_Negate
);
223 -- Returns negative of universal integer
225 function UI_Rem
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
226 function UI_Rem
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
227 function UI_Rem
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
228 -- Returns rem of two integer values
230 function UI_Sub
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
231 function UI_Sub
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
232 function UI_Sub
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
233 pragma Inline
(UI_Sub
);
234 -- Returns difference of two integer values
236 function UI_From_Int
(Input
: Int
) return Valid_Uint
;
237 -- Converts Int value to universal integer form
240 type In_T
is range <>;
241 function UI_From_Integral
(Input
: In_T
) return Valid_Uint
;
242 -- Likewise, but converts from any integer type. Must not be applied to
243 -- biased types (instantiation will provide a warning if actual is a biased
246 function UI_From_CC
(Input
: Char_Code
) return Valid_Uint
;
247 -- Converts Char_Code value to universal integer form
249 function UI_To_Int
(Input
: Valid_Uint
) return Int
;
250 -- Converts universal integer value to Int. Constraint_Error if value is
251 -- not in appropriate range.
253 type Unsigned_64
is mod 2**64;
254 function UI_To_Unsigned_64
(Input
: Valid_Uint
) return Unsigned_64
;
255 -- Converts universal integer value to Unsigned_64. Constraint_Error if
256 -- value is not in appropriate range.
258 function UI_To_CC
(Input
: Valid_Uint
) return Char_Code
;
259 -- Converts universal integer value to Char_Code. Constraint_Error if value
260 -- is not in Char_Code range.
262 function Num_Bits
(Input
: Valid_Uint
) return Nat
;
263 -- Approximate number of binary bits in given universal integer. This
264 -- function is used for capacity checks, and it can be one bit off
265 -- without affecting its usage.
267 ---------------------
268 -- Output Routines --
269 ---------------------
271 type UI_Format
is (Hex
, Decimal
, Auto
);
272 -- Used to determine whether UI_Image/UI_Write output is in hexadecimal
273 -- or decimal format. Auto, the default setting, lets the routine make a
274 -- decision based on the value.
276 UI_Image_Max
: constant := 1024;
277 UI_Image_Buffer
: String (1 .. UI_Image_Max
);
278 UI_Image_Length
: Natural;
279 -- Buffer used for UI_Image as described below
281 procedure UI_Image
(Input
: Uint
; Format
: UI_Format
:= Auto
);
282 -- Places a representation of Uint, consisting of a possible minus sign,
283 -- followed by the value in UI_Image_Buffer. The form of the value is an
284 -- integer literal in either decimal (no base) or hexadecimal (base 16)
285 -- format. If Hex is True on entry, then hex mode is forced, otherwise
286 -- UI_Image makes a guess at which output format is more convenient. The
287 -- value must fit in UI_Image_Buffer. The actual length of the result is
288 -- returned in UI_Image_Length. If necessary to meet this requirement, the
289 -- result is an approximation of the proper value, using an exponential
290 -- format. The image of No_Uint is output as a single question mark.
292 function UI_Image
(Input
: Uint
; Format
: UI_Format
:= Auto
) return String;
293 -- Functional form, in which the result is returned as a string. This call
294 -- also leaves the result in UI_Image_Buffer/Length as described above.
296 procedure UI_Write
(Input
: Uint
; Format
: UI_Format
:= Auto
);
297 -- Writes a representation of Uint, consisting of a possible minus sign,
298 -- followed by the value to the output file. The form of the value is an
299 -- integer literal in either decimal (no base) or hexadecimal (base 16)
300 -- format as appropriate. UI_Format shows which format to use. Auto, the
301 -- default, asks UI_Write to make a guess at which output format will be
302 -- more convenient to read.
304 procedure pid
(Input
: Uint
);
305 pragma Export
(Ada
, pid
);
306 -- Writes representation of Uint in decimal with a terminating line
307 -- return. This is intended for use from the debugger.
309 procedure pih
(Input
: Uint
);
310 pragma Export
(Ada
, pih
);
311 -- Writes representation of Uint in hex with a terminating line return.
312 -- This is intended for use from the debugger.
314 ------------------------
315 -- Operator Renamings --
316 ------------------------
318 function "+" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
320 function "+" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
322 function "+" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
325 function "/" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
327 function "/" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
329 function "/" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
332 function "*" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
334 function "*" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
336 function "*" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
339 function "-" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
341 function "-" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
343 function "-" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
346 function "**" (Left
: Valid_Uint
; Right
: Unat
) return Valid_Uint
348 function "**" (Left
: Valid_Uint
; Right
: Nat
) return Valid_Uint
350 function "**" (Left
: Int
; Right
: Unat
) return Valid_Uint
352 function "**" (Left
: Int
; Right
: Nat
) return Valid_Uint
355 function "abs" (Real
: Valid_Uint
) return Unat
358 function "mod" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
360 function "mod" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
362 function "mod" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
365 function "rem" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
367 function "rem" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
369 function "rem" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
372 function "-" (Real
: Valid_Uint
) return Valid_Uint
375 function "=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
377 function "=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
379 function "=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
382 function ">=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
384 function ">=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
386 function ">=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
389 function ">" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
391 function ">" (Left
: Int
; Right
: Valid_Uint
) return Boolean
393 function ">" (Left
: Valid_Uint
; Right
: Int
) return Boolean
396 function "<=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
398 function "<=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
400 function "<=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
403 function "<" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
405 function "<" (Left
: Int
; Right
: Valid_Uint
) return Boolean
407 function "<" (Left
: Valid_Uint
; Right
: Int
) return Boolean
410 -----------------------------
411 -- Mark/Release Processing --
412 -----------------------------
414 -- The space used by Uint data is not automatically reclaimed. However, a
415 -- mark-release regime is implemented which allows storage to be released
416 -- back to a previously noted mark. This is used for example when doing
417 -- comparisons, where only intermediate results get stored that do not
418 -- need to be saved for future use.
420 type Save_Mark
is private;
422 function Mark
return Save_Mark
;
423 -- Note mark point for future release
425 procedure Release
(M
: Save_Mark
);
426 -- Release storage allocated since mark was noted
428 procedure Release_And_Save
(M
: Save_Mark
; UI
: in out Valid_Uint
);
429 -- Like Release, except that the given Uint value (which is typically among
430 -- the data being released) is recopied after the release, so that it is
431 -- the most recent item, and UI is updated to point to its copied location.
433 procedure Release_And_Save
(M
: Save_Mark
; UI1
, UI2
: in out Valid_Uint
);
434 -- Like Release, except that the given Uint values (which are typically
435 -- among the data being released) are recopied after the release, so that
436 -- they are the most recent items, and UI1 and UI2 are updated if necessary
437 -- to point to the copied locations. This routine is careful to do things
438 -- in the right order, so that the values do not clobber one another.
440 -----------------------------------
441 -- Representation of Uint Values --
442 -----------------------------------
446 type Uint
is new Int
range Uint_Low_Bound
.. Uint_High_Bound
;
447 for Uint
'Size use 32;
449 No_Uint
: constant Uint
:= Uint
(Uint_Low_Bound
);
451 -- Uint values are represented as multiple precision integers stored in
452 -- a multi-digit format using Base as the base. This value is chosen so
453 -- that the product Base*Base is within the range of allowed Int values.
455 -- Base is defined to allow efficient execution of the primitive operations
456 -- (a0, b0, c0) defined in the section "The Classical Algorithms"
457 -- (sec. 4.3.1) of Donald Knuth's "The Art of Computer Programming",
458 -- Vol. 2. These algorithms are used in this package. In particular,
459 -- the product of two single digits in this base fits in a 32-bit integer.
461 Base_Bits
: constant := 15;
462 -- Number of bits in base value
464 Base
: constant Int
:= 2**Base_Bits
;
466 -- Values in the range -(Base-1) .. Max_Direct are encoded directly as
467 -- Uint values by adding a bias value. The value of Max_Direct is chosen
468 -- so that a directly represented number always fits in two digits when
469 -- represented in base format.
471 Min_Direct
: constant Int
:= -(Base
- 1);
472 Max_Direct
: constant Int
:= (Base
- 1) * (Base
- 1);
474 -- The following values define the bias used to store Uint values which
475 -- are in this range, as well as the biased values for the first and last
476 -- values in this range. We use a new derived type for these constants to
477 -- avoid accidental use of Uint arithmetic on these values, which is never
480 type Ctrl
is new Int
;
482 Uint_Direct_Bias
: constant Ctrl
:= Ctrl
(Uint_Low_Bound
) + Ctrl
(Base
);
483 Uint_Direct_First
: constant Ctrl
:= Uint_Direct_Bias
+ Ctrl
(Min_Direct
);
484 Uint_Direct_Last
: constant Ctrl
:= Uint_Direct_Bias
+ Ctrl
(Max_Direct
);
486 Uint_0
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 0);
487 Uint_1
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 1);
488 Uint_2
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 2);
489 Uint_3
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 3);
490 Uint_4
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 4);
491 Uint_5
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 5);
492 Uint_6
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 6);
493 Uint_7
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 7);
494 Uint_8
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 8);
495 Uint_9
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 9);
496 Uint_10
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 10);
497 Uint_11
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 11);
498 Uint_12
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 12);
499 Uint_13
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 13);
500 Uint_14
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 14);
501 Uint_15
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 15);
502 Uint_16
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 16);
503 Uint_24
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 24);
504 Uint_31
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 31);
505 Uint_32
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 32);
506 Uint_63
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 63);
507 Uint_64
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 64);
508 Uint_80
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 80);
509 Uint_127
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 127);
510 Uint_128
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 128);
511 Uint_256
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 256);
513 Uint_Minus_1
: constant Uint
:= Uint
(Uint_Direct_Bias
- 1);
514 Uint_Minus_2
: constant Uint
:= Uint
(Uint_Direct_Bias
- 2);
515 Uint_Minus_3
: constant Uint
:= Uint
(Uint_Direct_Bias
- 3);
516 Uint_Minus_4
: constant Uint
:= Uint
(Uint_Direct_Bias
- 4);
517 Uint_Minus_5
: constant Uint
:= Uint
(Uint_Direct_Bias
- 5);
518 Uint_Minus_6
: constant Uint
:= Uint
(Uint_Direct_Bias
- 6);
519 Uint_Minus_7
: constant Uint
:= Uint
(Uint_Direct_Bias
- 7);
520 Uint_Minus_8
: constant Uint
:= Uint
(Uint_Direct_Bias
- 8);
521 Uint_Minus_9
: constant Uint
:= Uint
(Uint_Direct_Bias
- 9);
522 Uint_Minus_12
: constant Uint
:= Uint
(Uint_Direct_Bias
- 12);
523 Uint_Minus_18
: constant Uint
:= Uint
(Uint_Direct_Bias
- 18);
524 Uint_Minus_31
: constant Uint
:= Uint
(Uint_Direct_Bias
- 31);
525 Uint_Minus_36
: constant Uint
:= Uint
(Uint_Direct_Bias
- 36);
526 Uint_Minus_63
: constant Uint
:= Uint
(Uint_Direct_Bias
- 63);
527 Uint_Minus_76
: constant Uint
:= Uint
(Uint_Direct_Bias
- 76);
528 Uint_Minus_80
: constant Uint
:= Uint
(Uint_Direct_Bias
- 80);
529 Uint_Minus_127
: constant Uint
:= Uint
(Uint_Direct_Bias
- 127);
530 Uint_Minus_128
: constant Uint
:= Uint
(Uint_Direct_Bias
- 128);
532 Uint_Max_Simple_Mul
: constant := Uint_Direct_Bias
+ 2**15;
533 -- If two values are directly represented and less than or equal to this
534 -- value, then we know the product fits in a 32-bit integer. This allows
535 -- UI_Mul to efficiently compute the product in this case.
537 type Save_Mark
is record
538 Save_Uint
: Valid_Uint
;
542 -- Values outside the range that is represented directly are stored using
543 -- two tables. The secondary table Udigits contains sequences of Int values
544 -- consisting of the digits of the number in a radix Base system. The
545 -- digits are stored from most significant to least significant with the
546 -- first digit only carrying the sign.
548 -- There is one entry in the primary Uints table for each distinct Uint
549 -- value. This table entry contains the length (number of digits) and
550 -- a starting offset of the value in the Udigits table.
552 Uint_First_Entry
: constant Uint
:= Uint
(Uint_Table_Start
);
554 -- Some subprograms defined in this package manipulate the Udigits table
555 -- directly, while for others it is more convenient to work with locally
556 -- defined arrays of the digits of the Universal Integers. The type
557 -- UI_Vector is declared in the package body for this purpose and some
558 -- internal subprograms used for converting from one to the other are
561 type Uint_Entry
is record
562 Length
: aliased Pos
;
563 -- Length of entry in Udigits table in digits (i.e. in words)
566 -- Starting location in Udigits table of this Uint value
569 package Uints
is new Table
.Table
(
570 Table_Component_Type
=> Uint_Entry
,
571 Table_Index_Type
=> Uint
'Base,
572 Table_Low_Bound
=> Uint_First_Entry
,
573 Table_Initial
=> Alloc
.Uints_Initial
,
574 Table_Increment
=> Alloc
.Uints_Increment
,
575 Table_Name
=> "Uints");
577 package Udigits
is new Table
.Table
(
578 Table_Component_Type
=> Int
,
579 Table_Index_Type
=> Int
,
580 Table_Low_Bound
=> 0,
581 Table_Initial
=> Alloc
.Udigits_Initial
,
582 Table_Increment
=> Alloc
.Udigits_Increment
,
583 Table_Name
=> "Udigits");
585 -- Note: the reason these tables are defined here in the private part of
586 -- the spec, rather than in the body, is that they are referenced directly