Nuke USB_DO_ATTACH and remove device_t dv, since it is no longer needed.
[dragonfly.git] / contrib / gcc-3.4 / gcc / libgcc2.c
blob4f45b09d284e0b4af8c93920a83eb7c9ffa053ba
1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 This file is part of GCC.
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.
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.)
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.
27 You should have received a copy of the GNU General Public License
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. */
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"
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. */
40 #include "tconfig.h"
41 #include "tsystem.h"
42 #include "coretypes.h"
43 #include "tm.h"
45 /* Don't use `fancy_abort' here even if config.h says to use it. */
46 #ifdef abort
47 #undef abort
48 #endif
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
52 #else
53 #define ATTRIBUTE_HIDDEN
54 #endif
56 #include "libgcc2.h"
58 #ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
60 #endif
62 #if defined (L_negdi2)
63 DWtype
64 __negdi2 (DWtype u)
66 const DWunion uu = {.ll = u};
67 const DWunion w = { {.low = -uu.s.low,
68 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
70 return w.ll;
72 #endif
74 #ifdef L_addvsi3
75 Wtype
76 __addvSI3 (Wtype a, Wtype b)
78 const Wtype w = a + b;
80 if (b >= 0 ? w < a : w > a)
81 abort ();
83 return w;
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
86 SItype
87 __addvsi3 (SItype a, SItype b)
89 const SItype w = a + b;
91 if (b >= 0 ? w < a : w > a)
92 abort ();
94 return w;
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
97 #endif
99 #ifdef L_addvdi3
100 DWtype
101 __addvDI3 (DWtype a, DWtype b)
103 const DWtype w = a + b;
105 if (b >= 0 ? w < a : w > a)
106 abort ();
108 return w;
110 #endif
112 #ifdef L_subvsi3
113 Wtype
114 __subvSI3 (Wtype a, Wtype b)
116 const Wtype w = a - b;
118 if (b >= 0 ? w > a : w < a)
119 abort ();
121 return w;
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
124 SItype
125 __subvsi3 (SItype a, SItype b)
127 const SItype w = a - b;
129 if (b >= 0 ? w > a : w < a)
130 abort ();
132 return w;
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
135 #endif
137 #ifdef L_subvdi3
138 DWtype
139 __subvDI3 (DWtype a, DWtype b)
141 const DWtype w = a - b;
143 if (b >= 0 ? w > a : w < a)
144 abort ();
146 return w;
148 #endif
150 #ifdef L_mulvsi3
151 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
152 Wtype
153 __mulvSI3 (Wtype a, Wtype b)
155 const DWtype w = (DWtype) a * (DWtype) b;
157 if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1))
158 abort ();
160 return w;
162 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
163 #undef WORD_SIZE
164 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
165 SItype
166 __mulvsi3 (SItype a, SItype b)
168 const DItype w = (DItype) a * (DItype) b;
170 if ((SItype) (w >> WORD_SIZE) != (SItype) w >> (WORD_SIZE-1))
171 abort ();
173 return w;
175 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
176 #endif
178 #ifdef L_negvsi2
179 Wtype
180 __negvSI2 (Wtype a)
182 const Wtype w = -a;
184 if (a >= 0 ? w > 0 : w < 0)
185 abort ();
187 return w;
189 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
190 SItype
191 __negvsi2 (SItype a)
193 const SItype w = -a;
195 if (a >= 0 ? w > 0 : w < 0)
196 abort ();
198 return w;
200 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
201 #endif
203 #ifdef L_negvdi2
204 DWtype
205 __negvDI2 (DWtype a)
207 const DWtype w = -a;
209 if (a >= 0 ? w > 0 : w < 0)
210 abort ();
212 return w;
214 #endif
216 #ifdef L_absvsi2
217 Wtype
218 __absvSI2 (Wtype a)
220 Wtype w = a;
222 if (a < 0)
223 #ifdef L_negvsi2
224 w = __negvSI2 (a);
225 #else
226 w = -a;
228 if (w < 0)
229 abort ();
230 #endif
232 return w;
234 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
235 SItype
236 __absvsi2 (SItype a)
238 SItype w = a;
240 if (a < 0)
241 #ifdef L_negvsi2
242 w = __negvsi2 (a);
243 #else
244 w = -a;
246 if (w < 0)
247 abort ();
248 #endif
250 return w;
252 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
253 #endif
255 #ifdef L_absvdi2
256 DWtype
257 __absvDI2 (DWtype a)
259 DWtype w = a;
261 if (a < 0)
262 #ifdef L_negvdi2
263 w = __negvDI2 (a);
264 #else
265 w = -a;
267 if (w < 0)
268 abort ();
269 #endif
271 return w;
273 #endif
275 #ifdef L_mulvdi3
276 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
277 DWtype
278 __mulvDI3 (DWtype u, DWtype v)
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu = {.ll = u};
283 const DWunion vv = {.ll = v};
285 if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
287 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype) uu.s.low * (DWtype) vv.s.low;
294 else
296 /* Two multiplications. */
297 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
298 * (UDWtype) (UWtype) vv.s.low};
299 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
300 * (UDWtype) (UWtype) vv.s.high};
302 if (vv.s.high < 0)
303 w1.s.high -= uu.s.low;
304 if (uu.s.low < 0)
305 w1.ll -= vv.ll;
306 w1.ll += (UWtype) w0.s.high;
307 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
309 w0.s.high = w1.s.low;
310 return w0.ll;
314 else
316 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
321 * (UDWtype) (UWtype) vv.s.low};
322 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
323 * (UDWtype) (UWtype) vv.s.low};
325 if (uu.s.high < 0)
326 w1.s.high -= vv.s.low;
327 if (vv.s.low < 0)
328 w1.ll -= uu.ll;
329 w1.ll += (UWtype) w0.s.high;
330 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
332 w0.s.high = w1.s.low;
333 return w0.ll;
336 else
338 /* A few sign checks and a single multiplication. */
339 if (uu.s.high >= 0)
341 if (vv.s.high >= 0)
343 if (uu.s.high == 0 && vv.s.high == 0)
345 const DWtype w = (UDWtype) (UWtype) uu.s.low
346 * (UDWtype) (UWtype) vv.s.low;
347 if (__builtin_expect (w >= 0, 1))
348 return w;
351 else
353 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
355 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
356 * (UDWtype) (UWtype) vv.s.low};
358 ww.s.high -= uu.s.low;
359 if (__builtin_expect (ww.s.high < 0, 1))
360 return ww.ll;
364 else
366 if (vv.s.high >= 0)
368 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
370 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
371 * (UDWtype) (UWtype) vv.s.low};
373 ww.s.high -= vv.s.low;
374 if (__builtin_expect (ww.s.high < 0, 1))
375 return ww.ll;
378 else
380 if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
382 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
383 * (UDWtype) (UWtype) vv.s.low};
385 ww.s.high -= uu.s.low;
386 ww.s.high -= vv.s.low;
387 if (__builtin_expect (ww.s.high >= 0, 1))
388 return ww.ll;
395 /* Overflow. */
396 abort ();
398 #endif
401 /* Unless shift functions are defined with full ANSI prototypes,
402 parameter b will be promoted to int if word_type is smaller than an int. */
403 #ifdef L_lshrdi3
404 DWtype
405 __lshrdi3 (DWtype u, word_type b)
407 if (b == 0)
408 return u;
410 const DWunion uu = {.ll = u};
411 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
412 DWunion w;
414 if (bm <= 0)
416 w.s.high = 0;
417 w.s.low = (UWtype) uu.s.high >> -bm;
419 else
421 const UWtype carries = (UWtype) uu.s.high << bm;
423 w.s.high = (UWtype) uu.s.high >> b;
424 w.s.low = ((UWtype) uu.s.low >> b) | carries;
427 return w.ll;
429 #endif
431 #ifdef L_ashldi3
432 DWtype
433 __ashldi3 (DWtype u, word_type b)
435 if (b == 0)
436 return u;
438 const DWunion uu = {.ll = u};
439 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
440 DWunion w;
442 if (bm <= 0)
444 w.s.low = 0;
445 w.s.high = (UWtype) uu.s.low << -bm;
447 else
449 const UWtype carries = (UWtype) uu.s.low >> bm;
451 w.s.low = (UWtype) uu.s.low << b;
452 w.s.high = ((UWtype) uu.s.high << b) | carries;
455 return w.ll;
457 #endif
459 #ifdef L_ashrdi3
460 DWtype
461 __ashrdi3 (DWtype u, word_type b)
463 if (b == 0)
464 return u;
466 const DWunion uu = {.ll = u};
467 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
468 DWunion w;
470 if (bm <= 0)
472 /* w.s.high = 1..1 or 0..0 */
473 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
474 w.s.low = uu.s.high >> -bm;
476 else
478 const UWtype carries = (UWtype) uu.s.high << bm;
480 w.s.high = uu.s.high >> b;
481 w.s.low = ((UWtype) uu.s.low >> b) | carries;
484 return w.ll;
486 #endif
488 #ifdef L_ffssi2
489 #undef int
490 extern int __ffsSI2 (UWtype u);
492 __ffsSI2 (UWtype u)
494 UWtype count;
496 if (u == 0)
497 return 0;
499 count_trailing_zeros (count, u);
500 return count + 1;
502 #endif
504 #ifdef L_ffsdi2
505 #undef int
506 extern int __ffsDI2 (DWtype u);
508 __ffsDI2 (DWtype u)
510 const DWunion uu = {.ll = u};
511 UWtype word, count, add;
513 if (uu.s.low != 0)
514 word = uu.s.low, add = 0;
515 else if (uu.s.high != 0)
516 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
517 else
518 return 0;
520 count_trailing_zeros (count, word);
521 return count + add + 1;
523 #endif
525 #ifdef L_muldi3
526 DWtype
527 __muldi3 (DWtype u, DWtype v)
529 const DWunion uu = {.ll = u};
530 const DWunion vv = {.ll = v};
531 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
533 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
534 + (UWtype) uu.s.high * (UWtype) vv.s.low);
536 return w.ll;
538 #endif
540 #if (defined (L_udivdi3) || defined (L_divdi3) || \
541 defined (L_umoddi3) || defined (L_moddi3))
542 #if defined (sdiv_qrnnd)
543 #define L_udiv_w_sdiv
544 #endif
545 #endif
547 #ifdef L_udiv_w_sdiv
548 #if defined (sdiv_qrnnd)
549 #if (defined (L_udivdi3) || defined (L_divdi3) || \
550 defined (L_umoddi3) || defined (L_moddi3))
551 static inline __attribute__ ((__always_inline__))
552 #endif
553 UWtype
554 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
556 UWtype q, r;
557 UWtype c0, c1, b1;
559 if ((Wtype) d >= 0)
561 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
563 /* dividend, divisor, and quotient are nonnegative */
564 sdiv_qrnnd (q, r, a1, a0, d);
566 else
568 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
569 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
570 /* Divide (c1*2^32 + c0) by d */
571 sdiv_qrnnd (q, r, c1, c0, d);
572 /* Add 2^31 to quotient */
573 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
576 else
578 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
579 c1 = a1 >> 1; /* A/2 */
580 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
582 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
584 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
586 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
587 if ((d & 1) != 0)
589 if (r >= q)
590 r = r - q;
591 else if (q - r <= d)
593 r = r - q + d;
594 q--;
596 else
598 r = r - q + 2*d;
599 q -= 2;
603 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
605 c1 = (b1 - 1) - c1;
606 c0 = ~c0; /* logical NOT */
608 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
610 q = ~q; /* (A/2)/b1 */
611 r = (b1 - 1) - r;
613 r = 2*r + (a0 & 1); /* A/(2*b1) */
615 if ((d & 1) != 0)
617 if (r >= q)
618 r = r - q;
619 else if (q - r <= d)
621 r = r - q + d;
622 q--;
624 else
626 r = r - q + 2*d;
627 q -= 2;
631 else /* Implies c1 = b1 */
632 { /* Hence a1 = d - 1 = 2*b1 - 1 */
633 if (a0 >= -d)
635 q = -1;
636 r = a0 + d;
638 else
640 q = -2;
641 r = a0 + 2*d;
646 *rp = r;
647 return q;
649 #else
650 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
651 UWtype
652 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
653 UWtype a1 __attribute__ ((__unused__)),
654 UWtype a0 __attribute__ ((__unused__)),
655 UWtype d __attribute__ ((__unused__)))
657 return 0;
659 #endif
660 #endif
662 #if (defined (L_udivdi3) || defined (L_divdi3) || \
663 defined (L_umoddi3) || defined (L_moddi3))
664 #define L_udivmoddi4
665 #endif
667 #ifdef L_clz
668 const UQItype __clz_tab[] =
670 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,
671 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,
672 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,
673 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,
674 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,
675 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,
676 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,
677 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,
679 #endif
681 #ifdef L_clzsi2
682 #undef int
683 extern int __clzSI2 (UWtype x);
685 __clzSI2 (UWtype x)
687 Wtype ret;
689 count_leading_zeros (ret, x);
691 return ret;
693 #endif
695 #ifdef L_clzdi2
696 #undef int
697 extern int __clzDI2 (UDWtype x);
699 __clzDI2 (UDWtype x)
701 const DWunion uu = {.ll = x};
702 UWtype word;
703 Wtype ret, add;
705 if (uu.s.high)
706 word = uu.s.high, add = 0;
707 else
708 word = uu.s.low, add = W_TYPE_SIZE;
710 count_leading_zeros (ret, word);
711 return ret + add;
713 #endif
715 #ifdef L_ctzsi2
716 #undef int
717 extern int __ctzSI2 (UWtype x);
719 __ctzSI2 (UWtype x)
721 Wtype ret;
723 count_trailing_zeros (ret, x);
725 return ret;
727 #endif
729 #ifdef L_ctzdi2
730 #undef int
731 extern int __ctzDI2 (UDWtype x);
733 __ctzDI2 (UDWtype x)
735 const DWunion uu = {.ll = x};
736 UWtype word;
737 Wtype ret, add;
739 if (uu.s.low)
740 word = uu.s.low, add = 0;
741 else
742 word = uu.s.high, add = W_TYPE_SIZE;
744 count_trailing_zeros (ret, word);
745 return ret + add;
747 #endif
749 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
750 || defined (L_popcount_tab))
751 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
752 #endif
754 #ifdef L_popcount_tab
755 const UQItype __popcount_tab[] =
757 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,
758 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,
759 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,
760 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,
761 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,
762 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,
763 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,
764 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,
766 #endif
768 #ifdef L_popcountsi2
769 #undef int
770 extern int __popcountSI2 (UWtype x);
772 __popcountSI2 (UWtype x)
774 UWtype i, ret = 0;
776 for (i = 0; i < W_TYPE_SIZE; i += 8)
777 ret += __popcount_tab[(x >> i) & 0xff];
779 return ret;
781 #endif
783 #ifdef L_popcountdi2
784 #undef int
785 extern int __popcountDI2 (UDWtype x);
787 __popcountDI2 (UDWtype x)
789 UWtype i, ret = 0;
791 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
792 ret += __popcount_tab[(x >> i) & 0xff];
794 return ret;
796 #endif
798 #ifdef L_paritysi2
799 #undef int
800 extern int __paritySI2 (UWtype x);
802 __paritySI2 (UWtype x)
804 #if W_TYPE_SIZE > 64
805 # error "fill out the table"
806 #endif
807 #if W_TYPE_SIZE > 32
808 x ^= x >> 32;
809 #endif
810 #if W_TYPE_SIZE > 16
811 x ^= x >> 16;
812 #endif
813 x ^= x >> 8;
814 x ^= x >> 4;
815 x &= 0xf;
816 return (0x6996 >> x) & 1;
818 #endif
820 #ifdef L_paritydi2
821 #undef int
822 extern int __parityDI2 (UDWtype x);
824 __parityDI2 (UDWtype x)
826 const DWunion uu = {.ll = x};
827 UWtype nx = uu.s.low ^ uu.s.high;
829 #if W_TYPE_SIZE > 64
830 # error "fill out the table"
831 #endif
832 #if W_TYPE_SIZE > 32
833 nx ^= nx >> 32;
834 #endif
835 #if W_TYPE_SIZE > 16
836 nx ^= nx >> 16;
837 #endif
838 nx ^= nx >> 8;
839 nx ^= nx >> 4;
840 nx &= 0xf;
841 return (0x6996 >> nx) & 1;
843 #endif
845 #ifdef L_udivmoddi4
847 #if (defined (L_udivdi3) || defined (L_divdi3) || \
848 defined (L_umoddi3) || defined (L_moddi3))
849 static inline __attribute__ ((__always_inline__))
850 #endif
851 UDWtype
852 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
854 const DWunion nn = {.ll = n};
855 const DWunion dd = {.ll = d};
856 DWunion rr;
857 UWtype d0, d1, n0, n1, n2;
858 UWtype q0, q1;
859 UWtype b, bm;
861 d0 = dd.s.low;
862 d1 = dd.s.high;
863 n0 = nn.s.low;
864 n1 = nn.s.high;
866 #if !UDIV_NEEDS_NORMALIZATION
867 if (d1 == 0)
869 if (d0 > n1)
871 /* 0q = nn / 0D */
873 udiv_qrnnd (q0, n0, n1, n0, d0);
874 q1 = 0;
876 /* Remainder in n0. */
878 else
880 /* qq = NN / 0d */
882 if (d0 == 0)
883 d0 = 1 / d0; /* Divide intentionally by zero. */
885 udiv_qrnnd (q1, n1, 0, n1, d0);
886 udiv_qrnnd (q0, n0, n1, n0, d0);
888 /* Remainder in n0. */
891 if (rp != 0)
893 rr.s.low = n0;
894 rr.s.high = 0;
895 *rp = rr.ll;
899 #else /* UDIV_NEEDS_NORMALIZATION */
901 if (d1 == 0)
903 if (d0 > n1)
905 /* 0q = nn / 0D */
907 count_leading_zeros (bm, d0);
909 if (bm != 0)
911 /* Normalize, i.e. make the most significant bit of the
912 denominator set. */
914 d0 = d0 << bm;
915 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
916 n0 = n0 << bm;
919 udiv_qrnnd (q0, n0, n1, n0, d0);
920 q1 = 0;
922 /* Remainder in n0 >> bm. */
924 else
926 /* qq = NN / 0d */
928 if (d0 == 0)
929 d0 = 1 / d0; /* Divide intentionally by zero. */
931 count_leading_zeros (bm, d0);
933 if (bm == 0)
935 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
936 conclude (the most significant bit of n1 is set) /\ (the
937 leading quotient digit q1 = 1).
939 This special case is necessary, not an optimization.
940 (Shifts counts of W_TYPE_SIZE are undefined.) */
942 n1 -= d0;
943 q1 = 1;
945 else
947 /* Normalize. */
949 b = W_TYPE_SIZE - bm;
951 d0 = d0 << bm;
952 n2 = n1 >> b;
953 n1 = (n1 << bm) | (n0 >> b);
954 n0 = n0 << bm;
956 udiv_qrnnd (q1, n1, n2, n1, d0);
959 /* n1 != d0... */
961 udiv_qrnnd (q0, n0, n1, n0, d0);
963 /* Remainder in n0 >> bm. */
966 if (rp != 0)
968 rr.s.low = n0 >> bm;
969 rr.s.high = 0;
970 *rp = rr.ll;
973 #endif /* UDIV_NEEDS_NORMALIZATION */
975 else
977 if (d1 > n1)
979 /* 00 = nn / DD */
981 q0 = 0;
982 q1 = 0;
984 /* Remainder in n1n0. */
985 if (rp != 0)
987 rr.s.low = n0;
988 rr.s.high = n1;
989 *rp = rr.ll;
992 else
994 /* 0q = NN / dd */
996 count_leading_zeros (bm, d1);
997 if (bm == 0)
999 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1000 conclude (the most significant bit of n1 is set) /\ (the
1001 quotient digit q0 = 0 or 1).
1003 This special case is necessary, not an optimization. */
1005 /* The condition on the next line takes advantage of that
1006 n1 >= d1 (true due to program flow). */
1007 if (n1 > d1 || n0 >= d0)
1009 q0 = 1;
1010 sub_ddmmss (n1, n0, n1, n0, d1, d0);
1012 else
1013 q0 = 0;
1015 q1 = 0;
1017 if (rp != 0)
1019 rr.s.low = n0;
1020 rr.s.high = n1;
1021 *rp = rr.ll;
1024 else
1026 UWtype m1, m0;
1027 /* Normalize. */
1029 b = W_TYPE_SIZE - bm;
1031 d1 = (d1 << bm) | (d0 >> b);
1032 d0 = d0 << bm;
1033 n2 = n1 >> b;
1034 n1 = (n1 << bm) | (n0 >> b);
1035 n0 = n0 << bm;
1037 udiv_qrnnd (q0, n1, n2, n1, d1);
1038 umul_ppmm (m1, m0, q0, d0);
1040 if (m1 > n1 || (m1 == n1 && m0 > n0))
1042 q0--;
1043 sub_ddmmss (m1, m0, m1, m0, d1, d0);
1046 q1 = 0;
1048 /* Remainder in (n1n0 - m1m0) >> bm. */
1049 if (rp != 0)
1051 sub_ddmmss (n1, n0, n1, n0, m1, m0);
1052 rr.s.low = (n1 << b) | (n0 >> bm);
1053 rr.s.high = n1 >> bm;
1054 *rp = rr.ll;
1060 const DWunion ww = {{.low = q0, .high = q1}};
1061 return ww.ll;
1063 #endif
1065 #ifdef L_divdi3
1066 DWtype
1067 __divdi3 (DWtype u, DWtype v)
1069 word_type c = 0;
1070 DWunion uu = {.ll = u};
1071 DWunion vv = {.ll = v};
1072 DWtype w;
1074 if (uu.s.high < 0)
1075 c = ~c,
1076 uu.ll = -uu.ll;
1077 if (vv.s.high < 0)
1078 c = ~c,
1079 vv.ll = -vv.ll;
1081 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1082 if (c)
1083 w = -w;
1085 return w;
1087 #endif
1089 #ifdef L_moddi3
1090 DWtype
1091 __moddi3 (DWtype u, DWtype v)
1093 word_type c = 0;
1094 DWunion uu = {.ll = u};
1095 DWunion vv = {.ll = v};
1096 DWtype w;
1098 if (uu.s.high < 0)
1099 c = ~c,
1100 uu.ll = -uu.ll;
1101 if (vv.s.high < 0)
1102 vv.ll = -vv.ll;
1104 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
1105 if (c)
1106 w = -w;
1108 return w;
1110 #endif
1112 #ifdef L_umoddi3
1113 UDWtype
1114 __umoddi3 (UDWtype u, UDWtype v)
1116 UDWtype w;
1118 (void) __udivmoddi4 (u, v, &w);
1120 return w;
1122 #endif
1124 #ifdef L_udivdi3
1125 UDWtype
1126 __udivdi3 (UDWtype n, UDWtype d)
1128 return __udivmoddi4 (n, d, (UDWtype *) 0);
1130 #endif
1132 #ifdef L_cmpdi2
1133 word_type
1134 __cmpdi2 (DWtype a, DWtype b)
1136 const DWunion au = {.ll = a};
1137 const DWunion bu = {.ll = b};
1139 if (au.s.high < bu.s.high)
1140 return 0;
1141 else if (au.s.high > bu.s.high)
1142 return 2;
1143 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1144 return 0;
1145 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1146 return 2;
1147 return 1;
1149 #endif
1151 #ifdef L_ucmpdi2
1152 word_type
1153 __ucmpdi2 (DWtype a, DWtype b)
1155 const DWunion au = {.ll = a};
1156 const DWunion bu = {.ll = b};
1158 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1159 return 0;
1160 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1161 return 2;
1162 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1163 return 0;
1164 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1165 return 2;
1166 return 1;
1168 #endif
1170 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1171 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1172 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1174 DWtype
1175 __fixunstfDI (TFtype a)
1177 if (a < 0)
1178 return 0;
1180 /* Compute high word of result, as a flonum. */
1181 const TFtype b = (a / HIGH_WORD_COEFF);
1182 /* Convert that to fixed (but not to DWtype!),
1183 and shift it into the high word. */
1184 UDWtype v = (UWtype) b;
1185 v <<= WORD_SIZE;
1186 /* Remove high part from the TFtype, leaving the low part as flonum. */
1187 a -= (TFtype)v;
1188 /* Convert that to fixed (but not to DWtype!) and add it in.
1189 Sometimes A comes out negative. This is significant, since
1190 A has more bits than a long int does. */
1191 if (a < 0)
1192 v -= (UWtype) (- a);
1193 else
1194 v += (UWtype) a;
1195 return v;
1197 #endif
1199 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1200 DWtype
1201 __fixtfdi (TFtype a)
1203 if (a < 0)
1204 return - __fixunstfDI (-a);
1205 return __fixunstfDI (a);
1207 #endif
1209 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1210 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1211 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1213 DWtype
1214 __fixunsxfDI (XFtype a)
1216 if (a < 0)
1217 return 0;
1219 /* Compute high word of result, as a flonum. */
1220 const XFtype b = (a / HIGH_WORD_COEFF);
1221 /* Convert that to fixed (but not to DWtype!),
1222 and shift it into the high word. */
1223 UDWtype v = (UWtype) b;
1224 v <<= WORD_SIZE;
1225 /* Remove high part from the XFtype, leaving the low part as flonum. */
1226 a -= (XFtype)v;
1227 /* Convert that to fixed (but not to DWtype!) and add it in.
1228 Sometimes A comes out negative. This is significant, since
1229 A has more bits than a long int does. */
1230 if (a < 0)
1231 v -= (UWtype) (- a);
1232 else
1233 v += (UWtype) a;
1234 return v;
1236 #endif
1238 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1239 DWtype
1240 __fixxfdi (XFtype a)
1242 if (a < 0)
1243 return - __fixunsxfDI (-a);
1244 return __fixunsxfDI (a);
1246 #endif
1248 #ifdef L_fixunsdfdi
1249 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1250 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1252 DWtype
1253 __fixunsdfDI (DFtype a)
1255 /* Get high part of result. The division here will just moves the radix
1256 point and will not cause any rounding. Then the conversion to integral
1257 type chops result as desired. */
1258 const UWtype hi = a / HIGH_WORD_COEFF;
1260 /* Get low part of result. Convert `hi' to floating type and scale it back,
1261 then subtract this from the number being converted. This leaves the low
1262 part. Convert that to integral type. */
1263 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1265 /* Assemble result from the two parts. */
1266 return ((UDWtype) hi << WORD_SIZE) | lo;
1268 #endif
1270 #ifdef L_fixdfdi
1271 DWtype
1272 __fixdfdi (DFtype a)
1274 if (a < 0)
1275 return - __fixunsdfDI (-a);
1276 return __fixunsdfDI (a);
1278 #endif
1280 #ifdef L_fixunssfdi
1281 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1282 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1284 DWtype
1285 __fixunssfDI (SFtype original_a)
1287 /* Convert the SFtype to a DFtype, because that is surely not going
1288 to lose any bits. Some day someone else can write a faster version
1289 that avoids converting to DFtype, and verify it really works right. */
1290 const DFtype a = original_a;
1292 /* Get high part of result. The division here will just moves the radix
1293 point and will not cause any rounding. Then the conversion to integral
1294 type chops result as desired. */
1295 const UWtype hi = a / HIGH_WORD_COEFF;
1297 /* Get low part of result. Convert `hi' to floating type and scale it back,
1298 then subtract this from the number being converted. This leaves the low
1299 part. Convert that to integral type. */
1300 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1302 /* Assemble result from the two parts. */
1303 return ((UDWtype) hi << WORD_SIZE) | lo;
1305 #endif
1307 #ifdef L_fixsfdi
1308 DWtype
1309 __fixsfdi (SFtype a)
1311 if (a < 0)
1312 return - __fixunssfDI (-a);
1313 return __fixunssfDI (a);
1315 #endif
1317 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1318 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1319 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1320 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1322 XFtype
1323 __floatdixf (DWtype u)
1325 XFtype d = (Wtype) (u >> WORD_SIZE);
1326 d *= HIGH_HALFWORD_COEFF;
1327 d *= HIGH_HALFWORD_COEFF;
1328 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1330 return d;
1332 #endif
1334 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1335 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1336 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1337 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1339 TFtype
1340 __floatditf (DWtype u)
1342 TFtype d = (Wtype) (u >> WORD_SIZE);
1343 d *= HIGH_HALFWORD_COEFF;
1344 d *= HIGH_HALFWORD_COEFF;
1345 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1347 return d;
1349 #endif
1351 #ifdef L_floatdidf
1352 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1353 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1354 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1356 DFtype
1357 __floatdidf (DWtype u)
1359 DFtype d = (Wtype) (u >> WORD_SIZE);
1360 d *= HIGH_HALFWORD_COEFF;
1361 d *= HIGH_HALFWORD_COEFF;
1362 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1364 return d;
1366 #endif
1368 #ifdef L_floatdisf
1369 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1370 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1371 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1373 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1374 #define DF_SIZE DBL_MANT_DIG
1375 #define SF_SIZE FLT_MANT_DIG
1377 SFtype
1378 __floatdisf (DWtype u)
1380 /* Protect against double-rounding error.
1381 Represent any low-order bits, that might be truncated in DFmode,
1382 by a bit that won't be lost. The bit can go in anywhere below the
1383 rounding position of the SFmode. A fixed mask and bit position
1384 handles all usual configurations. It doesn't handle the case
1385 of 128-bit DImode, however. */
1386 if (DF_SIZE < DI_SIZE
1387 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1389 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1390 if (! (- ((DWtype) 1 << DF_SIZE) < u
1391 && u < ((DWtype) 1 << DF_SIZE)))
1393 if ((UDWtype) u & (REP_BIT - 1))
1395 u &= ~ (REP_BIT - 1);
1396 u |= REP_BIT;
1400 /* Do the calculation in DFmode
1401 so that we don't lose any of the precision of the high word
1402 while multiplying it. */
1403 DFtype f = (Wtype) (u >> WORD_SIZE);
1404 f *= HIGH_HALFWORD_COEFF;
1405 f *= HIGH_HALFWORD_COEFF;
1406 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1408 return (SFtype) f;
1410 #endif
1412 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1413 /* Reenable the normal types, in case limits.h needs them. */
1414 #undef char
1415 #undef short
1416 #undef int
1417 #undef long
1418 #undef unsigned
1419 #undef float
1420 #undef double
1421 #undef MIN
1422 #undef MAX
1423 #include <limits.h>
1425 UWtype
1426 __fixunsxfSI (XFtype a)
1428 if (a >= - (DFtype) Wtype_MIN)
1429 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1430 return (Wtype) a;
1432 #endif
1434 #ifdef L_fixunsdfsi
1435 /* Reenable the normal types, in case limits.h needs them. */
1436 #undef char
1437 #undef short
1438 #undef int
1439 #undef long
1440 #undef unsigned
1441 #undef float
1442 #undef double
1443 #undef MIN
1444 #undef MAX
1445 #include <limits.h>
1447 UWtype
1448 __fixunsdfSI (DFtype a)
1450 if (a >= - (DFtype) Wtype_MIN)
1451 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1452 return (Wtype) a;
1454 #endif
1456 #ifdef L_fixunssfsi
1457 /* Reenable the normal types, in case limits.h needs them. */
1458 #undef char
1459 #undef short
1460 #undef int
1461 #undef long
1462 #undef unsigned
1463 #undef float
1464 #undef double
1465 #undef MIN
1466 #undef MAX
1467 #include <limits.h>
1469 UWtype
1470 __fixunssfSI (SFtype a)
1472 if (a >= - (SFtype) Wtype_MIN)
1473 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1474 return (Wtype) a;
1476 #endif
1478 /* From here on down, the routines use normal data types. */
1480 #define SItype bogus_type
1481 #define USItype bogus_type
1482 #define DItype bogus_type
1483 #define UDItype bogus_type
1484 #define SFtype bogus_type
1485 #define DFtype bogus_type
1486 #undef Wtype
1487 #undef UWtype
1488 #undef HWtype
1489 #undef UHWtype
1490 #undef DWtype
1491 #undef UDWtype
1493 #undef char
1494 #undef short
1495 #undef int
1496 #undef long
1497 #undef unsigned
1498 #undef float
1499 #undef double
1501 #ifdef L__gcc_bcmp
1503 /* Like bcmp except the sign is meaningful.
1504 Result is negative if S1 is less than S2,
1505 positive if S1 is greater, 0 if S1 and S2 are equal. */
1508 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1510 while (size > 0)
1512 const unsigned char c1 = *s1++, c2 = *s2++;
1513 if (c1 != c2)
1514 return c1 - c2;
1515 size--;
1517 return 0;
1520 #endif
1522 /* __eprintf used to be used by GCC's private version of <assert.h>.
1523 We no longer provide that header, but this routine remains in libgcc.a
1524 for binary backward compatibility. Note that it is not included in
1525 the shared version of libgcc. */
1526 #ifdef L_eprintf
1527 #ifndef inhibit_libc
1529 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1530 #include <stdio.h>
1532 void
1533 __eprintf (const char *string, const char *expression,
1534 unsigned int line, const char *filename)
1536 fprintf (stderr, string, expression, line, filename);
1537 fflush (stderr);
1538 abort ();
1541 #endif
1542 #endif
1545 #ifdef L_clear_cache
1546 /* Clear part of an instruction cache. */
1548 void
1549 __clear_cache (char *beg __attribute__((__unused__)),
1550 char *end __attribute__((__unused__)))
1552 #ifdef CLEAR_INSN_CACHE
1553 CLEAR_INSN_CACHE (beg, end);
1554 #endif /* CLEAR_INSN_CACHE */
1557 #endif /* L_clear_cache */
1559 #ifdef L_enable_execute_stack
1560 /* Attempt to turn on execute permission for the stack. */
1562 #ifdef ENABLE_EXECUTE_STACK
1563 ENABLE_EXECUTE_STACK
1564 #else
1565 void
1566 __enable_execute_stack (void *addr __attribute__((__unused__)))
1568 #endif /* ENABLE_EXECUTE_STACK */
1570 #endif /* L_enable_execute_stack */
1572 #ifdef L_trampoline
1574 /* Jump to a trampoline, loading the static chain address. */
1576 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1578 long
1579 getpagesize (void)
1581 #ifdef _ALPHA_
1582 return 8192;
1583 #else
1584 return 4096;
1585 #endif
1588 #ifdef __i386__
1589 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1590 #endif
1593 mprotect (char *addr, int len, int prot)
1595 int np, op;
1597 if (prot == 7)
1598 np = 0x40;
1599 else if (prot == 5)
1600 np = 0x20;
1601 else if (prot == 4)
1602 np = 0x10;
1603 else if (prot == 3)
1604 np = 0x04;
1605 else if (prot == 1)
1606 np = 0x02;
1607 else if (prot == 0)
1608 np = 0x01;
1610 if (VirtualProtect (addr, len, np, &op))
1611 return 0;
1612 else
1613 return -1;
1616 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1618 #ifdef TRANSFER_FROM_TRAMPOLINE
1619 TRANSFER_FROM_TRAMPOLINE
1620 #endif
1621 #endif /* L_trampoline */
1623 #ifndef __CYGWIN__
1624 #ifdef L__main
1626 #include "gbl-ctors.h"
1627 /* Some systems use __main in a way incompatible with its use in gcc, in these
1628 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1629 give the same symbol without quotes for an alternative entry point. You
1630 must define both, or neither. */
1631 #ifndef NAME__MAIN
1632 #define NAME__MAIN "__main"
1633 #define SYMBOL__MAIN __main
1634 #endif
1636 #ifdef INIT_SECTION_ASM_OP
1637 #undef HAS_INIT_SECTION
1638 #define HAS_INIT_SECTION
1639 #endif
1641 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1643 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1644 code to run constructors. In that case, we need to handle EH here, too. */
1646 #ifdef EH_FRAME_SECTION_NAME
1647 #include "unwind-dw2-fde.h"
1648 extern unsigned char __EH_FRAME_BEGIN__[];
1649 #endif
1651 /* Run all the global destructors on exit from the program. */
1653 void
1654 __do_global_dtors (void)
1656 #ifdef DO_GLOBAL_DTORS_BODY
1657 DO_GLOBAL_DTORS_BODY;
1658 #else
1659 static func_ptr *p = __DTOR_LIST__ + 1;
1660 while (*p)
1662 p++;
1663 (*(p-1)) ();
1665 #endif
1666 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1668 static int completed = 0;
1669 if (! completed)
1671 completed = 1;
1672 __deregister_frame_info (__EH_FRAME_BEGIN__);
1675 #endif
1677 #endif
1679 #ifndef HAS_INIT_SECTION
1680 /* Run all the global constructors on entry to the program. */
1682 void
1683 __do_global_ctors (void)
1685 #ifdef EH_FRAME_SECTION_NAME
1687 static struct object object;
1688 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1690 #endif
1691 DO_GLOBAL_CTORS_BODY;
1692 atexit (__do_global_dtors);
1694 #endif /* no HAS_INIT_SECTION */
1696 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1697 /* Subroutine called automatically by `main'.
1698 Compiling a global function named `main'
1699 produces an automatic call to this function at the beginning.
1701 For many systems, this routine calls __do_global_ctors.
1702 For systems which support a .init section we use the .init section
1703 to run __do_global_ctors, so we need not do anything here. */
1705 extern void SYMBOL__MAIN (void);
1706 void
1707 SYMBOL__MAIN (void)
1709 /* Support recursive calls to `main': run initializers just once. */
1710 static int initialized;
1711 if (! initialized)
1713 initialized = 1;
1714 __do_global_ctors ();
1717 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1719 #endif /* L__main */
1720 #endif /* __CYGWIN__ */
1722 #ifdef L_ctors
1724 #include "gbl-ctors.h"
1726 /* Provide default definitions for the lists of constructors and
1727 destructors, so that we don't get linker errors. These symbols are
1728 intentionally bss symbols, so that gld and/or collect will provide
1729 the right values. */
1731 /* We declare the lists here with two elements each,
1732 so that they are valid empty lists if no other definition is loaded.
1734 If we are using the old "set" extensions to have the gnu linker
1735 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1736 must be in the bss/common section.
1738 Long term no port should use those extensions. But many still do. */
1739 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1740 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1741 func_ptr __CTOR_LIST__[2] = {0, 0};
1742 func_ptr __DTOR_LIST__[2] = {0, 0};
1743 #else
1744 func_ptr __CTOR_LIST__[2];
1745 func_ptr __DTOR_LIST__[2];
1746 #endif
1747 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1748 #endif /* L_ctors */