OSDN Git Service

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