* config/sparc/sparc.c (load_pic_register): Emit the appropriate
[official-gcc.git] / gcc / libgcc2.c
blob1b1455d5d8d785870a71c8ccd621dc9ff8d8cbef
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, 2004 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
491 __ffsSI2 (UWtype u)
493 UWtype count;
495 if (u == 0)
496 return 0;
498 count_trailing_zeros (count, u);
499 return count + 1;
501 #endif
503 #ifdef L_ffsdi2
504 #undef int
506 __ffsDI2 (DWtype u)
508 const DWunion uu = {.ll = u};
509 UWtype word, count, add;
511 if (uu.s.low != 0)
512 word = uu.s.low, add = 0;
513 else if (uu.s.high != 0)
514 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
515 else
516 return 0;
518 count_trailing_zeros (count, word);
519 return count + add + 1;
521 #endif
523 #ifdef L_muldi3
524 DWtype
525 __muldi3 (DWtype u, DWtype v)
527 const DWunion uu = {.ll = u};
528 const DWunion vv = {.ll = v};
529 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
531 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
532 + (UWtype) uu.s.high * (UWtype) vv.s.low);
534 return w.ll;
536 #endif
538 #if (defined (L_udivdi3) || defined (L_divdi3) || \
539 defined (L_umoddi3) || defined (L_moddi3))
540 #if defined (sdiv_qrnnd)
541 #define L_udiv_w_sdiv
542 #endif
543 #endif
545 #ifdef L_udiv_w_sdiv
546 #if defined (sdiv_qrnnd)
547 #if (defined (L_udivdi3) || defined (L_divdi3) || \
548 defined (L_umoddi3) || defined (L_moddi3))
549 static inline __attribute__ ((__always_inline__))
550 #endif
551 UWtype
552 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
554 UWtype q, r;
555 UWtype c0, c1, b1;
557 if ((Wtype) d >= 0)
559 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
561 /* Dividend, divisor, and quotient are nonnegative. */
562 sdiv_qrnnd (q, r, a1, a0, d);
564 else
566 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
567 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
568 /* Divide (c1*2^32 + c0) by d. */
569 sdiv_qrnnd (q, r, c1, c0, d);
570 /* Add 2^31 to quotient. */
571 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
574 else
576 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
577 c1 = a1 >> 1; /* A/2 */
578 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
580 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
582 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
584 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
585 if ((d & 1) != 0)
587 if (r >= q)
588 r = r - q;
589 else if (q - r <= d)
591 r = r - q + d;
592 q--;
594 else
596 r = r - q + 2*d;
597 q -= 2;
601 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
603 c1 = (b1 - 1) - c1;
604 c0 = ~c0; /* logical NOT */
606 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
608 q = ~q; /* (A/2)/b1 */
609 r = (b1 - 1) - r;
611 r = 2*r + (a0 & 1); /* A/(2*b1) */
613 if ((d & 1) != 0)
615 if (r >= q)
616 r = r - q;
617 else if (q - r <= d)
619 r = r - q + d;
620 q--;
622 else
624 r = r - q + 2*d;
625 q -= 2;
629 else /* Implies c1 = b1 */
630 { /* Hence a1 = d - 1 = 2*b1 - 1 */
631 if (a0 >= -d)
633 q = -1;
634 r = a0 + d;
636 else
638 q = -2;
639 r = a0 + 2*d;
644 *rp = r;
645 return q;
647 #else
648 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
649 UWtype
650 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
651 UWtype a1 __attribute__ ((__unused__)),
652 UWtype a0 __attribute__ ((__unused__)),
653 UWtype d __attribute__ ((__unused__)))
655 return 0;
657 #endif
658 #endif
660 #if (defined (L_udivdi3) || defined (L_divdi3) || \
661 defined (L_umoddi3) || defined (L_moddi3))
662 #define L_udivmoddi4
663 #endif
665 #ifdef L_clz
666 const UQItype __clz_tab[] =
668 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,
669 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,
670 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,
671 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,
672 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,
673 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,
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,
677 #endif
679 #ifdef L_clzsi2
680 #undef int
682 __clzSI2 (UWtype x)
684 Wtype ret;
686 count_leading_zeros (ret, x);
688 return ret;
690 #endif
692 #ifdef L_clzdi2
693 #undef int
695 __clzDI2 (UDWtype x)
697 const DWunion uu = {.ll = x};
698 UWtype word;
699 Wtype ret, add;
701 if (uu.s.high)
702 word = uu.s.high, add = 0;
703 else
704 word = uu.s.low, add = W_TYPE_SIZE;
706 count_leading_zeros (ret, word);
707 return ret + add;
709 #endif
711 #ifdef L_ctzsi2
712 #undef int
714 __ctzSI2 (UWtype x)
716 Wtype ret;
718 count_trailing_zeros (ret, x);
720 return ret;
722 #endif
724 #ifdef L_ctzdi2
725 #undef int
727 __ctzDI2 (UDWtype x)
729 const DWunion uu = {.ll = x};
730 UWtype word;
731 Wtype ret, add;
733 if (uu.s.low)
734 word = uu.s.low, add = 0;
735 else
736 word = uu.s.high, add = W_TYPE_SIZE;
738 count_trailing_zeros (ret, word);
739 return ret + add;
741 #endif
743 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
744 || defined (L_popcount_tab))
745 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
746 #endif
748 #ifdef L_popcount_tab
749 const UQItype __popcount_tab[] =
751 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,
752 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,
753 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,
754 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,
755 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,
756 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,
757 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,
758 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,
760 #endif
762 #ifdef L_popcountsi2
763 #undef int
765 __popcountSI2 (UWtype x)
767 UWtype i, ret = 0;
769 for (i = 0; i < W_TYPE_SIZE; i += 8)
770 ret += __popcount_tab[(x >> i) & 0xff];
772 return ret;
774 #endif
776 #ifdef L_popcountdi2
777 #undef int
779 __popcountDI2 (UDWtype x)
781 UWtype i, ret = 0;
783 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
784 ret += __popcount_tab[(x >> i) & 0xff];
786 return ret;
788 #endif
790 #ifdef L_paritysi2
791 #undef int
793 __paritySI2 (UWtype x)
795 #if W_TYPE_SIZE > 64
796 # error "fill out the table"
797 #endif
798 #if W_TYPE_SIZE > 32
799 x ^= x >> 32;
800 #endif
801 #if W_TYPE_SIZE > 16
802 x ^= x >> 16;
803 #endif
804 x ^= x >> 8;
805 x ^= x >> 4;
806 x &= 0xf;
807 return (0x6996 >> x) & 1;
809 #endif
811 #ifdef L_paritydi2
812 #undef int
814 __parityDI2 (UDWtype x)
816 const DWunion uu = {.ll = x};
817 UWtype nx = uu.s.low ^ uu.s.high;
819 #if W_TYPE_SIZE > 64
820 # error "fill out the table"
821 #endif
822 #if W_TYPE_SIZE > 32
823 nx ^= nx >> 32;
824 #endif
825 #if W_TYPE_SIZE > 16
826 nx ^= nx >> 16;
827 #endif
828 nx ^= nx >> 8;
829 nx ^= nx >> 4;
830 nx &= 0xf;
831 return (0x6996 >> nx) & 1;
833 #endif
835 #ifdef L_udivmoddi4
837 #if (defined (L_udivdi3) || defined (L_divdi3) || \
838 defined (L_umoddi3) || defined (L_moddi3))
839 static inline __attribute__ ((__always_inline__))
840 #endif
841 UDWtype
842 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
844 const DWunion nn = {.ll = n};
845 const DWunion dd = {.ll = d};
846 DWunion rr;
847 UWtype d0, d1, n0, n1, n2;
848 UWtype q0, q1;
849 UWtype b, bm;
851 d0 = dd.s.low;
852 d1 = dd.s.high;
853 n0 = nn.s.low;
854 n1 = nn.s.high;
856 #if !UDIV_NEEDS_NORMALIZATION
857 if (d1 == 0)
859 if (d0 > n1)
861 /* 0q = nn / 0D */
863 udiv_qrnnd (q0, n0, n1, n0, d0);
864 q1 = 0;
866 /* Remainder in n0. */
868 else
870 /* qq = NN / 0d */
872 if (d0 == 0)
873 d0 = 1 / d0; /* Divide intentionally by zero. */
875 udiv_qrnnd (q1, n1, 0, n1, d0);
876 udiv_qrnnd (q0, n0, n1, n0, d0);
878 /* Remainder in n0. */
881 if (rp != 0)
883 rr.s.low = n0;
884 rr.s.high = 0;
885 *rp = rr.ll;
889 #else /* UDIV_NEEDS_NORMALIZATION */
891 if (d1 == 0)
893 if (d0 > n1)
895 /* 0q = nn / 0D */
897 count_leading_zeros (bm, d0);
899 if (bm != 0)
901 /* Normalize, i.e. make the most significant bit of the
902 denominator set. */
904 d0 = d0 << bm;
905 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
906 n0 = n0 << bm;
909 udiv_qrnnd (q0, n0, n1, n0, d0);
910 q1 = 0;
912 /* Remainder in n0 >> bm. */
914 else
916 /* qq = NN / 0d */
918 if (d0 == 0)
919 d0 = 1 / d0; /* Divide intentionally by zero. */
921 count_leading_zeros (bm, d0);
923 if (bm == 0)
925 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
926 conclude (the most significant bit of n1 is set) /\ (the
927 leading quotient digit q1 = 1).
929 This special case is necessary, not an optimization.
930 (Shifts counts of W_TYPE_SIZE are undefined.) */
932 n1 -= d0;
933 q1 = 1;
935 else
937 /* Normalize. */
939 b = W_TYPE_SIZE - bm;
941 d0 = d0 << bm;
942 n2 = n1 >> b;
943 n1 = (n1 << bm) | (n0 >> b);
944 n0 = n0 << bm;
946 udiv_qrnnd (q1, n1, n2, n1, d0);
949 /* n1 != d0... */
951 udiv_qrnnd (q0, n0, n1, n0, d0);
953 /* Remainder in n0 >> bm. */
956 if (rp != 0)
958 rr.s.low = n0 >> bm;
959 rr.s.high = 0;
960 *rp = rr.ll;
963 #endif /* UDIV_NEEDS_NORMALIZATION */
965 else
967 if (d1 > n1)
969 /* 00 = nn / DD */
971 q0 = 0;
972 q1 = 0;
974 /* Remainder in n1n0. */
975 if (rp != 0)
977 rr.s.low = n0;
978 rr.s.high = n1;
979 *rp = rr.ll;
982 else
984 /* 0q = NN / dd */
986 count_leading_zeros (bm, d1);
987 if (bm == 0)
989 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
990 conclude (the most significant bit of n1 is set) /\ (the
991 quotient digit q0 = 0 or 1).
993 This special case is necessary, not an optimization. */
995 /* The condition on the next line takes advantage of that
996 n1 >= d1 (true due to program flow). */
997 if (n1 > d1 || n0 >= d0)
999 q0 = 1;
1000 sub_ddmmss (n1, n0, n1, n0, d1, d0);
1002 else
1003 q0 = 0;
1005 q1 = 0;
1007 if (rp != 0)
1009 rr.s.low = n0;
1010 rr.s.high = n1;
1011 *rp = rr.ll;
1014 else
1016 UWtype m1, m0;
1017 /* Normalize. */
1019 b = W_TYPE_SIZE - bm;
1021 d1 = (d1 << bm) | (d0 >> b);
1022 d0 = d0 << bm;
1023 n2 = n1 >> b;
1024 n1 = (n1 << bm) | (n0 >> b);
1025 n0 = n0 << bm;
1027 udiv_qrnnd (q0, n1, n2, n1, d1);
1028 umul_ppmm (m1, m0, q0, d0);
1030 if (m1 > n1 || (m1 == n1 && m0 > n0))
1032 q0--;
1033 sub_ddmmss (m1, m0, m1, m0, d1, d0);
1036 q1 = 0;
1038 /* Remainder in (n1n0 - m1m0) >> bm. */
1039 if (rp != 0)
1041 sub_ddmmss (n1, n0, n1, n0, m1, m0);
1042 rr.s.low = (n1 << b) | (n0 >> bm);
1043 rr.s.high = n1 >> bm;
1044 *rp = rr.ll;
1050 const DWunion ww = {{.low = q0, .high = q1}};
1051 return ww.ll;
1053 #endif
1055 #ifdef L_divdi3
1056 DWtype
1057 __divdi3 (DWtype u, DWtype v)
1059 word_type c = 0;
1060 DWunion uu = {.ll = u};
1061 DWunion vv = {.ll = v};
1062 DWtype w;
1064 if (uu.s.high < 0)
1065 c = ~c,
1066 uu.ll = -uu.ll;
1067 if (vv.s.high < 0)
1068 c = ~c,
1069 vv.ll = -vv.ll;
1071 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1072 if (c)
1073 w = -w;
1075 return w;
1077 #endif
1079 #ifdef L_moddi3
1080 DWtype
1081 __moddi3 (DWtype u, DWtype v)
1083 word_type c = 0;
1084 DWunion uu = {.ll = u};
1085 DWunion vv = {.ll = v};
1086 DWtype w;
1088 if (uu.s.high < 0)
1089 c = ~c,
1090 uu.ll = -uu.ll;
1091 if (vv.s.high < 0)
1092 vv.ll = -vv.ll;
1094 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1095 if (c)
1096 w = -w;
1098 return w;
1100 #endif
1102 #ifdef L_umoddi3
1103 UDWtype
1104 __umoddi3 (UDWtype u, UDWtype v)
1106 UDWtype w;
1108 (void) __udivmoddi4 (u, v, &w);
1110 return w;
1112 #endif
1114 #ifdef L_udivdi3
1115 UDWtype
1116 __udivdi3 (UDWtype n, UDWtype d)
1118 return __udivmoddi4 (n, d, (UDWtype *) 0);
1120 #endif
1122 #ifdef L_cmpdi2
1123 word_type
1124 __cmpdi2 (DWtype a, DWtype b)
1126 const DWunion au = {.ll = a};
1127 const DWunion bu = {.ll = b};
1129 if (au.s.high < bu.s.high)
1130 return 0;
1131 else if (au.s.high > bu.s.high)
1132 return 2;
1133 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1134 return 0;
1135 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1136 return 2;
1137 return 1;
1139 #endif
1141 #ifdef L_ucmpdi2
1142 word_type
1143 __ucmpdi2 (DWtype a, DWtype b)
1145 const DWunion au = {.ll = a};
1146 const DWunion bu = {.ll = b};
1148 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1149 return 0;
1150 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1151 return 2;
1152 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1153 return 0;
1154 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1155 return 2;
1156 return 1;
1158 #endif
1160 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1161 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1162 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1164 DWtype
1165 __fixunstfDI (TFtype a)
1167 if (a < 0)
1168 return 0;
1170 /* Compute high word of result, as a flonum. */
1171 const TFtype b = (a / HIGH_WORD_COEFF);
1172 /* Convert that to fixed (but not to DWtype!),
1173 and shift it into the high word. */
1174 UDWtype v = (UWtype) b;
1175 v <<= WORD_SIZE;
1176 /* Remove high part from the TFtype, leaving the low part as flonum. */
1177 a -= (TFtype)v;
1178 /* Convert that to fixed (but not to DWtype!) and add it in.
1179 Sometimes A comes out negative. This is significant, since
1180 A has more bits than a long int does. */
1181 if (a < 0)
1182 v -= (UWtype) (- a);
1183 else
1184 v += (UWtype) a;
1185 return v;
1187 #endif
1189 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1190 DWtype
1191 __fixtfdi (TFtype a)
1193 if (a < 0)
1194 return - __fixunstfDI (-a);
1195 return __fixunstfDI (a);
1197 #endif
1199 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1200 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1201 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1203 DWtype
1204 __fixunsxfDI (XFtype a)
1206 if (a < 0)
1207 return 0;
1209 /* Compute high word of result, as a flonum. */
1210 const XFtype b = (a / HIGH_WORD_COEFF);
1211 /* Convert that to fixed (but not to DWtype!),
1212 and shift it into the high word. */
1213 UDWtype v = (UWtype) b;
1214 v <<= WORD_SIZE;
1215 /* Remove high part from the XFtype, leaving the low part as flonum. */
1216 a -= (XFtype)v;
1217 /* Convert that to fixed (but not to DWtype!) and add it in.
1218 Sometimes A comes out negative. This is significant, since
1219 A has more bits than a long int does. */
1220 if (a < 0)
1221 v -= (UWtype) (- a);
1222 else
1223 v += (UWtype) a;
1224 return v;
1226 #endif
1228 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1229 DWtype
1230 __fixxfdi (XFtype a)
1232 if (a < 0)
1233 return - __fixunsxfDI (-a);
1234 return __fixunsxfDI (a);
1236 #endif
1238 #ifdef L_fixunsdfdi
1239 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1240 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1242 DWtype
1243 __fixunsdfDI (DFtype a)
1245 /* Get high part of result. The division here will just moves the radix
1246 point and will not cause any rounding. Then the conversion to integral
1247 type chops result as desired. */
1248 const UWtype hi = a / HIGH_WORD_COEFF;
1250 /* Get low part of result. Convert `hi' to floating type and scale it back,
1251 then subtract this from the number being converted. This leaves the low
1252 part. Convert that to integral type. */
1253 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1255 /* Assemble result from the two parts. */
1256 return ((UDWtype) hi << WORD_SIZE) | lo;
1258 #endif
1260 #ifdef L_fixdfdi
1261 DWtype
1262 __fixdfdi (DFtype a)
1264 if (a < 0)
1265 return - __fixunsdfDI (-a);
1266 return __fixunsdfDI (a);
1268 #endif
1270 #ifdef L_fixunssfdi
1271 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1272 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1274 DWtype
1275 __fixunssfDI (SFtype original_a)
1277 /* Convert the SFtype to a DFtype, because that is surely not going
1278 to lose any bits. Some day someone else can write a faster version
1279 that avoids converting to DFtype, and verify it really works right. */
1280 const DFtype a = original_a;
1282 /* Get high part of result. The division here will just moves the radix
1283 point and will not cause any rounding. Then the conversion to integral
1284 type chops result as desired. */
1285 const UWtype hi = a / HIGH_WORD_COEFF;
1287 /* Get low part of result. Convert `hi' to floating type and scale it back,
1288 then subtract this from the number being converted. This leaves the low
1289 part. Convert that to integral type. */
1290 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1292 /* Assemble result from the two parts. */
1293 return ((UDWtype) hi << WORD_SIZE) | lo;
1295 #endif
1297 #ifdef L_fixsfdi
1298 DWtype
1299 __fixsfdi (SFtype a)
1301 if (a < 0)
1302 return - __fixunssfDI (-a);
1303 return __fixunssfDI (a);
1305 #endif
1307 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1308 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1309 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1310 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1312 XFtype
1313 __floatdixf (DWtype u)
1315 XFtype d = (Wtype) (u >> WORD_SIZE);
1316 d *= HIGH_HALFWORD_COEFF;
1317 d *= HIGH_HALFWORD_COEFF;
1318 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1320 return d;
1322 #endif
1324 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1325 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1326 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1327 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1329 TFtype
1330 __floatditf (DWtype u)
1332 TFtype d = (Wtype) (u >> WORD_SIZE);
1333 d *= HIGH_HALFWORD_COEFF;
1334 d *= HIGH_HALFWORD_COEFF;
1335 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1337 return d;
1339 #endif
1341 #ifdef L_floatdidf
1342 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1343 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1344 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1346 DFtype
1347 __floatdidf (DWtype u)
1349 DFtype d = (Wtype) (u >> WORD_SIZE);
1350 d *= HIGH_HALFWORD_COEFF;
1351 d *= HIGH_HALFWORD_COEFF;
1352 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1354 return d;
1356 #endif
1358 #ifdef L_floatdisf
1359 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1360 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1361 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1363 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1364 #define DF_SIZE DBL_MANT_DIG
1365 #define SF_SIZE FLT_MANT_DIG
1367 SFtype
1368 __floatdisf (DWtype u)
1370 /* Protect against double-rounding error.
1371 Represent any low-order bits, that might be truncated in DFmode,
1372 by a bit that won't be lost. The bit can go in anywhere below the
1373 rounding position of the SFmode. A fixed mask and bit position
1374 handles all usual configurations. It doesn't handle the case
1375 of 128-bit DImode, however. */
1376 if (DF_SIZE < DI_SIZE
1377 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1379 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1380 if (! (- ((DWtype) 1 << DF_SIZE) < u
1381 && u < ((DWtype) 1 << DF_SIZE)))
1383 if ((UDWtype) u & (REP_BIT - 1))
1385 u &= ~ (REP_BIT - 1);
1386 u |= REP_BIT;
1390 /* Do the calculation in DFmode
1391 so that we don't lose any of the precision of the high word
1392 while multiplying it. */
1393 DFtype f = (Wtype) (u >> WORD_SIZE);
1394 f *= HIGH_HALFWORD_COEFF;
1395 f *= HIGH_HALFWORD_COEFF;
1396 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1398 return (SFtype) f;
1400 #endif
1402 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80
1403 /* Reenable the normal types, in case limits.h needs them. */
1404 #undef char
1405 #undef short
1406 #undef int
1407 #undef long
1408 #undef unsigned
1409 #undef float
1410 #undef double
1411 #undef MIN
1412 #undef MAX
1413 #include <limits.h>
1415 UWtype
1416 __fixunsxfSI (XFtype a)
1418 if (a >= - (DFtype) Wtype_MIN)
1419 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1420 return (Wtype) a;
1422 #endif
1424 #ifdef L_fixunsdfsi
1425 /* Reenable the normal types, in case limits.h needs them. */
1426 #undef char
1427 #undef short
1428 #undef int
1429 #undef long
1430 #undef unsigned
1431 #undef float
1432 #undef double
1433 #undef MIN
1434 #undef MAX
1435 #include <limits.h>
1437 UWtype
1438 __fixunsdfSI (DFtype a)
1440 if (a >= - (DFtype) Wtype_MIN)
1441 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1442 return (Wtype) a;
1444 #endif
1446 #ifdef L_fixunssfsi
1447 /* Reenable the normal types, in case limits.h needs them. */
1448 #undef char
1449 #undef short
1450 #undef int
1451 #undef long
1452 #undef unsigned
1453 #undef float
1454 #undef double
1455 #undef MIN
1456 #undef MAX
1457 #include <limits.h>
1459 UWtype
1460 __fixunssfSI (SFtype a)
1462 if (a >= - (SFtype) Wtype_MIN)
1463 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1464 return (Wtype) a;
1466 #endif
1468 /* From here on down, the routines use normal data types. */
1470 #define SItype bogus_type
1471 #define USItype bogus_type
1472 #define DItype bogus_type
1473 #define UDItype bogus_type
1474 #define SFtype bogus_type
1475 #define DFtype bogus_type
1476 #undef Wtype
1477 #undef UWtype
1478 #undef HWtype
1479 #undef UHWtype
1480 #undef DWtype
1481 #undef UDWtype
1483 #undef char
1484 #undef short
1485 #undef int
1486 #undef long
1487 #undef unsigned
1488 #undef float
1489 #undef double
1491 #ifdef L__gcc_bcmp
1493 /* Like bcmp except the sign is meaningful.
1494 Result is negative if S1 is less than S2,
1495 positive if S1 is greater, 0 if S1 and S2 are equal. */
1498 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1500 while (size > 0)
1502 const unsigned char c1 = *s1++, c2 = *s2++;
1503 if (c1 != c2)
1504 return c1 - c2;
1505 size--;
1507 return 0;
1510 #endif
1512 /* __eprintf used to be used by GCC's private version of <assert.h>.
1513 We no longer provide that header, but this routine remains in libgcc.a
1514 for binary backward compatibility. Note that it is not included in
1515 the shared version of libgcc. */
1516 #ifdef L_eprintf
1517 #ifndef inhibit_libc
1519 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1520 #include <stdio.h>
1522 void
1523 __eprintf (const char *string, const char *expression,
1524 unsigned int line, const char *filename)
1526 fprintf (stderr, string, expression, line, filename);
1527 fflush (stderr);
1528 abort ();
1531 #endif
1532 #endif
1535 #ifdef L_clear_cache
1536 /* Clear part of an instruction cache. */
1538 void
1539 __clear_cache (char *beg __attribute__((__unused__)),
1540 char *end __attribute__((__unused__)))
1542 #ifdef CLEAR_INSN_CACHE
1543 CLEAR_INSN_CACHE (beg, end);
1544 #endif /* CLEAR_INSN_CACHE */
1547 #endif /* L_clear_cache */
1549 #ifdef L_enable_execute_stack
1550 /* Attempt to turn on execute permission for the stack. */
1552 #ifdef ENABLE_EXECUTE_STACK
1553 ENABLE_EXECUTE_STACK
1554 #else
1555 void
1556 __enable_execute_stack (void *addr __attribute__((__unused__)))
1558 #endif /* ENABLE_EXECUTE_STACK */
1560 #endif /* L_enable_execute_stack */
1562 #ifdef L_trampoline
1564 /* Jump to a trampoline, loading the static chain address. */
1566 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1569 getpagesize (void)
1571 #ifdef _ALPHA_
1572 return 8192;
1573 #else
1574 return 4096;
1575 #endif
1578 #ifdef __i386__
1579 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1580 #endif
1583 mprotect (char *addr, int len, int prot)
1585 int np, op;
1587 if (prot == 7)
1588 np = 0x40;
1589 else if (prot == 5)
1590 np = 0x20;
1591 else if (prot == 4)
1592 np = 0x10;
1593 else if (prot == 3)
1594 np = 0x04;
1595 else if (prot == 1)
1596 np = 0x02;
1597 else if (prot == 0)
1598 np = 0x01;
1600 if (VirtualProtect (addr, len, np, &op))
1601 return 0;
1602 else
1603 return -1;
1606 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1608 #ifdef TRANSFER_FROM_TRAMPOLINE
1609 TRANSFER_FROM_TRAMPOLINE
1610 #endif
1611 #endif /* L_trampoline */
1613 #ifndef __CYGWIN__
1614 #ifdef L__main
1616 #include "gbl-ctors.h"
1617 /* Some systems use __main in a way incompatible with its use in gcc, in these
1618 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1619 give the same symbol without quotes for an alternative entry point. You
1620 must define both, or neither. */
1621 #ifndef NAME__MAIN
1622 #define NAME__MAIN "__main"
1623 #define SYMBOL__MAIN __main
1624 #endif
1626 #ifdef INIT_SECTION_ASM_OP
1627 #undef HAS_INIT_SECTION
1628 #define HAS_INIT_SECTION
1629 #endif
1631 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1633 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1634 code to run constructors. In that case, we need to handle EH here, too. */
1636 #ifdef EH_FRAME_SECTION_NAME
1637 #include "unwind-dw2-fde.h"
1638 extern unsigned char __EH_FRAME_BEGIN__[];
1639 #endif
1641 /* Run all the global destructors on exit from the program. */
1643 void
1644 __do_global_dtors (void)
1646 #ifdef DO_GLOBAL_DTORS_BODY
1647 DO_GLOBAL_DTORS_BODY;
1648 #else
1649 static func_ptr *p = __DTOR_LIST__ + 1;
1650 while (*p)
1652 p++;
1653 (*(p-1)) ();
1655 #endif
1656 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1658 static int completed = 0;
1659 if (! completed)
1661 completed = 1;
1662 __deregister_frame_info (__EH_FRAME_BEGIN__);
1665 #endif
1667 #endif
1669 #ifndef HAS_INIT_SECTION
1670 /* Run all the global constructors on entry to the program. */
1672 void
1673 __do_global_ctors (void)
1675 #ifdef EH_FRAME_SECTION_NAME
1677 static struct object object;
1678 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1680 #endif
1681 DO_GLOBAL_CTORS_BODY;
1682 atexit (__do_global_dtors);
1684 #endif /* no HAS_INIT_SECTION */
1686 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1687 /* Subroutine called automatically by `main'.
1688 Compiling a global function named `main'
1689 produces an automatic call to this function at the beginning.
1691 For many systems, this routine calls __do_global_ctors.
1692 For systems which support a .init section we use the .init section
1693 to run __do_global_ctors, so we need not do anything here. */
1695 extern void SYMBOL__MAIN (void);
1696 void
1697 SYMBOL__MAIN (void)
1699 /* Support recursive calls to `main': run initializers just once. */
1700 static int initialized;
1701 if (! initialized)
1703 initialized = 1;
1704 __do_global_ctors ();
1707 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1709 #endif /* L__main */
1710 #endif /* __CYGWIN__ */
1712 #ifdef L_ctors
1714 #include "gbl-ctors.h"
1716 /* Provide default definitions for the lists of constructors and
1717 destructors, so that we don't get linker errors. These symbols are
1718 intentionally bss symbols, so that gld and/or collect will provide
1719 the right values. */
1721 /* We declare the lists here with two elements each,
1722 so that they are valid empty lists if no other definition is loaded.
1724 If we are using the old "set" extensions to have the gnu linker
1725 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1726 must be in the bss/common section.
1728 Long term no port should use those extensions. But many still do. */
1729 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1730 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1731 func_ptr __CTOR_LIST__[2] = {0, 0};
1732 func_ptr __DTOR_LIST__[2] = {0, 0};
1733 #else
1734 func_ptr __CTOR_LIST__[2];
1735 func_ptr __DTOR_LIST__[2];
1736 #endif
1737 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1738 #endif /* L_ctors */