1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989-2020 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
)
80 if (__builtin_add_overflow (a
, b
, &w
))
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
87 __addvsi3 (SItype a
, SItype b
)
91 if (__builtin_add_overflow (a
, b
, &w
))
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
101 __addvDI3 (DWtype a
, DWtype b
)
105 if (__builtin_add_overflow (a
, b
, &w
))
114 __subvSI3 (Wtype a
, Wtype b
)
118 if (__builtin_sub_overflow (a
, b
, &w
))
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
125 __subvsi3 (SItype a
, SItype b
)
129 if (__builtin_sub_overflow (a
, b
, &w
))
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
139 __subvDI3 (DWtype a
, DWtype b
)
143 if (__builtin_sub_overflow (a
, b
, &w
))
152 __mulvSI3 (Wtype a
, Wtype b
)
156 if (__builtin_mul_overflow (a
, b
, &w
))
161 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
163 __mulvsi3 (SItype a
, SItype b
)
167 if (__builtin_mul_overflow (a
, b
, &w
))
172 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
181 if (__builtin_sub_overflow (0, a
, &w
))
186 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
192 if (__builtin_sub_overflow (0, a
, &w
))
197 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
206 if (__builtin_sub_overflow (0, a
, &w
))
231 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
249 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
274 __mulvDI3 (DWtype u
, DWtype v
)
276 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
277 but the checked multiplication needs only two. */
278 const DWunion uu
= {.ll
= u
};
279 const DWunion vv
= {.ll
= v
};
281 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
283 /* u fits in a single Wtype. */
284 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
286 /* v fits in a single Wtype as well. */
287 /* A single multiplication. No overflow risk. */
288 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
292 /* Two multiplications. */
293 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
294 * (UDWtype
) (UWtype
) vv
.s
.low
};
295 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
296 * (UDWtype
) (UWtype
) vv
.s
.high
};
299 w1
.s
.high
-= uu
.s
.low
;
302 w1
.ll
+= (UWtype
) w0
.s
.high
;
303 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
305 w0
.s
.high
= w1
.s
.low
;
312 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
314 /* v fits into a single Wtype. */
315 /* Two multiplications. */
316 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
317 * (UDWtype
) (UWtype
) vv
.s
.low
};
318 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
319 * (UDWtype
) (UWtype
) vv
.s
.low
};
322 w1
.s
.high
-= vv
.s
.low
;
325 w1
.ll
+= (UWtype
) w0
.s
.high
;
326 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
328 w0
.s
.high
= w1
.s
.low
;
334 /* A few sign checks and a single multiplication. */
339 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
341 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
342 * (UDWtype
) (UWtype
) vv
.s
.low
;
343 if (__builtin_expect (w
>= 0, 1))
349 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
351 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
352 * (UDWtype
) (UWtype
) vv
.s
.low
};
354 ww
.s
.high
-= uu
.s
.low
;
355 if (__builtin_expect (ww
.s
.high
< 0, 1))
364 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
366 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
367 * (UDWtype
) (UWtype
) vv
.s
.low
};
369 ww
.s
.high
-= vv
.s
.low
;
370 if (__builtin_expect (ww
.s
.high
< 0, 1))
376 if ((uu
.s
.high
& vv
.s
.high
) == (Wtype
) -1
377 && (uu
.s
.low
| vv
.s
.low
) != 0)
379 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
380 * (UDWtype
) (UWtype
) vv
.s
.low
};
382 ww
.s
.high
-= uu
.s
.low
;
383 ww
.s
.high
-= vv
.s
.low
;
384 if (__builtin_expect (ww
.s
.high
>= 0, 1))
398 /* Unless shift functions are defined with full ANSI prototypes,
399 parameter b will be promoted to int if shift_count_type is smaller than an int. */
402 __lshrdi3 (DWtype u
, shift_count_type b
)
407 const DWunion uu
= {.ll
= u
};
408 const shift_count_type bm
= W_TYPE_SIZE
- b
;
414 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
418 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
420 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
421 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
430 __ashldi3 (DWtype u
, shift_count_type b
)
435 const DWunion uu
= {.ll
= u
};
436 const shift_count_type bm
= W_TYPE_SIZE
- b
;
442 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
446 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
448 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
449 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
458 __ashrdi3 (DWtype u
, shift_count_type b
)
463 const DWunion uu
= {.ll
= u
};
464 const shift_count_type bm
= W_TYPE_SIZE
- b
;
469 /* w.s.high = 1..1 or 0..0 */
470 w
.s
.high
= uu
.s
.high
>> (W_TYPE_SIZE
- 1);
471 w
.s
.low
= uu
.s
.high
>> -bm
;
475 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
477 w
.s
.high
= uu
.s
.high
>> b
;
478 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
487 __bswapsi2 (SItype u
)
489 return ((((u
) & 0xff000000) >> 24)
490 | (((u
) & 0x00ff0000) >> 8)
491 | (((u
) & 0x0000ff00) << 8)
492 | (((u
) & 0x000000ff) << 24));
497 __bswapdi2 (DItype u
)
499 return ((((u
) & 0xff00000000000000ull
) >> 56)
500 | (((u
) & 0x00ff000000000000ull
) >> 40)
501 | (((u
) & 0x0000ff0000000000ull
) >> 24)
502 | (((u
) & 0x000000ff00000000ull
) >> 8)
503 | (((u
) & 0x00000000ff000000ull
) << 8)
504 | (((u
) & 0x0000000000ff0000ull
) << 24)
505 | (((u
) & 0x000000000000ff00ull
) << 40)
506 | (((u
) & 0x00000000000000ffull
) << 56));
519 count_trailing_zeros (count
, u
);
529 const DWunion uu
= {.ll
= u
};
530 UWtype word
, count
, add
;
533 word
= uu
.s
.low
, add
= 0;
534 else if (uu
.s
.high
!= 0)
535 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
539 count_trailing_zeros (count
, word
);
540 return count
+ add
+ 1;
546 __muldi3 (DWtype u
, DWtype v
)
548 const DWunion uu
= {.ll
= u
};
549 const DWunion vv
= {.ll
= v
};
550 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
552 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
553 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
559 #if (defined (L_udivdi3) || defined (L_divdi3) || \
560 defined (L_umoddi3) || defined (L_moddi3))
561 #if defined (sdiv_qrnnd)
562 #define L_udiv_w_sdiv
567 #if defined (sdiv_qrnnd)
568 #if (defined (L_udivdi3) || defined (L_divdi3) || \
569 defined (L_umoddi3) || defined (L_moddi3))
570 static inline __attribute__ ((__always_inline__
))
573 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
580 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
582 /* Dividend, divisor, and quotient are nonnegative. */
583 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
587 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
588 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
589 /* Divide (c1*2^32 + c0) by d. */
590 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
591 /* Add 2^31 to quotient. */
592 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
597 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
598 c1
= a1
>> 1; /* A/2 */
599 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
601 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
603 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
605 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
622 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
625 c0
= ~c0
; /* logical NOT */
627 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
629 q
= ~q
; /* (A/2)/b1 */
632 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
650 else /* Implies c1 = b1 */
651 { /* Hence a1 = d - 1 = 2*b1 - 1 */
669 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
671 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
672 UWtype a1
__attribute__ ((__unused__
)),
673 UWtype a0
__attribute__ ((__unused__
)),
674 UWtype d
__attribute__ ((__unused__
)))
681 #if (defined (L_udivdi3) || defined (L_divdi3) || \
682 defined (L_umoddi3) || defined (L_moddi3) || \
683 defined (L_divmoddi4))
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 << __CHAR_BIT__) | x)
824 #define POPCOUNTCST4(x) (((UWtype) x << (2 * __CHAR_BIT__)) | x)
825 #define POPCOUNTCST8(x) (((UWtype) x << (4 * __CHAR_BIT__)) | x)
826 #if W_TYPE_SIZE == __CHAR_BIT__
827 #define POPCOUNTCST(x) x
828 #elif W_TYPE_SIZE == 2 * __CHAR_BIT__
829 #define POPCOUNTCST(x) POPCOUNTCST2 (x)
830 #elif W_TYPE_SIZE == 4 * __CHAR_BIT__
831 #define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
832 #elif W_TYPE_SIZE == 8 * __CHAR_BIT__
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) && __CHAR_BIT__ == 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
- __CHAR_BIT__
);
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) && __CHAR_BIT__ == 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
- __CHAR_BIT__
);
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;
937 #ifdef TARGET_HAS_NO_HW_DIVIDE
939 #if (defined (L_udivdi3) || defined (L_divdi3) || \
940 defined (L_umoddi3) || defined (L_moddi3) || \
941 defined (L_divmoddi4))
942 static inline __attribute__ ((__always_inline__
))
945 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
947 UDWtype q
= 0, r
= n
, y
= d
;
948 UWtype lz1
, lz2
, i
, k
;
950 /* Implements align divisor shift dividend method. This algorithm
951 aligns the divisor under the dividend and then perform number of
952 test-subtract iterations which shift the dividend left. Number of
953 iterations is k + 1 where k is the number of bit positions the
954 divisor must be shifted left to align it under the dividend.
955 quotient bits can be saved in the rightmost positions of the dividend
956 as it shifts left on each test-subtract iteration. */
960 lz1
= __builtin_clzll (d
);
961 lz2
= __builtin_clzll (n
);
966 /* Dividend can exceed 2 ^ (width - 1) - 1 but still be less than the
967 aligned divisor. Normal iteration can drops the high order bit
968 of the dividend. Therefore, first test-subtract iteration is a
969 special case, saving its quotient bit in a separate location and
970 not shifting the dividend. */
981 /* k additional iterations where k regular test subtract shift
982 dividend iterations are done. */
987 r
= ((r
- y
) << 1) + 1;
993 /* First quotient bit is combined with the quotient bits resulting
994 from the k regular iterations. */
1007 #if (defined (L_udivdi3) || defined (L_divdi3) || \
1008 defined (L_umoddi3) || defined (L_moddi3) || \
1009 defined (L_divmoddi4))
1010 static inline __attribute__ ((__always_inline__
))
1013 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
1015 const DWunion nn
= {.ll
= n
};
1016 const DWunion dd
= {.ll
= d
};
1018 UWtype d0
, d1
, n0
, n1
, n2
;
1027 #if !UDIV_NEEDS_NORMALIZATION
1034 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1037 /* Remainder in n0. */
1044 d0
= 1 / d0
; /* Divide intentionally by zero. */
1046 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
1047 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1049 /* Remainder in n0. */
1060 #else /* UDIV_NEEDS_NORMALIZATION */
1068 count_leading_zeros (bm
, d0
);
1072 /* Normalize, i.e. make the most significant bit of the
1076 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
1080 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1083 /* Remainder in n0 >> bm. */
1090 d0
= 1 / d0
; /* Divide intentionally by zero. */
1092 count_leading_zeros (bm
, d0
);
1096 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
1097 conclude (the most significant bit of n1 is set) /\ (the
1098 leading quotient digit q1 = 1).
1100 This special case is necessary, not an optimization.
1101 (Shifts counts of W_TYPE_SIZE are undefined.) */
1110 b
= W_TYPE_SIZE
- bm
;
1114 n1
= (n1
<< bm
) | (n0
>> b
);
1117 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
1122 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
1124 /* Remainder in n0 >> bm. */
1129 rr
.s
.low
= n0
>> bm
;
1134 #endif /* UDIV_NEEDS_NORMALIZATION */
1145 /* Remainder in n1n0. */
1157 count_leading_zeros (bm
, d1
);
1160 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1161 conclude (the most significant bit of n1 is set) /\ (the
1162 quotient digit q0 = 0 or 1).
1164 This special case is necessary, not an optimization. */
1166 /* The condition on the next line takes advantage of that
1167 n1 >= d1 (true due to program flow). */
1168 if (n1
> d1
|| n0
>= d0
)
1171 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1190 b
= W_TYPE_SIZE
- bm
;
1192 d1
= (d1
<< bm
) | (d0
>> b
);
1195 n1
= (n1
<< bm
) | (n0
>> b
);
1198 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1199 umul_ppmm (m1
, m0
, q0
, d0
);
1201 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1204 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1209 /* Remainder in (n1n0 - m1m0) >> bm. */
1212 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1213 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1214 rr
.s
.high
= n1
>> bm
;
1221 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1229 __divdi3 (DWtype u
, DWtype v
)
1232 DWunion uu
= {.ll
= u
};
1233 DWunion vv
= {.ll
= v
};
1243 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1253 __moddi3 (DWtype u
, DWtype v
)
1256 DWunion uu
= {.ll
= u
};
1257 DWunion vv
= {.ll
= v
};
1266 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1276 __divmoddi4 (DWtype u
, DWtype v
, DWtype
*rp
)
1278 Wtype c1
= 0, c2
= 0;
1279 DWunion uu
= {.ll
= u
};
1280 DWunion vv
= {.ll
= v
};
1291 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&r
);
1304 __umoddi3 (UDWtype u
, UDWtype v
)
1308 (void) __udivmoddi4 (u
, v
, &w
);
1316 __udivdi3 (UDWtype n
, UDWtype d
)
1318 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1324 __cmpdi2 (DWtype a
, DWtype b
)
1326 return (a
> b
) - (a
< b
) + 1;
1332 __ucmpdi2 (UDWtype a
, UDWtype b
)
1334 return (a
> b
) - (a
< b
) + 1;
1338 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1340 __fixunstfDI (TFtype a
)
1345 /* Compute high word of result, as a flonum. */
1346 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1347 /* Convert that to fixed (but not to DWtype!),
1348 and shift it into the high word. */
1349 UDWtype v
= (UWtype
) b
;
1351 /* Remove high part from the TFtype, leaving the low part as flonum. */
1353 /* Convert that to fixed (but not to DWtype!) and add it in.
1354 Sometimes A comes out negative. This is significant, since
1355 A has more bits than a long int does. */
1357 v
-= (UWtype
) (- a
);
1364 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1366 __fixtfdi (TFtype a
)
1369 return - __fixunstfDI (-a
);
1370 return __fixunstfDI (a
);
1374 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1376 __fixunsxfDI (XFtype a
)
1381 /* Compute high word of result, as a flonum. */
1382 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1383 /* Convert that to fixed (but not to DWtype!),
1384 and shift it into the high word. */
1385 UDWtype v
= (UWtype
) b
;
1387 /* Remove high part from the XFtype, leaving the low part as flonum. */
1389 /* Convert that to fixed (but not to DWtype!) and add it in.
1390 Sometimes A comes out negative. This is significant, since
1391 A has more bits than a long int does. */
1393 v
-= (UWtype
) (- a
);
1400 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1402 __fixxfdi (XFtype a
)
1405 return - __fixunsxfDI (-a
);
1406 return __fixunsxfDI (a
);
1410 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1412 __fixunsdfDI (DFtype a
)
1414 /* Get high part of result. The division here will just moves the radix
1415 point and will not cause any rounding. Then the conversion to integral
1416 type chops result as desired. */
1417 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1419 /* Get low part of result. Convert `hi' to floating type and scale it back,
1420 then subtract this from the number being converted. This leaves the low
1421 part. Convert that to integral type. */
1422 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1424 /* Assemble result from the two parts. */
1425 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1429 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1431 __fixdfdi (DFtype a
)
1434 return - __fixunsdfDI (-a
);
1435 return __fixunsdfDI (a
);
1439 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1441 __fixunssfDI (SFtype a
)
1443 #if LIBGCC2_HAS_DF_MODE
1444 /* Convert the SFtype to a DFtype, because that is surely not going
1445 to lose any bits. Some day someone else can write a faster version
1446 that avoids converting to DFtype, and verify it really works right. */
1447 const DFtype dfa
= a
;
1449 /* Get high part of result. The division here will just moves the radix
1450 point and will not cause any rounding. Then the conversion to integral
1451 type chops result as desired. */
1452 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1454 /* Get low part of result. Convert `hi' to floating type and scale it back,
1455 then subtract this from the number being converted. This leaves the low
1456 part. Convert that to integral type. */
1457 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1459 /* Assemble result from the two parts. */
1460 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1461 #elif FLT_MANT_DIG < W_TYPE_SIZE
1464 if (a
< Wtype_MAXp1_F
)
1466 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1468 /* Since we know that there are fewer significant bits in the SFmode
1469 quantity than in a word, we know that we can convert out all the
1470 significant bits in one step, and thus avoid losing bits. */
1472 /* ??? This following loop essentially performs frexpf. If we could
1473 use the real libm function, or poke at the actual bits of the fp
1474 format, it would be significantly faster. */
1476 UWtype shift
= 0, counter
;
1480 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1482 SFtype counterf
= (UWtype
)1 << counter
;
1490 /* Rescale into the range of one word, extract the bits of that
1491 one word, and shift the result into position. */
1494 return (DWtype
)counter
<< shift
;
1503 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1505 __fixsfdi (SFtype a
)
1508 return - __fixunssfDI (-a
);
1509 return __fixunssfDI (a
);
1513 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1515 __floatdixf (DWtype u
)
1517 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1520 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1527 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1529 __floatundixf (UDWtype u
)
1531 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
1534 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1541 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1543 __floatditf (DWtype u
)
1545 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1548 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1555 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1557 __floatunditf (UDWtype u
)
1559 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
1562 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1569 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1570 || (defined(L_floatdidf) && 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_floatdisf)
1577 #define FUNC __floatdisf
1578 #define FSTYPE SFtype
1579 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1581 #define FUNC __floatdidf
1582 #define FSTYPE DFtype
1583 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1589 #if FSSIZE >= W_TYPE_SIZE
1590 /* When the word size is small, we never get any rounding error. */
1591 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1595 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1596 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1597 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1599 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1600 # define FSIZE __LIBGCC_DF_MANT_DIG__
1601 # define FTYPE DFtype
1602 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1603 # define FSIZE __LIBGCC_XF_MANT_DIG__
1604 # define FTYPE XFtype
1605 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1606 # define FSIZE __LIBGCC_TF_MANT_DIG__
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 (! (- ((DWtype
) 1 << FSIZE
) < u
1620 && u
< ((DWtype
) 1 << FSIZE
)))
1622 if ((UDWtype
) u
& (REP_BIT
- 1))
1624 u
&= ~ (REP_BIT
- 1);
1629 /* Do the calculation in a wider type so that we don't lose any of
1630 the precision of the high word while multiplying it. */
1631 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1636 #if FSSIZE >= W_TYPE_SIZE - 2
1639 /* Finally, the word size is larger than the number of bits in the
1640 required FSTYPE, and we've got no suitable wider type. The only
1641 way to avoid double rounding is to special case the
1644 /* If there are no high bits set, fall back to one conversion. */
1646 return (FSTYPE
)(Wtype
)u
;
1648 /* Otherwise, find the power of two. */
1649 Wtype hi
= u
>> W_TYPE_SIZE
;
1653 UWtype count
, shift
;
1654 #if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE
1656 count
= W_TYPE_SIZE
;
1659 count_leading_zeros (count
, hi
);
1661 /* No leading bits means u == minimum. */
1663 return Wtype_MAXp1_F
* (FSTYPE
) (hi
| ((UWtype
) u
!= 0));
1665 shift
= 1 + W_TYPE_SIZE
- count
;
1667 /* Shift down the most significant bits. */
1670 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1671 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1674 /* Convert the one word of data, and rescale. */
1676 if (shift
== W_TYPE_SIZE
)
1678 /* The following two cases could be merged if we knew that the target
1679 supported a native unsigned->float conversion. More often, we only
1680 have a signed conversion, and have to add extra fixup code. */
1681 else if (shift
== W_TYPE_SIZE
- 1)
1682 e
= Wtype_MAXp1_F
/ 2;
1684 e
= (Wtype
)1 << shift
;
1690 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1691 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1692 #define DI_SIZE (W_TYPE_SIZE * 2)
1693 #define F_MODE_OK(SIZE) \
1695 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1696 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1697 #if defined(L_floatundisf)
1698 #define FUNC __floatundisf
1699 #define FSTYPE SFtype
1700 #define FSSIZE __LIBGCC_SF_MANT_DIG__
1702 #define FUNC __floatundidf
1703 #define FSTYPE DFtype
1704 #define FSSIZE __LIBGCC_DF_MANT_DIG__
1710 #if FSSIZE >= W_TYPE_SIZE
1711 /* When the word size is small, we never get any rounding error. */
1712 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1716 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
1717 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
1718 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1720 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
1721 # define FSIZE __LIBGCC_DF_MANT_DIG__
1722 # define FTYPE DFtype
1723 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
1724 # define FSIZE __LIBGCC_XF_MANT_DIG__
1725 # define FTYPE XFtype
1726 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
1727 # define FSIZE __LIBGCC_TF_MANT_DIG__
1728 # define FTYPE TFtype
1733 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1735 /* Protect against double-rounding error.
1736 Represent any low-order bits, that might be truncated by a bit that
1737 won't be lost. The bit can go in anywhere below the rounding position
1738 of the FSTYPE. A fixed mask and bit position handles all usual
1740 if (u
>= ((UDWtype
) 1 << FSIZE
))
1742 if ((UDWtype
) u
& (REP_BIT
- 1))
1744 u
&= ~ (REP_BIT
- 1);
1749 /* Do the calculation in a wider type so that we don't lose any of
1750 the precision of the high word while multiplying it. */
1751 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1756 #if FSSIZE == W_TYPE_SIZE - 1
1759 /* Finally, the word size is larger than the number of bits in the
1760 required FSTYPE, and we've got no suitable wider type. The only
1761 way to avoid double rounding is to special case the
1764 /* If there are no high bits set, fall back to one conversion. */
1766 return (FSTYPE
)(UWtype
)u
;
1768 /* Otherwise, find the power of two. */
1769 UWtype hi
= u
>> W_TYPE_SIZE
;
1771 UWtype count
, shift
;
1772 count_leading_zeros (count
, hi
);
1774 shift
= W_TYPE_SIZE
- count
;
1776 /* Shift down the most significant bits. */
1779 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1780 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1783 /* Convert the one word of data, and rescale. */
1785 if (shift
== W_TYPE_SIZE
)
1787 /* The following two cases could be merged if we knew that the target
1788 supported a native unsigned->float conversion. More often, we only
1789 have a signed conversion, and have to add extra fixup code. */
1790 else if (shift
== W_TYPE_SIZE
- 1)
1791 e
= Wtype_MAXp1_F
/ 2;
1793 e
= (Wtype
)1 << shift
;
1799 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1801 __fixunsxfSI (XFtype a
)
1803 if (a
>= - (DFtype
) Wtype_MIN
)
1804 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1809 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1811 __fixunsdfSI (DFtype a
)
1813 if (a
>= - (DFtype
) Wtype_MIN
)
1814 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1819 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1821 __fixunssfSI (SFtype a
)
1823 if (a
>= - (SFtype
) Wtype_MIN
)
1824 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1829 /* Integer power helper used from __builtin_powi for non-constant
1832 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1833 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1834 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1835 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1836 # if defined(L_powisf2)
1837 # define TYPE SFtype
1838 # define NAME __powisf2
1839 # elif defined(L_powidf2)
1840 # define TYPE DFtype
1841 # define NAME __powidf2
1842 # elif defined(L_powixf2)
1843 # define TYPE XFtype
1844 # define NAME __powixf2
1845 # elif defined(L_powitf2)
1846 # define TYPE TFtype
1847 # define NAME __powitf2
1853 NAME (TYPE x
, int m
)
1855 unsigned int n
= m
< 0 ? -m
: m
;
1856 TYPE y
= n
% 2 ? x
: 1;
1863 return m
< 0 ? 1/y
: y
;
1868 #if((defined(L_mulhc3) || defined(L_divhc3)) && LIBGCC2_HAS_HF_MODE) \
1869 || ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1870 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1871 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1872 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1878 #if defined(L_mulhc3) || defined(L_divhc3)
1879 # define MTYPE HFtype
1880 # define CTYPE HCtype
1882 # define CEXT __LIBGCC_HF_FUNC_EXT__
1883 # define NOTRUNC (!__LIBGCC_HF_EXCESS_PRECISION__)
1884 #elif defined(L_mulsc3) || defined(L_divsc3)
1885 # define MTYPE SFtype
1886 # define CTYPE SCtype
1888 # define CEXT __LIBGCC_SF_FUNC_EXT__
1889 # define NOTRUNC (!__LIBGCC_SF_EXCESS_PRECISION__)
1890 #elif defined(L_muldc3) || defined(L_divdc3)
1891 # define MTYPE DFtype
1892 # define CTYPE DCtype
1894 # define CEXT __LIBGCC_DF_FUNC_EXT__
1895 # define NOTRUNC (!__LIBGCC_DF_EXCESS_PRECISION__)
1896 #elif defined(L_mulxc3) || defined(L_divxc3)
1897 # define MTYPE XFtype
1898 # define CTYPE XCtype
1900 # define CEXT __LIBGCC_XF_FUNC_EXT__
1901 # define NOTRUNC (!__LIBGCC_XF_EXCESS_PRECISION__)
1902 #elif defined(L_multc3) || defined(L_divtc3)
1903 # define MTYPE TFtype
1904 # define CTYPE TCtype
1906 # define CEXT __LIBGCC_TF_FUNC_EXT__
1907 # define NOTRUNC (!__LIBGCC_TF_EXCESS_PRECISION__)
1912 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1913 #define _CONCAT3(A,B,C) A##B##C
1915 #define CONCAT2(A,B) _CONCAT2(A,B)
1916 #define _CONCAT2(A,B) A##B
1918 #define isnan(x) __builtin_isnan (x)
1919 #define isfinite(x) __builtin_isfinite (x)
1920 #define isinf(x) __builtin_isinf (x)
1922 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
1925 /* Helpers to make the following code slightly less gross. */
1926 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1927 #define FABS CONCAT2(__builtin_fabs, CEXT)
1929 /* Verify that MTYPE matches up with CEXT. */
1930 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1932 /* Ensure that we've lost any extra precision. */
1936 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1939 #if defined(L_mulhc3) || defined(L_mulsc3) || defined(L_muldc3) \
1940 || defined(L_mulxc3) || defined(L_multc3)
1943 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1945 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1961 if (isnan (x
) && isnan (y
))
1963 /* Recover infinities that computed as NaN + iNaN. */
1965 if (isinf (a
) || isinf (b
))
1967 /* z is infinite. "Box" the infinity and change NaNs in
1968 the other factor to 0. */
1969 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1970 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1971 if (isnan (c
)) c
= COPYSIGN (0, c
);
1972 if (isnan (d
)) d
= COPYSIGN (0, d
);
1975 if (isinf (c
) || isinf (d
))
1977 /* w is infinite. "Box" the infinity and change NaNs in
1978 the other factor to 0. */
1979 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1980 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1981 if (isnan (a
)) a
= COPYSIGN (0, a
);
1982 if (isnan (b
)) b
= COPYSIGN (0, b
);
1986 && (isinf (ac
) || isinf (bd
)
1987 || isinf (ad
) || isinf (bc
)))
1989 /* Recover infinities from overflow by changing NaNs to 0. */
1990 if (isnan (a
)) a
= COPYSIGN (0, a
);
1991 if (isnan (b
)) b
= COPYSIGN (0, b
);
1992 if (isnan (c
)) c
= COPYSIGN (0, c
);
1993 if (isnan (d
)) d
= COPYSIGN (0, d
);
1998 x
= INFINITY
* (a
* c
- b
* d
);
1999 y
= INFINITY
* (a
* d
+ b
* c
);
2007 #endif /* complex multiply */
2009 #if defined(L_divhc3) || defined(L_divsc3) || defined(L_divdc3) \
2010 || defined(L_divxc3) || defined(L_divtc3)
2013 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
2015 MTYPE denom
, ratio
, x
, y
;
2018 /* ??? We can get better behavior from logarithmic scaling instead of
2019 the division. But that would mean starting to link libgcc against
2020 libm. We could implement something akin to ldexp/frexp as gcc builtins
2022 if (FABS (c
) < FABS (d
))
2025 denom
= (c
* ratio
) + d
;
2026 x
= ((a
* ratio
) + b
) / denom
;
2027 y
= ((b
* ratio
) - a
) / denom
;
2032 denom
= (d
* ratio
) + c
;
2033 x
= ((b
* ratio
) + a
) / denom
;
2034 y
= (b
- (a
* ratio
)) / denom
;
2037 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
2038 are nonzero/zero, infinite/finite, and finite/infinite. */
2039 if (isnan (x
) && isnan (y
))
2041 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
2043 x
= COPYSIGN (INFINITY
, c
) * a
;
2044 y
= COPYSIGN (INFINITY
, c
) * b
;
2046 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
2048 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
2049 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
2050 x
= INFINITY
* (a
* c
+ b
* d
);
2051 y
= INFINITY
* (b
* c
- a
* d
);
2053 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
2055 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
2056 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
2057 x
= 0.0 * (a
* c
+ b
* d
);
2058 y
= 0.0 * (b
* c
- a
* d
);
2066 #endif /* complex divide */
2068 #endif /* all complex float routines */
2070 /* From here on down, the routines use normal data types. */
2072 #define SItype bogus_type
2073 #define USItype bogus_type
2074 #define DItype bogus_type
2075 #define UDItype bogus_type
2076 #define SFtype bogus_type
2077 #define DFtype bogus_type
2095 /* Like bcmp except the sign is meaningful.
2096 Result is negative if S1 is less than S2,
2097 positive if S1 is greater, 0 if S1 and S2 are equal. */
2100 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
2104 const unsigned char c1
= *s1
++, c2
= *s2
++;
2114 /* __eprintf used to be used by GCC's private version of <assert.h>.
2115 We no longer provide that header, but this routine remains in libgcc.a
2116 for binary backward compatibility. Note that it is not included in
2117 the shared version of libgcc. */
2119 #ifndef inhibit_libc
2121 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2125 __eprintf (const char *string
, const char *expression
,
2126 unsigned int line
, const char *filename
)
2128 fprintf (stderr
, string
, expression
, line
, filename
);
2137 #ifdef L_clear_cache
2138 /* Clear part of an instruction cache. */
2141 __clear_cache (void *beg
__attribute__((__unused__
)),
2142 void *end
__attribute__((__unused__
)))
2144 #ifdef CLEAR_INSN_CACHE
2145 /* Cast the void* pointers to char* as some implementations
2146 of the macro assume the pointers can be subtracted from
2148 CLEAR_INSN_CACHE ((char *) beg
, (char *) end
);
2149 #endif /* CLEAR_INSN_CACHE */
2152 #endif /* L_clear_cache */
2156 /* Jump to a trampoline, loading the static chain address. */
2158 #if defined(WINNT) && ! defined(__CYGWIN__)
2159 #include <windows.h>
2160 int getpagesize (void);
2161 int mprotect (char *,int, int);
2174 mprotect (char *addr
, int len
, int prot
)
2193 if (VirtualProtect (addr
, len
, np
, &op
))
2199 #endif /* WINNT && ! __CYGWIN__ */
2201 #ifdef TRANSFER_FROM_TRAMPOLINE
2202 TRANSFER_FROM_TRAMPOLINE
2204 #endif /* L_trampoline */
2209 #include "gbl-ctors.h"
2211 /* Some systems use __main in a way incompatible with its use in gcc, in these
2212 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2213 give the same symbol without quotes for an alternative entry point. You
2214 must define both, or neither. */
2216 #define NAME__MAIN "__main"
2217 #define SYMBOL__MAIN __main
2220 #if defined (__LIBGCC_INIT_SECTION_ASM_OP__) \
2221 || defined (__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
2222 #undef HAS_INIT_SECTION
2223 #define HAS_INIT_SECTION
2226 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2228 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2229 code to run constructors. In that case, we need to handle EH here, too.
2230 But MINGW32 is special because it handles CRTSTUFF and EH on its own. */
2233 #undef __LIBGCC_EH_FRAME_SECTION_NAME__
2236 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2237 #include "unwind-dw2-fde.h"
2238 extern unsigned char __EH_FRAME_BEGIN__
[];
2241 /* Run all the global destructors on exit from the program. */
2244 __do_global_dtors (void)
2246 #ifdef DO_GLOBAL_DTORS_BODY
2247 DO_GLOBAL_DTORS_BODY
;
2249 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2256 #if defined (__LIBGCC_EH_FRAME_SECTION_NAME__) && !defined (HAS_INIT_SECTION)
2258 static int completed
= 0;
2262 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2269 #ifndef HAS_INIT_SECTION
2270 /* Run all the global constructors on entry to the program. */
2273 __do_global_ctors (void)
2275 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
2277 static struct object object
;
2278 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2281 DO_GLOBAL_CTORS_BODY
;
2282 atexit (__do_global_dtors
);
2284 #endif /* no HAS_INIT_SECTION */
2286 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2287 /* Subroutine called automatically by `main'.
2288 Compiling a global function named `main'
2289 produces an automatic call to this function at the beginning.
2291 For many systems, this routine calls __do_global_ctors.
2292 For systems which support a .init section we use the .init section
2293 to run __do_global_ctors, so we need not do anything here. */
2295 extern void SYMBOL__MAIN (void);
2299 /* Support recursive calls to `main': run initializers just once. */
2300 static int initialized
;
2304 __do_global_ctors ();
2307 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2309 #endif /* L__main */
2310 #endif /* __CYGWIN__ */
2314 #include "gbl-ctors.h"
2316 /* Provide default definitions for the lists of constructors and
2317 destructors, so that we don't get linker errors. These symbols are
2318 intentionally bss symbols, so that gld and/or collect will provide
2319 the right values. */
2321 /* We declare the lists here with two elements each,
2322 so that they are valid empty lists if no other definition is loaded.
2324 If we are using the old "set" extensions to have the gnu linker
2325 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2326 must be in the bss/common section.
2328 Long term no port should use those extensions. But many still do. */
2329 #if !defined(__LIBGCC_INIT_SECTION_ASM_OP__)
2330 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2331 func_ptr __CTOR_LIST__
[2] = {0, 0};
2332 func_ptr __DTOR_LIST__
[2] = {0, 0};
2334 func_ptr __CTOR_LIST__
[2];
2335 func_ptr __DTOR_LIST__
[2];
2337 #endif /* no __LIBGCC_INIT_SECTION_ASM_OP__ */
2338 #endif /* L_ctors */
2339 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */