1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2021, 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
;
74 Uint_Minus_1
: constant Uint
;
75 Uint_Minus_2
: constant Uint
;
76 Uint_Minus_3
: constant Uint
;
77 Uint_Minus_4
: constant Uint
;
78 Uint_Minus_5
: constant Uint
;
79 Uint_Minus_6
: constant Uint
;
80 Uint_Minus_7
: constant Uint
;
81 Uint_Minus_8
: constant Uint
;
82 Uint_Minus_9
: constant Uint
;
83 Uint_Minus_12
: constant Uint
;
84 Uint_Minus_18
: constant Uint
;
85 Uint_Minus_31
: constant Uint
;
86 Uint_Minus_36
: constant Uint
;
87 Uint_Minus_63
: constant Uint
;
88 Uint_Minus_76
: constant Uint
;
89 Uint_Minus_80
: constant Uint
;
90 Uint_Minus_127
: constant Uint
;
91 Uint_Minus_128
: constant Uint
;
93 -- Functions for detecting No_Uint. Note that clients of this package
94 -- cannot use "=" and "/=" to compare with No_Uint; they must use No
95 -- and Present instead.
97 function No
(X
: Uint
) return Boolean is (X
= No_Uint
);
98 -- Note that this is using the predefined "=", not the "=" declared below,
99 -- which would blow up on No_Uint.
101 function Present
(X
: Uint
) return Boolean is (not No
(X
));
103 subtype Valid_Uint
is Uint
with Predicate
=> Present
(Valid_Uint
);
104 subtype Unat
is Valid_Uint
with Predicate
=> Unat
>= Uint_0
; -- natural
105 subtype Upos
is Valid_Uint
with Predicate
=> Upos
>= Uint_1
; -- positive
106 subtype Nonzero_Uint
is Valid_Uint
with Predicate
=> Nonzero_Uint
/= Uint_0
;
107 subtype Unegative
is Valid_Uint
with Predicate
=> Unegative
< Uint_0
;
108 subtype Ubool
is Valid_Uint
with Predicate
=> Ubool
in Uint_0 | Uint_1
;
109 subtype Opt_Ubool
is Uint
with
110 Predicate
=> No
(Opt_Ubool
) or else Opt_Ubool
in Ubool
;
116 procedure Initialize
;
117 -- Initialize Uint tables. Note also that there is no lock routine in this
118 -- unit, these are among the few tables that can be expanded during
121 function UI_Abs
(Right
: Valid_Uint
) return Unat
;
122 pragma Inline
(UI_Abs
);
123 -- Returns abs function of universal integer
125 function UI_Add
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
126 function UI_Add
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
127 function UI_Add
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
128 -- Returns sum of two integer values
130 function UI_Decimal_Digits_Hi
(U
: Valid_Uint
) return Nat
;
131 -- Returns an estimate of the number of decimal digits required to
132 -- represent the absolute value of U. This estimate is correct or high,
133 -- i.e. it never returns a value that is too low. The accuracy of the
134 -- estimate affects only the effectiveness of comparison optimizations
137 function UI_Decimal_Digits_Lo
(U
: Valid_Uint
) return Nat
;
138 -- Returns an estimate of the number of decimal digits required to
139 -- represent the absolute value of U. This estimate is correct or low,
140 -- i.e. it never returns a value that is too high. The accuracy of the
141 -- estimate affects only the effectiveness of comparison optimizations
144 function UI_Div
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
145 function UI_Div
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
146 function UI_Div
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
147 -- Returns quotient of two integer values. Fatal error if Right = 0
149 function UI_Eq
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
150 function UI_Eq
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
151 function UI_Eq
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
152 pragma Inline
(UI_Eq
);
153 -- Compares integer values for equality
155 function UI_Expon
(Left
: Valid_Uint
; Right
: Unat
) return Valid_Uint
;
156 function UI_Expon
(Left
: Int
; Right
: Unat
) return Valid_Uint
;
157 function UI_Expon
(Left
: Valid_Uint
; Right
: Nat
) return Valid_Uint
;
158 function UI_Expon
(Left
: Int
; Right
: Nat
) return Valid_Uint
;
159 -- Returns result of exponentiating two integer values.
160 -- Fatal error if Right is negative.
162 function UI_GCD
(Uin
, Vin
: Valid_Uint
) return Valid_Uint
;
163 -- Computes GCD of input values. Assumes Uin >= Vin >= 0
165 function UI_Ge
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
166 function UI_Ge
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
167 function UI_Ge
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
168 pragma Inline
(UI_Ge
);
169 -- Compares integer values for greater than or equal
171 function UI_Gt
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
172 function UI_Gt
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
173 function UI_Gt
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
174 pragma Inline
(UI_Gt
);
175 -- Compares integer values for greater than
177 function UI_Is_In_Int_Range
(Input
: Valid_Uint
) return Boolean;
178 pragma Inline
(UI_Is_In_Int_Range
);
179 -- Determines if universal integer is in Int range.
181 function UI_Le
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
182 function UI_Le
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
183 function UI_Le
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
184 pragma Inline
(UI_Le
);
185 -- Compares integer values for less than or equal
187 function UI_Lt
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
188 function UI_Lt
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
189 function UI_Lt
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
190 -- Compares integer values for less than
192 function UI_Max
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
193 function UI_Max
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
194 function UI_Max
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
195 -- Returns maximum of two integer values
197 function UI_Min
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
198 function UI_Min
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
199 function UI_Min
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
200 -- Returns minimum of two integer values
202 function UI_Mod
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
203 function UI_Mod
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
204 function UI_Mod
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
205 pragma Inline
(UI_Mod
);
206 -- Returns mod function of two integer values
208 function UI_Mul
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
209 function UI_Mul
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
210 function UI_Mul
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
211 -- Returns product of two integer values
213 function UI_Ne
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean;
214 function UI_Ne
(Left
: Int
; Right
: Valid_Uint
) return Boolean;
215 function UI_Ne
(Left
: Valid_Uint
; Right
: Int
) return Boolean;
216 pragma Inline
(UI_Ne
);
217 -- Compares integer values for inequality
219 function UI_Negate
(Right
: Valid_Uint
) return Valid_Uint
;
220 pragma Inline
(UI_Negate
);
221 -- Returns negative of universal integer
223 function UI_Rem
(Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
;
224 function UI_Rem
(Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
;
225 function UI_Rem
(Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
;
226 -- Returns rem of two integer values
228 function UI_Sub
(Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
;
229 function UI_Sub
(Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
;
230 function UI_Sub
(Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
;
231 pragma Inline
(UI_Sub
);
232 -- Returns difference of two integer values
234 function UI_From_Int
(Input
: Int
) return Valid_Uint
;
235 -- Converts Int value to universal integer form
238 type In_T
is range <>;
239 function UI_From_Integral
(Input
: In_T
) return Valid_Uint
;
240 -- Likewise, but converts from any integer type. Must not be applied to
241 -- biased types (instantiation will provide a warning if actual is a biased
244 function UI_From_CC
(Input
: Char_Code
) return Valid_Uint
;
245 -- Converts Char_Code value to universal integer form
247 function UI_To_Int
(Input
: Valid_Uint
) return Int
;
248 -- Converts universal integer value to Int. Constraint_Error if value is
249 -- not in appropriate range.
251 type Unsigned_64
is mod 2**64;
252 function UI_To_Unsigned_64
(Input
: Valid_Uint
) return Unsigned_64
;
253 -- Converts universal integer value to Unsigned_64. Constraint_Error if
254 -- value is not in appropriate range.
256 function UI_To_CC
(Input
: Valid_Uint
) return Char_Code
;
257 -- Converts universal integer value to Char_Code. Constraint_Error if value
258 -- is not in Char_Code range.
260 function Num_Bits
(Input
: Valid_Uint
) return Nat
;
261 -- Approximate number of binary bits in given universal integer. This
262 -- function is used for capacity checks, and it can be one bit off
263 -- without affecting its usage.
265 ---------------------
266 -- Output Routines --
267 ---------------------
269 type UI_Format
is (Hex
, Decimal
, Auto
);
270 -- Used to determine whether UI_Image/UI_Write output is in hexadecimal
271 -- or decimal format. Auto, the default setting, lets the routine make a
272 -- decision based on the value.
274 UI_Image_Max
: constant := 1024;
275 UI_Image_Buffer
: String (1 .. UI_Image_Max
);
276 UI_Image_Length
: Natural;
277 -- Buffer used for UI_Image as described below
279 procedure UI_Image
(Input
: Uint
; Format
: UI_Format
:= Auto
);
280 -- Places a representation of Uint, consisting of a possible minus sign,
281 -- followed by the value in UI_Image_Buffer. The form of the value is an
282 -- integer literal in either decimal (no base) or hexadecimal (base 16)
283 -- format. If Hex is True on entry, then hex mode is forced, otherwise
284 -- UI_Image makes a guess at which output format is more convenient. The
285 -- value must fit in UI_Image_Buffer. The actual length of the result is
286 -- returned in UI_Image_Length. If necessary to meet this requirement, the
287 -- result is an approximation of the proper value, using an exponential
288 -- format. The image of No_Uint is output as a single question mark.
290 function UI_Image
(Input
: Uint
; Format
: UI_Format
:= Auto
) return String;
291 -- Functional form, in which the result is returned as a string. This call
292 -- also leaves the result in UI_Image_Buffer/Length as described above.
294 procedure UI_Write
(Input
: Uint
; Format
: UI_Format
:= Auto
);
295 -- Writes a representation of Uint, consisting of a possible minus sign,
296 -- followed by the value to the output file. The form of the value is an
297 -- integer literal in either decimal (no base) or hexadecimal (base 16)
298 -- format as appropriate. UI_Format shows which format to use. Auto, the
299 -- default, asks UI_Write to make a guess at which output format will be
300 -- more convenient to read.
302 procedure pid
(Input
: Uint
);
303 pragma Export
(Ada
, pid
);
304 -- Writes representation of Uint in decimal with a terminating line
305 -- return. This is intended for use from the debugger.
307 procedure pih
(Input
: Uint
);
308 pragma Export
(Ada
, pih
);
309 -- Writes representation of Uint in hex with a terminating line return.
310 -- This is intended for use from the debugger.
312 ------------------------
313 -- Operator Renamings --
314 ------------------------
316 function "+" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
318 function "+" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
320 function "+" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
323 function "/" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
325 function "/" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
327 function "/" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
330 function "*" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
332 function "*" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
334 function "*" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
337 function "-" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Valid_Uint
339 function "-" (Left
: Int
; Right
: Valid_Uint
) return Valid_Uint
341 function "-" (Left
: Valid_Uint
; Right
: Int
) return Valid_Uint
344 function "**" (Left
: Valid_Uint
; Right
: Unat
) return Valid_Uint
346 function "**" (Left
: Valid_Uint
; Right
: Nat
) return Valid_Uint
348 function "**" (Left
: Int
; Right
: Unat
) return Valid_Uint
350 function "**" (Left
: Int
; Right
: Nat
) return Valid_Uint
353 function "abs" (Real
: Valid_Uint
) return Unat
356 function "mod" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
358 function "mod" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
360 function "mod" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
363 function "rem" (Left
: Valid_Uint
; Right
: Nonzero_Uint
) return Valid_Uint
365 function "rem" (Left
: Int
; Right
: Nonzero_Uint
) return Valid_Uint
367 function "rem" (Left
: Valid_Uint
; Right
: Nonzero_Int
) return Valid_Uint
370 function "-" (Real
: Valid_Uint
) return Valid_Uint
373 function "=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
375 function "=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
377 function "=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
380 function ">=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
382 function ">=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
384 function ">=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
387 function ">" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
389 function ">" (Left
: Int
; Right
: Valid_Uint
) return Boolean
391 function ">" (Left
: Valid_Uint
; Right
: Int
) return Boolean
394 function "<=" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
396 function "<=" (Left
: Int
; Right
: Valid_Uint
) return Boolean
398 function "<=" (Left
: Valid_Uint
; Right
: Int
) return Boolean
401 function "<" (Left
: Valid_Uint
; Right
: Valid_Uint
) return Boolean
403 function "<" (Left
: Int
; Right
: Valid_Uint
) return Boolean
405 function "<" (Left
: Valid_Uint
; Right
: Int
) return Boolean
408 -----------------------------
409 -- Mark/Release Processing --
410 -----------------------------
412 -- The space used by Uint data is not automatically reclaimed. However, a
413 -- mark-release regime is implemented which allows storage to be released
414 -- back to a previously noted mark. This is used for example when doing
415 -- comparisons, where only intermediate results get stored that do not
416 -- need to be saved for future use.
418 type Save_Mark
is private;
420 function Mark
return Save_Mark
;
421 -- Note mark point for future release
423 procedure Release
(M
: Save_Mark
);
424 -- Release storage allocated since mark was noted
426 procedure Release_And_Save
(M
: Save_Mark
; UI
: in out Valid_Uint
);
427 -- Like Release, except that the given Uint value (which is typically among
428 -- the data being released) is recopied after the release, so that it is
429 -- the most recent item, and UI is updated to point to its copied location.
431 procedure Release_And_Save
(M
: Save_Mark
; UI1
, UI2
: in out Valid_Uint
);
432 -- Like Release, except that the given Uint values (which are typically
433 -- among the data being released) are recopied after the release, so that
434 -- they are the most recent items, and UI1 and UI2 are updated if necessary
435 -- to point to the copied locations. This routine is careful to do things
436 -- in the right order, so that the values do not clobber one another.
438 -----------------------------------
439 -- Representation of Uint Values --
440 -----------------------------------
444 type Uint
is new Int
range Uint_Low_Bound
.. Uint_High_Bound
;
445 for Uint
'Size use 32;
447 No_Uint
: constant Uint
:= Uint
(Uint_Low_Bound
);
449 -- Uint values are represented as multiple precision integers stored in
450 -- a multi-digit format using Base as the base. This value is chosen so
451 -- that the product Base*Base is within the range of allowed Int values.
453 -- Base is defined to allow efficient execution of the primitive operations
454 -- (a0, b0, c0) defined in the section "The Classical Algorithms"
455 -- (sec. 4.3.1) of Donald Knuth's "The Art of Computer Programming",
456 -- Vol. 2. These algorithms are used in this package. In particular,
457 -- the product of two single digits in this base fits in a 32-bit integer.
459 Base_Bits
: constant := 15;
460 -- Number of bits in base value
462 Base
: constant Int
:= 2**Base_Bits
;
464 -- Values in the range -(Base-1) .. Max_Direct are encoded directly as
465 -- Uint values by adding a bias value. The value of Max_Direct is chosen
466 -- so that a directly represented number always fits in two digits when
467 -- represented in base format.
469 Min_Direct
: constant Int
:= -(Base
- 1);
470 Max_Direct
: constant Int
:= (Base
- 1) * (Base
- 1);
472 -- The following values define the bias used to store Uint values which
473 -- are in this range, as well as the biased values for the first and last
474 -- values in this range. We use a new derived type for these constants to
475 -- avoid accidental use of Uint arithmetic on these values, which is never
478 type Ctrl
is new Int
;
480 Uint_Direct_Bias
: constant Ctrl
:= Ctrl
(Uint_Low_Bound
) + Ctrl
(Base
);
481 Uint_Direct_First
: constant Ctrl
:= Uint_Direct_Bias
+ Ctrl
(Min_Direct
);
482 Uint_Direct_Last
: constant Ctrl
:= Uint_Direct_Bias
+ Ctrl
(Max_Direct
);
484 Uint_0
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 0);
485 Uint_1
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 1);
486 Uint_2
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 2);
487 Uint_3
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 3);
488 Uint_4
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 4);
489 Uint_5
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 5);
490 Uint_6
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 6);
491 Uint_7
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 7);
492 Uint_8
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 8);
493 Uint_9
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 9);
494 Uint_10
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 10);
495 Uint_11
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 11);
496 Uint_12
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 12);
497 Uint_13
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 13);
498 Uint_14
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 14);
499 Uint_15
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 15);
500 Uint_16
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 16);
501 Uint_24
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 24);
502 Uint_31
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 31);
503 Uint_32
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 32);
504 Uint_63
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 63);
505 Uint_64
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 64);
506 Uint_80
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 80);
507 Uint_127
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 127);
508 Uint_128
: constant Uint
:= Uint
(Uint_Direct_Bias
+ 128);
510 Uint_Minus_1
: constant Uint
:= Uint
(Uint_Direct_Bias
- 1);
511 Uint_Minus_2
: constant Uint
:= Uint
(Uint_Direct_Bias
- 2);
512 Uint_Minus_3
: constant Uint
:= Uint
(Uint_Direct_Bias
- 3);
513 Uint_Minus_4
: constant Uint
:= Uint
(Uint_Direct_Bias
- 4);
514 Uint_Minus_5
: constant Uint
:= Uint
(Uint_Direct_Bias
- 5);
515 Uint_Minus_6
: constant Uint
:= Uint
(Uint_Direct_Bias
- 6);
516 Uint_Minus_7
: constant Uint
:= Uint
(Uint_Direct_Bias
- 7);
517 Uint_Minus_8
: constant Uint
:= Uint
(Uint_Direct_Bias
- 8);
518 Uint_Minus_9
: constant Uint
:= Uint
(Uint_Direct_Bias
- 9);
519 Uint_Minus_12
: constant Uint
:= Uint
(Uint_Direct_Bias
- 12);
520 Uint_Minus_18
: constant Uint
:= Uint
(Uint_Direct_Bias
- 18);
521 Uint_Minus_31
: constant Uint
:= Uint
(Uint_Direct_Bias
- 31);
522 Uint_Minus_36
: constant Uint
:= Uint
(Uint_Direct_Bias
- 36);
523 Uint_Minus_63
: constant Uint
:= Uint
(Uint_Direct_Bias
- 63);
524 Uint_Minus_76
: constant Uint
:= Uint
(Uint_Direct_Bias
- 76);
525 Uint_Minus_80
: constant Uint
:= Uint
(Uint_Direct_Bias
- 80);
526 Uint_Minus_127
: constant Uint
:= Uint
(Uint_Direct_Bias
- 127);
527 Uint_Minus_128
: constant Uint
:= Uint
(Uint_Direct_Bias
- 128);
529 Uint_Max_Simple_Mul
: constant := Uint_Direct_Bias
+ 2**15;
530 -- If two values are directly represented and less than or equal to this
531 -- value, then we know the product fits in a 32-bit integer. This allows
532 -- UI_Mul to efficiently compute the product in this case.
534 type Save_Mark
is record
535 Save_Uint
: Valid_Uint
;
539 -- Values outside the range that is represented directly are stored using
540 -- two tables. The secondary table Udigits contains sequences of Int values
541 -- consisting of the digits of the number in a radix Base system. The
542 -- digits are stored from most significant to least significant with the
543 -- first digit only carrying the sign.
545 -- There is one entry in the primary Uints table for each distinct Uint
546 -- value. This table entry contains the length (number of digits) and
547 -- a starting offset of the value in the Udigits table.
549 Uint_First_Entry
: constant Uint
:= Uint
(Uint_Table_Start
);
551 -- Some subprograms defined in this package manipulate the Udigits table
552 -- directly, while for others it is more convenient to work with locally
553 -- defined arrays of the digits of the Universal Integers. The type
554 -- UI_Vector is declared in the package body for this purpose and some
555 -- internal subprograms used for converting from one to the other are
558 type Uint_Entry
is record
559 Length
: aliased Pos
;
560 -- Length of entry in Udigits table in digits (i.e. in words)
563 -- Starting location in Udigits table of this Uint value
566 package Uints
is new Table
.Table
(
567 Table_Component_Type
=> Uint_Entry
,
568 Table_Index_Type
=> Uint
'Base,
569 Table_Low_Bound
=> Uint_First_Entry
,
570 Table_Initial
=> Alloc
.Uints_Initial
,
571 Table_Increment
=> Alloc
.Uints_Increment
,
572 Table_Name
=> "Uints");
574 package Udigits
is new Table
.Table
(
575 Table_Component_Type
=> Int
,
576 Table_Index_Type
=> Int
,
577 Table_Low_Bound
=> 0,
578 Table_Initial
=> Alloc
.Udigits_Initial
,
579 Table_Increment
=> Alloc
.Udigits_Increment
,
580 Table_Name
=> "Udigits");
582 -- Note: the reason these tables are defined here in the private part of
583 -- the spec, rather than in the body, is that they are referenced directly