]>
Commit | Line | Data |
---|---|---|
62c63f32 | 1 | /* More subroutines needed by GCC output code on some machines. */ |
2 | /* Compile this one with gcc. */ | |
7429c938 | 3 | /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
0ba508e4 | 4 | 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
62c63f32 | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
62c63f32 | 7 | |
f12b58b3 | 8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 2, or (at your option) any later | |
11 | version. | |
62c63f32 | 12 | |
4c9b6e71 | 13 | In addition to the permissions in the GNU General Public License, the |
14 | Free Software Foundation gives you unlimited permission to link the | |
15 | compiled version of this file into combinations with other programs, | |
16 | and to distribute those combinations without any restriction coming | |
17 | from the use of this file. (The General Public License restrictions | |
18 | do apply in other respects; for example, they cover modification of | |
19 | the file, and distribution when not linked into a combine | |
20 | executable.) | |
21 | ||
f12b58b3 | 22 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
23 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
24 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
25 | for more details. | |
62c63f32 | 26 | |
27 | You should have received a copy of the GNU General Public License | |
f12b58b3 | 28 | along with GCC; see the file COPYING. If not, write to the Free |
29 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
30 | 02111-1307, USA. */ | |
62c63f32 | 31 | |
395d450a | 32 | |
33 | /* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is | |
34 | supposedly valid even though this is a "target" file. */ | |
35 | #include "auto-host.h" | |
36 | ||
62c63f32 | 37 | /* It is incorrect to include config.h here, because this file is being |
38 | compiled for the target, and hence definitions concerning only the host | |
39 | do not apply. */ | |
c538053c | 40 | #include "tconfig.h" |
069631e1 | 41 | #include "tsystem.h" |
805e22b2 | 42 | #include "coretypes.h" |
43 | #include "tm.h" | |
8c304688 | 44 | |
62c63f32 | 45 | /* Don't use `fancy_abort' here even if config.h says to use it. */ |
46 | #ifdef abort | |
47 | #undef abort | |
48 | #endif | |
49 | ||
395d450a | 50 | #ifdef HAVE_GAS_HIDDEN |
51 | #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) | |
52 | #else | |
53 | #define ATTRIBUTE_HIDDEN | |
54 | #endif | |
55 | ||
b1e341a2 | 56 | #include "libgcc2.h" |
62c63f32 | 57 | \f |
856ba90e | 58 | #ifdef DECLARE_LIBRARY_RENAMES |
59 | DECLARE_LIBRARY_RENAMES | |
60 | #endif | |
61 | ||
f4dbfb4e | 62 | #if defined (L_negdi2) |
e40ae714 | 63 | DWtype |
64 | __negdi2 (DWtype u) | |
65 | { | |
ec7f942b | 66 | const DWunion uu = {.ll = u}; |
67 | const DWunion w = { {.low = -uu.s.low, | |
68 | .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } }; | |
e40ae714 | 69 | |
70 | return w.ll; | |
71 | } | |
72 | #endif | |
bec2d490 | 73 | |
74 | #ifdef L_addvsi3 | |
578dc367 | 75 | Wtype |
76 | __addvsi3 (Wtype a, Wtype b) | |
bec2d490 | 77 | { |
ec7f942b | 78 | const Wtype w = a + b; |
bec2d490 | 79 | |
80 | if (b >= 0 ? w < a : w > a) | |
81 | abort (); | |
82 | ||
83 | return w; | |
87e97de6 | 84 | } |
e40ae714 | 85 | #endif |
bec2d490 | 86 | \f |
87 | #ifdef L_addvdi3 | |
578dc367 | 88 | DWtype |
89 | __addvdi3 (DWtype a, DWtype b) | |
bec2d490 | 90 | { |
ec7f942b | 91 | const DWtype w = a + b; |
bec2d490 | 92 | |
93 | if (b >= 0 ? w < a : w > a) | |
94 | abort (); | |
95 | ||
96 | return w; | |
97 | } | |
98 | #endif | |
99 | \f | |
100 | #ifdef L_subvsi3 | |
578dc367 | 101 | Wtype |
102 | __subvsi3 (Wtype a, Wtype b) | |
bec2d490 | 103 | { |
ec7f942b | 104 | const DWtype w = a - b; |
bec2d490 | 105 | |
106 | if (b >= 0 ? w > a : w < a) | |
107 | abort (); | |
108 | ||
109 | return w; | |
bec2d490 | 110 | } |
111 | #endif | |
112 | \f | |
113 | #ifdef L_subvdi3 | |
578dc367 | 114 | DWtype |
115 | __subvdi3 (DWtype a, DWtype b) | |
bec2d490 | 116 | { |
ec7f942b | 117 | const DWtype w = a - b; |
bec2d490 | 118 | |
119 | if (b >= 0 ? w > a : w < a) | |
120 | abort (); | |
121 | ||
122 | return w; | |
bec2d490 | 123 | } |
124 | #endif | |
125 | \f | |
126 | #ifdef L_mulvsi3 | |
4772072d | 127 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
578dc367 | 128 | Wtype |
129 | __mulvsi3 (Wtype a, Wtype b) | |
bec2d490 | 130 | { |
ec7f942b | 131 | const DWtype w = (DWtype) a * (DWtype) b; |
bec2d490 | 132 | |
0cf3a1b4 | 133 | if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1)) |
bec2d490 | 134 | abort (); |
135 | ||
136 | return w; | |
137 | } | |
138 | #endif | |
139 | \f | |
140 | #ifdef L_negvsi2 | |
578dc367 | 141 | Wtype |
142 | __negvsi2 (Wtype a) | |
bec2d490 | 143 | { |
ec7f942b | 144 | const Wtype w = -a; |
bec2d490 | 145 | |
146 | if (a >= 0 ? w > 0 : w < 0) | |
147 | abort (); | |
148 | ||
149 | return w; | |
150 | } | |
151 | #endif | |
152 | \f | |
153 | #ifdef L_negvdi2 | |
578dc367 | 154 | DWtype |
155 | __negvdi2 (DWtype a) | |
bec2d490 | 156 | { |
ec7f942b | 157 | const DWtype w = -a; |
bec2d490 | 158 | |
159 | if (a >= 0 ? w > 0 : w < 0) | |
160 | abort (); | |
161 | ||
8851e806 | 162 | return w; |
bec2d490 | 163 | } |
164 | #endif | |
165 | \f | |
166 | #ifdef L_absvsi2 | |
578dc367 | 167 | Wtype |
168 | __absvsi2 (Wtype a) | |
bec2d490 | 169 | { |
8851e806 | 170 | Wtype w = a; |
bec2d490 | 171 | |
8851e806 | 172 | if (a < 0) |
bec2d490 | 173 | #ifdef L_negvsi2 |
8851e806 | 174 | w = __negvsi2 (a); |
bec2d490 | 175 | #else |
8851e806 | 176 | w = -a; |
bec2d490 | 177 | |
8851e806 | 178 | if (w < 0) |
179 | abort (); | |
bec2d490 | 180 | #endif |
181 | ||
182 | return w; | |
183 | } | |
184 | #endif | |
185 | \f | |
186 | #ifdef L_absvdi2 | |
578dc367 | 187 | DWtype |
188 | __absvdi2 (DWtype a) | |
bec2d490 | 189 | { |
8851e806 | 190 | DWtype w = a; |
bec2d490 | 191 | |
8851e806 | 192 | if (a < 0) |
4772072d | 193 | #ifdef L_negvdi2 |
194 | w = __negvdi2 (a); | |
bec2d490 | 195 | #else |
8851e806 | 196 | w = -a; |
bec2d490 | 197 | |
8851e806 | 198 | if (w < 0) |
199 | abort (); | |
bec2d490 | 200 | #endif |
201 | ||
8851e806 | 202 | return w; |
bec2d490 | 203 | } |
204 | #endif | |
205 | \f | |
206 | #ifdef L_mulvdi3 | |
4772072d | 207 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
578dc367 | 208 | DWtype |
209 | __mulvdi3 (DWtype u, DWtype v) | |
bec2d490 | 210 | { |
4772072d | 211 | /* The unchecked multiplication needs 3 Wtype x Wtype multiplications, |
212 | but the checked multiplication needs only two. */ | |
ec7f942b | 213 | const DWunion uu = {.ll = u}; |
214 | const DWunion vv = {.ll = v}; | |
bec2d490 | 215 | |
4772072d | 216 | if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1)) |
217 | { | |
218 | /* u fits in a single Wtype. */ | |
219 | if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1)) | |
220 | { | |
221 | /* v fits in a single Wtype as well. */ | |
222 | /* A single multiplication. No overflow risk. */ | |
223 | return (DWtype) uu.s.low * (DWtype) vv.s.low; | |
224 | } | |
225 | else | |
226 | { | |
227 | /* Two multiplications. */ | |
ec7f942b | 228 | DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low |
229 | * (UDWtype) (UWtype) vv.s.low}; | |
230 | DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low | |
231 | * (UDWtype) (UWtype) vv.s.high}; | |
4772072d | 232 | |
4772072d | 233 | if (vv.s.high < 0) |
234 | w1.s.high -= uu.s.low; | |
235 | if (uu.s.low < 0) | |
236 | w1.ll -= vv.ll; | |
237 | w1.ll += (UWtype) w0.s.high; | |
238 | if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1)) | |
239 | { | |
240 | w0.s.high = w1.s.low; | |
241 | return w0.ll; | |
242 | } | |
243 | } | |
244 | } | |
245 | else | |
246 | { | |
247 | if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1)) | |
248 | { | |
249 | /* v fits into a single Wtype. */ | |
250 | /* Two multiplications. */ | |
ec7f942b | 251 | DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low |
252 | * (UDWtype) (UWtype) vv.s.low}; | |
253 | DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high | |
254 | * (UDWtype) (UWtype) vv.s.low}; | |
4772072d | 255 | |
4772072d | 256 | if (uu.s.high < 0) |
257 | w1.s.high -= vv.s.low; | |
258 | if (vv.s.low < 0) | |
259 | w1.ll -= uu.ll; | |
260 | w1.ll += (UWtype) w0.s.high; | |
261 | if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1)) | |
262 | { | |
263 | w0.s.high = w1.s.low; | |
264 | return w0.ll; | |
265 | } | |
266 | } | |
267 | else | |
268 | { | |
269 | /* A few sign checks and a single multiplication. */ | |
270 | if (uu.s.high >= 0) | |
271 | { | |
272 | if (vv.s.high >= 0) | |
273 | { | |
274 | if (uu.s.high == 0 && vv.s.high == 0) | |
275 | { | |
ec7f942b | 276 | const DWtype w = (UDWtype) (UWtype) uu.s.low |
277 | * (UDWtype) (UWtype) vv.s.low; | |
4772072d | 278 | if (__builtin_expect (w >= 0, 1)) |
279 | return w; | |
280 | } | |
281 | } | |
282 | else | |
283 | { | |
284 | if (uu.s.high == 0 && vv.s.high == (Wtype) -1) | |
285 | { | |
ec7f942b | 286 | DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low |
287 | * (UDWtype) (UWtype) vv.s.low}; | |
4772072d | 288 | |
4772072d | 289 | ww.s.high -= uu.s.low; |
290 | if (__builtin_expect (ww.s.high < 0, 1)) | |
291 | return ww.ll; | |
292 | } | |
293 | } | |
294 | } | |
295 | else | |
296 | { | |
297 | if (vv.s.high >= 0) | |
298 | { | |
299 | if (uu.s.high == (Wtype) -1 && vv.s.high == 0) | |
300 | { | |
ec7f942b | 301 | DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low |
302 | * (UDWtype) (UWtype) vv.s.low}; | |
4772072d | 303 | |
4772072d | 304 | ww.s.high -= vv.s.low; |
305 | if (__builtin_expect (ww.s.high < 0, 1)) | |
306 | return ww.ll; | |
307 | } | |
308 | } | |
309 | else | |
310 | { | |
311 | if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1) | |
312 | { | |
ec7f942b | 313 | DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low |
314 | * (UDWtype) (UWtype) vv.s.low}; | |
4772072d | 315 | |
4772072d | 316 | ww.s.high -= uu.s.low; |
317 | ww.s.high -= vv.s.low; | |
318 | if (__builtin_expect (ww.s.high >= 0, 1)) | |
319 | return ww.ll; | |
320 | } | |
321 | } | |
322 | } | |
323 | } | |
324 | } | |
bec2d490 | 325 | |
4772072d | 326 | /* Overflow. */ |
327 | abort (); | |
bec2d490 | 328 | } |
329 | #endif | |
330 | \f | |
62c63f32 | 331 | |
b903337a | 332 | /* Unless shift functions are defined with full ANSI prototypes, |
4f195a89 | 333 | parameter b will be promoted to int if word_type is smaller than an int. */ |
62c63f32 | 334 | #ifdef L_lshrdi3 |
cf378360 | 335 | DWtype |
336 | __lshrdi3 (DWtype u, word_type b) | |
62c63f32 | 337 | { |
62c63f32 | 338 | if (b == 0) |
339 | return u; | |
340 | ||
ec7f942b | 341 | const DWunion uu = {.ll = u}; |
342 | const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
343 | DWunion w; | |
62c63f32 | 344 | |
62c63f32 | 345 | if (bm <= 0) |
346 | { | |
347 | w.s.high = 0; | |
d1138980 | 348 | w.s.low = (UWtype) uu.s.high >> -bm; |
62c63f32 | 349 | } |
350 | else | |
351 | { | |
ec7f942b | 352 | const UWtype carries = (UWtype) uu.s.high << bm; |
d1138980 | 353 | |
354 | w.s.high = (UWtype) uu.s.high >> b; | |
355 | w.s.low = ((UWtype) uu.s.low >> b) | carries; | |
62c63f32 | 356 | } |
357 | ||
358 | return w.ll; | |
359 | } | |
360 | #endif | |
361 | ||
362 | #ifdef L_ashldi3 | |
cf378360 | 363 | DWtype |
364 | __ashldi3 (DWtype u, word_type b) | |
62c63f32 | 365 | { |
62c63f32 | 366 | if (b == 0) |
367 | return u; | |
368 | ||
ec7f942b | 369 | const DWunion uu = {.ll = u}; |
370 | const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
371 | DWunion w; | |
62c63f32 | 372 | |
62c63f32 | 373 | if (bm <= 0) |
374 | { | |
375 | w.s.low = 0; | |
d1138980 | 376 | w.s.high = (UWtype) uu.s.low << -bm; |
62c63f32 | 377 | } |
378 | else | |
379 | { | |
ec7f942b | 380 | const UWtype carries = (UWtype) uu.s.low >> bm; |
d1138980 | 381 | |
382 | w.s.low = (UWtype) uu.s.low << b; | |
383 | w.s.high = ((UWtype) uu.s.high << b) | carries; | |
62c63f32 | 384 | } |
385 | ||
386 | return w.ll; | |
387 | } | |
388 | #endif | |
389 | ||
390 | #ifdef L_ashrdi3 | |
cf378360 | 391 | DWtype |
392 | __ashrdi3 (DWtype u, word_type b) | |
62c63f32 | 393 | { |
62c63f32 | 394 | if (b == 0) |
395 | return u; | |
396 | ||
ec7f942b | 397 | const DWunion uu = {.ll = u}; |
398 | const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b; | |
399 | DWunion w; | |
62c63f32 | 400 | |
62c63f32 | 401 | if (bm <= 0) |
402 | { | |
403 | /* w.s.high = 1..1 or 0..0 */ | |
cf378360 | 404 | w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1); |
62c63f32 | 405 | w.s.low = uu.s.high >> -bm; |
406 | } | |
407 | else | |
408 | { | |
ec7f942b | 409 | const UWtype carries = (UWtype) uu.s.high << bm; |
d1138980 | 410 | |
62c63f32 | 411 | w.s.high = uu.s.high >> b; |
d1138980 | 412 | w.s.low = ((UWtype) uu.s.low >> b) | carries; |
62c63f32 | 413 | } |
414 | ||
415 | return w.ll; | |
416 | } | |
417 | #endif | |
418 | \f | |
092445b3 | 419 | #ifdef L_ffssi2 |
420 | #undef int | |
092445b3 | 421 | int |
422 | __ffsSI2 (UWtype u) | |
423 | { | |
424 | UWtype count; | |
425 | ||
426 | if (u == 0) | |
427 | return 0; | |
428 | ||
429 | count_trailing_zeros (count, u); | |
430 | return count + 1; | |
431 | } | |
432 | #endif | |
433 | \f | |
5e4e1583 | 434 | #ifdef L_ffsdi2 |
7a02b4da | 435 | #undef int |
7a02b4da | 436 | int |
092445b3 | 437 | __ffsDI2 (DWtype u) |
5e4e1583 | 438 | { |
ec7f942b | 439 | const DWunion uu = {.ll = u}; |
9ce1b52b | 440 | UWtype word, count, add; |
441 | ||
9ce1b52b | 442 | if (uu.s.low != 0) |
443 | word = uu.s.low, add = 0; | |
444 | else if (uu.s.high != 0) | |
445 | word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype); | |
446 | else | |
447 | return 0; | |
448 | ||
449 | count_trailing_zeros (count, word); | |
450 | return count + add + 1; | |
5e4e1583 | 451 | } |
452 | #endif | |
453 | \f | |
62c63f32 | 454 | #ifdef L_muldi3 |
cf378360 | 455 | DWtype |
456 | __muldi3 (DWtype u, DWtype v) | |
62c63f32 | 457 | { |
ec7f942b | 458 | const DWunion uu = {.ll = u}; |
459 | const DWunion vv = {.ll = v}; | |
460 | DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)}; | |
62c63f32 | 461 | |
cf378360 | 462 | w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high |
463 | + (UWtype) uu.s.high * (UWtype) vv.s.low); | |
62c63f32 | 464 | |
465 | return w.ll; | |
466 | } | |
467 | #endif | |
468 | \f | |
1b3950b9 | 469 | #if (defined (L_udivdi3) || defined (L_divdi3) || \ |
470 | defined (L_umoddi3) || defined (L_moddi3)) | |
6b9d1b54 | 471 | #if defined (sdiv_qrnnd) |
1b3950b9 | 472 | #define L_udiv_w_sdiv |
473 | #endif | |
6b9d1b54 | 474 | #endif |
1b3950b9 | 475 | |
a46ef09f | 476 | #ifdef L_udiv_w_sdiv |
b10877f3 | 477 | #if defined (sdiv_qrnnd) |
1b3950b9 | 478 | #if (defined (L_udivdi3) || defined (L_divdi3) || \ |
479 | defined (L_umoddi3) || defined (L_moddi3)) | |
9dae5ac3 | 480 | static inline __attribute__ ((__always_inline__)) |
1b3950b9 | 481 | #endif |
cf378360 | 482 | UWtype |
483 | __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d) | |
ba628a68 | 484 | { |
cf378360 | 485 | UWtype q, r; |
486 | UWtype c0, c1, b1; | |
ba628a68 | 487 | |
cf378360 | 488 | if ((Wtype) d >= 0) |
ba628a68 | 489 | { |
cf378360 | 490 | if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1))) |
ba628a68 | 491 | { |
778ac06a | 492 | /* Dividend, divisor, and quotient are nonnegative. */ |
ba628a68 | 493 | sdiv_qrnnd (q, r, a1, a0, d); |
494 | } | |
495 | else | |
496 | { | |
778ac06a | 497 | /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */ |
cf378360 | 498 | sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1)); |
778ac06a | 499 | /* Divide (c1*2^32 + c0) by d. */ |
ba628a68 | 500 | sdiv_qrnnd (q, r, c1, c0, d); |
778ac06a | 501 | /* Add 2^31 to quotient. */ |
cf378360 | 502 | q += (UWtype) 1 << (W_TYPE_SIZE - 1); |
ba628a68 | 503 | } |
504 | } | |
505 | else | |
506 | { | |
507 | b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */ | |
508 | c1 = a1 >> 1; /* A/2 */ | |
cf378360 | 509 | c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1); |
ba628a68 | 510 | |
511 | if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */ | |
512 | { | |
513 | sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ | |
514 | ||
515 | r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */ | |
516 | if ((d & 1) != 0) | |
517 | { | |
518 | if (r >= q) | |
519 | r = r - q; | |
520 | else if (q - r <= d) | |
521 | { | |
522 | r = r - q + d; | |
523 | q--; | |
524 | } | |
525 | else | |
526 | { | |
527 | r = r - q + 2*d; | |
528 | q -= 2; | |
529 | } | |
530 | } | |
531 | } | |
532 | else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */ | |
533 | { | |
534 | c1 = (b1 - 1) - c1; | |
535 | c0 = ~c0; /* logical NOT */ | |
536 | ||
537 | sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ | |
538 | ||
539 | q = ~q; /* (A/2)/b1 */ | |
540 | r = (b1 - 1) - r; | |
541 | ||
542 | r = 2*r + (a0 & 1); /* A/(2*b1) */ | |
543 | ||
544 | if ((d & 1) != 0) | |
545 | { | |
546 | if (r >= q) | |
547 | r = r - q; | |
548 | else if (q - r <= d) | |
549 | { | |
550 | r = r - q + d; | |
551 | q--; | |
552 | } | |
553 | else | |
554 | { | |
555 | r = r - q + 2*d; | |
556 | q -= 2; | |
557 | } | |
558 | } | |
559 | } | |
560 | else /* Implies c1 = b1 */ | |
561 | { /* Hence a1 = d - 1 = 2*b1 - 1 */ | |
562 | if (a0 >= -d) | |
563 | { | |
564 | q = -1; | |
565 | r = a0 + d; | |
566 | } | |
567 | else | |
568 | { | |
569 | q = -2; | |
570 | r = a0 + 2*d; | |
571 | } | |
572 | } | |
573 | } | |
574 | ||
575 | *rp = r; | |
576 | return q; | |
577 | } | |
b10877f3 | 578 | #else |
579 | /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */ | |
cf378360 | 580 | UWtype |
581 | __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)), | |
582 | UWtype a1 __attribute__ ((__unused__)), | |
583 | UWtype a0 __attribute__ ((__unused__)), | |
584 | UWtype d __attribute__ ((__unused__))) | |
73439ee0 | 585 | { |
586 | return 0; | |
587 | } | |
b10877f3 | 588 | #endif |
ba628a68 | 589 | #endif |
590 | \f | |
a47053cf | 591 | #if (defined (L_udivdi3) || defined (L_divdi3) || \ |
592 | defined (L_umoddi3) || defined (L_moddi3)) | |
593 | #define L_udivmoddi4 | |
594 | #endif | |
595 | ||
9ce1b52b | 596 | #ifdef L_clz |
597 | const UQItype __clz_tab[] = | |
62c63f32 | 598 | { |
599 | 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, | |
600 | 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, | |
601 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | |
602 | 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, | |
603 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
604 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
605 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
606 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | |
607 | }; | |
9ce1b52b | 608 | #endif |
6a08d0ab | 609 | \f |
610 | #ifdef L_clzsi2 | |
7a02b4da | 611 | #undef int |
7a02b4da | 612 | int |
0f186426 | 613 | __clzSI2 (UWtype x) |
6a08d0ab | 614 | { |
395d450a | 615 | Wtype ret; |
6a08d0ab | 616 | |
0f186426 | 617 | count_leading_zeros (ret, x); |
395d450a | 618 | |
619 | return ret; | |
6a08d0ab | 620 | } |
621 | #endif | |
622 | \f | |
623 | #ifdef L_clzdi2 | |
7a02b4da | 624 | #undef int |
7a02b4da | 625 | int |
0f186426 | 626 | __clzDI2 (UDWtype x) |
6a08d0ab | 627 | { |
ec7f942b | 628 | const DWunion uu = {.ll = x}; |
395d450a | 629 | UWtype word; |
630 | Wtype ret, add; | |
631 | ||
0f186426 | 632 | if (uu.s.high) |
633 | word = uu.s.high, add = 0; | |
395d450a | 634 | else |
0f186426 | 635 | word = uu.s.low, add = W_TYPE_SIZE; |
6a08d0ab | 636 | |
395d450a | 637 | count_leading_zeros (ret, word); |
638 | return ret + add; | |
6a08d0ab | 639 | } |
640 | #endif | |
641 | \f | |
642 | #ifdef L_ctzsi2 | |
7a02b4da | 643 | #undef int |
7a02b4da | 644 | int |
0f186426 | 645 | __ctzSI2 (UWtype x) |
6a08d0ab | 646 | { |
395d450a | 647 | Wtype ret; |
6a08d0ab | 648 | |
395d450a | 649 | count_trailing_zeros (ret, x); |
6a08d0ab | 650 | |
395d450a | 651 | return ret; |
6a08d0ab | 652 | } |
653 | #endif | |
654 | \f | |
655 | #ifdef L_ctzdi2 | |
7a02b4da | 656 | #undef int |
7a02b4da | 657 | int |
0f186426 | 658 | __ctzDI2 (UDWtype x) |
6a08d0ab | 659 | { |
ec7f942b | 660 | const DWunion uu = {.ll = x}; |
395d450a | 661 | UWtype word; |
662 | Wtype ret, add; | |
663 | ||
0f186426 | 664 | if (uu.s.low) |
665 | word = uu.s.low, add = 0; | |
395d450a | 666 | else |
0f186426 | 667 | word = uu.s.high, add = W_TYPE_SIZE; |
6a08d0ab | 668 | |
395d450a | 669 | count_trailing_zeros (ret, word); |
670 | return ret + add; | |
6a08d0ab | 671 | } |
672 | #endif | |
673 | ||
395d450a | 674 | #if (defined (L_popcountsi2) || defined (L_popcountdi2) \ |
675 | || defined (L_popcount_tab)) | |
676 | extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN; | |
6a08d0ab | 677 | #endif |
678 | ||
679 | #ifdef L_popcount_tab | |
680 | const UQItype __popcount_tab[] = | |
681 | { | |
682 | 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, | |
683 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
684 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
685 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
686 | 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, | |
687 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
688 | 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, | |
689 | 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8, | |
690 | }; | |
691 | #endif | |
692 | \f | |
693 | #ifdef L_popcountsi2 | |
7a02b4da | 694 | #undef int |
7a02b4da | 695 | int |
0f186426 | 696 | __popcountSI2 (UWtype x) |
6a08d0ab | 697 | { |
0f186426 | 698 | UWtype i, ret = 0; |
699 | ||
700 | for (i = 0; i < W_TYPE_SIZE; i += 8) | |
701 | ret += __popcount_tab[(x >> i) & 0xff]; | |
702 | ||
703 | return ret; | |
6a08d0ab | 704 | } |
705 | #endif | |
706 | \f | |
707 | #ifdef L_popcountdi2 | |
7a02b4da | 708 | #undef int |
7a02b4da | 709 | int |
0f186426 | 710 | __popcountDI2 (UDWtype x) |
6a08d0ab | 711 | { |
0f186426 | 712 | UWtype i, ret = 0; |
713 | ||
714 | for (i = 0; i < 2*W_TYPE_SIZE; i += 8) | |
715 | ret += __popcount_tab[(x >> i) & 0xff]; | |
716 | ||
717 | return ret; | |
6a08d0ab | 718 | } |
719 | #endif | |
720 | \f | |
721 | #ifdef L_paritysi2 | |
7a02b4da | 722 | #undef int |
7a02b4da | 723 | int |
0f186426 | 724 | __paritySI2 (UWtype x) |
6a08d0ab | 725 | { |
0f186426 | 726 | #if W_TYPE_SIZE > 64 |
727 | # error "fill out the table" | |
728 | #endif | |
729 | #if W_TYPE_SIZE > 32 | |
730 | x ^= x >> 32; | |
731 | #endif | |
732 | #if W_TYPE_SIZE > 16 | |
733 | x ^= x >> 16; | |
734 | #endif | |
735 | x ^= x >> 8; | |
736 | x ^= x >> 4; | |
737 | x &= 0xf; | |
738 | return (0x6996 >> x) & 1; | |
6a08d0ab | 739 | } |
740 | #endif | |
741 | \f | |
742 | #ifdef L_paritydi2 | |
7a02b4da | 743 | #undef int |
7a02b4da | 744 | int |
0f186426 | 745 | __parityDI2 (UDWtype x) |
6a08d0ab | 746 | { |
ec7f942b | 747 | const DWunion uu = {.ll = x}; |
748 | UWtype nx = uu.s.low ^ uu.s.high; | |
0f186426 | 749 | |
750 | #if W_TYPE_SIZE > 64 | |
751 | # error "fill out the table" | |
752 | #endif | |
753 | #if W_TYPE_SIZE > 32 | |
754 | nx ^= nx >> 32; | |
755 | #endif | |
756 | #if W_TYPE_SIZE > 16 | |
6a08d0ab | 757 | nx ^= nx >> 16; |
0f186426 | 758 | #endif |
6a08d0ab | 759 | nx ^= nx >> 8; |
395d450a | 760 | nx ^= nx >> 4; |
9acebba8 | 761 | nx &= 0xf; |
762 | return (0x6996 >> nx) & 1; | |
6a08d0ab | 763 | } |
764 | #endif | |
9ce1b52b | 765 | |
766 | #ifdef L_udivmoddi4 | |
62c63f32 | 767 | |
a47053cf | 768 | #if (defined (L_udivdi3) || defined (L_divdi3) || \ |
769 | defined (L_umoddi3) || defined (L_moddi3)) | |
9dae5ac3 | 770 | static inline __attribute__ ((__always_inline__)) |
a47053cf | 771 | #endif |
cf378360 | 772 | UDWtype |
773 | __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp) | |
62c63f32 | 774 | { |
ec7f942b | 775 | const DWunion nn = {.ll = n}; |
776 | const DWunion dd = {.ll = d}; | |
cf378360 | 777 | DWunion rr; |
778 | UWtype d0, d1, n0, n1, n2; | |
779 | UWtype q0, q1; | |
780 | UWtype b, bm; | |
62c63f32 | 781 | |
62c63f32 | 782 | d0 = dd.s.low; |
783 | d1 = dd.s.high; | |
784 | n0 = nn.s.low; | |
785 | n1 = nn.s.high; | |
786 | ||
787 | #if !UDIV_NEEDS_NORMALIZATION | |
788 | if (d1 == 0) | |
789 | { | |
790 | if (d0 > n1) | |
791 | { | |
792 | /* 0q = nn / 0D */ | |
793 | ||
794 | udiv_qrnnd (q0, n0, n1, n0, d0); | |
795 | q1 = 0; | |
796 | ||
797 | /* Remainder in n0. */ | |
798 | } | |
799 | else | |
800 | { | |
801 | /* qq = NN / 0d */ | |
802 | ||
803 | if (d0 == 0) | |
804 | d0 = 1 / d0; /* Divide intentionally by zero. */ | |
805 | ||
806 | udiv_qrnnd (q1, n1, 0, n1, d0); | |
807 | udiv_qrnnd (q0, n0, n1, n0, d0); | |
808 | ||
809 | /* Remainder in n0. */ | |
810 | } | |
811 | ||
812 | if (rp != 0) | |
813 | { | |
814 | rr.s.low = n0; | |
815 | rr.s.high = 0; | |
816 | *rp = rr.ll; | |
817 | } | |
818 | } | |
819 | ||
820 | #else /* UDIV_NEEDS_NORMALIZATION */ | |
821 | ||
822 | if (d1 == 0) | |
823 | { | |
824 | if (d0 > n1) | |
825 | { | |
826 | /* 0q = nn / 0D */ | |
827 | ||
828 | count_leading_zeros (bm, d0); | |
829 | ||
830 | if (bm != 0) | |
831 | { | |
832 | /* Normalize, i.e. make the most significant bit of the | |
833 | denominator set. */ | |
834 | ||
835 | d0 = d0 << bm; | |
cf378360 | 836 | n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm)); |
62c63f32 | 837 | n0 = n0 << bm; |
838 | } | |
839 | ||
840 | udiv_qrnnd (q0, n0, n1, n0, d0); | |
841 | q1 = 0; | |
842 | ||
843 | /* Remainder in n0 >> bm. */ | |
844 | } | |
845 | else | |
846 | { | |
847 | /* qq = NN / 0d */ | |
848 | ||
849 | if (d0 == 0) | |
850 | d0 = 1 / d0; /* Divide intentionally by zero. */ | |
851 | ||
852 | count_leading_zeros (bm, d0); | |
853 | ||
854 | if (bm == 0) | |
855 | { | |
856 | /* From (n1 >= d0) /\ (the most significant bit of d0 is set), | |
857 | conclude (the most significant bit of n1 is set) /\ (the | |
858 | leading quotient digit q1 = 1). | |
859 | ||
860 | This special case is necessary, not an optimization. | |
cf378360 | 861 | (Shifts counts of W_TYPE_SIZE are undefined.) */ |
62c63f32 | 862 | |
863 | n1 -= d0; | |
864 | q1 = 1; | |
865 | } | |
866 | else | |
867 | { | |
868 | /* Normalize. */ | |
869 | ||
cf378360 | 870 | b = W_TYPE_SIZE - bm; |
62c63f32 | 871 | |
872 | d0 = d0 << bm; | |
873 | n2 = n1 >> b; | |
874 | n1 = (n1 << bm) | (n0 >> b); | |
875 | n0 = n0 << bm; | |
876 | ||
877 | udiv_qrnnd (q1, n1, n2, n1, d0); | |
878 | } | |
879 | ||
a92771b8 | 880 | /* n1 != d0... */ |
62c63f32 | 881 | |
882 | udiv_qrnnd (q0, n0, n1, n0, d0); | |
883 | ||
884 | /* Remainder in n0 >> bm. */ | |
885 | } | |
886 | ||
887 | if (rp != 0) | |
888 | { | |
889 | rr.s.low = n0 >> bm; | |
890 | rr.s.high = 0; | |
891 | *rp = rr.ll; | |
892 | } | |
893 | } | |
894 | #endif /* UDIV_NEEDS_NORMALIZATION */ | |
895 | ||
896 | else | |
897 | { | |
898 | if (d1 > n1) | |
899 | { | |
900 | /* 00 = nn / DD */ | |
901 | ||
902 | q0 = 0; | |
903 | q1 = 0; | |
904 | ||
905 | /* Remainder in n1n0. */ | |
906 | if (rp != 0) | |
907 | { | |
908 | rr.s.low = n0; | |
909 | rr.s.high = n1; | |
910 | *rp = rr.ll; | |
911 | } | |
912 | } | |
913 | else | |
914 | { | |
915 | /* 0q = NN / dd */ | |
916 | ||
917 | count_leading_zeros (bm, d1); | |
918 | if (bm == 0) | |
919 | { | |
920 | /* From (n1 >= d1) /\ (the most significant bit of d1 is set), | |
921 | conclude (the most significant bit of n1 is set) /\ (the | |
922 | quotient digit q0 = 0 or 1). | |
923 | ||
924 | This special case is necessary, not an optimization. */ | |
925 | ||
926 | /* The condition on the next line takes advantage of that | |
927 | n1 >= d1 (true due to program flow). */ | |
928 | if (n1 > d1 || n0 >= d0) | |
929 | { | |
930 | q0 = 1; | |
931 | sub_ddmmss (n1, n0, n1, n0, d1, d0); | |
932 | } | |
933 | else | |
934 | q0 = 0; | |
935 | ||
936 | q1 = 0; | |
937 | ||
938 | if (rp != 0) | |
939 | { | |
940 | rr.s.low = n0; | |
941 | rr.s.high = n1; | |
942 | *rp = rr.ll; | |
943 | } | |
944 | } | |
945 | else | |
946 | { | |
cf378360 | 947 | UWtype m1, m0; |
62c63f32 | 948 | /* Normalize. */ |
949 | ||
cf378360 | 950 | b = W_TYPE_SIZE - bm; |
62c63f32 | 951 | |
952 | d1 = (d1 << bm) | (d0 >> b); | |
953 | d0 = d0 << bm; | |
954 | n2 = n1 >> b; | |
955 | n1 = (n1 << bm) | (n0 >> b); | |
956 | n0 = n0 << bm; | |
957 | ||
958 | udiv_qrnnd (q0, n1, n2, n1, d1); | |
959 | umul_ppmm (m1, m0, q0, d0); | |
960 | ||
961 | if (m1 > n1 || (m1 == n1 && m0 > n0)) | |
962 | { | |
963 | q0--; | |
964 | sub_ddmmss (m1, m0, m1, m0, d1, d0); | |
965 | } | |
966 | ||
967 | q1 = 0; | |
968 | ||
969 | /* Remainder in (n1n0 - m1m0) >> bm. */ | |
970 | if (rp != 0) | |
971 | { | |
972 | sub_ddmmss (n1, n0, n1, n0, m1, m0); | |
973 | rr.s.low = (n1 << b) | (n0 >> bm); | |
974 | rr.s.high = n1 >> bm; | |
975 | *rp = rr.ll; | |
976 | } | |
977 | } | |
978 | } | |
979 | } | |
980 | ||
ec7f942b | 981 | const DWunion ww = {{.low = q0, .high = q1}}; |
62c63f32 | 982 | return ww.ll; |
983 | } | |
984 | #endif | |
985 | ||
986 | #ifdef L_divdi3 | |
cf378360 | 987 | DWtype |
988 | __divdi3 (DWtype u, DWtype v) | |
62c63f32 | 989 | { |
60a744a6 | 990 | word_type c = 0; |
ec7f942b | 991 | DWunion uu = {.ll = u}; |
992 | DWunion vv = {.ll = v}; | |
cf378360 | 993 | DWtype w; |
62c63f32 | 994 | |
62c63f32 | 995 | if (uu.s.high < 0) |
996 | c = ~c, | |
f4dbfb4e | 997 | uu.ll = -uu.ll; |
62c63f32 | 998 | if (vv.s.high < 0) |
999 | c = ~c, | |
f4dbfb4e | 1000 | vv.ll = -vv.ll; |
62c63f32 | 1001 | |
cf378360 | 1002 | w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0); |
62c63f32 | 1003 | if (c) |
f4dbfb4e | 1004 | w = -w; |
62c63f32 | 1005 | |
1006 | return w; | |
1007 | } | |
1008 | #endif | |
1009 | ||
1010 | #ifdef L_moddi3 | |
cf378360 | 1011 | DWtype |
1012 | __moddi3 (DWtype u, DWtype v) | |
62c63f32 | 1013 | { |
60a744a6 | 1014 | word_type c = 0; |
ec7f942b | 1015 | DWunion uu = {.ll = u}; |
1016 | DWunion vv = {.ll = v}; | |
cf378360 | 1017 | DWtype w; |
62c63f32 | 1018 | |
62c63f32 | 1019 | if (uu.s.high < 0) |
1020 | c = ~c, | |
f4dbfb4e | 1021 | uu.ll = -uu.ll; |
62c63f32 | 1022 | if (vv.s.high < 0) |
f4dbfb4e | 1023 | vv.ll = -vv.ll; |
62c63f32 | 1024 | |
79cc8081 | 1025 | (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w); |
62c63f32 | 1026 | if (c) |
f4dbfb4e | 1027 | w = -w; |
62c63f32 | 1028 | |
1029 | return w; | |
1030 | } | |
1031 | #endif | |
1032 | ||
1033 | #ifdef L_umoddi3 | |
cf378360 | 1034 | UDWtype |
1035 | __umoddi3 (UDWtype u, UDWtype v) | |
62c63f32 | 1036 | { |
cf378360 | 1037 | UDWtype w; |
62c63f32 | 1038 | |
1039 | (void) __udivmoddi4 (u, v, &w); | |
1040 | ||
1041 | return w; | |
1042 | } | |
1043 | #endif | |
1044 | ||
1045 | #ifdef L_udivdi3 | |
cf378360 | 1046 | UDWtype |
1047 | __udivdi3 (UDWtype n, UDWtype d) | |
62c63f32 | 1048 | { |
cf378360 | 1049 | return __udivmoddi4 (n, d, (UDWtype *) 0); |
62c63f32 | 1050 | } |
1051 | #endif | |
1052 | \f | |
1053 | #ifdef L_cmpdi2 | |
61d95568 | 1054 | word_type |
cf378360 | 1055 | __cmpdi2 (DWtype a, DWtype b) |
62c63f32 | 1056 | { |
ec7f942b | 1057 | const DWunion au = {.ll = a}; |
1058 | const DWunion bu = {.ll = b}; | |
62c63f32 | 1059 | |
1060 | if (au.s.high < bu.s.high) | |
1061 | return 0; | |
1062 | else if (au.s.high > bu.s.high) | |
1063 | return 2; | |
cf378360 | 1064 | if ((UWtype) au.s.low < (UWtype) bu.s.low) |
62c63f32 | 1065 | return 0; |
cf378360 | 1066 | else if ((UWtype) au.s.low > (UWtype) bu.s.low) |
62c63f32 | 1067 | return 2; |
1068 | return 1; | |
1069 | } | |
1070 | #endif | |
1071 | ||
1072 | #ifdef L_ucmpdi2 | |
61d95568 | 1073 | word_type |
cf378360 | 1074 | __ucmpdi2 (DWtype a, DWtype b) |
62c63f32 | 1075 | { |
ec7f942b | 1076 | const DWunion au = {.ll = a}; |
1077 | const DWunion bu = {.ll = b}; | |
62c63f32 | 1078 | |
cf378360 | 1079 | if ((UWtype) au.s.high < (UWtype) bu.s.high) |
62c63f32 | 1080 | return 0; |
cf378360 | 1081 | else if ((UWtype) au.s.high > (UWtype) bu.s.high) |
62c63f32 | 1082 | return 2; |
cf378360 | 1083 | if ((UWtype) au.s.low < (UWtype) bu.s.low) |
62c63f32 | 1084 | return 0; |
cf378360 | 1085 | else if ((UWtype) au.s.low > (UWtype) bu.s.low) |
62c63f32 | 1086 | return 2; |
1087 | return 1; | |
1088 | } | |
1089 | #endif | |
1090 | \f | |
dd84cabc | 1091 | #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128) |
cf378360 | 1092 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1093 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
ade0e71b | 1094 | |
cf378360 | 1095 | DWtype |
d1138980 | 1096 | __fixunstfDI (TFtype a) |
ade0e71b | 1097 | { |
ade0e71b | 1098 | if (a < 0) |
1099 | return 0; | |
1100 | ||
1101 | /* Compute high word of result, as a flonum. */ | |
ec7f942b | 1102 | const TFtype b = (a / HIGH_WORD_COEFF); |
cf378360 | 1103 | /* Convert that to fixed (but not to DWtype!), |
ade0e71b | 1104 | and shift it into the high word. */ |
ec7f942b | 1105 | UDWtype v = (UWtype) b; |
ade0e71b | 1106 | v <<= WORD_SIZE; |
1107 | /* Remove high part from the TFtype, leaving the low part as flonum. */ | |
1108 | a -= (TFtype)v; | |
cf378360 | 1109 | /* Convert that to fixed (but not to DWtype!) and add it in. |
ade0e71b | 1110 | Sometimes A comes out negative. This is significant, since |
1111 | A has more bits than a long int does. */ | |
1112 | if (a < 0) | |
cf378360 | 1113 | v -= (UWtype) (- a); |
ade0e71b | 1114 | else |
cf378360 | 1115 | v += (UWtype) a; |
ade0e71b | 1116 | return v; |
1117 | } | |
1118 | #endif | |
1119 | ||
dd84cabc | 1120 | #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128) |
cf378360 | 1121 | DWtype |
4f195a89 | 1122 | __fixtfdi (TFtype a) |
ade0e71b | 1123 | { |
1124 | if (a < 0) | |
d1138980 | 1125 | return - __fixunstfDI (-a); |
1126 | return __fixunstfDI (a); | |
ade0e71b | 1127 | } |
1128 | #endif | |
1129 | ||
77d98cfe | 1130 | #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80) |
cf378360 | 1131 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1132 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
0e1cc047 | 1133 | |
cf378360 | 1134 | DWtype |
d1138980 | 1135 | __fixunsxfDI (XFtype a) |
0e1cc047 | 1136 | { |
0e1cc047 | 1137 | if (a < 0) |
1138 | return 0; | |
1139 | ||
1140 | /* Compute high word of result, as a flonum. */ | |
ec7f942b | 1141 | const XFtype b = (a / HIGH_WORD_COEFF); |
cf378360 | 1142 | /* Convert that to fixed (but not to DWtype!), |
0e1cc047 | 1143 | and shift it into the high word. */ |
ec7f942b | 1144 | UDWtype v = (UWtype) b; |
0e1cc047 | 1145 | v <<= WORD_SIZE; |
1146 | /* Remove high part from the XFtype, leaving the low part as flonum. */ | |
1147 | a -= (XFtype)v; | |
cf378360 | 1148 | /* Convert that to fixed (but not to DWtype!) and add it in. |
0e1cc047 | 1149 | Sometimes A comes out negative. This is significant, since |
1150 | A has more bits than a long int does. */ | |
1151 | if (a < 0) | |
cf378360 | 1152 | v -= (UWtype) (- a); |
0e1cc047 | 1153 | else |
cf378360 | 1154 | v += (UWtype) a; |
0e1cc047 | 1155 | return v; |
1156 | } | |
1157 | #endif | |
1158 | ||
77d98cfe | 1159 | #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80) |
cf378360 | 1160 | DWtype |
4f195a89 | 1161 | __fixxfdi (XFtype a) |
0e1cc047 | 1162 | { |
1163 | if (a < 0) | |
d1138980 | 1164 | return - __fixunsxfDI (-a); |
1165 | return __fixunsxfDI (a); | |
0e1cc047 | 1166 | } |
1167 | #endif | |
1168 | ||
62c63f32 | 1169 | #ifdef L_fixunsdfdi |
cf378360 | 1170 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1171 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
62c63f32 | 1172 | |
cf378360 | 1173 | DWtype |
d1138980 | 1174 | __fixunsdfDI (DFtype a) |
62c63f32 | 1175 | { |
805e22b2 | 1176 | /* Get high part of result. The division here will just moves the radix |
1177 | point and will not cause any rounding. Then the conversion to integral | |
1178 | type chops result as desired. */ | |
ec7f942b | 1179 | const UWtype hi = a / HIGH_WORD_COEFF; |
62c63f32 | 1180 | |
805e22b2 | 1181 | /* Get low part of result. Convert `hi' to floating type and scale it back, |
1182 | then subtract this from the number being converted. This leaves the low | |
1183 | part. Convert that to integral type. */ | |
ec7f942b | 1184 | const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF); |
805e22b2 | 1185 | |
1186 | /* Assemble result from the two parts. */ | |
1187 | return ((UDWtype) hi << WORD_SIZE) | lo; | |
62c63f32 | 1188 | } |
1189 | #endif | |
1190 | ||
1191 | #ifdef L_fixdfdi | |
cf378360 | 1192 | DWtype |
4f195a89 | 1193 | __fixdfdi (DFtype a) |
62c63f32 | 1194 | { |
1195 | if (a < 0) | |
d1138980 | 1196 | return - __fixunsdfDI (-a); |
1197 | return __fixunsdfDI (a); | |
62c63f32 | 1198 | } |
1199 | #endif | |
1200 | ||
1201 | #ifdef L_fixunssfdi | |
cf378360 | 1202 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1203 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
62c63f32 | 1204 | |
cf378360 | 1205 | DWtype |
d1138980 | 1206 | __fixunssfDI (SFtype original_a) |
62c63f32 | 1207 | { |
ade0e71b | 1208 | /* Convert the SFtype to a DFtype, because that is surely not going |
62c63f32 | 1209 | to lose any bits. Some day someone else can write a faster version |
ade0e71b | 1210 | that avoids converting to DFtype, and verify it really works right. */ |
ec7f942b | 1211 | const DFtype a = original_a; |
62c63f32 | 1212 | |
805e22b2 | 1213 | /* Get high part of result. The division here will just moves the radix |
1214 | point and will not cause any rounding. Then the conversion to integral | |
1215 | type chops result as desired. */ | |
ec7f942b | 1216 | const UWtype hi = a / HIGH_WORD_COEFF; |
62c63f32 | 1217 | |
805e22b2 | 1218 | /* Get low part of result. Convert `hi' to floating type and scale it back, |
1219 | then subtract this from the number being converted. This leaves the low | |
1220 | part. Convert that to integral type. */ | |
ec7f942b | 1221 | const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF); |
805e22b2 | 1222 | |
1223 | /* Assemble result from the two parts. */ | |
1224 | return ((UDWtype) hi << WORD_SIZE) | lo; | |
62c63f32 | 1225 | } |
1226 | #endif | |
1227 | ||
1228 | #ifdef L_fixsfdi | |
cf378360 | 1229 | DWtype |
ade0e71b | 1230 | __fixsfdi (SFtype a) |
62c63f32 | 1231 | { |
1232 | if (a < 0) | |
d1138980 | 1233 | return - __fixunssfDI (-a); |
1234 | return __fixunssfDI (a); | |
62c63f32 | 1235 | } |
1236 | #endif | |
1237 | ||
77d98cfe | 1238 | #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80) |
cf378360 | 1239 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1240 | #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2)) | |
1241 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
0e1cc047 | 1242 | |
1243 | XFtype | |
cf378360 | 1244 | __floatdixf (DWtype u) |
0e1cc047 | 1245 | { |
ec7f942b | 1246 | XFtype d = (Wtype) (u >> WORD_SIZE); |
0e1cc047 | 1247 | d *= HIGH_HALFWORD_COEFF; |
1248 | d *= HIGH_HALFWORD_COEFF; | |
cf378360 | 1249 | d += (UWtype) (u & (HIGH_WORD_COEFF - 1)); |
0e1cc047 | 1250 | |
997d68fe | 1251 | return d; |
0e1cc047 | 1252 | } |
1253 | #endif | |
1254 | ||
dd84cabc | 1255 | #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128) |
cf378360 | 1256 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1257 | #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2)) | |
1258 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
ade0e71b | 1259 | |
1260 | TFtype | |
cf378360 | 1261 | __floatditf (DWtype u) |
ade0e71b | 1262 | { |
ec7f942b | 1263 | TFtype d = (Wtype) (u >> WORD_SIZE); |
ade0e71b | 1264 | d *= HIGH_HALFWORD_COEFF; |
1265 | d *= HIGH_HALFWORD_COEFF; | |
cf378360 | 1266 | d += (UWtype) (u & (HIGH_WORD_COEFF - 1)); |
ade0e71b | 1267 | |
997d68fe | 1268 | return d; |
ade0e71b | 1269 | } |
1270 | #endif | |
1271 | ||
62c63f32 | 1272 | #ifdef L_floatdidf |
cf378360 | 1273 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1274 | #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2)) | |
1275 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
62c63f32 | 1276 | |
ade0e71b | 1277 | DFtype |
cf378360 | 1278 | __floatdidf (DWtype u) |
62c63f32 | 1279 | { |
ec7f942b | 1280 | DFtype d = (Wtype) (u >> WORD_SIZE); |
62c63f32 | 1281 | d *= HIGH_HALFWORD_COEFF; |
1282 | d *= HIGH_HALFWORD_COEFF; | |
cf378360 | 1283 | d += (UWtype) (u & (HIGH_WORD_COEFF - 1)); |
62c63f32 | 1284 | |
997d68fe | 1285 | return d; |
62c63f32 | 1286 | } |
1287 | #endif | |
1288 | ||
1289 | #ifdef L_floatdisf | |
cf378360 | 1290 | #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT) |
1291 | #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2)) | |
1292 | #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE) | |
87e97de6 | 1293 | |
536f5fb1 | 1294 | #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT) |
badfe841 | 1295 | #define DF_SIZE DBL_MANT_DIG |
1296 | #define SF_SIZE FLT_MANT_DIG | |
62c63f32 | 1297 | |
ade0e71b | 1298 | SFtype |
cf378360 | 1299 | __floatdisf (DWtype u) |
62c63f32 | 1300 | { |
b37ebc51 | 1301 | /* Protect against double-rounding error. |
1302 | Represent any low-order bits, that might be truncated in DFmode, | |
1303 | by a bit that won't be lost. The bit can go in anywhere below the | |
1304 | rounding position of the SFmode. A fixed mask and bit position | |
1305 | handles all usual configurations. It doesn't handle the case | |
1306 | of 128-bit DImode, however. */ | |
1307 | if (DF_SIZE < DI_SIZE | |
1308 | && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE)) | |
1309 | { | |
d1138980 | 1310 | #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE)) |
cf378360 | 1311 | if (! (- ((DWtype) 1 << DF_SIZE) < u |
1312 | && u < ((DWtype) 1 << DF_SIZE))) | |
b37ebc51 | 1313 | { |
d1138980 | 1314 | if ((UDWtype) u & (REP_BIT - 1)) |
f9c9dcd7 | 1315 | { |
1316 | u &= ~ (REP_BIT - 1); | |
1317 | u |= REP_BIT; | |
1318 | } | |
b37ebc51 | 1319 | } |
1320 | } | |
ec7f942b | 1321 | /* Do the calculation in DFmode |
1322 | so that we don't lose any of the precision of the high word | |
1323 | while multiplying it. */ | |
1324 | DFtype f = (Wtype) (u >> WORD_SIZE); | |
62c63f32 | 1325 | f *= HIGH_HALFWORD_COEFF; |
1326 | f *= HIGH_HALFWORD_COEFF; | |
cf378360 | 1327 | f += (UWtype) (u & (HIGH_WORD_COEFF - 1)); |
62c63f32 | 1328 | |
997d68fe | 1329 | return (SFtype) f; |
62c63f32 | 1330 | } |
1331 | #endif | |
1332 | ||
77d98cfe | 1333 | #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80 |
3873e172 | 1334 | /* Reenable the normal types, in case limits.h needs them. */ |
1335 | #undef char | |
1336 | #undef short | |
1337 | #undef int | |
1338 | #undef long | |
1339 | #undef unsigned | |
1340 | #undef float | |
1341 | #undef double | |
35e6d592 | 1342 | #undef MIN |
1343 | #undef MAX | |
ab195728 | 1344 | #include <limits.h> |
0e1cc047 | 1345 | |
cf378360 | 1346 | UWtype |
d1138980 | 1347 | __fixunsxfSI (XFtype a) |
0e1cc047 | 1348 | { |
7429c938 | 1349 | if (a >= - (DFtype) Wtype_MIN) |
1350 | return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
cf378360 | 1351 | return (Wtype) a; |
0e1cc047 | 1352 | } |
1353 | #endif | |
1354 | ||
62c63f32 | 1355 | #ifdef L_fixunsdfsi |
3873e172 | 1356 | /* Reenable the normal types, in case limits.h needs them. */ |
1357 | #undef char | |
1358 | #undef short | |
1359 | #undef int | |
1360 | #undef long | |
1361 | #undef unsigned | |
1362 | #undef float | |
1363 | #undef double | |
35e6d592 | 1364 | #undef MIN |
1365 | #undef MAX | |
ab195728 | 1366 | #include <limits.h> |
62c63f32 | 1367 | |
cf378360 | 1368 | UWtype |
d1138980 | 1369 | __fixunsdfSI (DFtype a) |
62c63f32 | 1370 | { |
7429c938 | 1371 | if (a >= - (DFtype) Wtype_MIN) |
1372 | return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
cf378360 | 1373 | return (Wtype) a; |
62c63f32 | 1374 | } |
1375 | #endif | |
1376 | ||
1377 | #ifdef L_fixunssfsi | |
3873e172 | 1378 | /* Reenable the normal types, in case limits.h needs them. */ |
1379 | #undef char | |
1380 | #undef short | |
1381 | #undef int | |
1382 | #undef long | |
1383 | #undef unsigned | |
1384 | #undef float | |
1385 | #undef double | |
35e6d592 | 1386 | #undef MIN |
1387 | #undef MAX | |
ab195728 | 1388 | #include <limits.h> |
62c63f32 | 1389 | |
cf378360 | 1390 | UWtype |
d1138980 | 1391 | __fixunssfSI (SFtype a) |
62c63f32 | 1392 | { |
7429c938 | 1393 | if (a >= - (SFtype) Wtype_MIN) |
1394 | return (Wtype) (a + Wtype_MIN) - Wtype_MIN; | |
cf378360 | 1395 | return (Wtype) a; |
62c63f32 | 1396 | } |
1397 | #endif | |
1398 | \f | |
ade0e71b | 1399 | /* From here on down, the routines use normal data types. */ |
1400 | ||
1401 | #define SItype bogus_type | |
1402 | #define USItype bogus_type | |
1403 | #define DItype bogus_type | |
1404 | #define UDItype bogus_type | |
1405 | #define SFtype bogus_type | |
1406 | #define DFtype bogus_type | |
cf378360 | 1407 | #undef Wtype |
1408 | #undef UWtype | |
1409 | #undef HWtype | |
1410 | #undef UHWtype | |
1411 | #undef DWtype | |
1412 | #undef UDWtype | |
ade0e71b | 1413 | |
1414 | #undef char | |
1415 | #undef short | |
1416 | #undef int | |
1417 | #undef long | |
1418 | #undef unsigned | |
1419 | #undef float | |
1420 | #undef double | |
e674bcb7 | 1421 | \f |
1422 | #ifdef L__gcc_bcmp | |
1423 | ||
1424 | /* Like bcmp except the sign is meaningful. | |
c3418f42 | 1425 | Result is negative if S1 is less than S2, |
e674bcb7 | 1426 | positive if S1 is greater, 0 if S1 and S2 are equal. */ |
1427 | ||
1428 | int | |
b1e341a2 | 1429 | __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size) |
e674bcb7 | 1430 | { |
1431 | while (size > 0) | |
1432 | { | |
ec7f942b | 1433 | const unsigned char c1 = *s1++, c2 = *s2++; |
e674bcb7 | 1434 | if (c1 != c2) |
1435 | return c1 - c2; | |
1436 | size--; | |
1437 | } | |
1438 | return 0; | |
1439 | } | |
ade0e71b | 1440 | |
0bad1e66 | 1441 | #endif |
1442 | \f | |
1443 | /* __eprintf used to be used by GCC's private version of <assert.h>. | |
1444 | We no longer provide that header, but this routine remains in libgcc.a | |
1445 | for binary backward compatibility. Note that it is not included in | |
1446 | the shared version of libgcc. */ | |
1447 | #ifdef L_eprintf | |
1448 | #ifndef inhibit_libc | |
1449 | ||
1450 | #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */ | |
1451 | #include <stdio.h> | |
1452 | ||
1453 | void | |
1454 | __eprintf (const char *string, const char *expression, | |
1455 | unsigned int line, const char *filename) | |
1456 | { | |
1457 | fprintf (stderr, string, expression, line, filename); | |
1458 | fflush (stderr); | |
1459 | abort (); | |
1460 | } | |
1461 | ||
1462 | #endif | |
62c63f32 | 1463 | #endif |
1464 | ||
62c63f32 | 1465 | \f |
62c63f32 | 1466 | #ifdef L_clear_cache |
1467 | /* Clear part of an instruction cache. */ | |
1468 | ||
62c63f32 | 1469 | void |
abbe5a3d | 1470 | __clear_cache (char *beg __attribute__((__unused__)), |
1471 | char *end __attribute__((__unused__))) | |
62c63f32 | 1472 | { |
87e97de6 | 1473 | #ifdef CLEAR_INSN_CACHE |
efa58f1a | 1474 | CLEAR_INSN_CACHE (beg, end); |
efa58f1a | 1475 | #endif /* CLEAR_INSN_CACHE */ |
62c63f32 | 1476 | } |
1477 | ||
1478 | #endif /* L_clear_cache */ | |
1479 | \f | |
5577e296 | 1480 | #ifdef L_enable_execute_stack |
1481 | /* Attempt to turn on execute permission for the stack. */ | |
1482 | ||
1483 | #ifdef ENABLE_EXECUTE_STACK | |
1484 | ENABLE_EXECUTE_STACK | |
1485 | #else | |
1486 | void | |
1487 | __enable_execute_stack (void *addr __attribute__((__unused__))) | |
1488 | {} | |
1489 | #endif /* ENABLE_EXECUTE_STACK */ | |
1490 | ||
1491 | #endif /* L_enable_execute_stack */ | |
1492 | \f | |
62c63f32 | 1493 | #ifdef L_trampoline |
1494 | ||
1495 | /* Jump to a trampoline, loading the static chain address. */ | |
1496 | ||
f1959ea2 | 1497 | #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN) |
8e782fcd | 1498 | |
4281d316 | 1499 | int |
71218a21 | 1500 | getpagesize (void) |
e30b7e49 | 1501 | { |
1502 | #ifdef _ALPHA_ | |
1503 | return 8192; | |
1504 | #else | |
1505 | return 4096; | |
1506 | #endif | |
1507 | } | |
1508 | ||
1ec6144c | 1509 | #ifdef __i386__ |
bdf89453 | 1510 | extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall)); |
1511 | #endif | |
1512 | ||
38e911c3 | 1513 | int |
1514 | mprotect (char *addr, int len, int prot) | |
e30b7e49 | 1515 | { |
1516 | int np, op; | |
1517 | ||
38e911c3 | 1518 | if (prot == 7) |
1519 | np = 0x40; | |
1520 | else if (prot == 5) | |
1521 | np = 0x20; | |
1522 | else if (prot == 4) | |
1523 | np = 0x10; | |
1524 | else if (prot == 3) | |
1525 | np = 0x04; | |
1526 | else if (prot == 1) | |
1527 | np = 0x02; | |
1528 | else if (prot == 0) | |
1529 | np = 0x01; | |
e30b7e49 | 1530 | |
1531 | if (VirtualProtect (addr, len, np, &op)) | |
1532 | return 0; | |
1533 | else | |
1534 | return -1; | |
e30b7e49 | 1535 | } |
1536 | ||
f1959ea2 | 1537 | #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */ |
e30b7e49 | 1538 | |
87e97de6 | 1539 | #ifdef TRANSFER_FROM_TRAMPOLINE |
1540 | TRANSFER_FROM_TRAMPOLINE | |
62c63f32 | 1541 | #endif |
62c63f32 | 1542 | #endif /* L_trampoline */ |
1543 | \f | |
e678484c | 1544 | #ifndef __CYGWIN__ |
62c63f32 | 1545 | #ifdef L__main |
1546 | ||
1547 | #include "gbl-ctors.h" | |
0c945479 | 1548 | /* Some systems use __main in a way incompatible with its use in gcc, in these |
1549 | cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to | |
1550 | give the same symbol without quotes for an alternative entry point. You | |
a92771b8 | 1551 | must define both, or neither. */ |
0c945479 | 1552 | #ifndef NAME__MAIN |
1553 | #define NAME__MAIN "__main" | |
1554 | #define SYMBOL__MAIN __main | |
1555 | #endif | |
62c63f32 | 1556 | |
8313a782 | 1557 | #ifdef INIT_SECTION_ASM_OP |
1558 | #undef HAS_INIT_SECTION | |
1559 | #define HAS_INIT_SECTION | |
1560 | #endif | |
1561 | ||
1562 | #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF) | |
a6881cf3 | 1563 | |
1564 | /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this | |
1565 | code to run constructors. In that case, we need to handle EH here, too. */ | |
1566 | ||
eb86c6db | 1567 | #ifdef EH_FRAME_SECTION_NAME |
899c9389 | 1568 | #include "unwind-dw2-fde.h" |
a6881cf3 | 1569 | extern unsigned char __EH_FRAME_BEGIN__[]; |
1570 | #endif | |
1571 | ||
62c63f32 | 1572 | /* Run all the global destructors on exit from the program. */ |
1573 | ||
1574 | void | |
71218a21 | 1575 | __do_global_dtors (void) |
62c63f32 | 1576 | { |
3a158972 | 1577 | #ifdef DO_GLOBAL_DTORS_BODY |
1578 | DO_GLOBAL_DTORS_BODY; | |
1579 | #else | |
113f9ca7 | 1580 | static func_ptr *p = __DTOR_LIST__ + 1; |
1581 | while (*p) | |
1582 | { | |
1583 | p++; | |
1584 | (*(p-1)) (); | |
1585 | } | |
3a158972 | 1586 | #endif |
eb86c6db | 1587 | #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION) |
3b1bfdbe | 1588 | { |
1589 | static int completed = 0; | |
1590 | if (! completed) | |
1591 | { | |
1592 | completed = 1; | |
1593 | __deregister_frame_info (__EH_FRAME_BEGIN__); | |
1594 | } | |
1595 | } | |
a6881cf3 | 1596 | #endif |
62c63f32 | 1597 | } |
b7c87ff2 | 1598 | #endif |
62c63f32 | 1599 | |
8313a782 | 1600 | #ifndef HAS_INIT_SECTION |
62c63f32 | 1601 | /* Run all the global constructors on entry to the program. */ |
1602 | ||
62c63f32 | 1603 | void |
71218a21 | 1604 | __do_global_ctors (void) |
62c63f32 | 1605 | { |
eb86c6db | 1606 | #ifdef EH_FRAME_SECTION_NAME |
a6881cf3 | 1607 | { |
1608 | static struct object object; | |
1609 | __register_frame_info (__EH_FRAME_BEGIN__, &object); | |
1610 | } | |
1611 | #endif | |
62c63f32 | 1612 | DO_GLOBAL_CTORS_BODY; |
bd84a596 | 1613 | atexit (__do_global_dtors); |
62c63f32 | 1614 | } |
8313a782 | 1615 | #endif /* no HAS_INIT_SECTION */ |
62c63f32 | 1616 | |
8313a782 | 1617 | #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main) |
62c63f32 | 1618 | /* Subroutine called automatically by `main'. |
1619 | Compiling a global function named `main' | |
1620 | produces an automatic call to this function at the beginning. | |
1621 | ||
1622 | For many systems, this routine calls __do_global_ctors. | |
1623 | For systems which support a .init section we use the .init section | |
1624 | to run __do_global_ctors, so we need not do anything here. */ | |
1625 | ||
f2dc410e | 1626 | extern void SYMBOL__MAIN (void); |
62c63f32 | 1627 | void |
f2dc410e | 1628 | SYMBOL__MAIN (void) |
62c63f32 | 1629 | { |
1630 | /* Support recursive calls to `main': run initializers just once. */ | |
5233d224 | 1631 | static int initialized; |
62c63f32 | 1632 | if (! initialized) |
1633 | { | |
1634 | initialized = 1; | |
1635 | __do_global_ctors (); | |
1636 | } | |
1637 | } | |
8313a782 | 1638 | #endif /* no HAS_INIT_SECTION or INVOKE__main */ |
62c63f32 | 1639 | |
1640 | #endif /* L__main */ | |
e678484c | 1641 | #endif /* __CYGWIN__ */ |
62c63f32 | 1642 | \f |
a0f2694a | 1643 | #ifdef L_ctors |
62c63f32 | 1644 | |
1645 | #include "gbl-ctors.h" | |
1646 | ||
1647 | /* Provide default definitions for the lists of constructors and | |
98ae6ed6 | 1648 | destructors, so that we don't get linker errors. These symbols are |
1649 | intentionally bss symbols, so that gld and/or collect will provide | |
1650 | the right values. */ | |
62c63f32 | 1651 | |
1652 | /* We declare the lists here with two elements each, | |
98ae6ed6 | 1653 | so that they are valid empty lists if no other definition is loaded. |
1654 | ||
1655 | If we are using the old "set" extensions to have the gnu linker | |
1656 | collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__ | |
1657 | must be in the bss/common section. | |
1658 | ||
1659 | Long term no port should use those extensions. But many still do. */ | |
b13ae905 | 1660 | #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY) |
e535c327 | 1661 | #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2) |
d069195c | 1662 | func_ptr __CTOR_LIST__[2] = {0, 0}; |
1663 | func_ptr __DTOR_LIST__[2] = {0, 0}; | |
98ae6ed6 | 1664 | #else |
1665 | func_ptr __CTOR_LIST__[2]; | |
1666 | func_ptr __DTOR_LIST__[2]; | |
1667 | #endif | |
b13ae905 | 1668 | #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */ |
a0f2694a | 1669 | #endif /* L_ctors */ |
62c63f32 | 1670 |