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