Debian Codegraph @

gcc/ada/libgnat/s-pack121.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . P A C K _ 1 2 1 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 with System.Address_To_Access_Conversions;
33 with System.Storage_Elements;
34 with System.Unsigned_Types;
35
36 package body System.Pack_121 is
37
38 -- The high-level idea of the implementation is to overlay a record
39 -- containing components of the same size as that of the component
40 -- of the array, in order words 121 bits, and to access the indexed
41 -- component of the array through the appropriate selected component
42 -- of the record.
43
44 -- The record must be of a fixed size for technical reasons, so we
45 -- effectively overlay a series of contiguous records containing 8
46 -- components (so that their size in bits is a multiple of a byte)
47 -- at the start of the array and access the component in the last
48 -- of them. However, this component in the last record may also be
49 -- mapped to the last component of the array, which means that the
50 -- generated code cannot safely access past it (or its last byte).
51 -- That's why the last record of the series is shortened, so the
52 -- accessed component is always the last component of the record.
53
54 -- A (0) A (N)
55 -- | |
56 -- V V
57 -- ---------------------------------------------------------------
58 -- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
59 -- ---------------------------------------------------------------
60 --
61 -- component K
62 -- |
63 -- V
64 -- ---------------------------------------------------------
65 -- | | | | |
66 -- ---------------------------------------------------------
67 -- | | | |
68 -- Cluster7 Cluster7 Cluster7 ClusterK
69 --
70 -- where the number of Cluster7 is N / 8 and K is N mod 8.
71
72 subtype Bit_Order is System.Bit_Order;
73 Reverse_Bit_Order : constant Bit_Order :=
74 Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
75
76 subtype Ofs is System.Storage_Elements.Storage_Offset;
77 subtype Uns is System.Unsigned_Types.Unsigned;
78 subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
79
80 use type System.Storage_Elements.Storage_Offset;
81 use type System.Unsigned_Types.Unsigned;
82
83 --------------
84 -- Cluster0 --
85 --------------
86
87 type Cluster0 is record
88 E0 : Bits_121;
89 end record;
90
91 for Cluster0 use record
92 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
93 end record;
94
95 for Cluster0'Size use Bits * (1 + 0);
96
97 for Cluster0'Alignment use Integer'Min (Standard'Maximum_Alignment,
98 1 +
99 1 * Boolean'Pos (Bits mod 2 = 0) +
100 2 * Boolean'Pos (Bits mod 4 = 0));
101 -- Use maximum possible alignment, given the bit field size, since this
102 -- will result in the most efficient code possible for the field.
103
104 package AAC0 is new Address_To_Access_Conversions (Cluster0);
105 -- We convert addresses to access values and dereference them instead of
106 -- directly using overlays in order to work around the implementation of
107 -- the RM 13.3(19) clause, which would pessimize the generated code.
108
109 type Rev_Cluster0 is new Cluster0
110 with Bit_Order => Reverse_Bit_Order,
111 Scalar_Storage_Order => Reverse_Bit_Order;
112
113 package Rev_AAC0 is new Address_To_Access_Conversions (Rev_Cluster0);
114
115 --------------
116 -- Cluster1 --
117 --------------
118
119 type Cluster1 is record
120 E0, E1 : Bits_121;
121 end record;
122
123 for Cluster1 use record
124 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
125 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
126 end record;
127
128 for Cluster1'Size use Bits * (1 + 1);
129
130 for Cluster1'Alignment use Integer'Min (Standard'Maximum_Alignment,
131 1 +
132 1 * Boolean'Pos (Bits mod 2 = 0) +
133 2 * Boolean'Pos (Bits mod 4 = 0));
134 -- Use maximum possible alignment, given the bit field size, since this
135 -- will result in the most efficient code possible for the field.
136
137 package AAC1 is new Address_To_Access_Conversions (Cluster1);
138 -- We convert addresses to access values and dereference them instead of
139 -- directly using overlays in order to work around the implementation of
140 -- the RM 13.3(19) clause, which would pessimize the generated code.
141
142 type Rev_Cluster1 is new Cluster1
143 with Bit_Order => Reverse_Bit_Order,
144 Scalar_Storage_Order => Reverse_Bit_Order;
145
146 package Rev_AAC1 is new Address_To_Access_Conversions (Rev_Cluster1);
147
148 --------------
149 -- Cluster2 --
150 --------------
151
152 type Cluster2 is record
153 E0, E1, E2 : Bits_121;
154 end record;
155
156 for Cluster2 use record
157 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
158 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
159 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
160 end record;
161
162 for Cluster2'Size use Bits * (1 + 2);
163
164 for Cluster2'Alignment use Integer'Min (Standard'Maximum_Alignment,
165 1 +
166 1 * Boolean'Pos (Bits mod 2 = 0) +
167 2 * Boolean'Pos (Bits mod 4 = 0));
168 -- Use maximum possible alignment, given the bit field size, since this
169 -- will result in the most efficient code possible for the field.
170
171 package AAC2 is new Address_To_Access_Conversions (Cluster2);
172 -- We convert addresses to access values and dereference them instead of
173 -- directly using overlays in order to work around the implementation of
174 -- the RM 13.3(19) clause, which would pessimize the generated code.
175
176 type Rev_Cluster2 is new Cluster2
177 with Bit_Order => Reverse_Bit_Order,
178 Scalar_Storage_Order => Reverse_Bit_Order;
179
180 package Rev_AAC2 is new Address_To_Access_Conversions (Rev_Cluster2);
181
182 --------------
183 -- Cluster3 --
184 --------------
185
186 type Cluster3 is record
187 E0, E1, E2, E3 : Bits_121;
188 end record;
189
190 for Cluster3 use record
191 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
192 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
193 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
194 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
195 end record;
196
197 for Cluster3'Size use Bits * (1 + 3);
198
199 for Cluster3'Alignment use Integer'Min (Standard'Maximum_Alignment,
200 1 +
201 1 * Boolean'Pos (Bits mod 2 = 0) +
202 2 * Boolean'Pos (Bits mod 4 = 0));
203 -- Use maximum possible alignment, given the bit field size, since this
204 -- will result in the most efficient code possible for the field.
205
206 package AAC3 is new Address_To_Access_Conversions (Cluster3);
207 -- We convert addresses to access values and dereference them instead of
208 -- directly using overlays in order to work around the implementation of
209 -- the RM 13.3(19) clause, which would pessimize the generated code.
210
211 type Rev_Cluster3 is new Cluster3
212 with Bit_Order => Reverse_Bit_Order,
213 Scalar_Storage_Order => Reverse_Bit_Order;
214
215 package Rev_AAC3 is new Address_To_Access_Conversions (Rev_Cluster3);
216
217 --------------
218 -- Cluster4 --
219 --------------
220
221 type Cluster4 is record
222 E0, E1, E2, E3, E4 : Bits_121;
223 end record;
224
225 for Cluster4 use record
226 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
227 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
228 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
229 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
230 E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
231 end record;
232
233 for Cluster4'Size use Bits * (1 + 4);
234
235 for Cluster4'Alignment use Integer'Min (Standard'Maximum_Alignment,
236 1 +
237 1 * Boolean'Pos (Bits mod 2 = 0) +
238 2 * Boolean'Pos (Bits mod 4 = 0));
239 -- Use maximum possible alignment, given the bit field size, since this
240 -- will result in the most efficient code possible for the field.
241
242 package AAC4 is new Address_To_Access_Conversions (Cluster4);
243 -- We convert addresses to access values and dereference them instead of
244 -- directly using overlays in order to work around the implementation of
245 -- the RM 13.3(19) clause, which would pessimize the generated code.
246
247 type Rev_Cluster4 is new Cluster4
248 with Bit_Order => Reverse_Bit_Order,
249 Scalar_Storage_Order => Reverse_Bit_Order;
250
251 package Rev_AAC4 is new Address_To_Access_Conversions (Rev_Cluster4);
252
253 --------------
254 -- Cluster5 --
255 --------------
256
257 type Cluster5 is record
258 E0, E1, E2, E3, E4, E5 : Bits_121;
259 end record;
260
261 for Cluster5 use record
262 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
263 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
264 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
265 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
266 E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
267 E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
268 end record;
269
270 for Cluster5'Size use Bits * (1 + 5);
271
272 for Cluster5'Alignment use Integer'Min (Standard'Maximum_Alignment,
273 1 +
274 1 * Boolean'Pos (Bits mod 2 = 0) +
275 2 * Boolean'Pos (Bits mod 4 = 0));
276 -- Use maximum possible alignment, given the bit field size, since this
277 -- will result in the most efficient code possible for the field.
278
279 package AAC5 is new Address_To_Access_Conversions (Cluster5);
280 -- We convert addresses to access values and dereference them instead of
281 -- directly using overlays in order to work around the implementation of
282 -- the RM 13.3(19) clause, which would pessimize the generated code.
283
284 type Rev_Cluster5 is new Cluster5
285 with Bit_Order => Reverse_Bit_Order,
286 Scalar_Storage_Order => Reverse_Bit_Order;
287
288 package Rev_AAC5 is new Address_To_Access_Conversions (Rev_Cluster5);
289
290 --------------
291 -- Cluster6 --
292 --------------
293
294 type Cluster6 is record
295 E0, E1, E2, E3, E4, E5, E6 : Bits_121;
296 end record;
297
298 for Cluster6 use record
299 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
300 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
301 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
302 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
303 E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
304 E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
305 E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
306 end record;
307
308 for Cluster6'Size use Bits * (1 + 6);
309
310 for Cluster6'Alignment use Integer'Min (Standard'Maximum_Alignment,
311 1 +
312 1 * Boolean'Pos (Bits mod 2 = 0) +
313 2 * Boolean'Pos (Bits mod 4 = 0));
314 -- Use maximum possible alignment, given the bit field size, since this
315 -- will result in the most efficient code possible for the field.
316
317 package AAC6 is new Address_To_Access_Conversions (Cluster6);
318 -- We convert addresses to access values and dereference them instead of
319 -- directly using overlays in order to work around the implementation of
320 -- the RM 13.3(19) clause, which would pessimize the generated code.
321
322 type Rev_Cluster6 is new Cluster6
323 with Bit_Order => Reverse_Bit_Order,
324 Scalar_Storage_Order => Reverse_Bit_Order;
325
326 package Rev_AAC6 is new Address_To_Access_Conversions (Rev_Cluster6);
327
328 --------------
329 -- Cluster7 --
330 --------------
331
332 type Cluster7 is record
333 E0, E1, E2, E3, E4, E5, E6, E7 : Bits_121;
334 end record;
335
336 for Cluster7 use record
337 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
338 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
339 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
340 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
341 E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
342 E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
343 E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
344 E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
345 end record;
346
347 for Cluster7'Size use Bits * (1 + 7);
348
349 for Cluster7'Alignment use Integer'Min (Standard'Maximum_Alignment,
350 1 +
351 1 * Boolean'Pos (Bits mod 2 = 0) +
352 2 * Boolean'Pos (Bits mod 4 = 0));
353 -- Use maximum possible alignment, given the bit field size, since this
354 -- will result in the most efficient code possible for the field.
355
356 package AAC7 is new Address_To_Access_Conversions (Cluster7);
357 -- We convert addresses to access values and dereference them instead of
358 -- directly using overlays in order to work around the implementation of
359 -- the RM 13.3(19) clause, which would pessimize the generated code.
360
361 type Rev_Cluster7 is new Cluster7
362 with Bit_Order => Reverse_Bit_Order,
363 Scalar_Storage_Order => Reverse_Bit_Order;
364
365 package Rev_AAC7 is new Address_To_Access_Conversions (Rev_Cluster7);
366
367 ------------
368 -- Get_121 --
369 ------------
370
371 function Get_121
372 (Arr : System.Address;
373 N : Natural;
374 Rev_SSO : Boolean) return Bits_121
375 is
376 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
377 C0 : constant AAC0.Object_Pointer := AAC0.To_Pointer (A);
378 C1 : constant AAC1.Object_Pointer := AAC1.To_Pointer (A);
379 C2 : constant AAC2.Object_Pointer := AAC2.To_Pointer (A);
380 C3 : constant AAC3.Object_Pointer := AAC3.To_Pointer (A);
381 C4 : constant AAC4.Object_Pointer := AAC4.To_Pointer (A);
382 C5 : constant AAC5.Object_Pointer := AAC5.To_Pointer (A);
383 C6 : constant AAC6.Object_Pointer := AAC6.To_Pointer (A);
384 C7 : constant AAC7.Object_Pointer := AAC7.To_Pointer (A);
385 RC0 : constant Rev_AAC0.Object_Pointer := Rev_AAC0.To_Pointer (A);
386 RC1 : constant Rev_AAC1.Object_Pointer := Rev_AAC1.To_Pointer (A);
387 RC2 : constant Rev_AAC2.Object_Pointer := Rev_AAC2.To_Pointer (A);
388 RC3 : constant Rev_AAC3.Object_Pointer := Rev_AAC3.To_Pointer (A);
389 RC4 : constant Rev_AAC4.Object_Pointer := Rev_AAC4.To_Pointer (A);
390 RC5 : constant Rev_AAC5.Object_Pointer := Rev_AAC5.To_Pointer (A);
391 RC6 : constant Rev_AAC6.Object_Pointer := Rev_AAC6.To_Pointer (A);
392 RC7 : constant Rev_AAC7.Object_Pointer := Rev_AAC7.To_Pointer (A);
393
394 begin
395 return
396 (if Rev_SSO then
397 (case N07 (Uns (N) mod 8) is
398 when 0 => RC0.E0,
399 when 1 => RC1.E1,
400 when 2 => RC2.E2,
401 when 3 => RC3.E3,
402 when 4 => RC4.E4,
403 when 5 => RC5.E5,
404 when 6 => RC6.E6,
405 when 7 => RC7.E7)
406
407 else
408 (case N07 (Uns (N) mod 8) is
409 when 0 => C0.E0,
410 when 1 => C1.E1,
411 when 2 => C2.E2,
412 when 3 => C3.E3,
413 when 4 => C4.E4,
414 when 5 => C5.E5,
415 when 6 => C6.E6,
416 when 7 => C7.E7)
417 );
418 end Get_121;
419
420 ------------
421 -- Set_121 --
422 ------------
423
424 procedure Set_121
425 (Arr : System.Address;
426 N : Natural;
427 E : Bits_121;
428 Rev_SSO : Boolean)
429 is
430 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
431 C0 : constant AAC0.Object_Pointer := AAC0.To_Pointer (A);
432 C1 : constant AAC1.Object_Pointer := AAC1.To_Pointer (A);
433 C2 : constant AAC2.Object_Pointer := AAC2.To_Pointer (A);
434 C3 : constant AAC3.Object_Pointer := AAC3.To_Pointer (A);
435 C4 : constant AAC4.Object_Pointer := AAC4.To_Pointer (A);
436 C5 : constant AAC5.Object_Pointer := AAC5.To_Pointer (A);
437 C6 : constant AAC6.Object_Pointer := AAC6.To_Pointer (A);
438 C7 : constant AAC7.Object_Pointer := AAC7.To_Pointer (A);
439 RC0 : constant Rev_AAC0.Object_Pointer := Rev_AAC0.To_Pointer (A);
440 RC1 : constant Rev_AAC1.Object_Pointer := Rev_AAC1.To_Pointer (A);
441 RC2 : constant Rev_AAC2.Object_Pointer := Rev_AAC2.To_Pointer (A);
442 RC3 : constant Rev_AAC3.Object_Pointer := Rev_AAC3.To_Pointer (A);
443 RC4 : constant Rev_AAC4.Object_Pointer := Rev_AAC4.To_Pointer (A);
444 RC5 : constant Rev_AAC5.Object_Pointer := Rev_AAC5.To_Pointer (A);
445 RC6 : constant Rev_AAC6.Object_Pointer := Rev_AAC6.To_Pointer (A);
446 RC7 : constant Rev_AAC7.Object_Pointer := Rev_AAC7.To_Pointer (A);
447
448 begin
449 if Rev_SSO then
450 case N07 (Uns (N) mod 8) is
451 when 0 => RC0.E0 := E;
452 when 1 => RC1.E1 := E;
453 when 2 => RC2.E2 := E;
454 when 3 => RC3.E3 := E;
455 when 4 => RC4.E4 := E;
456 when 5 => RC5.E5 := E;
457 when 6 => RC6.E6 := E;
458 when 7 => RC7.E7 := E;
459 end case;
460 else
461 case N07 (Uns (N) mod 8) is
462 when 0 => C0.E0 := E;
463 when 1 => C1.E1 := E;
464 when 2 => C2.E2 := E;
465 when 3 => C3.E3 := E;
466 when 4 => C4.E4 := E;
467 when 5 => C5.E5 := E;
468 when 6 => C6.E6 := E;
469 when 7 => C7.E7 := E;
470 end case;
471 end if;
472 end Set_121;
473
474 end System.Pack_121;