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, 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "coretypes.h"
37 #ifdef HAVE_GAS_HIDDEN
38 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
40 #define ATTRIBUTE_HIDDEN
43 #ifndef MIN_UNITS_PER_WORD
44 #define MIN_UNITS_PER_WORD UNITS_PER_WORD
47 #ifndef LIBGCC2_UNITS_PER_WORD
48 # if MIN_UNITS_PER_WORD > 4
49 # define LIBGCC2_UNITS_PER_WORD 8
50 # elif (MIN_UNITS_PER_WORD > 2 \
51 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
52 # define LIBGCC2_UNITS_PER_WORD 4
54 # define LIBGCC2_UNITS_PER_WORD MIN_UNITS_PER_WORD
58 #if LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD
62 #ifdef DECLARE_LIBRARY_RENAMES
63 DECLARE_LIBRARY_RENAMES
66 #if defined (L_negdi2)
70 const DWunion uu
= {.ll
= u
};
71 const DWunion w
= { {.low
= -uu
.s
.low
,
72 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
80 __addvSI3 (Wtype a
, Wtype b
)
82 const Wtype w
= a
+ b
;
84 if (b
>= 0 ? w
< a
: w
> a
)
89 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
91 __addvsi3 (SItype a
, SItype b
)
93 const SItype w
= a
+ b
;
95 if (b
>= 0 ? w
< a
: w
> a
)
100 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
105 __addvDI3 (DWtype a
, DWtype b
)
107 const DWtype w
= a
+ b
;
109 if (b
>= 0 ? w
< a
: w
> a
)
118 __subvSI3 (Wtype a
, Wtype b
)
120 const Wtype w
= a
- b
;
122 if (b
>= 0 ? w
> a
: w
< a
)
127 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
129 __subvsi3 (SItype a
, SItype b
)
131 const SItype w
= a
- b
;
133 if (b
>= 0 ? w
> a
: w
< a
)
138 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
143 __subvDI3 (DWtype a
, DWtype b
)
145 const DWtype w
= a
- b
;
147 if (b
>= 0 ? w
> a
: w
< a
)
156 __mulvSI3 (Wtype a
, Wtype b
)
158 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
160 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
165 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
167 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
169 __mulvsi3 (SItype a
, SItype b
)
171 const DItype w
= (DItype
) a
* (DItype
) b
;
173 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
178 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
187 if (a
>= 0 ? w
> 0 : w
< 0)
192 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
198 if (a
>= 0 ? w
> 0 : w
< 0)
203 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
212 if (a
>= 0 ? w
> 0 : w
< 0)
237 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
255 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
280 __mulvDI3 (DWtype u
, DWtype v
)
282 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
283 but the checked multiplication needs only two. */
284 const DWunion uu
= {.ll
= u
};
285 const DWunion vv
= {.ll
= v
};
287 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
289 /* u fits in a single Wtype. */
290 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
292 /* v fits in a single Wtype as well. */
293 /* A single multiplication. No overflow risk. */
294 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
298 /* Two multiplications. */
299 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
300 * (UDWtype
) (UWtype
) vv
.s
.low
};
301 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
302 * (UDWtype
) (UWtype
) vv
.s
.high
};
305 w1
.s
.high
-= uu
.s
.low
;
308 w1
.ll
+= (UWtype
) w0
.s
.high
;
309 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
311 w0
.s
.high
= w1
.s
.low
;
318 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
320 /* v fits into a single Wtype. */
321 /* Two multiplications. */
322 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
323 * (UDWtype
) (UWtype
) vv
.s
.low
};
324 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
325 * (UDWtype
) (UWtype
) vv
.s
.low
};
328 w1
.s
.high
-= vv
.s
.low
;
331 w1
.ll
+= (UWtype
) w0
.s
.high
;
332 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
334 w0
.s
.high
= w1
.s
.low
;
340 /* A few sign checks and a single multiplication. */
345 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
347 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
348 * (UDWtype
) (UWtype
) vv
.s
.low
;
349 if (__builtin_expect (w
>= 0, 1))
355 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
357 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
358 * (UDWtype
) (UWtype
) vv
.s
.low
};
360 ww
.s
.high
-= uu
.s
.low
;
361 if (__builtin_expect (ww
.s
.high
< 0, 1))
370 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
372 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
373 * (UDWtype
) (UWtype
) vv
.s
.low
};
375 ww
.s
.high
-= vv
.s
.low
;
376 if (__builtin_expect (ww
.s
.high
< 0, 1))
382 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
384 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
385 * (UDWtype
) (UWtype
) vv
.s
.low
};
387 ww
.s
.high
-= uu
.s
.low
;
388 ww
.s
.high
-= vv
.s
.low
;
389 if (__builtin_expect (ww
.s
.high
>= 0, 1))
403 /* Unless shift functions are defined with full ANSI prototypes,
404 parameter b will be promoted to int if word_type is smaller than an int. */
407 __lshrdi3 (DWtype u
, word_type b
)
412 const DWunion uu
= {.ll
= u
};
413 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
419 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
423 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
425 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
426 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
435 __ashldi3 (DWtype u
, word_type b
)
440 const DWunion uu
= {.ll
= u
};
441 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
447 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
451 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
453 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
454 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
463 __ashrdi3 (DWtype u
, word_type b
)
468 const DWunion uu
= {.ll
= u
};
469 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
474 /* w.s.high = 1..1 or 0..0 */
475 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
476 w
.s
.low
= uu
.s
.high
>> -bm
;
480 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
482 w
.s
.high
= uu
.s
.high
>> b
;
483 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
500 count_trailing_zeros (count
, u
);
510 const DWunion uu
= {.ll
= u
};
511 UWtype word
, count
, add
;
514 word
= uu
.s
.low
, add
= 0;
515 else if (uu
.s
.high
!= 0)
516 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
520 count_trailing_zeros (count
, word
);
521 return count
+ add
+ 1;
527 __muldi3 (DWtype u
, DWtype v
)
529 const DWunion uu
= {.ll
= u
};
530 const DWunion vv
= {.ll
= v
};
531 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
533 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
534 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
540 #if (defined (L_udivdi3) || defined (L_divdi3) || \
541 defined (L_umoddi3) || defined (L_moddi3))
542 #if defined (sdiv_qrnnd)
543 #define L_udiv_w_sdiv
548 #if defined (sdiv_qrnnd)
549 #if (defined (L_udivdi3) || defined (L_divdi3) || \
550 defined (L_umoddi3) || defined (L_moddi3))
551 static inline __attribute__ ((__always_inline__
))
554 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
561 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
563 /* Dividend, divisor, and quotient are nonnegative. */
564 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
568 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
569 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
570 /* Divide (c1*2^32 + c0) by d. */
571 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
572 /* Add 2^31 to quotient. */
573 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
578 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
579 c1
= a1
>> 1; /* A/2 */
580 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
582 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
584 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
586 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
603 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
606 c0
= ~c0
; /* logical NOT */
608 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
610 q
= ~q
; /* (A/2)/b1 */
613 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
631 else /* Implies c1 = b1 */
632 { /* Hence a1 = d - 1 = 2*b1 - 1 */
650 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
652 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
653 UWtype a1
__attribute__ ((__unused__
)),
654 UWtype a0
__attribute__ ((__unused__
)),
655 UWtype d
__attribute__ ((__unused__
)))
662 #if (defined (L_udivdi3) || defined (L_divdi3) || \
663 defined (L_umoddi3) || defined (L_moddi3))
668 const UQItype __clz_tab
[256] =
670 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,
671 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,
672 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,
673 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,
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,
676 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,
677 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
688 count_leading_zeros (ret
, x
);
699 const DWunion uu
= {.ll
= x
};
704 word
= uu
.s
.high
, add
= 0;
706 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
708 count_leading_zeros (ret
, word
);
720 count_trailing_zeros (ret
, x
);
731 const DWunion uu
= {.ll
= x
};
736 word
= uu
.s
.low
, add
= 0;
738 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
740 count_trailing_zeros (ret
, word
);
745 #ifdef L_popcount_tab
746 const UQItype __popcount_tab
[256] =
748 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,
749 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,
750 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,
751 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,
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 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,
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 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
762 __popcountSI2 (UWtype x
)
766 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
767 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
776 __popcountDI2 (UDWtype x
)
780 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
781 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
790 __paritySI2 (UWtype x
)
793 # error "fill out the table"
804 return (0x6996 >> x
) & 1;
811 __parityDI2 (UDWtype x
)
813 const DWunion uu
= {.ll
= x
};
814 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
817 # error "fill out the table"
828 return (0x6996 >> nx
) & 1;
834 #if (defined (L_udivdi3) || defined (L_divdi3) || \
835 defined (L_umoddi3) || defined (L_moddi3))
836 static inline __attribute__ ((__always_inline__
))
839 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
841 const DWunion nn
= {.ll
= n
};
842 const DWunion dd
= {.ll
= d
};
844 UWtype d0
, d1
, n0
, n1
, n2
;
853 #if !UDIV_NEEDS_NORMALIZATION
860 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
863 /* Remainder in n0. */
870 d0
= 1 / d0
; /* Divide intentionally by zero. */
872 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
873 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
875 /* Remainder in n0. */
886 #else /* UDIV_NEEDS_NORMALIZATION */
894 count_leading_zeros (bm
, d0
);
898 /* Normalize, i.e. make the most significant bit of the
902 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
906 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
909 /* Remainder in n0 >> bm. */
916 d0
= 1 / d0
; /* Divide intentionally by zero. */
918 count_leading_zeros (bm
, d0
);
922 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
923 conclude (the most significant bit of n1 is set) /\ (the
924 leading quotient digit q1 = 1).
926 This special case is necessary, not an optimization.
927 (Shifts counts of W_TYPE_SIZE are undefined.) */
936 b
= W_TYPE_SIZE
- bm
;
940 n1
= (n1
<< bm
) | (n0
>> b
);
943 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
948 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
950 /* Remainder in n0 >> bm. */
960 #endif /* UDIV_NEEDS_NORMALIZATION */
971 /* Remainder in n1n0. */
983 count_leading_zeros (bm
, d1
);
986 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
987 conclude (the most significant bit of n1 is set) /\ (the
988 quotient digit q0 = 0 or 1).
990 This special case is necessary, not an optimization. */
992 /* The condition on the next line takes advantage of that
993 n1 >= d1 (true due to program flow). */
994 if (n1
> d1
|| n0
>= d0
)
997 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1016 b
= W_TYPE_SIZE
- bm
;
1018 d1
= (d1
<< bm
) | (d0
>> b
);
1021 n1
= (n1
<< bm
) | (n0
>> b
);
1024 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1025 umul_ppmm (m1
, m0
, q0
, d0
);
1027 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1030 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1035 /* Remainder in (n1n0 - m1m0) >> bm. */
1038 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1039 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1040 rr
.s
.high
= n1
>> bm
;
1047 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1054 __divdi3 (DWtype u
, DWtype v
)
1057 DWunion uu
= {.ll
= u
};
1058 DWunion vv
= {.ll
= v
};
1068 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1078 __moddi3 (DWtype u
, DWtype v
)
1081 DWunion uu
= {.ll
= u
};
1082 DWunion vv
= {.ll
= v
};
1091 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1101 __umoddi3 (UDWtype u
, UDWtype v
)
1105 (void) __udivmoddi4 (u
, v
, &w
);
1113 __udivdi3 (UDWtype n
, UDWtype d
)
1115 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1121 __cmpdi2 (DWtype a
, DWtype b
)
1123 const DWunion au
= {.ll
= a
};
1124 const DWunion bu
= {.ll
= b
};
1126 if (au
.s
.high
< bu
.s
.high
)
1128 else if (au
.s
.high
> bu
.s
.high
)
1130 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1132 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1140 __ucmpdi2 (DWtype a
, DWtype b
)
1142 const DWunion au
= {.ll
= a
};
1143 const DWunion bu
= {.ll
= b
};
1145 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1147 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1149 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1151 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1157 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1159 __fixunstfDI (TFtype a
)
1164 /* Compute high word of result, as a flonum. */
1165 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1166 /* Convert that to fixed (but not to DWtype!),
1167 and shift it into the high word. */
1168 UDWtype v
= (UWtype
) b
;
1170 /* Remove high part from the TFtype, leaving the low part as flonum. */
1172 /* Convert that to fixed (but not to DWtype!) and add it in.
1173 Sometimes A comes out negative. This is significant, since
1174 A has more bits than a long int does. */
1176 v
-= (UWtype
) (- a
);
1183 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1185 __fixtfdi (TFtype a
)
1188 return - __fixunstfDI (-a
);
1189 return __fixunstfDI (a
);
1193 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1195 __fixunsxfDI (XFtype a
)
1200 /* Compute high word of result, as a flonum. */
1201 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1202 /* Convert that to fixed (but not to DWtype!),
1203 and shift it into the high word. */
1204 UDWtype v
= (UWtype
) b
;
1206 /* Remove high part from the XFtype, leaving the low part as flonum. */
1208 /* Convert that to fixed (but not to DWtype!) and add it in.
1209 Sometimes A comes out negative. This is significant, since
1210 A has more bits than a long int does. */
1212 v
-= (UWtype
) (- a
);
1219 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1221 __fixxfdi (XFtype a
)
1224 return - __fixunsxfDI (-a
);
1225 return __fixunsxfDI (a
);
1229 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1231 __fixunsdfDI (DFtype a
)
1233 /* Get high part of result. The division here will just moves the radix
1234 point and will not cause any rounding. Then the conversion to integral
1235 type chops result as desired. */
1236 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1238 /* Get low part of result. Convert `hi' to floating type and scale it back,
1239 then subtract this from the number being converted. This leaves the low
1240 part. Convert that to integral type. */
1241 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1243 /* Assemble result from the two parts. */
1244 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1248 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1250 __fixdfdi (DFtype a
)
1253 return - __fixunsdfDI (-a
);
1254 return __fixunsdfDI (a
);
1258 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1260 __fixunssfDI (SFtype a
)
1262 #if LIBGCC2_HAS_DF_MODE
1263 /* Convert the SFtype to a DFtype, because that is surely not going
1264 to lose any bits. Some day someone else can write a faster version
1265 that avoids converting to DFtype, and verify it really works right. */
1266 const DFtype dfa
= a
;
1268 /* Get high part of result. The division here will just moves the radix
1269 point and will not cause any rounding. Then the conversion to integral
1270 type chops result as desired. */
1271 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1273 /* Get low part of result. Convert `hi' to floating type and scale it back,
1274 then subtract this from the number being converted. This leaves the low
1275 part. Convert that to integral type. */
1276 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1278 /* Assemble result from the two parts. */
1279 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1280 #elif FLT_MANT_DIG < W_TYPE_SIZE
1283 if (a
< Wtype_MAXp1_F
)
1285 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1287 /* Since we know that there are fewer significant bits in the SFmode
1288 quantity than in a word, we know that we can convert out all the
1289 significant bits in one step, and thus avoid losing bits. */
1291 /* ??? This following loop essentially performs frexpf. If we could
1292 use the real libm function, or poke at the actual bits of the fp
1293 format, it would be significantly faster. */
1295 UWtype shift
= 0, counter
;
1299 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1301 SFtype counterf
= (UWtype
)1 << counter
;
1309 /* Rescale into the range of one word, extract the bits of that
1310 one word, and shift the result into position. */
1313 return (DWtype
)counter
<< shift
;
1322 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1324 __fixsfdi (SFtype a
)
1327 return - __fixunssfDI (-a
);
1328 return __fixunssfDI (a
);
1332 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1334 __floatdixf (DWtype u
)
1336 #if W_TYPE_SIZE > XF_SIZE
1339 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1346 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1348 __floatundixf (UDWtype u
)
1350 #if W_TYPE_SIZE > XF_SIZE
1353 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1360 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1362 __floatditf (DWtype u
)
1364 #if W_TYPE_SIZE > TF_SIZE
1367 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1374 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1376 __floatunditf (UDWtype u
)
1378 #if W_TYPE_SIZE > TF_SIZE
1381 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1388 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1389 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1390 #define DI_SIZE (W_TYPE_SIZE * 2)
1391 #define F_MODE_OK(SIZE) \
1393 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1394 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1395 The conversion from long double to float suffers from double \
1396 rounding, because we convert via double. In any case, the \
1397 fallback code is faster. */ \
1398 && !IS_IBM_EXTENDED (SIZE))
1399 #if defined(L_floatdisf)
1400 #define FUNC __floatdisf
1401 #define FSTYPE SFtype
1402 #define FSSIZE SF_SIZE
1404 #define FUNC __floatdidf
1405 #define FSTYPE DFtype
1406 #define FSSIZE DF_SIZE
1412 #if FSSIZE >= W_TYPE_SIZE
1413 /* When the word size is small, we never get any rounding error. */
1414 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1418 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1419 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1420 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1422 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1423 # define FSIZE DF_SIZE
1424 # define FTYPE DFtype
1425 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1426 # define FSIZE XF_SIZE
1427 # define FTYPE XFtype
1428 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1429 # define FSIZE TF_SIZE
1430 # define FTYPE TFtype
1435 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1437 /* Protect against double-rounding error.
1438 Represent any low-order bits, that might be truncated by a bit that
1439 won't be lost. The bit can go in anywhere below the rounding position
1440 of the FSTYPE. A fixed mask and bit position handles all usual
1442 if (! (- ((DWtype
) 1 << FSIZE
) < u
1443 && u
< ((DWtype
) 1 << FSIZE
)))
1445 if ((UDWtype
) u
& (REP_BIT
- 1))
1447 u
&= ~ (REP_BIT
- 1);
1452 /* Do the calculation in a wider type so that we don't lose any of
1453 the precision of the high word while multiplying it. */
1454 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1459 #if FSSIZE >= W_TYPE_SIZE - 2
1462 /* Finally, the word size is larger than the number of bits in the
1463 required FSTYPE, and we've got no suitable wider type. The only
1464 way to avoid double rounding is to special case the
1467 /* If there are no high bits set, fall back to one conversion. */
1469 return (FSTYPE
)(Wtype
)u
;
1471 /* Otherwise, find the power of two. */
1472 Wtype hi
= u
>> W_TYPE_SIZE
;
1476 UWtype count
, shift
;
1477 count_leading_zeros (count
, hi
);
1479 /* No leading bits means u == minimum. */
1481 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1483 shift
= 1 + W_TYPE_SIZE
- count
;
1485 /* Shift down the most significant bits. */
1488 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1489 if (u
& (((DWtype
)1 << shift
) - 1))
1492 /* Convert the one word of data, and rescale. */
1494 f
*= (UDWtype
)1 << shift
;
1500 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1501 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1502 #define DI_SIZE (W_TYPE_SIZE * 2)
1503 #define F_MODE_OK(SIZE) \
1505 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1506 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1507 The conversion from long double to float suffers from double \
1508 rounding, because we convert via double. In any case, the \
1509 fallback code is faster. */ \
1510 && !IS_IBM_EXTENDED (SIZE))
1511 #if defined(L_floatundisf)
1512 #define FUNC __floatundisf
1513 #define FSTYPE SFtype
1514 #define FSSIZE SF_SIZE
1516 #define FUNC __floatundidf
1517 #define FSTYPE DFtype
1518 #define FSSIZE DF_SIZE
1524 #if FSSIZE >= W_TYPE_SIZE
1525 /* When the word size is small, we never get any rounding error. */
1526 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1530 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1531 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1532 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1534 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1535 # define FSIZE DF_SIZE
1536 # define FTYPE DFtype
1537 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1538 # define FSIZE XF_SIZE
1539 # define FTYPE XFtype
1540 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1541 # define FSIZE TF_SIZE
1542 # define FTYPE TFtype
1547 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1549 /* Protect against double-rounding error.
1550 Represent any low-order bits, that might be truncated by a bit that
1551 won't be lost. The bit can go in anywhere below the rounding position
1552 of the FSTYPE. A fixed mask and bit position handles all usual
1554 if (u
>= ((UDWtype
) 1 << FSIZE
))
1556 if ((UDWtype
) u
& (REP_BIT
- 1))
1558 u
&= ~ (REP_BIT
- 1);
1563 /* Do the calculation in a wider type so that we don't lose any of
1564 the precision of the high word while multiplying it. */
1565 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1570 #if FSSIZE == W_TYPE_SIZE - 1
1573 /* Finally, the word size is larger than the number of bits in the
1574 required FSTYPE, and we've got no suitable wider type. The only
1575 way to avoid double rounding is to special case the
1578 /* If there are no high bits set, fall back to one conversion. */
1580 return (FSTYPE
)(UWtype
)u
;
1582 /* Otherwise, find the power of two. */
1583 UWtype hi
= u
>> W_TYPE_SIZE
;
1585 UWtype count
, shift
;
1586 count_leading_zeros (count
, hi
);
1588 shift
= W_TYPE_SIZE
- count
;
1590 /* Shift down the most significant bits. */
1593 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1594 if (u
& (((UDWtype
)1 << shift
) - 1))
1597 /* Convert the one word of data, and rescale. */
1599 f
*= (UDWtype
)1 << shift
;
1605 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1606 /* Reenable the normal types, in case limits.h needs them. */
1619 __fixunsxfSI (XFtype a
)
1621 if (a
>= - (DFtype
) Wtype_MIN
)
1622 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1627 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1628 /* Reenable the normal types, in case limits.h needs them. */
1641 __fixunsdfSI (DFtype a
)
1643 if (a
>= - (DFtype
) Wtype_MIN
)
1644 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1649 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1650 /* Reenable the normal types, in case limits.h needs them. */
1663 __fixunssfSI (SFtype a
)
1665 if (a
>= - (SFtype
) Wtype_MIN
)
1666 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1671 /* Integer power helper used from __builtin_powi for non-constant
1674 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1675 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1676 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1677 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1678 # if defined(L_powisf2)
1679 # define TYPE SFtype
1680 # define NAME __powisf2
1681 # elif defined(L_powidf2)
1682 # define TYPE DFtype
1683 # define NAME __powidf2
1684 # elif defined(L_powixf2)
1685 # define TYPE XFtype
1686 # define NAME __powixf2
1687 # elif defined(L_powitf2)
1688 # define TYPE TFtype
1689 # define NAME __powitf2
1695 NAME (TYPE x
, int m
)
1697 unsigned int n
= m
< 0 ? -m
: m
;
1698 TYPE y
= n
% 2 ? x
: 1;
1705 return m
< 0 ? 1/y
: y
;
1710 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1711 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1712 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1713 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1719 #if defined(L_mulsc3) || defined(L_divsc3)
1720 # define MTYPE SFtype
1721 # define CTYPE SCtype
1724 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1725 #elif defined(L_muldc3) || defined(L_divdc3)
1726 # define MTYPE DFtype
1727 # define CTYPE DCtype
1729 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1734 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1736 #elif defined(L_mulxc3) || defined(L_divxc3)
1737 # define MTYPE XFtype
1738 # define CTYPE XCtype
1742 #elif defined(L_multc3) || defined(L_divtc3)
1743 # define MTYPE TFtype
1744 # define CTYPE TCtype
1752 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1753 #define _CONCAT3(A,B,C) A##B##C
1755 #define CONCAT2(A,B) _CONCAT2(A,B)
1756 #define _CONCAT2(A,B) A##B
1758 /* All of these would be present in a full C99 implementation of <math.h>
1759 and <complex.h>. Our problem is that only a few systems have such full
1760 implementations. Further, libgcc_s.so isn't currently linked against
1761 libm.so, and even for systems that do provide full C99, the extra overhead
1762 of all programs using libgcc having to link against libm. So avoid it. */
1764 #define isnan(x) __builtin_expect ((x) != (x), 0)
1765 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1766 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1768 #define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1771 /* Helpers to make the following code slightly less gross. */
1772 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1773 #define FABS CONCAT2(__builtin_fabs, CEXT)
1775 /* Verify that MTYPE matches up with CEXT. */
1776 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1778 /* Ensure that we've lost any extra precision. */
1782 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1785 #if defined(L_mulsc3) || defined(L_muldc3) \
1786 || defined(L_mulxc3) || defined(L_multc3)
1789 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1791 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1806 if (isnan (x
) && isnan (y
))
1808 /* Recover infinities that computed as NaN + iNaN. */
1810 if (isinf (a
) || isinf (b
))
1812 /* z is infinite. "Box" the infinity and change NaNs in
1813 the other factor to 0. */
1814 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1815 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1816 if (isnan (c
)) c
= COPYSIGN (0, c
);
1817 if (isnan (d
)) d
= COPYSIGN (0, d
);
1820 if (isinf (c
) || isinf (d
))
1822 /* w is infinite. "Box" the infinity and change NaNs in
1823 the other factor to 0. */
1824 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1825 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1826 if (isnan (a
)) a
= COPYSIGN (0, a
);
1827 if (isnan (b
)) b
= COPYSIGN (0, b
);
1831 && (isinf (ac
) || isinf (bd
)
1832 || isinf (ad
) || isinf (bc
)))
1834 /* Recover infinities from overflow by changing NaNs to 0. */
1835 if (isnan (a
)) a
= COPYSIGN (0, a
);
1836 if (isnan (b
)) b
= COPYSIGN (0, b
);
1837 if (isnan (c
)) c
= COPYSIGN (0, c
);
1838 if (isnan (d
)) d
= COPYSIGN (0, d
);
1843 x
= INFINITY
* (a
* c
- b
* d
);
1844 y
= INFINITY
* (a
* d
+ b
* c
);
1850 #endif /* complex multiply */
1852 #if defined(L_divsc3) || defined(L_divdc3) \
1853 || defined(L_divxc3) || defined(L_divtc3)
1856 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1858 MTYPE denom
, ratio
, x
, y
;
1860 /* ??? We can get better behavior from logarithmic scaling instead of
1861 the division. But that would mean starting to link libgcc against
1862 libm. We could implement something akin to ldexp/frexp as gcc builtins
1864 if (FABS (c
) < FABS (d
))
1867 denom
= (c
* ratio
) + d
;
1868 x
= ((a
* ratio
) + b
) / denom
;
1869 y
= ((b
* ratio
) - a
) / denom
;
1874 denom
= (d
* ratio
) + c
;
1875 x
= ((b
* ratio
) + a
) / denom
;
1876 y
= (b
- (a
* ratio
)) / denom
;
1879 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1880 are nonzero/zero, infinite/finite, and finite/infinite. */
1881 if (isnan (x
) && isnan (y
))
1883 if (denom
== 0.0 && (!isnan (a
) || !isnan (b
)))
1885 x
= COPYSIGN (INFINITY
, c
) * a
;
1886 y
= COPYSIGN (INFINITY
, c
) * b
;
1888 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1890 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1891 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1892 x
= INFINITY
* (a
* c
+ b
* d
);
1893 y
= INFINITY
* (b
* c
- a
* d
);
1895 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1897 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1898 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1899 x
= 0.0 * (a
* c
+ b
* d
);
1900 y
= 0.0 * (b
* c
- a
* d
);
1906 #endif /* complex divide */
1908 #endif /* all complex float routines */
1910 /* From here on down, the routines use normal data types. */
1912 #define SItype bogus_type
1913 #define USItype bogus_type
1914 #define DItype bogus_type
1915 #define UDItype bogus_type
1916 #define SFtype bogus_type
1917 #define DFtype bogus_type
1935 /* Like bcmp except the sign is meaningful.
1936 Result is negative if S1 is less than S2,
1937 positive if S1 is greater, 0 if S1 and S2 are equal. */
1940 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1944 const unsigned char c1
= *s1
++, c2
= *s2
++;
1954 /* __eprintf used to be used by GCC's private version of <assert.h>.
1955 We no longer provide that header, but this routine remains in libgcc.a
1956 for binary backward compatibility. Note that it is not included in
1957 the shared version of libgcc. */
1959 #ifndef inhibit_libc
1961 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1965 __eprintf (const char *string
, const char *expression
,
1966 unsigned int line
, const char *filename
)
1968 fprintf (stderr
, string
, expression
, line
, filename
);
1977 #ifdef L_clear_cache
1978 /* Clear part of an instruction cache. */
1981 __clear_cache (char *beg
__attribute__((__unused__
)),
1982 char *end
__attribute__((__unused__
)))
1984 #ifdef CLEAR_INSN_CACHE
1985 CLEAR_INSN_CACHE (beg
, end
);
1986 #endif /* CLEAR_INSN_CACHE */
1989 #endif /* L_clear_cache */
1991 #ifdef L_enable_execute_stack
1992 /* Attempt to turn on execute permission for the stack. */
1994 #ifdef ENABLE_EXECUTE_STACK
1995 ENABLE_EXECUTE_STACK
1998 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
2000 #endif /* ENABLE_EXECUTE_STACK */
2002 #endif /* L_enable_execute_stack */
2006 /* Jump to a trampoline, loading the static chain address. */
2008 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
2021 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
2025 mprotect (char *addr
, int len
, int prot
)
2042 if (VirtualProtect (addr
, len
, np
, &op
))
2048 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
2050 #ifdef TRANSFER_FROM_TRAMPOLINE
2051 TRANSFER_FROM_TRAMPOLINE
2053 #endif /* L_trampoline */
2058 #include "gbl-ctors.h"
2060 /* Some systems use __main in a way incompatible with its use in gcc, in these
2061 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2062 give the same symbol without quotes for an alternative entry point. You
2063 must define both, or neither. */
2065 #define NAME__MAIN "__main"
2066 #define SYMBOL__MAIN __main
2069 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2070 #undef HAS_INIT_SECTION
2071 #define HAS_INIT_SECTION
2074 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2076 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2077 code to run constructors. In that case, we need to handle EH here, too. */
2079 #ifdef EH_FRAME_SECTION_NAME
2080 #include "unwind-dw2-fde.h"
2081 extern unsigned char __EH_FRAME_BEGIN__
[];
2084 /* Run all the global destructors on exit from the program. */
2087 __do_global_dtors (void)
2089 #ifdef DO_GLOBAL_DTORS_BODY
2090 DO_GLOBAL_DTORS_BODY
;
2092 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2099 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2101 static int completed
= 0;
2105 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2112 #ifndef HAS_INIT_SECTION
2113 /* Run all the global constructors on entry to the program. */
2116 __do_global_ctors (void)
2118 #ifdef EH_FRAME_SECTION_NAME
2120 static struct object object
;
2121 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2124 DO_GLOBAL_CTORS_BODY
;
2125 atexit (__do_global_dtors
);
2127 #endif /* no HAS_INIT_SECTION */
2129 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2130 /* Subroutine called automatically by `main'.
2131 Compiling a global function named `main'
2132 produces an automatic call to this function at the beginning.
2134 For many systems, this routine calls __do_global_ctors.
2135 For systems which support a .init section we use the .init section
2136 to run __do_global_ctors, so we need not do anything here. */
2138 extern void SYMBOL__MAIN (void);
2142 /* Support recursive calls to `main': run initializers just once. */
2143 static int initialized
;
2147 __do_global_ctors ();
2150 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2152 #endif /* L__main */
2153 #endif /* __CYGWIN__ */
2157 #include "gbl-ctors.h"
2159 /* Provide default definitions for the lists of constructors and
2160 destructors, so that we don't get linker errors. These symbols are
2161 intentionally bss symbols, so that gld and/or collect will provide
2162 the right values. */
2164 /* We declare the lists here with two elements each,
2165 so that they are valid empty lists if no other definition is loaded.
2167 If we are using the old "set" extensions to have the gnu linker
2168 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2169 must be in the bss/common section.
2171 Long term no port should use those extensions. But many still do. */
2172 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2173 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2174 func_ptr __CTOR_LIST__
[2] = {0, 0};
2175 func_ptr __DTOR_LIST__
[2] = {0, 0};
2177 func_ptr __CTOR_LIST__
[2];
2178 func_ptr __DTOR_LIST__
[2];
2180 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2181 #endif /* L_ctors */
2182 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */