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 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)
72 w.s.high = -uu.s.high - ((UWtype) w.s.low > 0);
80 __addvsi3 (Wtype a, Wtype b)
86 if (b >= 0 ? w < a : w > a)
95 __addvdi3 (DWtype a, DWtype b)
101 if (b >= 0 ? w < a : w > a)
110 __subvsi3 (Wtype a, Wtype b)
113 return __addvsi3 (a, (-b));
119 if (b >= 0 ? w > a : w < a)
129 __subvdi3 (DWtype a, DWtype b)
138 if (b >= 0 ? w > a : w < a)
148 __mulvsi3 (Wtype a, Wtype b)
154 if (((a >= 0) == (b >= 0)) ? w < 0 : w > 0)
169 if (a >= 0 ? w > 0 : w < 0)
184 if (a >= 0 ? w > 0 : w < 0)
233 __mulvdi3 (DWtype u, DWtype v)
239 if (((u >= 0) == (v >= 0)) ? w < 0 : w > 0)
247 /* Unless shift functions are defined with full ANSI prototypes,
248 parameter b will be promoted to int if word_type is smaller than an int. */
251 __lshrdi3 (DWtype u, word_type b)
262 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
266 w.s.low = (UWtype) uu.s.high >> -bm;
270 UWtype carries = (UWtype) uu.s.high << bm;
272 w.s.high = (UWtype) uu.s.high >> b;
273 w.s.low = ((UWtype) uu.s.low >> b) | carries;
282 __ashldi3 (DWtype u, word_type b)
293 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
297 w.s.high = (UWtype) uu.s.low << -bm;
301 UWtype carries = (UWtype) uu.s.low >> bm;
303 w.s.low = (UWtype) uu.s.low << b;
304 w.s.high = ((UWtype) uu.s.high << b) | carries;
313 __ashrdi3 (DWtype u, word_type b)
324 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
327 /* w.s.high = 1..1 or 0..0 */
328 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
329 w.s.low = uu.s.high >> -bm;
333 UWtype carries = (UWtype) uu.s.high << bm;
335 w.s.high = uu.s.high >> b;
336 w.s.low = ((UWtype) uu.s.low >> b) | carries;
345 extern int __ffsdi2 (DWtype u);
350 UWtype word, count, add;
354 word = uu.s.low, add = 0;
355 else if (uu.s.high != 0)
356 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
360 count_trailing_zeros (count, word);
361 return count + add + 1;
367 __muldi3 (DWtype u, DWtype v)
375 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
376 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
377 + (UWtype) uu.s.high * (UWtype) vv.s.low);
383 #if (defined (L_udivdi3) || defined (L_divdi3) || \
384 defined (L_umoddi3) || defined (L_moddi3))
385 #if defined (sdiv_qrnnd)
386 #define L_udiv_w_sdiv
391 #if defined (sdiv_qrnnd)
392 #if (defined (L_udivdi3) || defined (L_divdi3) || \
393 defined (L_umoddi3) || defined (L_moddi3))
394 static inline __attribute__ ((__always_inline__))
397 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
404 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
406 /* dividend, divisor, and quotient are nonnegative */
407 sdiv_qrnnd (q, r, a1, a0, d);
411 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
412 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
413 /* Divide (c1*2^32 + c0) by d */
414 sdiv_qrnnd (q, r, c1, c0, d);
415 /* Add 2^31 to quotient */
416 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
421 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
422 c1 = a1 >> 1; /* A/2 */
423 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
425 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
427 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
429 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
446 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
449 c0 = ~c0; /* logical NOT */
451 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
453 q = ~q; /* (A/2)/b1 */
456 r = 2*r + (a0 & 1); /* A/(2*b1) */
474 else /* Implies c1 = b1 */
475 { /* Hence a1 = d - 1 = 2*b1 - 1 */
493 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
495 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
496 UWtype a1 __attribute__ ((__unused__)),
497 UWtype a0 __attribute__ ((__unused__)),
498 UWtype d __attribute__ ((__unused__)))
505 #if (defined (L_udivdi3) || defined (L_divdi3) || \
506 defined (L_umoddi3) || defined (L_moddi3))
511 const UQItype __clz_tab[] =
513 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,
514 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,
515 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,
516 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,
517 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,
518 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,
519 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,
520 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,
526 extern int __clzsi2 (USItype x);
533 count_leading_zeros (ret, w);
534 ret -= (sizeof(w) - sizeof(x)) * BITS_PER_UNIT;
542 extern int __clzdi2 (UDItype x);
549 if (sizeof(x) > sizeof(word))
555 word = uu.s.high, add = 0;
557 word = uu.s.low, add = W_TYPE_SIZE;
560 word = x, add = (Wtype)(sizeof(x) - sizeof(word)) * BITS_PER_UNIT;
562 count_leading_zeros (ret, word);
569 extern int __ctzsi2 (USItype x);
575 count_trailing_zeros (ret, x);
583 extern int __ctzdi2 (UDItype x);
590 if (sizeof(x) > sizeof(word))
596 word = uu.s.low, add = 0;
598 word = uu.s.high, add = W_TYPE_SIZE;
603 count_trailing_zeros (ret, word);
608 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
609 || defined (L_popcount_tab))
610 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
613 #ifdef L_popcount_tab
614 const UQItype __popcount_tab[] =
616 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,
617 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,
618 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,
619 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,
620 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,
621 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,
622 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,
623 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,
629 extern int __popcountsi2 (USItype x);
631 __popcountsi2 (USItype x)
633 return __popcount_tab[(x >> 0) & 0xff]
634 + __popcount_tab[(x >> 8) & 0xff]
635 + __popcount_tab[(x >> 16) & 0xff]
636 + __popcount_tab[(x >> 24) & 0xff];
642 extern int __popcountdi2 (UDItype x);
644 __popcountdi2 (UDItype x)
646 return __popcount_tab[(x >> 0) & 0xff]
647 + __popcount_tab[(x >> 8) & 0xff]
648 + __popcount_tab[(x >> 16) & 0xff]
649 + __popcount_tab[(x >> 24) & 0xff]
650 + __popcount_tab[(x >> 32) & 0xff]
651 + __popcount_tab[(x >> 40) & 0xff]
652 + __popcount_tab[(x >> 48) & 0xff]
653 + __popcount_tab[(x >> 56) & 0xff];
659 extern int __paritysi2 (USItype x);
661 __paritysi2 (USItype x)
675 extern int __paritydi2 (UDItype x);
677 __paritydi2 (UDItype x)
679 UWtype nx = x ^ (x >> 32);
691 #if (defined (L_udivdi3) || defined (L_divdi3) || \
692 defined (L_umoddi3) || defined (L_moddi3))
693 static inline __attribute__ ((__always_inline__))
696 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
701 UWtype d0, d1, n0, n1, n2;
713 #if !UDIV_NEEDS_NORMALIZATION
720 udiv_qrnnd (q0, n0, n1, n0, d0);
723 /* Remainder in n0. */
730 d0 = 1 / d0; /* Divide intentionally by zero. */
732 udiv_qrnnd (q1, n1, 0, n1, d0);
733 udiv_qrnnd (q0, n0, n1, n0, d0);
735 /* Remainder in n0. */
746 #else /* UDIV_NEEDS_NORMALIZATION */
754 count_leading_zeros (bm, d0);
758 /* Normalize, i.e. make the most significant bit of the
762 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
766 udiv_qrnnd (q0, n0, n1, n0, d0);
769 /* Remainder in n0 >> bm. */
776 d0 = 1 / d0; /* Divide intentionally by zero. */
778 count_leading_zeros (bm, d0);
782 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
783 conclude (the most significant bit of n1 is set) /\ (the
784 leading quotient digit q1 = 1).
786 This special case is necessary, not an optimization.
787 (Shifts counts of W_TYPE_SIZE are undefined.) */
796 b = W_TYPE_SIZE - bm;
800 n1 = (n1 << bm) | (n0 >> b);
803 udiv_qrnnd (q1, n1, n2, n1, d0);
808 udiv_qrnnd (q0, n0, n1, n0, d0);
810 /* Remainder in n0 >> bm. */
820 #endif /* UDIV_NEEDS_NORMALIZATION */
831 /* Remainder in n1n0. */
843 count_leading_zeros (bm, d1);
846 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
847 conclude (the most significant bit of n1 is set) /\ (the
848 quotient digit q0 = 0 or 1).
850 This special case is necessary, not an optimization. */
852 /* The condition on the next line takes advantage of that
853 n1 >= d1 (true due to program flow). */
854 if (n1 > d1 || n0 >= d0)
857 sub_ddmmss (n1, n0, n1, n0, d1, d0);
876 b = W_TYPE_SIZE - bm;
878 d1 = (d1 << bm) | (d0 >> b);
881 n1 = (n1 << bm) | (n0 >> b);
884 udiv_qrnnd (q0, n1, n2, n1, d1);
885 umul_ppmm (m1, m0, q0, d0);
887 if (m1 > n1 || (m1 == n1 && m0 > n0))
890 sub_ddmmss (m1, m0, m1, m0, d1, d0);
895 /* Remainder in (n1n0 - m1m0) >> bm. */
898 sub_ddmmss (n1, n0, n1, n0, m1, m0);
899 rr.s.low = (n1 << b) | (n0 >> bm);
900 rr.s.high = n1 >> bm;
915 __divdi3 (DWtype u, DWtype v)
931 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
941 __moddi3 (DWtype u, DWtype v)
956 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
966 __umoddi3 (UDWtype u, UDWtype v)
970 (void) __udivmoddi4 (u, v, &w);
978 __udivdi3 (UDWtype n, UDWtype d)
980 return __udivmoddi4 (n, d, (UDWtype *) 0);
986 __cmpdi2 (DWtype a, DWtype b)
990 au.ll = a, bu.ll = b;
992 if (au.s.high < bu.s.high)
994 else if (au.s.high > bu.s.high)
996 if ((UWtype) au.s.low < (UWtype) bu.s.low)
998 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1006 __ucmpdi2 (DWtype a, DWtype b)
1010 au.ll = a, bu.ll = b;
1012 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1014 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1016 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1018 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1024 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1025 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1026 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1029 __fixunstfDI (TFtype a)
1037 /* Compute high word of result, as a flonum. */
1038 b = (a / HIGH_WORD_COEFF);
1039 /* Convert that to fixed (but not to DWtype!),
1040 and shift it into the high word. */
1043 /* Remove high part from the TFtype, leaving the low part as flonum. */
1045 /* Convert that to fixed (but not to DWtype!) and add it in.
1046 Sometimes A comes out negative. This is significant, since
1047 A has more bits than a long int does. */
1049 v -= (UWtype) (- a);
1056 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1058 __fixtfdi (TFtype a)
1061 return - __fixunstfDI (-a);
1062 return __fixunstfDI (a);
1066 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1067 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1068 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1071 __fixunsxfDI (XFtype a)
1079 /* Compute high word of result, as a flonum. */
1080 b = (a / HIGH_WORD_COEFF);
1081 /* Convert that to fixed (but not to DWtype!),
1082 and shift it into the high word. */
1085 /* Remove high part from the XFtype, leaving the low part as flonum. */
1087 /* Convert that to fixed (but not to DWtype!) and add it in.
1088 Sometimes A comes out negative. This is significant, since
1089 A has more bits than a long int does. */
1091 v -= (UWtype) (- a);
1098 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1100 __fixxfdi (XFtype a)
1103 return - __fixunsxfDI (-a);
1104 return __fixunsxfDI (a);
1109 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1110 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1113 __fixunsdfDI (DFtype a)
1117 /* Get high part of result. The division here will just moves the radix
1118 point and will not cause any rounding. Then the conversion to integral
1119 type chops result as desired. */
1120 hi = a / HIGH_WORD_COEFF;
1122 /* Get low part of result. Convert `hi' to floating type and scale it back,
1123 then subtract this from the number being converted. This leaves the low
1124 part. Convert that to integral type. */
1125 lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1127 /* Assemble result from the two parts. */
1128 return ((UDWtype) hi << WORD_SIZE) | lo;
1134 __fixdfdi (DFtype a)
1137 return - __fixunsdfDI (-a);
1138 return __fixunsdfDI (a);
1143 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1144 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1147 __fixunssfDI (SFtype original_a)
1149 /* Convert the SFtype to a DFtype, because that is surely not going
1150 to lose any bits. Some day someone else can write a faster version
1151 that avoids converting to DFtype, and verify it really works right. */
1152 DFtype a = original_a;
1155 /* Get high part of result. The division here will just moves the radix
1156 point and will not cause any rounding. Then the conversion to integral
1157 type chops result as desired. */
1158 hi = a / HIGH_WORD_COEFF;
1160 /* Get low part of result. Convert `hi' to floating type and scale it back,
1161 then subtract this from the number being converted. This leaves the low
1162 part. Convert that to integral type. */
1163 lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1165 /* Assemble result from the two parts. */
1166 return ((UDWtype) hi << WORD_SIZE) | lo;
1172 __fixsfdi (SFtype a)
1175 return - __fixunssfDI (-a);
1176 return __fixunssfDI (a);
1180 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1181 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1182 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1183 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1186 __floatdixf (DWtype u)
1190 d = (Wtype) (u >> WORD_SIZE);
1191 d *= HIGH_HALFWORD_COEFF;
1192 d *= HIGH_HALFWORD_COEFF;
1193 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1199 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1200 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1201 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1202 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1205 __floatditf (DWtype u)
1209 d = (Wtype) (u >> WORD_SIZE);
1210 d *= HIGH_HALFWORD_COEFF;
1211 d *= HIGH_HALFWORD_COEFF;
1212 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1219 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1220 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1221 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1224 __floatdidf (DWtype u)
1228 d = (Wtype) (u >> WORD_SIZE);
1229 d *= HIGH_HALFWORD_COEFF;
1230 d *= HIGH_HALFWORD_COEFF;
1231 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1238 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1239 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1240 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1242 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1243 #define DF_SIZE DBL_MANT_DIG
1244 #define SF_SIZE FLT_MANT_DIG
1247 __floatdisf (DWtype u)
1249 /* Do the calculation in DFmode
1250 so that we don't lose any of the precision of the high word
1251 while multiplying it. */
1254 /* Protect against double-rounding error.
1255 Represent any low-order bits, that might be truncated in DFmode,
1256 by a bit that won't be lost. The bit can go in anywhere below the
1257 rounding position of the SFmode. A fixed mask and bit position
1258 handles all usual configurations. It doesn't handle the case
1259 of 128-bit DImode, however. */
1260 if (DF_SIZE < DI_SIZE
1261 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1263 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1264 if (! (- ((DWtype) 1 << DF_SIZE) < u
1265 && u < ((DWtype) 1 << DF_SIZE)))
1267 if ((UDWtype) u & (REP_BIT - 1))
1269 u &= ~ (REP_BIT - 1);
1274 f = (Wtype) (u >> WORD_SIZE);
1275 f *= HIGH_HALFWORD_COEFF;
1276 f *= HIGH_HALFWORD_COEFF;
1277 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1283 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1284 /* Reenable the normal types, in case limits.h needs them. */
1297 __fixunsxfSI (XFtype a)
1299 if (a >= - (DFtype) Wtype_MIN)
1300 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1306 /* Reenable the normal types, in case limits.h needs them. */
1319 __fixunsdfSI (DFtype a)
1321 if (a >= - (DFtype) Wtype_MIN)
1322 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1328 /* Reenable the normal types, in case limits.h needs them. */
1341 __fixunssfSI (SFtype a)
1343 if (a >= - (SFtype) Wtype_MIN)
1344 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1349 /* From here on down, the routines use normal data types. */
1351 #define SItype bogus_type
1352 #define USItype bogus_type
1353 #define DItype bogus_type
1354 #define UDItype bogus_type
1355 #define SFtype bogus_type
1356 #define DFtype bogus_type
1374 /* Like bcmp except the sign is meaningful.
1375 Result is negative if S1 is less than S2,
1376 positive if S1 is greater, 0 if S1 and S2 are equal. */
1379 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1383 unsigned char c1 = *s1++, c2 = *s2++;
1393 /* __eprintf used to be used by GCC's private version of <assert.h>.
1394 We no longer provide that header, but this routine remains in libgcc.a
1395 for binary backward compatibility. Note that it is not included in
1396 the shared version of libgcc. */
1398 #ifndef inhibit_libc
1400 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1404 __eprintf (const char *string, const char *expression,
1405 unsigned int line, const char *filename)
1407 fprintf (stderr, string, expression, line, filename);
1416 #ifdef L_clear_cache
1417 /* Clear part of an instruction cache. */
1419 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1422 __clear_cache (char *beg __attribute__((__unused__)),
1423 char *end __attribute__((__unused__)))
1425 #ifdef CLEAR_INSN_CACHE
1426 CLEAR_INSN_CACHE (beg, end);
1428 #ifdef INSN_CACHE_SIZE
1429 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1430 static int initialized;
1434 typedef (*function_ptr) (void);
1436 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1437 /* It's cheaper to clear the whole cache.
1438 Put in a series of jump instructions so that calling the beginning
1439 of the cache will clear the whole thing. */
1443 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1444 & -INSN_CACHE_LINE_WIDTH);
1445 int end_ptr = ptr + INSN_CACHE_SIZE;
1447 while (ptr < end_ptr)
1449 *(INSTRUCTION_TYPE *)ptr
1450 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1451 ptr += INSN_CACHE_LINE_WIDTH;
1453 *(INSTRUCTION_TYPE *) (ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1458 /* Call the beginning of the sequence. */
1459 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1460 & -INSN_CACHE_LINE_WIDTH))
1463 #else /* Cache is large. */
1467 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1468 & -INSN_CACHE_LINE_WIDTH);
1470 while (ptr < (int) array + sizeof array)
1472 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1473 ptr += INSN_CACHE_LINE_WIDTH;
1479 /* Find the location in array that occupies the same cache line as BEG. */
1481 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1482 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1483 & -INSN_CACHE_PLANE_SIZE)
1486 /* Compute the cache alignment of the place to stop clearing. */
1487 #if 0 /* This is not needed for gcc's purposes. */
1488 /* If the block to clear is bigger than a cache plane,
1489 we clear the entire cache, and OFFSET is already correct. */
1490 if (end < beg + INSN_CACHE_PLANE_SIZE)
1492 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1493 & -INSN_CACHE_LINE_WIDTH)
1494 & (INSN_CACHE_PLANE_SIZE - 1));
1496 #if INSN_CACHE_DEPTH > 1
1497 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1498 if (end_addr <= start_addr)
1499 end_addr += INSN_CACHE_PLANE_SIZE;
1501 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1503 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1504 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1506 while (addr != stop)
1508 /* Call the return instruction at ADDR. */
1509 ((function_ptr) addr) ();
1511 addr += INSN_CACHE_LINE_WIDTH;
1514 #else /* just one plane */
1517 /* Call the return instruction at START_ADDR. */
1518 ((function_ptr) start_addr) ();
1520 start_addr += INSN_CACHE_LINE_WIDTH;
1522 while ((start_addr % INSN_CACHE_SIZE) != offset);
1523 #endif /* just one plane */
1524 #endif /* Cache is large */
1525 #endif /* Cache exists */
1526 #endif /* CLEAR_INSN_CACHE */
1529 #endif /* L_clear_cache */
1533 /* Jump to a trampoline, loading the static chain address. */
1535 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1548 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1552 mprotect (char *addr, int len, int prot)
1569 if (VirtualProtect (addr, len, np, &op))
1575 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1577 #ifdef TRANSFER_FROM_TRAMPOLINE
1578 TRANSFER_FROM_TRAMPOLINE
1583 #include <sys/signal.h>
1586 /* Motorola forgot to put memctl.o in the libp version of libc881.a,
1587 so define it here, because we need it in __clear_insn_cache below */
1588 /* On older versions of this OS, no memctl or MCT_TEXT are defined;
1589 hence we enable this stuff only if MCT_TEXT is #define'd. */
1604 /* Clear instruction cache so we can call trampolines on stack.
1605 This is called from FINALIZE_TRAMPOLINE in mot3300.h. */
1608 __clear_insn_cache (void)
1613 /* Preserve errno, because users would be surprised to have
1614 errno changing without explicitly calling any system-call. */
1617 /* Keep it simple : memctl (MCT_TEXT) always fully clears the insn cache.
1618 No need to use an address derived from _start or %sp, as 0 works also. */
1619 memctl(0, 4096, MCT_TEXT);
1624 #endif /* __sysV68__ */
1625 #endif /* L_trampoline */
1630 #include "gbl-ctors.h"
1631 /* Some systems use __main in a way incompatible with its use in gcc, in these
1632 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1633 give the same symbol without quotes for an alternative entry point. You
1634 must define both, or neither. */
1636 #define NAME__MAIN "__main"
1637 #define SYMBOL__MAIN __main
1640 #ifdef INIT_SECTION_ASM_OP
1641 #undef HAS_INIT_SECTION
1642 #define HAS_INIT_SECTION
1645 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1647 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1648 code to run constructors. In that case, we need to handle EH here, too. */
1650 #ifdef EH_FRAME_SECTION_NAME
1651 #include "unwind-dw2-fde.h"
1652 extern unsigned char __EH_FRAME_BEGIN__[];
1655 /* Run all the global destructors on exit from the program. */
1658 __do_global_dtors (void)
1660 #ifdef DO_GLOBAL_DTORS_BODY
1661 DO_GLOBAL_DTORS_BODY;
1663 static func_ptr *p = __DTOR_LIST__ + 1;
1670 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1672 static int completed = 0;
1676 __deregister_frame_info (__EH_FRAME_BEGIN__);
1683 #ifndef HAS_INIT_SECTION
1684 /* Run all the global constructors on entry to the program. */
1687 __do_global_ctors (void)
1689 #ifdef EH_FRAME_SECTION_NAME
1691 static struct object object;
1692 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1695 DO_GLOBAL_CTORS_BODY;
1696 atexit (__do_global_dtors);
1698 #endif /* no HAS_INIT_SECTION */
1700 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1701 /* Subroutine called automatically by `main'.
1702 Compiling a global function named `main'
1703 produces an automatic call to this function at the beginning.
1705 For many systems, this routine calls __do_global_ctors.
1706 For systems which support a .init section we use the .init section
1707 to run __do_global_ctors, so we need not do anything here. */
1712 /* Support recursive calls to `main': run initializers just once. */
1713 static int initialized;
1717 __do_global_ctors ();
1720 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1722 #endif /* L__main */
1723 #endif /* __CYGWIN__ */
1727 #include "gbl-ctors.h"
1729 /* Provide default definitions for the lists of constructors and
1730 destructors, so that we don't get linker errors. These symbols are
1731 intentionally bss symbols, so that gld and/or collect will provide
1732 the right values. */
1734 /* We declare the lists here with two elements each,
1735 so that they are valid empty lists if no other definition is loaded.
1737 If we are using the old "set" extensions to have the gnu linker
1738 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1739 must be in the bss/common section.
1741 Long term no port should use those extensions. But many still do. */
1742 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1743 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1744 func_ptr __CTOR_LIST__[2] = {0, 0};
1745 func_ptr __DTOR_LIST__[2] = {0, 0};
1747 func_ptr __CTOR_LIST__[2];
1748 func_ptr __DTOR_LIST__[2];
1750 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1751 #endif /* L_ctors */
1755 #include "gbl-ctors.h"
1763 static func_ptr *atexit_chain = 0;
1764 static long atexit_chain_length = 0;
1765 static volatile long last_atexit_chain_slot = -1;
1768 atexit (func_ptr func)
1770 if (++last_atexit_chain_slot == atexit_chain_length)
1772 atexit_chain_length += 32;
1774 atexit_chain = (func_ptr *) realloc (atexit_chain, atexit_chain_length
1775 * sizeof (func_ptr));
1777 atexit_chain = (func_ptr *) malloc (atexit_chain_length
1778 * sizeof (func_ptr));
1781 atexit_chain_length = 0;
1782 last_atexit_chain_slot = -1;
1787 atexit_chain[last_atexit_chain_slot] = func;
1791 extern void _cleanup (void);
1792 extern void _exit (int) __attribute__ ((__noreturn__));
1799 for ( ; last_atexit_chain_slot-- >= 0; )
1801 (*atexit_chain[last_atexit_chain_slot + 1]) ();
1802 atexit_chain[last_atexit_chain_slot + 1] = 0;
1804 free (atexit_chain);
1817 /* Simple; we just need a wrapper for ON_EXIT. */
1819 atexit (func_ptr func)
1821 return ON_EXIT (func);
1824 #endif /* ON_EXIT */
1825 #endif /* NEED_ATEXIT */