1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2016 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) * __CHAR_BIT__)
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) || \
684 defined (L_divmoddi4))
689 const UQItype __clz_tab
[256] =
691 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,
692 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,
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 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 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,
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
709 count_leading_zeros (ret
, x
);
720 const DWunion uu
= {.ll
= x
};
725 word
= uu
.s
.high
, add
= 0;
727 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
729 count_leading_zeros (ret
, word
);
741 count_trailing_zeros (ret
, x
);
752 const DWunion uu
= {.ll
= x
};
757 word
= uu
.s
.low
, add
= 0;
759 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
761 count_trailing_zeros (ret
, word
);
776 return W_TYPE_SIZE
- 1;
777 count_leading_zeros (ret
, x
);
785 __clrsbDI2 (DWtype x
)
787 const DWunion uu
= {.ll
= x
};
792 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
793 else if (uu
.s
.high
== -1)
794 word
= ~uu
.s
.low
, add
= W_TYPE_SIZE
;
795 else if (uu
.s
.high
>= 0)
796 word
= uu
.s
.high
, add
= 0;
798 word
= ~uu
.s
.high
, add
= 0;
803 count_leading_zeros (ret
, word
);
805 return ret
+ add
- 1;
809 #ifdef L_popcount_tab
810 const UQItype __popcount_tab
[256] =
812 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,
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 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 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,
816 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,
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 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 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
823 #if defined(L_popcountsi2) || defined(L_popcountdi2)
824 #define POPCOUNTCST2(x) (((UWtype) x << __CHAR_BIT__) | x)
825 #define POPCOUNTCST4(x) (((UWtype) x << (2 * __CHAR_BIT__)) | x)
826 #define POPCOUNTCST8(x) (((UWtype) x << (4 * __CHAR_BIT__)) | x)
827 #if W_TYPE_SIZE == __CHAR_BIT__
828 #define POPCOUNTCST(x) x
829 #elif W_TYPE_SIZE == 2 * __CHAR_BIT__
830 #define POPCOUNTCST(x) POPCOUNTCST2 (x)
831 #elif W_TYPE_SIZE == 4 * __CHAR_BIT__
832 #define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
833 #elif W_TYPE_SIZE == 8 * __CHAR_BIT__
834 #define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
841 __popcountSI2 (UWtype x
)
843 /* Force table lookup on targets like AVR and RL78 which only
844 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
845 have 1, and other small word targets. */
846 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
847 x
= x
- ((x
>> 1) & POPCOUNTCST (0x55));
848 x
= (x
& POPCOUNTCST (0x33)) + ((x
>> 2) & POPCOUNTCST (0x33));
849 x
= (x
+ (x
>> 4)) & POPCOUNTCST (0x0F);
850 return (x
* POPCOUNTCST (0x01)) >> (W_TYPE_SIZE
- __CHAR_BIT__
);
854 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
855 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
865 __popcountDI2 (UDWtype x
)
867 /* Force table lookup on targets like AVR and RL78 which only
868 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
869 have 1, and other small word targets. */
870 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
871 const DWunion uu
= {.ll
= x
};
872 UWtype x1
= uu
.s
.low
, x2
= uu
.s
.high
;
873 x1
= x1
- ((x1
>> 1) & POPCOUNTCST (0x55));
874 x2
= x2
- ((x2
>> 1) & POPCOUNTCST (0x55));
875 x1
= (x1
& POPCOUNTCST (0x33)) + ((x1
>> 2) & POPCOUNTCST (0x33));
876 x2
= (x2
& POPCOUNTCST (0x33)) + ((x2
>> 2) & POPCOUNTCST (0x33));
877 x1
= (x1
+ (x1
>> 4)) & POPCOUNTCST (0x0F);
878 x2
= (x2
+ (x2
>> 4)) & POPCOUNTCST (0x0F);
880 return (x1
* POPCOUNTCST (0x01)) >> (W_TYPE_SIZE
- __CHAR_BIT__
);
884 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
885 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
895 __paritySI2 (UWtype x
)
898 # error "fill out the table"
909 return (0x6996 >> x
) & 1;
916 __parityDI2 (UDWtype x
)
918 const DWunion uu
= {.ll
= x
};
919 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
922 # error "fill out the table"
933 return (0x6996 >> nx
) & 1;
938 #ifdef TARGET_HAS_NO_HW_DIVIDE
940 #if (defined (L_udivdi3) || defined (L_divdi3) || \
941 defined (L_umoddi3) || defined (L_moddi3) || \
942 defined (L_divmoddi4))
943 static inline __attribute__ ((__always_inline__
))
946 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
948 UDWtype q
= 0, r
= n
, y
= d
;
949 UWtype lz1
, lz2
, i
, k
;
951 /* Implements align divisor shift dividend method. This algorithm
952 aligns the divisor under the dividend and then perform number of
953 test-subtract iterations which shift the dividend left. Number of
954 iterations is k + 1 where k is the number of bit positions the
955 divisor must be shifted left to align it under the dividend.
956 quotient bits can be saved in the rightmost positions of the dividend
957 as it shifts left on each test-subtract iteration. */
961 lz1
= __builtin_clzll (d
);
962 lz2
= __builtin_clzll (n
);
967 /* Dividend can exceed 2 ^ (width − 1) − 1 but still be less than the
968 aligned divisor. Normal iteration can drops the high order bit
969 of the dividend. Therefore, first test-subtract iteration is a
970 special case, saving its quotient bit in a separate location and
971 not shifting the dividend. */
982 /* k additional iterations where k regular test subtract shift
983 dividend iterations are done. */
988 r
= ((r
- y
) << 1) + 1;
994 /* First quotient bit is combined with the quotient bits resulting
995 from the k regular iterations. */
1008 #if (defined (L_udivdi3) || defined (L_divdi3) || \
1009 defined (L_umoddi3) || defined (L_moddi3) || \
1010 defined (L_divmoddi4))
1011 static inline __attribute__ ((__always_inline__
))
1014 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
1016 const DWunion nn
= {.ll
= n
};
1017 const DWunion dd
= {.ll
= d
};
1019 UWtype d0
, d1
, n0
, n1
, n2
;
1028 #if !UDIV_NEEDS_NORMALIZATION
1035 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1038 /* Remainder in n0. */
1045 d0
= 1 / d0
; /* Divide intentionally by zero. */
1047 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
1048 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1050 /* Remainder in n0. */
1061 #else /* UDIV_NEEDS_NORMALIZATION */
1069 count_leading_zeros (bm
, d0
);
1073 /* Normalize, i.e. make the most significant bit of the
1077 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
1081 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1084 /* Remainder in n0 >> bm. */
1091 d0
= 1 / d0
; /* Divide intentionally by zero. */
1093 count_leading_zeros (bm
, d0
);
1097 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
1098 conclude (the most significant bit of n1 is set) /\ (the
1099 leading quotient digit q1 = 1).
1101 This special case is necessary, not an optimization.
1102 (Shifts counts of W_TYPE_SIZE are undefined.) */
1111 b
= W_TYPE_SIZE
- bm
;
1115 n1
= (n1
<< bm
) | (n0
>> b
);
1118 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
1123 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1125 /* Remainder in n0 >> bm. */
1130 rr
.s
.low
= n0
>> bm
;
1135 #endif /* UDIV_NEEDS_NORMALIZATION */
1146 /* Remainder in n1n0. */
1158 count_leading_zeros (bm
, d1
);
1161 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1162 conclude (the most significant bit of n1 is set) /\ (the
1163 quotient digit q0 = 0 or 1).
1165 This special case is necessary, not an optimization. */
1167 /* The condition on the next line takes advantage of that
1168 n1 >= d1 (true due to program flow). */
1169 if (n1
> d1
|| n0
>= d0
)
1172 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1191 b
= W_TYPE_SIZE
- bm
;
1193 d1
= (d1
<< bm
) | (d0
>> b
);
1196 n1
= (n1
<< bm
) | (n0
>> b
);
1199 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1200 umul_ppmm (m1
, m0
, q0
, d0
);
1202 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1205 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1210 /* Remainder in (n1n0 - m1m0) >> bm. */
1213 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1214 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1215 rr
.s
.high
= n1
>> bm
;
1222 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1230 __divdi3 (DWtype u
, DWtype v
)
1233 DWunion uu
= {.ll
= u
};
1234 DWunion vv
= {.ll
= v
};
1244 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1254 __moddi3 (DWtype u
, DWtype v
)
1257 DWunion uu
= {.ll
= u
};
1258 DWunion vv
= {.ll
= v
};
1267 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1277 __divmoddi4 (DWtype u
, DWtype v
, DWtype
*rp
)
1279 Wtype c1
= 0, c2
= 0;
1280 DWunion uu
= {.ll
= u
};
1281 DWunion vv
= {.ll
= v
};
1292 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&r
);
1305 __umoddi3 (UDWtype u
, UDWtype v
)
1309 (void) __udivmoddi4 (u
, v
, &w
);
1317 __udivdi3 (UDWtype n
, UDWtype d
)
1319 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1325 __cmpdi2 (DWtype a
, DWtype b
)
1327 const DWunion au
= {.ll
= a
};
1328 const DWunion bu
= {.ll
= b
};
1330 if (au
.s
.high
< bu
.s
.high
)
1332 else if (au
.s
.high
> bu
.s
.high
)
1334 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1336 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1344 __ucmpdi2 (DWtype a
, DWtype b
)
1346 const DWunion au
= {.ll
= a
};
1347 const DWunion bu
= {.ll
= b
};
1349 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1351 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1353 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1355 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1361 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1363 __fixunstfDI (TFtype a
)
1368 /* Compute high word of result, as a flonum. */
1369 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1370 /* Convert that to fixed (but not to DWtype!),
1371 and shift it into the high word. */
1372 UDWtype v
= (UWtype
) b
;
1374 /* Remove high part from the TFtype, leaving the low part as flonum. */
1376 /* Convert that to fixed (but not to DWtype!) and add it in.
1377 Sometimes A comes out negative. This is significant, since
1378 A has more bits than a long int does. */
1380 v
-= (UWtype
) (- a
);
1387 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1389 __fixtfdi (TFtype a
)
1392 return - __fixunstfDI (-a
);
1393 return __fixunstfDI (a
);
1397 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1399 __fixunsxfDI (XFtype a
)
1404 /* Compute high word of result, as a flonum. */
1405 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1406 /* Convert that to fixed (but not to DWtype!),
1407 and shift it into the high word. */
1408 UDWtype v
= (UWtype
) b
;
1410 /* Remove high part from the XFtype, leaving the low part as flonum. */
1412 /* Convert that to fixed (but not to DWtype!) and add it in.
1413 Sometimes A comes out negative. This is significant, since
1414 A has more bits than a long int does. */
1416 v
-= (UWtype
) (- a
);
1423 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1425 __fixxfdi (XFtype a
)
1428 return - __fixunsxfDI (-a
);
1429 return __fixunsxfDI (a
);
1433 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1435 __fixunsdfDI (DFtype a
)
1437 /* Get high part of result. The division here will just moves the radix
1438 point and will not cause any rounding. Then the conversion to integral
1439 type chops result as desired. */
1440 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1442 /* Get low part of result. Convert `hi' to floating type and scale it back,
1443 then subtract this from the number being converted. This leaves the low
1444 part. Convert that to integral type. */
1445 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1447 /* Assemble result from the two parts. */
1448 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1452 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1454 __fixdfdi (DFtype a
)
1457 return - __fixunsdfDI (-a
);
1458 return __fixunsdfDI (a
);
1462 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1464 __fixunssfDI (SFtype a
)
1466 #if LIBGCC2_HAS_DF_MODE
1467 /* Convert the SFtype to a DFtype, because that is surely not going
1468 to lose any bits. Some day someone else can write a faster version
1469 that avoids converting to DFtype, and verify it really works right. */
1470 const DFtype dfa
= a
;
1472 /* Get high part of result. The division here will just moves the radix
1473 point and will not cause any rounding. Then the conversion to integral
1474 type chops result as desired. */
1475 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1477 /* Get low part of result. Convert `hi' to floating type and scale it back,
1478 then subtract this from the number being converted. This leaves the low
1479 part. Convert that to integral type. */
1480 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1482 /* Assemble result from the two parts. */
1483 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1484 #elif FLT_MANT_DIG < W_TYPE_SIZE
1487 if (a
< Wtype_MAXp1_F
)
1489 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1491 /* Since we know that there are fewer significant bits in the SFmode
1492 quantity than in a word, we know that we can convert out all the
1493 significant bits in one step, and thus avoid losing bits. */
1495 /* ??? This following loop essentially performs frexpf. If we could
1496 use the real libm function, or poke at the actual bits of the fp
1497 format, it would be significantly faster. */
1499 UWtype shift
= 0, counter
;
1503 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1505 SFtype counterf
= (UWtype
)1 << counter
;
1513 /* Rescale into the range of one word, extract the bits of that
1514 one word, and shift the result into position. */
1517 return (DWtype
)counter
<< shift
;
1526 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1528 __fixsfdi (SFtype a
)
1531 return - __fixunssfDI (-a
);
1532 return __fixunssfDI (a
);
1536 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1538 __floatdixf (DWtype u
)
1540 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1543 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1550 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1552 __floatundixf (UDWtype u
)
1554 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1557 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1564 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1566 __floatditf (DWtype u
)
1568 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1571 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1578 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1580 __floatunditf (UDWtype u
)
1582 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1585 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1592 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1593 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1594 #define DI_SIZE (W_TYPE_SIZE * 2)
1595 #define F_MODE_OK(SIZE) \
1597 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1598 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1599 #if defined(L_floatdisf)
1600 #define FUNC __floatdisf
1601 #define FSTYPE SFtype
1602 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1604 #define FUNC __floatdidf
1605 #define FSTYPE DFtype
1606 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1612 #if FSSIZE >= W_TYPE_SIZE
1613 /* When the word size is small, we never get any rounding error. */
1614 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1618 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1619 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1620 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1622 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1623 # define FSIZE __LIBGCC_DF_MANT_DIG__
1624 # define FTYPE DFtype
1625 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1626 # define FSIZE __LIBGCC_XF_MANT_DIG__
1627 # define FTYPE XFtype
1628 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1629 # define FSIZE __LIBGCC_TF_MANT_DIG__
1630 # define FTYPE TFtype
1635 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1637 /* Protect against double-rounding error.
1638 Represent any low-order bits, that might be truncated by a bit that
1639 won't be lost. The bit can go in anywhere below the rounding position
1640 of the FSTYPE. A fixed mask and bit position handles all usual
1642 if (! (- ((DWtype
) 1 << FSIZE
) < u
1643 && u
< ((DWtype
) 1 << FSIZE
)))
1645 if ((UDWtype
) u
& (REP_BIT
- 1))
1647 u
&= ~ (REP_BIT
- 1);
1652 /* Do the calculation in a wider type so that we don't lose any of
1653 the precision of the high word while multiplying it. */
1654 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1659 #if FSSIZE >= W_TYPE_SIZE - 2
1662 /* Finally, the word size is larger than the number of bits in the
1663 required FSTYPE, and we've got no suitable wider type. The only
1664 way to avoid double rounding is to special case the
1667 /* If there are no high bits set, fall back to one conversion. */
1669 return (FSTYPE
)(Wtype
)u
;
1671 /* Otherwise, find the power of two. */
1672 Wtype hi
= u
>> W_TYPE_SIZE
;
1676 UWtype count
, shift
;
1677 #if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE
1679 count
= W_TYPE_SIZE
;
1682 count_leading_zeros (count
, hi
);
1684 /* No leading bits means u == minimum. */
1686 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1688 shift
= 1 + W_TYPE_SIZE
- count
;
1690 /* Shift down the most significant bits. */
1693 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1694 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1697 /* Convert the one word of data, and rescale. */
1699 if (shift
== W_TYPE_SIZE
)
1701 /* The following two cases could be merged if we knew that the target
1702 supported a native unsigned->float conversion. More often, we only
1703 have a signed conversion, and have to add extra fixup code. */
1704 else if (shift
== W_TYPE_SIZE
- 1)
1705 e
= Wtype_MAXp1_F
/ 2;
1707 e
= (Wtype
)1 << shift
;
1713 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1714 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1715 #define DI_SIZE (W_TYPE_SIZE * 2)
1716 #define F_MODE_OK(SIZE) \
1718 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1719 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1720 #if defined(L_floatundisf)
1721 #define FUNC __floatundisf
1722 #define FSTYPE SFtype
1723 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1725 #define FUNC __floatundidf
1726 #define FSTYPE DFtype
1727 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1733 #if FSSIZE >= W_TYPE_SIZE
1734 /* When the word size is small, we never get any rounding error. */
1735 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1739 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1740 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1741 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1743 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1744 # define FSIZE __LIBGCC_DF_MANT_DIG__
1745 # define FTYPE DFtype
1746 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1747 # define FSIZE __LIBGCC_XF_MANT_DIG__
1748 # define FTYPE XFtype
1749 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1750 # define FSIZE __LIBGCC_TF_MANT_DIG__
1751 # define FTYPE TFtype
1756 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1758 /* Protect against double-rounding error.
1759 Represent any low-order bits, that might be truncated by a bit that
1760 won't be lost. The bit can go in anywhere below the rounding position
1761 of the FSTYPE. A fixed mask and bit position handles all usual
1763 if (u
>= ((UDWtype
) 1 << FSIZE
))
1765 if ((UDWtype
) u
& (REP_BIT
- 1))
1767 u
&= ~ (REP_BIT
- 1);
1772 /* Do the calculation in a wider type so that we don't lose any of
1773 the precision of the high word while multiplying it. */
1774 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1779 #if FSSIZE == W_TYPE_SIZE - 1
1782 /* Finally, the word size is larger than the number of bits in the
1783 required FSTYPE, and we've got no suitable wider type. The only
1784 way to avoid double rounding is to special case the
1787 /* If there are no high bits set, fall back to one conversion. */
1789 return (FSTYPE
)(UWtype
)u
;
1791 /* Otherwise, find the power of two. */
1792 UWtype hi
= u
>> W_TYPE_SIZE
;
1794 UWtype count
, shift
;
1795 count_leading_zeros (count
, hi
);
1797 shift
= W_TYPE_SIZE
- count
;
1799 /* Shift down the most significant bits. */
1802 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1803 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1806 /* Convert the one word of data, and rescale. */
1808 if (shift
== W_TYPE_SIZE
)
1810 /* The following two cases could be merged if we knew that the target
1811 supported a native unsigned->float conversion. More often, we only
1812 have a signed conversion, and have to add extra fixup code. */
1813 else if (shift
== W_TYPE_SIZE
- 1)
1814 e
= Wtype_MAXp1_F
/ 2;
1816 e
= (Wtype
)1 << shift
;
1822 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1824 __fixunsxfSI (XFtype a
)
1826 if (a
>= - (DFtype
) Wtype_MIN
)
1827 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1832 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1834 __fixunsdfSI (DFtype a
)
1836 if (a
>= - (DFtype
) Wtype_MIN
)
1837 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1842 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1844 __fixunssfSI (SFtype a
)
1846 if (a
>= - (SFtype
) Wtype_MIN
)
1847 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1852 /* Integer power helper used from __builtin_powi for non-constant
1855 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1856 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1857 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1858 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1859 # if defined(L_powisf2)
1860 # define TYPE SFtype
1861 # define NAME __powisf2
1862 # elif defined(L_powidf2)
1863 # define TYPE DFtype
1864 # define NAME __powidf2
1865 # elif defined(L_powixf2)
1866 # define TYPE XFtype
1867 # define NAME __powixf2
1868 # elif defined(L_powitf2)
1869 # define TYPE TFtype
1870 # define NAME __powitf2
1876 NAME (TYPE x
, int m
)
1878 unsigned int n
= m
< 0 ? -m
: m
;
1879 TYPE y
= n
% 2 ? x
: 1;
1886 return m
< 0 ? 1/y
: y
;
1891 #if((defined(L_mulhc3) || defined(L_divhc3)) && LIBGCC2_HAS_HF_MODE) \
1892 || ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1893 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1894 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1895 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1901 #if defined(L_mulhc3) || defined(L_divhc3)
1902 # define MTYPE HFtype
1903 # define CTYPE HCtype
1905 # define CEXT __LIBGCC_HF_FUNC_EXT__
1906 # define NOTRUNC (!__LIBGCC_HF_EXCESS_PRECISION__)
1907 #elif defined(L_mulsc3) || defined(L_divsc3)
1908 # define MTYPE SFtype
1909 # define CTYPE SCtype
1911 # define CEXT __LIBGCC_SF_FUNC_EXT__
1912 # define NOTRUNC (!__LIBGCC_SF_EXCESS_PRECISION__)
1913 #elif defined(L_muldc3) || defined(L_divdc3)
1914 # define MTYPE DFtype
1915 # define CTYPE DCtype
1917 # define CEXT __LIBGCC_DF_FUNC_EXT__
1918 # define NOTRUNC (!__LIBGCC_DF_EXCESS_PRECISION__)
1919 #elif defined(L_mulxc3) || defined(L_divxc3)
1920 # define MTYPE XFtype
1921 # define CTYPE XCtype
1923 # define CEXT __LIBGCC_XF_FUNC_EXT__
1924 # define NOTRUNC (!__LIBGCC_XF_EXCESS_PRECISION__)
1925 #elif defined(L_multc3) || defined(L_divtc3)
1926 # define MTYPE TFtype
1927 # define CTYPE TCtype
1929 # define CEXT __LIBGCC_TF_FUNC_EXT__
1930 # define NOTRUNC (!__LIBGCC_TF_EXCESS_PRECISION__)
1935 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1936 #define _CONCAT3(A,B,C) A##B##C
1938 #define CONCAT2(A,B) _CONCAT2(A,B)
1939 #define _CONCAT2(A,B) A##B
1941 /* All of these would be present in a full C99 implementation of <math.h>
1942 and <complex.h>. Our problem is that only a few systems have such full
1943 implementations. Further, libgcc_s.so isn't currently linked against
1944 libm.so, and even for systems that do provide full C99, the extra overhead
1945 of all programs using libgcc having to link against libm. So avoid it. */
1947 #define isnan(x) __builtin_expect ((x) != (x), 0)
1948 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1949 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1951 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1954 /* Helpers to make the following code slightly less gross. */
1955 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1956 #define FABS CONCAT2(__builtin_fabs, CEXT)
1958 /* Verify that MTYPE matches up with CEXT. */
1959 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1961 /* Ensure that we've lost any extra precision. */
1965 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1968 #if defined(L_mulhc3) || defined(L_mulsc3) || defined(L_muldc3) \
1969 || defined(L_mulxc3) || defined(L_multc3)
1972 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1974 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1990 if (isnan (x
) && isnan (y
))
1992 /* Recover infinities that computed as NaN + iNaN. */
1994 if (isinf (a
) || isinf (b
))
1996 /* z is infinite. "Box" the infinity and change NaNs in
1997 the other factor to 0. */
1998 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1999 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
2000 if (isnan (c
)) c
= COPYSIGN (0, c
);
2001 if (isnan (d
)) d
= COPYSIGN (0, d
);
2004 if (isinf (c
) || isinf (d
))
2006 /* w is infinite. "Box" the infinity and change NaNs in
2007 the other factor to 0. */
2008 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
2009 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
2010 if (isnan (a
)) a
= COPYSIGN (0, a
);
2011 if (isnan (b
)) b
= COPYSIGN (0, b
);
2015 && (isinf (ac
) || isinf (bd
)
2016 || isinf (ad
) || isinf (bc
)))
2018 /* Recover infinities from overflow by changing NaNs to 0. */
2019 if (isnan (a
)) a
= COPYSIGN (0, a
);
2020 if (isnan (b
)) b
= COPYSIGN (0, b
);
2021 if (isnan (c
)) c
= COPYSIGN (0, c
);
2022 if (isnan (d
)) d
= COPYSIGN (0, d
);
2027 x
= INFINITY
* (a
* c
- b
* d
);
2028 y
= INFINITY
* (a
* d
+ b
* c
);
2036 #endif /* complex multiply */
2038 #if defined(L_divhc3) || defined(L_divsc3) || defined(L_divdc3) \
2039 || defined(L_divxc3) || defined(L_divtc3)
2042 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
2044 MTYPE denom
, ratio
, x
, y
;
2047 /* ??? We can get better behavior from logarithmic scaling instead of
2048 the division. But that would mean starting to link libgcc against
2049 libm. We could implement something akin to ldexp/frexp as gcc builtins
2051 if (FABS (c
) < FABS (d
))
2054 denom
= (c
* ratio
) + d
;
2055 x
= ((a
* ratio
) + b
) / denom
;
2056 y
= ((b
* ratio
) - a
) / denom
;
2061 denom
= (d
* ratio
) + c
;
2062 x
= ((b
* ratio
) + a
) / denom
;
2063 y
= (b
- (a
* ratio
)) / denom
;
2066 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
2067 are nonzero/zero, infinite/finite, and finite/infinite. */
2068 if (isnan (x
) && isnan (y
))
2070 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
2072 x
= COPYSIGN (INFINITY
, c
) * a
;
2073 y
= COPYSIGN (INFINITY
, c
) * b
;
2075 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
2077 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
2078 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
2079 x
= INFINITY
* (a
* c
+ b
* d
);
2080 y
= INFINITY
* (b
* c
- a
* d
);
2082 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
2084 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
2085 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
2086 x
= 0.0 * (a
* c
+ b
* d
);
2087 y
= 0.0 * (b
* c
- a
* d
);
2095 #endif /* complex divide */
2097 #endif /* all complex float routines */
2099 /* From here on down, the routines use normal data types. */
2101 #define SItype bogus_type
2102 #define USItype bogus_type
2103 #define DItype bogus_type
2104 #define UDItype bogus_type
2105 #define SFtype bogus_type
2106 #define DFtype bogus_type
2124 /* Like bcmp except the sign is meaningful.
2125 Result is negative if S1 is less than S2,
2126 positive if S1 is greater, 0 if S1 and S2 are equal. */
2129 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
2133 const unsigned char c1
= *s1
++, c2
= *s2
++;
2143 /* __eprintf used to be used by GCC's private version of <assert.h>.
2144 We no longer provide that header, but this routine remains in libgcc.a
2145 for binary backward compatibility. Note that it is not included in
2146 the shared version of libgcc. */
2148 #ifndef inhibit_libc
2150 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2154 __eprintf (const char *string
, const char *expression
,
2155 unsigned int line
, const char *filename
)
2157 fprintf (stderr
, string
, expression
, line
, filename
);
2166 #ifdef L_clear_cache
2167 /* Clear part of an instruction cache. */
2170 __clear_cache (char *beg
__attribute__((__unused__
)),
2171 char *end
__attribute__((__unused__
)))
2173 #ifdef CLEAR_INSN_CACHE
2174 CLEAR_INSN_CACHE (beg
, end
);
2175 #endif /* CLEAR_INSN_CACHE */
2178 #endif /* L_clear_cache */
2182 /* Jump to a trampoline, loading the static chain address. */
2184 #if defined(WINNT) && ! defined(__CYGWIN__)
2185 #include <windows.h>
2186 int getpagesize (void);
2187 int mprotect (char *,int, int);
2200 mprotect (char *addr
, int len
, int prot
)
2219 if (VirtualProtect (addr
, len
, np
, &op
))
2225 #endif /* WINNT && ! __CYGWIN__ */
2227 #ifdef TRANSFER_FROM_TRAMPOLINE
2228 TRANSFER_FROM_TRAMPOLINE
2230 #endif /* L_trampoline */
2235 #include "gbl-ctors.h"
2237 /* Some systems use __main in a way incompatible with its use in gcc, in these
2238 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2239 give the same symbol without quotes for an alternative entry point. You
2240 must define both, or neither. */
2242 #define NAME__MAIN "__main"
2243 #define SYMBOL__MAIN __main
2246 #if defined (__LIBGCC_INIT_SECTION_ASM_OP__) \
2247 || defined (__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
2248 #undef HAS_INIT_SECTION
2249 #define HAS_INIT_SECTION
2252 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2254 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2255 code to run constructors. In that case, we need to handle EH here, too.
2256 But MINGW32 is special because it handles CRTSTUFF and EH on its own. */
2259 #undef __LIBGCC_EH_FRAME_SECTION_NAME__
2262 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2263 #include "unwind-dw2-fde.h"
2264 extern unsigned char __EH_FRAME_BEGIN__
[];
2267 /* Run all the global destructors on exit from the program. */
2270 __do_global_dtors (void)
2272 #ifdef DO_GLOBAL_DTORS_BODY
2273 DO_GLOBAL_DTORS_BODY
;
2275 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2282 #if defined (__LIBGCC_EH_FRAME_SECTION_NAME__) && !defined (HAS_INIT_SECTION)
2284 static int completed
= 0;
2288 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2295 #ifndef HAS_INIT_SECTION
2296 /* Run all the global constructors on entry to the program. */
2299 __do_global_ctors (void)
2301 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2303 static struct object object
;
2304 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2307 DO_GLOBAL_CTORS_BODY
;
2308 atexit (__do_global_dtors
);
2310 #endif /* no HAS_INIT_SECTION */
2312 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2313 /* Subroutine called automatically by `main'.
2314 Compiling a global function named `main'
2315 produces an automatic call to this function at the beginning.
2317 For many systems, this routine calls __do_global_ctors.
2318 For systems which support a .init section we use the .init section
2319 to run __do_global_ctors, so we need not do anything here. */
2321 extern void SYMBOL__MAIN (void);
2325 /* Support recursive calls to `main': run initializers just once. */
2326 static int initialized
;
2330 __do_global_ctors ();
2333 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2335 #endif /* L__main */
2336 #endif /* __CYGWIN__ */
2340 #include "gbl-ctors.h"
2342 /* Provide default definitions for the lists of constructors and
2343 destructors, so that we don't get linker errors. These symbols are
2344 intentionally bss symbols, so that gld and/or collect will provide
2345 the right values. */
2347 /* We declare the lists here with two elements each,
2348 so that they are valid empty lists if no other definition is loaded.
2350 If we are using the old "set" extensions to have the gnu linker
2351 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2352 must be in the bss/common section.
2354 Long term no port should use those extensions. But many still do. */
2355 #if !defined(__LIBGCC_INIT_SECTION_ASM_OP__)
2356 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2357 func_ptr __CTOR_LIST__
[2] = {0, 0};
2358 func_ptr __DTOR_LIST__
[2] = {0, 0};
2360 func_ptr __CTOR_LIST__
[2];
2361 func_ptr __DTOR_LIST__
[2];
2363 #endif /* no __LIBGCC_INIT_SECTION_ASM_OP__ */
2364 #endif /* L_ctors */
2365 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */