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 /* Work out the largest "word" size that we can deal with on this target. */
48 #if MIN_UNITS_PER_WORD > 4
49 # define LIBGCC2_MAX_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_MAX_UNITS_PER_WORD 4
54 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
57 /* Work out what word size we are using for this compilation.
58 The value can be set on the command line. */
59 #ifndef LIBGCC2_UNITS_PER_WORD
60 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
63 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
67 #ifdef DECLARE_LIBRARY_RENAMES
68 DECLARE_LIBRARY_RENAMES
71 #if defined (L_negdi2)
75 const DWunion uu
= {.ll
= u
};
76 const DWunion w
= { {.low
= -uu
.s
.low
,
77 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
85 __addvSI3 (Wtype a
, Wtype b
)
87 const Wtype w
= a
+ b
;
89 if (b
>= 0 ? w
< a
: w
> a
)
94 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
96 __addvsi3 (SItype a
, SItype b
)
98 const SItype w
= a
+ b
;
100 if (b
>= 0 ? w
< a
: w
> a
)
105 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
110 __addvDI3 (DWtype a
, DWtype b
)
112 const DWtype w
= a
+ b
;
114 if (b
>= 0 ? w
< a
: w
> a
)
123 __subvSI3 (Wtype a
, Wtype b
)
125 const Wtype w
= a
- b
;
127 if (b
>= 0 ? w
> a
: w
< a
)
132 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
134 __subvsi3 (SItype a
, SItype b
)
136 const SItype w
= a
- b
;
138 if (b
>= 0 ? w
> a
: w
< a
)
143 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
148 __subvDI3 (DWtype a
, DWtype b
)
150 const DWtype w
= a
- b
;
152 if (b
>= 0 ? w
> a
: w
< a
)
161 __mulvSI3 (Wtype a
, Wtype b
)
163 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
165 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
170 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
172 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
174 __mulvsi3 (SItype a
, SItype b
)
176 const DItype w
= (DItype
) a
* (DItype
) b
;
178 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
183 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
192 if (a
>= 0 ? w
> 0 : w
< 0)
197 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
203 if (a
>= 0 ? w
> 0 : w
< 0)
208 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
217 if (a
>= 0 ? w
> 0 : w
< 0)
242 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
260 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
285 __mulvDI3 (DWtype u
, DWtype v
)
287 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
288 but the checked multiplication needs only two. */
289 const DWunion uu
= {.ll
= u
};
290 const DWunion vv
= {.ll
= v
};
292 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
294 /* u fits in a single Wtype. */
295 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
297 /* v fits in a single Wtype as well. */
298 /* A single multiplication. No overflow risk. */
299 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
303 /* Two multiplications. */
304 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
305 * (UDWtype
) (UWtype
) vv
.s
.low
};
306 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
307 * (UDWtype
) (UWtype
) vv
.s
.high
};
310 w1
.s
.high
-= uu
.s
.low
;
313 w1
.ll
+= (UWtype
) w0
.s
.high
;
314 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
316 w0
.s
.high
= w1
.s
.low
;
323 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
325 /* v fits into a single Wtype. */
326 /* Two multiplications. */
327 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
328 * (UDWtype
) (UWtype
) vv
.s
.low
};
329 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
330 * (UDWtype
) (UWtype
) vv
.s
.low
};
333 w1
.s
.high
-= vv
.s
.low
;
336 w1
.ll
+= (UWtype
) w0
.s
.high
;
337 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
339 w0
.s
.high
= w1
.s
.low
;
345 /* A few sign checks and a single multiplication. */
350 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
352 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
353 * (UDWtype
) (UWtype
) vv
.s
.low
;
354 if (__builtin_expect (w
>= 0, 1))
360 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
362 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
363 * (UDWtype
) (UWtype
) vv
.s
.low
};
365 ww
.s
.high
-= uu
.s
.low
;
366 if (__builtin_expect (ww
.s
.high
< 0, 1))
375 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
377 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
378 * (UDWtype
) (UWtype
) vv
.s
.low
};
380 ww
.s
.high
-= vv
.s
.low
;
381 if (__builtin_expect (ww
.s
.high
< 0, 1))
387 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
389 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
390 * (UDWtype
) (UWtype
) vv
.s
.low
};
392 ww
.s
.high
-= uu
.s
.low
;
393 ww
.s
.high
-= vv
.s
.low
;
394 if (__builtin_expect (ww
.s
.high
>= 0, 1))
408 /* Unless shift functions are defined with full ANSI prototypes,
409 parameter b will be promoted to int if word_type is smaller than an int. */
412 __lshrdi3 (DWtype u
, word_type b
)
417 const DWunion uu
= {.ll
= u
};
418 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
424 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
428 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
430 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
431 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
440 __ashldi3 (DWtype u
, word_type b
)
445 const DWunion uu
= {.ll
= u
};
446 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
452 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
456 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
458 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
459 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
468 __ashrdi3 (DWtype u
, word_type b
)
473 const DWunion uu
= {.ll
= u
};
474 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
479 /* w.s.high = 1..1 or 0..0 */
480 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
481 w
.s
.low
= uu
.s
.high
>> -bm
;
485 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
487 w
.s
.high
= uu
.s
.high
>> b
;
488 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
497 __bswapsi2 (SItype u
)
499 return ((((u
) & 0xff000000) >> 24)
500 | (((u
) & 0x00ff0000) >> 8)
501 | (((u
) & 0x0000ff00) << 8)
502 | (((u
) & 0x000000ff) << 24));
507 __bswapdi2 (DItype u
)
509 return ((((u
) & 0xff00000000000000ull
) >> 56)
510 | (((u
) & 0x00ff000000000000ull
) >> 40)
511 | (((u
) & 0x0000ff0000000000ull
) >> 24)
512 | (((u
) & 0x000000ff00000000ull
) >> 8)
513 | (((u
) & 0x00000000ff000000ull
) << 8)
514 | (((u
) & 0x0000000000ff0000ull
) << 24)
515 | (((u
) & 0x000000000000ff00ull
) << 40)
516 | (((u
) & 0x00000000000000ffull
) << 56));
529 count_trailing_zeros (count
, u
);
539 const DWunion uu
= {.ll
= u
};
540 UWtype word
, count
, add
;
543 word
= uu
.s
.low
, add
= 0;
544 else if (uu
.s
.high
!= 0)
545 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
549 count_trailing_zeros (count
, word
);
550 return count
+ add
+ 1;
556 __muldi3 (DWtype u
, DWtype v
)
558 const DWunion uu
= {.ll
= u
};
559 const DWunion vv
= {.ll
= v
};
560 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
562 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
563 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
569 #if (defined (L_udivdi3) || defined (L_divdi3) || \
570 defined (L_umoddi3) || defined (L_moddi3))
571 #if defined (sdiv_qrnnd)
572 #define L_udiv_w_sdiv
577 #if defined (sdiv_qrnnd)
578 #if (defined (L_udivdi3) || defined (L_divdi3) || \
579 defined (L_umoddi3) || defined (L_moddi3))
580 static inline __attribute__ ((__always_inline__
))
583 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
590 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
592 /* Dividend, divisor, and quotient are nonnegative. */
593 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
597 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
598 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
599 /* Divide (c1*2^32 + c0) by d. */
600 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
601 /* Add 2^31 to quotient. */
602 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
607 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
608 c1
= a1
>> 1; /* A/2 */
609 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
611 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
613 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
615 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
632 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
635 c0
= ~c0
; /* logical NOT */
637 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
639 q
= ~q
; /* (A/2)/b1 */
642 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
660 else /* Implies c1 = b1 */
661 { /* Hence a1 = d - 1 = 2*b1 - 1 */
679 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
681 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
682 UWtype a1
__attribute__ ((__unused__
)),
683 UWtype a0
__attribute__ ((__unused__
)),
684 UWtype d
__attribute__ ((__unused__
)))
691 #if (defined (L_udivdi3) || defined (L_divdi3) || \
692 defined (L_umoddi3) || defined (L_moddi3))
697 const UQItype __clz_tab
[256] =
699 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,
700 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,
701 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,
702 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,
703 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,
704 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,
705 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,
706 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
717 count_leading_zeros (ret
, x
);
728 const DWunion uu
= {.ll
= x
};
733 word
= uu
.s
.high
, add
= 0;
735 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
737 count_leading_zeros (ret
, word
);
749 count_trailing_zeros (ret
, x
);
760 const DWunion uu
= {.ll
= x
};
765 word
= uu
.s
.low
, add
= 0;
767 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
769 count_trailing_zeros (ret
, word
);
774 #ifdef L_popcount_tab
775 const UQItype __popcount_tab
[256] =
777 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,
778 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,
779 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,
780 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,
781 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,
782 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,
783 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,
784 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
791 __popcountSI2 (UWtype x
)
795 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
796 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
805 __popcountDI2 (UDWtype x
)
809 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
810 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
819 __paritySI2 (UWtype x
)
822 # error "fill out the table"
833 return (0x6996 >> x
) & 1;
840 __parityDI2 (UDWtype x
)
842 const DWunion uu
= {.ll
= x
};
843 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
846 # error "fill out the table"
857 return (0x6996 >> nx
) & 1;
863 #if (defined (L_udivdi3) || defined (L_divdi3) || \
864 defined (L_umoddi3) || defined (L_moddi3))
865 static inline __attribute__ ((__always_inline__
))
868 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
870 const DWunion nn
= {.ll
= n
};
871 const DWunion dd
= {.ll
= d
};
873 UWtype d0
, d1
, n0
, n1
, n2
;
882 #if !UDIV_NEEDS_NORMALIZATION
889 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
892 /* Remainder in n0. */
899 d0
= 1 / d0
; /* Divide intentionally by zero. */
901 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
902 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
904 /* Remainder in n0. */
915 #else /* UDIV_NEEDS_NORMALIZATION */
923 count_leading_zeros (bm
, d0
);
927 /* Normalize, i.e. make the most significant bit of the
931 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
935 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
938 /* Remainder in n0 >> bm. */
945 d0
= 1 / d0
; /* Divide intentionally by zero. */
947 count_leading_zeros (bm
, d0
);
951 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
952 conclude (the most significant bit of n1 is set) /\ (the
953 leading quotient digit q1 = 1).
955 This special case is necessary, not an optimization.
956 (Shifts counts of W_TYPE_SIZE are undefined.) */
965 b
= W_TYPE_SIZE
- bm
;
969 n1
= (n1
<< bm
) | (n0
>> b
);
972 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
977 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
979 /* Remainder in n0 >> bm. */
989 #endif /* UDIV_NEEDS_NORMALIZATION */
1000 /* Remainder in n1n0. */
1012 count_leading_zeros (bm
, d1
);
1015 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1016 conclude (the most significant bit of n1 is set) /\ (the
1017 quotient digit q0 = 0 or 1).
1019 This special case is necessary, not an optimization. */
1021 /* The condition on the next line takes advantage of that
1022 n1 >= d1 (true due to program flow). */
1023 if (n1
> d1
|| n0
>= d0
)
1026 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1045 b
= W_TYPE_SIZE
- bm
;
1047 d1
= (d1
<< bm
) | (d0
>> b
);
1050 n1
= (n1
<< bm
) | (n0
>> b
);
1053 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1054 umul_ppmm (m1
, m0
, q0
, d0
);
1056 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1059 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1064 /* Remainder in (n1n0 - m1m0) >> bm. */
1067 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1068 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1069 rr
.s
.high
= n1
>> bm
;
1076 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1083 __divdi3 (DWtype u
, DWtype v
)
1086 DWunion uu
= {.ll
= u
};
1087 DWunion vv
= {.ll
= v
};
1097 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1107 __moddi3 (DWtype u
, DWtype v
)
1110 DWunion uu
= {.ll
= u
};
1111 DWunion vv
= {.ll
= v
};
1120 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1130 __umoddi3 (UDWtype u
, UDWtype v
)
1134 (void) __udivmoddi4 (u
, v
, &w
);
1142 __udivdi3 (UDWtype n
, UDWtype d
)
1144 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1150 __cmpdi2 (DWtype a
, DWtype b
)
1152 const DWunion au
= {.ll
= a
};
1153 const DWunion bu
= {.ll
= b
};
1155 if (au
.s
.high
< bu
.s
.high
)
1157 else if (au
.s
.high
> bu
.s
.high
)
1159 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1161 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1169 __ucmpdi2 (DWtype a
, DWtype b
)
1171 const DWunion au
= {.ll
= a
};
1172 const DWunion bu
= {.ll
= b
};
1174 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1176 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1178 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1180 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1186 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1188 __fixunstfDI (TFtype a
)
1193 /* Compute high word of result, as a flonum. */
1194 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1195 /* Convert that to fixed (but not to DWtype!),
1196 and shift it into the high word. */
1197 UDWtype v
= (UWtype
) b
;
1199 /* Remove high part from the TFtype, leaving the low part as flonum. */
1201 /* Convert that to fixed (but not to DWtype!) and add it in.
1202 Sometimes A comes out negative. This is significant, since
1203 A has more bits than a long int does. */
1205 v
-= (UWtype
) (- a
);
1212 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1214 __fixtfdi (TFtype a
)
1217 return - __fixunstfDI (-a
);
1218 return __fixunstfDI (a
);
1222 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1224 __fixunsxfDI (XFtype a
)
1229 /* Compute high word of result, as a flonum. */
1230 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1231 /* Convert that to fixed (but not to DWtype!),
1232 and shift it into the high word. */
1233 UDWtype v
= (UWtype
) b
;
1235 /* Remove high part from the XFtype, leaving the low part as flonum. */
1237 /* Convert that to fixed (but not to DWtype!) and add it in.
1238 Sometimes A comes out negative. This is significant, since
1239 A has more bits than a long int does. */
1241 v
-= (UWtype
) (- a
);
1248 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1250 __fixxfdi (XFtype a
)
1253 return - __fixunsxfDI (-a
);
1254 return __fixunsxfDI (a
);
1258 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1260 __fixunsdfDI (DFtype a
)
1262 /* Get high part of result. The division here will just moves the radix
1263 point and will not cause any rounding. Then the conversion to integral
1264 type chops result as desired. */
1265 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1267 /* Get low part of result. Convert `hi' to floating type and scale it back,
1268 then subtract this from the number being converted. This leaves the low
1269 part. Convert that to integral type. */
1270 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1272 /* Assemble result from the two parts. */
1273 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1277 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1279 __fixdfdi (DFtype a
)
1282 return - __fixunsdfDI (-a
);
1283 return __fixunsdfDI (a
);
1287 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1289 __fixunssfDI (SFtype a
)
1291 #if LIBGCC2_HAS_DF_MODE
1292 /* Convert the SFtype to a DFtype, because that is surely not going
1293 to lose any bits. Some day someone else can write a faster version
1294 that avoids converting to DFtype, and verify it really works right. */
1295 const DFtype dfa
= a
;
1297 /* Get high part of result. The division here will just moves the radix
1298 point and will not cause any rounding. Then the conversion to integral
1299 type chops result as desired. */
1300 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1302 /* Get low part of result. Convert `hi' to floating type and scale it back,
1303 then subtract this from the number being converted. This leaves the low
1304 part. Convert that to integral type. */
1305 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1307 /* Assemble result from the two parts. */
1308 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1309 #elif FLT_MANT_DIG < W_TYPE_SIZE
1312 if (a
< Wtype_MAXp1_F
)
1314 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1316 /* Since we know that there are fewer significant bits in the SFmode
1317 quantity than in a word, we know that we can convert out all the
1318 significant bits in one step, and thus avoid losing bits. */
1320 /* ??? This following loop essentially performs frexpf. If we could
1321 use the real libm function, or poke at the actual bits of the fp
1322 format, it would be significantly faster. */
1324 UWtype shift
= 0, counter
;
1328 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1330 SFtype counterf
= (UWtype
)1 << counter
;
1338 /* Rescale into the range of one word, extract the bits of that
1339 one word, and shift the result into position. */
1342 return (DWtype
)counter
<< shift
;
1351 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1353 __fixsfdi (SFtype a
)
1356 return - __fixunssfDI (-a
);
1357 return __fixunssfDI (a
);
1361 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1363 __floatdixf (DWtype u
)
1365 #if W_TYPE_SIZE > XF_SIZE
1368 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1375 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1377 __floatundixf (UDWtype u
)
1379 #if W_TYPE_SIZE > XF_SIZE
1382 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1389 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1391 __floatditf (DWtype u
)
1393 #if W_TYPE_SIZE > TF_SIZE
1396 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1403 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1405 __floatunditf (UDWtype u
)
1407 #if W_TYPE_SIZE > TF_SIZE
1410 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1417 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1418 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1419 #define DI_SIZE (W_TYPE_SIZE * 2)
1420 #define F_MODE_OK(SIZE) \
1422 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1423 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1424 The conversion from long double to float suffers from double \
1425 rounding, because we convert via double. In any case, the \
1426 fallback code is faster. */ \
1427 && !IS_IBM_EXTENDED (SIZE))
1428 #if defined(L_floatdisf)
1429 #define FUNC __floatdisf
1430 #define FSTYPE SFtype
1431 #define FSSIZE SF_SIZE
1433 #define FUNC __floatdidf
1434 #define FSTYPE DFtype
1435 #define FSSIZE DF_SIZE
1441 #if FSSIZE >= W_TYPE_SIZE
1442 /* When the word size is small, we never get any rounding error. */
1443 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1447 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1448 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1449 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1451 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1452 # define FSIZE DF_SIZE
1453 # define FTYPE DFtype
1454 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1455 # define FSIZE XF_SIZE
1456 # define FTYPE XFtype
1457 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1458 # define FSIZE TF_SIZE
1459 # define FTYPE TFtype
1464 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1466 /* Protect against double-rounding error.
1467 Represent any low-order bits, that might be truncated by a bit that
1468 won't be lost. The bit can go in anywhere below the rounding position
1469 of the FSTYPE. A fixed mask and bit position handles all usual
1471 if (! (- ((DWtype
) 1 << FSIZE
) < u
1472 && u
< ((DWtype
) 1 << FSIZE
)))
1474 if ((UDWtype
) u
& (REP_BIT
- 1))
1476 u
&= ~ (REP_BIT
- 1);
1481 /* Do the calculation in a wider type so that we don't lose any of
1482 the precision of the high word while multiplying it. */
1483 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1488 #if FSSIZE >= W_TYPE_SIZE - 2
1491 /* Finally, the word size is larger than the number of bits in the
1492 required FSTYPE, and we've got no suitable wider type. The only
1493 way to avoid double rounding is to special case the
1496 /* If there are no high bits set, fall back to one conversion. */
1498 return (FSTYPE
)(Wtype
)u
;
1500 /* Otherwise, find the power of two. */
1501 Wtype hi
= u
>> W_TYPE_SIZE
;
1505 UWtype count
, shift
;
1506 count_leading_zeros (count
, hi
);
1508 /* No leading bits means u == minimum. */
1510 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1512 shift
= 1 + W_TYPE_SIZE
- count
;
1514 /* Shift down the most significant bits. */
1517 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1518 if (u
& (((DWtype
)1 << shift
) - 1))
1521 /* Convert the one word of data, and rescale. */
1523 f
*= (UDWtype
)1 << shift
;
1529 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1530 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1531 #define DI_SIZE (W_TYPE_SIZE * 2)
1532 #define F_MODE_OK(SIZE) \
1534 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1535 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1536 The conversion from long double to float suffers from double \
1537 rounding, because we convert via double. In any case, the \
1538 fallback code is faster. */ \
1539 && !IS_IBM_EXTENDED (SIZE))
1540 #if defined(L_floatundisf)
1541 #define FUNC __floatundisf
1542 #define FSTYPE SFtype
1543 #define FSSIZE SF_SIZE
1545 #define FUNC __floatundidf
1546 #define FSTYPE DFtype
1547 #define FSSIZE DF_SIZE
1553 #if FSSIZE >= W_TYPE_SIZE
1554 /* When the word size is small, we never get any rounding error. */
1555 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1559 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1560 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1561 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1563 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1564 # define FSIZE DF_SIZE
1565 # define FTYPE DFtype
1566 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1567 # define FSIZE XF_SIZE
1568 # define FTYPE XFtype
1569 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1570 # define FSIZE TF_SIZE
1571 # define FTYPE TFtype
1576 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1578 /* Protect against double-rounding error.
1579 Represent any low-order bits, that might be truncated by a bit that
1580 won't be lost. The bit can go in anywhere below the rounding position
1581 of the FSTYPE. A fixed mask and bit position handles all usual
1583 if (u
>= ((UDWtype
) 1 << FSIZE
))
1585 if ((UDWtype
) u
& (REP_BIT
- 1))
1587 u
&= ~ (REP_BIT
- 1);
1592 /* Do the calculation in a wider type so that we don't lose any of
1593 the precision of the high word while multiplying it. */
1594 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1599 #if FSSIZE == W_TYPE_SIZE - 1
1602 /* Finally, the word size is larger than the number of bits in the
1603 required FSTYPE, and we've got no suitable wider type. The only
1604 way to avoid double rounding is to special case the
1607 /* If there are no high bits set, fall back to one conversion. */
1609 return (FSTYPE
)(UWtype
)u
;
1611 /* Otherwise, find the power of two. */
1612 UWtype hi
= u
>> W_TYPE_SIZE
;
1614 UWtype count
, shift
;
1615 count_leading_zeros (count
, hi
);
1617 shift
= W_TYPE_SIZE
- count
;
1619 /* Shift down the most significant bits. */
1622 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1623 if (u
& (((UDWtype
)1 << shift
) - 1))
1626 /* Convert the one word of data, and rescale. */
1628 f
*= (UDWtype
)1 << shift
;
1634 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1635 /* Reenable the normal types, in case limits.h needs them. */
1648 __fixunsxfSI (XFtype a
)
1650 if (a
>= - (DFtype
) Wtype_MIN
)
1651 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1656 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1657 /* Reenable the normal types, in case limits.h needs them. */
1670 __fixunsdfSI (DFtype a
)
1672 if (a
>= - (DFtype
) Wtype_MIN
)
1673 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1678 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1679 /* Reenable the normal types, in case limits.h needs them. */
1692 __fixunssfSI (SFtype a
)
1694 if (a
>= - (SFtype
) Wtype_MIN
)
1695 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1700 /* Integer power helper used from __builtin_powi for non-constant
1703 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1704 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1705 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1706 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1707 # if defined(L_powisf2)
1708 # define TYPE SFtype
1709 # define NAME __powisf2
1710 # elif defined(L_powidf2)
1711 # define TYPE DFtype
1712 # define NAME __powidf2
1713 # elif defined(L_powixf2)
1714 # define TYPE XFtype
1715 # define NAME __powixf2
1716 # elif defined(L_powitf2)
1717 # define TYPE TFtype
1718 # define NAME __powitf2
1724 NAME (TYPE x
, int m
)
1726 unsigned int n
= m
< 0 ? -m
: m
;
1727 TYPE y
= n
% 2 ? x
: 1;
1734 return m
< 0 ? 1/y
: y
;
1739 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1740 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1741 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1742 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1748 #if defined(L_mulsc3) || defined(L_divsc3)
1749 # define MTYPE SFtype
1750 # define CTYPE SCtype
1753 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1754 #elif defined(L_muldc3) || defined(L_divdc3)
1755 # define MTYPE DFtype
1756 # define CTYPE DCtype
1758 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1763 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1765 #elif defined(L_mulxc3) || defined(L_divxc3)
1766 # define MTYPE XFtype
1767 # define CTYPE XCtype
1771 #elif defined(L_multc3) || defined(L_divtc3)
1772 # define MTYPE TFtype
1773 # define CTYPE TCtype
1781 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1782 #define _CONCAT3(A,B,C) A##B##C
1784 #define CONCAT2(A,B) _CONCAT2(A,B)
1785 #define _CONCAT2(A,B) A##B
1787 /* All of these would be present in a full C99 implementation of <math.h>
1788 and <complex.h>. Our problem is that only a few systems have such full
1789 implementations. Further, libgcc_s.so isn't currently linked against
1790 libm.so, and even for systems that do provide full C99, the extra overhead
1791 of all programs using libgcc having to link against libm. So avoid it. */
1793 #define isnan(x) __builtin_expect ((x) != (x), 0)
1794 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1795 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1797 #define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1800 /* Helpers to make the following code slightly less gross. */
1801 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1802 #define FABS CONCAT2(__builtin_fabs, CEXT)
1804 /* Verify that MTYPE matches up with CEXT. */
1805 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1807 /* Ensure that we've lost any extra precision. */
1811 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1814 #if defined(L_mulsc3) || defined(L_muldc3) \
1815 || defined(L_mulxc3) || defined(L_multc3)
1818 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1820 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1835 if (isnan (x
) && isnan (y
))
1837 /* Recover infinities that computed as NaN + iNaN. */
1839 if (isinf (a
) || isinf (b
))
1841 /* z is infinite. "Box" the infinity and change NaNs in
1842 the other factor to 0. */
1843 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1844 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1845 if (isnan (c
)) c
= COPYSIGN (0, c
);
1846 if (isnan (d
)) d
= COPYSIGN (0, d
);
1849 if (isinf (c
) || isinf (d
))
1851 /* w is infinite. "Box" the infinity and change NaNs in
1852 the other factor to 0. */
1853 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1854 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1855 if (isnan (a
)) a
= COPYSIGN (0, a
);
1856 if (isnan (b
)) b
= COPYSIGN (0, b
);
1860 && (isinf (ac
) || isinf (bd
)
1861 || isinf (ad
) || isinf (bc
)))
1863 /* Recover infinities from overflow by changing NaNs to 0. */
1864 if (isnan (a
)) a
= COPYSIGN (0, a
);
1865 if (isnan (b
)) b
= COPYSIGN (0, b
);
1866 if (isnan (c
)) c
= COPYSIGN (0, c
);
1867 if (isnan (d
)) d
= COPYSIGN (0, d
);
1872 x
= INFINITY
* (a
* c
- b
* d
);
1873 y
= INFINITY
* (a
* d
+ b
* c
);
1879 #endif /* complex multiply */
1881 #if defined(L_divsc3) || defined(L_divdc3) \
1882 || defined(L_divxc3) || defined(L_divtc3)
1885 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1887 MTYPE denom
, ratio
, x
, y
;
1889 /* ??? We can get better behavior from logarithmic scaling instead of
1890 the division. But that would mean starting to link libgcc against
1891 libm. We could implement something akin to ldexp/frexp as gcc builtins
1893 if (FABS (c
) < FABS (d
))
1896 denom
= (c
* ratio
) + d
;
1897 x
= ((a
* ratio
) + b
) / denom
;
1898 y
= ((b
* ratio
) - a
) / denom
;
1903 denom
= (d
* ratio
) + c
;
1904 x
= ((b
* ratio
) + a
) / denom
;
1905 y
= (b
- (a
* ratio
)) / denom
;
1908 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1909 are nonzero/zero, infinite/finite, and finite/infinite. */
1910 if (isnan (x
) && isnan (y
))
1912 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
1914 x
= COPYSIGN (INFINITY
, c
) * a
;
1915 y
= COPYSIGN (INFINITY
, c
) * b
;
1917 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1919 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1920 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1921 x
= INFINITY
* (a
* c
+ b
* d
);
1922 y
= INFINITY
* (b
* c
- a
* d
);
1924 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1926 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1927 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1928 x
= 0.0 * (a
* c
+ b
* d
);
1929 y
= 0.0 * (b
* c
- a
* d
);
1935 #endif /* complex divide */
1937 #endif /* all complex float routines */
1939 /* From here on down, the routines use normal data types. */
1941 #define SItype bogus_type
1942 #define USItype bogus_type
1943 #define DItype bogus_type
1944 #define UDItype bogus_type
1945 #define SFtype bogus_type
1946 #define DFtype bogus_type
1964 /* Like bcmp except the sign is meaningful.
1965 Result is negative if S1 is less than S2,
1966 positive if S1 is greater, 0 if S1 and S2 are equal. */
1969 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1973 const unsigned char c1
= *s1
++, c2
= *s2
++;
1983 /* __eprintf used to be used by GCC's private version of <assert.h>.
1984 We no longer provide that header, but this routine remains in libgcc.a
1985 for binary backward compatibility. Note that it is not included in
1986 the shared version of libgcc. */
1988 #ifndef inhibit_libc
1990 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1994 __eprintf (const char *string
, const char *expression
,
1995 unsigned int line
, const char *filename
)
1997 fprintf (stderr
, string
, expression
, line
, filename
);
2006 #ifdef L_clear_cache
2007 /* Clear part of an instruction cache. */
2010 __clear_cache (char *beg
__attribute__((__unused__
)),
2011 char *end
__attribute__((__unused__
)))
2013 #ifdef CLEAR_INSN_CACHE
2014 CLEAR_INSN_CACHE (beg
, end
);
2015 #endif /* CLEAR_INSN_CACHE */
2018 #endif /* L_clear_cache */
2020 #ifdef L_enable_execute_stack
2021 /* Attempt to turn on execute permission for the stack. */
2023 #ifdef ENABLE_EXECUTE_STACK
2024 ENABLE_EXECUTE_STACK
2027 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
2029 #endif /* ENABLE_EXECUTE_STACK */
2031 #endif /* L_enable_execute_stack */
2035 /* Jump to a trampoline, loading the static chain address. */
2037 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
2050 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
2054 mprotect (char *addr
, int len
, int prot
)
2071 if (VirtualProtect (addr
, len
, np
, &op
))
2077 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
2079 #ifdef TRANSFER_FROM_TRAMPOLINE
2080 TRANSFER_FROM_TRAMPOLINE
2082 #endif /* L_trampoline */
2087 #include "gbl-ctors.h"
2089 /* Some systems use __main in a way incompatible with its use in gcc, in these
2090 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2091 give the same symbol without quotes for an alternative entry point. You
2092 must define both, or neither. */
2094 #define NAME__MAIN "__main"
2095 #define SYMBOL__MAIN __main
2098 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2099 #undef HAS_INIT_SECTION
2100 #define HAS_INIT_SECTION
2103 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2105 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2106 code to run constructors. In that case, we need to handle EH here, too. */
2108 #ifdef EH_FRAME_SECTION_NAME
2109 #include "unwind-dw2-fde.h"
2110 extern unsigned char __EH_FRAME_BEGIN__
[];
2113 /* Run all the global destructors on exit from the program. */
2116 __do_global_dtors (void)
2118 #ifdef DO_GLOBAL_DTORS_BODY
2119 DO_GLOBAL_DTORS_BODY
;
2121 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2128 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2130 static int completed
= 0;
2134 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2141 #ifndef HAS_INIT_SECTION
2142 /* Run all the global constructors on entry to the program. */
2145 __do_global_ctors (void)
2147 #ifdef EH_FRAME_SECTION_NAME
2149 static struct object object
;
2150 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2153 DO_GLOBAL_CTORS_BODY
;
2154 atexit (__do_global_dtors
);
2156 #endif /* no HAS_INIT_SECTION */
2158 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2159 /* Subroutine called automatically by `main'.
2160 Compiling a global function named `main'
2161 produces an automatic call to this function at the beginning.
2163 For many systems, this routine calls __do_global_ctors.
2164 For systems which support a .init section we use the .init section
2165 to run __do_global_ctors, so we need not do anything here. */
2167 extern void SYMBOL__MAIN (void);
2171 /* Support recursive calls to `main': run initializers just once. */
2172 static int initialized
;
2176 __do_global_ctors ();
2179 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2181 #endif /* L__main */
2182 #endif /* __CYGWIN__ */
2186 #include "gbl-ctors.h"
2188 /* Provide default definitions for the lists of constructors and
2189 destructors, so that we don't get linker errors. These symbols are
2190 intentionally bss symbols, so that gld and/or collect will provide
2191 the right values. */
2193 /* We declare the lists here with two elements each,
2194 so that they are valid empty lists if no other definition is loaded.
2196 If we are using the old "set" extensions to have the gnu linker
2197 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2198 must be in the bss/common section.
2200 Long term no port should use those extensions. But many still do. */
2201 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2202 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2203 func_ptr __CTOR_LIST__
[2] = {0, 0};
2204 func_ptr __DTOR_LIST__
[2] = {0, 0};
2206 func_ptr __CTOR_LIST__
[2];
2207 func_ptr __DTOR_LIST__
[2];
2209 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2210 #endif /* L_ctors */
2211 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */