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