Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

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