1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2013 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
30 #include "libgcc_tm.h"
32 #ifdef HAVE_GAS_HIDDEN
33 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
35 #define ATTRIBUTE_HIDDEN
38 /* Work out the largest "word" size that we can deal with on this target. */
39 #if MIN_UNITS_PER_WORD > 4
40 # define LIBGCC2_MAX_UNITS_PER_WORD 8
41 #elif (MIN_UNITS_PER_WORD > 2 \
42 || (MIN_UNITS_PER_WORD > 1 && __SIZEOF_LONG_LONG__ > 4))
43 # define LIBGCC2_MAX_UNITS_PER_WORD 4
45 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
48 /* Work out what word size we are using for this compilation.
49 The value can be set on the command line. */
50 #ifndef LIBGCC2_UNITS_PER_WORD
51 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
54 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
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
= (UWtype
) a
+ (UWtype
) 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
= (USItype
) a
+ (USItype
) 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
= (UDWtype
) a
+ (UDWtype
) b
;
105 if (b
>= 0 ? w
< a
: w
> a
)
114 __subvSI3 (Wtype a
, Wtype b
)
116 const Wtype w
= (UWtype
) a
- (UWtype
) 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
= (USItype
) a
- (USItype
) 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
= (UDWtype
) a
- (UDWtype
) 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 */
181 const Wtype w
= -(UWtype
) a
;
183 if (a
>= 0 ? w
> 0 : w
< 0)
188 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
192 const SItype w
= -(USItype
) a
;
194 if (a
>= 0 ? w
> 0 : w
< 0)
199 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
206 const DWtype w
= -(UDWtype
) a
;
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 shift_count_type is smaller than an int. */
403 __lshrdi3 (DWtype u
, shift_count_type b
)
408 const DWunion uu
= {.ll
= u
};
409 const shift_count_type bm
= W_TYPE_SIZE
- 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
, shift_count_type b
)
436 const DWunion uu
= {.ll
= u
};
437 const shift_count_type bm
= W_TYPE_SIZE
- 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
, shift_count_type b
)
464 const DWunion uu
= {.ll
= u
};
465 const shift_count_type bm
= W_TYPE_SIZE
- b
;
470 /* w.s.high = 1..1 or 0..0 */
471 w
.s
.high
= uu
.s
.high
>> (W_TYPE_SIZE
- 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
;
488 __bswapsi2 (SItype u
)
490 return ((((u
) & 0xff000000) >> 24)
491 | (((u
) & 0x00ff0000) >> 8)
492 | (((u
) & 0x0000ff00) << 8)
493 | (((u
) & 0x000000ff) << 24));
498 __bswapdi2 (DItype u
)
500 return ((((u
) & 0xff00000000000000ull
) >> 56)
501 | (((u
) & 0x00ff000000000000ull
) >> 40)
502 | (((u
) & 0x0000ff0000000000ull
) >> 24)
503 | (((u
) & 0x000000ff00000000ull
) >> 8)
504 | (((u
) & 0x00000000ff000000ull
) << 8)
505 | (((u
) & 0x0000000000ff0000ull
) << 24)
506 | (((u
) & 0x000000000000ff00ull
) << 40)
507 | (((u
) & 0x00000000000000ffull
) << 56));
520 count_trailing_zeros (count
, u
);
530 const DWunion uu
= {.ll
= u
};
531 UWtype word
, count
, add
;
534 word
= uu
.s
.low
, add
= 0;
535 else if (uu
.s
.high
!= 0)
536 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
540 count_trailing_zeros (count
, word
);
541 return count
+ add
+ 1;
547 __muldi3 (DWtype u
, DWtype v
)
549 const DWunion uu
= {.ll
= u
};
550 const DWunion vv
= {.ll
= v
};
551 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
553 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
554 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
560 #if (defined (L_udivdi3) || defined (L_divdi3) || \
561 defined (L_umoddi3) || defined (L_moddi3))
562 #if defined (sdiv_qrnnd)
563 #define L_udiv_w_sdiv
568 #if defined (sdiv_qrnnd)
569 #if (defined (L_udivdi3) || defined (L_divdi3) || \
570 defined (L_umoddi3) || defined (L_moddi3))
571 static inline __attribute__ ((__always_inline__
))
574 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
581 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
583 /* Dividend, divisor, and quotient are nonnegative. */
584 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
588 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
589 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
590 /* Divide (c1*2^32 + c0) by d. */
591 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
592 /* Add 2^31 to quotient. */
593 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
598 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
599 c1
= a1
>> 1; /* A/2 */
600 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
602 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
604 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
606 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
623 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
626 c0
= ~c0
; /* logical NOT */
628 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
630 q
= ~q
; /* (A/2)/b1 */
633 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
651 else /* Implies c1 = b1 */
652 { /* Hence a1 = d - 1 = 2*b1 - 1 */
670 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
672 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
673 UWtype a1
__attribute__ ((__unused__
)),
674 UWtype a0
__attribute__ ((__unused__
)),
675 UWtype d
__attribute__ ((__unused__
)))
682 #if (defined (L_udivdi3) || defined (L_divdi3) || \
683 defined (L_umoddi3) || defined (L_moddi3))
688 const UQItype __clz_tab
[256] =
690 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,
691 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,
692 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,
693 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,
694 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,
695 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,
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
708 count_leading_zeros (ret
, x
);
719 const DWunion uu
= {.ll
= x
};
724 word
= uu
.s
.high
, add
= 0;
726 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
728 count_leading_zeros (ret
, word
);
740 count_trailing_zeros (ret
, x
);
751 const DWunion uu
= {.ll
= x
};
756 word
= uu
.s
.low
, add
= 0;
758 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
760 count_trailing_zeros (ret
, word
);
775 return W_TYPE_SIZE
- 1;
776 count_leading_zeros (ret
, x
);
784 __clrsbDI2 (DWtype x
)
786 const DWunion uu
= {.ll
= x
};
791 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
792 else if (uu
.s
.high
== -1)
793 word
= ~uu
.s
.low
, add
= W_TYPE_SIZE
;
794 else if (uu
.s
.high
>= 0)
795 word
= uu
.s
.high
, add
= 0;
797 word
= ~uu
.s
.high
, add
= 0;
802 count_leading_zeros (ret
, word
);
804 return ret
+ add
- 1;
808 #ifdef L_popcount_tab
809 const UQItype __popcount_tab
[256] =
811 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,
812 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,
813 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,
814 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,
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 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,
818 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
822 #if defined(L_popcountsi2) || defined(L_popcountdi2)
823 #define POPCOUNTCST2(x) (((UWtype) x << BITS_PER_UNIT) | x)
824 #define POPCOUNTCST4(x) (((UWtype) x << (2 * BITS_PER_UNIT)) | x)
825 #define POPCOUNTCST8(x) (((UWtype) x << (4 * BITS_PER_UNIT)) | x)
826 #if W_TYPE_SIZE == BITS_PER_UNIT
827 #define POPCOUNTCST(x) x
828 #elif W_TYPE_SIZE == 2 * BITS_PER_UNIT
829 #define POPCOUNTCST(x) POPCOUNTCST2 (x)
830 #elif W_TYPE_SIZE == 4 * BITS_PER_UNIT
831 #define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
832 #elif W_TYPE_SIZE == 8 * BITS_PER_UNIT
833 #define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
840 __popcountSI2 (UWtype x
)
842 /* Force table lookup on targets like AVR and RL78 which only
843 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
844 have 1, and other small word targets. */
845 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && BITS_PER_UNIT == 8
846 x
= x
- ((x
>> 1) & POPCOUNTCST (0x55));
847 x
= (x
& POPCOUNTCST (0x33)) + ((x
>> 2) & POPCOUNTCST (0x33));
848 x
= (x
+ (x
>> 4)) & POPCOUNTCST (0x0F);
849 return (x
* POPCOUNTCST (0x01)) >> (W_TYPE_SIZE
- BITS_PER_UNIT
);
853 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
854 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
864 __popcountDI2 (UDWtype x
)
866 /* Force table lookup on targets like AVR and RL78 which only
867 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
868 have 1, and other small word targets. */
869 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && BITS_PER_UNIT == 8
870 const DWunion uu
= {.ll
= x
};
871 UWtype x1
= uu
.s
.low
, x2
= uu
.s
.high
;
872 x1
= x1
- ((x1
>> 1) & POPCOUNTCST (0x55));
873 x2
= x2
- ((x2
>> 1) & POPCOUNTCST (0x55));
874 x1
= (x1
& POPCOUNTCST (0x33)) + ((x1
>> 2) & POPCOUNTCST (0x33));
875 x2
= (x2
& POPCOUNTCST (0x33)) + ((x2
>> 2) & POPCOUNTCST (0x33));
876 x1
= (x1
+ (x1
>> 4)) & POPCOUNTCST (0x0F);
877 x2
= (x2
+ (x2
>> 4)) & POPCOUNTCST (0x0F);
879 return (x1
* POPCOUNTCST (0x01)) >> (W_TYPE_SIZE
- BITS_PER_UNIT
);
883 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
884 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
894 __paritySI2 (UWtype x
)
897 # error "fill out the table"
908 return (0x6996 >> x
) & 1;
915 __parityDI2 (UDWtype x
)
917 const DWunion uu
= {.ll
= x
};
918 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
921 # error "fill out the table"
932 return (0x6996 >> nx
) & 1;
938 #if (defined (L_udivdi3) || defined (L_divdi3) || \
939 defined (L_umoddi3) || defined (L_moddi3))
940 static inline __attribute__ ((__always_inline__
))
943 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
945 const DWunion nn
= {.ll
= n
};
946 const DWunion dd
= {.ll
= d
};
948 UWtype d0
, d1
, n0
, n1
, n2
;
957 #if !UDIV_NEEDS_NORMALIZATION
964 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
967 /* Remainder in n0. */
974 d0
= 1 / d0
; /* Divide intentionally by zero. */
976 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
977 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
979 /* Remainder in n0. */
990 #else /* UDIV_NEEDS_NORMALIZATION */
998 count_leading_zeros (bm
, d0
);
1002 /* Normalize, i.e. make the most significant bit of the
1006 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
1010 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1013 /* Remainder in n0 >> bm. */
1020 d0
= 1 / d0
; /* Divide intentionally by zero. */
1022 count_leading_zeros (bm
, d0
);
1026 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
1027 conclude (the most significant bit of n1 is set) /\ (the
1028 leading quotient digit q1 = 1).
1030 This special case is necessary, not an optimization.
1031 (Shifts counts of W_TYPE_SIZE are undefined.) */
1040 b
= W_TYPE_SIZE
- bm
;
1044 n1
= (n1
<< bm
) | (n0
>> b
);
1047 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
1052 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1054 /* Remainder in n0 >> bm. */
1059 rr
.s
.low
= n0
>> bm
;
1064 #endif /* UDIV_NEEDS_NORMALIZATION */
1075 /* Remainder in n1n0. */
1087 count_leading_zeros (bm
, d1
);
1090 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1091 conclude (the most significant bit of n1 is set) /\ (the
1092 quotient digit q0 = 0 or 1).
1094 This special case is necessary, not an optimization. */
1096 /* The condition on the next line takes advantage of that
1097 n1 >= d1 (true due to program flow). */
1098 if (n1
> d1
|| n0
>= d0
)
1101 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1120 b
= W_TYPE_SIZE
- bm
;
1122 d1
= (d1
<< bm
) | (d0
>> b
);
1125 n1
= (n1
<< bm
) | (n0
>> b
);
1128 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1129 umul_ppmm (m1
, m0
, q0
, d0
);
1131 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1134 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1139 /* Remainder in (n1n0 - m1m0) >> bm. */
1142 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1143 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1144 rr
.s
.high
= n1
>> bm
;
1151 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1158 __divdi3 (DWtype u
, DWtype v
)
1161 DWunion uu
= {.ll
= u
};
1162 DWunion vv
= {.ll
= v
};
1172 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1182 __moddi3 (DWtype u
, DWtype v
)
1185 DWunion uu
= {.ll
= u
};
1186 DWunion vv
= {.ll
= v
};
1195 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1205 __umoddi3 (UDWtype u
, UDWtype v
)
1209 (void) __udivmoddi4 (u
, v
, &w
);
1217 __udivdi3 (UDWtype n
, UDWtype d
)
1219 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1225 __cmpdi2 (DWtype a
, DWtype b
)
1227 const DWunion au
= {.ll
= a
};
1228 const DWunion bu
= {.ll
= b
};
1230 if (au
.s
.high
< bu
.s
.high
)
1232 else if (au
.s
.high
> bu
.s
.high
)
1234 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1236 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1244 __ucmpdi2 (DWtype a
, DWtype b
)
1246 const DWunion au
= {.ll
= a
};
1247 const DWunion bu
= {.ll
= b
};
1249 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1251 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1253 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1255 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1261 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1263 __fixunstfDI (TFtype a
)
1268 /* Compute high word of result, as a flonum. */
1269 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1270 /* Convert that to fixed (but not to DWtype!),
1271 and shift it into the high word. */
1272 UDWtype v
= (UWtype
) b
;
1274 /* Remove high part from the TFtype, leaving the low part as flonum. */
1276 /* Convert that to fixed (but not to DWtype!) and add it in.
1277 Sometimes A comes out negative. This is significant, since
1278 A has more bits than a long int does. */
1280 v
-= (UWtype
) (- a
);
1287 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1289 __fixtfdi (TFtype a
)
1292 return - __fixunstfDI (-a
);
1293 return __fixunstfDI (a
);
1297 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1299 __fixunsxfDI (XFtype a
)
1304 /* Compute high word of result, as a flonum. */
1305 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1306 /* Convert that to fixed (but not to DWtype!),
1307 and shift it into the high word. */
1308 UDWtype v
= (UWtype
) b
;
1310 /* Remove high part from the XFtype, leaving the low part as flonum. */
1312 /* Convert that to fixed (but not to DWtype!) and add it in.
1313 Sometimes A comes out negative. This is significant, since
1314 A has more bits than a long int does. */
1316 v
-= (UWtype
) (- a
);
1323 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1325 __fixxfdi (XFtype a
)
1328 return - __fixunsxfDI (-a
);
1329 return __fixunsxfDI (a
);
1333 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1335 __fixunsdfDI (DFtype a
)
1337 /* Get high part of result. The division here will just moves the radix
1338 point and will not cause any rounding. Then the conversion to integral
1339 type chops result as desired. */
1340 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1342 /* Get low part of result. Convert `hi' to floating type and scale it back,
1343 then subtract this from the number being converted. This leaves the low
1344 part. Convert that to integral type. */
1345 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1347 /* Assemble result from the two parts. */
1348 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1352 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1354 __fixdfdi (DFtype a
)
1357 return - __fixunsdfDI (-a
);
1358 return __fixunsdfDI (a
);
1362 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1364 __fixunssfDI (SFtype a
)
1366 #if LIBGCC2_HAS_DF_MODE
1367 /* Convert the SFtype to a DFtype, because that is surely not going
1368 to lose any bits. Some day someone else can write a faster version
1369 that avoids converting to DFtype, and verify it really works right. */
1370 const DFtype dfa
= a
;
1372 /* Get high part of result. The division here will just moves the radix
1373 point and will not cause any rounding. Then the conversion to integral
1374 type chops result as desired. */
1375 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1377 /* Get low part of result. Convert `hi' to floating type and scale it back,
1378 then subtract this from the number being converted. This leaves the low
1379 part. Convert that to integral type. */
1380 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1382 /* Assemble result from the two parts. */
1383 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1384 #elif FLT_MANT_DIG < W_TYPE_SIZE
1387 if (a
< Wtype_MAXp1_F
)
1389 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1391 /* Since we know that there are fewer significant bits in the SFmode
1392 quantity than in a word, we know that we can convert out all the
1393 significant bits in one step, and thus avoid losing bits. */
1395 /* ??? This following loop essentially performs frexpf. If we could
1396 use the real libm function, or poke at the actual bits of the fp
1397 format, it would be significantly faster. */
1399 UWtype shift
= 0, counter
;
1403 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1405 SFtype counterf
= (UWtype
)1 << counter
;
1413 /* Rescale into the range of one word, extract the bits of that
1414 one word, and shift the result into position. */
1417 return (DWtype
)counter
<< shift
;
1426 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1428 __fixsfdi (SFtype a
)
1431 return - __fixunssfDI (-a
);
1432 return __fixunssfDI (a
);
1436 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1438 __floatdixf (DWtype u
)
1440 #if W_TYPE_SIZE > XF_SIZE
1443 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1450 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1452 __floatundixf (UDWtype u
)
1454 #if W_TYPE_SIZE > XF_SIZE
1457 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1464 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1466 __floatditf (DWtype u
)
1468 #if W_TYPE_SIZE > TF_SIZE
1471 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1478 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1480 __floatunditf (UDWtype u
)
1482 #if W_TYPE_SIZE > TF_SIZE
1485 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1492 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1493 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1494 #define DI_SIZE (W_TYPE_SIZE * 2)
1495 #define F_MODE_OK(SIZE) \
1497 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1498 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1499 #if defined(L_floatdisf)
1500 #define FUNC __floatdisf
1501 #define FSTYPE SFtype
1502 #define FSSIZE SF_SIZE
1504 #define FUNC __floatdidf
1505 #define FSTYPE DFtype
1506 #define FSSIZE DF_SIZE
1512 #if FSSIZE >= W_TYPE_SIZE
1513 /* When the word size is small, we never get any rounding error. */
1514 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1518 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1519 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1520 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1522 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1523 # define FSIZE DF_SIZE
1524 # define FTYPE DFtype
1525 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1526 # define FSIZE XF_SIZE
1527 # define FTYPE XFtype
1528 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1529 # define FSIZE TF_SIZE
1530 # define FTYPE TFtype
1535 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1537 /* Protect against double-rounding error.
1538 Represent any low-order bits, that might be truncated by a bit that
1539 won't be lost. The bit can go in anywhere below the rounding position
1540 of the FSTYPE. A fixed mask and bit position handles all usual
1542 if (! (- ((DWtype
) 1 << FSIZE
) < u
1543 && u
< ((DWtype
) 1 << FSIZE
)))
1545 if ((UDWtype
) u
& (REP_BIT
- 1))
1547 u
&= ~ (REP_BIT
- 1);
1552 /* Do the calculation in a wider type so that we don't lose any of
1553 the precision of the high word while multiplying it. */
1554 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1559 #if FSSIZE >= W_TYPE_SIZE - 2
1562 /* Finally, the word size is larger than the number of bits in the
1563 required FSTYPE, and we've got no suitable wider type. The only
1564 way to avoid double rounding is to special case the
1567 /* If there are no high bits set, fall back to one conversion. */
1569 return (FSTYPE
)(Wtype
)u
;
1571 /* Otherwise, find the power of two. */
1572 Wtype hi
= u
>> W_TYPE_SIZE
;
1576 UWtype count
, shift
;
1577 count_leading_zeros (count
, hi
);
1579 /* No leading bits means u == minimum. */
1581 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1583 shift
= 1 + W_TYPE_SIZE
- count
;
1585 /* Shift down the most significant bits. */
1588 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1589 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1592 /* Convert the one word of data, and rescale. */
1594 if (shift
== W_TYPE_SIZE
)
1596 /* The following two cases could be merged if we knew that the target
1597 supported a native unsigned->float conversion. More often, we only
1598 have a signed conversion, and have to add extra fixup code. */
1599 else if (shift
== W_TYPE_SIZE
- 1)
1600 e
= Wtype_MAXp1_F
/ 2;
1602 e
= (Wtype
)1 << shift
;
1608 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1609 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1610 #define DI_SIZE (W_TYPE_SIZE * 2)
1611 #define F_MODE_OK(SIZE) \
1613 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1614 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1615 #if defined(L_floatundisf)
1616 #define FUNC __floatundisf
1617 #define FSTYPE SFtype
1618 #define FSSIZE SF_SIZE
1620 #define FUNC __floatundidf
1621 #define FSTYPE DFtype
1622 #define FSSIZE DF_SIZE
1628 #if FSSIZE >= W_TYPE_SIZE
1629 /* When the word size is small, we never get any rounding error. */
1630 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1634 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1635 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1636 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1638 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1639 # define FSIZE DF_SIZE
1640 # define FTYPE DFtype
1641 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1642 # define FSIZE XF_SIZE
1643 # define FTYPE XFtype
1644 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1645 # define FSIZE TF_SIZE
1646 # define FTYPE TFtype
1651 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1653 /* Protect against double-rounding error.
1654 Represent any low-order bits, that might be truncated by a bit that
1655 won't be lost. The bit can go in anywhere below the rounding position
1656 of the FSTYPE. A fixed mask and bit position handles all usual
1658 if (u
>= ((UDWtype
) 1 << FSIZE
))
1660 if ((UDWtype
) u
& (REP_BIT
- 1))
1662 u
&= ~ (REP_BIT
- 1);
1667 /* Do the calculation in a wider type so that we don't lose any of
1668 the precision of the high word while multiplying it. */
1669 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1674 #if FSSIZE == W_TYPE_SIZE - 1
1677 /* Finally, the word size is larger than the number of bits in the
1678 required FSTYPE, and we've got no suitable wider type. The only
1679 way to avoid double rounding is to special case the
1682 /* If there are no high bits set, fall back to one conversion. */
1684 return (FSTYPE
)(UWtype
)u
;
1686 /* Otherwise, find the power of two. */
1687 UWtype hi
= u
>> W_TYPE_SIZE
;
1689 UWtype count
, shift
;
1690 count_leading_zeros (count
, hi
);
1692 shift
= W_TYPE_SIZE
- count
;
1694 /* Shift down the most significant bits. */
1697 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1698 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1701 /* Convert the one word of data, and rescale. */
1703 if (shift
== W_TYPE_SIZE
)
1705 /* The following two cases could be merged if we knew that the target
1706 supported a native unsigned->float conversion. More often, we only
1707 have a signed conversion, and have to add extra fixup code. */
1708 else if (shift
== W_TYPE_SIZE
- 1)
1709 e
= Wtype_MAXp1_F
/ 2;
1711 e
= (Wtype
)1 << shift
;
1717 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1719 __fixunsxfSI (XFtype a
)
1721 if (a
>= - (DFtype
) Wtype_MIN
)
1722 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1727 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1729 __fixunsdfSI (DFtype a
)
1731 if (a
>= - (DFtype
) Wtype_MIN
)
1732 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1737 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1739 __fixunssfSI (SFtype a
)
1741 if (a
>= - (SFtype
) Wtype_MIN
)
1742 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1747 /* Integer power helper used from __builtin_powi for non-constant
1750 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1751 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1752 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1753 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1754 # if defined(L_powisf2)
1755 # define TYPE SFtype
1756 # define NAME __powisf2
1757 # elif defined(L_powidf2)
1758 # define TYPE DFtype
1759 # define NAME __powidf2
1760 # elif defined(L_powixf2)
1761 # define TYPE XFtype
1762 # define NAME __powixf2
1763 # elif defined(L_powitf2)
1764 # define TYPE TFtype
1765 # define NAME __powitf2
1771 NAME (TYPE x
, int m
)
1773 unsigned int n
= m
< 0 ? -m
: m
;
1774 TYPE y
= n
% 2 ? x
: 1;
1781 return m
< 0 ? 1/y
: y
;
1786 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1787 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1788 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1789 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1795 #if defined(L_mulsc3) || defined(L_divsc3)
1796 # define MTYPE SFtype
1797 # define CTYPE SCtype
1800 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1801 #elif defined(L_muldc3) || defined(L_divdc3)
1802 # define MTYPE DFtype
1803 # define CTYPE DCtype
1805 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1810 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1812 #elif defined(L_mulxc3) || defined(L_divxc3)
1813 # define MTYPE XFtype
1814 # define CTYPE XCtype
1818 #elif defined(L_multc3) || defined(L_divtc3)
1819 # define MTYPE TFtype
1820 # define CTYPE TCtype
1822 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
1825 # define CEXT LIBGCC2_TF_CEXT
1832 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1833 #define _CONCAT3(A,B,C) A##B##C
1835 #define CONCAT2(A,B) _CONCAT2(A,B)
1836 #define _CONCAT2(A,B) A##B
1838 /* All of these would be present in a full C99 implementation of <math.h>
1839 and <complex.h>. Our problem is that only a few systems have such full
1840 implementations. Further, libgcc_s.so isn't currently linked against
1841 libm.so, and even for systems that do provide full C99, the extra overhead
1842 of all programs using libgcc having to link against libm. So avoid it. */
1844 #define isnan(x) __builtin_expect ((x) != (x), 0)
1845 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1846 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1848 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1851 /* Helpers to make the following code slightly less gross. */
1852 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1853 #define FABS CONCAT2(__builtin_fabs, CEXT)
1855 /* Verify that MTYPE matches up with CEXT. */
1856 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1858 /* Ensure that we've lost any extra precision. */
1862 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1865 #if defined(L_mulsc3) || defined(L_muldc3) \
1866 || defined(L_mulxc3) || defined(L_multc3)
1869 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1871 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1887 if (isnan (x
) && isnan (y
))
1889 /* Recover infinities that computed as NaN + iNaN. */
1891 if (isinf (a
) || isinf (b
))
1893 /* z is infinite. "Box" the infinity and change NaNs in
1894 the other factor to 0. */
1895 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1896 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1897 if (isnan (c
)) c
= COPYSIGN (0, c
);
1898 if (isnan (d
)) d
= COPYSIGN (0, d
);
1901 if (isinf (c
) || isinf (d
))
1903 /* w is infinite. "Box" the infinity and change NaNs in
1904 the other factor to 0. */
1905 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1906 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1907 if (isnan (a
)) a
= COPYSIGN (0, a
);
1908 if (isnan (b
)) b
= COPYSIGN (0, b
);
1912 && (isinf (ac
) || isinf (bd
)
1913 || isinf (ad
) || isinf (bc
)))
1915 /* Recover infinities from overflow by changing NaNs to 0. */
1916 if (isnan (a
)) a
= COPYSIGN (0, a
);
1917 if (isnan (b
)) b
= COPYSIGN (0, b
);
1918 if (isnan (c
)) c
= COPYSIGN (0, c
);
1919 if (isnan (d
)) d
= COPYSIGN (0, d
);
1924 x
= INFINITY
* (a
* c
- b
* d
);
1925 y
= INFINITY
* (a
* d
+ b
* c
);
1933 #endif /* complex multiply */
1935 #if defined(L_divsc3) || defined(L_divdc3) \
1936 || defined(L_divxc3) || defined(L_divtc3)
1939 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1941 MTYPE denom
, ratio
, x
, y
;
1944 /* ??? We can get better behavior from logarithmic scaling instead of
1945 the division. But that would mean starting to link libgcc against
1946 libm. We could implement something akin to ldexp/frexp as gcc builtins
1948 if (FABS (c
) < FABS (d
))
1951 denom
= (c
* ratio
) + d
;
1952 x
= ((a
* ratio
) + b
) / denom
;
1953 y
= ((b
* ratio
) - a
) / denom
;
1958 denom
= (d
* ratio
) + c
;
1959 x
= ((b
* ratio
) + a
) / denom
;
1960 y
= (b
- (a
* ratio
)) / denom
;
1963 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1964 are nonzero/zero, infinite/finite, and finite/infinite. */
1965 if (isnan (x
) && isnan (y
))
1967 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
1969 x
= COPYSIGN (INFINITY
, c
) * a
;
1970 y
= COPYSIGN (INFINITY
, c
) * b
;
1972 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1974 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1975 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1976 x
= INFINITY
* (a
* c
+ b
* d
);
1977 y
= INFINITY
* (b
* c
- a
* d
);
1979 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1981 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1982 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1983 x
= 0.0 * (a
* c
+ b
* d
);
1984 y
= 0.0 * (b
* c
- a
* d
);
1992 #endif /* complex divide */
1994 #endif /* all complex float routines */
1996 /* From here on down, the routines use normal data types. */
1998 #define SItype bogus_type
1999 #define USItype bogus_type
2000 #define DItype bogus_type
2001 #define UDItype bogus_type
2002 #define SFtype bogus_type
2003 #define DFtype bogus_type
2021 /* Like bcmp except the sign is meaningful.
2022 Result is negative if S1 is less than S2,
2023 positive if S1 is greater, 0 if S1 and S2 are equal. */
2026 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
2030 const unsigned char c1
= *s1
++, c2
= *s2
++;
2040 /* __eprintf used to be used by GCC's private version of <assert.h>.
2041 We no longer provide that header, but this routine remains in libgcc.a
2042 for binary backward compatibility. Note that it is not included in
2043 the shared version of libgcc. */
2045 #ifndef inhibit_libc
2047 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2051 __eprintf (const char *string
, const char *expression
,
2052 unsigned int line
, const char *filename
)
2054 fprintf (stderr
, string
, expression
, line
, filename
);
2063 #ifdef L_clear_cache
2064 /* Clear part of an instruction cache. */
2067 __clear_cache (char *beg
__attribute__((__unused__
)),
2068 char *end
__attribute__((__unused__
)))
2070 #ifdef CLEAR_INSN_CACHE
2071 CLEAR_INSN_CACHE (beg
, end
);
2072 #endif /* CLEAR_INSN_CACHE */
2075 #endif /* L_clear_cache */
2079 /* Jump to a trampoline, loading the static chain address. */
2081 #if defined(WINNT) && ! defined(__CYGWIN__)
2082 #include <windows.h>
2083 int getpagesize (void);
2084 int mprotect (char *,int, int);
2097 mprotect (char *addr
, int len
, int prot
)
2116 if (VirtualProtect (addr
, len
, np
, &op
))
2122 #endif /* WINNT && ! __CYGWIN__ */
2124 #ifdef TRANSFER_FROM_TRAMPOLINE
2125 TRANSFER_FROM_TRAMPOLINE
2127 #endif /* L_trampoline */
2132 #include "gbl-ctors.h"
2134 /* Some systems use __main in a way incompatible with its use in gcc, in these
2135 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2136 give the same symbol without quotes for an alternative entry point. You
2137 must define both, or neither. */
2139 #define NAME__MAIN "__main"
2140 #define SYMBOL__MAIN __main
2143 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2144 #undef HAS_INIT_SECTION
2145 #define HAS_INIT_SECTION
2148 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2150 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2151 code to run constructors. In that case, we need to handle EH here, too. */
2153 #ifdef EH_FRAME_SECTION_NAME
2154 #include "unwind-dw2-fde.h"
2155 extern unsigned char __EH_FRAME_BEGIN__
[];
2158 /* Run all the global destructors on exit from the program. */
2161 __do_global_dtors (void)
2163 #ifdef DO_GLOBAL_DTORS_BODY
2164 DO_GLOBAL_DTORS_BODY
;
2166 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2173 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2175 static int completed
= 0;
2179 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2186 #ifndef HAS_INIT_SECTION
2187 /* Run all the global constructors on entry to the program. */
2190 __do_global_ctors (void)
2192 #ifdef EH_FRAME_SECTION_NAME
2194 static struct object object
;
2195 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2198 DO_GLOBAL_CTORS_BODY
;
2199 atexit (__do_global_dtors
);
2201 #endif /* no HAS_INIT_SECTION */
2203 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2204 /* Subroutine called automatically by `main'.
2205 Compiling a global function named `main'
2206 produces an automatic call to this function at the beginning.
2208 For many systems, this routine calls __do_global_ctors.
2209 For systems which support a .init section we use the .init section
2210 to run __do_global_ctors, so we need not do anything here. */
2212 extern void SYMBOL__MAIN (void);
2216 /* Support recursive calls to `main': run initializers just once. */
2217 static int initialized
;
2221 __do_global_ctors ();
2224 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2226 #endif /* L__main */
2227 #endif /* __CYGWIN__ */
2231 #include "gbl-ctors.h"
2233 /* Provide default definitions for the lists of constructors and
2234 destructors, so that we don't get linker errors. These symbols are
2235 intentionally bss symbols, so that gld and/or collect will provide
2236 the right values. */
2238 /* We declare the lists here with two elements each,
2239 so that they are valid empty lists if no other definition is loaded.
2241 If we are using the old "set" extensions to have the gnu linker
2242 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2243 must be in the bss/common section.
2245 Long term no port should use those extensions. But many still do. */
2246 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2247 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2248 func_ptr __CTOR_LIST__
[2] = {0, 0};
2249 func_ptr __DTOR_LIST__
[2] = {0, 0};
2251 func_ptr __CTOR_LIST__
[2];
2252 func_ptr __DTOR_LIST__
[2];
2254 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2255 #endif /* L_ctors */
2256 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */