1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
33 /* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
34 supposedly valid even though this is a "target" file. */
35 #include "auto-host.h"
37 /* It is incorrect to include config.h here, because this file is being
38 compiled for the target, and hence definitions concerning only the host
42 #include "coretypes.h"
45 /* Don't use `fancy_abort' here even if config.h says to use it. */
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
53 #define ATTRIBUTE_HIDDEN
58 #ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
62 #if defined (L_negdi2)
66 const DWunion uu = {.ll = u};
67 const DWunion w = { {.low = -uu.s.low,
68 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
76 __addvSI3 (Wtype a, Wtype b)
78 const Wtype w = a + b;
80 if (b >= 0 ? w < a : w > a)
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
87 __addvsi3 (SItype a, SItype b)
89 const SItype w = a + b;
91 if (b >= 0 ? w < a : w > a)
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
101 __addvDI3 (DWtype a, DWtype b)
103 const DWtype w = a + b;
105 if (b >= 0 ? w < a : w > a)
114 __subvSI3 (Wtype a, Wtype b)
116 const Wtype w = a - b;
118 if (b >= 0 ? w > a : w < a)
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
125 __subvsi3 (SItype a, SItype b)
127 const SItype w = a - b;
129 if (b >= 0 ? w > a : w < a)
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
139 __subvDI3 (DWtype a, DWtype b)
141 const DWtype w = a - b;
143 if (b >= 0 ? w > a : w < a)
151 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
153 __mulvSI3 (Wtype a, Wtype b)
155 const DWtype w = (DWtype) a * (DWtype) b;
157 if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1))
162 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
164 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
166 __mulvsi3 (SItype a, SItype b)
168 const DItype w = (DItype) a * (DItype) b;
170 if ((SItype) (w >> WORD_SIZE) != (SItype) w >> (WORD_SIZE-1))
175 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
184 if (a >= 0 ? w > 0 : w < 0)
189 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
195 if (a >= 0 ? w > 0 : w < 0)
200 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
209 if (a >= 0 ? w > 0 : w < 0)
234 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
252 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
276 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
278 __mulvDI3 (DWtype u, DWtype v)
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu = {.ll = u};
283 const DWunion vv = {.ll = v};
285 if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
287 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype) uu.s.low * (DWtype) vv.s.low;
296 /* Two multiplications. */
297 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
298 * (UDWtype) (UWtype) vv.s.low};
299 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
300 * (UDWtype) (UWtype) vv.s.high};
303 w1.s.high -= uu.s.low;
306 w1.ll += (UWtype) w0.s.high;
307 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
309 w0.s.high = w1.s.low;
316 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
321 * (UDWtype) (UWtype) vv.s.low};
322 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
323 * (UDWtype) (UWtype) vv.s.low};
326 w1.s.high -= vv.s.low;
329 w1.ll += (UWtype) w0.s.high;
330 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
332 w0.s.high = w1.s.low;
338 /* A few sign checks and a single multiplication. */
343 if (uu.s.high == 0 && vv.s.high == 0)
345 const DWtype w = (UDWtype) (UWtype) uu.s.low
346 * (UDWtype) (UWtype) vv.s.low;
347 if (__builtin_expect (w >= 0, 1))
353 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
355 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
356 * (UDWtype) (UWtype) vv.s.low};
358 ww.s.high -= uu.s.low;
359 if (__builtin_expect (ww.s.high < 0, 1))
368 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
370 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
371 * (UDWtype) (UWtype) vv.s.low};
373 ww.s.high -= vv.s.low;
374 if (__builtin_expect (ww.s.high < 0, 1))
380 if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
382 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
383 * (UDWtype) (UWtype) vv.s.low};
385 ww.s.high -= uu.s.low;
386 ww.s.high -= vv.s.low;
387 if (__builtin_expect (ww.s.high >= 0, 1))
401 /* Unless shift functions are defined with full ANSI prototypes,
402 parameter b will be promoted to int if word_type is smaller than an int. */
405 __lshrdi3 (DWtype u, word_type b)
410 const DWunion uu = {.ll = u};
411 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
417 w.s.low = (UWtype) uu.s.high >> -bm;
421 const UWtype carries = (UWtype) uu.s.high << bm;
423 w.s.high = (UWtype) uu.s.high >> b;
424 w.s.low = ((UWtype) uu.s.low >> b) | carries;
433 __ashldi3 (DWtype u, word_type b)
438 const DWunion uu = {.ll = u};
439 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
445 w.s.high = (UWtype) uu.s.low << -bm;
449 const UWtype carries = (UWtype) uu.s.low >> bm;
451 w.s.low = (UWtype) uu.s.low << b;
452 w.s.high = ((UWtype) uu.s.high << b) | carries;
461 __ashrdi3 (DWtype u, word_type b)
466 const DWunion uu = {.ll = u};
467 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
472 /* w.s.high = 1..1 or 0..0 */
473 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
474 w.s.low = uu.s.high >> -bm;
478 const UWtype carries = (UWtype) uu.s.high << bm;
480 w.s.high = uu.s.high >> b;
481 w.s.low = ((UWtype) uu.s.low >> b) | carries;
498 count_trailing_zeros (count, u);
508 const DWunion uu = {.ll = u};
509 UWtype word, count, add;
512 word = uu.s.low, add = 0;
513 else if (uu.s.high != 0)
514 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
518 count_trailing_zeros (count, word);
519 return count + add + 1;
525 __muldi3 (DWtype u, DWtype v)
527 const DWunion uu = {.ll = u};
528 const DWunion vv = {.ll = v};
529 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
531 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
532 + (UWtype) uu.s.high * (UWtype) vv.s.low);
538 #if (defined (L_udivdi3) || defined (L_divdi3) || \
539 defined (L_umoddi3) || defined (L_moddi3))
540 #if defined (sdiv_qrnnd)
541 #define L_udiv_w_sdiv
546 #if defined (sdiv_qrnnd)
547 #if (defined (L_udivdi3) || defined (L_divdi3) || \
548 defined (L_umoddi3) || defined (L_moddi3))
549 static inline __attribute__ ((__always_inline__))
552 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
559 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
561 /* Dividend, divisor, and quotient are nonnegative. */
562 sdiv_qrnnd (q, r, a1, a0, d);
566 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
567 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
568 /* Divide (c1*2^32 + c0) by d. */
569 sdiv_qrnnd (q, r, c1, c0, d);
570 /* Add 2^31 to quotient. */
571 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
576 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
577 c1 = a1 >> 1; /* A/2 */
578 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
580 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
582 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
584 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
601 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
604 c0 = ~c0; /* logical NOT */
606 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
608 q = ~q; /* (A/2)/b1 */
611 r = 2*r + (a0 & 1); /* A/(2*b1) */
629 else /* Implies c1 = b1 */
630 { /* Hence a1 = d - 1 = 2*b1 - 1 */
648 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
650 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
651 UWtype a1 __attribute__ ((__unused__)),
652 UWtype a0 __attribute__ ((__unused__)),
653 UWtype d __attribute__ ((__unused__)))
660 #if (defined (L_udivdi3) || defined (L_divdi3) || \
661 defined (L_umoddi3) || defined (L_moddi3))
666 const UQItype __clz_tab[] =
668 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
669 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
670 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
671 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
672 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
673 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
674 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
675 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
686 count_leading_zeros (ret, x);
697 const DWunion uu = {.ll = x};
702 word = uu.s.high, add = 0;
704 word = uu.s.low, add = W_TYPE_SIZE;
706 count_leading_zeros (ret, word);
718 count_trailing_zeros (ret, x);
729 const DWunion uu = {.ll = x};
734 word = uu.s.low, add = 0;
736 word = uu.s.high, add = W_TYPE_SIZE;
738 count_trailing_zeros (ret, word);
743 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
744 || defined (L_popcount_tab))
745 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
748 #ifdef L_popcount_tab
749 const UQItype __popcount_tab[] =
751 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
752 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
753 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
754 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
755 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
756 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
757 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
758 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
765 __popcountSI2 (UWtype x)
769 for (i = 0; i < W_TYPE_SIZE; i += 8)
770 ret += __popcount_tab[(x >> i) & 0xff];
779 __popcountDI2 (UDWtype x)
783 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
784 ret += __popcount_tab[(x >> i) & 0xff];
793 __paritySI2 (UWtype x)
796 # error "fill out the table"
807 return (0x6996 >> x) & 1;
814 __parityDI2 (UDWtype x)
816 const DWunion uu = {.ll = x};
817 UWtype nx = uu.s.low ^ uu.s.high;
820 # error "fill out the table"
831 return (0x6996 >> nx) & 1;
837 #if (defined (L_udivdi3) || defined (L_divdi3) || \
838 defined (L_umoddi3) || defined (L_moddi3))
839 static inline __attribute__ ((__always_inline__))
842 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
844 const DWunion nn = {.ll = n};
845 const DWunion dd = {.ll = d};
847 UWtype d0, d1, n0, n1, n2;
856 #if !UDIV_NEEDS_NORMALIZATION
863 udiv_qrnnd (q0, n0, n1, n0, d0);
866 /* Remainder in n0. */
873 d0 = 1 / d0; /* Divide intentionally by zero. */
875 udiv_qrnnd (q1, n1, 0, n1, d0);
876 udiv_qrnnd (q0, n0, n1, n0, d0);
878 /* Remainder in n0. */
889 #else /* UDIV_NEEDS_NORMALIZATION */
897 count_leading_zeros (bm, d0);
901 /* Normalize, i.e. make the most significant bit of the
905 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
909 udiv_qrnnd (q0, n0, n1, n0, d0);
912 /* Remainder in n0 >> bm. */
919 d0 = 1 / d0; /* Divide intentionally by zero. */
921 count_leading_zeros (bm, d0);
925 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
926 conclude (the most significant bit of n1 is set) /\ (the
927 leading quotient digit q1 = 1).
929 This special case is necessary, not an optimization.
930 (Shifts counts of W_TYPE_SIZE are undefined.) */
939 b = W_TYPE_SIZE - bm;
943 n1 = (n1 << bm) | (n0 >> b);
946 udiv_qrnnd (q1, n1, n2, n1, d0);
951 udiv_qrnnd (q0, n0, n1, n0, d0);
953 /* Remainder in n0 >> bm. */
963 #endif /* UDIV_NEEDS_NORMALIZATION */
974 /* Remainder in n1n0. */
986 count_leading_zeros (bm, d1);
989 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
990 conclude (the most significant bit of n1 is set) /\ (the
991 quotient digit q0 = 0 or 1).
993 This special case is necessary, not an optimization. */
995 /* The condition on the next line takes advantage of that
996 n1 >= d1 (true due to program flow). */
997 if (n1 > d1 || n0 >= d0)
1000 sub_ddmmss (n1, n0, n1, n0, d1, d0);
1019 b = W_TYPE_SIZE - bm;
1021 d1 = (d1 << bm) | (d0 >> b);
1024 n1 = (n1 << bm) | (n0 >> b);
1027 udiv_qrnnd (q0, n1, n2, n1, d1);
1028 umul_ppmm (m1, m0, q0, d0);
1030 if (m1 > n1 || (m1 == n1 && m0 > n0))
1033 sub_ddmmss (m1, m0, m1, m0, d1, d0);
1038 /* Remainder in (n1n0 - m1m0) >> bm. */
1041 sub_ddmmss (n1, n0, n1, n0, m1, m0);
1042 rr.s.low = (n1 << b) | (n0 >> bm);
1043 rr.s.high = n1 >> bm;
1050 const DWunion ww = {{.low = q0, .high = q1}};
1057 __divdi3 (DWtype u, DWtype v)
1060 DWunion uu = {.ll = u};
1061 DWunion vv = {.ll = v};
1071 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1081 __moddi3 (DWtype u, DWtype v)
1084 DWunion uu = {.ll = u};
1085 DWunion vv = {.ll = v};
1094 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1104 __umoddi3 (UDWtype u, UDWtype v)
1108 (void) __udivmoddi4 (u, v, &w);
1116 __udivdi3 (UDWtype n, UDWtype d)
1118 return __udivmoddi4 (n, d, (UDWtype *) 0);
1124 __cmpdi2 (DWtype a, DWtype b)
1126 const DWunion au = {.ll = a};
1127 const DWunion bu = {.ll = b};
1129 if (au.s.high < bu.s.high)
1131 else if (au.s.high > bu.s.high)
1133 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1135 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1143 __ucmpdi2 (DWtype a, DWtype b)
1145 const DWunion au = {.ll = a};
1146 const DWunion bu = {.ll = b};
1148 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1150 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1152 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1154 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1160 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1161 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1162 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1165 __fixunstfDI (TFtype a)
1170 /* Compute high word of result, as a flonum. */
1171 const TFtype b = (a / HIGH_WORD_COEFF);
1172 /* Convert that to fixed (but not to DWtype!),
1173 and shift it into the high word. */
1174 UDWtype v = (UWtype) b;
1176 /* Remove high part from the TFtype, leaving the low part as flonum. */
1178 /* Convert that to fixed (but not to DWtype!) and add it in.
1179 Sometimes A comes out negative. This is significant, since
1180 A has more bits than a long int does. */
1182 v -= (UWtype) (- a);
1189 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1191 __fixtfdi (TFtype a)
1194 return - __fixunstfDI (-a);
1195 return __fixunstfDI (a);
1199 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1200 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1201 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1204 __fixunsxfDI (XFtype a)
1209 /* Compute high word of result, as a flonum. */
1210 const XFtype b = (a / HIGH_WORD_COEFF);
1211 /* Convert that to fixed (but not to DWtype!),
1212 and shift it into the high word. */
1213 UDWtype v = (UWtype) b;
1215 /* Remove high part from the XFtype, leaving the low part as flonum. */
1217 /* Convert that to fixed (but not to DWtype!) and add it in.
1218 Sometimes A comes out negative. This is significant, since
1219 A has more bits than a long int does. */
1221 v -= (UWtype) (- a);
1228 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1230 __fixxfdi (XFtype a)
1233 return - __fixunsxfDI (-a);
1234 return __fixunsxfDI (a);
1239 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1240 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1243 __fixunsdfDI (DFtype a)
1245 /* Get high part of result. The division here will just moves the radix
1246 point and will not cause any rounding. Then the conversion to integral
1247 type chops result as desired. */
1248 const UWtype hi = a / HIGH_WORD_COEFF;
1250 /* Get low part of result. Convert `hi' to floating type and scale it back,
1251 then subtract this from the number being converted. This leaves the low
1252 part. Convert that to integral type. */
1253 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1255 /* Assemble result from the two parts. */
1256 return ((UDWtype) hi << WORD_SIZE) | lo;
1262 __fixdfdi (DFtype a)
1265 return - __fixunsdfDI (-a);
1266 return __fixunsdfDI (a);
1271 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1272 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1275 __fixunssfDI (SFtype original_a)
1277 /* Convert the SFtype to a DFtype, because that is surely not going
1278 to lose any bits. Some day someone else can write a faster version
1279 that avoids converting to DFtype, and verify it really works right. */
1280 const DFtype a = original_a;
1282 /* Get high part of result. The division here will just moves the radix
1283 point and will not cause any rounding. Then the conversion to integral
1284 type chops result as desired. */
1285 const UWtype hi = a / HIGH_WORD_COEFF;
1287 /* Get low part of result. Convert `hi' to floating type and scale it back,
1288 then subtract this from the number being converted. This leaves the low
1289 part. Convert that to integral type. */
1290 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1292 /* Assemble result from the two parts. */
1293 return ((UDWtype) hi << WORD_SIZE) | lo;
1299 __fixsfdi (SFtype a)
1302 return - __fixunssfDI (-a);
1303 return __fixunssfDI (a);
1307 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80)
1308 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1309 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1310 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1313 __floatdixf (DWtype u)
1315 XFtype d = (Wtype) (u >> WORD_SIZE);
1316 d *= HIGH_HALFWORD_COEFF;
1317 d *= HIGH_HALFWORD_COEFF;
1318 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1324 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1325 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1326 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1327 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1330 __floatditf (DWtype u)
1332 TFtype d = (Wtype) (u >> WORD_SIZE);
1333 d *= HIGH_HALFWORD_COEFF;
1334 d *= HIGH_HALFWORD_COEFF;
1335 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1342 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1343 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1344 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1347 __floatdidf (DWtype u)
1349 DFtype d = (Wtype) (u >> WORD_SIZE);
1350 d *= HIGH_HALFWORD_COEFF;
1351 d *= HIGH_HALFWORD_COEFF;
1352 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1359 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1360 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1361 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1363 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1364 #define DF_SIZE DBL_MANT_DIG
1365 #define SF_SIZE FLT_MANT_DIG
1368 __floatdisf (DWtype u)
1370 /* Protect against double-rounding error.
1371 Represent any low-order bits, that might be truncated in DFmode,
1372 by a bit that won't be lost. The bit can go in anywhere below the
1373 rounding position of the SFmode. A fixed mask and bit position
1374 handles all usual configurations. It doesn't handle the case
1375 of 128-bit DImode, however. */
1376 if (DF_SIZE < DI_SIZE
1377 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1379 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1380 if (! (- ((DWtype) 1 << DF_SIZE) < u
1381 && u < ((DWtype) 1 << DF_SIZE)))
1383 if ((UDWtype) u & (REP_BIT - 1))
1385 u &= ~ (REP_BIT - 1);
1390 /* Do the calculation in DFmode
1391 so that we don't lose any of the precision of the high word
1392 while multiplying it. */
1393 DFtype f = (Wtype) (u >> WORD_SIZE);
1394 f *= HIGH_HALFWORD_COEFF;
1395 f *= HIGH_HALFWORD_COEFF;
1396 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1402 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80
1403 /* Reenable the normal types, in case limits.h needs them. */
1416 __fixunsxfSI (XFtype a)
1418 if (a >= - (DFtype) Wtype_MIN)
1419 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1425 /* Reenable the normal types, in case limits.h needs them. */
1438 __fixunsdfSI (DFtype a)
1440 if (a >= - (DFtype) Wtype_MIN)
1441 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1447 /* Reenable the normal types, in case limits.h needs them. */
1460 __fixunssfSI (SFtype a)
1462 if (a >= - (SFtype) Wtype_MIN)
1463 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1468 /* Integer power helper used from __builtin_powi for non-constant
1471 #if defined(L_powisf2) || defined(L_powidf2) \
1472 || (defined(L_powixf2) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 80) \
1473 || (defined(L_powitf2) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1474 # if defined(L_powisf2)
1475 # define TYPE SFtype
1476 # define NAME __powisf2
1477 # elif defined(L_powidf2)
1478 # define TYPE DFtype
1479 # define NAME __powidf2
1480 # elif defined(L_powixf2)
1481 # define TYPE XFtype
1482 # define NAME __powixf2
1483 # elif defined(L_powitf2)
1484 # define TYPE TFtype
1485 # define NAME __powitf2
1489 NAME (TYPE x, Wtype m)
1491 UWtype n = m < 0 ? -m : m;
1492 TYPE y = n % 2 ? x : 1;
1499 return m < 0 ? 1/y : y;
1504 /* From here on down, the routines use normal data types. */
1506 #define SItype bogus_type
1507 #define USItype bogus_type
1508 #define DItype bogus_type
1509 #define UDItype bogus_type
1510 #define SFtype bogus_type
1511 #define DFtype bogus_type
1529 /* Like bcmp except the sign is meaningful.
1530 Result is negative if S1 is less than S2,
1531 positive if S1 is greater, 0 if S1 and S2 are equal. */
1534 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1538 const unsigned char c1 = *s1++, c2 = *s2++;
1548 /* __eprintf used to be used by GCC's private version of <assert.h>.
1549 We no longer provide that header, but this routine remains in libgcc.a
1550 for binary backward compatibility. Note that it is not included in
1551 the shared version of libgcc. */
1553 #ifndef inhibit_libc
1555 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1559 __eprintf (const char *string, const char *expression,
1560 unsigned int line, const char *filename)
1562 fprintf (stderr, string, expression, line, filename);
1571 #ifdef L_clear_cache
1572 /* Clear part of an instruction cache. */
1575 __clear_cache (char *beg __attribute__((__unused__)),
1576 char *end __attribute__((__unused__)))
1578 #ifdef CLEAR_INSN_CACHE
1579 CLEAR_INSN_CACHE (beg, end);
1580 #endif /* CLEAR_INSN_CACHE */
1583 #endif /* L_clear_cache */
1585 #ifdef L_enable_execute_stack
1586 /* Attempt to turn on execute permission for the stack. */
1588 #ifdef ENABLE_EXECUTE_STACK
1589 ENABLE_EXECUTE_STACK
1592 __enable_execute_stack (void *addr __attribute__((__unused__)))
1594 #endif /* ENABLE_EXECUTE_STACK */
1596 #endif /* L_enable_execute_stack */
1600 /* Jump to a trampoline, loading the static chain address. */
1602 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1615 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1619 mprotect (char *addr, int len, int prot)
1636 if (VirtualProtect (addr, len, np, &op))
1642 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1644 #ifdef TRANSFER_FROM_TRAMPOLINE
1645 TRANSFER_FROM_TRAMPOLINE
1647 #endif /* L_trampoline */
1652 #include "gbl-ctors.h"
1653 /* Some systems use __main in a way incompatible with its use in gcc, in these
1654 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1655 give the same symbol without quotes for an alternative entry point. You
1656 must define both, or neither. */
1658 #define NAME__MAIN "__main"
1659 #define SYMBOL__MAIN __main
1662 #ifdef INIT_SECTION_ASM_OP
1663 #undef HAS_INIT_SECTION
1664 #define HAS_INIT_SECTION
1667 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1669 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1670 code to run constructors. In that case, we need to handle EH here, too. */
1672 #ifdef EH_FRAME_SECTION_NAME
1673 #include "unwind-dw2-fde.h"
1674 extern unsigned char __EH_FRAME_BEGIN__[];
1677 /* Run all the global destructors on exit from the program. */
1680 __do_global_dtors (void)
1682 #ifdef DO_GLOBAL_DTORS_BODY
1683 DO_GLOBAL_DTORS_BODY;
1685 static func_ptr *p = __DTOR_LIST__ + 1;
1692 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1694 static int completed = 0;
1698 __deregister_frame_info (__EH_FRAME_BEGIN__);
1705 #ifndef HAS_INIT_SECTION
1706 /* Run all the global constructors on entry to the program. */
1709 __do_global_ctors (void)
1711 #ifdef EH_FRAME_SECTION_NAME
1713 static struct object object;
1714 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1717 DO_GLOBAL_CTORS_BODY;
1718 atexit (__do_global_dtors);
1720 #endif /* no HAS_INIT_SECTION */
1722 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1723 /* Subroutine called automatically by `main'.
1724 Compiling a global function named `main'
1725 produces an automatic call to this function at the beginning.
1727 For many systems, this routine calls __do_global_ctors.
1728 For systems which support a .init section we use the .init section
1729 to run __do_global_ctors, so we need not do anything here. */
1731 extern void SYMBOL__MAIN (void);
1735 /* Support recursive calls to `main': run initializers just once. */
1736 static int initialized;
1740 __do_global_ctors ();
1743 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1745 #endif /* L__main */
1746 #endif /* __CYGWIN__ */
1750 #include "gbl-ctors.h"
1752 /* Provide default definitions for the lists of constructors and
1753 destructors, so that we don't get linker errors. These symbols are
1754 intentionally bss symbols, so that gld and/or collect will provide
1755 the right values. */
1757 /* We declare the lists here with two elements each,
1758 so that they are valid empty lists if no other definition is loaded.
1760 If we are using the old "set" extensions to have the gnu linker
1761 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1762 must be in the bss/common section.
1764 Long term no port should use those extensions. But many still do. */
1765 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1766 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1767 func_ptr __CTOR_LIST__[2] = {0, 0};
1768 func_ptr __DTOR_LIST__[2] = {0, 0};
1770 func_ptr __CTOR_LIST__[2];
1771 func_ptr __DTOR_LIST__[2];
1773 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1774 #endif /* L_ctors */