1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
33 /* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
34 supposedly valid even though this is a "target" file. */
35 #include "auto-host.h"
37 /* It is incorrect to include config.h here, because this file is being
38 compiled for the target, and hence definitions concerning only the host
42 #include "coretypes.h"
45 /* Don't use `fancy_abort' here even if config.h says to use it. */
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
53 #define ATTRIBUTE_HIDDEN
58 #ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
62 #if defined (L_negdi2)
66 const DWunion uu
= {.ll
= u
};
67 const DWunion w
= { {.low
= -uu
.s
.low
,
68 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
76 __addvSI3 (Wtype a
, Wtype b
)
78 const Wtype w
= a
+ b
;
80 if (b
>= 0 ? w
< a
: w
> a
)
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
87 __addvsi3 (SItype a
, SItype b
)
89 const SItype w
= a
+ b
;
91 if (b
>= 0 ? w
< a
: w
> a
)
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
101 __addvDI3 (DWtype a
, DWtype b
)
103 const DWtype w
= a
+ b
;
105 if (b
>= 0 ? w
< a
: w
> a
)
114 __subvSI3 (Wtype a
, Wtype b
)
116 const Wtype w
= a
- b
;
118 if (b
>= 0 ? w
> a
: w
< a
)
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
125 __subvsi3 (SItype a
, SItype b
)
127 const SItype w
= a
- b
;
129 if (b
>= 0 ? w
> a
: w
< a
)
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
139 __subvDI3 (DWtype a
, DWtype b
)
141 const DWtype w
= a
- b
;
143 if (b
>= 0 ? w
> a
: w
< a
)
152 __mulvSI3 (Wtype a
, Wtype b
)
154 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
156 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
161 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
163 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
165 __mulvsi3 (SItype a
, SItype b
)
167 const DItype w
= (DItype
) a
* (DItype
) b
;
169 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
174 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
183 if (a
>= 0 ? w
> 0 : w
< 0)
188 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
194 if (a
>= 0 ? w
> 0 : w
< 0)
199 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
208 if (a
>= 0 ? w
> 0 : w
< 0)
233 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
251 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
276 __mulvDI3 (DWtype u
, DWtype v
)
278 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
279 but the checked multiplication needs only two. */
280 const DWunion uu
= {.ll
= u
};
281 const DWunion vv
= {.ll
= v
};
283 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
285 /* u fits in a single Wtype. */
286 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
288 /* v fits in a single Wtype as well. */
289 /* A single multiplication. No overflow risk. */
290 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
294 /* Two multiplications. */
295 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
296 * (UDWtype
) (UWtype
) vv
.s
.low
};
297 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
298 * (UDWtype
) (UWtype
) vv
.s
.high
};
301 w1
.s
.high
-= uu
.s
.low
;
304 w1
.ll
+= (UWtype
) w0
.s
.high
;
305 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
307 w0
.s
.high
= w1
.s
.low
;
314 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
316 /* v fits into a single Wtype. */
317 /* Two multiplications. */
318 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
319 * (UDWtype
) (UWtype
) vv
.s
.low
};
320 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
321 * (UDWtype
) (UWtype
) vv
.s
.low
};
324 w1
.s
.high
-= vv
.s
.low
;
327 w1
.ll
+= (UWtype
) w0
.s
.high
;
328 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
330 w0
.s
.high
= w1
.s
.low
;
336 /* A few sign checks and a single multiplication. */
341 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
343 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
344 * (UDWtype
) (UWtype
) vv
.s
.low
;
345 if (__builtin_expect (w
>= 0, 1))
351 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
353 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
354 * (UDWtype
) (UWtype
) vv
.s
.low
};
356 ww
.s
.high
-= uu
.s
.low
;
357 if (__builtin_expect (ww
.s
.high
< 0, 1))
366 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
368 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
369 * (UDWtype
) (UWtype
) vv
.s
.low
};
371 ww
.s
.high
-= vv
.s
.low
;
372 if (__builtin_expect (ww
.s
.high
< 0, 1))
378 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
380 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
381 * (UDWtype
) (UWtype
) vv
.s
.low
};
383 ww
.s
.high
-= uu
.s
.low
;
384 ww
.s
.high
-= vv
.s
.low
;
385 if (__builtin_expect (ww
.s
.high
>= 0, 1))
399 /* Unless shift functions are defined with full ANSI prototypes,
400 parameter b will be promoted to int if word_type is smaller than an int. */
403 __lshrdi3 (DWtype u
, word_type b
)
408 const DWunion uu
= {.ll
= u
};
409 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
415 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
419 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
421 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
422 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
431 __ashldi3 (DWtype u
, word_type b
)
436 const DWunion uu
= {.ll
= u
};
437 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
443 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
447 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
449 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
450 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
459 __ashrdi3 (DWtype u
, word_type b
)
464 const DWunion uu
= {.ll
= u
};
465 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
470 /* w.s.high = 1..1 or 0..0 */
471 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
472 w
.s
.low
= uu
.s
.high
>> -bm
;
476 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
478 w
.s
.high
= uu
.s
.high
>> b
;
479 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
496 count_trailing_zeros (count
, u
);
506 const DWunion uu
= {.ll
= u
};
507 UWtype word
, count
, add
;
510 word
= uu
.s
.low
, add
= 0;
511 else if (uu
.s
.high
!= 0)
512 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
516 count_trailing_zeros (count
, word
);
517 return count
+ add
+ 1;
523 __muldi3 (DWtype u
, DWtype v
)
525 const DWunion uu
= {.ll
= u
};
526 const DWunion vv
= {.ll
= v
};
527 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
529 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
530 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
536 #if (defined (L_udivdi3) || defined (L_divdi3) || \
537 defined (L_umoddi3) || defined (L_moddi3))
538 #if defined (sdiv_qrnnd)
539 #define L_udiv_w_sdiv
544 #if defined (sdiv_qrnnd)
545 #if (defined (L_udivdi3) || defined (L_divdi3) || \
546 defined (L_umoddi3) || defined (L_moddi3))
547 static inline __attribute__ ((__always_inline__
))
550 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
557 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
559 /* Dividend, divisor, and quotient are nonnegative. */
560 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
564 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
565 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
566 /* Divide (c1*2^32 + c0) by d. */
567 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
568 /* Add 2^31 to quotient. */
569 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
574 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
575 c1
= a1
>> 1; /* A/2 */
576 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
578 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
580 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
582 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
599 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
602 c0
= ~c0
; /* logical NOT */
604 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
606 q
= ~q
; /* (A/2)/b1 */
609 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
627 else /* Implies c1 = b1 */
628 { /* Hence a1 = d - 1 = 2*b1 - 1 */
646 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
648 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
649 UWtype a1
__attribute__ ((__unused__
)),
650 UWtype a0
__attribute__ ((__unused__
)),
651 UWtype d
__attribute__ ((__unused__
)))
658 #if (defined (L_udivdi3) || defined (L_divdi3) || \
659 defined (L_umoddi3) || defined (L_moddi3))
664 const UQItype __clz_tab
[] =
666 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,
667 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,
668 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,
669 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,
670 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,
671 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,
672 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
673 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
684 count_leading_zeros (ret
, x
);
695 const DWunion uu
= {.ll
= x
};
700 word
= uu
.s
.high
, add
= 0;
702 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
704 count_leading_zeros (ret
, word
);
716 count_trailing_zeros (ret
, x
);
727 const DWunion uu
= {.ll
= x
};
732 word
= uu
.s
.low
, add
= 0;
734 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
736 count_trailing_zeros (ret
, word
);
741 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
742 || defined (L_popcount_tab))
743 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
746 #ifdef L_popcount_tab
747 const UQItype __popcount_tab
[] =
749 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,
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 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,
752 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,
753 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
754 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
755 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,
756 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,
763 __popcountSI2 (UWtype x
)
767 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
768 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
777 __popcountDI2 (UDWtype x
)
781 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
782 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
791 __paritySI2 (UWtype x
)
794 # error "fill out the table"
805 return (0x6996 >> x
) & 1;
812 __parityDI2 (UDWtype x
)
814 const DWunion uu
= {.ll
= x
};
815 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
818 # error "fill out the table"
829 return (0x6996 >> nx
) & 1;
835 #if (defined (L_udivdi3) || defined (L_divdi3) || \
836 defined (L_umoddi3) || defined (L_moddi3))
837 static inline __attribute__ ((__always_inline__
))
840 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
842 const DWunion nn
= {.ll
= n
};
843 const DWunion dd
= {.ll
= d
};
845 UWtype d0
, d1
, n0
, n1
, n2
;
854 #if !UDIV_NEEDS_NORMALIZATION
861 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
864 /* Remainder in n0. */
871 d0
= 1 / d0
; /* Divide intentionally by zero. */
873 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
874 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
876 /* Remainder in n0. */
887 #else /* UDIV_NEEDS_NORMALIZATION */
895 count_leading_zeros (bm
, d0
);
899 /* Normalize, i.e. make the most significant bit of the
903 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
907 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
910 /* Remainder in n0 >> bm. */
917 d0
= 1 / d0
; /* Divide intentionally by zero. */
919 count_leading_zeros (bm
, d0
);
923 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
924 conclude (the most significant bit of n1 is set) /\ (the
925 leading quotient digit q1 = 1).
927 This special case is necessary, not an optimization.
928 (Shifts counts of W_TYPE_SIZE are undefined.) */
937 b
= W_TYPE_SIZE
- bm
;
941 n1
= (n1
<< bm
) | (n0
>> b
);
944 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
949 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
951 /* Remainder in n0 >> bm. */
961 #endif /* UDIV_NEEDS_NORMALIZATION */
972 /* Remainder in n1n0. */
984 count_leading_zeros (bm
, d1
);
987 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
988 conclude (the most significant bit of n1 is set) /\ (the
989 quotient digit q0 = 0 or 1).
991 This special case is necessary, not an optimization. */
993 /* The condition on the next line takes advantage of that
994 n1 >= d1 (true due to program flow). */
995 if (n1
> d1
|| n0
>= d0
)
998 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1017 b
= W_TYPE_SIZE
- bm
;
1019 d1
= (d1
<< bm
) | (d0
>> b
);
1022 n1
= (n1
<< bm
) | (n0
>> b
);
1025 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1026 umul_ppmm (m1
, m0
, q0
, d0
);
1028 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1031 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1036 /* Remainder in (n1n0 - m1m0) >> bm. */
1039 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1040 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1041 rr
.s
.high
= n1
>> bm
;
1048 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1055 __divdi3 (DWtype u
, DWtype v
)
1058 DWunion uu
= {.ll
= u
};
1059 DWunion vv
= {.ll
= v
};
1069 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1079 __moddi3 (DWtype u
, DWtype v
)
1082 DWunion uu
= {.ll
= u
};
1083 DWunion vv
= {.ll
= v
};
1092 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1102 __umoddi3 (UDWtype u
, UDWtype v
)
1106 (void) __udivmoddi4 (u
, v
, &w
);
1114 __udivdi3 (UDWtype n
, UDWtype d
)
1116 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1122 __cmpdi2 (DWtype a
, DWtype b
)
1124 const DWunion au
= {.ll
= a
};
1125 const DWunion bu
= {.ll
= b
};
1127 if (au
.s
.high
< bu
.s
.high
)
1129 else if (au
.s
.high
> bu
.s
.high
)
1131 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1133 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1141 __ucmpdi2 (DWtype a
, DWtype b
)
1143 const DWunion au
= {.ll
= a
};
1144 const DWunion bu
= {.ll
= b
};
1146 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1148 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1150 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1152 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1158 #if defined(L_fixunstfdi) && defined(HAVE_TFMODE)
1160 __fixunstfDI (TFtype a
)
1165 /* Compute high word of result, as a flonum. */
1166 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1167 /* Convert that to fixed (but not to DWtype!),
1168 and shift it into the high word. */
1169 UDWtype v
= (UWtype
) b
;
1171 /* Remove high part from the TFtype, leaving the low part as flonum. */
1173 /* Convert that to fixed (but not to DWtype!) and add it in.
1174 Sometimes A comes out negative. This is significant, since
1175 A has more bits than a long int does. */
1177 v
-= (UWtype
) (- a
);
1184 #if defined(L_fixtfdi) && defined(HAVE_TFMODE)
1186 __fixtfdi (TFtype a
)
1189 return - __fixunstfDI (-a
);
1190 return __fixunstfDI (a
);
1194 #if defined(L_fixunsxfdi) && defined(HAVE_XFMODE)
1196 __fixunsxfDI (XFtype a
)
1201 /* Compute high word of result, as a flonum. */
1202 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1203 /* Convert that to fixed (but not to DWtype!),
1204 and shift it into the high word. */
1205 UDWtype v
= (UWtype
) b
;
1207 /* Remove high part from the XFtype, leaving the low part as flonum. */
1209 /* Convert that to fixed (but not to DWtype!) and add it in.
1210 Sometimes A comes out negative. This is significant, since
1211 A has more bits than a long int does. */
1213 v
-= (UWtype
) (- a
);
1220 #if defined(L_fixxfdi) && defined(HAVE_XFMODE)
1222 __fixxfdi (XFtype a
)
1225 return - __fixunsxfDI (-a
);
1226 return __fixunsxfDI (a
);
1230 #if defined(L_fixunsdfdi) && defined(HAVE_DFMODE)
1232 __fixunsdfDI (DFtype a
)
1234 /* Get high part of result. The division here will just moves the radix
1235 point and will not cause any rounding. Then the conversion to integral
1236 type chops result as desired. */
1237 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1239 /* Get low part of result. Convert `hi' to floating type and scale it back,
1240 then subtract this from the number being converted. This leaves the low
1241 part. Convert that to integral type. */
1242 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1244 /* Assemble result from the two parts. */
1245 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1249 #if defined(L_fixdfdi) && defined(HAVE_DFMODE)
1251 __fixdfdi (DFtype a
)
1254 return - __fixunsdfDI (-a
);
1255 return __fixunsdfDI (a
);
1261 __fixunssfDI (SFtype a
)
1263 #if defined(HAVE_DFMODE)
1264 /* Convert the SFtype to a DFtype, because that is surely not going
1265 to lose any bits. Some day someone else can write a faster version
1266 that avoids converting to DFtype, and verify it really works right. */
1267 const DFtype dfa
= a
;
1269 /* Get high part of result. The division here will just moves the radix
1270 point and will not cause any rounding. Then the conversion to integral
1271 type chops result as desired. */
1272 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1274 /* Get low part of result. Convert `hi' to floating type and scale it back,
1275 then subtract this from the number being converted. This leaves the low
1276 part. Convert that to integral type. */
1277 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1279 /* Assemble result from the two parts. */
1280 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1281 #elif FLT_MANT_DIG < W_TYPE_SIZE
1284 if (a
< Wtype_MAXp1_F
)
1286 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1288 /* Since we know that there are fewer significant bits in the SFmode
1289 quantity than in a word, we know that we can convert out all the
1290 significant bits in one step, and thus avoid losing bits. */
1292 /* ??? This following loop essentially performs frexpf. If we could
1293 use the real libm function, or poke at the actual bits of the fp
1294 format, it would be significantly faster. */
1296 UWtype shift
= 0, counter
;
1300 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1302 SFtype counterf
= (UWtype
)1 << counter
;
1310 /* Rescale into the range of one word, extract the bits of that
1311 one word, and shift the result into position. */
1314 return (DWtype
)counter
<< shift
;
1325 __fixsfdi (SFtype a
)
1328 return - __fixunssfDI (-a
);
1329 return __fixunssfDI (a
);
1333 #if defined(L_floatdixf) && defined(HAVE_XFMODE)
1335 __floatdixf (DWtype u
)
1337 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1344 #if defined(L_floatditf) && defined(HAVE_TFMODE)
1346 __floatditf (DWtype u
)
1348 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1355 #if defined(L_floatdidf) && defined(HAVE_DFMODE)
1357 __floatdidf (DWtype u
)
1359 DFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1367 #define DI_SIZE (W_TYPE_SIZE * 2)
1368 #define SF_SIZE FLT_MANT_DIG
1371 __floatdisf (DWtype u
)
1373 #if SF_SIZE >= W_TYPE_SIZE
1374 /* When the word size is small, we never get any rounding error. */
1375 SFtype f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1379 #elif defined(HAVE_DFMODE)
1381 #if LIBGCC2_DOUBLE_TYPE_SIZE == 64
1382 #define DF_SIZE DBL_MANT_DIG
1383 #elif LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1384 #define DF_SIZE LDBL_MANT_DIG
1389 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1391 /* Protect against double-rounding error.
1392 Represent any low-order bits, that might be truncated by a bit that
1393 won't be lost. The bit can go in anywhere below the rounding position
1394 of the SFmode. A fixed mask and bit position handles all usual
1395 configurations. It doesn't handle the case of 128-bit DImode, however. */
1396 if (DF_SIZE
< DI_SIZE
1397 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1399 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1400 && u
< ((DWtype
) 1 << DF_SIZE
)))
1402 if ((UDWtype
) u
& (REP_BIT
- 1))
1404 u
&= ~ (REP_BIT
- 1);
1410 /* Do the calculation in DFmode so that we don't lose any of the
1411 precision of the high word while multiplying it. */
1412 DFtype f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1417 /* Finally, the word size is larger than the number of bits in SFmode,
1418 and we've got no DFmode. The only way to avoid double rounding is
1419 to special case the extraction. */
1421 /* If there are no high bits set, fall back to one conversion. */
1423 return (SFtype
)(Wtype
)u
;
1425 /* Otherwise, find the power of two. */
1426 Wtype hi
= u
>> W_TYPE_SIZE
;
1430 UWtype count
, shift
;
1431 count_leading_zeros (count
, hi
);
1433 /* No leading bits means u == minimum. */
1435 return -(Wtype_MAXp1_F
* Wtype_MAXp1_F
/ 2);
1437 shift
= W_TYPE_SIZE
- count
;
1439 /* Shift down the most significant bits. */
1442 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1443 if (u
& ((1 << shift
) - 1))
1446 /* Convert the one word of data, and rescale. */
1448 f
*= (UWtype
)1 << shift
;
1454 #if defined(L_fixunsxfsi) && defined(HAVE_XFMODE)
1455 /* Reenable the normal types, in case limits.h needs them. */
1468 __fixunsxfSI (XFtype a
)
1470 if (a
>= - (DFtype
) Wtype_MIN
)
1471 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1476 #if defined(L_fixunsdfsi) && defined(HAVE_DFMODE)
1477 /* Reenable the normal types, in case limits.h needs them. */
1490 __fixunsdfSI (DFtype a
)
1492 if (a
>= - (DFtype
) Wtype_MIN
)
1493 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1499 /* Reenable the normal types, in case limits.h needs them. */
1512 __fixunssfSI (SFtype a
)
1514 if (a
>= - (SFtype
) Wtype_MIN
)
1515 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1520 /* Integer power helper used from __builtin_powi for non-constant
1523 #if defined(L_powisf2) \
1524 || (defined(L_powidf2) && defined(HAVE_DFMODE)) \
1525 || (defined(L_powixf2) && defined(HAVE_XFMODE)) \
1526 || (defined(L_powitf2) && defined(HAVE_TFMODE))
1527 # if defined(L_powisf2)
1528 # define TYPE SFtype
1529 # define NAME __powisf2
1530 # elif defined(L_powidf2)
1531 # define TYPE DFtype
1532 # define NAME __powidf2
1533 # elif defined(L_powixf2)
1534 # define TYPE XFtype
1535 # define NAME __powixf2
1536 # elif defined(L_powitf2)
1537 # define TYPE TFtype
1538 # define NAME __powitf2
1542 NAME (TYPE x
, Wtype m
)
1544 UWtype n
= m
< 0 ? -m
: m
;
1545 TYPE y
= n
% 2 ? x
: 1;
1552 return m
< 0 ? 1/y
: y
;
1557 #if defined(L_mulsc3) || defined(L_divsc3) \
1558 || ((defined(L_muldc3) || defined(L_divdc3)) && defined(HAVE_DFMODE)) \
1559 || ((defined(L_mulxc3) || defined(L_divxc3)) && defined(HAVE_XFMODE)) \
1560 || ((defined(L_multc3) || defined(L_divtc3)) && defined(HAVE_TFMODE))
1566 #if defined(L_mulsc3) || defined(L_divsc3)
1567 # define MTYPE SFtype
1568 # define CTYPE SCtype
1571 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1572 #elif defined(L_muldc3) || defined(L_divdc3)
1573 # define MTYPE DFtype
1574 # define CTYPE DCtype
1576 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1581 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1583 #elif defined(L_mulxc3) || defined(L_divxc3)
1584 # define MTYPE XFtype
1585 # define CTYPE XCtype
1589 #elif defined(L_multc3) || defined(L_divtc3)
1590 # define MTYPE TFtype
1591 # define CTYPE TCtype
1599 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1600 #define _CONCAT3(A,B,C) A##B##C
1602 #define CONCAT2(A,B) _CONCAT2(A,B)
1603 #define _CONCAT2(A,B) A##B
1605 /* All of these would be present in a full C99 implementation of <math.h>
1606 and <complex.h>. Our problem is that only a few systems have such full
1607 implementations. Further, libgcc_s.so isn't currently linked against
1608 libm.so, and even for systems that do provide full C99, the extra overhead
1609 of all programs using libgcc having to link against libm. So avoid it. */
1611 #define isnan(x) __builtin_expect ((x) != (x), 0)
1612 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1613 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1615 #define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1618 /* Helpers to make the following code slightly less gross. */
1619 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1620 #define FABS CONCAT2(__builtin_fabs, CEXT)
1622 /* Verify that MTYPE matches up with CEXT. */
1623 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1625 /* Ensure that we've lost any extra precision. */
1629 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1632 #if defined(L_mulsc3) || defined(L_muldc3) \
1633 || defined(L_mulxc3) || defined(L_multc3)
1636 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1638 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1653 if (isnan (x
) && isnan (y
))
1655 /* Recover infinities that computed as NaN + iNaN. */
1657 if (isinf (a
) || isinf (b
))
1659 /* z is infinite. "Box" the infinity and change NaNs in
1660 the other factor to 0. */
1661 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1662 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1663 if (isnan (c
)) c
= COPYSIGN (0, c
);
1664 if (isnan (d
)) d
= COPYSIGN (0, d
);
1667 if (isinf (c
) || isinf (d
))
1669 /* w is infinite. "Box" the infinity and change NaNs in
1670 the other factor to 0. */
1671 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1672 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1673 if (isnan (a
)) a
= COPYSIGN (0, a
);
1674 if (isnan (b
)) b
= COPYSIGN (0, b
);
1678 && (isinf (ac
) || isinf (bd
)
1679 || isinf (ad
) || isinf (bc
)))
1681 /* Recover infinities from overflow by changing NaNs to 0. */
1682 if (isnan (a
)) a
= COPYSIGN (0, a
);
1683 if (isnan (b
)) b
= COPYSIGN (0, b
);
1684 if (isnan (c
)) c
= COPYSIGN (0, c
);
1685 if (isnan (d
)) d
= COPYSIGN (0, d
);
1690 x
= INFINITY
* (a
* c
- b
* d
);
1691 y
= INFINITY
* (a
* d
+ b
* c
);
1697 #endif /* complex multiply */
1699 #if defined(L_divsc3) || defined(L_divdc3) \
1700 || defined(L_divxc3) || defined(L_divtc3)
1703 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1705 MTYPE denom
, ratio
, x
, y
;
1707 /* ??? We can get better behavior from logarithmic scaling instead of
1708 the division. But that would mean starting to link libgcc against
1709 libm. We could implement something akin to ldexp/frexp as gcc builtins
1711 if (FABS (c
) < FABS (d
))
1714 denom
= (c
* ratio
) + d
;
1715 x
= ((a
* ratio
) + b
) / denom
;
1716 y
= ((b
* ratio
) - a
) / denom
;
1721 denom
= (d
* ratio
) + c
;
1722 x
= ((b
* ratio
) + a
) / denom
;
1723 y
= (b
- (a
* ratio
)) / denom
;
1726 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1727 are nonzero/zero, infinite/finite, and finite/infinite. */
1728 if (isnan (x
) && isnan (y
))
1730 if (denom
== 0.0 && (!isnan (a
) || !isnan (b
)))
1732 x
= COPYSIGN (INFINITY
, c
) * a
;
1733 y
= COPYSIGN (INFINITY
, c
) * b
;
1735 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1737 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1738 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1739 x
= INFINITY
* (a
* c
+ b
* d
);
1740 y
= INFINITY
* (b
* c
- a
* d
);
1742 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1744 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1745 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1746 x
= 0.0 * (a
* c
+ b
* d
);
1747 y
= 0.0 * (b
* c
- a
* d
);
1753 #endif /* complex divide */
1755 #endif /* all complex float routines */
1757 /* From here on down, the routines use normal data types. */
1759 #define SItype bogus_type
1760 #define USItype bogus_type
1761 #define DItype bogus_type
1762 #define UDItype bogus_type
1763 #define SFtype bogus_type
1764 #define DFtype bogus_type
1782 /* Like bcmp except the sign is meaningful.
1783 Result is negative if S1 is less than S2,
1784 positive if S1 is greater, 0 if S1 and S2 are equal. */
1787 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1791 const unsigned char c1
= *s1
++, c2
= *s2
++;
1801 /* __eprintf used to be used by GCC's private version of <assert.h>.
1802 We no longer provide that header, but this routine remains in libgcc.a
1803 for binary backward compatibility. Note that it is not included in
1804 the shared version of libgcc. */
1806 #ifndef inhibit_libc
1808 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1812 __eprintf (const char *string
, const char *expression
,
1813 unsigned int line
, const char *filename
)
1815 fprintf (stderr
, string
, expression
, line
, filename
);
1824 #ifdef L_clear_cache
1825 /* Clear part of an instruction cache. */
1828 __clear_cache (char *beg
__attribute__((__unused__
)),
1829 char *end
__attribute__((__unused__
)))
1831 #ifdef CLEAR_INSN_CACHE
1832 CLEAR_INSN_CACHE (beg
, end
);
1833 #endif /* CLEAR_INSN_CACHE */
1836 #endif /* L_clear_cache */
1838 #ifdef L_enable_execute_stack
1839 /* Attempt to turn on execute permission for the stack. */
1841 #ifdef ENABLE_EXECUTE_STACK
1842 ENABLE_EXECUTE_STACK
1845 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
1847 #endif /* ENABLE_EXECUTE_STACK */
1849 #endif /* L_enable_execute_stack */
1853 /* Jump to a trampoline, loading the static chain address. */
1855 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1868 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1872 mprotect (char *addr
, int len
, int prot
)
1889 if (VirtualProtect (addr
, len
, np
, &op
))
1895 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1897 #ifdef TRANSFER_FROM_TRAMPOLINE
1898 TRANSFER_FROM_TRAMPOLINE
1900 #endif /* L_trampoline */
1905 #include "gbl-ctors.h"
1906 /* Some systems use __main in a way incompatible with its use in gcc, in these
1907 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1908 give the same symbol without quotes for an alternative entry point. You
1909 must define both, or neither. */
1911 #define NAME__MAIN "__main"
1912 #define SYMBOL__MAIN __main
1915 #ifdef INIT_SECTION_ASM_OP
1916 #undef HAS_INIT_SECTION
1917 #define HAS_INIT_SECTION
1920 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1922 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1923 code to run constructors. In that case, we need to handle EH here, too. */
1925 #ifdef EH_FRAME_SECTION_NAME
1926 #include "unwind-dw2-fde.h"
1927 extern unsigned char __EH_FRAME_BEGIN__
[];
1930 /* Run all the global destructors on exit from the program. */
1933 __do_global_dtors (void)
1935 #ifdef DO_GLOBAL_DTORS_BODY
1936 DO_GLOBAL_DTORS_BODY
;
1938 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1945 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1947 static int completed
= 0;
1951 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1958 #ifndef HAS_INIT_SECTION
1959 /* Run all the global constructors on entry to the program. */
1962 __do_global_ctors (void)
1964 #ifdef EH_FRAME_SECTION_NAME
1966 static struct object object
;
1967 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1970 DO_GLOBAL_CTORS_BODY
;
1971 atexit (__do_global_dtors
);
1973 #endif /* no HAS_INIT_SECTION */
1975 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1976 /* Subroutine called automatically by `main'.
1977 Compiling a global function named `main'
1978 produces an automatic call to this function at the beginning.
1980 For many systems, this routine calls __do_global_ctors.
1981 For systems which support a .init section we use the .init section
1982 to run __do_global_ctors, so we need not do anything here. */
1984 extern void SYMBOL__MAIN (void);
1988 /* Support recursive calls to `main': run initializers just once. */
1989 static int initialized
;
1993 __do_global_ctors ();
1996 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1998 #endif /* L__main */
1999 #endif /* __CYGWIN__ */
2003 #include "gbl-ctors.h"
2005 /* Provide default definitions for the lists of constructors and
2006 destructors, so that we don't get linker errors. These symbols are
2007 intentionally bss symbols, so that gld and/or collect will provide
2008 the right values. */
2010 /* We declare the lists here with two elements each,
2011 so that they are valid empty lists if no other definition is loaded.
2013 If we are using the old "set" extensions to have the gnu linker
2014 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2015 must be in the bss/common section.
2017 Long term no port should use those extensions. But many still do. */
2018 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2019 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2020 func_ptr __CTOR_LIST__
[2] = {0, 0};
2021 func_ptr __DTOR_LIST__
[2] = {0, 0};
2023 func_ptr __CTOR_LIST__
[2];
2024 func_ptr __DTOR_LIST__
[2];
2026 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2027 #endif /* L_ctors */