annotate gcc/ada/uintp.ads @ 131:84e7813d76e9

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