[RS6000] Use LIB2_SIDITI_CONV_FUNCS in place of ppc64-fp.c
[official-gcc.git] / libgcc / libgcc2.c
blobcf0ca299c7247a3d0b7a16854de03883be59d019
1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #include "tconfig.h"
27 #include "tsystem.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "libgcc_tm.h"
32 #ifdef HAVE_GAS_HIDDEN
33 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
34 #else
35 #define ATTRIBUTE_HIDDEN
36 #endif
38 /* Work out the largest "word" size that we can deal with on this target. */
39 #if MIN_UNITS_PER_WORD > 4
40 # define LIBGCC2_MAX_UNITS_PER_WORD 8
41 #elif (MIN_UNITS_PER_WORD > 2 \
42 || (MIN_UNITS_PER_WORD > 1 && __SIZEOF_LONG_LONG__ > 4))
43 # define LIBGCC2_MAX_UNITS_PER_WORD 4
44 #else
45 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
46 #endif
48 /* Work out what word size we are using for this compilation.
49 The value can be set on the command line. */
50 #ifndef LIBGCC2_UNITS_PER_WORD
51 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
52 #endif
54 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
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 Wtype w;
80 if (__builtin_add_overflow (a, b, &w))
81 abort ();
83 return w;
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
86 SItype
87 __addvsi3 (SItype a, SItype b)
89 SItype w;
91 if (__builtin_add_overflow (a, b, &w))
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 DWtype w;
105 if (__builtin_add_overflow (a, b, &w))
106 abort ();
108 return w;
110 #endif
112 #ifdef L_subvsi3
113 Wtype
114 __subvSI3 (Wtype a, Wtype b)
116 Wtype w;
118 if (__builtin_sub_overflow (a, b, &w))
119 abort ();
121 return w;
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
124 SItype
125 __subvsi3 (SItype a, SItype b)
127 SItype w;
129 if (__builtin_sub_overflow (a, b, &w))
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 DWtype w;
143 if (__builtin_sub_overflow (a, b, &w))
144 abort ();
146 return w;
148 #endif
150 #ifdef L_mulvsi3
151 Wtype
152 __mulvSI3 (Wtype a, Wtype b)
154 Wtype w;
156 if (__builtin_mul_overflow (a, b, &w))
157 abort ();
159 return w;
161 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
162 SItype
163 __mulvsi3 (SItype a, SItype b)
165 SItype w;
167 if (__builtin_mul_overflow (a, b, &w))
168 abort ();
170 return w;
172 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
173 #endif
175 #ifdef L_negvsi2
176 Wtype
177 __negvSI2 (Wtype a)
179 Wtype w;
181 if (__builtin_sub_overflow (0, a, &w))
182 abort ();
184 return w;
186 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
187 SItype
188 __negvsi2 (SItype a)
190 SItype w;
192 if (__builtin_sub_overflow (0, a, &w))
193 abort ();
195 return w;
197 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
198 #endif
200 #ifdef L_negvdi2
201 DWtype
202 __negvDI2 (DWtype a)
204 DWtype w;
206 if (__builtin_sub_overflow (0, a, &w))
207 abort ();
209 return w;
211 #endif
213 #ifdef L_absvsi2
214 Wtype
215 __absvSI2 (Wtype a)
217 Wtype w = a;
219 if (a < 0)
220 #ifdef L_negvsi2
221 w = __negvSI2 (a);
222 #else
223 w = -(UWtype) a;
225 if (w < 0)
226 abort ();
227 #endif
229 return w;
231 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
232 SItype
233 __absvsi2 (SItype a)
235 SItype w = a;
237 if (a < 0)
238 #ifdef L_negvsi2
239 w = __negvsi2 (a);
240 #else
241 w = -(USItype) a;
243 if (w < 0)
244 abort ();
245 #endif
247 return w;
249 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
250 #endif
252 #ifdef L_absvdi2
253 DWtype
254 __absvDI2 (DWtype a)
256 DWtype w = a;
258 if (a < 0)
259 #ifdef L_negvdi2
260 w = __negvDI2 (a);
261 #else
262 w = -(UDWtype) a;
264 if (w < 0)
265 abort ();
266 #endif
268 return w;
270 #endif
272 #ifdef L_mulvdi3
273 DWtype
274 __mulvDI3 (DWtype u, DWtype v)
276 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
277 but the checked multiplication needs only two. */
278 const DWunion uu = {.ll = u};
279 const DWunion vv = {.ll = v};
281 if (__builtin_expect (uu.s.high == uu.s.low >> (W_TYPE_SIZE - 1), 1))
283 /* u fits in a single Wtype. */
284 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
286 /* v fits in a single Wtype as well. */
287 /* A single multiplication. No overflow risk. */
288 return (DWtype) uu.s.low * (DWtype) vv.s.low;
290 else
292 /* Two multiplications. */
293 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
294 * (UDWtype) (UWtype) vv.s.low};
295 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
296 * (UDWtype) (UWtype) vv.s.high};
298 if (vv.s.high < 0)
299 w1.s.high -= uu.s.low;
300 if (uu.s.low < 0)
301 w1.ll -= vv.ll;
302 w1.ll += (UWtype) w0.s.high;
303 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
305 w0.s.high = w1.s.low;
306 return w0.ll;
310 else
312 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
314 /* v fits into a single Wtype. */
315 /* Two multiplications. */
316 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
317 * (UDWtype) (UWtype) vv.s.low};
318 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
319 * (UDWtype) (UWtype) vv.s.low};
321 if (uu.s.high < 0)
322 w1.s.high -= vv.s.low;
323 if (vv.s.low < 0)
324 w1.ll -= uu.ll;
325 w1.ll += (UWtype) w0.s.high;
326 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
328 w0.s.high = w1.s.low;
329 return w0.ll;
332 else
334 /* A few sign checks and a single multiplication. */
335 if (uu.s.high >= 0)
337 if (vv.s.high >= 0)
339 if (uu.s.high == 0 && vv.s.high == 0)
341 const DWtype w = (UDWtype) (UWtype) uu.s.low
342 * (UDWtype) (UWtype) vv.s.low;
343 if (__builtin_expect (w >= 0, 1))
344 return w;
347 else
349 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
351 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
352 * (UDWtype) (UWtype) vv.s.low};
354 ww.s.high -= uu.s.low;
355 if (__builtin_expect (ww.s.high < 0, 1))
356 return ww.ll;
360 else
362 if (vv.s.high >= 0)
364 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
366 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
367 * (UDWtype) (UWtype) vv.s.low};
369 ww.s.high -= vv.s.low;
370 if (__builtin_expect (ww.s.high < 0, 1))
371 return ww.ll;
374 else
376 if ((uu.s.high & vv.s.high) == (Wtype) -1
377 && (uu.s.low | vv.s.low) != 0)
379 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
380 * (UDWtype) (UWtype) vv.s.low};
382 ww.s.high -= uu.s.low;
383 ww.s.high -= vv.s.low;
384 if (__builtin_expect (ww.s.high >= 0, 1))
385 return ww.ll;
392 /* Overflow. */
393 abort ();
395 #endif
398 /* Unless shift functions are defined with full ANSI prototypes,
399 parameter b will be promoted to int if shift_count_type is smaller than an int. */
400 #ifdef L_lshrdi3
401 DWtype
402 __lshrdi3 (DWtype u, shift_count_type b)
404 if (b == 0)
405 return u;
407 const DWunion uu = {.ll = u};
408 const shift_count_type bm = W_TYPE_SIZE - b;
409 DWunion w;
411 if (bm <= 0)
413 w.s.high = 0;
414 w.s.low = (UWtype) uu.s.high >> -bm;
416 else
418 const UWtype carries = (UWtype) uu.s.high << bm;
420 w.s.high = (UWtype) uu.s.high >> b;
421 w.s.low = ((UWtype) uu.s.low >> b) | carries;
424 return w.ll;
426 #endif
428 #ifdef L_ashldi3
429 DWtype
430 __ashldi3 (DWtype u, shift_count_type b)
432 if (b == 0)
433 return u;
435 const DWunion uu = {.ll = u};
436 const shift_count_type bm = W_TYPE_SIZE - b;
437 DWunion w;
439 if (bm <= 0)
441 w.s.low = 0;
442 w.s.high = (UWtype) uu.s.low << -bm;
444 else
446 const UWtype carries = (UWtype) uu.s.low >> bm;
448 w.s.low = (UWtype) uu.s.low << b;
449 w.s.high = ((UWtype) uu.s.high << b) | carries;
452 return w.ll;
454 #endif
456 #ifdef L_ashrdi3
457 DWtype
458 __ashrdi3 (DWtype u, shift_count_type b)
460 if (b == 0)
461 return u;
463 const DWunion uu = {.ll = u};
464 const shift_count_type bm = W_TYPE_SIZE - b;
465 DWunion w;
467 if (bm <= 0)
469 /* w.s.high = 1..1 or 0..0 */
470 w.s.high = uu.s.high >> (W_TYPE_SIZE - 1);
471 w.s.low = uu.s.high >> -bm;
473 else
475 const UWtype carries = (UWtype) uu.s.high << bm;
477 w.s.high = uu.s.high >> b;
478 w.s.low = ((UWtype) uu.s.low >> b) | carries;
481 return w.ll;
483 #endif
485 #ifdef L_bswapsi2
486 SItype
487 __bswapsi2 (SItype u)
489 return ((((u) & 0xff000000) >> 24)
490 | (((u) & 0x00ff0000) >> 8)
491 | (((u) & 0x0000ff00) << 8)
492 | (((u) & 0x000000ff) << 24));
494 #endif
495 #ifdef L_bswapdi2
496 DItype
497 __bswapdi2 (DItype u)
499 return ((((u) & 0xff00000000000000ull) >> 56)
500 | (((u) & 0x00ff000000000000ull) >> 40)
501 | (((u) & 0x0000ff0000000000ull) >> 24)
502 | (((u) & 0x000000ff00000000ull) >> 8)
503 | (((u) & 0x00000000ff000000ull) << 8)
504 | (((u) & 0x0000000000ff0000ull) << 24)
505 | (((u) & 0x000000000000ff00ull) << 40)
506 | (((u) & 0x00000000000000ffull) << 56));
508 #endif
509 #ifdef L_ffssi2
510 #undef int
512 __ffsSI2 (UWtype u)
514 UWtype count;
516 if (u == 0)
517 return 0;
519 count_trailing_zeros (count, u);
520 return count + 1;
522 #endif
524 #ifdef L_ffsdi2
525 #undef int
527 __ffsDI2 (DWtype u)
529 const DWunion uu = {.ll = u};
530 UWtype word, count, add;
532 if (uu.s.low != 0)
533 word = uu.s.low, add = 0;
534 else if (uu.s.high != 0)
535 word = uu.s.high, add = W_TYPE_SIZE;
536 else
537 return 0;
539 count_trailing_zeros (count, word);
540 return count + add + 1;
542 #endif
544 #ifdef L_muldi3
545 DWtype
546 __muldi3 (DWtype u, DWtype v)
548 const DWunion uu = {.ll = u};
549 const DWunion vv = {.ll = v};
550 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
552 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
553 + (UWtype) uu.s.high * (UWtype) vv.s.low);
555 return w.ll;
557 #endif
559 #if (defined (L_udivdi3) || defined (L_divdi3) || \
560 defined (L_umoddi3) || defined (L_moddi3))
561 #if defined (sdiv_qrnnd)
562 #define L_udiv_w_sdiv
563 #endif
564 #endif
566 #ifdef L_udiv_w_sdiv
567 #if defined (sdiv_qrnnd)
568 #if (defined (L_udivdi3) || defined (L_divdi3) || \
569 defined (L_umoddi3) || defined (L_moddi3))
570 static inline __attribute__ ((__always_inline__))
571 #endif
572 UWtype
573 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
575 UWtype q, r;
576 UWtype c0, c1, b1;
578 if ((Wtype) d >= 0)
580 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
582 /* Dividend, divisor, and quotient are nonnegative. */
583 sdiv_qrnnd (q, r, a1, a0, d);
585 else
587 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
588 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
589 /* Divide (c1*2^32 + c0) by d. */
590 sdiv_qrnnd (q, r, c1, c0, d);
591 /* Add 2^31 to quotient. */
592 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
595 else
597 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
598 c1 = a1 >> 1; /* A/2 */
599 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
601 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
603 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
605 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
606 if ((d & 1) != 0)
608 if (r >= q)
609 r = r - q;
610 else if (q - r <= d)
612 r = r - q + d;
613 q--;
615 else
617 r = r - q + 2*d;
618 q -= 2;
622 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
624 c1 = (b1 - 1) - c1;
625 c0 = ~c0; /* logical NOT */
627 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
629 q = ~q; /* (A/2)/b1 */
630 r = (b1 - 1) - r;
632 r = 2*r + (a0 & 1); /* A/(2*b1) */
634 if ((d & 1) != 0)
636 if (r >= q)
637 r = r - q;
638 else if (q - r <= d)
640 r = r - q + d;
641 q--;
643 else
645 r = r - q + 2*d;
646 q -= 2;
650 else /* Implies c1 = b1 */
651 { /* Hence a1 = d - 1 = 2*b1 - 1 */
652 if (a0 >= -d)
654 q = -1;
655 r = a0 + d;
657 else
659 q = -2;
660 r = a0 + 2*d;
665 *rp = r;
666 return q;
668 #else
669 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
670 UWtype
671 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
672 UWtype a1 __attribute__ ((__unused__)),
673 UWtype a0 __attribute__ ((__unused__)),
674 UWtype d __attribute__ ((__unused__)))
676 return 0;
678 #endif
679 #endif
681 #if (defined (L_udivdi3) || defined (L_divdi3) || \
682 defined (L_umoddi3) || defined (L_moddi3) || \
683 defined (L_divmoddi4))
684 #define L_udivmoddi4
685 #endif
687 #ifdef L_clz
688 const UQItype __clz_tab[256] =
690 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,
691 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,
692 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,
693 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,
694 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,
695 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,
696 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,
697 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
699 #endif
701 #ifdef L_clzsi2
702 #undef int
704 __clzSI2 (UWtype x)
706 Wtype ret;
708 count_leading_zeros (ret, x);
710 return ret;
712 #endif
714 #ifdef L_clzdi2
715 #undef int
717 __clzDI2 (UDWtype x)
719 const DWunion uu = {.ll = x};
720 UWtype word;
721 Wtype ret, add;
723 if (uu.s.high)
724 word = uu.s.high, add = 0;
725 else
726 word = uu.s.low, add = W_TYPE_SIZE;
728 count_leading_zeros (ret, word);
729 return ret + add;
731 #endif
733 #ifdef L_ctzsi2
734 #undef int
736 __ctzSI2 (UWtype x)
738 Wtype ret;
740 count_trailing_zeros (ret, x);
742 return ret;
744 #endif
746 #ifdef L_ctzdi2
747 #undef int
749 __ctzDI2 (UDWtype x)
751 const DWunion uu = {.ll = x};
752 UWtype word;
753 Wtype ret, add;
755 if (uu.s.low)
756 word = uu.s.low, add = 0;
757 else
758 word = uu.s.high, add = W_TYPE_SIZE;
760 count_trailing_zeros (ret, word);
761 return ret + add;
763 #endif
765 #ifdef L_clrsbsi2
766 #undef int
768 __clrsbSI2 (Wtype x)
770 Wtype ret;
772 if (x < 0)
773 x = ~x;
774 if (x == 0)
775 return W_TYPE_SIZE - 1;
776 count_leading_zeros (ret, x);
777 return ret - 1;
779 #endif
781 #ifdef L_clrsbdi2
782 #undef int
784 __clrsbDI2 (DWtype x)
786 const DWunion uu = {.ll = x};
787 UWtype word;
788 Wtype ret, add;
790 if (uu.s.high == 0)
791 word = uu.s.low, add = W_TYPE_SIZE;
792 else if (uu.s.high == -1)
793 word = ~uu.s.low, add = W_TYPE_SIZE;
794 else if (uu.s.high >= 0)
795 word = uu.s.high, add = 0;
796 else
797 word = ~uu.s.high, add = 0;
799 if (word == 0)
800 ret = W_TYPE_SIZE;
801 else
802 count_leading_zeros (ret, word);
804 return ret + add - 1;
806 #endif
808 #ifdef L_popcount_tab
809 const UQItype __popcount_tab[256] =
811 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,
812 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,
813 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,
814 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,
815 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,
816 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,
817 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,
818 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
820 #endif
822 #if defined(L_popcountsi2) || defined(L_popcountdi2)
823 #define POPCOUNTCST2(x) (((UWtype) x << __CHAR_BIT__) | x)
824 #define POPCOUNTCST4(x) (((UWtype) x << (2 * __CHAR_BIT__)) | x)
825 #define POPCOUNTCST8(x) (((UWtype) x << (4 * __CHAR_BIT__)) | x)
826 #if W_TYPE_SIZE == __CHAR_BIT__
827 #define POPCOUNTCST(x) x
828 #elif W_TYPE_SIZE == 2 * __CHAR_BIT__
829 #define POPCOUNTCST(x) POPCOUNTCST2 (x)
830 #elif W_TYPE_SIZE == 4 * __CHAR_BIT__
831 #define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
832 #elif W_TYPE_SIZE == 8 * __CHAR_BIT__
833 #define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
834 #endif
835 #endif
837 #ifdef L_popcountsi2
838 #undef int
840 __popcountSI2 (UWtype x)
842 /* Force table lookup on targets like AVR and RL78 which only
843 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
844 have 1, and other small word targets. */
845 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
846 x = x - ((x >> 1) & POPCOUNTCST (0x55));
847 x = (x & POPCOUNTCST (0x33)) + ((x >> 2) & POPCOUNTCST (0x33));
848 x = (x + (x >> 4)) & POPCOUNTCST (0x0F);
849 return (x * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - __CHAR_BIT__);
850 #else
851 int i, ret = 0;
853 for (i = 0; i < W_TYPE_SIZE; i += 8)
854 ret += __popcount_tab[(x >> i) & 0xff];
856 return ret;
857 #endif
859 #endif
861 #ifdef L_popcountdi2
862 #undef int
864 __popcountDI2 (UDWtype x)
866 /* Force table lookup on targets like AVR and RL78 which only
867 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
868 have 1, and other small word targets. */
869 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
870 const DWunion uu = {.ll = x};
871 UWtype x1 = uu.s.low, x2 = uu.s.high;
872 x1 = x1 - ((x1 >> 1) & POPCOUNTCST (0x55));
873 x2 = x2 - ((x2 >> 1) & POPCOUNTCST (0x55));
874 x1 = (x1 & POPCOUNTCST (0x33)) + ((x1 >> 2) & POPCOUNTCST (0x33));
875 x2 = (x2 & POPCOUNTCST (0x33)) + ((x2 >> 2) & POPCOUNTCST (0x33));
876 x1 = (x1 + (x1 >> 4)) & POPCOUNTCST (0x0F);
877 x2 = (x2 + (x2 >> 4)) & POPCOUNTCST (0x0F);
878 x1 += x2;
879 return (x1 * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - __CHAR_BIT__);
880 #else
881 int i, ret = 0;
883 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
884 ret += __popcount_tab[(x >> i) & 0xff];
886 return ret;
887 #endif
889 #endif
891 #ifdef L_paritysi2
892 #undef int
894 __paritySI2 (UWtype x)
896 #if W_TYPE_SIZE > 64
897 # error "fill out the table"
898 #endif
899 #if W_TYPE_SIZE > 32
900 x ^= x >> 32;
901 #endif
902 #if W_TYPE_SIZE > 16
903 x ^= x >> 16;
904 #endif
905 x ^= x >> 8;
906 x ^= x >> 4;
907 x &= 0xf;
908 return (0x6996 >> x) & 1;
910 #endif
912 #ifdef L_paritydi2
913 #undef int
915 __parityDI2 (UDWtype x)
917 const DWunion uu = {.ll = x};
918 UWtype nx = uu.s.low ^ uu.s.high;
920 #if W_TYPE_SIZE > 64
921 # error "fill out the table"
922 #endif
923 #if W_TYPE_SIZE > 32
924 nx ^= nx >> 32;
925 #endif
926 #if W_TYPE_SIZE > 16
927 nx ^= nx >> 16;
928 #endif
929 nx ^= nx >> 8;
930 nx ^= nx >> 4;
931 nx &= 0xf;
932 return (0x6996 >> nx) & 1;
934 #endif
936 #ifdef L_udivmoddi4
937 #ifdef TARGET_HAS_NO_HW_DIVIDE
939 #if (defined (L_udivdi3) || defined (L_divdi3) || \
940 defined (L_umoddi3) || defined (L_moddi3) || \
941 defined (L_divmoddi4))
942 static inline __attribute__ ((__always_inline__))
943 #endif
944 UDWtype
945 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
947 UDWtype q = 0, r = n, y = d;
948 UWtype lz1, lz2, i, k;
950 /* Implements align divisor shift dividend method. This algorithm
951 aligns the divisor under the dividend and then perform number of
952 test-subtract iterations which shift the dividend left. Number of
953 iterations is k + 1 where k is the number of bit positions the
954 divisor must be shifted left to align it under the dividend.
955 quotient bits can be saved in the rightmost positions of the dividend
956 as it shifts left on each test-subtract iteration. */
958 if (y <= r)
960 lz1 = __builtin_clzll (d);
961 lz2 = __builtin_clzll (n);
963 k = lz1 - lz2;
964 y = (y << k);
966 /* Dividend can exceed 2 ^ (width - 1) - 1 but still be less than the
967 aligned divisor. Normal iteration can drops the high order bit
968 of the dividend. Therefore, first test-subtract iteration is a
969 special case, saving its quotient bit in a separate location and
970 not shifting the dividend. */
971 if (r >= y)
973 r = r - y;
974 q = (1ULL << k);
977 if (k > 0)
979 y = y >> 1;
981 /* k additional iterations where k regular test subtract shift
982 dividend iterations are done. */
983 i = k;
986 if (r >= y)
987 r = ((r - y) << 1) + 1;
988 else
989 r = (r << 1);
990 i = i - 1;
991 } while (i != 0);
993 /* First quotient bit is combined with the quotient bits resulting
994 from the k regular iterations. */
995 q = q + r;
996 r = r >> k;
997 q = q - (r << k);
1001 if (rp)
1002 *rp = r;
1003 return q;
1005 #else
1007 #if (defined (L_udivdi3) || defined (L_divdi3) || \
1008 defined (L_umoddi3) || defined (L_moddi3) || \
1009 defined (L_divmoddi4))
1010 static inline __attribute__ ((__always_inline__))
1011 #endif
1012 UDWtype
1013 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
1015 const DWunion nn = {.ll = n};
1016 const DWunion dd = {.ll = d};
1017 DWunion rr;
1018 UWtype d0, d1, n0, n1, n2;
1019 UWtype q0, q1;
1020 UWtype b, bm;
1022 d0 = dd.s.low;
1023 d1 = dd.s.high;
1024 n0 = nn.s.low;
1025 n1 = nn.s.high;
1027 #if !UDIV_NEEDS_NORMALIZATION
1028 if (d1 == 0)
1030 if (d0 > n1)
1032 /* 0q = nn / 0D */
1034 udiv_qrnnd (q0, n0, n1, n0, d0);
1035 q1 = 0;
1037 /* Remainder in n0. */
1039 else
1041 /* qq = NN / 0d */
1043 if (d0 == 0)
1044 d0 = 1 / d0; /* Divide intentionally by zero. */
1046 udiv_qrnnd (q1, n1, 0, n1, d0);
1047 udiv_qrnnd (q0, n0, n1, n0, d0);
1049 /* Remainder in n0. */
1052 if (rp != 0)
1054 rr.s.low = n0;
1055 rr.s.high = 0;
1056 *rp = rr.ll;
1060 #else /* UDIV_NEEDS_NORMALIZATION */
1062 if (d1 == 0)
1064 if (d0 > n1)
1066 /* 0q = nn / 0D */
1068 count_leading_zeros (bm, d0);
1070 if (bm != 0)
1072 /* Normalize, i.e. make the most significant bit of the
1073 denominator set. */
1075 d0 = d0 << bm;
1076 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
1077 n0 = n0 << bm;
1080 udiv_qrnnd (q0, n0, n1, n0, d0);
1081 q1 = 0;
1083 /* Remainder in n0 >> bm. */
1085 else
1087 /* qq = NN / 0d */
1089 if (d0 == 0)
1090 d0 = 1 / d0; /* Divide intentionally by zero. */
1092 count_leading_zeros (bm, d0);
1094 if (bm == 0)
1096 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
1097 conclude (the most significant bit of n1 is set) /\ (the
1098 leading quotient digit q1 = 1).
1100 This special case is necessary, not an optimization.
1101 (Shifts counts of W_TYPE_SIZE are undefined.) */
1103 n1 -= d0;
1104 q1 = 1;
1106 else
1108 /* Normalize. */
1110 b = W_TYPE_SIZE - bm;
1112 d0 = d0 << bm;
1113 n2 = n1 >> b;
1114 n1 = (n1 << bm) | (n0 >> b);
1115 n0 = n0 << bm;
1117 udiv_qrnnd (q1, n1, n2, n1, d0);
1120 /* n1 != d0... */
1122 udiv_qrnnd (q0, n0, n1, n0, d0);
1124 /* Remainder in n0 >> bm. */
1127 if (rp != 0)
1129 rr.s.low = n0 >> bm;
1130 rr.s.high = 0;
1131 *rp = rr.ll;
1134 #endif /* UDIV_NEEDS_NORMALIZATION */
1136 else
1138 if (d1 > n1)
1140 /* 00 = nn / DD */
1142 q0 = 0;
1143 q1 = 0;
1145 /* Remainder in n1n0. */
1146 if (rp != 0)
1148 rr.s.low = n0;
1149 rr.s.high = n1;
1150 *rp = rr.ll;
1153 else
1155 /* 0q = NN / dd */
1157 count_leading_zeros (bm, d1);
1158 if (bm == 0)
1160 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1161 conclude (the most significant bit of n1 is set) /\ (the
1162 quotient digit q0 = 0 or 1).
1164 This special case is necessary, not an optimization. */
1166 /* The condition on the next line takes advantage of that
1167 n1 >= d1 (true due to program flow). */
1168 if (n1 > d1 || n0 >= d0)
1170 q0 = 1;
1171 sub_ddmmss (n1, n0, n1, n0, d1, d0);
1173 else
1174 q0 = 0;
1176 q1 = 0;
1178 if (rp != 0)
1180 rr.s.low = n0;
1181 rr.s.high = n1;
1182 *rp = rr.ll;
1185 else
1187 UWtype m1, m0;
1188 /* Normalize. */
1190 b = W_TYPE_SIZE - bm;
1192 d1 = (d1 << bm) | (d0 >> b);
1193 d0 = d0 << bm;
1194 n2 = n1 >> b;
1195 n1 = (n1 << bm) | (n0 >> b);
1196 n0 = n0 << bm;
1198 udiv_qrnnd (q0, n1, n2, n1, d1);
1199 umul_ppmm (m1, m0, q0, d0);
1201 if (m1 > n1 || (m1 == n1 && m0 > n0))
1203 q0--;
1204 sub_ddmmss (m1, m0, m1, m0, d1, d0);
1207 q1 = 0;
1209 /* Remainder in (n1n0 - m1m0) >> bm. */
1210 if (rp != 0)
1212 sub_ddmmss (n1, n0, n1, n0, m1, m0);
1213 rr.s.low = (n1 << b) | (n0 >> bm);
1214 rr.s.high = n1 >> bm;
1215 *rp = rr.ll;
1221 const DWunion ww = {{.low = q0, .high = q1}};
1222 return ww.ll;
1224 #endif
1225 #endif
1227 #ifdef L_divdi3
1228 DWtype
1229 __divdi3 (DWtype u, DWtype v)
1231 Wtype c = 0;
1232 DWunion uu = {.ll = u};
1233 DWunion vv = {.ll = v};
1234 DWtype w;
1236 if (uu.s.high < 0)
1237 c = ~c,
1238 uu.ll = -uu.ll;
1239 if (vv.s.high < 0)
1240 c = ~c,
1241 vv.ll = -vv.ll;
1243 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1244 if (c)
1245 w = -w;
1247 return w;
1249 #endif
1251 #ifdef L_moddi3
1252 DWtype
1253 __moddi3 (DWtype u, DWtype v)
1255 Wtype c = 0;
1256 DWunion uu = {.ll = u};
1257 DWunion vv = {.ll = v};
1258 DWtype w;
1260 if (uu.s.high < 0)
1261 c = ~c,
1262 uu.ll = -uu.ll;
1263 if (vv.s.high < 0)
1264 vv.ll = -vv.ll;
1266 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1267 if (c)
1268 w = -w;
1270 return w;
1272 #endif
1274 #ifdef L_divmoddi4
1275 DWtype
1276 __divmoddi4 (DWtype u, DWtype v, DWtype *rp)
1278 Wtype c1 = 0, c2 = 0;
1279 DWunion uu = {.ll = u};
1280 DWunion vv = {.ll = v};
1281 DWtype w;
1282 DWtype r;
1284 if (uu.s.high < 0)
1285 c1 = ~c1, c2 = ~c2,
1286 uu.ll = -uu.ll;
1287 if (vv.s.high < 0)
1288 c1 = ~c1,
1289 vv.ll = -vv.ll;
1291 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&r);
1292 if (c1)
1293 w = -w;
1294 if (c2)
1295 r = -r;
1297 *rp = r;
1298 return w;
1300 #endif
1302 #ifdef L_umoddi3
1303 UDWtype
1304 __umoddi3 (UDWtype u, UDWtype v)
1306 UDWtype w;
1308 (void) __udivmoddi4 (u, v, &w);
1310 return w;
1312 #endif
1314 #ifdef L_udivdi3
1315 UDWtype
1316 __udivdi3 (UDWtype n, UDWtype d)
1318 return __udivmoddi4 (n, d, (UDWtype *) 0);
1320 #endif
1322 #ifdef L_cmpdi2
1323 cmp_return_type
1324 __cmpdi2 (DWtype a, DWtype b)
1326 return (a > b) - (a < b) + 1;
1328 #endif
1330 #ifdef L_ucmpdi2
1331 cmp_return_type
1332 __ucmpdi2 (UDWtype a, UDWtype b)
1334 return (a > b) - (a < b) + 1;
1336 #endif
1338 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1339 UDWtype
1340 __fixunstfDI (TFtype a)
1342 if (a < 0)
1343 return 0;
1345 /* Compute high word of result, as a flonum. */
1346 const TFtype b = (a / Wtype_MAXp1_F);
1347 /* Convert that to fixed (but not to DWtype!),
1348 and shift it into the high word. */
1349 UDWtype v = (UWtype) b;
1350 v <<= W_TYPE_SIZE;
1351 /* Remove high part from the TFtype, leaving the low part as flonum. */
1352 a -= (TFtype)v;
1353 /* Convert that to fixed (but not to DWtype!) and add it in.
1354 Sometimes A comes out negative. This is significant, since
1355 A has more bits than a long int does. */
1356 if (a < 0)
1357 v -= (UWtype) (- a);
1358 else
1359 v += (UWtype) a;
1360 return v;
1362 #endif
1364 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1365 DWtype
1366 __fixtfdi (TFtype a)
1368 if (a < 0)
1369 return - __fixunstfDI (-a);
1370 return __fixunstfDI (a);
1372 #endif
1374 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1375 UDWtype
1376 __fixunsxfDI (XFtype a)
1378 if (a < 0)
1379 return 0;
1381 /* Compute high word of result, as a flonum. */
1382 const XFtype b = (a / Wtype_MAXp1_F);
1383 /* Convert that to fixed (but not to DWtype!),
1384 and shift it into the high word. */
1385 UDWtype v = (UWtype) b;
1386 v <<= W_TYPE_SIZE;
1387 /* Remove high part from the XFtype, leaving the low part as flonum. */
1388 a -= (XFtype)v;
1389 /* Convert that to fixed (but not to DWtype!) and add it in.
1390 Sometimes A comes out negative. This is significant, since
1391 A has more bits than a long int does. */
1392 if (a < 0)
1393 v -= (UWtype) (- a);
1394 else
1395 v += (UWtype) a;
1396 return v;
1398 #endif
1400 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1401 DWtype
1402 __fixxfdi (XFtype a)
1404 if (a < 0)
1405 return - __fixunsxfDI (-a);
1406 return __fixunsxfDI (a);
1408 #endif
1410 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1411 UDWtype
1412 __fixunsdfDI (DFtype a)
1414 /* Get high part of result. The division here will just moves the radix
1415 point and will not cause any rounding. Then the conversion to integral
1416 type chops result as desired. */
1417 const UWtype hi = a / Wtype_MAXp1_F;
1419 /* Get low part of result. Convert `hi' to floating type and scale it back,
1420 then subtract this from the number being converted. This leaves the low
1421 part. Convert that to integral type. */
1422 const UWtype lo = a - (DFtype) hi * Wtype_MAXp1_F;
1424 /* Assemble result from the two parts. */
1425 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1427 #endif
1429 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1430 DWtype
1431 __fixdfdi (DFtype a)
1433 if (a < 0)
1434 return - __fixunsdfDI (-a);
1435 return __fixunsdfDI (a);
1437 #endif
1439 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1440 UDWtype
1441 __fixunssfDI (SFtype a)
1443 #if LIBGCC2_HAS_DF_MODE
1444 /* Convert the SFtype to a DFtype, because that is surely not going
1445 to lose any bits. Some day someone else can write a faster version
1446 that avoids converting to DFtype, and verify it really works right. */
1447 const DFtype dfa = a;
1449 /* Get high part of result. The division here will just moves the radix
1450 point and will not cause any rounding. Then the conversion to integral
1451 type chops result as desired. */
1452 const UWtype hi = dfa / Wtype_MAXp1_F;
1454 /* Get low part of result. Convert `hi' to floating type and scale it back,
1455 then subtract this from the number being converted. This leaves the low
1456 part. Convert that to integral type. */
1457 const UWtype lo = dfa - (DFtype) hi * Wtype_MAXp1_F;
1459 /* Assemble result from the two parts. */
1460 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1461 #elif FLT_MANT_DIG < W_TYPE_SIZE
1462 if (a < 1)
1463 return 0;
1464 if (a < Wtype_MAXp1_F)
1465 return (UWtype)a;
1466 if (a < Wtype_MAXp1_F * Wtype_MAXp1_F)
1468 /* Since we know that there are fewer significant bits in the SFmode
1469 quantity than in a word, we know that we can convert out all the
1470 significant bits in one step, and thus avoid losing bits. */
1472 /* ??? This following loop essentially performs frexpf. If we could
1473 use the real libm function, or poke at the actual bits of the fp
1474 format, it would be significantly faster. */
1476 UWtype shift = 0, counter;
1477 SFtype msb;
1479 a /= Wtype_MAXp1_F;
1480 for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1)
1482 SFtype counterf = (UWtype)1 << counter;
1483 if (a >= counterf)
1485 shift |= counter;
1486 a /= counterf;
1490 /* Rescale into the range of one word, extract the bits of that
1491 one word, and shift the result into position. */
1492 a *= Wtype_MAXp1_F;
1493 counter = a;
1494 return (DWtype)counter << shift;
1496 return -1;
1497 #else
1498 # error
1499 #endif
1501 #endif
1503 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1504 DWtype
1505 __fixsfdi (SFtype a)
1507 if (a < 0)
1508 return - __fixunssfDI (-a);
1509 return __fixunssfDI (a);
1511 #endif
1513 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1514 XFtype
1515 __floatdixf (DWtype u)
1517 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1518 # error
1519 #endif
1520 XFtype d = (Wtype) (u >> W_TYPE_SIZE);
1521 d *= Wtype_MAXp1_F;
1522 d += (UWtype)u;
1523 return d;
1525 #endif
1527 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1528 XFtype
1529 __floatundixf (UDWtype u)
1531 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1532 # error
1533 #endif
1534 XFtype d = (UWtype) (u >> W_TYPE_SIZE);
1535 d *= Wtype_MAXp1_F;
1536 d += (UWtype)u;
1537 return d;
1539 #endif
1541 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1542 TFtype
1543 __floatditf (DWtype u)
1545 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1546 # error
1547 #endif
1548 TFtype d = (Wtype) (u >> W_TYPE_SIZE);
1549 d *= Wtype_MAXp1_F;
1550 d += (UWtype)u;
1551 return d;
1553 #endif
1555 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1556 TFtype
1557 __floatunditf (UDWtype u)
1559 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1560 # error
1561 #endif
1562 TFtype d = (UWtype) (u >> W_TYPE_SIZE);
1563 d *= Wtype_MAXp1_F;
1564 d += (UWtype)u;
1565 return d;
1567 #endif
1569 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1570 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1571 #define DI_SIZE (W_TYPE_SIZE * 2)
1572 #define F_MODE_OK(SIZE) \
1573 (SIZE < DI_SIZE \
1574 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1575 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1576 #if defined(L_floatdisf)
1577 #define FUNC __floatdisf
1578 #define FSTYPE SFtype
1579 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1580 #else
1581 #define FUNC __floatdidf
1582 #define FSTYPE DFtype
1583 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1584 #endif
1586 FSTYPE
1587 FUNC (DWtype u)
1589 #if FSSIZE >= W_TYPE_SIZE
1590 /* When the word size is small, we never get any rounding error. */
1591 FSTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1592 f *= Wtype_MAXp1_F;
1593 f += (UWtype)u;
1594 return f;
1595 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1596 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1597 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1599 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1600 # define FSIZE __LIBGCC_DF_MANT_DIG__
1601 # define FTYPE DFtype
1602 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1603 # define FSIZE __LIBGCC_XF_MANT_DIG__
1604 # define FTYPE XFtype
1605 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1606 # define FSIZE __LIBGCC_TF_MANT_DIG__
1607 # define FTYPE TFtype
1608 #else
1609 # error
1610 #endif
1612 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1614 /* Protect against double-rounding error.
1615 Represent any low-order bits, that might be truncated by a bit that
1616 won't be lost. The bit can go in anywhere below the rounding position
1617 of the FSTYPE. A fixed mask and bit position handles all usual
1618 configurations. */
1619 if (! (- ((DWtype) 1 << FSIZE) < u
1620 && u < ((DWtype) 1 << FSIZE)))
1622 if ((UDWtype) u & (REP_BIT - 1))
1624 u &= ~ (REP_BIT - 1);
1625 u |= REP_BIT;
1629 /* Do the calculation in a wider type so that we don't lose any of
1630 the precision of the high word while multiplying it. */
1631 FTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1632 f *= Wtype_MAXp1_F;
1633 f += (UWtype)u;
1634 return (FSTYPE) f;
1635 #else
1636 #if FSSIZE >= W_TYPE_SIZE - 2
1637 # error
1638 #endif
1639 /* Finally, the word size is larger than the number of bits in the
1640 required FSTYPE, and we've got no suitable wider type. The only
1641 way to avoid double rounding is to special case the
1642 extraction. */
1644 /* If there are no high bits set, fall back to one conversion. */
1645 if ((Wtype)u == u)
1646 return (FSTYPE)(Wtype)u;
1648 /* Otherwise, find the power of two. */
1649 Wtype hi = u >> W_TYPE_SIZE;
1650 if (hi < 0)
1651 hi = -(UWtype) hi;
1653 UWtype count, shift;
1654 #if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE
1655 if (hi == 0)
1656 count = W_TYPE_SIZE;
1657 else
1658 #endif
1659 count_leading_zeros (count, hi);
1661 /* No leading bits means u == minimum. */
1662 if (count == 0)
1663 return Wtype_MAXp1_F * (FSTYPE) (hi | ((UWtype) u != 0));
1665 shift = 1 + W_TYPE_SIZE - count;
1667 /* Shift down the most significant bits. */
1668 hi = u >> shift;
1670 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1671 if ((UWtype)u << (W_TYPE_SIZE - shift))
1672 hi |= 1;
1674 /* Convert the one word of data, and rescale. */
1675 FSTYPE f = hi, e;
1676 if (shift == W_TYPE_SIZE)
1677 e = Wtype_MAXp1_F;
1678 /* The following two cases could be merged if we knew that the target
1679 supported a native unsigned->float conversion. More often, we only
1680 have a signed conversion, and have to add extra fixup code. */
1681 else if (shift == W_TYPE_SIZE - 1)
1682 e = Wtype_MAXp1_F / 2;
1683 else
1684 e = (Wtype)1 << shift;
1685 return f * e;
1686 #endif
1688 #endif
1690 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1691 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1692 #define DI_SIZE (W_TYPE_SIZE * 2)
1693 #define F_MODE_OK(SIZE) \
1694 (SIZE < DI_SIZE \
1695 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1696 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1697 #if defined(L_floatundisf)
1698 #define FUNC __floatundisf
1699 #define FSTYPE SFtype
1700 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1701 #else
1702 #define FUNC __floatundidf
1703 #define FSTYPE DFtype
1704 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1705 #endif
1707 FSTYPE
1708 FUNC (UDWtype u)
1710 #if FSSIZE >= W_TYPE_SIZE
1711 /* When the word size is small, we never get any rounding error. */
1712 FSTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1713 f *= Wtype_MAXp1_F;
1714 f += (UWtype)u;
1715 return f;
1716 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1717 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1718 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1720 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1721 # define FSIZE __LIBGCC_DF_MANT_DIG__
1722 # define FTYPE DFtype
1723 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1724 # define FSIZE __LIBGCC_XF_MANT_DIG__
1725 # define FTYPE XFtype
1726 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1727 # define FSIZE __LIBGCC_TF_MANT_DIG__
1728 # define FTYPE TFtype
1729 #else
1730 # error
1731 #endif
1733 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1735 /* Protect against double-rounding error.
1736 Represent any low-order bits, that might be truncated by a bit that
1737 won't be lost. The bit can go in anywhere below the rounding position
1738 of the FSTYPE. A fixed mask and bit position handles all usual
1739 configurations. */
1740 if (u >= ((UDWtype) 1 << FSIZE))
1742 if ((UDWtype) u & (REP_BIT - 1))
1744 u &= ~ (REP_BIT - 1);
1745 u |= REP_BIT;
1749 /* Do the calculation in a wider type so that we don't lose any of
1750 the precision of the high word while multiplying it. */
1751 FTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1752 f *= Wtype_MAXp1_F;
1753 f += (UWtype)u;
1754 return (FSTYPE) f;
1755 #else
1756 #if FSSIZE == W_TYPE_SIZE - 1
1757 # error
1758 #endif
1759 /* Finally, the word size is larger than the number of bits in the
1760 required FSTYPE, and we've got no suitable wider type. The only
1761 way to avoid double rounding is to special case the
1762 extraction. */
1764 /* If there are no high bits set, fall back to one conversion. */
1765 if ((UWtype)u == u)
1766 return (FSTYPE)(UWtype)u;
1768 /* Otherwise, find the power of two. */
1769 UWtype hi = u >> W_TYPE_SIZE;
1771 UWtype count, shift;
1772 count_leading_zeros (count, hi);
1774 shift = W_TYPE_SIZE - count;
1776 /* Shift down the most significant bits. */
1777 hi = u >> shift;
1779 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1780 if ((UWtype)u << (W_TYPE_SIZE - shift))
1781 hi |= 1;
1783 /* Convert the one word of data, and rescale. */
1784 FSTYPE f = hi, e;
1785 if (shift == W_TYPE_SIZE)
1786 e = Wtype_MAXp1_F;
1787 /* The following two cases could be merged if we knew that the target
1788 supported a native unsigned->float conversion. More often, we only
1789 have a signed conversion, and have to add extra fixup code. */
1790 else if (shift == W_TYPE_SIZE - 1)
1791 e = Wtype_MAXp1_F / 2;
1792 else
1793 e = (Wtype)1 << shift;
1794 return f * e;
1795 #endif
1797 #endif
1799 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1800 UWtype
1801 __fixunsxfSI (XFtype a)
1803 if (a >= - (DFtype) Wtype_MIN)
1804 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1805 return (Wtype) a;
1807 #endif
1809 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1810 UWtype
1811 __fixunsdfSI (DFtype a)
1813 if (a >= - (DFtype) Wtype_MIN)
1814 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1815 return (Wtype) a;
1817 #endif
1819 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1820 UWtype
1821 __fixunssfSI (SFtype a)
1823 if (a >= - (SFtype) Wtype_MIN)
1824 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1825 return (Wtype) a;
1827 #endif
1829 /* Integer power helper used from __builtin_powi for non-constant
1830 exponents. */
1832 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1833 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1834 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1835 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1836 # if defined(L_powisf2)
1837 # define TYPE SFtype
1838 # define NAME __powisf2
1839 # elif defined(L_powidf2)
1840 # define TYPE DFtype
1841 # define NAME __powidf2
1842 # elif defined(L_powixf2)
1843 # define TYPE XFtype
1844 # define NAME __powixf2
1845 # elif defined(L_powitf2)
1846 # define TYPE TFtype
1847 # define NAME __powitf2
1848 # endif
1850 #undef int
1851 #undef unsigned
1852 TYPE
1853 NAME (TYPE x, int m)
1855 unsigned int n = m < 0 ? -m : m;
1856 TYPE y = n % 2 ? x : 1;
1857 while (n >>= 1)
1859 x = x * x;
1860 if (n % 2)
1861 y = y * x;
1863 return m < 0 ? 1/y : y;
1866 #endif
1868 #if((defined(L_mulhc3) || defined(L_divhc3)) && LIBGCC2_HAS_HF_MODE) \
1869 || ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1870 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1871 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1872 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1874 #undef float
1875 #undef double
1876 #undef long
1878 #if defined(L_mulhc3) || defined(L_divhc3)
1879 # define MTYPE HFtype
1880 # define CTYPE HCtype
1881 # define MODE hc
1882 # define CEXT __LIBGCC_HF_FUNC_EXT__
1883 # define NOTRUNC (!__LIBGCC_HF_EXCESS_PRECISION__)
1884 #elif defined(L_mulsc3) || defined(L_divsc3)
1885 # define MTYPE SFtype
1886 # define CTYPE SCtype
1887 # define MODE sc
1888 # define CEXT __LIBGCC_SF_FUNC_EXT__
1889 # define NOTRUNC (!__LIBGCC_SF_EXCESS_PRECISION__)
1890 #elif defined(L_muldc3) || defined(L_divdc3)
1891 # define MTYPE DFtype
1892 # define CTYPE DCtype
1893 # define MODE dc
1894 # define CEXT __LIBGCC_DF_FUNC_EXT__
1895 # define NOTRUNC (!__LIBGCC_DF_EXCESS_PRECISION__)
1896 #elif defined(L_mulxc3) || defined(L_divxc3)
1897 # define MTYPE XFtype
1898 # define CTYPE XCtype
1899 # define MODE xc
1900 # define CEXT __LIBGCC_XF_FUNC_EXT__
1901 # define NOTRUNC (!__LIBGCC_XF_EXCESS_PRECISION__)
1902 #elif defined(L_multc3) || defined(L_divtc3)
1903 # define MTYPE TFtype
1904 # define CTYPE TCtype
1905 # define MODE tc
1906 # define CEXT __LIBGCC_TF_FUNC_EXT__
1907 # define NOTRUNC (!__LIBGCC_TF_EXCESS_PRECISION__)
1908 #else
1909 # error
1910 #endif
1912 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1913 #define _CONCAT3(A,B,C) A##B##C
1915 #define CONCAT2(A,B) _CONCAT2(A,B)
1916 #define _CONCAT2(A,B) A##B
1918 #define isnan(x) __builtin_isnan (x)
1919 #define isfinite(x) __builtin_isfinite (x)
1920 #define isinf(x) __builtin_isinf (x)
1922 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1923 #define I 1i
1925 /* Helpers to make the following code slightly less gross. */
1926 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1927 #define FABS CONCAT2(__builtin_fabs, CEXT)
1929 /* Verify that MTYPE matches up with CEXT. */
1930 extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1];
1932 /* Ensure that we've lost any extra precision. */
1933 #if NOTRUNC
1934 # define TRUNC(x)
1935 #else
1936 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1937 #endif
1939 #if defined(L_mulhc3) || defined(L_mulsc3) || defined(L_muldc3) \
1940 || defined(L_mulxc3) || defined(L_multc3)
1942 CTYPE
1943 CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
1945 MTYPE ac, bd, ad, bc, x, y;
1946 CTYPE res;
1948 ac = a * c;
1949 bd = b * d;
1950 ad = a * d;
1951 bc = b * c;
1953 TRUNC (ac);
1954 TRUNC (bd);
1955 TRUNC (ad);
1956 TRUNC (bc);
1958 x = ac - bd;
1959 y = ad + bc;
1961 if (isnan (x) && isnan (y))
1963 /* Recover infinities that computed as NaN + iNaN. */
1964 _Bool recalc = 0;
1965 if (isinf (a) || isinf (b))
1967 /* z is infinite. "Box" the infinity and change NaNs in
1968 the other factor to 0. */
1969 a = COPYSIGN (isinf (a) ? 1 : 0, a);
1970 b = COPYSIGN (isinf (b) ? 1 : 0, b);
1971 if (isnan (c)) c = COPYSIGN (0, c);
1972 if (isnan (d)) d = COPYSIGN (0, d);
1973 recalc = 1;
1975 if (isinf (c) || isinf (d))
1977 /* w is infinite. "Box" the infinity and change NaNs in
1978 the other factor to 0. */
1979 c = COPYSIGN (isinf (c) ? 1 : 0, c);
1980 d = COPYSIGN (isinf (d) ? 1 : 0, d);
1981 if (isnan (a)) a = COPYSIGN (0, a);
1982 if (isnan (b)) b = COPYSIGN (0, b);
1983 recalc = 1;
1985 if (!recalc
1986 && (isinf (ac) || isinf (bd)
1987 || isinf (ad) || isinf (bc)))
1989 /* Recover infinities from overflow by changing NaNs to 0. */
1990 if (isnan (a)) a = COPYSIGN (0, a);
1991 if (isnan (b)) b = COPYSIGN (0, b);
1992 if (isnan (c)) c = COPYSIGN (0, c);
1993 if (isnan (d)) d = COPYSIGN (0, d);
1994 recalc = 1;
1996 if (recalc)
1998 x = INFINITY * (a * c - b * d);
1999 y = INFINITY * (a * d + b * c);
2003 __real__ res = x;
2004 __imag__ res = y;
2005 return res;
2007 #endif /* complex multiply */
2009 #if defined(L_divhc3) || defined(L_divsc3) || defined(L_divdc3) \
2010 || defined(L_divxc3) || defined(L_divtc3)
2012 CTYPE
2013 CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
2015 MTYPE denom, ratio, x, y;
2016 CTYPE res;
2018 /* ??? We can get better behavior from logarithmic scaling instead of
2019 the division. But that would mean starting to link libgcc against
2020 libm. We could implement something akin to ldexp/frexp as gcc builtins
2021 fairly easily... */
2022 if (FABS (c) < FABS (d))
2024 ratio = c / d;
2025 denom = (c * ratio) + d;
2026 x = ((a * ratio) + b) / denom;
2027 y = ((b * ratio) - a) / denom;
2029 else
2031 ratio = d / c;
2032 denom = (d * ratio) + c;
2033 x = ((b * ratio) + a) / denom;
2034 y = (b - (a * ratio)) / denom;
2037 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
2038 are nonzero/zero, infinite/finite, and finite/infinite. */
2039 if (isnan (x) && isnan (y))
2041 if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b)))
2043 x = COPYSIGN (INFINITY, c) * a;
2044 y = COPYSIGN (INFINITY, c) * b;
2046 else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d))
2048 a = COPYSIGN (isinf (a) ? 1 : 0, a);
2049 b = COPYSIGN (isinf (b) ? 1 : 0, b);
2050 x = INFINITY * (a * c + b * d);
2051 y = INFINITY * (b * c - a * d);
2053 else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b))
2055 c = COPYSIGN (isinf (c) ? 1 : 0, c);
2056 d = COPYSIGN (isinf (d) ? 1 : 0, d);
2057 x = 0.0 * (a * c + b * d);
2058 y = 0.0 * (b * c - a * d);
2062 __real__ res = x;
2063 __imag__ res = y;
2064 return res;
2066 #endif /* complex divide */
2068 #endif /* all complex float routines */
2070 /* From here on down, the routines use normal data types. */
2072 #define SItype bogus_type
2073 #define USItype bogus_type
2074 #define DItype bogus_type
2075 #define UDItype bogus_type
2076 #define SFtype bogus_type
2077 #define DFtype bogus_type
2078 #undef Wtype
2079 #undef UWtype
2080 #undef HWtype
2081 #undef UHWtype
2082 #undef DWtype
2083 #undef UDWtype
2085 #undef char
2086 #undef short
2087 #undef int
2088 #undef long
2089 #undef unsigned
2090 #undef float
2091 #undef double
2093 #ifdef L__gcc_bcmp
2095 /* Like bcmp except the sign is meaningful.
2096 Result is negative if S1 is less than S2,
2097 positive if S1 is greater, 0 if S1 and S2 are equal. */
2100 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
2102 while (size > 0)
2104 const unsigned char c1 = *s1++, c2 = *s2++;
2105 if (c1 != c2)
2106 return c1 - c2;
2107 size--;
2109 return 0;
2112 #endif
2114 /* __eprintf used to be used by GCC's private version of <assert.h>.
2115 We no longer provide that header, but this routine remains in libgcc.a
2116 for binary backward compatibility. Note that it is not included in
2117 the shared version of libgcc. */
2118 #ifdef L_eprintf
2119 #ifndef inhibit_libc
2121 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2122 #include <stdio.h>
2124 void
2125 __eprintf (const char *string, const char *expression,
2126 unsigned int line, const char *filename)
2128 fprintf (stderr, string, expression, line, filename);
2129 fflush (stderr);
2130 abort ();
2133 #endif
2134 #endif
2137 #ifdef L_clear_cache
2138 /* Clear part of an instruction cache. */
2140 void
2141 __clear_cache (void *beg __attribute__((__unused__)),
2142 void *end __attribute__((__unused__)))
2144 #ifdef CLEAR_INSN_CACHE
2145 /* Cast the void* pointers to char* as some implementations
2146 of the macro assume the pointers can be subtracted from
2147 one another. */
2148 CLEAR_INSN_CACHE ((char *) beg, (char *) end);
2149 #endif /* CLEAR_INSN_CACHE */
2152 #endif /* L_clear_cache */
2154 #ifdef L_trampoline
2156 /* Jump to a trampoline, loading the static chain address. */
2158 #if defined(WINNT) && ! defined(__CYGWIN__)
2159 #include <windows.h>
2160 int getpagesize (void);
2161 int mprotect (char *,int, int);
2164 getpagesize (void)
2166 #ifdef _ALPHA_
2167 return 8192;
2168 #else
2169 return 4096;
2170 #endif
2174 mprotect (char *addr, int len, int prot)
2176 DWORD np, op;
2178 if (prot == 7)
2179 np = 0x40;
2180 else if (prot == 5)
2181 np = 0x20;
2182 else if (prot == 4)
2183 np = 0x10;
2184 else if (prot == 3)
2185 np = 0x04;
2186 else if (prot == 1)
2187 np = 0x02;
2188 else if (prot == 0)
2189 np = 0x01;
2190 else
2191 return -1;
2193 if (VirtualProtect (addr, len, np, &op))
2194 return 0;
2195 else
2196 return -1;
2199 #endif /* WINNT && ! __CYGWIN__ */
2201 #ifdef TRANSFER_FROM_TRAMPOLINE
2202 TRANSFER_FROM_TRAMPOLINE
2203 #endif
2204 #endif /* L_trampoline */
2206 #ifndef __CYGWIN__
2207 #ifdef L__main
2209 #include "gbl-ctors.h"
2211 /* Some systems use __main in a way incompatible with its use in gcc, in these
2212 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2213 give the same symbol without quotes for an alternative entry point. You
2214 must define both, or neither. */
2215 #ifndef NAME__MAIN
2216 #define NAME__MAIN "__main"
2217 #define SYMBOL__MAIN __main
2218 #endif
2220 #if defined (__LIBGCC_INIT_SECTION_ASM_OP__) \
2221 || defined (__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
2222 #undef HAS_INIT_SECTION
2223 #define HAS_INIT_SECTION
2224 #endif
2226 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2228 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2229 code to run constructors. In that case, we need to handle EH here, too.
2230 But MINGW32 is special because it handles CRTSTUFF and EH on its own. */
2232 #ifdef __MINGW32__
2233 #undef __LIBGCC_EH_FRAME_SECTION_NAME__
2234 #endif
2236 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2237 #include "unwind-dw2-fde.h"
2238 extern unsigned char __EH_FRAME_BEGIN__[];
2239 #endif
2241 /* Run all the global destructors on exit from the program. */
2243 void
2244 __do_global_dtors (void)
2246 #ifdef DO_GLOBAL_DTORS_BODY
2247 DO_GLOBAL_DTORS_BODY;
2248 #else
2249 static func_ptr *p = __DTOR_LIST__ + 1;
2250 while (*p)
2252 p++;
2253 (*(p-1)) ();
2255 #endif
2256 #if defined (__LIBGCC_EH_FRAME_SECTION_NAME__) && !defined (HAS_INIT_SECTION)
2258 static int completed = 0;
2259 if (! completed)
2261 completed = 1;
2262 __deregister_frame_info (__EH_FRAME_BEGIN__);
2265 #endif
2267 #endif
2269 #ifndef HAS_INIT_SECTION
2270 /* Run all the global constructors on entry to the program. */
2272 void
2273 __do_global_ctors (void)
2275 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2277 static struct object object;
2278 __register_frame_info (__EH_FRAME_BEGIN__, &object);
2280 #endif
2281 DO_GLOBAL_CTORS_BODY;
2282 atexit (__do_global_dtors);
2284 #endif /* no HAS_INIT_SECTION */
2286 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2287 /* Subroutine called automatically by `main'.
2288 Compiling a global function named `main'
2289 produces an automatic call to this function at the beginning.
2291 For many systems, this routine calls __do_global_ctors.
2292 For systems which support a .init section we use the .init section
2293 to run __do_global_ctors, so we need not do anything here. */
2295 extern void SYMBOL__MAIN (void);
2296 void
2297 SYMBOL__MAIN (void)
2299 /* Support recursive calls to `main': run initializers just once. */
2300 static int initialized;
2301 if (! initialized)
2303 initialized = 1;
2304 __do_global_ctors ();
2307 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2309 #endif /* L__main */
2310 #endif /* __CYGWIN__ */
2312 #ifdef L_ctors
2314 #include "gbl-ctors.h"
2316 /* Provide default definitions for the lists of constructors and
2317 destructors, so that we don't get linker errors. These symbols are
2318 intentionally bss symbols, so that gld and/or collect will provide
2319 the right values. */
2321 /* We declare the lists here with two elements each,
2322 so that they are valid empty lists if no other definition is loaded.
2324 If we are using the old "set" extensions to have the gnu linker
2325 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2326 must be in the bss/common section.
2328 Long term no port should use those extensions. But many still do. */
2329 #if !defined(__LIBGCC_INIT_SECTION_ASM_OP__)
2330 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2331 func_ptr __CTOR_LIST__[2] = {0, 0};
2332 func_ptr __DTOR_LIST__[2] = {0, 0};
2333 #else
2334 func_ptr __CTOR_LIST__[2];
2335 func_ptr __DTOR_LIST__[2];
2336 #endif
2337 #endif /* no __LIBGCC_INIT_SECTION_ASM_OP__ */
2338 #endif /* L_ctors */
2339 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */