Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / s-pack44.adb
blobfa6390e8aceab9170af26551004d63be8fadf56a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . P A C K _ 4 4 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2023, 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 ------------------------------------------------------------------------------
32 with System.Storage_Elements;
33 with System.Unsigned_Types;
35 package body System.Pack_44 is
37 subtype Bit_Order is System.Bit_Order;
38 Reverse_Bit_Order : constant Bit_Order :=
39 Bit_Order'Val (1 - Bit_Order'Pos (System.Default_Bit_Order));
41 subtype Ofs is System.Storage_Elements.Storage_Offset;
42 subtype Uns is System.Unsigned_Types.Unsigned;
43 subtype N07 is System.Unsigned_Types.Unsigned range 0 .. 7;
45 use type System.Storage_Elements.Storage_Offset;
46 use type System.Unsigned_Types.Unsigned;
48 type Cluster is record
49 E0, E1, E2, E3, E4, E5, E6, E7 : Bits_44;
50 end record;
52 for Cluster use record
53 E0 at 0 range 0 * Bits .. 0 * Bits + Bits - 1;
54 E1 at 0 range 1 * Bits .. 1 * Bits + Bits - 1;
55 E2 at 0 range 2 * Bits .. 2 * Bits + Bits - 1;
56 E3 at 0 range 3 * Bits .. 3 * Bits + Bits - 1;
57 E4 at 0 range 4 * Bits .. 4 * Bits + Bits - 1;
58 E5 at 0 range 5 * Bits .. 5 * Bits + Bits - 1;
59 E6 at 0 range 6 * Bits .. 6 * Bits + Bits - 1;
60 E7 at 0 range 7 * Bits .. 7 * Bits + Bits - 1;
61 end record;
63 for Cluster'Size use Bits * 8;
65 for Cluster'Alignment use Integer'Min (Standard'Maximum_Alignment,
66 1 +
67 1 * Boolean'Pos (Bits mod 2 = 0) +
68 2 * Boolean'Pos (Bits mod 4 = 0));
69 -- Use maximum possible alignment, given the bit field size, since this
70 -- will result in the most efficient code possible for the field.
72 type Cluster_Ref is access Cluster;
74 type Rev_Cluster is new Cluster
75 with Bit_Order => Reverse_Bit_Order,
76 Scalar_Storage_Order => Reverse_Bit_Order;
77 type Rev_Cluster_Ref is access Rev_Cluster;
79 -- The following declarations are for the case where the address
80 -- passed to GetU_44 or SetU_44 is not guaranteed to be aligned.
81 -- These routines are used when the packed array is itself a
82 -- component of a packed record, and therefore may not be aligned.
84 type ClusterU is new Cluster;
85 for ClusterU'Alignment use 1;
87 type ClusterU_Ref is access ClusterU;
89 type Rev_ClusterU is new ClusterU
90 with Bit_Order => Reverse_Bit_Order,
91 Scalar_Storage_Order => Reverse_Bit_Order;
92 type Rev_ClusterU_Ref is access Rev_ClusterU;
94 ------------
95 -- Get_44 --
96 ------------
98 function Get_44
99 (Arr : System.Address;
100 N : Natural;
101 Rev_SSO : Boolean) return Bits_44
103 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
104 C : Cluster_Ref with Address => A'Address, Import;
105 RC : Rev_Cluster_Ref with Address => A'Address, Import;
106 begin
107 return
108 (if Rev_SSO then
109 (case N07 (Uns (N) mod 8) is
110 when 0 => RC.E0,
111 when 1 => RC.E1,
112 when 2 => RC.E2,
113 when 3 => RC.E3,
114 when 4 => RC.E4,
115 when 5 => RC.E5,
116 when 6 => RC.E6,
117 when 7 => RC.E7)
119 else
120 (case N07 (Uns (N) mod 8) is
121 when 0 => C.E0,
122 when 1 => C.E1,
123 when 2 => C.E2,
124 when 3 => C.E3,
125 when 4 => C.E4,
126 when 5 => C.E5,
127 when 6 => C.E6,
128 when 7 => C.E7)
130 end Get_44;
132 -------------
133 -- GetU_44 --
134 -------------
136 function GetU_44
137 (Arr : System.Address;
138 N : Natural;
139 Rev_SSO : Boolean) return Bits_44
141 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
142 C : ClusterU_Ref with Address => A'Address, Import;
143 RC : Rev_ClusterU_Ref with Address => A'Address, Import;
144 begin
145 return
146 (if Rev_SSO then
147 (case N07 (Uns (N) mod 8) is
148 when 0 => RC.E0,
149 when 1 => RC.E1,
150 when 2 => RC.E2,
151 when 3 => RC.E3,
152 when 4 => RC.E4,
153 when 5 => RC.E5,
154 when 6 => RC.E6,
155 when 7 => RC.E7)
157 else
158 (case N07 (Uns (N) mod 8) is
159 when 0 => C.E0,
160 when 1 => C.E1,
161 when 2 => C.E2,
162 when 3 => C.E3,
163 when 4 => C.E4,
164 when 5 => C.E5,
165 when 6 => C.E6,
166 when 7 => C.E7)
168 end GetU_44;
170 ------------
171 -- Set_44 --
172 ------------
174 procedure Set_44
175 (Arr : System.Address;
176 N : Natural;
177 E : Bits_44;
178 Rev_SSO : Boolean)
180 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
181 C : Cluster_Ref with Address => A'Address, Import;
182 RC : Rev_Cluster_Ref with Address => A'Address, Import;
183 begin
184 if Rev_SSO then
185 case N07 (Uns (N) mod 8) is
186 when 0 => RC.E0 := E;
187 when 1 => RC.E1 := E;
188 when 2 => RC.E2 := E;
189 when 3 => RC.E3 := E;
190 when 4 => RC.E4 := E;
191 when 5 => RC.E5 := E;
192 when 6 => RC.E6 := E;
193 when 7 => RC.E7 := E;
194 end case;
195 else
196 case N07 (Uns (N) mod 8) is
197 when 0 => C.E0 := E;
198 when 1 => C.E1 := E;
199 when 2 => C.E2 := E;
200 when 3 => C.E3 := E;
201 when 4 => C.E4 := E;
202 when 5 => C.E5 := E;
203 when 6 => C.E6 := E;
204 when 7 => C.E7 := E;
205 end case;
206 end if;
207 end Set_44;
209 -------------
210 -- SetU_44 --
211 -------------
213 procedure SetU_44
214 (Arr : System.Address;
215 N : Natural;
216 E : Bits_44;
217 Rev_SSO : Boolean)
219 A : constant System.Address := Arr + Bits * Ofs (Uns (N) / 8);
220 C : ClusterU_Ref with Address => A'Address, Import;
221 RC : Rev_ClusterU_Ref with Address => A'Address, Import;
222 begin
223 if Rev_SSO then
224 case N07 (Uns (N) mod 8) is
225 when 0 => RC.E0 := E;
226 when 1 => RC.E1 := E;
227 when 2 => RC.E2 := E;
228 when 3 => RC.E3 := E;
229 when 4 => RC.E4 := E;
230 when 5 => RC.E5 := E;
231 when 6 => RC.E6 := E;
232 when 7 => RC.E7 := E;
233 end case;
234 else
235 case N07 (Uns (N) mod 8) is
236 when 0 => C.E0 := E;
237 when 1 => C.E1 := E;
238 when 2 => C.E2 := E;
239 when 3 => C.E3 := E;
240 when 4 => C.E4 := E;
241 when 5 => C.E5 := E;
242 when 6 => C.E6 := E;
243 when 7 => C.E7 := E;
244 end case;
245 end if;
246 end SetU_44;
248 end System.Pack_44;