Debian Codegraph @

gcc/ada/libgnat/s-scaval__128.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . S C A L A R _ V A L U E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2003-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 Ada.Unchecked_Conversion;
33
34 package body System.Scalar_Values is
35
36 use Interfaces;
37
38 ----------------
39 -- Initialize --
40 ----------------
41
42 procedure Initialize (Mode1 : Character; Mode2 : Character) is
43 C1 : Character := Mode1;
44 C2 : Character := Mode2;
45
46 procedure Get_Env_Value_Ptr (Name, Length, Ptr : Address);
47 pragma Import (C, Get_Env_Value_Ptr, "__gnat_getenv");
48
49 subtype String2 is String (1 .. 2);
50 type String2_Ptr is access all String2;
51
52 Env_Value_Ptr : aliased String2_Ptr;
53 Env_Value_Length : aliased Integer;
54
55 EV_Val : aliased constant String :=
56 "GNAT_INIT_SCALARS" & ASCII.NUL;
57
58 B : Byte1;
59
60 EFloat : constant Boolean := Long_Long_Float'Size > Long_Float'Size;
61 -- Set True if we are on an x86 with 96-bit floats for extended
62
63 type ByteLF is array (0 .. 7) of Byte1;
64
65 for ByteLF'Component_Size use 8;
66 function To_ByteLF is new Ada.Unchecked_Conversion (Byte8, ByteLF);
67
68 type ByteLLF is array (0 .. 7 + 4 * Boolean'Pos (EFloat)) of Byte1;
69
70 for ByteLLF'Component_Size use 8;
71
72 -- Type used to initialize Long_Long_Float values used on x86 and
73 -- any other target with the same 80-bit floating-point values that
74 -- GCC always stores in 96-bits. Note that we are assuming Intel
75 -- format little-endian addressing for this type. On non-Intel
76 -- architectures, this is the same length as Byte8 and holds
77 -- a Long_Float value.
78
79 -- The following variables are used to initialize the float values
80 -- by overlay. We can't assign directly to the float values, since
81 -- we may be assigning signalling Nan's that will cause a trap if
82 -- loaded into a floating-point register.
83
84 IV_Isf : aliased Byte4; -- Initialize short float
85 IV_Ifl : aliased Byte4; -- Initialize float
86 IV_Ilf : aliased ByteLF; -- Initialize long float
87 IV_Ill : aliased ByteLLF; -- Initialize long long float
88
89 for IV_Isf'Address use IS_Isf'Address;
90 for IV_Ifl'Address use IS_Ifl'Address;
91 for IV_Ilf'Address use IS_Ilf'Address;
92 for IV_Ill'Address use IS_Ill'Address;
93
94 -- The following pragmas are used to suppress initialization
95
96 pragma Import (Ada, IV_Isf);
97 pragma Import (Ada, IV_Ifl);
98 pragma Import (Ada, IV_Ilf);
99 pragma Import (Ada, IV_Ill);
100
101 begin
102 -- Acquire environment variable value if necessary
103
104 if C1 = 'E' and then C2 = 'V' then
105 Get_Env_Value_Ptr
106 (EV_Val'Address, Env_Value_Length'Address, Env_Value_Ptr'Address);
107
108 -- Ignore if length is not 2
109
110 if Env_Value_Length /= 2 then
111 C1 := 'I';
112 C2 := 'N';
113
114 -- Length is 2, see if it is a valid value
115
116 else
117 -- Acquire two characters and fold to upper case
118
119 C1 := Env_Value_Ptr (1);
120 C2 := Env_Value_Ptr (2);
121
122 if C1 in 'a' .. 'z' then
123 C1 := Character'Val (Character'Pos (C1) - 32);
124 end if;
125
126 if C2 in 'a' .. 'z' then
127 C2 := Character'Val (Character'Pos (C2) - 32);
128 end if;
129
130 -- IN/LO/HI are ok values
131
132 if (C1 = 'I' and then C2 = 'N')
133 or else
134 (C1 = 'L' and then C2 = 'O')
135 or else
136 (C1 = 'H' and then C2 = 'I')
137 then
138 null;
139
140 -- Try for valid hex digits
141
142 elsif (C1 in '0' .. '9' or else C1 in 'A' .. 'Z')
143 or else
144 (C2 in '0' .. '9' or else C2 in 'A' .. 'Z')
145 then
146 null;
147
148 -- Otherwise environment value is bad, ignore and use IN (invalid)
149
150 else
151 C1 := 'I';
152 C2 := 'N';
153 end if;
154 end if;
155 end if;
156
157 -- IN (invalid value)
158
159 if C1 = 'I' and then C2 = 'N' then
160 IS_Is1 := 16#80#;
161 IS_Is2 := 16#8000#;
162 IS_Is4 := 16#8000_0000#;
163 IS_Is8 := 16#8000_0000_0000_0000#;
164 IS_Is16 := 16#8000_0000_0000_0000_0000_0000_0000_0000#;
165
166 IS_Iu1 := 16#FF#;
167 IS_Iu2 := 16#FFFF#;
168 IS_Iu4 := 16#FFFF_FFFF#;
169 IS_Iu8 := 16#FFFF_FFFF_FFFF_FFFF#;
170 IS_Iu16 := 16#FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF#;
171
172 IS_Iz1 := 16#00#;
173 IS_Iz2 := 16#0000#;
174 IS_Iz4 := 16#0000_0000#;
175 IS_Iz8 := 16#0000_0000_0000_0000#;
176 IS_Iz16 := 16#0000_0000_0000_0000_0000_0000_0000_0000#;
177
178 IV_Isf := IS_Iu4;
179 IV_Ifl := IS_Iu4;
180 IV_Ilf := To_ByteLF (IS_Iu8);
181
182 if EFloat then
183 IV_Ill := [0, 0, 0, 0, 0, 0, 0, 16#C0#, 16#FF#, 16#FF#, 0, 0];
184 end if;
185
186 -- LO (Low values)
187
188 elsif C1 = 'L' and then C2 = 'O' then
189 IS_Is1 := 16#80#;
190 IS_Is2 := 16#8000#;
191 IS_Is4 := 16#8000_0000#;
192 IS_Is8 := 16#8000_0000_0000_0000#;
193 IS_Is16 := 16#8000_0000_0000_0000_0000_0000_0000_0000#;
194
195 IS_Iu1 := 16#00#;
196 IS_Iu2 := 16#0000#;
197 IS_Iu4 := 16#0000_0000#;
198 IS_Iu8 := 16#0000_0000_0000_0000#;
199 IS_Iu16 := 16#0000_0000_0000_0000_0000_0000_0000_0000#;
200
201 IS_Iz1 := 16#00#;
202 IS_Iz2 := 16#0000#;
203 IS_Iz4 := 16#0000_0000#;
204 IS_Iz8 := 16#0000_0000_0000_0000#;
205 IS_Iz16 := 16#0000_0000_0000_0000_0000_0000_0000_0000#;
206
207 IV_Isf := 16#FF80_0000#;
208 IV_Ifl := 16#FF80_0000#;
209 IV_Ilf := To_ByteLF (16#FFF0_0000_0000_0000#);
210
211 if EFloat then
212 IV_Ill := [0, 0, 0, 0, 0, 0, 0, 16#80#, 16#FF#, 16#FF#, 0, 0];
213 end if;
214
215 -- HI (High values)
216
217 elsif C1 = 'H' and then C2 = 'I' then
218 IS_Is1 := 16#7F#;
219 IS_Is2 := 16#7FFF#;
220 IS_Is4 := 16#7FFF_FFFF#;
221 IS_Is8 := 16#7FFF_FFFF_FFFF_FFFF#;
222 IS_Is16 := 16#7FFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF#;
223
224 IS_Iu1 := 16#FF#;
225 IS_Iu2 := 16#FFFF#;
226 IS_Iu4 := 16#FFFF_FFFF#;
227 IS_Iu8 := 16#FFFF_FFFF_FFFF_FFFF#;
228 IS_Iu16 := 16#FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF#;
229
230 IS_Iz1 := 16#FF#;
231 IS_Iz2 := 16#FFFF#;
232 IS_Iz4 := 16#FFFF_FFFF#;
233 IS_Iz8 := 16#FFFF_FFFF_FFFF_FFFF#;
234 IS_Iz16 := 16#FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF#;
235
236 IV_Isf := 16#7F80_0000#;
237 IV_Ifl := 16#7F80_0000#;
238 IV_Ilf := To_ByteLF (16#7FF0_0000_0000_0000#);
239
240 if EFloat then
241 IV_Ill := [0, 0, 0, 0, 0, 0, 0, 16#80#, 16#FF#, 16#7F#, 0, 0];
242 end if;
243
244 -- -Shh (hex byte)
245
246 else
247 -- Convert the two hex digits (we know they are valid here)
248
249 B := 16 * (Character'Pos (C1)
250 - (if C1 in '0' .. '9'
251 then Character'Pos ('0')
252 else Character'Pos ('A') - 10))
253 + (Character'Pos (C2)
254 - (if C2 in '0' .. '9'
255 then Character'Pos ('0')
256 else Character'Pos ('A') - 10));
257
258 -- Initialize data values from the hex value
259
260 IS_Is1 := B;
261 IS_Is2 := 2**8 * Byte2 (IS_Is1) + Byte2 (IS_Is1);
262 IS_Is4 := 2**16 * Byte4 (IS_Is2) + Byte4 (IS_Is2);
263 IS_Is8 := 2**32 * Byte8 (IS_Is4) + Byte8 (IS_Is4);
264 IS_Is16 := 2**64 * Byte16 (IS_Is8) + Byte16 (IS_Is8);
265
266 IS_Iu1 := IS_Is1;
267 IS_Iu2 := IS_Is2;
268 IS_Iu4 := IS_Is4;
269 IS_Iu8 := IS_Is8;
270 IS_Iu16 := IS_Is16;
271
272 IS_Iz1 := IS_Is1;
273 IS_Iz2 := IS_Is2;
274 IS_Iz4 := IS_Is4;
275 IS_Iz8 := IS_Is8;
276 IS_Iz16 := IS_Is16;
277
278 IV_Isf := IS_Is4;
279 IV_Ifl := IS_Is4;
280
281 IV_Ilf := To_ByteLF (IS_Is8);
282
283 if EFloat then
284 IV_Ill := [B, B, B, B, B, B, B, B, B, B, B, B];
285 end if;
286 end if;
287
288 -- If no separate Long_Long_Float, then use Long_Float value as
289 -- Long_Long_Float initial value.
290
291 if not EFloat then
292 declare
293 pragma Warnings (Off); -- because sizes don't match
294 function To_ByteLLF is
295 new Ada.Unchecked_Conversion (ByteLF, ByteLLF);
296 pragma Warnings (On);
297 begin
298 IV_Ill := To_ByteLLF (IV_Ilf);
299 end;
300 end if;
301 end Initialize;
302
303 end System.Scalar_Values;