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, 2007, 2008, 2009
5 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
30 #include "coretypes.h"
33 #ifdef HAVE_GAS_HIDDEN
34 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
36 #define ATTRIBUTE_HIDDEN
39 #ifndef MIN_UNITS_PER_WORD
40 #define MIN_UNITS_PER_WORD UNITS_PER_WORD
43 /* Work out the largest "word" size that we can deal with on this target. */
44 #if MIN_UNITS_PER_WORD > 4
45 # define LIBGCC2_MAX_UNITS_PER_WORD 8
46 #elif (MIN_UNITS_PER_WORD > 2 \
47 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
48 # define LIBGCC2_MAX_UNITS_PER_WORD 4
50 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
53 /* Work out what word size we are using for this compilation.
54 The value can be set on the command line. */
55 #ifndef LIBGCC2_UNITS_PER_WORD
56 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
59 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
63 #ifdef DECLARE_LIBRARY_RENAMES
64 DECLARE_LIBRARY_RENAMES
67 #if defined (L_negdi2)
71 const DWunion uu
= {.ll
= u
};
72 const DWunion w
= { {.low
= -uu
.s
.low
,
73 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
81 __addvSI3 (Wtype a
, Wtype b
)
83 const Wtype w
= (UWtype
) a
+ (UWtype
) b
;
85 if (b
>= 0 ? w
< a
: w
> a
)
90 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
92 __addvsi3 (SItype a
, SItype b
)
94 const SItype w
= (USItype
) a
+ (USItype
) b
;
96 if (b
>= 0 ? w
< a
: w
> a
)
101 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
106 __addvDI3 (DWtype a
, DWtype b
)
108 const DWtype w
= (UDWtype
) a
+ (UDWtype
) b
;
110 if (b
>= 0 ? w
< a
: w
> a
)
119 __subvSI3 (Wtype a
, Wtype b
)
121 const Wtype w
= (UWtype
) a
- (UWtype
) b
;
123 if (b
>= 0 ? w
> a
: w
< a
)
128 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
130 __subvsi3 (SItype a
, SItype b
)
132 const SItype w
= (USItype
) a
- (USItype
) b
;
134 if (b
>= 0 ? w
> a
: w
< a
)
139 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
144 __subvDI3 (DWtype a
, DWtype b
)
146 const DWtype w
= (UDWtype
) a
- (UDWtype
) b
;
148 if (b
>= 0 ? w
> a
: w
< a
)
157 __mulvSI3 (Wtype a
, Wtype b
)
159 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
161 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
166 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
168 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
170 __mulvsi3 (SItype a
, SItype b
)
172 const DItype w
= (DItype
) a
* (DItype
) b
;
174 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
179 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
186 const Wtype w
= -(UWtype
) a
;
188 if (a
>= 0 ? w
> 0 : w
< 0)
193 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
197 const SItype w
= -(USItype
) a
;
199 if (a
>= 0 ? w
> 0 : w
< 0)
204 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
211 const DWtype w
= -(UDWtype
) a
;
213 if (a
>= 0 ? w
> 0 : w
< 0)
238 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
256 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
281 __mulvDI3 (DWtype u
, DWtype v
)
283 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
284 but the checked multiplication needs only two. */
285 const DWunion uu
= {.ll
= u
};
286 const DWunion vv
= {.ll
= v
};
288 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
290 /* u fits in a single Wtype. */
291 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
293 /* v fits in a single Wtype as well. */
294 /* A single multiplication. No overflow risk. */
295 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
299 /* Two multiplications. */
300 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
301 * (UDWtype
) (UWtype
) vv
.s
.low
};
302 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
303 * (UDWtype
) (UWtype
) vv
.s
.high
};
306 w1
.s
.high
-= uu
.s
.low
;
309 w1
.ll
+= (UWtype
) w0
.s
.high
;
310 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
312 w0
.s
.high
= w1
.s
.low
;
319 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
321 /* v fits into a single Wtype. */
322 /* Two multiplications. */
323 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
324 * (UDWtype
) (UWtype
) vv
.s
.low
};
325 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
326 * (UDWtype
) (UWtype
) vv
.s
.low
};
329 w1
.s
.high
-= vv
.s
.low
;
332 w1
.ll
+= (UWtype
) w0
.s
.high
;
333 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
335 w0
.s
.high
= w1
.s
.low
;
341 /* A few sign checks and a single multiplication. */
346 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
348 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
349 * (UDWtype
) (UWtype
) vv
.s
.low
;
350 if (__builtin_expect (w
>= 0, 1))
356 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
358 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
359 * (UDWtype
) (UWtype
) vv
.s
.low
};
361 ww
.s
.high
-= uu
.s
.low
;
362 if (__builtin_expect (ww
.s
.high
< 0, 1))
371 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
373 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
374 * (UDWtype
) (UWtype
) vv
.s
.low
};
376 ww
.s
.high
-= vv
.s
.low
;
377 if (__builtin_expect (ww
.s
.high
< 0, 1))
383 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
385 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
386 * (UDWtype
) (UWtype
) vv
.s
.low
};
388 ww
.s
.high
-= uu
.s
.low
;
389 ww
.s
.high
-= vv
.s
.low
;
390 if (__builtin_expect (ww
.s
.high
>= 0, 1))
404 /* Unless shift functions are defined with full ANSI prototypes,
405 parameter b will be promoted to int if shift_count_type is smaller than an int. */
408 __lshrdi3 (DWtype u
, shift_count_type b
)
413 const DWunion uu
= {.ll
= u
};
414 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
420 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
424 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
426 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
427 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
436 __ashldi3 (DWtype u
, shift_count_type b
)
441 const DWunion uu
= {.ll
= u
};
442 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
448 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
452 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
454 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
455 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
464 __ashrdi3 (DWtype u
, shift_count_type b
)
469 const DWunion uu
= {.ll
= u
};
470 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
475 /* w.s.high = 1..1 or 0..0 */
476 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
477 w
.s
.low
= uu
.s
.high
>> -bm
;
481 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
483 w
.s
.high
= uu
.s
.high
>> b
;
484 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
493 __bswapsi2 (SItype u
)
495 return ((((u
) & 0xff000000) >> 24)
496 | (((u
) & 0x00ff0000) >> 8)
497 | (((u
) & 0x0000ff00) << 8)
498 | (((u
) & 0x000000ff) << 24));
503 __bswapdi2 (DItype u
)
505 return ((((u
) & 0xff00000000000000ull
) >> 56)
506 | (((u
) & 0x00ff000000000000ull
) >> 40)
507 | (((u
) & 0x0000ff0000000000ull
) >> 24)
508 | (((u
) & 0x000000ff00000000ull
) >> 8)
509 | (((u
) & 0x00000000ff000000ull
) << 8)
510 | (((u
) & 0x0000000000ff0000ull
) << 24)
511 | (((u
) & 0x000000000000ff00ull
) << 40)
512 | (((u
) & 0x00000000000000ffull
) << 56));
525 count_trailing_zeros (count
, u
);
535 const DWunion uu
= {.ll
= u
};
536 UWtype word
, count
, add
;
539 word
= uu
.s
.low
, add
= 0;
540 else if (uu
.s
.high
!= 0)
541 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
545 count_trailing_zeros (count
, word
);
546 return count
+ add
+ 1;
552 __muldi3 (DWtype u
, DWtype v
)
554 const DWunion uu
= {.ll
= u
};
555 const DWunion vv
= {.ll
= v
};
556 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
558 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
559 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
565 #if (defined (L_udivdi3) || defined (L_divdi3) || \
566 defined (L_umoddi3) || defined (L_moddi3))
567 #if defined (sdiv_qrnnd)
568 #define L_udiv_w_sdiv
573 #if defined (sdiv_qrnnd)
574 #if (defined (L_udivdi3) || defined (L_divdi3) || \
575 defined (L_umoddi3) || defined (L_moddi3))
576 static inline __attribute__ ((__always_inline__
))
579 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
586 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
588 /* Dividend, divisor, and quotient are nonnegative. */
589 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
593 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
594 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
595 /* Divide (c1*2^32 + c0) by d. */
596 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
597 /* Add 2^31 to quotient. */
598 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
603 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
604 c1
= a1
>> 1; /* A/2 */
605 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
607 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
609 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
611 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
628 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
631 c0
= ~c0
; /* logical NOT */
633 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
635 q
= ~q
; /* (A/2)/b1 */
638 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
656 else /* Implies c1 = b1 */
657 { /* Hence a1 = d - 1 = 2*b1 - 1 */
675 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
677 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
678 UWtype a1
__attribute__ ((__unused__
)),
679 UWtype a0
__attribute__ ((__unused__
)),
680 UWtype d
__attribute__ ((__unused__
)))
687 #if (defined (L_udivdi3) || defined (L_divdi3) || \
688 defined (L_umoddi3) || defined (L_moddi3))
693 const UQItype __clz_tab
[256] =
695 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,
696 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,
697 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,
698 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,
699 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,
700 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,
701 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,
702 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
713 count_leading_zeros (ret
, x
);
724 const DWunion uu
= {.ll
= x
};
729 word
= uu
.s
.high
, add
= 0;
731 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
733 count_leading_zeros (ret
, word
);
745 count_trailing_zeros (ret
, x
);
756 const DWunion uu
= {.ll
= x
};
761 word
= uu
.s
.low
, add
= 0;
763 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
765 count_trailing_zeros (ret
, word
);
770 #ifdef L_popcount_tab
771 const UQItype __popcount_tab
[256] =
773 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,
774 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,
775 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,
776 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,
777 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,
778 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,
779 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,
780 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
787 __popcountSI2 (UWtype x
)
791 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
792 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
801 __popcountDI2 (UDWtype x
)
805 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
806 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
815 __paritySI2 (UWtype x
)
818 # error "fill out the table"
829 return (0x6996 >> x
) & 1;
836 __parityDI2 (UDWtype x
)
838 const DWunion uu
= {.ll
= x
};
839 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
842 # error "fill out the table"
853 return (0x6996 >> nx
) & 1;
859 #if (defined (L_udivdi3) || defined (L_divdi3) || \
860 defined (L_umoddi3) || defined (L_moddi3))
861 static inline __attribute__ ((__always_inline__
))
864 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
866 const DWunion nn
= {.ll
= n
};
867 const DWunion dd
= {.ll
= d
};
869 UWtype d0
, d1
, n0
, n1
, n2
;
878 #if !UDIV_NEEDS_NORMALIZATION
885 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
888 /* Remainder in n0. */
895 d0
= 1 / d0
; /* Divide intentionally by zero. */
897 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
898 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
900 /* Remainder in n0. */
911 #else /* UDIV_NEEDS_NORMALIZATION */
919 count_leading_zeros (bm
, d0
);
923 /* Normalize, i.e. make the most significant bit of the
927 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
931 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
934 /* Remainder in n0 >> bm. */
941 d0
= 1 / d0
; /* Divide intentionally by zero. */
943 count_leading_zeros (bm
, d0
);
947 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
948 conclude (the most significant bit of n1 is set) /\ (the
949 leading quotient digit q1 = 1).
951 This special case is necessary, not an optimization.
952 (Shifts counts of W_TYPE_SIZE are undefined.) */
961 b
= W_TYPE_SIZE
- bm
;
965 n1
= (n1
<< bm
) | (n0
>> b
);
968 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
973 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
975 /* Remainder in n0 >> bm. */
985 #endif /* UDIV_NEEDS_NORMALIZATION */
996 /* Remainder in n1n0. */
1008 count_leading_zeros (bm
, d1
);
1011 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1012 conclude (the most significant bit of n1 is set) /\ (the
1013 quotient digit q0 = 0 or 1).
1015 This special case is necessary, not an optimization. */
1017 /* The condition on the next line takes advantage of that
1018 n1 >= d1 (true due to program flow). */
1019 if (n1
> d1
|| n0
>= d0
)
1022 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1041 b
= W_TYPE_SIZE
- bm
;
1043 d1
= (d1
<< bm
) | (d0
>> b
);
1046 n1
= (n1
<< bm
) | (n0
>> b
);
1049 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1050 umul_ppmm (m1
, m0
, q0
, d0
);
1052 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1055 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1060 /* Remainder in (n1n0 - m1m0) >> bm. */
1063 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1064 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1065 rr
.s
.high
= n1
>> bm
;
1072 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1079 __divdi3 (DWtype u
, DWtype v
)
1082 DWunion uu
= {.ll
= u
};
1083 DWunion vv
= {.ll
= v
};
1093 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1103 __moddi3 (DWtype u
, DWtype v
)
1106 DWunion uu
= {.ll
= u
};
1107 DWunion vv
= {.ll
= v
};
1116 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1126 __umoddi3 (UDWtype u
, UDWtype v
)
1130 (void) __udivmoddi4 (u
, v
, &w
);
1138 __udivdi3 (UDWtype n
, UDWtype d
)
1140 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1146 __cmpdi2 (DWtype a
, DWtype b
)
1148 const DWunion au
= {.ll
= a
};
1149 const DWunion bu
= {.ll
= b
};
1151 if (au
.s
.high
< bu
.s
.high
)
1153 else if (au
.s
.high
> bu
.s
.high
)
1155 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1157 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1165 __ucmpdi2 (DWtype a
, DWtype b
)
1167 const DWunion au
= {.ll
= a
};
1168 const DWunion bu
= {.ll
= b
};
1170 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1172 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1174 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1176 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1182 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1184 __fixunstfDI (TFtype a
)
1189 /* Compute high word of result, as a flonum. */
1190 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1191 /* Convert that to fixed (but not to DWtype!),
1192 and shift it into the high word. */
1193 UDWtype v
= (UWtype
) b
;
1195 /* Remove high part from the TFtype, leaving the low part as flonum. */
1197 /* Convert that to fixed (but not to DWtype!) and add it in.
1198 Sometimes A comes out negative. This is significant, since
1199 A has more bits than a long int does. */
1201 v
-= (UWtype
) (- a
);
1208 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1210 __fixtfdi (TFtype a
)
1213 return - __fixunstfDI (-a
);
1214 return __fixunstfDI (a
);
1218 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1220 __fixunsxfDI (XFtype a
)
1225 /* Compute high word of result, as a flonum. */
1226 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1227 /* Convert that to fixed (but not to DWtype!),
1228 and shift it into the high word. */
1229 UDWtype v
= (UWtype
) b
;
1231 /* Remove high part from the XFtype, leaving the low part as flonum. */
1233 /* Convert that to fixed (but not to DWtype!) and add it in.
1234 Sometimes A comes out negative. This is significant, since
1235 A has more bits than a long int does. */
1237 v
-= (UWtype
) (- a
);
1244 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1246 __fixxfdi (XFtype a
)
1249 return - __fixunsxfDI (-a
);
1250 return __fixunsxfDI (a
);
1254 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1256 __fixunsdfDI (DFtype a
)
1258 /* Get high part of result. The division here will just moves the radix
1259 point and will not cause any rounding. Then the conversion to integral
1260 type chops result as desired. */
1261 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1263 /* Get low part of result. Convert `hi' to floating type and scale it back,
1264 then subtract this from the number being converted. This leaves the low
1265 part. Convert that to integral type. */
1266 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1268 /* Assemble result from the two parts. */
1269 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1273 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1275 __fixdfdi (DFtype a
)
1278 return - __fixunsdfDI (-a
);
1279 return __fixunsdfDI (a
);
1283 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1285 __fixunssfDI (SFtype a
)
1287 #if LIBGCC2_HAS_DF_MODE
1288 /* Convert the SFtype to a DFtype, because that is surely not going
1289 to lose any bits. Some day someone else can write a faster version
1290 that avoids converting to DFtype, and verify it really works right. */
1291 const DFtype dfa
= a
;
1293 /* Get high part of result. The division here will just moves the radix
1294 point and will not cause any rounding. Then the conversion to integral
1295 type chops result as desired. */
1296 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1298 /* Get low part of result. Convert `hi' to floating type and scale it back,
1299 then subtract this from the number being converted. This leaves the low
1300 part. Convert that to integral type. */
1301 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1303 /* Assemble result from the two parts. */
1304 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1305 #elif FLT_MANT_DIG < W_TYPE_SIZE
1308 if (a
< Wtype_MAXp1_F
)
1310 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1312 /* Since we know that there are fewer significant bits in the SFmode
1313 quantity than in a word, we know that we can convert out all the
1314 significant bits in one step, and thus avoid losing bits. */
1316 /* ??? This following loop essentially performs frexpf. If we could
1317 use the real libm function, or poke at the actual bits of the fp
1318 format, it would be significantly faster. */
1320 UWtype shift
= 0, counter
;
1324 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1326 SFtype counterf
= (UWtype
)1 << counter
;
1334 /* Rescale into the range of one word, extract the bits of that
1335 one word, and shift the result into position. */
1338 return (DWtype
)counter
<< shift
;
1347 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1349 __fixsfdi (SFtype a
)
1352 return - __fixunssfDI (-a
);
1353 return __fixunssfDI (a
);
1357 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1359 __floatdixf (DWtype u
)
1361 #if W_TYPE_SIZE > XF_SIZE
1364 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1371 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1373 __floatundixf (UDWtype u
)
1375 #if W_TYPE_SIZE > XF_SIZE
1378 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1385 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1387 __floatditf (DWtype u
)
1389 #if W_TYPE_SIZE > TF_SIZE
1392 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1399 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1401 __floatunditf (UDWtype u
)
1403 #if W_TYPE_SIZE > TF_SIZE
1406 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1413 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1414 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1415 #define DI_SIZE (W_TYPE_SIZE * 2)
1416 #define F_MODE_OK(SIZE) \
1418 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1419 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1420 #if defined(L_floatdisf)
1421 #define FUNC __floatdisf
1422 #define FSTYPE SFtype
1423 #define FSSIZE SF_SIZE
1425 #define FUNC __floatdidf
1426 #define FSTYPE DFtype
1427 #define FSSIZE DF_SIZE
1433 #if FSSIZE >= W_TYPE_SIZE
1434 /* When the word size is small, we never get any rounding error. */
1435 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1439 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1440 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1441 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1443 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1444 # define FSIZE DF_SIZE
1445 # define FTYPE DFtype
1446 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1447 # define FSIZE XF_SIZE
1448 # define FTYPE XFtype
1449 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1450 # define FSIZE TF_SIZE
1451 # define FTYPE TFtype
1456 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1458 /* Protect against double-rounding error.
1459 Represent any low-order bits, that might be truncated by a bit that
1460 won't be lost. The bit can go in anywhere below the rounding position
1461 of the FSTYPE. A fixed mask and bit position handles all usual
1463 if (! (- ((DWtype
) 1 << FSIZE
) < u
1464 && u
< ((DWtype
) 1 << FSIZE
)))
1466 if ((UDWtype
) u
& (REP_BIT
- 1))
1468 u
&= ~ (REP_BIT
- 1);
1473 /* Do the calculation in a wider type so that we don't lose any of
1474 the precision of the high word while multiplying it. */
1475 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1480 #if FSSIZE >= W_TYPE_SIZE - 2
1483 /* Finally, the word size is larger than the number of bits in the
1484 required FSTYPE, and we've got no suitable wider type. The only
1485 way to avoid double rounding is to special case the
1488 /* If there are no high bits set, fall back to one conversion. */
1490 return (FSTYPE
)(Wtype
)u
;
1492 /* Otherwise, find the power of two. */
1493 Wtype hi
= u
>> W_TYPE_SIZE
;
1497 UWtype count
, shift
;
1498 count_leading_zeros (count
, hi
);
1500 /* No leading bits means u == minimum. */
1502 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1504 shift
= 1 + W_TYPE_SIZE
- count
;
1506 /* Shift down the most significant bits. */
1509 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1510 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1513 /* Convert the one word of data, and rescale. */
1515 if (shift
== W_TYPE_SIZE
)
1517 /* The following two cases could be merged if we knew that the target
1518 supported a native unsigned->float conversion. More often, we only
1519 have a signed conversion, and have to add extra fixup code. */
1520 else if (shift
== W_TYPE_SIZE
- 1)
1521 e
= Wtype_MAXp1_F
/ 2;
1523 e
= (Wtype
)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 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1536 #if defined(L_floatundisf)
1537 #define FUNC __floatundisf
1538 #define FSTYPE SFtype
1539 #define FSSIZE SF_SIZE
1541 #define FUNC __floatundidf
1542 #define FSTYPE DFtype
1543 #define FSSIZE DF_SIZE
1549 #if FSSIZE >= W_TYPE_SIZE
1550 /* When the word size is small, we never get any rounding error. */
1551 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1555 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1556 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1557 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1559 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1560 # define FSIZE DF_SIZE
1561 # define FTYPE DFtype
1562 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1563 # define FSIZE XF_SIZE
1564 # define FTYPE XFtype
1565 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1566 # define FSIZE TF_SIZE
1567 # define FTYPE TFtype
1572 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1574 /* Protect against double-rounding error.
1575 Represent any low-order bits, that might be truncated by a bit that
1576 won't be lost. The bit can go in anywhere below the rounding position
1577 of the FSTYPE. A fixed mask and bit position handles all usual
1579 if (u
>= ((UDWtype
) 1 << FSIZE
))
1581 if ((UDWtype
) u
& (REP_BIT
- 1))
1583 u
&= ~ (REP_BIT
- 1);
1588 /* Do the calculation in a wider type so that we don't lose any of
1589 the precision of the high word while multiplying it. */
1590 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1595 #if FSSIZE == W_TYPE_SIZE - 1
1598 /* Finally, the word size is larger than the number of bits in the
1599 required FSTYPE, and we've got no suitable wider type. The only
1600 way to avoid double rounding is to special case the
1603 /* If there are no high bits set, fall back to one conversion. */
1605 return (FSTYPE
)(UWtype
)u
;
1607 /* Otherwise, find the power of two. */
1608 UWtype hi
= u
>> W_TYPE_SIZE
;
1610 UWtype count
, shift
;
1611 count_leading_zeros (count
, hi
);
1613 shift
= W_TYPE_SIZE
- count
;
1615 /* Shift down the most significant bits. */
1618 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1619 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1622 /* Convert the one word of data, and rescale. */
1624 if (shift
== W_TYPE_SIZE
)
1626 /* The following two cases could be merged if we knew that the target
1627 supported a native unsigned->float conversion. More often, we only
1628 have a signed conversion, and have to add extra fixup code. */
1629 else if (shift
== W_TYPE_SIZE
- 1)
1630 e
= Wtype_MAXp1_F
/ 2;
1632 e
= (Wtype
)1 << shift
;
1638 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1639 /* Reenable the normal types, in case limits.h needs them. */
1652 __fixunsxfSI (XFtype a
)
1654 if (a
>= - (DFtype
) Wtype_MIN
)
1655 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1660 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1661 /* Reenable the normal types, in case limits.h needs them. */
1674 __fixunsdfSI (DFtype a
)
1676 if (a
>= - (DFtype
) Wtype_MIN
)
1677 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1682 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1683 /* Reenable the normal types, in case limits.h needs them. */
1696 __fixunssfSI (SFtype a
)
1698 if (a
>= - (SFtype
) Wtype_MIN
)
1699 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1704 /* Integer power helper used from __builtin_powi for non-constant
1707 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1708 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1709 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1710 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1711 # if defined(L_powisf2)
1712 # define TYPE SFtype
1713 # define NAME __powisf2
1714 # elif defined(L_powidf2)
1715 # define TYPE DFtype
1716 # define NAME __powidf2
1717 # elif defined(L_powixf2)
1718 # define TYPE XFtype
1719 # define NAME __powixf2
1720 # elif defined(L_powitf2)
1721 # define TYPE TFtype
1722 # define NAME __powitf2
1728 NAME (TYPE x
, int m
)
1730 unsigned int n
= m
< 0 ? -m
: m
;
1731 TYPE y
= n
% 2 ? x
: 1;
1738 return m
< 0 ? 1/y
: y
;
1743 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1744 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1745 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1746 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1752 #if defined(L_mulsc3) || defined(L_divsc3)
1753 # define MTYPE SFtype
1754 # define CTYPE SCtype
1757 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1758 #elif defined(L_muldc3) || defined(L_divdc3)
1759 # define MTYPE DFtype
1760 # define CTYPE DCtype
1762 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1767 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1769 #elif defined(L_mulxc3) || defined(L_divxc3)
1770 # define MTYPE XFtype
1771 # define CTYPE XCtype
1775 #elif defined(L_multc3) || defined(L_divtc3)
1776 # define MTYPE TFtype
1777 # define CTYPE TCtype
1779 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
1782 # define CEXT LIBGCC2_TF_CEXT
1789 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1790 #define _CONCAT3(A,B,C) A##B##C
1792 #define CONCAT2(A,B) _CONCAT2(A,B)
1793 #define _CONCAT2(A,B) A##B
1795 /* All of these would be present in a full C99 implementation of <math.h>
1796 and <complex.h>. Our problem is that only a few systems have such full
1797 implementations. Further, libgcc_s.so isn't currently linked against
1798 libm.so, and even for systems that do provide full C99, the extra overhead
1799 of all programs using libgcc having to link against libm. So avoid it. */
1801 #define isnan(x) __builtin_expect ((x) != (x), 0)
1802 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1803 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1805 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1808 /* Helpers to make the following code slightly less gross. */
1809 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1810 #define FABS CONCAT2(__builtin_fabs, CEXT)
1812 /* Verify that MTYPE matches up with CEXT. */
1813 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1815 /* Ensure that we've lost any extra precision. */
1819 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1822 #if defined(L_mulsc3) || defined(L_muldc3) \
1823 || defined(L_mulxc3) || defined(L_multc3)
1826 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1828 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1844 if (isnan (x
) && isnan (y
))
1846 /* Recover infinities that computed as NaN + iNaN. */
1848 if (isinf (a
) || isinf (b
))
1850 /* z is infinite. "Box" the infinity and change NaNs in
1851 the other factor to 0. */
1852 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1853 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1854 if (isnan (c
)) c
= COPYSIGN (0, c
);
1855 if (isnan (d
)) d
= COPYSIGN (0, d
);
1858 if (isinf (c
) || isinf (d
))
1860 /* w is infinite. "Box" the infinity and change NaNs in
1861 the other factor to 0. */
1862 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1863 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1864 if (isnan (a
)) a
= COPYSIGN (0, a
);
1865 if (isnan (b
)) b
= COPYSIGN (0, b
);
1869 && (isinf (ac
) || isinf (bd
)
1870 || isinf (ad
) || isinf (bc
)))
1872 /* Recover infinities from overflow by changing NaNs to 0. */
1873 if (isnan (a
)) a
= COPYSIGN (0, a
);
1874 if (isnan (b
)) b
= COPYSIGN (0, b
);
1875 if (isnan (c
)) c
= COPYSIGN (0, c
);
1876 if (isnan (d
)) d
= COPYSIGN (0, d
);
1881 x
= INFINITY
* (a
* c
- b
* d
);
1882 y
= INFINITY
* (a
* d
+ b
* c
);
1890 #endif /* complex multiply */
1892 #if defined(L_divsc3) || defined(L_divdc3) \
1893 || defined(L_divxc3) || defined(L_divtc3)
1896 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1898 MTYPE denom
, ratio
, x
, y
;
1901 /* ??? We can get better behavior from logarithmic scaling instead of
1902 the division. But that would mean starting to link libgcc against
1903 libm. We could implement something akin to ldexp/frexp as gcc builtins
1905 if (FABS (c
) < FABS (d
))
1908 denom
= (c
* ratio
) + d
;
1909 x
= ((a
* ratio
) + b
) / denom
;
1910 y
= ((b
* ratio
) - a
) / denom
;
1915 denom
= (d
* ratio
) + c
;
1916 x
= ((b
* ratio
) + a
) / denom
;
1917 y
= (b
- (a
* ratio
)) / denom
;
1920 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1921 are nonzero/zero, infinite/finite, and finite/infinite. */
1922 if (isnan (x
) && isnan (y
))
1924 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
1926 x
= COPYSIGN (INFINITY
, c
) * a
;
1927 y
= COPYSIGN (INFINITY
, c
) * b
;
1929 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1931 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1932 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1933 x
= INFINITY
* (a
* c
+ b
* d
);
1934 y
= INFINITY
* (b
* c
- a
* d
);
1936 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1938 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1939 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1940 x
= 0.0 * (a
* c
+ b
* d
);
1941 y
= 0.0 * (b
* c
- a
* d
);
1949 #endif /* complex divide */
1951 #endif /* all complex float routines */
1953 /* From here on down, the routines use normal data types. */
1955 #define SItype bogus_type
1956 #define USItype bogus_type
1957 #define DItype bogus_type
1958 #define UDItype bogus_type
1959 #define SFtype bogus_type
1960 #define DFtype bogus_type
1978 /* Like bcmp except the sign is meaningful.
1979 Result is negative if S1 is less than S2,
1980 positive if S1 is greater, 0 if S1 and S2 are equal. */
1983 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1987 const unsigned char c1
= *s1
++, c2
= *s2
++;
1997 /* __eprintf used to be used by GCC's private version of <assert.h>.
1998 We no longer provide that header, but this routine remains in libgcc.a
1999 for binary backward compatibility. Note that it is not included in
2000 the shared version of libgcc. */
2002 #ifndef inhibit_libc
2004 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2008 __eprintf (const char *string
, const char *expression
,
2009 unsigned int line
, const char *filename
)
2011 fprintf (stderr
, string
, expression
, line
, filename
);
2020 #ifdef L_clear_cache
2021 /* Clear part of an instruction cache. */
2024 __clear_cache (char *beg
__attribute__((__unused__
)),
2025 char *end
__attribute__((__unused__
)))
2027 #ifdef CLEAR_INSN_CACHE
2028 CLEAR_INSN_CACHE (beg
, end
);
2029 #endif /* CLEAR_INSN_CACHE */
2032 #endif /* L_clear_cache */
2034 #ifdef L_enable_execute_stack
2035 /* Attempt to turn on execute permission for the stack. */
2037 #ifdef ENABLE_EXECUTE_STACK
2038 ENABLE_EXECUTE_STACK
2041 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
2043 #endif /* ENABLE_EXECUTE_STACK */
2045 #endif /* L_enable_execute_stack */
2049 /* Jump to a trampoline, loading the static chain address. */
2051 #if defined(WINNT) && ! defined(__CYGWIN__)
2064 mprotect (char *addr
, int len
, int prot
)
2083 if (VirtualProtect (addr
, len
, np
, &op
))
2089 #endif /* WINNT && ! __CYGWIN__ */
2091 #ifdef TRANSFER_FROM_TRAMPOLINE
2092 TRANSFER_FROM_TRAMPOLINE
2094 #endif /* L_trampoline */
2099 #include "gbl-ctors.h"
2101 /* Some systems use __main in a way incompatible with its use in gcc, in these
2102 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2103 give the same symbol without quotes for an alternative entry point. You
2104 must define both, or neither. */
2106 #define NAME__MAIN "__main"
2107 #define SYMBOL__MAIN __main
2110 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2111 #undef HAS_INIT_SECTION
2112 #define HAS_INIT_SECTION
2115 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2117 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2118 code to run constructors. In that case, we need to handle EH here, too. */
2120 #ifdef EH_FRAME_SECTION_NAME
2121 #include "unwind-dw2-fde.h"
2122 extern unsigned char __EH_FRAME_BEGIN__
[];
2125 /* Run all the global destructors on exit from the program. */
2128 __do_global_dtors (void)
2130 #ifdef DO_GLOBAL_DTORS_BODY
2131 DO_GLOBAL_DTORS_BODY
;
2133 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2140 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2142 static int completed
= 0;
2146 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2153 #ifndef HAS_INIT_SECTION
2154 /* Run all the global constructors on entry to the program. */
2157 __do_global_ctors (void)
2159 #ifdef EH_FRAME_SECTION_NAME
2161 static struct object object
;
2162 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2165 DO_GLOBAL_CTORS_BODY
;
2166 atexit (__do_global_dtors
);
2168 #endif /* no HAS_INIT_SECTION */
2170 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2171 /* Subroutine called automatically by `main'.
2172 Compiling a global function named `main'
2173 produces an automatic call to this function at the beginning.
2175 For many systems, this routine calls __do_global_ctors.
2176 For systems which support a .init section we use the .init section
2177 to run __do_global_ctors, so we need not do anything here. */
2179 extern void SYMBOL__MAIN (void);
2183 /* Support recursive calls to `main': run initializers just once. */
2184 static int initialized
;
2188 __do_global_ctors ();
2191 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2193 #endif /* L__main */
2194 #endif /* __CYGWIN__ */
2198 #include "gbl-ctors.h"
2200 /* Provide default definitions for the lists of constructors and
2201 destructors, so that we don't get linker errors. These symbols are
2202 intentionally bss symbols, so that gld and/or collect will provide
2203 the right values. */
2205 /* We declare the lists here with two elements each,
2206 so that they are valid empty lists if no other definition is loaded.
2208 If we are using the old "set" extensions to have the gnu linker
2209 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2210 must be in the bss/common section.
2212 Long term no port should use those extensions. But many still do. */
2213 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2214 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2215 func_ptr __CTOR_LIST__
[2] = {0, 0};
2216 func_ptr __DTOR_LIST__
[2] = {0, 0};
2218 func_ptr __CTOR_LIST__
[2];
2219 func_ptr __DTOR_LIST__
[2];
2221 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2222 #endif /* L_ctors */
2223 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */