1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                                U I N T P                                 --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2012, 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--  Support for universal integer arithmetic
33
34--  WARNING: There is a C version of this package. Any changes to this
35--  source file must be properly reflected in the C header file uintp.h
36
37with Alloc;
38with Table;
39pragma Elaborate_All (Table);
40with Types; use Types;
41
42package Uintp is
43
44   -------------------------------------------------
45   -- Basic Types and Constants for Uintp Package --
46   -------------------------------------------------
47
48   type Uint is private;
49   --  The basic universal integer type
50
51   No_Uint : constant Uint;
52   --  A constant value indicating a missing or unset Uint value
53
54   Uint_0   : constant Uint;
55   Uint_1   : constant Uint;
56   Uint_2   : constant Uint;
57   Uint_3   : constant Uint;
58   Uint_4   : constant Uint;
59   Uint_5   : constant Uint;
60   Uint_6   : constant Uint;
61   Uint_7   : constant Uint;
62   Uint_8   : constant Uint;
63   Uint_9   : constant Uint;
64   Uint_10  : constant Uint;
65   Uint_11  : constant Uint;
66   Uint_12  : constant Uint;
67   Uint_13  : constant Uint;
68   Uint_14  : constant Uint;
69   Uint_15  : constant Uint;
70   Uint_16  : constant Uint;
71   Uint_24  : constant Uint;
72   Uint_32  : constant Uint;
73   Uint_63  : constant Uint;
74   Uint_64  : constant Uint;
75   Uint_80  : constant Uint;
76   Uint_128 : constant Uint;
77
78   Uint_Minus_1   : constant Uint;
79   Uint_Minus_2   : constant Uint;
80   Uint_Minus_3   : constant Uint;
81   Uint_Minus_4   : constant Uint;
82   Uint_Minus_5   : constant Uint;
83   Uint_Minus_6   : constant Uint;
84   Uint_Minus_7   : constant Uint;
85   Uint_Minus_8   : constant Uint;
86   Uint_Minus_9   : constant Uint;
87   Uint_Minus_12  : constant Uint;
88   Uint_Minus_36  : constant Uint;
89   Uint_Minus_63  : constant Uint;
90   Uint_Minus_80  : constant Uint;
91   Uint_Minus_128 : constant Uint;
92
93   type UI_Vector is array (Pos range <>) of Int;
94   --  Vector containing the integer values of a Uint value
95
96   --  Note: An earlier version of this package used pointers of arrays of Ints
97   --  (dynamically allocated) for the Uint type. The change leads to a few
98   --  less natural idioms used throughout this code, but eliminates all uses
99   --  of the heap except for the table package itself. For example, Uint
100   --  parameters are often converted to UI_Vectors for internal manipulation.
101   --  This is done by creating the local UI_Vector using the function N_Digits
102   --  on the Uint to find the size needed for the vector, and then calling
103   --  Init_Operand to copy the values out of the table into the vector.
104
105   -----------------
106   -- Subprograms --
107   -----------------
108
109   procedure Initialize;
110   --  Initialize Uint tables. Note that Initialize must not be called if
111   --  Tree_Read is used. Note also that there is no lock routine in this
112   --  unit, these are among the few tables that can be expanded during
113   --  gigi processing.
114
115   procedure Tree_Read;
116   --  Initializes internal tables from current tree file using the relevant
117   --  Table.Tree_Read routines. Note that Initialize should not be called if
118   --  Tree_Read is used. Tree_Read includes all necessary initialization.
119
120   procedure Tree_Write;
121   --  Writes out internal tables to current tree file using the relevant
122   --  Table.Tree_Write routines.
123
124   function UI_Abs (Right : Uint) return Uint;
125   pragma Inline (UI_Abs);
126   --  Returns abs function of universal integer
127
128   function UI_Add (Left : Uint; Right : Uint) return Uint;
129   function UI_Add (Left : Int;  Right : Uint) return Uint;
130   function UI_Add (Left : Uint; Right : Int)  return Uint;
131   --  Returns sum of two integer values
132
133   function UI_Decimal_Digits_Hi (U : Uint) return Nat;
134   --  Returns an estimate of the number of decimal digits required to
135   --  represent the absolute value of U. This estimate is correct or high,
136   --  i.e. it never returns a value that is too low. The accuracy of the
137   --  estimate affects only the effectiveness of comparison optimizations
138   --  in Urealp.
139
140   function UI_Decimal_Digits_Lo (U : Uint) return Nat;
141   --  Returns an estimate of the number of decimal digits required to
142   --  represent the absolute value of U. This estimate is correct or low,
143   --  i.e. it never returns a value that is too high. The accuracy of the
144   --  estimate affects only the effectiveness of comparison optimizations
145   --  in Urealp.
146
147   function UI_Div (Left : Uint; Right : Uint) return Uint;
148   function UI_Div (Left : Int;  Right : Uint) return Uint;
149   function UI_Div (Left : Uint; Right : Int)  return Uint;
150   --  Returns quotient of two integer values. Fatal error if Right = 0
151
152   function UI_Eq (Left : Uint; Right : Uint) return Boolean;
153   function UI_Eq (Left : Int;  Right : Uint) return Boolean;
154   function UI_Eq (Left : Uint; Right : Int)  return Boolean;
155   pragma Inline (UI_Eq);
156   --  Compares integer values for equality
157
158   function UI_Expon (Left : Uint; Right : Uint) return Uint;
159   function UI_Expon (Left : Int;  Right : Uint) return Uint;
160   function UI_Expon (Left : Uint; Right : Int)  return Uint;
161   function UI_Expon (Left : Int;  Right : Int)  return Uint;
162   --  Returns result of exponentiating two integer values.
163   --  Fatal error if Right is negative.
164
165   function UI_GCD (Uin, Vin : Uint) return Uint;
166   --  Computes GCD of input values. Assumes Uin >= Vin >= 0
167
168   function UI_Ge (Left : Uint; Right : Uint) return Boolean;
169   function UI_Ge (Left : Int;  Right : Uint) return Boolean;
170   function UI_Ge (Left : Uint; Right : Int)  return Boolean;
171   pragma Inline (UI_Ge);
172   --  Compares integer values for greater than or equal
173
174   function UI_Gt (Left : Uint; Right : Uint) return Boolean;
175   function UI_Gt (Left : Int;  Right : Uint) return Boolean;
176   function UI_Gt (Left : Uint; Right : Int)  return Boolean;
177   pragma Inline (UI_Gt);
178   --  Compares integer values for greater than
179
180   function UI_Is_In_Int_Range (Input : Uint) return Boolean;
181   pragma Inline (UI_Is_In_Int_Range);
182   --  Determines if universal integer is in Int range
183
184   function UI_Le (Left : Uint; Right : Uint) return Boolean;
185   function UI_Le (Left : Int;  Right : Uint) return Boolean;
186   function UI_Le (Left : Uint; Right : Int)  return Boolean;
187   pragma Inline (UI_Le);
188   --  Compares integer values for less than or equal
189
190   function UI_Lt (Left : Uint; Right : Uint) return Boolean;
191   function UI_Lt (Left : Int;  Right : Uint) return Boolean;
192   function UI_Lt (Left : Uint; Right : Int)  return Boolean;
193   --  Compares integer values for less than
194
195   function UI_Max (Left : Uint; Right : Uint) return Uint;
196   function UI_Max (Left : Int;  Right : Uint) return Uint;
197   function UI_Max (Left : Uint; Right : Int)  return Uint;
198   --  Returns maximum of two integer values
199
200   function UI_Min (Left : Uint; Right : Uint) return Uint;
201   function UI_Min (Left : Int;  Right : Uint) return Uint;
202   function UI_Min (Left : Uint; Right : Int)  return Uint;
203   --  Returns minimum of two integer values
204
205   function UI_Mod (Left : Uint; Right : Uint) return Uint;
206   function UI_Mod (Left : Int;  Right : Uint) return Uint;
207   function UI_Mod (Left : Uint; Right : Int)  return Uint;
208   pragma Inline (UI_Mod);
209   --  Returns mod function of two integer values
210
211   function UI_Mul (Left : Uint; Right : Uint) return Uint;
212   function UI_Mul (Left : Int;  Right : Uint) return Uint;
213   function UI_Mul (Left : Uint; Right : Int)  return Uint;
214   --  Returns product of two integer values
215
216   function UI_Ne (Left : Uint; Right : Uint) return Boolean;
217   function UI_Ne (Left : Int;  Right : Uint) return Boolean;
218   function UI_Ne (Left : Uint; Right : Int)  return Boolean;
219   pragma Inline (UI_Ne);
220   --  Compares integer values for inequality
221
222   function UI_Negate (Right : Uint) return Uint;
223   pragma Inline (UI_Negate);
224   --  Returns negative of universal integer
225
226   function UI_Rem (Left : Uint; Right : Uint) return Uint;
227   function UI_Rem (Left : Int;  Right : Uint) return Uint;
228   function UI_Rem (Left : Uint; Right : Int)  return Uint;
229   --  Returns rem of two integer values
230
231   function UI_Sub (Left : Uint; Right : Uint) return Uint;
232   function UI_Sub (Left : Int;  Right : Uint) return Uint;
233   function UI_Sub (Left : Uint; Right : Int)  return Uint;
234   pragma Inline (UI_Sub);
235   --  Returns difference of two integer values
236
237   function UI_Modular_Exponentiation
238     (B      : Uint;
239      E      : Uint;
240      Modulo : Uint) return Uint;
241   --  Efficiently compute (B ** E) rem Modulo
242
243   function UI_Modular_Inverse (N : Uint; Modulo : Uint) return Uint;
244   --  Compute the multiplicative inverse of N in modular arithmetics with the
245   --  given Modulo (uses Euclid's algorithm). Note: the call is considered
246   --  to be erroneous (and the behavior is undefined) if n is not invertible.
247
248   function UI_From_Int (Input : Int) return Uint;
249   --  Converts Int value to universal integer form
250
251   function UI_From_CC (Input : Char_Code) return Uint;
252   --  Converts Char_Code value to universal integer form
253
254   function UI_To_Int (Input : Uint) return Int;
255   --  Converts universal integer value to Int. Fatal error if value is not in
256   --  appropriate range.
257
258   function UI_To_CC (Input : Uint) return Char_Code;
259   --  Converts universal integer value to Char_Code. Fatal error if value is
260   --  not in Char_Code range.
261
262   function Num_Bits (Input : 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.
266
267   function Vector_To_Uint
268     (In_Vec   : UI_Vector;
269      Negative : Boolean) return Uint;
270   --  Functions that calculate values in UI_Vectors, call this function to
271   --  create and return the Uint value. In_Vec contains the multiple precision
272   --  (Base) representation of a non-negative value. Leading zeroes are
273   --  permitted. Negative is set if the desired result is the negative of the
274   --  given value. The result will be either the appropriate directly
275   --  represented value, or a table entry in the proper canonical format is
276   --  created and returned.
277   --
278   --  Note that Init_Operand puts a signed value in the result vector, but
279   --  Vector_To_Uint is always presented with a non-negative value. The
280   --  processing of signs is something that is done by the caller before
281   --  calling Vector_To_Uint.
282
283   ---------------------
284   -- Output Routines --
285   ---------------------
286
287   type UI_Format is (Hex, Decimal, Auto);
288   --  Used to determine whether UI_Image/UI_Write output is in hexadecimal
289   --  or decimal format. Auto, the default setting, lets the routine make a
290   --  decision based on the value.
291
292   UI_Image_Max    : constant := 48; -- Enough for a 128-bit number
293   UI_Image_Buffer : String (1 .. UI_Image_Max);
294   UI_Image_Length : Natural;
295   --  Buffer used for UI_Image as described below
296
297   procedure UI_Image (Input : Uint; Format : UI_Format := Auto);
298   --  Places a representation of Uint, consisting of a possible minus sign,
299   --  followed by the value in UI_Image_Buffer. The form of the value is an
300   --  integer literal in either decimal (no base) or hexadecimal (base 16)
301   --  format. If Hex is True on entry, then hex mode is forced, otherwise
302   --  UI_Image makes a guess at which output format is more convenient.
303   --  The value must fit in UI_Image_Buffer. If necessary, the result is an
304   --  approximation of the proper value, using an exponential format. The
305   --  image of No_Uint is output as a single question mark.
306
307   procedure UI_Write (Input : Uint; Format : UI_Format := Auto);
308   --  Writes a representation of Uint, consisting of a possible minus sign,
309   --  followed by the value to the output file. The form of the value is an
310   --  integer literal in either decimal (no base) or hexadecimal (base 16)
311   --  format as appropriate. UI_Format shows which format to use. Auto, the
312   --  default, asks UI_Write to make a guess at which output format will be
313   --  more convenient to read.
314
315   procedure pid (Input : Uint);
316   pragma Export (Ada, pid);
317   --  Writes representation of Uint in decimal with a terminating line
318   --  return. This is intended for use from the debugger.
319
320   procedure pih (Input : Uint);
321   pragma Export (Ada, pih);
322   --  Writes representation of Uint in hex with a terminating line return.
323   --  This is intended for use from the debugger.
324
325   ------------------------
326   -- Operator Renamings --
327   ------------------------
328
329   function "+" (Left : Uint; Right : Uint) return Uint renames UI_Add;
330   function "+" (Left : Int;  Right : Uint) return Uint renames UI_Add;
331   function "+" (Left : Uint; Right : Int)  return Uint renames UI_Add;
332
333   function "/" (Left : Uint; Right : Uint) return Uint renames UI_Div;
334   function "/" (Left : Int;  Right : Uint) return Uint renames UI_Div;
335   function "/" (Left : Uint; Right : Int)  return Uint renames UI_Div;
336
337   function "*" (Left : Uint; Right : Uint) return Uint renames UI_Mul;
338   function "*" (Left : Int;  Right : Uint) return Uint renames UI_Mul;
339   function "*" (Left : Uint; Right : Int)  return Uint renames UI_Mul;
340
341   function "-" (Left : Uint; Right : Uint) return Uint renames UI_Sub;
342   function "-" (Left : Int;  Right : Uint) return Uint renames UI_Sub;
343   function "-" (Left : Uint; Right : Int)  return Uint renames UI_Sub;
344
345   function "**"  (Left : Uint; Right : Uint) return Uint renames UI_Expon;
346   function "**"  (Left : Uint; Right : Int)  return Uint renames UI_Expon;
347   function "**"  (Left : Int;  Right : Uint) return Uint renames UI_Expon;
348   function "**"  (Left : Int;  Right : Int)  return Uint renames UI_Expon;
349
350   function "abs" (Real : Uint) return Uint renames UI_Abs;
351
352   function "mod" (Left : Uint; Right : Uint) return Uint renames UI_Mod;
353   function "mod" (Left : Int;  Right : Uint) return Uint renames UI_Mod;
354   function "mod" (Left : Uint; Right : Int)  return Uint renames UI_Mod;
355
356   function "rem" (Left : Uint; Right : Uint) return Uint renames UI_Rem;
357   function "rem" (Left : Int;  Right : Uint) return Uint renames UI_Rem;
358   function "rem" (Left : Uint; Right : Int)  return Uint renames UI_Rem;
359
360   function "-"   (Real : Uint) return Uint renames UI_Negate;
361
362   function "="   (Left : Uint; Right : Uint) return Boolean renames UI_Eq;
363   function "="   (Left : Int;  Right : Uint) return Boolean renames UI_Eq;
364   function "="   (Left : Uint; Right : Int)  return Boolean renames UI_Eq;
365
366   function ">="  (Left : Uint; Right : Uint) return Boolean renames UI_Ge;
367   function ">="  (Left : Int;  Right : Uint) return Boolean renames UI_Ge;
368   function ">="  (Left : Uint; Right : Int)  return Boolean renames UI_Ge;
369
370   function ">"   (Left : Uint; Right : Uint) return Boolean renames UI_Gt;
371   function ">"   (Left : Int;  Right : Uint) return Boolean renames UI_Gt;
372   function ">"   (Left : Uint; Right : Int)  return Boolean renames UI_Gt;
373
374   function "<="  (Left : Uint; Right : Uint) return Boolean renames UI_Le;
375   function "<="  (Left : Int;  Right : Uint) return Boolean renames UI_Le;
376   function "<="  (Left : Uint; Right : Int)  return Boolean renames UI_Le;
377
378   function "<"   (Left : Uint; Right : Uint) return Boolean renames UI_Lt;
379   function "<"   (Left : Int;  Right : Uint) return Boolean renames UI_Lt;
380   function "<"   (Left : Uint; Right : Int)  return Boolean renames UI_Lt;
381
382   -----------------------------
383   -- Mark/Release Processing --
384   -----------------------------
385
386   --  The space used by Uint data is not automatically reclaimed. However, a
387   --  mark-release regime is implemented which allows storage to be released
388   --  back to a previously noted mark. This is used for example when doing
389   --  comparisons, where only intermediate results get stored that do not
390   --  need to be saved for future use.
391
392   type Save_Mark is private;
393
394   function Mark return Save_Mark;
395   --  Note mark point for future release
396
397   procedure Release (M : Save_Mark);
398   --  Release storage allocated since mark was noted
399
400   procedure Release_And_Save (M : Save_Mark; UI : in out Uint);
401   --  Like Release, except that the given Uint value (which is typically among
402   --  the data being released) is recopied after the release, so that it is
403   --  the most recent item, and UI is updated to point to its copied location.
404
405   procedure Release_And_Save (M : Save_Mark; UI1, UI2 : in out Uint);
406   --  Like Release, except that the given Uint values (which are typically
407   --  among the data being released) are recopied after the release, so that
408   --  they are the most recent items, and UI1 and UI2 are updated if necessary
409   --  to point to the copied locations. This routine is careful to do things
410   --  in the right order, so that the values do not clobber one another.
411
412   -----------------------------------
413   -- Representation of Uint Values --
414   -----------------------------------
415
416private
417
418   type Uint is new Int range Uint_Low_Bound .. Uint_High_Bound;
419   for Uint'Size use 32;
420
421   No_Uint : constant Uint := Uint (Uint_Low_Bound);
422
423   --  Uint values are represented as multiple precision integers stored in
424   --  a multi-digit format using Base as the base. This value is chosen so
425   --  that the product Base*Base is within the range of allowed Int values.
426
427   --  Base is defined to allow efficient execution of the primitive operations
428   --  (a0, b0, c0) defined in the section "The Classical Algorithms"
429   --  (sec. 4.3.1) of Donald Knuth's "The Art of Computer  Programming",
430   --  Vol. 2. These algorithms are used in this package. In particular,
431   --  the product of two single digits in this base fits in a 32-bit integer.
432
433   Base_Bits : constant := 15;
434   --  Number of bits in base value
435
436   Base : constant Int := 2 ** Base_Bits;
437
438   --  Values in the range -(Base-1) .. Max_Direct are encoded directly as
439   --  Uint values by adding a bias value. The value of Max_Direct is chosen
440   --  so that a directly represented number always fits in two digits when
441   --  represented in base format.
442
443   Min_Direct : constant Int := -(Base - 1);
444   Max_Direct : constant Int := (Base - 1) * (Base - 1);
445
446   --  The following values define the bias used to store Uint values which
447   --  are in this range, as well as the biased values for the first and last
448   --  values in this range. We use a new derived type for these constants to
449   --  avoid accidental use of Uint arithmetic on these values, which is never
450   --  correct.
451
452   type Ctrl is range Int'First .. Int'Last;
453
454   Uint_Direct_Bias  : constant Ctrl := Ctrl (Uint_Low_Bound) + Ctrl (Base);
455   Uint_Direct_First : constant Ctrl := Uint_Direct_Bias + Ctrl (Min_Direct);
456   Uint_Direct_Last  : constant Ctrl := Uint_Direct_Bias + Ctrl (Max_Direct);
457
458   Uint_0   : constant Uint := Uint (Uint_Direct_Bias);
459   Uint_1   : constant Uint := Uint (Uint_Direct_Bias + 1);
460   Uint_2   : constant Uint := Uint (Uint_Direct_Bias + 2);
461   Uint_3   : constant Uint := Uint (Uint_Direct_Bias + 3);
462   Uint_4   : constant Uint := Uint (Uint_Direct_Bias + 4);
463   Uint_5   : constant Uint := Uint (Uint_Direct_Bias + 5);
464   Uint_6   : constant Uint := Uint (Uint_Direct_Bias + 6);
465   Uint_7   : constant Uint := Uint (Uint_Direct_Bias + 7);
466   Uint_8   : constant Uint := Uint (Uint_Direct_Bias + 8);
467   Uint_9   : constant Uint := Uint (Uint_Direct_Bias + 9);
468   Uint_10  : constant Uint := Uint (Uint_Direct_Bias + 10);
469   Uint_11  : constant Uint := Uint (Uint_Direct_Bias + 11);
470   Uint_12  : constant Uint := Uint (Uint_Direct_Bias + 12);
471   Uint_13  : constant Uint := Uint (Uint_Direct_Bias + 13);
472   Uint_14  : constant Uint := Uint (Uint_Direct_Bias + 14);
473   Uint_15  : constant Uint := Uint (Uint_Direct_Bias + 15);
474   Uint_16  : constant Uint := Uint (Uint_Direct_Bias + 16);
475   Uint_24  : constant Uint := Uint (Uint_Direct_Bias + 24);
476   Uint_32  : constant Uint := Uint (Uint_Direct_Bias + 32);
477   Uint_63  : constant Uint := Uint (Uint_Direct_Bias + 63);
478   Uint_64  : constant Uint := Uint (Uint_Direct_Bias + 64);
479   Uint_80  : constant Uint := Uint (Uint_Direct_Bias + 80);
480   Uint_128 : constant Uint := Uint (Uint_Direct_Bias + 128);
481
482   Uint_Minus_1   : constant Uint := Uint (Uint_Direct_Bias - 1);
483   Uint_Minus_2   : constant Uint := Uint (Uint_Direct_Bias - 2);
484   Uint_Minus_3   : constant Uint := Uint (Uint_Direct_Bias - 3);
485   Uint_Minus_4   : constant Uint := Uint (Uint_Direct_Bias - 4);
486   Uint_Minus_5   : constant Uint := Uint (Uint_Direct_Bias - 5);
487   Uint_Minus_6   : constant Uint := Uint (Uint_Direct_Bias - 6);
488   Uint_Minus_7   : constant Uint := Uint (Uint_Direct_Bias - 7);
489   Uint_Minus_8   : constant Uint := Uint (Uint_Direct_Bias - 8);
490   Uint_Minus_9   : constant Uint := Uint (Uint_Direct_Bias - 9);
491   Uint_Minus_12  : constant Uint := Uint (Uint_Direct_Bias - 12);
492   Uint_Minus_36  : constant Uint := Uint (Uint_Direct_Bias - 36);
493   Uint_Minus_63  : constant Uint := Uint (Uint_Direct_Bias - 63);
494   Uint_Minus_80  : constant Uint := Uint (Uint_Direct_Bias - 80);
495   Uint_Minus_128 : constant Uint := Uint (Uint_Direct_Bias - 128);
496
497   Uint_Max_Simple_Mul : constant := Uint_Direct_Bias + 2 ** 15;
498   --  If two values are directly represented and less than or equal to this
499   --  value, then we know the product fits in a 32-bit integer. This allows
500   --  UI_Mul to efficiently compute the product in this case.
501
502   type Save_Mark is record
503      Save_Uint   : Uint;
504      Save_Udigit : Int;
505   end record;
506
507   --  Values outside the range that is represented directly are stored using
508   --  two tables. The secondary table Udigits contains sequences of Int values
509   --  consisting of the digits of the number in a radix Base system. The
510   --  digits are stored from most significant to least significant with the
511   --  first digit only carrying the sign.
512
513   --  There is one entry in the primary Uints table for each distinct Uint
514   --  value. This table entry contains the length (number of digits) and
515   --  a starting offset of the value in the Udigits table.
516
517   Uint_First_Entry : constant Uint := Uint (Uint_Table_Start);
518
519   --  Some subprograms defined in this package manipulate the Udigits table
520   --  directly, while for others it is more convenient to work with locally
521   --  defined arrays of the digits of the Universal Integers. The type
522   --  UI_Vector is defined for this purpose and some internal subprograms
523   --  used for converting from one to the other are defined.
524
525   type Uint_Entry is record
526      Length : Pos;
527      --  Length of entry in Udigits table in digits (i.e. in words)
528
529      Loc : Int;
530      --  Starting location in Udigits table of this Uint value
531   end record;
532
533   package Uints is new Table.Table (
534     Table_Component_Type => Uint_Entry,
535     Table_Index_Type     => Uint'Base,
536     Table_Low_Bound      => Uint_First_Entry,
537     Table_Initial        => Alloc.Uints_Initial,
538     Table_Increment      => Alloc.Uints_Increment,
539     Table_Name           => "Uints");
540
541   package Udigits is new Table.Table (
542     Table_Component_Type => Int,
543     Table_Index_Type     => Int,
544     Table_Low_Bound      => 0,
545     Table_Initial        => Alloc.Udigits_Initial,
546     Table_Increment      => Alloc.Udigits_Increment,
547     Table_Name           => "Udigits");
548
549   --  Note: the reason these tables are defined here in the private part of
550   --  the spec, rather than in the body, is that they are referenced directly
551   --  by gigi.
552
553end Uintp;
554