OSDN Git Service

* java/util/zip/ZipEntry.java (setCompressedSize): Allow any
[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  Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file.  (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
20 executable.)
21
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING.  If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 02111-1307, USA.  */
31
32
33 /* We include auto-host.h here to get HAVE_GAS_HIDDEN.  This is
34    supposedly valid even though this is a "target" file.  */
35 #include "auto-host.h"
36
37 /* It is incorrect to include config.h here, because this file is being
38    compiled for the target, and hence definitions concerning only the host
39    do not apply.  */
40 #include "tconfig.h"
41 #include "tsystem.h"
42 #include "coretypes.h"
43 #include "tm.h"
44
45 /* Don't use `fancy_abort' here even if config.h says to use it.  */
46 #ifdef abort
47 #undef abort
48 #endif
49
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN  __attribute__ ((__visibility__ ("hidden")))
52 #else
53 #define ATTRIBUTE_HIDDEN
54 #endif
55
56 #include "libgcc2.h"
57 \f
58 #ifdef DECLARE_LIBRARY_RENAMES
59   DECLARE_LIBRARY_RENAMES
60 #endif
61
62 #if defined (L_negdi2)
63 DWtype
64 __negdi2 (DWtype u)
65 {
66   const DWunion uu = {.ll = u};
67   const DWunion w = { {.low = -uu.s.low,
68                        .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
69
70   return w.ll;
71 }
72 #endif
73
74 #ifdef L_addvsi3
75 Wtype
76 __addvSI3 (Wtype a, Wtype b)
77 {
78   const Wtype w = a + b;
79
80   if (b >= 0 ? w < a : w > a)
81     abort ();
82
83   return w;
84 }
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
86 SItype
87 __addvsi3 (SItype a, SItype b)
88 {
89   const SItype w = a + b;
90
91   if (b >= 0 ? w < a : w > a)
92     abort ();
93
94   return w;
95 }
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
97 #endif
98 \f
99 #ifdef L_addvdi3
100 DWtype
101 __addvDI3 (DWtype a, DWtype b)
102 {
103   const DWtype w = a + b;
104
105   if (b >= 0 ? w < a : w > a)
106     abort ();
107
108   return w;
109 }
110 #endif
111 \f
112 #ifdef L_subvsi3
113 Wtype
114 __subvSI3 (Wtype a, Wtype b)
115 {
116   const Wtype w = a - b;
117
118   if (b >= 0 ? w > a : w < a)
119     abort ();
120
121   return w;
122 }
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
124 SItype
125 __subvsi3 (SItype a, SItype b)
126 {
127   const SItype w = a - b;
128
129   if (b >= 0 ? w > a : w < a)
130     abort ();
131
132   return w;
133 }
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
135 #endif
136 \f
137 #ifdef L_subvdi3
138 DWtype
139 __subvDI3 (DWtype a, DWtype b)
140 {
141   const DWtype w = a - b;
142
143   if (b >= 0 ? w > a : w < a)
144     abort ();
145
146   return w;
147 }
148 #endif
149 \f
150 #ifdef L_mulvsi3
151 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
152 Wtype
153 __mulvSI3 (Wtype a, Wtype b)
154 {
155   const DWtype w = (DWtype) a * (DWtype) b;
156
157   if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_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 = -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 = -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 = -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 = -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 = -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 = -a;
266
267   if (w < 0)
268     abort ();
269 #endif
270
271   return w;
272 }
273 #endif
274 \f
275 #ifdef L_mulvdi3
276 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
277 DWtype
278 __mulvDI3 (DWtype u, DWtype v)
279 {
280   /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281      but the checked multiplication needs only two.  */
282   const DWunion uu = {.ll = u};
283   const DWunion vv = {.ll = v};
284
285   if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
286     {
287       /* u fits in a single Wtype.  */
288       if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
289         {
290           /* v fits in a single Wtype as well.  */
291           /* A single multiplication.  No overflow risk.  */
292           return (DWtype) uu.s.low * (DWtype) vv.s.low;
293         }
294       else
295         {
296           /* Two multiplications.  */
297           DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
298                         * (UDWtype) (UWtype) vv.s.low};
299           DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
300                         * (UDWtype) (UWtype) vv.s.high};
301
302           if (vv.s.high < 0)
303             w1.s.high -= uu.s.low;
304           if (uu.s.low < 0)
305             w1.ll -= vv.ll;
306           w1.ll += (UWtype) w0.s.high;
307           if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
308             {
309               w0.s.high = w1.s.low;
310               return w0.ll;
311             }
312         }
313     }
314   else
315     {
316       if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
317         {
318           /* v fits into a single Wtype.  */
319           /* Two multiplications.  */
320           DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
321                         * (UDWtype) (UWtype) vv.s.low};
322           DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
323                         * (UDWtype) (UWtype) vv.s.low};
324
325           if (uu.s.high < 0)
326             w1.s.high -= vv.s.low;
327           if (vv.s.low < 0)
328             w1.ll -= uu.ll;
329           w1.ll += (UWtype) w0.s.high;
330           if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
331             {
332               w0.s.high = w1.s.low;
333               return w0.ll;
334             }
335         }
336       else
337         {
338           /* A few sign checks and a single multiplication.  */
339           if (uu.s.high >= 0)
340             {
341               if (vv.s.high >= 0)
342                 {
343                   if (uu.s.high == 0 && vv.s.high == 0)
344                     {
345                       const DWtype w = (UDWtype) (UWtype) uu.s.low
346                         * (UDWtype) (UWtype) vv.s.low;
347                       if (__builtin_expect (w >= 0, 1))
348                         return w;
349                     }
350                 }
351               else
352                 {
353                   if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
354                     {
355                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
356                                     * (UDWtype) (UWtype) vv.s.low};
357
358                       ww.s.high -= uu.s.low;
359                       if (__builtin_expect (ww.s.high < 0, 1))
360                         return ww.ll;
361                     }
362                 }
363             }
364           else
365             {
366               if (vv.s.high >= 0)
367                 {
368                   if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
369                     {
370                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
371                                     * (UDWtype) (UWtype) vv.s.low};
372
373                       ww.s.high -= vv.s.low;
374                       if (__builtin_expect (ww.s.high < 0, 1))
375                         return ww.ll;
376                     }
377                 }
378               else
379                 {
380                   if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
381                     {
382                       DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
383                                     * (UDWtype) (UWtype) vv.s.low};
384
385                       ww.s.high -= uu.s.low;
386                       ww.s.high -= vv.s.low;
387                       if (__builtin_expect (ww.s.high >= 0, 1))
388                         return ww.ll;
389                     }
390                 }
391             }
392         }
393     }
394
395   /* Overflow.  */
396   abort ();
397 }
398 #endif
399 \f
400
401 /* Unless shift functions are defined with full ANSI prototypes,
402    parameter b will be promoted to int if word_type is smaller than an int.  */
403 #ifdef L_lshrdi3
404 DWtype
405 __lshrdi3 (DWtype u, word_type b)
406 {
407   if (b == 0)
408     return u;
409
410   const DWunion uu = {.ll = u};
411   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
412   DWunion w;
413
414   if (bm <= 0)
415     {
416       w.s.high = 0;
417       w.s.low = (UWtype) uu.s.high >> -bm;
418     }
419   else
420     {
421       const UWtype carries = (UWtype) uu.s.high << bm;
422
423       w.s.high = (UWtype) uu.s.high >> b;
424       w.s.low = ((UWtype) uu.s.low >> b) | carries;
425     }
426
427   return w.ll;
428 }
429 #endif
430
431 #ifdef L_ashldi3
432 DWtype
433 __ashldi3 (DWtype u, word_type b)
434 {
435   if (b == 0)
436     return u;
437
438   const DWunion uu = {.ll = u};
439   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
440   DWunion w;
441
442   if (bm <= 0)
443     {
444       w.s.low = 0;
445       w.s.high = (UWtype) uu.s.low << -bm;
446     }
447   else
448     {
449       const UWtype carries = (UWtype) uu.s.low >> bm;
450
451       w.s.low = (UWtype) uu.s.low << b;
452       w.s.high = ((UWtype) uu.s.high << b) | carries;
453     }
454
455   return w.ll;
456 }
457 #endif
458
459 #ifdef L_ashrdi3
460 DWtype
461 __ashrdi3 (DWtype u, word_type b)
462 {
463   if (b == 0)
464     return u;
465
466   const DWunion uu = {.ll = u};
467   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
468   DWunion w;
469
470   if (bm <= 0)
471     {
472       /* w.s.high = 1..1 or 0..0 */
473       w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
474       w.s.low = uu.s.high >> -bm;
475     }
476   else
477     {
478       const UWtype carries = (UWtype) uu.s.high << bm;
479
480       w.s.high = uu.s.high >> b;
481       w.s.low = ((UWtype) uu.s.low >> b) | carries;
482     }
483
484   return w.ll;
485 }
486 #endif
487 \f
488 #ifdef L_ffssi2
489 #undef int
490 int
491 __ffsSI2 (UWtype u)
492 {
493   UWtype count;
494
495   if (u == 0)
496     return 0;
497
498   count_trailing_zeros (count, u);
499   return count + 1;
500 }
501 #endif
502 \f
503 #ifdef L_ffsdi2
504 #undef int
505 int
506 __ffsDI2 (DWtype u)
507 {
508   const DWunion uu = {.ll = u};
509   UWtype word, count, add;
510
511   if (uu.s.low != 0)
512     word = uu.s.low, add = 0;
513   else if (uu.s.high != 0)
514     word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
515   else
516     return 0;
517
518   count_trailing_zeros (count, word);
519   return count + add + 1;
520 }
521 #endif
522 \f
523 #ifdef L_muldi3
524 DWtype
525 __muldi3 (DWtype u, DWtype v)
526 {
527   const DWunion uu = {.ll = u};
528   const DWunion vv = {.ll = v};
529   DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
530
531   w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
532                + (UWtype) uu.s.high * (UWtype) vv.s.low);
533
534   return w.ll;
535 }
536 #endif
537 \f
538 #if (defined (L_udivdi3) || defined (L_divdi3) || \
539      defined (L_umoddi3) || defined (L_moddi3))
540 #if defined (sdiv_qrnnd)
541 #define L_udiv_w_sdiv
542 #endif
543 #endif
544
545 #ifdef L_udiv_w_sdiv
546 #if defined (sdiv_qrnnd)
547 #if (defined (L_udivdi3) || defined (L_divdi3) || \
548      defined (L_umoddi3) || defined (L_moddi3))
549 static inline __attribute__ ((__always_inline__))
550 #endif
551 UWtype
552 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
553 {
554   UWtype q, r;
555   UWtype c0, c1, b1;
556
557   if ((Wtype) d >= 0)
558     {
559       if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
560         {
561           /* Dividend, divisor, and quotient are nonnegative.  */
562           sdiv_qrnnd (q, r, a1, a0, d);
563         }
564       else
565         {
566           /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d.  */
567           sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
568           /* Divide (c1*2^32 + c0) by d.  */
569           sdiv_qrnnd (q, r, c1, c0, d);
570           /* Add 2^31 to quotient.  */
571           q += (UWtype) 1 << (W_TYPE_SIZE - 1);
572         }
573     }
574   else
575     {
576       b1 = d >> 1;                      /* d/2, between 2^30 and 2^31 - 1 */
577       c1 = a1 >> 1;                     /* A/2 */
578       c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
579
580       if (a1 < b1)                      /* A < 2^32*b1, so A/2 < 2^31*b1 */
581         {
582           sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
583
584           r = 2*r + (a0 & 1);           /* Remainder from A/(2*b1) */
585           if ((d & 1) != 0)
586             {
587               if (r >= q)
588                 r = r - q;
589               else if (q - r <= d)
590                 {
591                   r = r - q + d;
592                   q--;
593                 }
594               else
595                 {
596                   r = r - q + 2*d;
597                   q -= 2;
598                 }
599             }
600         }
601       else if (c1 < b1)                 /* So 2^31 <= (A/2)/b1 < 2^32 */
602         {
603           c1 = (b1 - 1) - c1;
604           c0 = ~c0;                     /* logical NOT */
605
606           sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
607
608           q = ~q;                       /* (A/2)/b1 */
609           r = (b1 - 1) - r;
610
611           r = 2*r + (a0 & 1);           /* A/(2*b1) */
612
613           if ((d & 1) != 0)
614             {
615               if (r >= q)
616                 r = r - q;
617               else if (q - r <= d)
618                 {
619                   r = r - q + d;
620                   q--;
621                 }
622               else
623                 {
624                   r = r - q + 2*d;
625                   q -= 2;
626                 }
627             }
628         }
629       else                              /* Implies c1 = b1 */
630         {                               /* Hence a1 = d - 1 = 2*b1 - 1 */
631           if (a0 >= -d)
632             {
633               q = -1;
634               r = a0 + d;
635             }
636           else
637             {
638               q = -2;
639               r = a0 + 2*d;
640             }
641         }
642     }
643
644   *rp = r;
645   return q;
646 }
647 #else
648 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv.  */
649 UWtype
650 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
651                UWtype a1 __attribute__ ((__unused__)),
652                UWtype a0 __attribute__ ((__unused__)),
653                UWtype d __attribute__ ((__unused__)))
654 {
655   return 0;
656 }
657 #endif
658 #endif
659 \f
660 #if (defined (L_udivdi3) || defined (L_divdi3) || \
661      defined (L_umoddi3) || defined (L_moddi3))
662 #define L_udivmoddi4
663 #endif
664
665 #ifdef L_clz
666 const UQItype __clz_tab[] =
667 {
668   0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
669   6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
670   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
671   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
672   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
673   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
674   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
675   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
676 };
677 #endif
678 \f
679 #ifdef L_clzsi2
680 #undef int
681 int
682 __clzSI2 (UWtype x)
683 {
684   Wtype ret;
685
686   count_leading_zeros (ret, x);
687
688   return ret;
689 }
690 #endif
691 \f
692 #ifdef L_clzdi2
693 #undef int
694 int
695 __clzDI2 (UDWtype x)
696 {
697   const DWunion uu = {.ll = x};
698   UWtype word;
699   Wtype ret, add;
700
701   if (uu.s.high)
702     word = uu.s.high, add = 0;
703   else
704     word = uu.s.low, add = W_TYPE_SIZE;
705
706   count_leading_zeros (ret, word);
707   return ret + add;
708 }
709 #endif
710 \f
711 #ifdef L_ctzsi2
712 #undef int
713 int
714 __ctzSI2 (UWtype x)
715 {
716   Wtype ret;
717
718   count_trailing_zeros (ret, x);
719
720   return ret;
721 }
722 #endif
723 \f
724 #ifdef L_ctzdi2
725 #undef int
726 int
727 __ctzDI2 (UDWtype x)
728 {
729   const DWunion uu = {.ll = x};
730   UWtype word;
731   Wtype ret, add;
732
733   if (uu.s.low)
734     word = uu.s.low, add = 0;
735   else
736     word = uu.s.high, add = W_TYPE_SIZE;
737
738   count_trailing_zeros (ret, word);
739   return ret + add;
740 }
741 #endif
742
743 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
744      || defined (L_popcount_tab))
745 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
746 #endif
747
748 #ifdef L_popcount_tab
749 const UQItype __popcount_tab[] =
750 {
751     0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
752     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
753     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
754     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
755     1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
756     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
757     2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
758     3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
759 };
760 #endif
761 \f
762 #ifdef L_popcountsi2
763 #undef int
764 int
765 __popcountSI2 (UWtype x)
766 {
767   UWtype i, ret = 0;
768
769   for (i = 0; i < W_TYPE_SIZE; i += 8)
770     ret += __popcount_tab[(x >> i) & 0xff];
771
772   return ret;
773 }
774 #endif
775 \f
776 #ifdef L_popcountdi2
777 #undef int
778 int
779 __popcountDI2 (UDWtype x)
780 {
781   UWtype i, ret = 0;
782
783   for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
784     ret += __popcount_tab[(x >> i) & 0xff];
785
786   return ret;
787 }
788 #endif
789 \f
790 #ifdef L_paritysi2
791 #undef int
792 int
793 __paritySI2 (UWtype x)
794 {
795 #if W_TYPE_SIZE > 64
796 # error "fill out the table"
797 #endif
798 #if W_TYPE_SIZE > 32
799   x ^= x >> 32;
800 #endif
801 #if W_TYPE_SIZE > 16
802   x ^= x >> 16;
803 #endif
804   x ^= x >> 8;
805   x ^= x >> 4;
806   x &= 0xf;
807   return (0x6996 >> x) & 1;
808 }
809 #endif
810 \f
811 #ifdef L_paritydi2
812 #undef int
813 int
814 __parityDI2 (UDWtype x)
815 {
816   const DWunion uu = {.ll = x};
817   UWtype nx = uu.s.low ^ uu.s.high;
818
819 #if W_TYPE_SIZE > 64
820 # error "fill out the table"
821 #endif
822 #if W_TYPE_SIZE > 32
823   nx ^= nx >> 32;
824 #endif
825 #if W_TYPE_SIZE > 16
826   nx ^= nx >> 16;
827 #endif
828   nx ^= nx >> 8;
829   nx ^= nx >> 4;
830   nx &= 0xf;
831   return (0x6996 >> nx) & 1;
832 }
833 #endif
834
835 #ifdef L_udivmoddi4
836
837 #if (defined (L_udivdi3) || defined (L_divdi3) || \
838      defined (L_umoddi3) || defined (L_moddi3))
839 static inline __attribute__ ((__always_inline__))
840 #endif
841 UDWtype
842 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
843 {
844   const DWunion nn = {.ll = n};
845   const DWunion dd = {.ll = d};
846   DWunion rr;
847   UWtype d0, d1, n0, n1, n2;
848   UWtype q0, q1;
849   UWtype b, bm;
850
851   d0 = dd.s.low;
852   d1 = dd.s.high;
853   n0 = nn.s.low;
854   n1 = nn.s.high;
855
856 #if !UDIV_NEEDS_NORMALIZATION
857   if (d1 == 0)
858     {
859       if (d0 > n1)
860         {
861           /* 0q = nn / 0D */
862
863           udiv_qrnnd (q0, n0, n1, n0, d0);
864           q1 = 0;
865
866           /* Remainder in n0.  */
867         }
868       else
869         {
870           /* qq = NN / 0d */
871
872           if (d0 == 0)
873             d0 = 1 / d0;        /* Divide intentionally by zero.  */
874
875           udiv_qrnnd (q1, n1, 0, n1, d0);
876           udiv_qrnnd (q0, n0, n1, n0, d0);
877
878           /* Remainder in n0.  */
879         }
880
881       if (rp != 0)
882         {
883           rr.s.low = n0;
884           rr.s.high = 0;
885           *rp = rr.ll;
886         }
887     }
888
889 #else /* UDIV_NEEDS_NORMALIZATION */
890
891   if (d1 == 0)
892     {
893       if (d0 > n1)
894         {
895           /* 0q = nn / 0D */
896
897           count_leading_zeros (bm, d0);
898
899           if (bm != 0)
900             {
901               /* Normalize, i.e. make the most significant bit of the
902                  denominator set.  */
903
904               d0 = d0 << bm;
905               n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
906               n0 = n0 << bm;
907             }
908
909           udiv_qrnnd (q0, n0, n1, n0, d0);
910           q1 = 0;
911
912           /* Remainder in n0 >> bm.  */
913         }
914       else
915         {
916           /* qq = NN / 0d */
917
918           if (d0 == 0)
919             d0 = 1 / d0;        /* Divide intentionally by zero.  */
920
921           count_leading_zeros (bm, d0);
922
923           if (bm == 0)
924             {
925               /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
926                  conclude (the most significant bit of n1 is set) /\ (the
927                  leading quotient digit q1 = 1).
928
929                  This special case is necessary, not an optimization.
930                  (Shifts counts of W_TYPE_SIZE are undefined.)  */
931
932               n1 -= d0;
933               q1 = 1;
934             }
935           else
936             {
937               /* Normalize.  */
938
939               b = W_TYPE_SIZE - bm;
940
941               d0 = d0 << bm;
942               n2 = n1 >> b;
943               n1 = (n1 << bm) | (n0 >> b);
944               n0 = n0 << bm;
945
946               udiv_qrnnd (q1, n1, n2, n1, d0);
947             }
948
949           /* n1 != d0...  */
950
951           udiv_qrnnd (q0, n0, n1, n0, d0);
952
953           /* Remainder in n0 >> bm.  */
954         }
955
956       if (rp != 0)
957         {
958           rr.s.low = n0 >> bm;
959           rr.s.high = 0;
960           *rp = rr.ll;
961         }
962     }
963 #endif /* UDIV_NEEDS_NORMALIZATION */
964
965   else
966     {
967       if (d1 > n1)
968         {
969           /* 00 = nn / DD */
970
971           q0 = 0;
972           q1 = 0;
973
974           /* Remainder in n1n0.  */
975           if (rp != 0)
976             {
977               rr.s.low = n0;
978               rr.s.high = n1;
979               *rp = rr.ll;
980             }
981         }
982       else
983         {
984           /* 0q = NN / dd */
985
986           count_leading_zeros (bm, d1);
987           if (bm == 0)
988             {
989               /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
990                  conclude (the most significant bit of n1 is set) /\ (the
991                  quotient digit q0 = 0 or 1).
992
993                  This special case is necessary, not an optimization.  */
994
995               /* The condition on the next line takes advantage of that
996                  n1 >= d1 (true due to program flow).  */
997               if (n1 > d1 || n0 >= d0)
998                 {
999                   q0 = 1;
1000                   sub_ddmmss (n1, n0, n1, n0, d1, d0);
1001                 }
1002               else
1003                 q0 = 0;
1004
1005               q1 = 0;
1006
1007               if (rp != 0)
1008                 {
1009                   rr.s.low = n0;
1010                   rr.s.high = n1;
1011                   *rp = rr.ll;
1012                 }
1013             }
1014           else
1015             {
1016               UWtype m1, m0;
1017               /* Normalize.  */
1018
1019               b = W_TYPE_SIZE - bm;
1020
1021               d1 = (d1 << bm) | (d0 >> b);
1022               d0 = d0 << bm;
1023               n2 = n1 >> b;
1024               n1 = (n1 << bm) | (n0 >> b);
1025               n0 = n0 << bm;
1026
1027               udiv_qrnnd (q0, n1, n2, n1, d1);
1028               umul_ppmm (m1, m0, q0, d0);
1029
1030               if (m1 > n1 || (m1 == n1 && m0 > n0))
1031                 {
1032                   q0--;
1033                   sub_ddmmss (m1, m0, m1, m0, d1, d0);
1034                 }
1035
1036               q1 = 0;
1037
1038               /* Remainder in (n1n0 - m1m0) >> bm.  */
1039               if (rp != 0)
1040                 {
1041                   sub_ddmmss (n1, n0, n1, n0, m1, m0);
1042                   rr.s.low = (n1 << b) | (n0 >> bm);
1043                   rr.s.high = n1 >> bm;
1044                   *rp = rr.ll;
1045                 }
1046             }
1047         }
1048     }
1049
1050   const DWunion ww = {{.low = q0, .high = q1}};
1051   return ww.ll;
1052 }
1053 #endif
1054
1055 #ifdef L_divdi3
1056 DWtype
1057 __divdi3 (DWtype u, DWtype v)
1058 {
1059   word_type c = 0;
1060   DWunion uu = {.ll = u};
1061   DWunion vv = {.ll = v};
1062   DWtype w;
1063
1064   if (uu.s.high < 0)
1065     c = ~c,
1066     uu.ll = -uu.ll;
1067   if (vv.s.high < 0)
1068     c = ~c,
1069     vv.ll = -vv.ll;
1070
1071   w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1072   if (c)
1073     w = -w;
1074
1075   return w;
1076 }
1077 #endif
1078
1079 #ifdef L_moddi3
1080 DWtype
1081 __moddi3 (DWtype u, DWtype v)
1082 {
1083   word_type c = 0;
1084   DWunion uu = {.ll = u};
1085   DWunion vv = {.ll = v};
1086   DWtype w;
1087
1088   if (uu.s.high < 0)
1089     c = ~c,
1090     uu.ll = -uu.ll;
1091   if (vv.s.high < 0)
1092     vv.ll = -vv.ll;
1093
1094   (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1095   if (c)
1096     w = -w;
1097
1098   return w;
1099 }
1100 #endif
1101
1102 #ifdef L_umoddi3
1103 UDWtype
1104 __umoddi3 (UDWtype u, UDWtype v)
1105 {
1106   UDWtype w;
1107
1108   (void) __udivmoddi4 (u, v, &w);
1109
1110   return w;
1111 }
1112 #endif
1113
1114 #ifdef L_udivdi3
1115 UDWtype
1116 __udivdi3 (UDWtype n, UDWtype d)
1117 {
1118   return __udivmoddi4 (n, d, (UDWtype *) 0);
1119 }
1120 #endif
1121 \f
1122 #ifdef L_cmpdi2
1123 word_type
1124 __cmpdi2 (DWtype a, DWtype b)
1125 {
1126   const DWunion au = {.ll = a};
1127   const DWunion bu = {.ll = b};
1128
1129   if (au.s.high < bu.s.high)
1130     return 0;
1131   else if (au.s.high > bu.s.high)
1132     return 2;
1133   if ((UWtype) au.s.low < (UWtype) bu.s.low)
1134     return 0;
1135   else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1136     return 2;
1137   return 1;
1138 }
1139 #endif
1140
1141 #ifdef L_ucmpdi2
1142 word_type
1143 __ucmpdi2 (DWtype a, DWtype b)
1144 {
1145   const DWunion au = {.ll = a};
1146   const DWunion bu = {.ll = b};
1147
1148   if ((UWtype) au.s.high < (UWtype) bu.s.high)
1149     return 0;
1150   else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1151     return 2;
1152   if ((UWtype) au.s.low < (UWtype) bu.s.low)
1153     return 0;
1154   else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1155     return 2;
1156   return 1;
1157 }
1158 #endif
1159 \f
1160 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1161 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1162 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1163
1164 DWtype
1165 __fixunstfDI (TFtype a)
1166 {
1167   if (a < 0)
1168     return 0;
1169
1170   /* Compute high word of result, as a flonum.  */
1171   const TFtype b = (a / HIGH_WORD_COEFF);
1172   /* Convert that to fixed (but not to DWtype!),
1173      and shift it into the high word.  */
1174   UDWtype v = (UWtype) b;
1175   v <<= WORD_SIZE;
1176   /* Remove high part from the TFtype, leaving the low part as flonum.  */
1177   a -= (TFtype)v;
1178   /* Convert that to fixed (but not to DWtype!) and add it in.
1179      Sometimes A comes out negative.  This is significant, since
1180      A has more bits than a long int does.  */
1181   if (a < 0)
1182     v -= (UWtype) (- a);
1183   else
1184     v += (UWtype) a;
1185   return v;
1186 }
1187 #endif
1188
1189 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1190 DWtype
1191 __fixtfdi (TFtype a)
1192 {
1193   if (a < 0)
1194     return - __fixunstfDI (-a);
1195   return __fixunstfDI (a);
1196 }
1197 #endif
1198
1199 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1200 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1201 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1202
1203 DWtype
1204 __fixunsxfDI (XFtype a)
1205 {
1206   if (a < 0)
1207     return 0;
1208
1209   /* Compute high word of result, as a flonum.  */
1210   const XFtype b = (a / HIGH_WORD_COEFF);
1211   /* Convert that to fixed (but not to DWtype!),
1212      and shift it into the high word.  */
1213   UDWtype v = (UWtype) b;
1214   v <<= WORD_SIZE;
1215   /* Remove high part from the XFtype, leaving the low part as flonum.  */
1216   a -= (XFtype)v;
1217   /* Convert that to fixed (but not to DWtype!) and add it in.
1218      Sometimes A comes out negative.  This is significant, since
1219      A has more bits than a long int does.  */
1220   if (a < 0)
1221     v -= (UWtype) (- a);
1222   else
1223     v += (UWtype) a;
1224   return v;
1225 }
1226 #endif
1227
1228 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1229 DWtype
1230 __fixxfdi (XFtype a)
1231 {
1232   if (a < 0)
1233     return - __fixunsxfDI (-a);
1234   return __fixunsxfDI (a);
1235 }
1236 #endif
1237
1238 #ifdef L_fixunsdfdi
1239 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1240 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1241
1242 DWtype
1243 __fixunsdfDI (DFtype a)
1244 {
1245   /* Get high part of result.  The division here will just moves the radix
1246      point and will not cause any rounding.  Then the conversion to integral
1247      type chops result as desired.  */
1248   const UWtype hi = a / HIGH_WORD_COEFF;
1249
1250   /* Get low part of result.  Convert `hi' to floating type and scale it back,
1251      then subtract this from the number being converted.  This leaves the low
1252      part.  Convert that to integral type.  */
1253   const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1254
1255   /* Assemble result from the two parts.  */
1256   return ((UDWtype) hi << WORD_SIZE) | lo;
1257 }
1258 #endif
1259
1260 #ifdef L_fixdfdi
1261 DWtype
1262 __fixdfdi (DFtype a)
1263 {
1264   if (a < 0)
1265     return - __fixunsdfDI (-a);
1266   return __fixunsdfDI (a);
1267 }
1268 #endif
1269
1270 #ifdef L_fixunssfdi
1271 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1272 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1273
1274 DWtype
1275 __fixunssfDI (SFtype original_a)
1276 {
1277   /* Convert the SFtype to a DFtype, because that is surely not going
1278      to lose any bits.  Some day someone else can write a faster version
1279      that avoids converting to DFtype, and verify it really works right.  */
1280   const DFtype a = original_a;
1281
1282   /* Get high part of result.  The division here will just moves the radix
1283      point and will not cause any rounding.  Then the conversion to integral
1284      type chops result as desired.  */
1285   const UWtype hi = a / HIGH_WORD_COEFF;
1286
1287   /* Get low part of result.  Convert `hi' to floating type and scale it back,
1288      then subtract this from the number being converted.  This leaves the low
1289      part.  Convert that to integral type.  */
1290   const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1291
1292   /* Assemble result from the two parts.  */
1293   return ((UDWtype) hi << WORD_SIZE) | lo;
1294 }
1295 #endif
1296
1297 #ifdef L_fixsfdi
1298 DWtype
1299 __fixsfdi (SFtype a)
1300 {
1301   if (a < 0)
1302     return - __fixunssfDI (-a);
1303   return __fixunssfDI (a);
1304 }
1305 #endif
1306
1307 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1308 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1309 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1310 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1311
1312 XFtype
1313 __floatdixf (DWtype u)
1314 {
1315   XFtype d = (Wtype) (u >> WORD_SIZE);
1316   d *= HIGH_HALFWORD_COEFF;
1317   d *= HIGH_HALFWORD_COEFF;
1318   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1319
1320   return d;
1321 }
1322 #endif
1323
1324 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1325 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1326 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1327 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1328
1329 TFtype
1330 __floatditf (DWtype u)
1331 {
1332   TFtype d = (Wtype) (u >> WORD_SIZE);
1333   d *= HIGH_HALFWORD_COEFF;
1334   d *= HIGH_HALFWORD_COEFF;
1335   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1336
1337   return d;
1338 }
1339 #endif
1340
1341 #ifdef L_floatdidf
1342 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1343 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1344 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1345
1346 DFtype
1347 __floatdidf (DWtype u)
1348 {
1349   DFtype d = (Wtype) (u >> WORD_SIZE);
1350   d *= HIGH_HALFWORD_COEFF;
1351   d *= HIGH_HALFWORD_COEFF;
1352   d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1353
1354   return d;
1355 }
1356 #endif
1357
1358 #ifdef L_floatdisf
1359 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1360 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1361 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1362
1363 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1364 #define DF_SIZE DBL_MANT_DIG
1365 #define SF_SIZE FLT_MANT_DIG
1366
1367 SFtype
1368 __floatdisf (DWtype u)
1369 {
1370   /* Protect against double-rounding error.
1371      Represent any low-order bits, that might be truncated in DFmode,
1372      by a bit that won't be lost.  The bit can go in anywhere below the
1373      rounding position of the SFmode.  A fixed mask and bit position
1374      handles all usual configurations.  It doesn't handle the case
1375      of 128-bit DImode, however.  */
1376   if (DF_SIZE < DI_SIZE
1377       && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1378     {
1379 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1380       if (! (- ((DWtype) 1 << DF_SIZE) < u
1381              && u < ((DWtype) 1 << DF_SIZE)))
1382         {
1383           if ((UDWtype) u & (REP_BIT - 1))
1384             {
1385               u &= ~ (REP_BIT - 1);
1386               u |= REP_BIT;
1387             }
1388         }
1389     }
1390   /* Do the calculation in DFmode
1391      so that we don't lose any of the precision of the high word
1392      while multiplying it.  */
1393   DFtype f = (Wtype) (u >> WORD_SIZE);
1394   f *= HIGH_HALFWORD_COEFF;
1395   f *= HIGH_HALFWORD_COEFF;
1396   f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1397
1398   return (SFtype) f;
1399 }
1400 #endif
1401
1402 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80
1403 /* Reenable the normal types, in case limits.h needs them.  */
1404 #undef char
1405 #undef short
1406 #undef int
1407 #undef long
1408 #undef unsigned
1409 #undef float
1410 #undef double
1411 #undef MIN
1412 #undef MAX
1413 #include <limits.h>
1414
1415 UWtype
1416 __fixunsxfSI (XFtype a)
1417 {
1418   if (a >= - (DFtype) Wtype_MIN)
1419     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1420   return (Wtype) a;
1421 }
1422 #endif
1423
1424 #ifdef L_fixunsdfsi
1425 /* Reenable the normal types, in case limits.h needs them.  */
1426 #undef char
1427 #undef short
1428 #undef int
1429 #undef long
1430 #undef unsigned
1431 #undef float
1432 #undef double
1433 #undef MIN
1434 #undef MAX
1435 #include <limits.h>
1436
1437 UWtype
1438 __fixunsdfSI (DFtype a)
1439 {
1440   if (a >= - (DFtype) Wtype_MIN)
1441     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1442   return (Wtype) a;
1443 }
1444 #endif
1445
1446 #ifdef L_fixunssfsi
1447 /* Reenable the normal types, in case limits.h needs them.  */
1448 #undef char
1449 #undef short
1450 #undef int
1451 #undef long
1452 #undef unsigned
1453 #undef float
1454 #undef double
1455 #undef MIN
1456 #undef MAX
1457 #include <limits.h>
1458
1459 UWtype
1460 __fixunssfSI (SFtype a)
1461 {
1462   if (a >= - (SFtype) Wtype_MIN)
1463     return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1464   return (Wtype) a;
1465 }
1466 #endif
1467 \f
1468 /* From here on down, the routines use normal data types.  */
1469
1470 #define SItype bogus_type
1471 #define USItype bogus_type
1472 #define DItype bogus_type
1473 #define UDItype bogus_type
1474 #define SFtype bogus_type
1475 #define DFtype bogus_type
1476 #undef Wtype
1477 #undef UWtype
1478 #undef HWtype
1479 #undef UHWtype
1480 #undef DWtype
1481 #undef UDWtype
1482
1483 #undef char
1484 #undef short
1485 #undef int
1486 #undef long
1487 #undef unsigned
1488 #undef float
1489 #undef double
1490 \f
1491 #ifdef L__gcc_bcmp
1492
1493 /* Like bcmp except the sign is meaningful.
1494    Result is negative if S1 is less than S2,
1495    positive if S1 is greater, 0 if S1 and S2 are equal.  */
1496
1497 int
1498 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1499 {
1500   while (size > 0)
1501     {
1502       const unsigned char c1 = *s1++, c2 = *s2++;
1503       if (c1 != c2)
1504         return c1 - c2;
1505       size--;
1506     }
1507   return 0;
1508 }
1509
1510 #endif
1511 \f
1512 /* __eprintf used to be used by GCC's private version of <assert.h>.
1513    We no longer provide that header, but this routine remains in libgcc.a
1514    for binary backward compatibility.  Note that it is not included in
1515    the shared version of libgcc.  */
1516 #ifdef L_eprintf
1517 #ifndef inhibit_libc
1518
1519 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
1520 #include <stdio.h>
1521
1522 void
1523 __eprintf (const char *string, const char *expression,
1524            unsigned int line, const char *filename)
1525 {
1526   fprintf (stderr, string, expression, line, filename);
1527   fflush (stderr);
1528   abort ();
1529 }
1530
1531 #endif
1532 #endif
1533
1534 \f
1535 #ifdef L_clear_cache
1536 /* Clear part of an instruction cache.  */
1537
1538 void
1539 __clear_cache (char *beg __attribute__((__unused__)),
1540                char *end __attribute__((__unused__)))
1541 {
1542 #ifdef CLEAR_INSN_CACHE
1543   CLEAR_INSN_CACHE (beg, end);
1544 #endif /* CLEAR_INSN_CACHE */
1545 }
1546
1547 #endif /* L_clear_cache */
1548 \f
1549 #ifdef L_enable_execute_stack
1550 /* Attempt to turn on execute permission for the stack.  */
1551
1552 #ifdef ENABLE_EXECUTE_STACK
1553   ENABLE_EXECUTE_STACK
1554 #else
1555 void
1556 __enable_execute_stack (void *addr __attribute__((__unused__)))
1557 {}
1558 #endif /* ENABLE_EXECUTE_STACK */
1559
1560 #endif /* L_enable_execute_stack */
1561 \f
1562 #ifdef L_trampoline
1563
1564 /* Jump to a trampoline, loading the static chain address.  */
1565
1566 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1567
1568 int
1569 getpagesize (void)
1570 {
1571 #ifdef _ALPHA_
1572   return 8192;
1573 #else
1574   return 4096;
1575 #endif
1576 }
1577
1578 #ifdef __i386__
1579 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1580 #endif
1581
1582 int
1583 mprotect (char *addr, int len, int prot)
1584 {
1585   int np, op;
1586
1587   if (prot == 7)
1588     np = 0x40;
1589   else if (prot == 5)
1590     np = 0x20;
1591   else if (prot == 4)
1592     np = 0x10;
1593   else if (prot == 3)
1594     np = 0x04;
1595   else if (prot == 1)
1596     np = 0x02;
1597   else if (prot == 0)
1598     np = 0x01;
1599
1600   if (VirtualProtect (addr, len, np, &op))
1601     return 0;
1602   else
1603     return -1;
1604 }
1605
1606 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1607
1608 #ifdef TRANSFER_FROM_TRAMPOLINE
1609 TRANSFER_FROM_TRAMPOLINE
1610 #endif
1611 #endif /* L_trampoline */
1612 \f
1613 #ifndef __CYGWIN__
1614 #ifdef L__main
1615
1616 #include "gbl-ctors.h"
1617 /* Some systems use __main in a way incompatible with its use in gcc, in these
1618    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1619    give the same symbol without quotes for an alternative entry point.  You
1620    must define both, or neither.  */
1621 #ifndef NAME__MAIN
1622 #define NAME__MAIN "__main"
1623 #define SYMBOL__MAIN __main
1624 #endif
1625
1626 #ifdef INIT_SECTION_ASM_OP
1627 #undef HAS_INIT_SECTION
1628 #define HAS_INIT_SECTION
1629 #endif
1630
1631 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1632
1633 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1634    code to run constructors.  In that case, we need to handle EH here, too.  */
1635
1636 #ifdef EH_FRAME_SECTION_NAME
1637 #include "unwind-dw2-fde.h"
1638 extern unsigned char __EH_FRAME_BEGIN__[];
1639 #endif
1640
1641 /* Run all the global destructors on exit from the program.  */
1642
1643 void
1644 __do_global_dtors (void)
1645 {
1646 #ifdef DO_GLOBAL_DTORS_BODY
1647   DO_GLOBAL_DTORS_BODY;
1648 #else
1649   static func_ptr *p = __DTOR_LIST__ + 1;
1650   while (*p)
1651     {
1652       p++;
1653       (*(p-1)) ();
1654     }
1655 #endif
1656 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1657   {
1658     static int completed = 0;
1659     if (! completed)
1660       {
1661         completed = 1;
1662         __deregister_frame_info (__EH_FRAME_BEGIN__);
1663       }
1664   }
1665 #endif
1666 }
1667 #endif
1668
1669 #ifndef HAS_INIT_SECTION
1670 /* Run all the global constructors on entry to the program.  */
1671
1672 void
1673 __do_global_ctors (void)
1674 {
1675 #ifdef EH_FRAME_SECTION_NAME
1676   {
1677     static struct object object;
1678     __register_frame_info (__EH_FRAME_BEGIN__, &object);
1679   }
1680 #endif
1681   DO_GLOBAL_CTORS_BODY;
1682   atexit (__do_global_dtors);
1683 }
1684 #endif /* no HAS_INIT_SECTION */
1685
1686 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1687 /* Subroutine called automatically by `main'.
1688    Compiling a global function named `main'
1689    produces an automatic call to this function at the beginning.
1690
1691    For many systems, this routine calls __do_global_ctors.
1692    For systems which support a .init section we use the .init section
1693    to run __do_global_ctors, so we need not do anything here.  */
1694
1695 extern void SYMBOL__MAIN (void);
1696 void
1697 SYMBOL__MAIN (void)
1698 {
1699   /* Support recursive calls to `main': run initializers just once.  */
1700   static int initialized;
1701   if (! initialized)
1702     {
1703       initialized = 1;
1704       __do_global_ctors ();
1705     }
1706 }
1707 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1708
1709 #endif /* L__main */
1710 #endif /* __CYGWIN__ */
1711 \f
1712 #ifdef L_ctors
1713
1714 #include "gbl-ctors.h"
1715
1716 /* Provide default definitions for the lists of constructors and
1717    destructors, so that we don't get linker errors.  These symbols are
1718    intentionally bss symbols, so that gld and/or collect will provide
1719    the right values.  */
1720
1721 /* We declare the lists here with two elements each,
1722    so that they are valid empty lists if no other definition is loaded.
1723
1724    If we are using the old "set" extensions to have the gnu linker
1725    collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1726    must be in the bss/common section.
1727
1728    Long term no port should use those extensions.  But many still do.  */
1729 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1730 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1731 func_ptr __CTOR_LIST__[2] = {0, 0};
1732 func_ptr __DTOR_LIST__[2] = {0, 0};
1733 #else
1734 func_ptr __CTOR_LIST__[2];
1735 func_ptr __DTOR_LIST__[2];
1736 #endif
1737 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1738 #endif /* L_ctors */
1739