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
)
132 return __addvdi3 (a
, (-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 __ffsSI2 (UWtype u
);
354 count_trailing_zeros (count
, u
);
361 extern int __ffsDI2 (DWtype u
);
366 UWtype word
, count
, add
;
370 word
= uu
.s
.low
, add
= 0;
371 else if (uu
.s
.high
!= 0)
372 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
376 count_trailing_zeros (count
, word
);
377 return count
+ add
+ 1;
383 __muldi3 (DWtype u
, DWtype v
)
391 w
.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
);
392 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
393 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
399 #if (defined (L_udivdi3) || defined (L_divdi3) || \
400 defined (L_umoddi3) || defined (L_moddi3))
401 #if defined (sdiv_qrnnd)
402 #define L_udiv_w_sdiv
407 #if defined (sdiv_qrnnd)
408 #if (defined (L_udivdi3) || defined (L_divdi3) || \
409 defined (L_umoddi3) || defined (L_moddi3))
410 static inline __attribute__ ((__always_inline__
))
413 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
420 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
422 /* dividend, divisor, and quotient are nonnegative */
423 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
427 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
428 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
429 /* Divide (c1*2^32 + c0) by d */
430 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
431 /* Add 2^31 to quotient */
432 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
437 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
438 c1
= a1
>> 1; /* A/2 */
439 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
441 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
443 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
445 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
462 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
465 c0
= ~c0
; /* logical NOT */
467 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
469 q
= ~q
; /* (A/2)/b1 */
472 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
490 else /* Implies c1 = b1 */
491 { /* Hence a1 = d - 1 = 2*b1 - 1 */
509 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
511 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
512 UWtype a1
__attribute__ ((__unused__
)),
513 UWtype a0
__attribute__ ((__unused__
)),
514 UWtype d
__attribute__ ((__unused__
)))
521 #if (defined (L_udivdi3) || defined (L_divdi3) || \
522 defined (L_umoddi3) || defined (L_moddi3))
527 const UQItype __clz_tab
[] =
529 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,
530 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,
531 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,
532 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,
533 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,
534 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,
535 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,
536 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,
542 extern int __clzSI2 (UWtype x
);
548 count_leading_zeros (ret
, x
);
556 extern int __clzDI2 (UDWtype x
);
566 word
= uu
.s
.high
, add
= 0;
568 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
570 count_leading_zeros (ret
, word
);
577 extern int __ctzSI2 (UWtype x
);
583 count_trailing_zeros (ret
, x
);
591 extern int __ctzDI2 (UDWtype x
);
601 word
= uu
.s
.low
, add
= 0;
603 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
605 count_trailing_zeros (ret
, word
);
610 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
611 || defined (L_popcount_tab))
612 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
615 #ifdef L_popcount_tab
616 const UQItype __popcount_tab
[] =
618 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,
619 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,
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 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,
623 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,
624 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,
625 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,
631 extern int __popcountSI2 (UWtype x
);
633 __popcountSI2 (UWtype x
)
637 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
638 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
646 extern int __popcountDI2 (UDWtype x
);
648 __popcountDI2 (UDWtype x
)
652 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
653 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
661 extern int __paritySI2 (UWtype x
);
663 __paritySI2 (UWtype x
)
666 # error "fill out the table"
677 return (0x6996 >> x
) & 1;
683 extern int __parityDI2 (UDWtype x
);
685 __parityDI2 (UDWtype x
)
691 nx
= uu
.s
.low
^ uu
.s
.high
;
694 # error "fill out the table"
705 return (0x6996 >> nx
) & 1;
711 #if (defined (L_udivdi3) || defined (L_divdi3) || \
712 defined (L_umoddi3) || defined (L_moddi3))
713 static inline __attribute__ ((__always_inline__
))
716 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
721 UWtype d0
, d1
, n0
, n1
, n2
;
733 #if !UDIV_NEEDS_NORMALIZATION
740 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
743 /* Remainder in n0. */
750 d0
= 1 / d0
; /* Divide intentionally by zero. */
752 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
753 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
755 /* Remainder in n0. */
766 #else /* UDIV_NEEDS_NORMALIZATION */
774 count_leading_zeros (bm
, d0
);
778 /* Normalize, i.e. make the most significant bit of the
782 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
786 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
789 /* Remainder in n0 >> bm. */
796 d0
= 1 / d0
; /* Divide intentionally by zero. */
798 count_leading_zeros (bm
, d0
);
802 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
803 conclude (the most significant bit of n1 is set) /\ (the
804 leading quotient digit q1 = 1).
806 This special case is necessary, not an optimization.
807 (Shifts counts of W_TYPE_SIZE are undefined.) */
816 b
= W_TYPE_SIZE
- bm
;
820 n1
= (n1
<< bm
) | (n0
>> b
);
823 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
828 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
830 /* Remainder in n0 >> bm. */
840 #endif /* UDIV_NEEDS_NORMALIZATION */
851 /* Remainder in n1n0. */
863 count_leading_zeros (bm
, d1
);
866 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
867 conclude (the most significant bit of n1 is set) /\ (the
868 quotient digit q0 = 0 or 1).
870 This special case is necessary, not an optimization. */
872 /* The condition on the next line takes advantage of that
873 n1 >= d1 (true due to program flow). */
874 if (n1
> d1
|| n0
>= d0
)
877 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
896 b
= W_TYPE_SIZE
- bm
;
898 d1
= (d1
<< bm
) | (d0
>> b
);
901 n1
= (n1
<< bm
) | (n0
>> b
);
904 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
905 umul_ppmm (m1
, m0
, q0
, d0
);
907 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
910 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
915 /* Remainder in (n1n0 - m1m0) >> bm. */
918 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
919 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
920 rr
.s
.high
= n1
>> bm
;
935 __divdi3 (DWtype u
, DWtype v
)
951 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
961 __moddi3 (DWtype u
, DWtype v
)
976 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
986 __umoddi3 (UDWtype u
, UDWtype v
)
990 (void) __udivmoddi4 (u
, v
, &w
);
998 __udivdi3 (UDWtype n
, UDWtype d
)
1000 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1006 __cmpdi2 (DWtype a
, DWtype b
)
1010 au
.ll
= a
, bu
.ll
= b
;
1012 if (au
.s
.high
< bu
.s
.high
)
1014 else if (au
.s
.high
> bu
.s
.high
)
1016 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1018 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1026 __ucmpdi2 (DWtype a
, DWtype b
)
1030 au
.ll
= a
, bu
.ll
= b
;
1032 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1034 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1036 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1038 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1044 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1045 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1046 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1049 __fixunstfDI (TFtype a
)
1057 /* Compute high word of result, as a flonum. */
1058 b
= (a
/ HIGH_WORD_COEFF
);
1059 /* Convert that to fixed (but not to DWtype!),
1060 and shift it into the high word. */
1063 /* Remove high part from the TFtype, leaving the low part as flonum. */
1065 /* Convert that to fixed (but not to DWtype!) and add it in.
1066 Sometimes A comes out negative. This is significant, since
1067 A has more bits than a long int does. */
1069 v
-= (UWtype
) (- a
);
1076 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1078 __fixtfdi (TFtype a
)
1081 return - __fixunstfDI (-a
);
1082 return __fixunstfDI (a
);
1086 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1087 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1088 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1091 __fixunsxfDI (XFtype a
)
1099 /* Compute high word of result, as a flonum. */
1100 b
= (a
/ HIGH_WORD_COEFF
);
1101 /* Convert that to fixed (but not to DWtype!),
1102 and shift it into the high word. */
1105 /* Remove high part from the XFtype, leaving the low part as flonum. */
1107 /* Convert that to fixed (but not to DWtype!) and add it in.
1108 Sometimes A comes out negative. This is significant, since
1109 A has more bits than a long int does. */
1111 v
-= (UWtype
) (- a
);
1118 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1120 __fixxfdi (XFtype a
)
1123 return - __fixunsxfDI (-a
);
1124 return __fixunsxfDI (a
);
1129 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1130 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1133 __fixunsdfDI (DFtype a
)
1137 /* Get high part of result. The division here will just moves the radix
1138 point and will not cause any rounding. Then the conversion to integral
1139 type chops result as desired. */
1140 hi
= a
/ HIGH_WORD_COEFF
;
1142 /* Get low part of result. Convert `hi' to floating type and scale it back,
1143 then subtract this from the number being converted. This leaves the low
1144 part. Convert that to integral type. */
1145 lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1147 /* Assemble result from the two parts. */
1148 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1154 __fixdfdi (DFtype a
)
1157 return - __fixunsdfDI (-a
);
1158 return __fixunsdfDI (a
);
1163 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1164 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1167 __fixunssfDI (SFtype original_a
)
1169 /* Convert the SFtype to a DFtype, because that is surely not going
1170 to lose any bits. Some day someone else can write a faster version
1171 that avoids converting to DFtype, and verify it really works right. */
1172 DFtype a
= original_a
;
1175 /* Get high part of result. The division here will just moves the radix
1176 point and will not cause any rounding. Then the conversion to integral
1177 type chops result as desired. */
1178 hi
= a
/ HIGH_WORD_COEFF
;
1180 /* Get low part of result. Convert `hi' to floating type and scale it back,
1181 then subtract this from the number being converted. This leaves the low
1182 part. Convert that to integral type. */
1183 lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1185 /* Assemble result from the two parts. */
1186 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1192 __fixsfdi (SFtype a
)
1195 return - __fixunssfDI (-a
);
1196 return __fixunssfDI (a
);
1200 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1201 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1202 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1203 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1206 __floatdixf (DWtype u
)
1210 d
= (Wtype
) (u
>> WORD_SIZE
);
1211 d
*= HIGH_HALFWORD_COEFF
;
1212 d
*= HIGH_HALFWORD_COEFF
;
1213 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1219 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1220 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1221 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1222 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1225 __floatditf (DWtype u
)
1229 d
= (Wtype
) (u
>> WORD_SIZE
);
1230 d
*= HIGH_HALFWORD_COEFF
;
1231 d
*= HIGH_HALFWORD_COEFF
;
1232 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1239 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1240 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1241 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1244 __floatdidf (DWtype u
)
1248 d
= (Wtype
) (u
>> WORD_SIZE
);
1249 d
*= HIGH_HALFWORD_COEFF
;
1250 d
*= HIGH_HALFWORD_COEFF
;
1251 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1258 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1259 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1260 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1262 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1263 #define DF_SIZE DBL_MANT_DIG
1264 #define SF_SIZE FLT_MANT_DIG
1267 __floatdisf (DWtype u
)
1269 /* Do the calculation in DFmode
1270 so that we don't lose any of the precision of the high word
1271 while multiplying it. */
1274 /* Protect against double-rounding error.
1275 Represent any low-order bits, that might be truncated in DFmode,
1276 by a bit that won't be lost. The bit can go in anywhere below the
1277 rounding position of the SFmode. A fixed mask and bit position
1278 handles all usual configurations. It doesn't handle the case
1279 of 128-bit DImode, however. */
1280 if (DF_SIZE
< DI_SIZE
1281 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1283 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1284 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1285 && u
< ((DWtype
) 1 << DF_SIZE
)))
1287 if ((UDWtype
) u
& (REP_BIT
- 1))
1289 u
&= ~ (REP_BIT
- 1);
1294 f
= (Wtype
) (u
>> WORD_SIZE
);
1295 f
*= HIGH_HALFWORD_COEFF
;
1296 f
*= HIGH_HALFWORD_COEFF
;
1297 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1303 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1304 /* Reenable the normal types, in case limits.h needs them. */
1317 __fixunsxfSI (XFtype a
)
1319 if (a
>= - (DFtype
) Wtype_MIN
)
1320 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1326 /* Reenable the normal types, in case limits.h needs them. */
1339 __fixunsdfSI (DFtype a
)
1341 if (a
>= - (DFtype
) Wtype_MIN
)
1342 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1348 /* Reenable the normal types, in case limits.h needs them. */
1361 __fixunssfSI (SFtype a
)
1363 if (a
>= - (SFtype
) Wtype_MIN
)
1364 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1369 /* From here on down, the routines use normal data types. */
1371 #define SItype bogus_type
1372 #define USItype bogus_type
1373 #define DItype bogus_type
1374 #define UDItype bogus_type
1375 #define SFtype bogus_type
1376 #define DFtype bogus_type
1394 /* Like bcmp except the sign is meaningful.
1395 Result is negative if S1 is less than S2,
1396 positive if S1 is greater, 0 if S1 and S2 are equal. */
1399 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1403 unsigned char c1
= *s1
++, c2
= *s2
++;
1413 /* __eprintf used to be used by GCC's private version of <assert.h>.
1414 We no longer provide that header, but this routine remains in libgcc.a
1415 for binary backward compatibility. Note that it is not included in
1416 the shared version of libgcc. */
1418 #ifndef inhibit_libc
1420 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1424 __eprintf (const char *string
, const char *expression
,
1425 unsigned int line
, const char *filename
)
1427 fprintf (stderr
, string
, expression
, line
, filename
);
1436 #ifdef L_clear_cache
1437 /* Clear part of an instruction cache. */
1439 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1442 __clear_cache (char *beg
__attribute__((__unused__
)),
1443 char *end
__attribute__((__unused__
)))
1445 #ifdef CLEAR_INSN_CACHE
1446 CLEAR_INSN_CACHE (beg
, end
);
1448 #ifdef INSN_CACHE_SIZE
1449 static char array
[INSN_CACHE_SIZE
+ INSN_CACHE_PLANE_SIZE
+ INSN_CACHE_LINE_WIDTH
];
1450 static int initialized
;
1454 typedef (*function_ptr
) (void);
1456 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1457 /* It's cheaper to clear the whole cache.
1458 Put in a series of jump instructions so that calling the beginning
1459 of the cache will clear the whole thing. */
1463 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1464 & -INSN_CACHE_LINE_WIDTH
);
1465 int end_ptr
= ptr
+ INSN_CACHE_SIZE
;
1467 while (ptr
< end_ptr
)
1469 *(INSTRUCTION_TYPE
*)ptr
1470 = JUMP_AHEAD_INSTRUCTION
+ INSN_CACHE_LINE_WIDTH
;
1471 ptr
+= INSN_CACHE_LINE_WIDTH
;
1473 *(INSTRUCTION_TYPE
*) (ptr
- INSN_CACHE_LINE_WIDTH
) = RETURN_INSTRUCTION
;
1478 /* Call the beginning of the sequence. */
1479 (((function_ptr
) (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1480 & -INSN_CACHE_LINE_WIDTH
))
1483 #else /* Cache is large. */
1487 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1488 & -INSN_CACHE_LINE_WIDTH
);
1490 while (ptr
< (int) array
+ sizeof array
)
1492 *(INSTRUCTION_TYPE
*)ptr
= RETURN_INSTRUCTION
;
1493 ptr
+= INSN_CACHE_LINE_WIDTH
;
1499 /* Find the location in array that occupies the same cache line as BEG. */
1501 offset
= ((int) beg
& -INSN_CACHE_LINE_WIDTH
) & (INSN_CACHE_PLANE_SIZE
- 1);
1502 start_addr
= (((int) (array
+ INSN_CACHE_PLANE_SIZE
- 1)
1503 & -INSN_CACHE_PLANE_SIZE
)
1506 /* Compute the cache alignment of the place to stop clearing. */
1507 #if 0 /* This is not needed for gcc's purposes. */
1508 /* If the block to clear is bigger than a cache plane,
1509 we clear the entire cache, and OFFSET is already correct. */
1510 if (end
< beg
+ INSN_CACHE_PLANE_SIZE
)
1512 offset
= (((int) (end
+ INSN_CACHE_LINE_WIDTH
- 1)
1513 & -INSN_CACHE_LINE_WIDTH
)
1514 & (INSN_CACHE_PLANE_SIZE
- 1));
1516 #if INSN_CACHE_DEPTH > 1
1517 end_addr
= (start_addr
& -INSN_CACHE_PLANE_SIZE
) + offset
;
1518 if (end_addr
<= start_addr
)
1519 end_addr
+= INSN_CACHE_PLANE_SIZE
;
1521 for (plane
= 0; plane
< INSN_CACHE_DEPTH
; plane
++)
1523 int addr
= start_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1524 int stop
= end_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1526 while (addr
!= stop
)
1528 /* Call the return instruction at ADDR. */
1529 ((function_ptr
) addr
) ();
1531 addr
+= INSN_CACHE_LINE_WIDTH
;
1534 #else /* just one plane */
1537 /* Call the return instruction at START_ADDR. */
1538 ((function_ptr
) start_addr
) ();
1540 start_addr
+= INSN_CACHE_LINE_WIDTH
;
1542 while ((start_addr
% INSN_CACHE_SIZE
) != offset
);
1543 #endif /* just one plane */
1544 #endif /* Cache is large */
1545 #endif /* Cache exists */
1546 #endif /* CLEAR_INSN_CACHE */
1549 #endif /* L_clear_cache */
1553 /* Jump to a trampoline, loading the static chain address. */
1555 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1568 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1572 mprotect (char *addr
, int len
, int prot
)
1589 if (VirtualProtect (addr
, len
, np
, &op
))
1595 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1597 #ifdef TRANSFER_FROM_TRAMPOLINE
1598 TRANSFER_FROM_TRAMPOLINE
1603 #include <sys/signal.h>
1606 /* Motorola forgot to put memctl.o in the libp version of libc881.a,
1607 so define it here, because we need it in __clear_insn_cache below */
1608 /* On older versions of this OS, no memctl or MCT_TEXT are defined;
1609 hence we enable this stuff only if MCT_TEXT is #define'd. */
1624 /* Clear instruction cache so we can call trampolines on stack.
1625 This is called from FINALIZE_TRAMPOLINE in mot3300.h. */
1628 __clear_insn_cache (void)
1633 /* Preserve errno, because users would be surprised to have
1634 errno changing without explicitly calling any system-call. */
1637 /* Keep it simple : memctl (MCT_TEXT) always fully clears the insn cache.
1638 No need to use an address derived from _start or %sp, as 0 works also. */
1639 memctl(0, 4096, MCT_TEXT
);
1644 #endif /* __sysV68__ */
1645 #endif /* L_trampoline */
1650 #include "gbl-ctors.h"
1651 /* Some systems use __main in a way incompatible with its use in gcc, in these
1652 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1653 give the same symbol without quotes for an alternative entry point. You
1654 must define both, or neither. */
1656 #define NAME__MAIN "__main"
1657 #define SYMBOL__MAIN __main
1660 #ifdef INIT_SECTION_ASM_OP
1661 #undef HAS_INIT_SECTION
1662 #define HAS_INIT_SECTION
1665 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1667 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1668 code to run constructors. In that case, we need to handle EH here, too. */
1670 #ifdef EH_FRAME_SECTION_NAME
1671 #include "unwind-dw2-fde.h"
1672 extern unsigned char __EH_FRAME_BEGIN__
[];
1675 /* Run all the global destructors on exit from the program. */
1678 __do_global_dtors (void)
1680 #ifdef DO_GLOBAL_DTORS_BODY
1681 DO_GLOBAL_DTORS_BODY
;
1683 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1690 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1692 static int completed
= 0;
1696 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1703 #ifndef HAS_INIT_SECTION
1704 /* Run all the global constructors on entry to the program. */
1707 __do_global_ctors (void)
1709 #ifdef EH_FRAME_SECTION_NAME
1711 static struct object object
;
1712 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1715 DO_GLOBAL_CTORS_BODY
;
1716 atexit (__do_global_dtors
);
1718 #endif /* no HAS_INIT_SECTION */
1720 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1721 /* Subroutine called automatically by `main'.
1722 Compiling a global function named `main'
1723 produces an automatic call to this function at the beginning.
1725 For many systems, this routine calls __do_global_ctors.
1726 For systems which support a .init section we use the .init section
1727 to run __do_global_ctors, so we need not do anything here. */
1732 /* Support recursive calls to `main': run initializers just once. */
1733 static int initialized
;
1737 __do_global_ctors ();
1740 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1742 #endif /* L__main */
1743 #endif /* __CYGWIN__ */
1747 #include "gbl-ctors.h"
1749 /* Provide default definitions for the lists of constructors and
1750 destructors, so that we don't get linker errors. These symbols are
1751 intentionally bss symbols, so that gld and/or collect will provide
1752 the right values. */
1754 /* We declare the lists here with two elements each,
1755 so that they are valid empty lists if no other definition is loaded.
1757 If we are using the old "set" extensions to have the gnu linker
1758 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1759 must be in the bss/common section.
1761 Long term no port should use those extensions. But many still do. */
1762 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1763 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1764 func_ptr __CTOR_LIST__
[2] = {0, 0};
1765 func_ptr __DTOR_LIST__
[2] = {0, 0};
1767 func_ptr __CTOR_LIST__
[2];
1768 func_ptr __DTOR_LIST__
[2];
1770 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1771 #endif /* L_ctors */
1775 #include "gbl-ctors.h"
1783 static func_ptr
*atexit_chain
= 0;
1784 static long atexit_chain_length
= 0;
1785 static volatile long last_atexit_chain_slot
= -1;
1788 atexit (func_ptr func
)
1790 if (++last_atexit_chain_slot
== atexit_chain_length
)
1792 atexit_chain_length
+= 32;
1794 atexit_chain
= (func_ptr
*) realloc (atexit_chain
, atexit_chain_length
1795 * sizeof (func_ptr
));
1797 atexit_chain
= (func_ptr
*) malloc (atexit_chain_length
1798 * sizeof (func_ptr
));
1801 atexit_chain_length
= 0;
1802 last_atexit_chain_slot
= -1;
1807 atexit_chain
[last_atexit_chain_slot
] = func
;
1811 extern void _cleanup (void);
1812 extern void _exit (int) __attribute__ ((__noreturn__
));
1819 for ( ; last_atexit_chain_slot
-- >= 0; )
1821 (*atexit_chain
[last_atexit_chain_slot
+ 1]) ();
1822 atexit_chain
[last_atexit_chain_slot
+ 1] = 0;
1824 free (atexit_chain
);
1837 /* Simple; we just need a wrapper for ON_EXIT. */
1839 atexit (func_ptr func
)
1841 return ON_EXIT (func
);
1844 #endif /* ON_EXIT */
1845 #endif /* NEED_ATEXIT */