OSDN Git Service

PR target/5362
[pf3gnuchains/gcc-fork.git] / gcc / libgcc2.c
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, 2005, 2007, 2008
5    Free Software Foundation, Inc.
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13
14 In addition to the permissions in the GNU General Public License, the
15 Free Software Foundation gives you unlimited permission to link the
16 compiled version of this file into combinations with other programs,
17 and to distribute those combinations without any restriction coming
18 from the use of this file.  (The General Public License restrictions
19 do apply in other respects; for example, they cover modification of
20 the file, and distribution when not linked into a combine
21 executable.)
22
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26 for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING.  If not, write to the Free
30 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
31 02110-1301, USA.  */
32
33 #include "tconfig.h"
34 #include "tsystem.h"
35 #include "coretypes.h"
36 #include "tm.h"
37
38 #ifdef HAVE_GAS_HIDDEN
39 #define ATTRIBUTE_HIDDEN  __attribute__ ((__visibility__ ("hidden")))
40 #else
41 #define ATTRIBUTE_HIDDEN
42 #endif
43
44 #ifndef MIN_UNITS_PER_WORD
45 #define MIN_UNITS_PER_WORD UNITS_PER_WORD
46 #endif
47
48 /* Work out the largest "word" size that we can deal with on this target.  */
49 #if MIN_UNITS_PER_WORD > 4
50 # define LIBGCC2_MAX_UNITS_PER_WORD 8
51 #elif (MIN_UNITS_PER_WORD > 2 \
52        || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
53 # define LIBGCC2_MAX_UNITS_PER_WORD 4
54 #else
55 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
56 #endif
57
58 /* Work out what word size we are using for this compilation.
59    The value can be set on the command line.  */
60 #ifndef LIBGCC2_UNITS_PER_WORD
61 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
62 #endif
63
64 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
65
66 #include "libgcc2.h"
67 \f
68 #ifdef DECLARE_LIBRARY_RENAMES
69   DECLARE_LIBRARY_RENAMES
70 #endif
71
72 #if defined (L_negdi2)
73 DWtype
74 __negdi2 (DWtype u)
75 {
76   const DWunion uu = {.ll = u};
77   const DWunion w = { {.low = -uu.s.low,
78                        .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
79
80   return w.ll;
81 }
82 #endif
83
84 #ifdef L_addvsi3
85 Wtype
86 __addvSI3 (Wtype a, Wtype b)
87 {
88   const Wtype w = (UWtype) a + (UWtype) b;
89
90   if (b >= 0 ? w < a : w > a)
91     abort ();
92
93   return w;
94 }
95 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
96 SItype
97 __addvsi3 (SItype a, SItype b)
98 {
99   const SItype w = (USItype) a + (USItype) b;
100
101   if (b >= 0 ? w < a : w > a)
102     abort ();
103
104   return w;
105 }
106 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
107 #endif
108 \f
109 #ifdef L_addvdi3
110 DWtype
111 __addvDI3 (DWtype a, DWtype b)
112 {
113   const DWtype w = (UDWtype) a + (UDWtype) b;
114
115   if (b >= 0 ? w < a : w > a)
116     abort ();
117
118   return w;
119 }
120 #endif
121 \f
122 #ifdef L_subvsi3
123 Wtype
124 __subvSI3 (Wtype a, Wtype b)
125 {
126   const Wtype w = (UWtype) a - (UWtype) b;
127
128   if (b >= 0 ? w > a : w < a)
129     abort ();
130
131   return w;
132 }
133 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
134 SItype
135 __subvsi3 (SItype a, SItype b)
136 {
137   const SItype w = (USItype) a - (USItype) b;
138
139   if (b >= 0 ? w > a : w < a)
140     abort ();
141
142   return w;
143 }
144 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
145 #endif
146 \f
147 #ifdef L_subvdi3
148 DWtype
149 __subvDI3 (DWtype a, DWtype b)
150 {
151   const DWtype w = (UDWtype) a - (UDWtype) b;
152
153   if (b >= 0 ? w > a : w < a)
154     abort ();
155
156   return w;
157 }
158 #endif
159 \f
160 #ifdef L_mulvsi3
161 Wtype
162 __mulvSI3 (Wtype a, Wtype b)
163 {
164   const DWtype w = (DWtype) a * (DWtype) b;
165
166   if ((Wtype) (w >> W_TYPE_SIZE) != (Wtype) w >> (W_TYPE_SIZE - 1))
167     abort ();
168
169   return w;
170 }
171 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
172 #undef WORD_SIZE
173 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
174 SItype
175 __mulvsi3 (SItype a, SItype b)
176 {
177   const DItype w = (DItype) a * (DItype) b;
178
179   if ((SItype) (w >> WORD_SIZE) != (SItype) w >> (WORD_SIZE-1))
180     abort ();
181
182   return w;
183 }
184 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
185 #endif
186 \f
187 #ifdef L_negvsi2
188 Wtype
189 __negvSI2 (Wtype a)
190 {
191   const Wtype w = -(UWtype) a;
192
193   if (a >= 0 ? w > 0 : w < 0)
194     abort ();
195
196    return w;
197 }
198 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
199 SItype
200 __negvsi2 (SItype a)
201 {
202   const SItype w = -(USItype) a;
203
204   if (a >= 0 ? w > 0 : w < 0)
205     abort ();
206
207    return w;
208 }
209 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
210 #endif
211 \f
212 #ifdef L_negvdi2
213 DWtype
214 __negvDI2 (DWtype a)
215 {
216   const DWtype w = -(UDWtype) a;
217
218   if (a >= 0 ? w > 0 : w < 0)
219     abort ();
220
221   return w;
222 }
223 #endif
224 \f
225 #ifdef L_absvsi2
226 Wtype
227 __absvSI2 (Wtype a)
228 {
229   Wtype w = a;
230
231   if (a < 0)
232 #ifdef L_negvsi2
233     w = __negvSI2 (a);
234 #else
235     w = -(UWtype) a;
236
237   if (w < 0)
238     abort ();
239 #endif
240
241    return w;
242 }
243 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
244 SItype
245 __absvsi2 (SItype a)
246 {
247   SItype w = a;
248
249   if (a < 0)
250 #ifdef L_negvsi2
251     w = __negvsi2 (a);
252 #else
253     w = -(USItype) a;
254
255   if (w < 0)
256     abort ();
257 #endif
258
259    return w;
260 }
261 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
262 #endif
263 \f
264 #ifdef L_absvdi2
265 DWtype
266 __absvDI2 (DWtype a)
267 {
268   DWtype w = a;
269
270   if (a < 0)
271 #ifdef L_negvdi2
272     w = __negvDI2 (a);
273 #else
274     w = -(UDWtype) a;
275
276   if (w < 0)
277     abort ();
278 #endif
279
280   return w;
281 }
282 #endif
283 \f
284 #ifdef L_mulvdi3
285 DWtype
286 __mulvDI3 (DWtype u, DWtype v)
287 {
288   /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
289      but the checked multiplication needs only two.  */
290   const DWunion uu = {.ll = u};
291   const DWunion vv = {.ll = v};
292
293   if (__builtin_expect (uu.s.high == uu.s.low >> (W_TYPE_SIZE - 1), 1))
294     {
295       /* u fits in a single Wtype.  */
296       if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
297         {
298           /* v fits in a single Wtype as well.  */
299           /* A single multiplication.  No overflow risk.  */
300           return (DWtype) uu.s.low * (DWtype) vv.s.low;
301         }
302       else
303         {
304           /* Two multiplications.  */
305           DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
306                         * (UDWtype) (UWtype) vv.s.low};
307           DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
308                         * (UDWtype) (UWtype) vv.s.high};
309
310           if (vv.s.high < 0)
311             w1.s.high -= uu.s.low;
312           if (uu.s.low < 0)
313             w1.ll -= vv.ll;
314           w1.ll += (UWtype) w0.s.high;
315           if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
316             {
317               w0.s.high = w1.s.low;
318               return w0.ll;
319             }
320         }
321     }
322   else
323     {
324       if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
325         {
326           /* v fits into a single Wtype.  */
327           /* Two multiplications.  */
328           DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
329                         * (UDWtype) (UWtype) vv.s.low};
330           DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
331                         * (UDWtype) (UWtype) vv.s.low};
332
333           if (uu.s.high < 0)
334             w1.s.high -= vv.s.low;
335           if (vv.s.low < 0)
336             w1.ll -= uu.ll;
337           w1.ll += (UWtype) w0.s.high;
338           if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
339             {
340               w0.s.high = w1.s.low;
341               return w0.ll;
342             }
343         }
344       else
345         {
346           /* A few sign checks and a single multiplication.  */
347           if (uu.s.high >= 0)
348             {
349               if (vv.s.high >= 0)
350                 {
351                   if (uu.s.high == 0 && vv.s.high == 0)
352                     {
353                       const DWtype w = (UDWtype) (UWtype) uu.s.low
354                         * (UDWtype) (UWtype) vv.s.low;
355                       if (__builtin_expect (w >= 0, 1))
356                         return w;
357                     }
358                 }
359               else
360                 {
361                   if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
362                     {
363                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
364                                     * (UDWtype) (UWtype) vv.s.low};
365
366                       ww.s.high -= uu.s.low;
367                       if (__builtin_expect (ww.s.high < 0, 1))
368                         return ww.ll;
369                     }
370                 }
371             }
372           else
373             {
374               if (vv.s.high >= 0)
375                 {
376                   if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
377                     {
378                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
379                                     * (UDWtype) (UWtype) vv.s.low};
380
381                       ww.s.high -= vv.s.low;
382                       if (__builtin_expect (ww.s.high < 0, 1))
383                         return ww.ll;
384                     }
385                 }
386               else
387                 {
388                   if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
389                     {
390                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
391                                     * (UDWtype) (UWtype) vv.s.low};
392
393                       ww.s.high -= uu.s.low;
394                       ww.s.high -= vv.s.low;
395                       if (__builtin_expect (ww.s.high >= 0, 1))
396                         return ww.ll;
397                     }
398                 }
399             }
400         }
401     }
402
403   /* Overflow.  */
404   abort ();
405 }
406 #endif
407 \f
408
409 /* Unless shift functions are defined with full ANSI prototypes,
410    parameter b will be promoted to int if shift_count_type is smaller than an int.  */
411 #ifdef L_lshrdi3
412 DWtype
413 __lshrdi3 (DWtype u, shift_count_type b)
414 {
415   if (b == 0)
416     return u;
417
418   const DWunion uu = {.ll = u};
419   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
420   DWunion w;
421
422   if (bm <= 0)
423     {
424       w.s.high = 0;
425       w.s.low = (UWtype) uu.s.high >> -bm;
426     }
427   else
428     {
429       const UWtype carries = (UWtype) uu.s.high << bm;
430
431       w.s.high = (UWtype) uu.s.high >> b;
432       w.s.low = ((UWtype) uu.s.low >> b) | carries;
433     }
434
435   return w.ll;
436 }
437 #endif
438
439 #ifdef L_ashldi3
440 DWtype
441 __ashldi3 (DWtype u, shift_count_type b)
442 {
443   if (b == 0)
444     return u;
445
446   const DWunion uu = {.ll = u};
447   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
448   DWunion w;
449
450   if (bm <= 0)
451     {
452       w.s.low = 0;
453       w.s.high = (UWtype) uu.s.low << -bm;
454     }
455   else
456     {
457       const UWtype carries = (UWtype) uu.s.low >> bm;
458
459       w.s.low = (UWtype) uu.s.low << b;
460       w.s.high = ((UWtype) uu.s.high << b) | carries;
461     }
462
463   return w.ll;
464 }
465 #endif
466
467 #ifdef L_ashrdi3
468 DWtype
469 __ashrdi3 (DWtype u, shift_count_type b)
470 {
471   if (b == 0)
472     return u;
473
474   const DWunion uu = {.ll = u};
475   const shift_count_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
476   DWunion w;
477
478   if (bm <= 0)
479     {
480       /* w.s.high = 1..1 or 0..0 */
481       w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
482       w.s.low = uu.s.high >> -bm;
483     }
484   else
485     {
486       const UWtype carries = (UWtype) uu.s.high << bm;
487
488       w.s.high = uu.s.high >> b;
489       w.s.low = ((UWtype) uu.s.low >> b) | carries;
490     }
491
492   return w.ll;
493 }
494 #endif
495 \f
496 #ifdef L_bswapsi2
497 SItype
498 __bswapsi2 (SItype u)
499 {
500   return ((((u) & 0xff000000) >> 24)
501           | (((u) & 0x00ff0000) >>  8)
502           | (((u) & 0x0000ff00) <<  8)
503           | (((u) & 0x000000ff) << 24));
504 }
505 #endif
506 #ifdef L_bswapdi2
507 DItype
508 __bswapdi2 (DItype u)
509 {
510   return ((((u) & 0xff00000000000000ull) >> 56)
511           | (((u) & 0x00ff000000000000ull) >> 40)
512           | (((u) & 0x0000ff0000000000ull) >> 24)
513           | (((u) & 0x000000ff00000000ull) >>  8)
514           | (((u) & 0x00000000ff000000ull) <<  8)
515           | (((u) & 0x0000000000ff0000ull) << 24)
516           | (((u) & 0x000000000000ff00ull) << 40)
517           | (((u) & 0x00000000000000ffull) << 56));
518 }
519 #endif
520 #ifdef L_ffssi2
521 #undef int
522 int
523 __ffsSI2 (UWtype u)
524 {
525   UWtype count;
526
527   if (u == 0)
528     return 0;
529
530   count_trailing_zeros (count, u);
531   return count + 1;
532 }
533 #endif
534 \f
535 #ifdef L_ffsdi2
536 #undef int
537 int
538 __ffsDI2 (DWtype u)
539 {
540   const DWunion uu = {.ll = u};
541   UWtype word, count, add;
542
543   if (uu.s.low != 0)
544     word = uu.s.low, add = 0;
545   else if (uu.s.high != 0)
546     word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
547   else
548     return 0;
549
550   count_trailing_zeros (count, word);
551   return count + add + 1;
552 }
553 #endif
554 \f
555 #ifdef L_muldi3
556 DWtype
557 __muldi3 (DWtype u, DWtype v)
558 {
559   const DWunion uu = {.ll = u};
560   const DWunion vv = {.ll = v};
561   DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
562
563   w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
564                + (UWtype) uu.s.high * (UWtype) vv.s.low);
565
566   return w.ll;
567 }
568 #endif
569 \f
570 #if (defined (L_udivdi3) || defined (L_divdi3) || \
571      defined (L_umoddi3) || defined (L_moddi3))
572 #if defined (sdiv_qrnnd)
573 #define L_udiv_w_sdiv
574 #endif
575 #endif
576
577 #ifdef L_udiv_w_sdiv
578 #if defined (sdiv_qrnnd)
579 #if (defined (L_udivdi3) || defined (L_divdi3) || \
580      defined (L_umoddi3) || defined (L_moddi3))
581 static inline __attribute__ ((__always_inline__))
582 #endif
583 UWtype
584 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
585 {
586   UWtype q, r;
587   UWtype c0, c1, b1;
588
589   if ((Wtype) d >= 0)
590     {
591       if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
592         {
593           /* Dividend, divisor, and quotient are nonnegative.  */
594           sdiv_qrnnd (q, r, a1, a0, d);
595         }
596       else
597         {
598           /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d.  */
599           sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
600           /* Divide (c1*2^32 + c0) by d.  */
601           sdiv_qrnnd (q, r, c1, c0, d);
602           /* Add 2^31 to quotient.  */
603           q += (UWtype) 1 << (W_TYPE_SIZE - 1);
604         }
605     }
606   else
607     {
608       b1 = d >> 1;                      /* d/2, between 2^30 and 2^31 - 1 */
609       c1 = a1 >> 1;                     /* A/2 */
610       c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
611
612       if (a1 < b1)                      /* A < 2^32*b1, so A/2 < 2^31*b1 */
613         {
614           sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
615
616           r = 2*r + (a0 & 1);           /* Remainder from A/(2*b1) */
617           if ((d & 1) != 0)
618             {
619               if (r >= q)
620                 r = r - q;
621               else if (q - r <= d)
622                 {
623                   r = r - q + d;
624                   q--;
625                 }
626               else
627                 {
628                   r = r - q + 2*d;
629                   q -= 2;
630                 }
631             }
632         }
633       else if (c1 < b1)                 /* So 2^31 <= (A/2)/b1 < 2^32 */
634         {
635           c1 = (b1 - 1) - c1;
636           c0 = ~c0;                     /* logical NOT */
637
638           sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
639
640           q = ~q;                       /* (A/2)/b1 */
641           r = (b1 - 1) - r;
642
643           r = 2*r + (a0 & 1);           /* A/(2*b1) */
644
645           if ((d & 1) != 0)
646             {
647               if (r >= q)
648                 r = r - q;
649               else if (q - r <= d)
650                 {
651                   r = r - q + d;
652                   q--;
653                 }
654               else
655                 {
656                   r = r - q + 2*d;
657                   q -= 2;
658                 }
659             }
660         }
661       else                              /* Implies c1 = b1 */
662         {                               /* Hence a1 = d - 1 = 2*b1 - 1 */
663           if (a0 >= -d)
664             {
665               q = -1;
666               r = a0 + d;
667             }
668           else
669             {
670               q = -2;
671               r = a0 + 2*d;
672             }
673         }
674     }
675
676   *rp = r;
677   return q;
678 }
679 #else
680 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv.  */
681 UWtype
682 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
683                UWtype a1 __attribute__ ((__unused__)),
684                UWtype a0 __attribute__ ((__unused__)),
685                UWtype d __attribute__ ((__unused__)))
686 {
687   return 0;
688 }
689 #endif
690 #endif
691 \f
692 #if (defined (L_udivdi3) || defined (L_divdi3) || \
693      defined (L_umoddi3) || defined (L_moddi3))
694 #define L_udivmoddi4
695 #endif
696
697 #ifdef L_clz
698 const UQItype __clz_tab[256] =
699 {
700   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,
701   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,
702   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,
703   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,
704   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,
705   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,
706   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,
707   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
708 };
709 #endif
710 \f
711 #ifdef L_clzsi2
712 #undef int
713 int
714 __clzSI2 (UWtype x)
715 {
716   Wtype ret;
717
718   count_leading_zeros (ret, x);
719
720   return ret;
721 }
722 #endif
723 \f
724 #ifdef L_clzdi2
725 #undef int
726 int
727 __clzDI2 (UDWtype x)
728 {
729   const DWunion uu = {.ll = x};
730   UWtype word;
731   Wtype ret, add;
732
733   if (uu.s.high)
734     word = uu.s.high, add = 0;
735   else
736     word = uu.s.low, add = W_TYPE_SIZE;
737
738   count_leading_zeros (ret, word);
739   return ret + add;
740 }
741 #endif
742 \f
743 #ifdef L_ctzsi2
744 #undef int
745 int
746 __ctzSI2 (UWtype x)
747 {
748   Wtype ret;
749
750   count_trailing_zeros (ret, x);
751
752   return ret;
753 }
754 #endif
755 \f
756 #ifdef L_ctzdi2
757 #undef int
758 int
759 __ctzDI2 (UDWtype x)
760 {
761   const DWunion uu = {.ll = x};
762   UWtype word;
763   Wtype ret, add;
764
765   if (uu.s.low)
766     word = uu.s.low, add = 0;
767   else
768     word = uu.s.high, add = W_TYPE_SIZE;
769
770   count_trailing_zeros (ret, word);
771   return ret + add;
772 }
773 #endif
774
775 #ifdef L_popcount_tab
776 const UQItype __popcount_tab[256] =
777 {
778     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,
779     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,
780     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,
781     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,
782     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,
783     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,
784     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,
785     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
786 };
787 #endif
788 \f
789 #ifdef L_popcountsi2
790 #undef int
791 int
792 __popcountSI2 (UWtype x)
793 {
794   int i, ret = 0;
795
796   for (i = 0; i < W_TYPE_SIZE; i += 8)
797     ret += __popcount_tab[(x >> i) & 0xff];
798
799   return ret;
800 }
801 #endif
802 \f
803 #ifdef L_popcountdi2
804 #undef int
805 int
806 __popcountDI2 (UDWtype x)
807 {
808   int i, ret = 0;
809
810   for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
811     ret += __popcount_tab[(x >> i) & 0xff];
812
813   return ret;
814 }
815 #endif
816 \f
817 #ifdef L_paritysi2
818 #undef int
819 int
820 __paritySI2 (UWtype x)
821 {
822 #if W_TYPE_SIZE > 64
823 # error "fill out the table"
824 #endif
825 #if W_TYPE_SIZE > 32
826   x ^= x >> 32;
827 #endif
828 #if W_TYPE_SIZE > 16
829   x ^= x >> 16;
830 #endif
831   x ^= x >> 8;
832   x ^= x >> 4;
833   x &= 0xf;
834   return (0x6996 >> x) & 1;
835 }
836 #endif
837 \f
838 #ifdef L_paritydi2
839 #undef int
840 int
841 __parityDI2 (UDWtype x)
842 {
843   const DWunion uu = {.ll = x};
844   UWtype nx = uu.s.low ^ uu.s.high;
845
846 #if W_TYPE_SIZE > 64
847 # error "fill out the table"
848 #endif
849 #if W_TYPE_SIZE > 32
850   nx ^= nx >> 32;
851 #endif
852 #if W_TYPE_SIZE > 16
853   nx ^= nx >> 16;
854 #endif
855   nx ^= nx >> 8;
856   nx ^= nx >> 4;
857   nx &= 0xf;
858   return (0x6996 >> nx) & 1;
859 }
860 #endif
861
862 #ifdef L_udivmoddi4
863
864 #if (defined (L_udivdi3) || defined (L_divdi3) || \
865      defined (L_umoddi3) || defined (L_moddi3))
866 static inline __attribute__ ((__always_inline__))
867 #endif
868 UDWtype
869 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
870 {
871   const DWunion nn = {.ll = n};
872   const DWunion dd = {.ll = d};
873   DWunion rr;
874   UWtype d0, d1, n0, n1, n2;
875   UWtype q0, q1;
876   UWtype b, bm;
877
878   d0 = dd.s.low;
879   d1 = dd.s.high;
880   n0 = nn.s.low;
881   n1 = nn.s.high;
882
883 #if !UDIV_NEEDS_NORMALIZATION
884   if (d1 == 0)
885     {
886       if (d0 > n1)
887         {
888           /* 0q = nn / 0D */
889
890           udiv_qrnnd (q0, n0, n1, n0, d0);
891           q1 = 0;
892
893           /* Remainder in n0.  */
894         }
895       else
896         {
897           /* qq = NN / 0d */
898
899           if (d0 == 0)
900             d0 = 1 / d0;        /* Divide intentionally by zero.  */
901
902           udiv_qrnnd (q1, n1, 0, n1, d0);
903           udiv_qrnnd (q0, n0, n1, n0, d0);
904
905           /* Remainder in n0.  */
906         }
907
908       if (rp != 0)
909         {
910           rr.s.low = n0;
911           rr.s.high = 0;
912           *rp = rr.ll;
913         }
914     }
915
916 #else /* UDIV_NEEDS_NORMALIZATION */
917
918   if (d1 == 0)
919     {
920       if (d0 > n1)
921         {
922           /* 0q = nn / 0D */
923
924           count_leading_zeros (bm, d0);
925
926           if (bm != 0)
927             {
928               /* Normalize, i.e. make the most significant bit of the
929                  denominator set.  */
930
931               d0 = d0 << bm;
932               n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
933               n0 = n0 << bm;
934             }
935
936           udiv_qrnnd (q0, n0, n1, n0, d0);
937           q1 = 0;
938
939           /* Remainder in n0 >> bm.  */
940         }
941       else
942         {
943           /* qq = NN / 0d */
944
945           if (d0 == 0)
946             d0 = 1 / d0;        /* Divide intentionally by zero.  */
947
948           count_leading_zeros (bm, d0);
949
950           if (bm == 0)
951             {
952               /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
953                  conclude (the most significant bit of n1 is set) /\ (the
954                  leading quotient digit q1 = 1).
955
956                  This special case is necessary, not an optimization.
957                  (Shifts counts of W_TYPE_SIZE are undefined.)  */
958
959               n1 -= d0;
960               q1 = 1;
961             }
962           else
963             {
964               /* Normalize.  */
965
966               b = W_TYPE_SIZE - bm;
967
968               d0 = d0 << bm;
969               n2 = n1 >> b;
970               n1 = (n1 << bm) | (n0 >> b);
971               n0 = n0 << bm;
972
973               udiv_qrnnd (q1, n1, n2, n1, d0);
974             }
975
976           /* n1 != d0...  */
977
978           udiv_qrnnd (q0, n0, n1, n0, d0);
979
980           /* Remainder in n0 >> bm.  */
981         }
982
983       if (rp != 0)
984         {
985           rr.s.low = n0 >> bm;
986           rr.s.high = 0;
987           *rp = rr.ll;
988         }
989     }
990 #endif /* UDIV_NEEDS_NORMALIZATION */
991
992   else
993     {
994       if (d1 > n1)
995         {
996           /* 00 = nn / DD */
997
998           q0 = 0;
999           q1 = 0;
1000
1001           /* Remainder in n1n0.  */
1002           if (rp != 0)
1003             {
1004               rr.s.low = n0;
1005               rr.s.high = n1;
1006               *rp = rr.ll;
1007             }
1008         }
1009       else
1010         {
1011           /* 0q = NN / dd */
1012
1013           count_leading_zeros (bm, d1);
1014           if (bm == 0)
1015             {
1016               /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1017                  conclude (the most significant bit of n1 is set) /\ (the
1018                  quotient digit q0 = 0 or 1).
1019
1020                  This special case is necessary, not an optimization.  */
1021
1022               /* The condition on the next line takes advantage of that
1023                  n1 >= d1 (true due to program flow).  */
1024               if (n1 > d1 || n0 >= d0)
1025                 {
1026                   q0 = 1;
1027                   sub_ddmmss (n1, n0, n1, n0, d1, d0);
1028                 }
1029               else
1030                 q0 = 0;
1031
1032               q1 = 0;
1033
1034               if (rp != 0)
1035                 {
1036                   rr.s.low = n0;
1037                   rr.s.high = n1;
1038                   *rp = rr.ll;
1039                 }
1040             }
1041           else
1042             {
1043               UWtype m1, m0;
1044               /* Normalize.  */
1045
1046               b = W_TYPE_SIZE - bm;
1047
1048               d1 = (d1 << bm) | (d0 >> b);
1049               d0 = d0 << bm;
1050               n2 = n1 >> b;
1051               n1 = (n1 << bm) | (n0 >> b);
1052               n0 = n0 << bm;
1053
1054               udiv_qrnnd (q0, n1, n2, n1, d1);
1055               umul_ppmm (m1, m0, q0, d0);
1056
1057               if (m1 > n1 || (m1 == n1 && m0 > n0))
1058                 {
1059                   q0--;
1060                   sub_ddmmss (m1, m0, m1, m0, d1, d0);
1061                 }
1062
1063               q1 = 0;
1064
1065               /* Remainder in (n1n0 - m1m0) >> bm.  */
1066               if (rp != 0)
1067                 {
1068                   sub_ddmmss (n1, n0, n1, n0, m1, m0);
1069                   rr.s.low = (n1 << b) | (n0 >> bm);
1070                   rr.s.high = n1 >> bm;
1071                   *rp = rr.ll;
1072                 }
1073             }
1074         }
1075     }
1076
1077   const DWunion ww = {{.low = q0, .high = q1}};
1078   return ww.ll;
1079 }
1080 #endif
1081
1082 #ifdef L_divdi3
1083 DWtype
1084 __divdi3 (DWtype u, DWtype v)
1085 {
1086   Wtype c = 0;
1087   DWunion uu = {.ll = u};
1088   DWunion vv = {.ll = v};
1089   DWtype w;
1090
1091   if (uu.s.high < 0)
1092     c = ~c,
1093     uu.ll = -uu.ll;
1094   if (vv.s.high < 0)
1095     c = ~c,
1096     vv.ll = -vv.ll;
1097
1098   w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1099   if (c)
1100     w = -w;
1101
1102   return w;
1103 }
1104 #endif
1105
1106 #ifdef L_moddi3
1107 DWtype
1108 __moddi3 (DWtype u, DWtype v)
1109 {
1110   Wtype c = 0;
1111   DWunion uu = {.ll = u};
1112   DWunion vv = {.ll = v};
1113   DWtype w;
1114
1115   if (uu.s.high < 0)
1116     c = ~c,
1117     uu.ll = -uu.ll;
1118   if (vv.s.high < 0)
1119     vv.ll = -vv.ll;
1120
1121   (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1122   if (c)
1123     w = -w;
1124
1125   return w;
1126 }
1127 #endif
1128
1129 #ifdef L_umoddi3
1130 UDWtype
1131 __umoddi3 (UDWtype u, UDWtype v)
1132 {
1133   UDWtype w;
1134
1135   (void) __udivmoddi4 (u, v, &w);
1136
1137   return w;
1138 }
1139 #endif
1140
1141 #ifdef L_udivdi3
1142 UDWtype
1143 __udivdi3 (UDWtype n, UDWtype d)
1144 {
1145   return __udivmoddi4 (n, d, (UDWtype *) 0);
1146 }
1147 #endif
1148 \f
1149 #ifdef L_cmpdi2
1150 cmp_return_type
1151 __cmpdi2 (DWtype a, DWtype b)
1152 {
1153   const DWunion au = {.ll = a};
1154   const DWunion bu = {.ll = b};
1155
1156   if (au.s.high < bu.s.high)
1157     return 0;
1158   else if (au.s.high > bu.s.high)
1159     return 2;
1160   if ((UWtype) au.s.low < (UWtype) bu.s.low)
1161     return 0;
1162   else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1163     return 2;
1164   return 1;
1165 }
1166 #endif
1167
1168 #ifdef L_ucmpdi2
1169 cmp_return_type
1170 __ucmpdi2 (DWtype a, DWtype b)
1171 {
1172   const DWunion au = {.ll = a};
1173   const DWunion bu = {.ll = b};
1174
1175   if ((UWtype) au.s.high < (UWtype) bu.s.high)
1176     return 0;
1177   else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1178     return 2;
1179   if ((UWtype) au.s.low < (UWtype) bu.s.low)
1180     return 0;
1181   else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1182     return 2;
1183   return 1;
1184 }
1185 #endif
1186 \f
1187 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1188 UDWtype
1189 __fixunstfDI (TFtype a)
1190 {
1191   if (a < 0)
1192     return 0;
1193
1194   /* Compute high word of result, as a flonum.  */
1195   const TFtype b = (a / Wtype_MAXp1_F);
1196   /* Convert that to fixed (but not to DWtype!),
1197      and shift it into the high word.  */
1198   UDWtype v = (UWtype) b;
1199   v <<= W_TYPE_SIZE;
1200   /* Remove high part from the TFtype, leaving the low part as flonum.  */
1201   a -= (TFtype)v;
1202   /* Convert that to fixed (but not to DWtype!) and add it in.
1203      Sometimes A comes out negative.  This is significant, since
1204      A has more bits than a long int does.  */
1205   if (a < 0)
1206     v -= (UWtype) (- a);
1207   else
1208     v += (UWtype) a;
1209   return v;
1210 }
1211 #endif
1212
1213 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1214 DWtype
1215 __fixtfdi (TFtype a)
1216 {
1217   if (a < 0)
1218     return - __fixunstfDI (-a);
1219   return __fixunstfDI (a);
1220 }
1221 #endif
1222
1223 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1224 UDWtype
1225 __fixunsxfDI (XFtype a)
1226 {
1227   if (a < 0)
1228     return 0;
1229
1230   /* Compute high word of result, as a flonum.  */
1231   const XFtype b = (a / Wtype_MAXp1_F);
1232   /* Convert that to fixed (but not to DWtype!),
1233      and shift it into the high word.  */
1234   UDWtype v = (UWtype) b;
1235   v <<= W_TYPE_SIZE;
1236   /* Remove high part from the XFtype, leaving the low part as flonum.  */
1237   a -= (XFtype)v;
1238   /* Convert that to fixed (but not to DWtype!) and add it in.
1239      Sometimes A comes out negative.  This is significant, since
1240      A has more bits than a long int does.  */
1241   if (a < 0)
1242     v -= (UWtype) (- a);
1243   else
1244     v += (UWtype) a;
1245   return v;
1246 }
1247 #endif
1248
1249 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1250 DWtype
1251 __fixxfdi (XFtype a)
1252 {
1253   if (a < 0)
1254     return - __fixunsxfDI (-a);
1255   return __fixunsxfDI (a);
1256 }
1257 #endif
1258
1259 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1260 UDWtype
1261 __fixunsdfDI (DFtype a)
1262 {
1263   /* Get high part of result.  The division here will just moves the radix
1264      point and will not cause any rounding.  Then the conversion to integral
1265      type chops result as desired.  */
1266   const UWtype hi = a / Wtype_MAXp1_F;
1267
1268   /* Get low part of result.  Convert `hi' to floating type and scale it back,
1269      then subtract this from the number being converted.  This leaves the low
1270      part.  Convert that to integral type.  */
1271   const UWtype lo = a - (DFtype) hi * Wtype_MAXp1_F;
1272
1273   /* Assemble result from the two parts.  */
1274   return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1275 }
1276 #endif
1277
1278 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1279 DWtype
1280 __fixdfdi (DFtype a)
1281 {
1282   if (a < 0)
1283     return - __fixunsdfDI (-a);
1284   return __fixunsdfDI (a);
1285 }
1286 #endif
1287
1288 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1289 UDWtype
1290 __fixunssfDI (SFtype a)
1291 {
1292 #if LIBGCC2_HAS_DF_MODE
1293   /* Convert the SFtype to a DFtype, because that is surely not going
1294      to lose any bits.  Some day someone else can write a faster version
1295      that avoids converting to DFtype, and verify it really works right.  */
1296   const DFtype dfa = a;
1297
1298   /* Get high part of result.  The division here will just moves the radix
1299      point and will not cause any rounding.  Then the conversion to integral
1300      type chops result as desired.  */
1301   const UWtype hi = dfa / Wtype_MAXp1_F;
1302
1303   /* Get low part of result.  Convert `hi' to floating type and scale it back,
1304      then subtract this from the number being converted.  This leaves the low
1305      part.  Convert that to integral type.  */
1306   const UWtype lo = dfa - (DFtype) hi * Wtype_MAXp1_F;
1307
1308   /* Assemble result from the two parts.  */
1309   return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1310 #elif FLT_MANT_DIG < W_TYPE_SIZE
1311   if (a < 1)
1312     return 0;
1313   if (a < Wtype_MAXp1_F)
1314     return (UWtype)a;
1315   if (a < Wtype_MAXp1_F * Wtype_MAXp1_F)
1316     {
1317       /* Since we know that there are fewer significant bits in the SFmode
1318          quantity than in a word, we know that we can convert out all the
1319          significant bits in one step, and thus avoid losing bits.  */
1320
1321       /* ??? This following loop essentially performs frexpf.  If we could
1322          use the real libm function, or poke at the actual bits of the fp
1323          format, it would be significantly faster.  */
1324
1325       UWtype shift = 0, counter;
1326       SFtype msb;
1327
1328       a /= Wtype_MAXp1_F;
1329       for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1)
1330         {
1331           SFtype counterf = (UWtype)1 << counter;
1332           if (a >= counterf)
1333             {
1334               shift |= counter;
1335               a /= counterf;
1336             }
1337         }
1338
1339       /* Rescale into the range of one word, extract the bits of that
1340          one word, and shift the result into position.  */
1341       a *= Wtype_MAXp1_F;
1342       counter = a;
1343       return (DWtype)counter << shift;
1344     }
1345   return -1;
1346 #else
1347 # error
1348 #endif
1349 }
1350 #endif
1351
1352 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1353 DWtype
1354 __fixsfdi (SFtype a)
1355 {
1356   if (a < 0)
1357     return - __fixunssfDI (-a);
1358   return __fixunssfDI (a);
1359 }
1360 #endif
1361
1362 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1363 XFtype
1364 __floatdixf (DWtype u)
1365 {
1366 #if W_TYPE_SIZE > XF_SIZE
1367 # error
1368 #endif
1369   XFtype d = (Wtype) (u >> W_TYPE_SIZE);
1370   d *= Wtype_MAXp1_F;
1371   d += (UWtype)u;
1372   return d;
1373 }
1374 #endif
1375
1376 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1377 XFtype
1378 __floatundixf (UDWtype u)
1379 {
1380 #if W_TYPE_SIZE > XF_SIZE
1381 # error
1382 #endif
1383   XFtype d = (UWtype) (u >> W_TYPE_SIZE);
1384   d *= Wtype_MAXp1_F;
1385   d += (UWtype)u;
1386   return d;
1387 }
1388 #endif
1389
1390 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1391 TFtype
1392 __floatditf (DWtype u)
1393 {
1394 #if W_TYPE_SIZE > TF_SIZE
1395 # error
1396 #endif
1397   TFtype d = (Wtype) (u >> W_TYPE_SIZE);
1398   d *= Wtype_MAXp1_F;
1399   d += (UWtype)u;
1400   return d;
1401 }
1402 #endif
1403
1404 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1405 TFtype
1406 __floatunditf (UDWtype u)
1407 {
1408 #if W_TYPE_SIZE > TF_SIZE
1409 # error
1410 #endif
1411   TFtype d = (UWtype) (u >> W_TYPE_SIZE);
1412   d *= Wtype_MAXp1_F;
1413   d += (UWtype)u;
1414   return d;
1415 }
1416 #endif
1417
1418 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE)       \
1419      || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1420 #define DI_SIZE (W_TYPE_SIZE * 2)
1421 #define F_MODE_OK(SIZE) \
1422   (SIZE < DI_SIZE                                                       \
1423    && SIZE > (DI_SIZE - SIZE + FSSIZE)                                  \
1424    && !AVOID_FP_TYPE_CONVERSION(SIZE))
1425 #if defined(L_floatdisf)
1426 #define FUNC __floatdisf
1427 #define FSTYPE SFtype
1428 #define FSSIZE SF_SIZE
1429 #else
1430 #define FUNC __floatdidf
1431 #define FSTYPE DFtype
1432 #define FSSIZE DF_SIZE
1433 #endif
1434
1435 FSTYPE
1436 FUNC (DWtype u)
1437 {
1438 #if FSSIZE >= W_TYPE_SIZE
1439   /* When the word size is small, we never get any rounding error.  */
1440   FSTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1441   f *= Wtype_MAXp1_F;
1442   f += (UWtype)u;
1443   return f;
1444 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))      \
1445      || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))    \
1446      || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1447
1448 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1449 # define FSIZE DF_SIZE
1450 # define FTYPE DFtype
1451 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1452 # define FSIZE XF_SIZE
1453 # define FTYPE XFtype
1454 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1455 # define FSIZE TF_SIZE
1456 # define FTYPE TFtype
1457 #else
1458 # error
1459 #endif
1460
1461 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1462
1463   /* Protect against double-rounding error.
1464      Represent any low-order bits, that might be truncated by a bit that
1465      won't be lost.  The bit can go in anywhere below the rounding position
1466      of the FSTYPE.  A fixed mask and bit position handles all usual
1467      configurations.  */
1468   if (! (- ((DWtype) 1 << FSIZE) < u
1469          && u < ((DWtype) 1 << FSIZE)))
1470     {
1471       if ((UDWtype) u & (REP_BIT - 1))
1472         {
1473           u &= ~ (REP_BIT - 1);
1474           u |= REP_BIT;
1475         }
1476     }
1477
1478   /* Do the calculation in a wider type so that we don't lose any of
1479      the precision of the high word while multiplying it.  */
1480   FTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1481   f *= Wtype_MAXp1_F;
1482   f += (UWtype)u;
1483   return (FSTYPE) f;
1484 #else
1485 #if FSSIZE >= W_TYPE_SIZE - 2
1486 # error
1487 #endif
1488   /* Finally, the word size is larger than the number of bits in the
1489      required FSTYPE, and we've got no suitable wider type.  The only
1490      way to avoid double rounding is to special case the
1491      extraction.  */
1492
1493   /* If there are no high bits set, fall back to one conversion.  */
1494   if ((Wtype)u == u)
1495     return (FSTYPE)(Wtype)u;
1496
1497   /* Otherwise, find the power of two.  */
1498   Wtype hi = u >> W_TYPE_SIZE;
1499   if (hi < 0)
1500     hi = -hi;
1501
1502   UWtype count, shift;
1503   count_leading_zeros (count, hi);
1504
1505   /* No leading bits means u == minimum.  */
1506   if (count == 0)
1507     return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2));
1508
1509   shift = 1 + W_TYPE_SIZE - count;
1510
1511   /* Shift down the most significant bits.  */
1512   hi = u >> shift;
1513
1514   /* If we lost any nonzero bits, set the lsb to ensure correct rounding.  */
1515   if ((UWtype)u << (W_TYPE_SIZE - shift))
1516     hi |= 1;
1517
1518   /* Convert the one word of data, and rescale.  */
1519   FSTYPE f = hi, e;
1520   if (shift == W_TYPE_SIZE)
1521     e = Wtype_MAXp1_F;
1522   /* The following two cases could be merged if we knew that the target
1523      supported a native unsigned->float conversion.  More often, we only
1524      have a signed conversion, and have to add extra fixup code.  */
1525   else if (shift == W_TYPE_SIZE - 1)
1526     e = Wtype_MAXp1_F / 2;
1527   else
1528     e = (Wtype)1 << shift;
1529   return f * e;
1530 #endif
1531 }
1532 #endif
1533
1534 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE)     \
1535      || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1536 #define DI_SIZE (W_TYPE_SIZE * 2)
1537 #define F_MODE_OK(SIZE) \
1538   (SIZE < DI_SIZE                                                       \
1539    && SIZE > (DI_SIZE - SIZE + FSSIZE)                                  \
1540    && !AVOID_FP_TYPE_CONVERSION(SIZE))
1541 #if defined(L_floatundisf)
1542 #define FUNC __floatundisf
1543 #define FSTYPE SFtype
1544 #define FSSIZE SF_SIZE
1545 #else
1546 #define FUNC __floatundidf
1547 #define FSTYPE DFtype
1548 #define FSSIZE DF_SIZE
1549 #endif
1550
1551 FSTYPE
1552 FUNC (UDWtype u)
1553 {
1554 #if FSSIZE >= W_TYPE_SIZE
1555   /* When the word size is small, we never get any rounding error.  */
1556   FSTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1557   f *= Wtype_MAXp1_F;
1558   f += (UWtype)u;
1559   return f;
1560 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))      \
1561      || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))    \
1562      || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1563
1564 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1565 # define FSIZE DF_SIZE
1566 # define FTYPE DFtype
1567 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1568 # define FSIZE XF_SIZE
1569 # define FTYPE XFtype
1570 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1571 # define FSIZE TF_SIZE
1572 # define FTYPE TFtype
1573 #else
1574 # error
1575 #endif
1576
1577 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1578
1579   /* Protect against double-rounding error.
1580      Represent any low-order bits, that might be truncated by a bit that
1581      won't be lost.  The bit can go in anywhere below the rounding position
1582      of the FSTYPE.  A fixed mask and bit position handles all usual
1583      configurations.  */
1584   if (u >= ((UDWtype) 1 << FSIZE))
1585     {
1586       if ((UDWtype) u & (REP_BIT - 1))
1587         {
1588           u &= ~ (REP_BIT - 1);
1589           u |= REP_BIT;
1590         }
1591     }
1592
1593   /* Do the calculation in a wider type so that we don't lose any of
1594      the precision of the high word while multiplying it.  */
1595   FTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1596   f *= Wtype_MAXp1_F;
1597   f += (UWtype)u;
1598   return (FSTYPE) f;
1599 #else
1600 #if FSSIZE == W_TYPE_SIZE - 1
1601 # error
1602 #endif
1603   /* Finally, the word size is larger than the number of bits in the
1604      required FSTYPE, and we've got no suitable wider type.  The only
1605      way to avoid double rounding is to special case the
1606      extraction.  */
1607
1608   /* If there are no high bits set, fall back to one conversion.  */
1609   if ((UWtype)u == u)
1610     return (FSTYPE)(UWtype)u;
1611
1612   /* Otherwise, find the power of two.  */
1613   UWtype hi = u >> W_TYPE_SIZE;
1614
1615   UWtype count, shift;
1616   count_leading_zeros (count, hi);
1617
1618   shift = W_TYPE_SIZE - count;
1619
1620   /* Shift down the most significant bits.  */
1621   hi = u >> shift;
1622
1623   /* If we lost any nonzero bits, set the lsb to ensure correct rounding.  */
1624   if ((UWtype)u << (W_TYPE_SIZE - shift))
1625     hi |= 1;
1626
1627   /* Convert the one word of data, and rescale.  */
1628   FSTYPE f = hi, e;
1629   if (shift == W_TYPE_SIZE)
1630     e = Wtype_MAXp1_F;
1631   /* The following two cases could be merged if we knew that the target
1632      supported a native unsigned->float conversion.  More often, we only
1633      have a signed conversion, and have to add extra fixup code.  */
1634   else if (shift == W_TYPE_SIZE - 1)
1635     e = Wtype_MAXp1_F / 2;
1636   else
1637     e = (Wtype)1 << shift;
1638   return f * e;
1639 #endif
1640 }
1641 #endif
1642
1643 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1644 /* Reenable the normal types, in case limits.h needs them.  */
1645 #undef char
1646 #undef short
1647 #undef int
1648 #undef long
1649 #undef unsigned
1650 #undef float
1651 #undef double
1652 #undef MIN
1653 #undef MAX
1654 #include <limits.h>
1655
1656 UWtype
1657 __fixunsxfSI (XFtype a)
1658 {
1659   if (a >= - (DFtype) Wtype_MIN)
1660     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1661   return (Wtype) a;
1662 }
1663 #endif
1664
1665 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1666 /* Reenable the normal types, in case limits.h needs them.  */
1667 #undef char
1668 #undef short
1669 #undef int
1670 #undef long
1671 #undef unsigned
1672 #undef float
1673 #undef double
1674 #undef MIN
1675 #undef MAX
1676 #include <limits.h>
1677
1678 UWtype
1679 __fixunsdfSI (DFtype a)
1680 {
1681   if (a >= - (DFtype) Wtype_MIN)
1682     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1683   return (Wtype) a;
1684 }
1685 #endif
1686
1687 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1688 /* Reenable the normal types, in case limits.h needs them.  */
1689 #undef char
1690 #undef short
1691 #undef int
1692 #undef long
1693 #undef unsigned
1694 #undef float
1695 #undef double
1696 #undef MIN
1697 #undef MAX
1698 #include <limits.h>
1699
1700 UWtype
1701 __fixunssfSI (SFtype a)
1702 {
1703   if (a >= - (SFtype) Wtype_MIN)
1704     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1705   return (Wtype) a;
1706 }
1707 #endif
1708 \f
1709 /* Integer power helper used from __builtin_powi for non-constant
1710    exponents.  */
1711
1712 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1713     || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1714     || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1715     || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1716 # if defined(L_powisf2)
1717 #  define TYPE SFtype
1718 #  define NAME __powisf2
1719 # elif defined(L_powidf2)
1720 #  define TYPE DFtype
1721 #  define NAME __powidf2
1722 # elif defined(L_powixf2)
1723 #  define TYPE XFtype
1724 #  define NAME __powixf2
1725 # elif defined(L_powitf2)
1726 #  define TYPE TFtype
1727 #  define NAME __powitf2
1728 # endif
1729
1730 #undef int
1731 #undef unsigned
1732 TYPE
1733 NAME (TYPE x, int m)
1734 {
1735   unsigned int n = m < 0 ? -m : m;
1736   TYPE y = n % 2 ? x : 1;
1737   while (n >>= 1)
1738     {
1739       x = x * x;
1740       if (n % 2)
1741         y = y * x;
1742     }
1743   return m < 0 ? 1/y : y;
1744 }
1745
1746 #endif
1747 \f
1748 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1749     || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1750     || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1751     || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1752
1753 #undef float
1754 #undef double
1755 #undef long
1756
1757 #if defined(L_mulsc3) || defined(L_divsc3)
1758 # define MTYPE  SFtype
1759 # define CTYPE  SCtype
1760 # define MODE   sc
1761 # define CEXT   f
1762 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1763 #elif defined(L_muldc3) || defined(L_divdc3)
1764 # define MTYPE  DFtype
1765 # define CTYPE  DCtype
1766 # define MODE   dc
1767 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1768 #  define CEXT  l
1769 #  define NOTRUNC 1
1770 # else
1771 #  define CEXT
1772 #  define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1773 # endif
1774 #elif defined(L_mulxc3) || defined(L_divxc3)
1775 # define MTYPE  XFtype
1776 # define CTYPE  XCtype
1777 # define MODE   xc
1778 # define CEXT   l
1779 # define NOTRUNC 1
1780 #elif defined(L_multc3) || defined(L_divtc3)
1781 # define MTYPE  TFtype
1782 # define CTYPE  TCtype
1783 # define MODE   tc
1784 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
1785 #  define CEXT l
1786 # else
1787 #  define CEXT LIBGCC2_TF_CEXT
1788 # endif
1789 # define NOTRUNC 1
1790 #else
1791 # error
1792 #endif
1793
1794 #define CONCAT3(A,B,C)  _CONCAT3(A,B,C)
1795 #define _CONCAT3(A,B,C) A##B##C
1796
1797 #define CONCAT2(A,B)    _CONCAT2(A,B)
1798 #define _CONCAT2(A,B)   A##B
1799
1800 /* All of these would be present in a full C99 implementation of <math.h>
1801    and <complex.h>.  Our problem is that only a few systems have such full
1802    implementations.  Further, libgcc_s.so isn't currently linked against
1803    libm.so, and even for systems that do provide full C99, the extra overhead
1804    of all programs using libgcc having to link against libm.  So avoid it.  */
1805
1806 #define isnan(x)        __builtin_expect ((x) != (x), 0)
1807 #define isfinite(x)     __builtin_expect (!isnan((x) - (x)), 1)
1808 #define isinf(x)        __builtin_expect (!isnan(x) & !isfinite(x), 0)
1809
1810 #define INFINITY        CONCAT2(__builtin_inf, CEXT) ()
1811 #define I               1i
1812
1813 /* Helpers to make the following code slightly less gross.  */
1814 #define COPYSIGN        CONCAT2(__builtin_copysign, CEXT)
1815 #define FABS            CONCAT2(__builtin_fabs, CEXT)
1816
1817 /* Verify that MTYPE matches up with CEXT.  */
1818 extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1];
1819
1820 /* Ensure that we've lost any extra precision.  */
1821 #if NOTRUNC
1822 # define TRUNC(x)
1823 #else
1824 # define TRUNC(x)       __asm__ ("" : "=m"(x) : "m"(x))
1825 #endif
1826
1827 #if defined(L_mulsc3) || defined(L_muldc3) \
1828     || defined(L_mulxc3) || defined(L_multc3)
1829
1830 CTYPE
1831 CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
1832 {
1833   MTYPE ac, bd, ad, bc, x, y;
1834   CTYPE res;
1835
1836   ac = a * c;
1837   bd = b * d;
1838   ad = a * d;
1839   bc = b * c;
1840
1841   TRUNC (ac);
1842   TRUNC (bd);
1843   TRUNC (ad);
1844   TRUNC (bc);
1845
1846   x = ac - bd;
1847   y = ad + bc;
1848
1849   if (isnan (x) && isnan (y))
1850     {
1851       /* Recover infinities that computed as NaN + iNaN.  */
1852       _Bool recalc = 0;
1853       if (isinf (a) || isinf (b))
1854         {
1855           /* z is infinite.  "Box" the infinity and change NaNs in
1856              the other factor to 0.  */
1857           a = COPYSIGN (isinf (a) ? 1 : 0, a);
1858           b = COPYSIGN (isinf (b) ? 1 : 0, b);
1859           if (isnan (c)) c = COPYSIGN (0, c);
1860           if (isnan (d)) d = COPYSIGN (0, d);
1861           recalc = 1;
1862         }
1863      if (isinf (c) || isinf (d))
1864         {
1865           /* w is infinite.  "Box" the infinity and change NaNs in
1866              the other factor to 0.  */
1867           c = COPYSIGN (isinf (c) ? 1 : 0, c);
1868           d = COPYSIGN (isinf (d) ? 1 : 0, d);
1869           if (isnan (a)) a = COPYSIGN (0, a);
1870           if (isnan (b)) b = COPYSIGN (0, b);
1871           recalc = 1;
1872         }
1873      if (!recalc
1874           && (isinf (ac) || isinf (bd)
1875               || isinf (ad) || isinf (bc)))
1876         {
1877           /* Recover infinities from overflow by changing NaNs to 0.  */
1878           if (isnan (a)) a = COPYSIGN (0, a);
1879           if (isnan (b)) b = COPYSIGN (0, b);
1880           if (isnan (c)) c = COPYSIGN (0, c);
1881           if (isnan (d)) d = COPYSIGN (0, d);
1882           recalc = 1;
1883         }
1884       if (recalc)
1885         {
1886           x = INFINITY * (a * c - b * d);
1887           y = INFINITY * (a * d + b * c);
1888         }
1889     }
1890
1891   __real__ res = x;
1892   __imag__ res = y;
1893   return res;
1894 }
1895 #endif /* complex multiply */
1896
1897 #if defined(L_divsc3) || defined(L_divdc3) \
1898     || defined(L_divxc3) || defined(L_divtc3)
1899
1900 CTYPE
1901 CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
1902 {
1903   MTYPE denom, ratio, x, y;
1904   CTYPE res;
1905
1906   /* ??? We can get better behavior from logarithmic scaling instead of
1907      the division.  But that would mean starting to link libgcc against
1908      libm.  We could implement something akin to ldexp/frexp as gcc builtins
1909      fairly easily...  */
1910   if (FABS (c) < FABS (d))
1911     {
1912       ratio = c / d;
1913       denom = (c * ratio) + d;
1914       x = ((a * ratio) + b) / denom;
1915       y = ((b * ratio) - a) / denom;
1916     }
1917   else
1918     {
1919       ratio = d / c;
1920       denom = (d * ratio) + c;
1921       x = ((b * ratio) + a) / denom;
1922       y = (b - (a * ratio)) / denom;
1923     }
1924
1925   /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1926      are nonzero/zero, infinite/finite, and finite/infinite.  */
1927   if (isnan (x) && isnan (y))
1928     {
1929       if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b)))
1930         {
1931           x = COPYSIGN (INFINITY, c) * a;
1932           y = COPYSIGN (INFINITY, c) * b;
1933         }
1934       else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d))
1935         {
1936           a = COPYSIGN (isinf (a) ? 1 : 0, a);
1937           b = COPYSIGN (isinf (b) ? 1 : 0, b);
1938           x = INFINITY * (a * c + b * d);
1939           y = INFINITY * (b * c - a * d);
1940         }
1941       else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b))
1942         {
1943           c = COPYSIGN (isinf (c) ? 1 : 0, c);
1944           d = COPYSIGN (isinf (d) ? 1 : 0, d);
1945           x = 0.0 * (a * c + b * d);
1946           y = 0.0 * (b * c - a * d);
1947         }
1948     }
1949
1950   __real__ res = x;
1951   __imag__ res = y;
1952   return res;
1953 }
1954 #endif /* complex divide */
1955
1956 #endif /* all complex float routines */
1957 \f
1958 /* From here on down, the routines use normal data types.  */
1959
1960 #define SItype bogus_type
1961 #define USItype bogus_type
1962 #define DItype bogus_type
1963 #define UDItype bogus_type
1964 #define SFtype bogus_type
1965 #define DFtype bogus_type
1966 #undef Wtype
1967 #undef UWtype
1968 #undef HWtype
1969 #undef UHWtype
1970 #undef DWtype
1971 #undef UDWtype
1972
1973 #undef char
1974 #undef short
1975 #undef int
1976 #undef long
1977 #undef unsigned
1978 #undef float
1979 #undef double
1980 \f
1981 #ifdef L__gcc_bcmp
1982
1983 /* Like bcmp except the sign is meaningful.
1984    Result is negative if S1 is less than S2,
1985    positive if S1 is greater, 0 if S1 and S2 are equal.  */
1986
1987 int
1988 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1989 {
1990   while (size > 0)
1991     {
1992       const unsigned char c1 = *s1++, c2 = *s2++;
1993       if (c1 != c2)
1994         return c1 - c2;
1995       size--;
1996     }
1997   return 0;
1998 }
1999
2000 #endif
2001 \f
2002 /* __eprintf used to be used by GCC's private version of <assert.h>.
2003    We no longer provide that header, but this routine remains in libgcc.a
2004    for binary backward compatibility.  Note that it is not included in
2005    the shared version of libgcc.  */
2006 #ifdef L_eprintf
2007 #ifndef inhibit_libc
2008
2009 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
2010 #include <stdio.h>
2011
2012 void
2013 __eprintf (const char *string, const char *expression,
2014            unsigned int line, const char *filename)
2015 {
2016   fprintf (stderr, string, expression, line, filename);
2017   fflush (stderr);
2018   abort ();
2019 }
2020
2021 #endif
2022 #endif
2023
2024 \f
2025 #ifdef L_clear_cache
2026 /* Clear part of an instruction cache.  */
2027
2028 void
2029 __clear_cache (char *beg __attribute__((__unused__)),
2030                char *end __attribute__((__unused__)))
2031 {
2032 #ifdef CLEAR_INSN_CACHE
2033   CLEAR_INSN_CACHE (beg, end);
2034 #endif /* CLEAR_INSN_CACHE */
2035 }
2036
2037 #endif /* L_clear_cache */
2038 \f
2039 #ifdef L_enable_execute_stack
2040 /* Attempt to turn on execute permission for the stack.  */
2041
2042 #ifdef ENABLE_EXECUTE_STACK
2043   ENABLE_EXECUTE_STACK
2044 #else
2045 void
2046 __enable_execute_stack (void *addr __attribute__((__unused__)))
2047 {}
2048 #endif /* ENABLE_EXECUTE_STACK */
2049
2050 #endif /* L_enable_execute_stack */
2051 \f
2052 #ifdef L_trampoline
2053
2054 /* Jump to a trampoline, loading the static chain address.  */
2055
2056 #if defined(WINNT) && ! defined(__CYGWIN__)
2057
2058 int
2059 getpagesize (void)
2060 {
2061 #ifdef _ALPHA_
2062   return 8192;
2063 #else
2064   return 4096;
2065 #endif
2066 }
2067
2068 int
2069 mprotect (char *addr, int len, int prot)
2070 {
2071   int np, op;
2072
2073   if (prot == 7)
2074     np = 0x40;
2075   else if (prot == 5)
2076     np = 0x20;
2077   else if (prot == 4)
2078     np = 0x10;
2079   else if (prot == 3)
2080     np = 0x04;
2081   else if (prot == 1)
2082     np = 0x02;
2083   else if (prot == 0)
2084     np = 0x01;
2085
2086   if (VirtualProtect (addr, len, np, &op))
2087     return 0;
2088   else
2089     return -1;
2090 }
2091
2092 #endif /* WINNT && ! __CYGWIN__ */
2093
2094 #ifdef TRANSFER_FROM_TRAMPOLINE
2095 TRANSFER_FROM_TRAMPOLINE
2096 #endif
2097 #endif /* L_trampoline */
2098 \f
2099 #ifndef __CYGWIN__
2100 #ifdef L__main
2101
2102 #include "gbl-ctors.h"
2103
2104 /* Some systems use __main in a way incompatible with its use in gcc, in these
2105    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2106    give the same symbol without quotes for an alternative entry point.  You
2107    must define both, or neither.  */
2108 #ifndef NAME__MAIN
2109 #define NAME__MAIN "__main"
2110 #define SYMBOL__MAIN __main
2111 #endif
2112
2113 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2114 #undef HAS_INIT_SECTION
2115 #define HAS_INIT_SECTION
2116 #endif
2117
2118 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2119
2120 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2121    code to run constructors.  In that case, we need to handle EH here, too.  */
2122
2123 #ifdef EH_FRAME_SECTION_NAME
2124 #include "unwind-dw2-fde.h"
2125 extern unsigned char __EH_FRAME_BEGIN__[];
2126 #endif
2127
2128 /* Run all the global destructors on exit from the program.  */
2129
2130 void
2131 __do_global_dtors (void)
2132 {
2133 #ifdef DO_GLOBAL_DTORS_BODY
2134   DO_GLOBAL_DTORS_BODY;
2135 #else
2136   static func_ptr *p = __DTOR_LIST__ + 1;
2137   while (*p)
2138     {
2139       p++;
2140       (*(p-1)) ();
2141     }
2142 #endif
2143 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2144   {
2145     static int completed = 0;
2146     if (! completed)
2147       {
2148         completed = 1;
2149         __deregister_frame_info (__EH_FRAME_BEGIN__);
2150       }
2151   }
2152 #endif
2153 }
2154 #endif
2155
2156 #ifndef HAS_INIT_SECTION
2157 /* Run all the global constructors on entry to the program.  */
2158
2159 void
2160 __do_global_ctors (void)
2161 {
2162 #ifdef EH_FRAME_SECTION_NAME
2163   {
2164     static struct object object;
2165     __register_frame_info (__EH_FRAME_BEGIN__, &object);
2166   }
2167 #endif
2168   DO_GLOBAL_CTORS_BODY;
2169   atexit (__do_global_dtors);
2170 }
2171 #endif /* no HAS_INIT_SECTION */
2172
2173 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2174 /* Subroutine called automatically by `main'.
2175    Compiling a global function named `main'
2176    produces an automatic call to this function at the beginning.
2177
2178    For many systems, this routine calls __do_global_ctors.
2179    For systems which support a .init section we use the .init section
2180    to run __do_global_ctors, so we need not do anything here.  */
2181
2182 extern void SYMBOL__MAIN (void);
2183 void
2184 SYMBOL__MAIN (void)
2185 {
2186   /* Support recursive calls to `main': run initializers just once.  */
2187   static int initialized;
2188   if (! initialized)
2189     {
2190       initialized = 1;
2191       __do_global_ctors ();
2192     }
2193 }
2194 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2195
2196 #endif /* L__main */
2197 #endif /* __CYGWIN__ */
2198 \f
2199 #ifdef L_ctors
2200
2201 #include "gbl-ctors.h"
2202
2203 /* Provide default definitions for the lists of constructors and
2204    destructors, so that we don't get linker errors.  These symbols are
2205    intentionally bss symbols, so that gld and/or collect will provide
2206    the right values.  */
2207
2208 /* We declare the lists here with two elements each,
2209    so that they are valid empty lists if no other definition is loaded.
2210
2211    If we are using the old "set" extensions to have the gnu linker
2212    collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2213    must be in the bss/common section.
2214
2215    Long term no port should use those extensions.  But many still do.  */
2216 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2217 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2218 func_ptr __CTOR_LIST__[2] = {0, 0};
2219 func_ptr __DTOR_LIST__[2] = {0, 0};
2220 #else
2221 func_ptr __CTOR_LIST__[2];
2222 func_ptr __DTOR_LIST__[2];
2223 #endif
2224 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2225 #endif /* L_ctors */
2226 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */