home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / libgcc2.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  37KB  |  1,694 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* As a special exception, if you link this library with files
  22.    compiled with GCC to produce an executable, this does not cause
  23.    the resulting executable to be covered by the GNU General Public License.
  24.    This exception does not however invalidate any other reasons why
  25.    the executable file might be covered by the GNU General Public License.  */
  26.  
  27. /* It is incorrect to include config.h here, because this file is being
  28.    compiled for the target, and hence definitions concerning only the host
  29.    do not apply.  */
  30.  
  31. #include "tconfig.h"
  32. #include "machmode.h"
  33. #ifndef L_trampoline
  34. #include "gstddef.h"
  35. #endif
  36.  
  37. /* Don't use `fancy_abort' here even if config.h says to use it.  */
  38. #ifdef abort
  39. #undef abort
  40. #endif
  41.  
  42. /* In the first part of this file, we are interfacing to calls generated
  43.    by the compiler itself.  These calls pass values into these routines
  44.    which have very specific modes (rather than very specific types), and
  45.    these compiler-generated calls also expect any return values to have
  46.    very specific modes (rather than very specific types).  Thus, we need
  47.    to avoid using regular C language type names in this part of the file
  48.    because the sizes for those types can be configured to be anything.
  49.    Instead we use the following special type names.  */
  50.  
  51. typedef unsigned int UQItype    __attribute__ ((mode (QI)));
  52. typedef      int SItype    __attribute__ ((mode (SI)));
  53. typedef unsigned int USItype    __attribute__ ((mode (SI)));
  54. typedef         int DItype    __attribute__ ((mode (DI)));
  55. typedef unsigned int UDItype    __attribute__ ((mode (DI)));
  56. typedef     float SFtype    __attribute__ ((mode (SF)));
  57. typedef        float DFtype    __attribute__ ((mode (DF)));
  58. #if 0
  59. typedef        float XFtype    __attribute__ ((mode (XF)));
  60. #endif
  61. #if LONG_DOUBLE_TYPE_SIZE == 128
  62. typedef        float TFtype    __attribute__ ((mode (TF)));
  63. #endif
  64.  
  65. /* Make sure that we don't accidentaly use any normal C language built-in
  66.    type names in the first part of this file.  Instead we want to use *only*
  67.    the type names defined above.  The following macro definitions insure
  68.    that if we *do* accidently use soem normal C language built-in type name,
  69.    we will get a syntax error.  */
  70.  
  71. #define char bogus_type
  72. #define short bogus_type
  73. #define int bogus_type
  74. #define long bogus_type
  75. #define unsigned bogus_type
  76. #define float bogus_type
  77. #define double bogus_type
  78.  
  79. #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  80.  
  81. /* DIstructs are pairs of SItype values in the order determined by
  82.    WORDS_BIG_ENDIAN.  */
  83.  
  84. #if WORDS_BIG_ENDIAN
  85.   struct DIstruct {SItype high, low;};
  86. #else
  87.   struct DIstruct {SItype low, high;};
  88. #endif
  89.  
  90. /* We need this union to unpack/pack DImode values, since we don't have
  91.    any arithmetic yet.  Incoming DImode parameters are stored into the
  92.    `ll' field, and the unpacked result is read from the struct `s'.  */
  93.  
  94. typedef union
  95. {
  96.   struct DIstruct s;
  97.   DItype ll;
  98. } DIunion;
  99.  
  100. #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
  101.  
  102. #include "longlong.h"
  103.  
  104. #endif /* udiv or mul */
  105.  
  106. extern DItype __fixunssfdi (SFtype a);
  107. extern DItype __fixunsdfdi (DFtype a);
  108.  
  109. #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
  110. #if defined (L_divdi3) || defined (L_moddi3)
  111. static inline
  112. #endif
  113. DItype
  114. __negdi2 (u)
  115.      DItype u;
  116. {
  117.   DIunion w;
  118.   DIunion uu;
  119.  
  120.   uu.ll = u;
  121.  
  122.   w.s.low = -uu.s.low;
  123.   w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
  124.  
  125.   return w.ll;
  126. }
  127. #endif
  128.  
  129. #ifdef L_lshldi3
  130. DItype
  131. __lshldi3 (u, b)
  132.      DItype u;
  133.      SItype b;
  134. {
  135.   DIunion w;
  136.   SItype bm;
  137.   DIunion uu;
  138.  
  139.   if (b == 0)
  140.     return u;
  141.  
  142.   uu.ll = u;
  143.  
  144.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  145.   if (bm <= 0)
  146.     {
  147.       w.s.low = 0;
  148.       w.s.high = (USItype)uu.s.low << -bm;
  149.     }
  150.   else
  151.     {
  152.       USItype carries = (USItype)uu.s.low >> bm;
  153.       w.s.low = (USItype)uu.s.low << b;
  154.       w.s.high = ((USItype)uu.s.high << b) | carries;
  155.     }
  156.  
  157.   return w.ll;
  158. }
  159. #endif
  160.  
  161. #ifdef L_lshrdi3
  162. DItype
  163. __lshrdi3 (u, b)
  164.      DItype u;
  165.      SItype b;
  166. {
  167.   DIunion w;
  168.   SItype bm;
  169.   DIunion uu;
  170.  
  171.   if (b == 0)
  172.     return u;
  173.  
  174.   uu.ll = u;
  175.  
  176.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  177.   if (bm <= 0)
  178.     {
  179.       w.s.high = 0;
  180.       w.s.low = (USItype)uu.s.high >> -bm;
  181.     }
  182.   else
  183.     {
  184.       USItype carries = (USItype)uu.s.high << bm;
  185.       w.s.high = (USItype)uu.s.high >> b;
  186.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  187.     }
  188.  
  189.   return w.ll;
  190. }
  191. #endif
  192.  
  193. #ifdef L_ashldi3
  194. DItype
  195. __ashldi3 (u, b)
  196.      DItype u;
  197.      SItype b;
  198. {
  199.   DIunion w;
  200.   SItype bm;
  201.   DIunion uu;
  202.  
  203.   if (b == 0)
  204.     return u;
  205.  
  206.   uu.ll = u;
  207.  
  208.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  209.   if (bm <= 0)
  210.     {
  211.       w.s.low = 0;
  212.       w.s.high = (USItype)uu.s.low << -bm;
  213.     }
  214.   else
  215.     {
  216.       USItype carries = (USItype)uu.s.low >> bm;
  217.       w.s.low = (USItype)uu.s.low << b;
  218.       w.s.high = ((USItype)uu.s.high << b) | carries;
  219.     }
  220.  
  221.   return w.ll;
  222. }
  223. #endif
  224.  
  225. #ifdef L_ashrdi3
  226. DItype
  227. __ashrdi3 (u, b)
  228.      DItype u;
  229.      SItype b;
  230. {
  231.   DIunion w;
  232.   SItype bm;
  233.   DIunion uu;
  234.  
  235.   if (b == 0)
  236.     return u;
  237.  
  238.   uu.ll = u;
  239.  
  240.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  241.   if (bm <= 0)
  242.     {
  243.       /* w.s.high = 1..1 or 0..0 */
  244.       w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
  245.       w.s.low = uu.s.high >> -bm;
  246.     }
  247.   else
  248.     {
  249.       USItype carries = (USItype)uu.s.high << bm;
  250.       w.s.high = uu.s.high >> b;
  251.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  252.     }
  253.  
  254.   return w.ll;
  255. }
  256. #endif
  257.  
  258. #ifdef L_muldi3
  259. DItype
  260. __muldi3 (u, v)
  261.      DItype u, v;
  262. {
  263.   DIunion w;
  264.   DIunion uu, vv;
  265.  
  266.   uu.ll = u,
  267.   vv.ll = v;
  268.  
  269.   w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  270.   w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  271.            + (USItype) uu.s.high * (USItype) vv.s.low);
  272.  
  273.   return w.ll;
  274. }
  275. #endif
  276.  
  277. #ifdef L_udiv_w_sdiv
  278. USItype
  279. __udiv_w_sdiv (rp, a1, a0, d)
  280.      USItype *rp, a1, a0, d;
  281. {
  282.   USItype q, r;
  283.   USItype c0, c1, b1;
  284.  
  285.   if ((SItype) d >= 0)
  286.     {
  287.       if (a1 < d - a1 - (a0 >> 31))
  288.     {
  289.       /* dividend, divisor, and quotient are nonnegative */
  290.       sdiv_qrnnd (q, r, a1, a0, d);
  291.     }
  292.       else
  293.     {
  294.       /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
  295.       sub_ddmmss (c1, c0, a1, a0, d >> 1, d << 31);
  296.       /* Divide (c1*2^32 + c0) by d */
  297.       sdiv_qrnnd (q, r, c1, c0, d);
  298.       /* Add 2^31 to quotient */
  299.       q += (USItype) 1 << 31;
  300.     }
  301.     }
  302.   else
  303.     {
  304.       b1 = d >> 1;            /* d/2, between 2^30 and 2^31 - 1 */
  305.       c1 = a1 >> 1;            /* A/2 */
  306.       c0 = (a1 << 31) + (a0 >> 1);
  307.  
  308.       if (a1 < b1)            /* A < 2^32*b1, so A/2 < 2^31*b1 */
  309.     {
  310.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  311.  
  312.       r = 2*r + (a0 & 1);        /* Remainder from A/(2*b1) */
  313.       if ((d & 1) != 0)
  314.         {
  315.           if (r >= q)
  316.         r = r - q;
  317.           else if (q - r <= d)
  318.         {
  319.           r = r - q + d;
  320.           q--;
  321.         }
  322.           else
  323.         {
  324.           r = r - q + 2*d;
  325.           q -= 2;
  326.         }
  327.         }
  328.     }
  329.       else if (c1 < b1)            /* So 2^31 <= (A/2)/b1 < 2^32 */
  330.     {
  331.       c1 = (b1 - 1) - c1;
  332.       c0 = ~c0;            /* logical NOT */
  333.  
  334.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  335.  
  336.       q = ~q;            /* (A/2)/b1 */
  337.       r = (b1 - 1) - r;
  338.  
  339.       r = 2*r + (a0 & 1);        /* A/(2*b1) */
  340.  
  341.       if ((d & 1) != 0)
  342.         {
  343.           if (r >= q)
  344.         r = r - q;
  345.           else if (q - r <= d)
  346.         {
  347.           r = r - q + d;
  348.           q--;
  349.         }
  350.           else
  351.         {
  352.           r = r - q + 2*d;
  353.           q -= 2;
  354.         }
  355.         }
  356.     }
  357.       else                /* Implies c1 = b1 */
  358.     {                /* Hence a1 = d - 1 = 2*b1 - 1 */
  359.       if (a0 >= -d)
  360.         {
  361.           q = -1;
  362.           r = a0 + d;
  363.         }
  364.       else
  365.         {
  366.           q = -2;
  367.           r = a0 +