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, 2010, 2011
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"
32 #include "libgcc_tm.h"
34 #ifdef HAVE_GAS_HIDDEN
35 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
37 #define ATTRIBUTE_HIDDEN
40 /* Work out the largest "word" size that we can deal with on this target. */
41 #if MIN_UNITS_PER_WORD > 4
42 # define LIBGCC2_MAX_UNITS_PER_WORD 8
43 #elif (MIN_UNITS_PER_WORD > 2 \
44 || (MIN_UNITS_PER_WORD > 1 && __SIZEOF_LONG_LONG__ > 4))
45 # define LIBGCC2_MAX_UNITS_PER_WORD 4
47 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
50 /* Work out what word size we are using for this compilation.
51 The value can be set on the command line. */
52 #ifndef LIBGCC2_UNITS_PER_WORD
53 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
56 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
60 #ifdef DECLARE_LIBRARY_RENAMES
61 DECLARE_LIBRARY_RENAMES
64 #if defined (L_negdi2)
68 const DWunion uu
= {.ll
= u
};
69 const DWunion w
= { {.low
= -uu
.s
.low
,
70 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
78 __addvSI3 (Wtype a
, Wtype b
)
80 const Wtype w
= (UWtype
) a
+ (UWtype
) b
;
82 if (b
>= 0 ? w
< a
: w
> a
)
87 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
89 __addvsi3 (SItype a
, SItype b
)
91 const SItype w
= (USItype
) a
+ (USItype
) b
;
93 if (b
>= 0 ? w
< a
: w
> a
)
98 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
103 __addvDI3 (DWtype a
, DWtype b
)
105 const DWtype w
= (UDWtype
) a
+ (UDWtype
) b
;
107 if (b
>= 0 ? w
< a
: w
> a
)
116 __subvSI3 (Wtype a
, Wtype b
)
118 const Wtype w
= (UWtype
) a
- (UWtype
) b
;
120 if (b
>= 0 ? w
> a
: w
< a
)
125 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
127 __subvsi3 (SItype a
, SItype b
)
129 const SItype w
= (USItype
) a
- (USItype
) b
;
131 if (b
>= 0 ? w
> a
: w
< a
)
136 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
141 __subvDI3 (DWtype a
, DWtype b
)
143 const DWtype w
= (UDWtype
) a
- (UDWtype
) b
;
145 if (b
>= 0 ? w
> a
: w
< a
)
154 __mulvSI3 (Wtype a
, Wtype b
)
156 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
158 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
163 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
165 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
167 __mulvsi3 (SItype a
, SItype b
)
169 const DItype w
= (DItype
) a
* (DItype
) b
;
171 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
176 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
183 const Wtype w
= -(UWtype
) a
;
185 if (a
>= 0 ? w
> 0 : w
< 0)
190 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
194 const SItype w
= -(USItype
) a
;
196 if (a
>= 0 ? w
> 0 : w
< 0)
201 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
208 const DWtype w
= -(UDWtype
) a
;
210 if (a
>= 0 ? w
> 0 : w
< 0)
235 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
253 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
278 __mulvDI3 (DWtype u
, DWtype v
)
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu
= {.ll
= u
};
283 const DWunion vv
= {.ll
= v
};
285 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
287 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
296 /* Two multiplications. */
297 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
298 * (UDWtype
) (UWtype
) vv
.s
.low
};
299 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
300 * (UDWtype
) (UWtype
) vv
.s
.high
};
303 w1
.s
.high
-= uu
.s
.low
;
306 w1
.ll
+= (UWtype
) w0
.s
.high
;
307 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
309 w0
.s
.high
= w1
.s
.low
;
316 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
321 * (UDWtype
) (UWtype
) vv
.s
.low
};
322 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
323 * (UDWtype
) (UWtype
) vv
.s
.low
};
326 w1
.s
.high
-= vv
.s
.low
;
329 w1
.ll
+= (UWtype
) w0
.s
.high
;
330 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
332 w0
.s
.high
= w1
.s
.low
;
338 /* A few sign checks and a single multiplication. */
343 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
345 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
346 * (UDWtype
) (UWtype
) vv
.s
.low
;
347 if (__builtin_expect (w
>= 0, 1))
353 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
355 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
356 * (UDWtype
) (UWtype
) vv
.s
.low
};
358 ww
.s
.high
-= uu
.s
.low
;
359 if (__builtin_expect (ww
.s
.high
< 0, 1))
368 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
370 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
371 * (UDWtype
) (UWtype
) vv
.s
.low
};
373 ww
.s
.high
-= vv
.s
.low
;
374 if (__builtin_expect (ww
.s
.high
< 0, 1))
380 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
382 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
383 * (UDWtype
) (UWtype
) vv
.s
.low
};
385 ww
.s
.high
-= uu
.s
.low
;
386 ww
.s
.high
-= vv
.s
.low
;
387 if (__builtin_expect (ww
.s
.high
>= 0, 1))
401 /* Unless shift functions are defined with full ANSI prototypes,
402 parameter b will be promoted to int if shift_count_type is smaller than an int. */
405 __lshrdi3 (DWtype u
, shift_count_type b
)
410 const DWunion uu
= {.ll
= u
};
411 const shift_count_type bm
= W_TYPE_SIZE
- b
;
417 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
421 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
423 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
424 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
433 __ashldi3 (DWtype u
, shift_count_type b
)
438 const DWunion uu
= {.ll
= u
};
439 const shift_count_type bm
= W_TYPE_SIZE
- b
;
445 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
449 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
451 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
452 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
461 __ashrdi3 (DWtype u
, shift_count_type b
)
466 const DWunion uu
= {.ll
= u
};
467 const shift_count_type bm
= W_TYPE_SIZE
- b
;
472 /* w.s.high = 1..1 or 0..0 */
473 w
.s
.high
= uu
.s
.high
>> (W_TYPE_SIZE
- 1);
474 w
.s
.low
= uu
.s
.high
>> -bm
;
478 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
480 w
.s
.high
= uu
.s
.high
>> b
;
481 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
490 __bswapsi2 (SItype u
)
492 return ((((u
) & 0xff000000) >> 24)
493 | (((u
) & 0x00ff0000) >> 8)
494 | (((u
) & 0x0000ff00) << 8)
495 | (((u
) & 0x000000ff) << 24));
500 __bswapdi2 (DItype u
)
502 return ((((u
) & 0xff00000000000000ull
) >> 56)
503 | (((u
) & 0x00ff000000000000ull
) >> 40)
504 | (((u
) & 0x0000ff0000000000ull
) >> 24)
505 | (((u
) & 0x000000ff00000000ull
) >> 8)
506 | (((u
) & 0x00000000ff000000ull
) << 8)
507 | (((u
) & 0x0000000000ff0000ull
) << 24)
508 | (((u
) & 0x000000000000ff00ull
) << 40)
509 | (((u
) & 0x00000000000000ffull
) << 56));
522 count_trailing_zeros (count
, u
);
532 const DWunion uu
= {.ll
= u
};
533 UWtype word
, count
, add
;
536 word
= uu
.s
.low
, add
= 0;
537 else if (uu
.s
.high
!= 0)
538 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
542 count_trailing_zeros (count
, word
);
543 return count
+ add
+ 1;
549 __muldi3 (DWtype u
, DWtype v
)
551 const DWunion uu
= {.ll
= u
};
552 const DWunion vv
= {.ll
= v
};
553 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
555 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
556 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
562 #if (defined (L_udivdi3) || defined (L_divdi3) || \
563 defined (L_umoddi3) || defined (L_moddi3))
564 #if defined (sdiv_qrnnd)
565 #define L_udiv_w_sdiv
570 #if defined (sdiv_qrnnd)
571 #if (defined (L_udivdi3) || defined (L_divdi3) || \
572 defined (L_umoddi3) || defined (L_moddi3))
573 static inline __attribute__ ((__always_inline__
))
576 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
583 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
585 /* Dividend, divisor, and quotient are nonnegative. */
586 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
590 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
591 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
592 /* Divide (c1*2^32 + c0) by d. */
593 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
594 /* Add 2^31 to quotient. */
595 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
600 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
601 c1
= a1
>> 1; /* A/2 */
602 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
604 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
606 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
608 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
625 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
628 c0
= ~c0
; /* logical NOT */
630 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
632 q
= ~q
; /* (A/2)/b1 */
635 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
653 else /* Implies c1 = b1 */
654 { /* Hence a1 = d - 1 = 2*b1 - 1 */
672 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
674 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
675 UWtype a1
__attribute__ ((__unused__
)),
676 UWtype a0
__attribute__ ((__unused__
)),
677 UWtype d
__attribute__ ((__unused__
)))
684 #if (defined (L_udivdi3) || defined (L_divdi3) || \
685 defined (L_umoddi3) || defined (L_moddi3))
690 const UQItype __clz_tab
[256] =
692 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,
693 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,
694 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,
695 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,
696 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,
697 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,
698 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,
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
710 count_leading_zeros (ret
, x
);
721 const DWunion uu
= {.ll
= x
};
726 word
= uu
.s
.high
, add
= 0;
728 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
730 count_leading_zeros (ret
, word
);
742 count_trailing_zeros (ret
, x
);
753 const DWunion uu
= {.ll
= x
};
758 word
= uu
.s
.low
, add
= 0;
760 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
762 count_trailing_zeros (ret
, word
);
777 return W_TYPE_SIZE
- 1;
778 count_leading_zeros (ret
, x
);
786 __clrsbDI2 (DWtype x
)
788 const DWunion uu
= {.ll
= x
};
793 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
794 else if (uu
.s
.high
== -1)
795 word
= ~uu
.s
.low
, add
= W_TYPE_SIZE
;
796 else if (uu
.s
.high
>= 0)
797 word
= uu
.s
.high
, add
= 0;
799 word
= ~uu
.s
.high
, add
= 0;
804 count_leading_zeros (ret
, word
);
806 return ret
+ add
- 1;
810 #ifdef L_popcount_tab
811 const UQItype __popcount_tab
[256] =
813 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,
814 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,
815 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,
816 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,
817 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,
818 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,
819 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,
820 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
827 __popcountSI2 (UWtype x
)
831 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
832 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
841 __popcountDI2 (UDWtype x
)
845 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
846 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
855 __paritySI2 (UWtype x
)
858 # error "fill out the table"
869 return (0x6996 >> x
) & 1;
876 __parityDI2 (UDWtype x
)
878 const DWunion uu
= {.ll
= x
};
879 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
882 # error "fill out the table"
893 return (0x6996 >> nx
) & 1;
899 #if (defined (L_udivdi3) || defined (L_divdi3) || \
900 defined (L_umoddi3) || defined (L_moddi3))
901 static inline __attribute__ ((__always_inline__
))
904 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
906 const DWunion nn
= {.ll
= n
};
907 const DWunion dd
= {.ll
= d
};
909 UWtype d0
, d1
, n0
, n1
, n2
;
918 #if !UDIV_NEEDS_NORMALIZATION
925 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
928 /* Remainder in n0. */
935 d0
= 1 / d0
; /* Divide intentionally by zero. */
937 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
938 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
940 /* Remainder in n0. */
951 #else /* UDIV_NEEDS_NORMALIZATION */
959 count_leading_zeros (bm
, d0
);
963 /* Normalize, i.e. make the most significant bit of the
967 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
971 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
974 /* Remainder in n0 >> bm. */
981 d0
= 1 / d0
; /* Divide intentionally by zero. */
983 count_leading_zeros (bm
, d0
);
987 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
988 conclude (the most significant bit of n1 is set) /\ (the
989 leading quotient digit q1 = 1).
991 This special case is necessary, not an optimization.
992 (Shifts counts of W_TYPE_SIZE are undefined.) */
1001 b
= W_TYPE_SIZE
- bm
;
1005 n1
= (n1
<< bm
) | (n0
>> b
);
1008 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
1013 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1015 /* Remainder in n0 >> bm. */
1020 rr
.s
.low
= n0
>> bm
;
1025 #endif /* UDIV_NEEDS_NORMALIZATION */
1036 /* Remainder in n1n0. */
1048 count_leading_zeros (bm
, d1
);
1051 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1052 conclude (the most significant bit of n1 is set) /\ (the
1053 quotient digit q0 = 0 or 1).
1055 This special case is necessary, not an optimization. */
1057 /* The condition on the next line takes advantage of that
1058 n1 >= d1 (true due to program flow). */
1059 if (n1
> d1
|| n0
>= d0
)
1062 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1081 b
= W_TYPE_SIZE
- bm
;
1083 d1
= (d1
<< bm
) | (d0
>> b
);
1086 n1
= (n1
<< bm
) | (n0
>> b
);
1089 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1090 umul_ppmm (m1
, m0
, q0
, d0
);
1092 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1095 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1100 /* Remainder in (n1n0 - m1m0) >> bm. */
1103 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1104 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1105 rr
.s
.high
= n1
>> bm
;
1112 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1119 __divdi3 (DWtype u
, DWtype v
)
1122 DWunion uu
= {.ll
= u
};
1123 DWunion vv
= {.ll
= v
};
1133 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1143 __moddi3 (DWtype u
, DWtype v
)
1146 DWunion uu
= {.ll
= u
};
1147 DWunion vv
= {.ll
= v
};
1156 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1166 __umoddi3 (UDWtype u
, UDWtype v
)
1170 (void) __udivmoddi4 (u
, v
, &w
);
1178 __udivdi3 (UDWtype n
, UDWtype d
)
1180 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1186 __cmpdi2 (DWtype a
, DWtype b
)
1188 const DWunion au
= {.ll
= a
};
1189 const DWunion bu
= {.ll
= b
};
1191 if (au
.s
.high
< bu
.s
.high
)
1193 else if (au
.s
.high
> bu
.s
.high
)
1195 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1197 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1205 __ucmpdi2 (DWtype a
, DWtype b
)
1207 const DWunion au
= {.ll
= a
};
1208 const DWunion bu
= {.ll
= b
};
1210 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1212 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1214 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1216 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1222 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1224 __fixunstfDI (TFtype a
)
1229 /* Compute high word of result, as a flonum. */
1230 const TFtype 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 TFtype, 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_fixtfdi) && LIBGCC2_HAS_TF_MODE
1250 __fixtfdi (TFtype a
)
1253 return - __fixunstfDI (-a
);
1254 return __fixunstfDI (a
);
1258 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1260 __fixunsxfDI (XFtype a
)
1265 /* Compute high word of result, as a flonum. */
1266 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1267 /* Convert that to fixed (but not to DWtype!),
1268 and shift it into the high word. */
1269 UDWtype v
= (UWtype
) b
;
1271 /* Remove high part from the XFtype, leaving the low part as flonum. */
1273 /* Convert that to fixed (but not to DWtype!) and add it in.
1274 Sometimes A comes out negative. This is significant, since
1275 A has more bits than a long int does. */
1277 v
-= (UWtype
) (- a
);
1284 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1286 __fixxfdi (XFtype a
)
1289 return - __fixunsxfDI (-a
);
1290 return __fixunsxfDI (a
);
1294 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1296 __fixunsdfDI (DFtype a
)
1298 /* Get high part of result. The division here will just moves the radix
1299 point and will not cause any rounding. Then the conversion to integral
1300 type chops result as desired. */
1301 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1303 /* Get low part of result. Convert `hi' to floating type and scale it back,
1304 then subtract this from the number being converted. This leaves the low
1305 part. Convert that to integral type. */
1306 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1308 /* Assemble result from the two parts. */
1309 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1313 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1315 __fixdfdi (DFtype a
)
1318 return - __fixunsdfDI (-a
);
1319 return __fixunsdfDI (a
);
1323 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1325 __fixunssfDI (SFtype a
)
1327 #if LIBGCC2_HAS_DF_MODE
1328 /* Convert the SFtype to a DFtype, because that is surely not going
1329 to lose any bits. Some day someone else can write a faster version
1330 that avoids converting to DFtype, and verify it really works right. */
1331 const DFtype dfa
= a
;
1333 /* Get high part of result. The division here will just moves the radix
1334 point and will not cause any rounding. Then the conversion to integral
1335 type chops result as desired. */
1336 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1338 /* Get low part of result. Convert `hi' to floating type and scale it back,
1339 then subtract this from the number being converted. This leaves the low
1340 part. Convert that to integral type. */
1341 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1343 /* Assemble result from the two parts. */
1344 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1345 #elif FLT_MANT_DIG < W_TYPE_SIZE
1348 if (a
< Wtype_MAXp1_F
)
1350 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1352 /* Since we know that there are fewer significant bits in the SFmode
1353 quantity than in a word, we know that we can convert out all the
1354 significant bits in one step, and thus avoid losing bits. */
1356 /* ??? This following loop essentially performs frexpf. If we could
1357 use the real libm function, or poke at the actual bits of the fp
1358 format, it would be significantly faster. */
1360 UWtype shift
= 0, counter
;
1364 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1366 SFtype counterf
= (UWtype
)1 << counter
;
1374 /* Rescale into the range of one word, extract the bits of that
1375 one word, and shift the result into position. */
1378 return (DWtype
)counter
<< shift
;
1387 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1389 __fixsfdi (SFtype a
)
1392 return - __fixunssfDI (-a
);
1393 return __fixunssfDI (a
);
1397 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1399 __floatdixf (DWtype u
)
1401 #if W_TYPE_SIZE > XF_SIZE
1404 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1411 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1413 __floatundixf (UDWtype u
)
1415 #if W_TYPE_SIZE > XF_SIZE
1418 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1425 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1427 __floatditf (DWtype u
)
1429 #if W_TYPE_SIZE > TF_SIZE
1432 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1439 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1441 __floatunditf (UDWtype u
)
1443 #if W_TYPE_SIZE > TF_SIZE
1446 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1453 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1454 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1455 #define DI_SIZE (W_TYPE_SIZE * 2)
1456 #define F_MODE_OK(SIZE) \
1458 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1459 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1460 #if defined(L_floatdisf)
1461 #define FUNC __floatdisf
1462 #define FSTYPE SFtype
1463 #define FSSIZE SF_SIZE
1465 #define FUNC __floatdidf
1466 #define FSTYPE DFtype
1467 #define FSSIZE DF_SIZE
1473 #if FSSIZE >= W_TYPE_SIZE
1474 /* When the word size is small, we never get any rounding error. */
1475 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1479 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1480 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1481 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1483 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1484 # define FSIZE DF_SIZE
1485 # define FTYPE DFtype
1486 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1487 # define FSIZE XF_SIZE
1488 # define FTYPE XFtype
1489 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1490 # define FSIZE TF_SIZE
1491 # define FTYPE TFtype
1496 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1498 /* Protect against double-rounding error.
1499 Represent any low-order bits, that might be truncated by a bit that
1500 won't be lost. The bit can go in anywhere below the rounding position
1501 of the FSTYPE. A fixed mask and bit position handles all usual
1503 if (! (- ((DWtype
) 1 << FSIZE
) < u
1504 && u
< ((DWtype
) 1 << FSIZE
)))
1506 if ((UDWtype
) u
& (REP_BIT
- 1))
1508 u
&= ~ (REP_BIT
- 1);
1513 /* Do the calculation in a wider type so that we don't lose any of
1514 the precision of the high word while multiplying it. */
1515 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1520 #if FSSIZE >= W_TYPE_SIZE - 2
1523 /* Finally, the word size is larger than the number of bits in the
1524 required FSTYPE, and we've got no suitable wider type. The only
1525 way to avoid double rounding is to special case the
1528 /* If there are no high bits set, fall back to one conversion. */
1530 return (FSTYPE
)(Wtype
)u
;
1532 /* Otherwise, find the power of two. */
1533 Wtype hi
= u
>> W_TYPE_SIZE
;
1537 UWtype count
, shift
;
1538 count_leading_zeros (count
, hi
);
1540 /* No leading bits means u == minimum. */
1542 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1544 shift
= 1 + W_TYPE_SIZE
- count
;
1546 /* Shift down the most significant bits. */
1549 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1550 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1553 /* Convert the one word of data, and rescale. */
1555 if (shift
== W_TYPE_SIZE
)
1557 /* The following two cases could be merged if we knew that the target
1558 supported a native unsigned->float conversion. More often, we only
1559 have a signed conversion, and have to add extra fixup code. */
1560 else if (shift
== W_TYPE_SIZE
- 1)
1561 e
= Wtype_MAXp1_F
/ 2;
1563 e
= (Wtype
)1 << shift
;
1569 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1570 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1571 #define DI_SIZE (W_TYPE_SIZE * 2)
1572 #define F_MODE_OK(SIZE) \
1574 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1575 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1576 #if defined(L_floatundisf)
1577 #define FUNC __floatundisf
1578 #define FSTYPE SFtype
1579 #define FSSIZE SF_SIZE
1581 #define FUNC __floatundidf
1582 #define FSTYPE DFtype
1583 #define FSSIZE DF_SIZE
1589 #if FSSIZE >= W_TYPE_SIZE
1590 /* When the word size is small, we never get any rounding error. */
1591 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1595 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1596 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1597 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1599 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1600 # define FSIZE DF_SIZE
1601 # define FTYPE DFtype
1602 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1603 # define FSIZE XF_SIZE
1604 # define FTYPE XFtype
1605 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1606 # define FSIZE TF_SIZE
1607 # define FTYPE TFtype
1612 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1614 /* Protect against double-rounding error.
1615 Represent any low-order bits, that might be truncated by a bit that
1616 won't be lost. The bit can go in anywhere below the rounding position
1617 of the FSTYPE. A fixed mask and bit position handles all usual
1619 if (u
>= ((UDWtype
) 1 << FSIZE
))
1621 if ((UDWtype
) u
& (REP_BIT
- 1))
1623 u
&= ~ (REP_BIT
- 1);
1628 /* Do the calculation in a wider type so that we don't lose any of
1629 the precision of the high word while multiplying it. */
1630 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1635 #if FSSIZE == W_TYPE_SIZE - 1
1638 /* Finally, the word size is larger than the number of bits in the
1639 required FSTYPE, and we've got no suitable wider type. The only
1640 way to avoid double rounding is to special case the
1643 /* If there are no high bits set, fall back to one conversion. */
1645 return (FSTYPE
)(UWtype
)u
;
1647 /* Otherwise, find the power of two. */
1648 UWtype hi
= u
>> W_TYPE_SIZE
;
1650 UWtype count
, shift
;
1651 count_leading_zeros (count
, hi
);
1653 shift
= W_TYPE_SIZE
- count
;
1655 /* Shift down the most significant bits. */
1658 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1659 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1662 /* Convert the one word of data, and rescale. */
1664 if (shift
== W_TYPE_SIZE
)
1666 /* The following two cases could be merged if we knew that the target
1667 supported a native unsigned->float conversion. More often, we only
1668 have a signed conversion, and have to add extra fixup code. */
1669 else if (shift
== W_TYPE_SIZE
- 1)
1670 e
= Wtype_MAXp1_F
/ 2;
1672 e
= (Wtype
)1 << shift
;
1678 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1679 /* Reenable the normal types, in case limits.h needs them. */
1692 __fixunsxfSI (XFtype a
)
1694 if (a
>= - (DFtype
) Wtype_MIN
)
1695 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1700 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1701 /* Reenable the normal types, in case limits.h needs them. */
1714 __fixunsdfSI (DFtype a
)
1716 if (a
>= - (DFtype
) Wtype_MIN
)
1717 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1722 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1723 /* Reenable the normal types, in case limits.h needs them. */
1736 __fixunssfSI (SFtype a
)
1738 if (a
>= - (SFtype
) Wtype_MIN
)
1739 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1744 /* Integer power helper used from __builtin_powi for non-constant
1747 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1748 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1749 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1750 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1751 # if defined(L_powisf2)
1752 # define TYPE SFtype
1753 # define NAME __powisf2
1754 # elif defined(L_powidf2)
1755 # define TYPE DFtype
1756 # define NAME __powidf2
1757 # elif defined(L_powixf2)
1758 # define TYPE XFtype
1759 # define NAME __powixf2
1760 # elif defined(L_powitf2)
1761 # define TYPE TFtype
1762 # define NAME __powitf2
1768 NAME (TYPE x
, int m
)
1770 unsigned int n
= m
< 0 ? -m
: m
;
1771 TYPE y
= n
% 2 ? x
: 1;
1778 return m
< 0 ? 1/y
: y
;
1783 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1784 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1785 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1786 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1792 #if defined(L_mulsc3) || defined(L_divsc3)
1793 # define MTYPE SFtype
1794 # define CTYPE SCtype
1797 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1798 #elif defined(L_muldc3) || defined(L_divdc3)
1799 # define MTYPE DFtype
1800 # define CTYPE DCtype
1802 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1807 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1809 #elif defined(L_mulxc3) || defined(L_divxc3)
1810 # define MTYPE XFtype
1811 # define CTYPE XCtype
1815 #elif defined(L_multc3) || defined(L_divtc3)
1816 # define MTYPE TFtype
1817 # define CTYPE TCtype
1819 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
1822 # define CEXT LIBGCC2_TF_CEXT
1829 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1830 #define _CONCAT3(A,B,C) A##B##C
1832 #define CONCAT2(A,B) _CONCAT2(A,B)
1833 #define _CONCAT2(A,B) A##B
1835 /* All of these would be present in a full C99 implementation of <math.h>
1836 and <complex.h>. Our problem is that only a few systems have such full
1837 implementations. Further, libgcc_s.so isn't currently linked against
1838 libm.so, and even for systems that do provide full C99, the extra overhead
1839 of all programs using libgcc having to link against libm. So avoid it. */
1841 #define isnan(x) __builtin_expect ((x) != (x), 0)
1842 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1843 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1845 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1848 /* Helpers to make the following code slightly less gross. */
1849 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1850 #define FABS CONCAT2(__builtin_fabs, CEXT)
1852 /* Verify that MTYPE matches up with CEXT. */
1853 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1855 /* Ensure that we've lost any extra precision. */
1859 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1862 #if defined(L_mulsc3) || defined(L_muldc3) \
1863 || defined(L_mulxc3) || defined(L_multc3)
1866 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1868 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1884 if (isnan (x
) && isnan (y
))
1886 /* Recover infinities that computed as NaN + iNaN. */
1888 if (isinf (a
) || isinf (b
))
1890 /* z is infinite. "Box" the infinity and change NaNs in
1891 the other factor to 0. */
1892 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1893 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1894 if (isnan (c
)) c
= COPYSIGN (0, c
);
1895 if (isnan (d
)) d
= COPYSIGN (0, d
);
1898 if (isinf (c
) || isinf (d
))
1900 /* w is infinite. "Box" the infinity and change NaNs in
1901 the other factor to 0. */
1902 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1903 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1904 if (isnan (a
)) a
= COPYSIGN (0, a
);
1905 if (isnan (b
)) b
= COPYSIGN (0, b
);
1909 && (isinf (ac
) || isinf (bd
)
1910 || isinf (ad
) || isinf (bc
)))
1912 /* Recover infinities from overflow by changing NaNs to 0. */
1913 if (isnan (a
)) a
= COPYSIGN (0, a
);
1914 if (isnan (b
)) b
= COPYSIGN (0, b
);
1915 if (isnan (c
)) c
= COPYSIGN (0, c
);
1916 if (isnan (d
)) d
= COPYSIGN (0, d
);
1921 x
= INFINITY
* (a
* c
- b
* d
);
1922 y
= INFINITY
* (a
* d
+ b
* c
);
1930 #endif /* complex multiply */
1932 #if defined(L_divsc3) || defined(L_divdc3) \
1933 || defined(L_divxc3) || defined(L_divtc3)
1936 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1938 MTYPE denom
, ratio
, x
, y
;
1941 /* ??? We can get better behavior from logarithmic scaling instead of
1942 the division. But that would mean starting to link libgcc against
1943 libm. We could implement something akin to ldexp/frexp as gcc builtins
1945 if (FABS (c
) < FABS (d
))
1948 denom
= (c
* ratio
) + d
;
1949 x
= ((a
* ratio
) + b
) / denom
;
1950 y
= ((b
* ratio
) - a
) / denom
;
1955 denom
= (d
* ratio
) + c
;
1956 x
= ((b
* ratio
) + a
) / denom
;
1957 y
= (b
- (a
* ratio
)) / denom
;
1960 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1961 are nonzero/zero, infinite/finite, and finite/infinite. */
1962 if (isnan (x
) && isnan (y
))
1964 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
1966 x
= COPYSIGN (INFINITY
, c
) * a
;
1967 y
= COPYSIGN (INFINITY
, c
) * b
;
1969 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1971 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1972 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1973 x
= INFINITY
* (a
* c
+ b
* d
);
1974 y
= INFINITY
* (b
* c
- a
* d
);
1976 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1978 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1979 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1980 x
= 0.0 * (a
* c
+ b
* d
);
1981 y
= 0.0 * (b
* c
- a
* d
);
1989 #endif /* complex divide */
1991 #endif /* all complex float routines */
1993 /* From here on down, the routines use normal data types. */
1995 #define SItype bogus_type
1996 #define USItype bogus_type
1997 #define DItype bogus_type
1998 #define UDItype bogus_type
1999 #define SFtype bogus_type
2000 #define DFtype bogus_type
2018 /* Like bcmp except the sign is meaningful.
2019 Result is negative if S1 is less than S2,
2020 positive if S1 is greater, 0 if S1 and S2 are equal. */
2023 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
2027 const unsigned char c1
= *s1
++, c2
= *s2
++;
2037 /* __eprintf used to be used by GCC's private version of <assert.h>.
2038 We no longer provide that header, but this routine remains in libgcc.a
2039 for binary backward compatibility. Note that it is not included in
2040 the shared version of libgcc. */
2042 #ifndef inhibit_libc
2044 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2048 __eprintf (const char *string
, const char *expression
,
2049 unsigned int line
, const char *filename
)
2051 fprintf (stderr
, string
, expression
, line
, filename
);
2060 #ifdef L_clear_cache
2061 /* Clear part of an instruction cache. */
2064 __clear_cache (char *beg
__attribute__((__unused__
)),
2065 char *end
__attribute__((__unused__
)))
2067 #ifdef CLEAR_INSN_CACHE
2068 CLEAR_INSN_CACHE (beg
, end
);
2069 #endif /* CLEAR_INSN_CACHE */
2072 #endif /* L_clear_cache */
2076 /* Jump to a trampoline, loading the static chain address. */
2078 #if defined(WINNT) && ! defined(__CYGWIN__)
2079 #include <windows.h>
2080 int getpagesize (void);
2081 int mprotect (char *,int, int);
2094 mprotect (char *addr
, int len
, int prot
)
2113 if (VirtualProtect (addr
, len
, np
, &op
))
2119 #endif /* WINNT && ! __CYGWIN__ */
2121 #ifdef TRANSFER_FROM_TRAMPOLINE
2122 TRANSFER_FROM_TRAMPOLINE
2124 #endif /* L_trampoline */
2129 #include "gbl-ctors.h"
2131 /* Some systems use __main in a way incompatible with its use in gcc, in these
2132 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2133 give the same symbol without quotes for an alternative entry point. You
2134 must define both, or neither. */
2136 #define NAME__MAIN "__main"
2137 #define SYMBOL__MAIN __main
2140 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2141 #undef HAS_INIT_SECTION
2142 #define HAS_INIT_SECTION
2145 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2147 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2148 code to run constructors. In that case, we need to handle EH here, too. */
2150 #ifdef EH_FRAME_SECTION_NAME
2151 #include "unwind-dw2-fde.h"
2152 extern unsigned char __EH_FRAME_BEGIN__
[];
2155 /* Run all the global destructors on exit from the program. */
2158 __do_global_dtors (void)
2160 #ifdef DO_GLOBAL_DTORS_BODY
2161 DO_GLOBAL_DTORS_BODY
;
2163 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2170 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2172 static int completed
= 0;
2176 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2183 #ifndef HAS_INIT_SECTION
2184 /* Run all the global constructors on entry to the program. */
2187 __do_global_ctors (void)
2189 #ifdef EH_FRAME_SECTION_NAME
2191 static struct object object
;
2192 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2195 DO_GLOBAL_CTORS_BODY
;
2196 atexit (__do_global_dtors
);
2198 #endif /* no HAS_INIT_SECTION */
2200 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2201 /* Subroutine called automatically by `main'.
2202 Compiling a global function named `main'
2203 produces an automatic call to this function at the beginning.
2205 For many systems, this routine calls __do_global_ctors.
2206 For systems which support a .init section we use the .init section
2207 to run __do_global_ctors, so we need not do anything here. */
2209 extern void SYMBOL__MAIN (void);
2213 /* Support recursive calls to `main': run initializers just once. */
2214 static int initialized
;
2218 __do_global_ctors ();
2221 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2223 #endif /* L__main */
2224 #endif /* __CYGWIN__ */
2228 #include "gbl-ctors.h"
2230 /* Provide default definitions for the lists of constructors and
2231 destructors, so that we don't get linker errors. These symbols are
2232 intentionally bss symbols, so that gld and/or collect will provide
2233 the right values. */
2235 /* We declare the lists here with two elements each,
2236 so that they are valid empty lists if no other definition is loaded.
2238 If we are using the old "set" extensions to have the gnu linker
2239 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2240 must be in the bss/common section.
2242 Long term no port should use those extensions. But many still do. */
2243 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2244 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2245 func_ptr __CTOR_LIST__
[2] = {0, 0};
2246 func_ptr __DTOR_LIST__
[2] = {0, 0};
2248 func_ptr __CTOR_LIST__
[2];
2249 func_ptr __DTOR_LIST__
[2];
2251 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2252 #endif /* L_ctors */
2253 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */