1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "coretypes.h"
37 #ifdef HAVE_GAS_HIDDEN
38 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
40 #define ATTRIBUTE_HIDDEN
45 #ifdef DECLARE_LIBRARY_RENAMES
46 DECLARE_LIBRARY_RENAMES
49 #if defined (L_negdi2)
53 const DWunion uu
= {.ll
= u
};
54 const DWunion w
= { {.low
= -uu
.s
.low
,
55 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
63 __addvSI3 (Wtype a
, Wtype b
)
65 const Wtype w
= a
+ b
;
67 if (b
>= 0 ? w
< a
: w
> a
)
72 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
74 __addvsi3 (SItype a
, SItype b
)
76 const SItype w
= a
+ b
;
78 if (b
>= 0 ? w
< a
: w
> a
)
83 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
88 __addvDI3 (DWtype a
, DWtype b
)
90 const DWtype w
= a
+ b
;
92 if (b
>= 0 ? w
< a
: w
> a
)
101 __subvSI3 (Wtype a
, Wtype b
)
103 const Wtype w
= a
- b
;
105 if (b
>= 0 ? w
> a
: w
< a
)
110 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
112 __subvsi3 (SItype a
, SItype b
)
114 const SItype w
= a
- b
;
116 if (b
>= 0 ? w
> a
: w
< a
)
121 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
126 __subvDI3 (DWtype a
, DWtype b
)
128 const DWtype w
= a
- b
;
130 if (b
>= 0 ? w
> a
: w
< a
)
139 __mulvSI3 (Wtype a
, Wtype b
)
141 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
143 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
148 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
150 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
152 __mulvsi3 (SItype a
, SItype b
)
154 const DItype w
= (DItype
) a
* (DItype
) b
;
156 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
161 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
170 if (a
>= 0 ? w
> 0 : w
< 0)
175 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
181 if (a
>= 0 ? w
> 0 : w
< 0)
186 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
195 if (a
>= 0 ? w
> 0 : w
< 0)
220 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
238 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
263 __mulvDI3 (DWtype u
, DWtype v
)
265 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
266 but the checked multiplication needs only two. */
267 const DWunion uu
= {.ll
= u
};
268 const DWunion vv
= {.ll
= v
};
270 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
272 /* u fits in a single Wtype. */
273 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
275 /* v fits in a single Wtype as well. */
276 /* A single multiplication. No overflow risk. */
277 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
281 /* Two multiplications. */
282 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
283 * (UDWtype
) (UWtype
) vv
.s
.low
};
284 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
285 * (UDWtype
) (UWtype
) vv
.s
.high
};
288 w1
.s
.high
-= uu
.s
.low
;
291 w1
.ll
+= (UWtype
) w0
.s
.high
;
292 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
294 w0
.s
.high
= w1
.s
.low
;
301 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
303 /* v fits into a single Wtype. */
304 /* Two multiplications. */
305 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
306 * (UDWtype
) (UWtype
) vv
.s
.low
};
307 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
308 * (UDWtype
) (UWtype
) vv
.s
.low
};
311 w1
.s
.high
-= vv
.s
.low
;
314 w1
.ll
+= (UWtype
) w0
.s
.high
;
315 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
317 w0
.s
.high
= w1
.s
.low
;
323 /* A few sign checks and a single multiplication. */
328 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
330 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
331 * (UDWtype
) (UWtype
) vv
.s
.low
;
332 if (__builtin_expect (w
>= 0, 1))
338 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
340 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
341 * (UDWtype
) (UWtype
) vv
.s
.low
};
343 ww
.s
.high
-= uu
.s
.low
;
344 if (__builtin_expect (ww
.s
.high
< 0, 1))
353 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
355 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
356 * (UDWtype
) (UWtype
) vv
.s
.low
};
358 ww
.s
.high
-= vv
.s
.low
;
359 if (__builtin_expect (ww
.s
.high
< 0, 1))
365 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
367 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
368 * (UDWtype
) (UWtype
) vv
.s
.low
};
370 ww
.s
.high
-= uu
.s
.low
;
371 ww
.s
.high
-= vv
.s
.low
;
372 if (__builtin_expect (ww
.s
.high
>= 0, 1))
386 /* Unless shift functions are defined with full ANSI prototypes,
387 parameter b will be promoted to int if word_type is smaller than an int. */
390 __lshrdi3 (DWtype u
, word_type b
)
395 const DWunion uu
= {.ll
= u
};
396 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
402 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
406 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
408 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
409 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
418 __ashldi3 (DWtype u
, word_type b
)
423 const DWunion uu
= {.ll
= u
};
424 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
430 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
434 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
436 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
437 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
446 __ashrdi3 (DWtype u
, word_type b
)
451 const DWunion uu
= {.ll
= u
};
452 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
457 /* w.s.high = 1..1 or 0..0 */
458 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
459 w
.s
.low
= uu
.s
.high
>> -bm
;
463 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
465 w
.s
.high
= uu
.s
.high
>> b
;
466 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
483 count_trailing_zeros (count
, u
);
493 const DWunion uu
= {.ll
= u
};
494 UWtype word
, count
, add
;
497 word
= uu
.s
.low
, add
= 0;
498 else if (uu
.s
.high
!= 0)
499 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
503 count_trailing_zeros (count
, word
);
504 return count
+ add
+ 1;
510 __muldi3 (DWtype u
, DWtype v
)
512 const DWunion uu
= {.ll
= u
};
513 const DWunion vv
= {.ll
= v
};
514 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
516 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
517 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
523 #if (defined (L_udivdi3) || defined (L_divdi3) || \
524 defined (L_umoddi3) || defined (L_moddi3))
525 #if defined (sdiv_qrnnd)
526 #define L_udiv_w_sdiv
531 #if defined (sdiv_qrnnd)
532 #if (defined (L_udivdi3) || defined (L_divdi3) || \
533 defined (L_umoddi3) || defined (L_moddi3))
534 static inline __attribute__ ((__always_inline__
))
537 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
544 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
546 /* Dividend, divisor, and quotient are nonnegative. */
547 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
551 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
552 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
553 /* Divide (c1*2^32 + c0) by d. */
554 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
555 /* Add 2^31 to quotient. */
556 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
561 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
562 c1
= a1
>> 1; /* A/2 */
563 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
565 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
567 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
569 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
586 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
589 c0
= ~c0
; /* logical NOT */
591 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
593 q
= ~q
; /* (A/2)/b1 */
596 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
614 else /* Implies c1 = b1 */
615 { /* Hence a1 = d - 1 = 2*b1 - 1 */
633 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
635 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
636 UWtype a1
__attribute__ ((__unused__
)),
637 UWtype a0
__attribute__ ((__unused__
)),
638 UWtype d
__attribute__ ((__unused__
)))
645 #if (defined (L_udivdi3) || defined (L_divdi3) || \
646 defined (L_umoddi3) || defined (L_moddi3))
651 const UQItype __clz_tab
[256] =
653 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,
654 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,
655 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,
656 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,
657 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,
658 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,
659 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,
660 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
671 count_leading_zeros (ret
, x
);
682 const DWunion uu
= {.ll
= x
};
687 word
= uu
.s
.high
, add
= 0;
689 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
691 count_leading_zeros (ret
, word
);
703 count_trailing_zeros (ret
, x
);
714 const DWunion uu
= {.ll
= x
};
719 word
= uu
.s
.low
, add
= 0;
721 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
723 count_trailing_zeros (ret
, word
);
728 #ifdef L_popcount_tab
729 const UQItype __popcount_tab
[256] =
731 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,
732 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,
733 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,
734 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,
735 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,
736 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,
737 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,
738 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
745 __popcountSI2 (UWtype x
)
749 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
750 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
759 __popcountDI2 (UDWtype x
)
763 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
764 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
773 __paritySI2 (UWtype x
)
776 # error "fill out the table"
787 return (0x6996 >> x
) & 1;
794 __parityDI2 (UDWtype x
)
796 const DWunion uu
= {.ll
= x
};
797 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
800 # error "fill out the table"
811 return (0x6996 >> nx
) & 1;
817 #if (defined (L_udivdi3) || defined (L_divdi3) || \
818 defined (L_umoddi3) || defined (L_moddi3))
819 static inline __attribute__ ((__always_inline__
))
822 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
824 const DWunion nn
= {.ll
= n
};
825 const DWunion dd
= {.ll
= d
};
827 UWtype d0
, d1
, n0
, n1
, n2
;
836 #if !UDIV_NEEDS_NORMALIZATION
843 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
846 /* Remainder in n0. */
853 d0
= 1 / d0
; /* Divide intentionally by zero. */
855 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
856 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
858 /* Remainder in n0. */
869 #else /* UDIV_NEEDS_NORMALIZATION */
877 count_leading_zeros (bm
, d0
);
881 /* Normalize, i.e. make the most significant bit of the
885 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
889 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
892 /* Remainder in n0 >> bm. */
899 d0
= 1 / d0
; /* Divide intentionally by zero. */
901 count_leading_zeros (bm
, d0
);
905 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
906 conclude (the most significant bit of n1 is set) /\ (the
907 leading quotient digit q1 = 1).
909 This special case is necessary, not an optimization.
910 (Shifts counts of W_TYPE_SIZE are undefined.) */
919 b
= W_TYPE_SIZE
- bm
;
923 n1
= (n1
<< bm
) | (n0
>> b
);
926 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
931 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
933 /* Remainder in n0 >> bm. */
943 #endif /* UDIV_NEEDS_NORMALIZATION */
954 /* Remainder in n1n0. */
966 count_leading_zeros (bm
, d1
);
969 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
970 conclude (the most significant bit of n1 is set) /\ (the
971 quotient digit q0 = 0 or 1).
973 This special case is necessary, not an optimization. */
975 /* The condition on the next line takes advantage of that
976 n1 >= d1 (true due to program flow). */
977 if (n1
> d1
|| n0
>= d0
)
980 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
999 b
= W_TYPE_SIZE
- bm
;
1001 d1
= (d1
<< bm
) | (d0
>> b
);
1004 n1
= (n1
<< bm
) | (n0
>> b
);
1007 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1008 umul_ppmm (m1
, m0
, q0
, d0
);
1010 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1013 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1018 /* Remainder in (n1n0 - m1m0) >> bm. */
1021 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1022 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1023 rr
.s
.high
= n1
>> bm
;
1030 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1037 __divdi3 (DWtype u
, DWtype v
)
1040 DWunion uu
= {.ll
= u
};
1041 DWunion vv
= {.ll
= v
};
1051 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1061 __moddi3 (DWtype u
, DWtype v
)
1064 DWunion uu
= {.ll
= u
};
1065 DWunion vv
= {.ll
= v
};
1074 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1084 __umoddi3 (UDWtype u
, UDWtype v
)
1088 (void) __udivmoddi4 (u
, v
, &w
);
1096 __udivdi3 (UDWtype n
, UDWtype d
)
1098 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1104 __cmpdi2 (DWtype a
, DWtype b
)
1106 const DWunion au
= {.ll
= a
};
1107 const DWunion bu
= {.ll
= b
};
1109 if (au
.s
.high
< bu
.s
.high
)
1111 else if (au
.s
.high
> bu
.s
.high
)
1113 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1115 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1123 __ucmpdi2 (DWtype a
, DWtype b
)
1125 const DWunion au
= {.ll
= a
};
1126 const DWunion bu
= {.ll
= b
};
1128 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1130 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1132 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1134 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1140 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1142 __fixunstfDI (TFtype a
)
1147 /* Compute high word of result, as a flonum. */
1148 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1149 /* Convert that to fixed (but not to DWtype!),
1150 and shift it into the high word. */
1151 UDWtype v
= (UWtype
) b
;
1153 /* Remove high part from the TFtype, leaving the low part as flonum. */
1155 /* Convert that to fixed (but not to DWtype!) and add it in.
1156 Sometimes A comes out negative. This is significant, since
1157 A has more bits than a long int does. */
1159 v
-= (UWtype
) (- a
);
1166 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1168 __fixtfdi (TFtype a
)
1171 return - __fixunstfDI (-a
);
1172 return __fixunstfDI (a
);
1176 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1178 __fixunsxfDI (XFtype a
)
1183 /* Compute high word of result, as a flonum. */
1184 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1185 /* Convert that to fixed (but not to DWtype!),
1186 and shift it into the high word. */
1187 UDWtype v
= (UWtype
) b
;
1189 /* Remove high part from the XFtype, leaving the low part as flonum. */
1191 /* Convert that to fixed (but not to DWtype!) and add it in.
1192 Sometimes A comes out negative. This is significant, since
1193 A has more bits than a long int does. */
1195 v
-= (UWtype
) (- a
);
1202 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1204 __fixxfdi (XFtype a
)
1207 return - __fixunsxfDI (-a
);
1208 return __fixunsxfDI (a
);
1212 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1214 __fixunsdfDI (DFtype a
)
1216 /* Get high part of result. The division here will just moves the radix
1217 point and will not cause any rounding. Then the conversion to integral
1218 type chops result as desired. */
1219 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1221 /* Get low part of result. Convert `hi' to floating type and scale it back,
1222 then subtract this from the number being converted. This leaves the low
1223 part. Convert that to integral type. */
1224 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1226 /* Assemble result from the two parts. */
1227 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1231 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1233 __fixdfdi (DFtype a
)
1236 return - __fixunsdfDI (-a
);
1237 return __fixunsdfDI (a
);
1241 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1243 __fixunssfDI (SFtype a
)
1245 #if LIBGCC2_HAS_DF_MODE
1246 /* Convert the SFtype to a DFtype, because that is surely not going
1247 to lose any bits. Some day someone else can write a faster version
1248 that avoids converting to DFtype, and verify it really works right. */
1249 const DFtype dfa
= a
;
1251 /* Get high part of result. The division here will just moves the radix
1252 point and will not cause any rounding. Then the conversion to integral
1253 type chops result as desired. */
1254 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1256 /* Get low part of result. Convert `hi' to floating type and scale it back,
1257 then subtract this from the number being converted. This leaves the low
1258 part. Convert that to integral type. */
1259 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1261 /* Assemble result from the two parts. */
1262 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1263 #elif FLT_MANT_DIG < W_TYPE_SIZE
1266 if (a
< Wtype_MAXp1_F
)
1268 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1270 /* Since we know that there are fewer significant bits in the SFmode
1271 quantity than in a word, we know that we can convert out all the
1272 significant bits in one step, and thus avoid losing bits. */
1274 /* ??? This following loop essentially performs frexpf. If we could
1275 use the real libm function, or poke at the actual bits of the fp
1276 format, it would be significantly faster. */
1278 UWtype shift
= 0, counter
;
1282 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1284 SFtype counterf
= (UWtype
)1 << counter
;
1292 /* Rescale into the range of one word, extract the bits of that
1293 one word, and shift the result into position. */
1296 return (DWtype
)counter
<< shift
;
1305 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1307 __fixsfdi (SFtype a
)
1310 return - __fixunssfDI (-a
);
1311 return __fixunssfDI (a
);
1315 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1317 __floatdixf (DWtype u
)
1319 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1326 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1328 __floatditf (DWtype u
)
1330 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1337 #if defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE
1339 __floatdidf (DWtype u
)
1341 DFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1348 #if defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE
1349 #define DI_SIZE (W_TYPE_SIZE * 2)
1350 #define SF_SIZE FLT_MANT_DIG
1353 __floatdisf (DWtype u
)
1355 #if SF_SIZE >= W_TYPE_SIZE
1356 /* When the word size is small, we never get any rounding error. */
1357 SFtype f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1361 #elif LIBGCC2_HAS_DF_MODE
1363 #if LIBGCC2_DOUBLE_TYPE_SIZE == 64
1364 #define DF_SIZE DBL_MANT_DIG
1365 #elif LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1366 #define DF_SIZE LDBL_MANT_DIG
1371 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1373 /* Protect against double-rounding error.
1374 Represent any low-order bits, that might be truncated by a bit that
1375 won't be lost. The bit can go in anywhere below the rounding position
1376 of the SFmode. A fixed mask and bit position handles all usual
1377 configurations. It doesn't handle the case of 128-bit DImode, however. */
1378 if (DF_SIZE
< DI_SIZE
1379 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1381 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1382 && u
< ((DWtype
) 1 << DF_SIZE
)))
1384 if ((UDWtype
) u
& (REP_BIT
- 1))
1386 u
&= ~ (REP_BIT
- 1);
1392 /* Do the calculation in DFmode so that we don't lose any of the
1393 precision of the high word while multiplying it. */
1394 DFtype f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1399 /* Finally, the word size is larger than the number of bits in SFmode,
1400 and we've got no DFmode. The only way to avoid double rounding is
1401 to special case the extraction. */
1403 /* If there are no high bits set, fall back to one conversion. */
1405 return (SFtype
)(Wtype
)u
;
1407 /* Otherwise, find the power of two. */
1408 Wtype hi
= u
>> W_TYPE_SIZE
;
1412 UWtype count
, shift
;
1413 count_leading_zeros (count
, hi
);
1415 /* No leading bits means u == minimum. */
1417 return -(Wtype_MAXp1_F
* Wtype_MAXp1_F
/ 2);
1419 shift
= W_TYPE_SIZE
- count
;
1421 /* Shift down the most significant bits. */
1424 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1425 if (u
& ((1 << shift
) - 1))
1428 /* Convert the one word of data, and rescale. */
1430 f
*= (UWtype
)1 << shift
;
1436 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1437 /* Reenable the normal types, in case limits.h needs them. */
1450 __fixunsxfSI (XFtype a
)
1452 if (a
>= - (DFtype
) Wtype_MIN
)
1453 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1458 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1459 /* Reenable the normal types, in case limits.h needs them. */
1472 __fixunsdfSI (DFtype a
)
1474 if (a
>= - (DFtype
) Wtype_MIN
)
1475 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1480 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1481 /* Reenable the normal types, in case limits.h needs them. */
1494 __fixunssfSI (SFtype a
)
1496 if (a
>= - (SFtype
) Wtype_MIN
)
1497 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1502 /* Integer power helper used from __builtin_powi for non-constant
1505 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1506 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1507 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1508 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1509 # if defined(L_powisf2)
1510 # define TYPE SFtype
1511 # define NAME __powisf2
1512 # elif defined(L_powidf2)
1513 # define TYPE DFtype
1514 # define NAME __powidf2
1515 # elif defined(L_powixf2)
1516 # define TYPE XFtype
1517 # define NAME __powixf2
1518 # elif defined(L_powitf2)
1519 # define TYPE TFtype
1520 # define NAME __powitf2
1526 NAME (TYPE x
, int m
)
1528 unsigned int n
= m
< 0 ? -m
: m
;
1529 TYPE y
= n
% 2 ? x
: 1;
1536 return m
< 0 ? 1/y
: y
;
1541 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1542 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1543 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1544 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1550 #if defined(L_mulsc3) || defined(L_divsc3)
1551 # define MTYPE SFtype
1552 # define CTYPE SCtype
1555 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1556 #elif defined(L_muldc3) || defined(L_divdc3)
1557 # define MTYPE DFtype
1558 # define CTYPE DCtype
1560 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1565 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1567 #elif defined(L_mulxc3) || defined(L_divxc3)
1568 # define MTYPE XFtype
1569 # define CTYPE XCtype
1573 #elif defined(L_multc3) || defined(L_divtc3)
1574 # define MTYPE TFtype
1575 # define CTYPE TCtype
1583 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1584 #define _CONCAT3(A,B,C) A##B##C
1586 #define CONCAT2(A,B) _CONCAT2(A,B)
1587 #define _CONCAT2(A,B) A##B
1589 /* All of these would be present in a full C99 implementation of <math.h>
1590 and <complex.h>. Our problem is that only a few systems have such full
1591 implementations. Further, libgcc_s.so isn't currently linked against
1592 libm.so, and even for systems that do provide full C99, the extra overhead
1593 of all programs using libgcc having to link against libm. So avoid it. */
1595 #define isnan(x) __builtin_expect ((x) != (x), 0)
1596 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1597 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1599 #define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1602 /* Helpers to make the following code slightly less gross. */
1603 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1604 #define FABS CONCAT2(__builtin_fabs, CEXT)
1606 /* Verify that MTYPE matches up with CEXT. */
1607 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1609 /* Ensure that we've lost any extra precision. */
1613 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1616 #if defined(L_mulsc3) || defined(L_muldc3) \
1617 || defined(L_mulxc3) || defined(L_multc3)
1620 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1622 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1637 if (isnan (x
) && isnan (y
))
1639 /* Recover infinities that computed as NaN + iNaN. */
1641 if (isinf (a
) || isinf (b
))
1643 /* z is infinite. "Box" the infinity and change NaNs in
1644 the other factor to 0. */
1645 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1646 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1647 if (isnan (c
)) c
= COPYSIGN (0, c
);
1648 if (isnan (d
)) d
= COPYSIGN (0, d
);
1651 if (isinf (c
) || isinf (d
))
1653 /* w is infinite. "Box" the infinity and change NaNs in
1654 the other factor to 0. */
1655 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1656 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1657 if (isnan (a
)) a
= COPYSIGN (0, a
);
1658 if (isnan (b
)) b
= COPYSIGN (0, b
);
1662 && (isinf (ac
) || isinf (bd
)
1663 || isinf (ad
) || isinf (bc
)))
1665 /* Recover infinities from overflow by changing NaNs to 0. */
1666 if (isnan (a
)) a
= COPYSIGN (0, a
);
1667 if (isnan (b
)) b
= COPYSIGN (0, b
);
1668 if (isnan (c
)) c
= COPYSIGN (0, c
);
1669 if (isnan (d
)) d
= COPYSIGN (0, d
);
1674 x
= INFINITY
* (a
* c
- b
* d
);
1675 y
= INFINITY
* (a
* d
+ b
* c
);
1681 #endif /* complex multiply */
1683 #if defined(L_divsc3) || defined(L_divdc3) \
1684 || defined(L_divxc3) || defined(L_divtc3)
1687 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1689 MTYPE denom
, ratio
, x
, y
;
1691 /* ??? We can get better behavior from logarithmic scaling instead of
1692 the division. But that would mean starting to link libgcc against
1693 libm. We could implement something akin to ldexp/frexp as gcc builtins
1695 if (FABS (c
) < FABS (d
))
1698 denom
= (c
* ratio
) + d
;
1699 x
= ((a
* ratio
) + b
) / denom
;
1700 y
= ((b
* ratio
) - a
) / denom
;
1705 denom
= (d
* ratio
) + c
;
1706 x
= ((b
* ratio
) + a
) / denom
;
1707 y
= (b
- (a
* ratio
)) / denom
;
1710 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1711 are nonzero/zero, infinite/finite, and finite/infinite. */
1712 if (isnan (x
) && isnan (y
))
1714 if (denom
== 0.0 && (!isnan (a
) || !isnan (b
)))
1716 x
= COPYSIGN (INFINITY
, c
) * a
;
1717 y
= COPYSIGN (INFINITY
, c
) * b
;
1719 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1721 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1722 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1723 x
= INFINITY
* (a
* c
+ b
* d
);
1724 y
= INFINITY
* (b
* c
- a
* d
);
1726 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1728 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1729 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1730 x
= 0.0 * (a
* c
+ b
* d
);
1731 y
= 0.0 * (b
* c
- a
* d
);
1737 #endif /* complex divide */
1739 #endif /* all complex float routines */
1741 /* From here on down, the routines use normal data types. */
1743 #define SItype bogus_type
1744 #define USItype bogus_type
1745 #define DItype bogus_type
1746 #define UDItype bogus_type
1747 #define SFtype bogus_type
1748 #define DFtype bogus_type
1766 /* Like bcmp except the sign is meaningful.
1767 Result is negative if S1 is less than S2,
1768 positive if S1 is greater, 0 if S1 and S2 are equal. */
1771 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1775 const unsigned char c1
= *s1
++, c2
= *s2
++;
1785 /* __eprintf used to be used by GCC's private version of <assert.h>.
1786 We no longer provide that header, but this routine remains in libgcc.a
1787 for binary backward compatibility. Note that it is not included in
1788 the shared version of libgcc. */
1790 #ifndef inhibit_libc
1792 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1796 __eprintf (const char *string
, const char *expression
,
1797 unsigned int line
, const char *filename
)
1799 fprintf (stderr
, string
, expression
, line
, filename
);
1808 #ifdef L_clear_cache
1809 /* Clear part of an instruction cache. */
1812 __clear_cache (char *beg
__attribute__((__unused__
)),
1813 char *end
__attribute__((__unused__
)))
1815 #ifdef CLEAR_INSN_CACHE
1816 CLEAR_INSN_CACHE (beg
, end
);
1817 #endif /* CLEAR_INSN_CACHE */
1820 #endif /* L_clear_cache */
1822 #ifdef L_enable_execute_stack
1823 /* Attempt to turn on execute permission for the stack. */
1825 #ifdef ENABLE_EXECUTE_STACK
1826 ENABLE_EXECUTE_STACK
1829 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
1831 #endif /* ENABLE_EXECUTE_STACK */
1833 #endif /* L_enable_execute_stack */
1837 /* Jump to a trampoline, loading the static chain address. */
1839 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1852 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1856 mprotect (char *addr
, int len
, int prot
)
1873 if (VirtualProtect (addr
, len
, np
, &op
))
1879 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1881 #ifdef TRANSFER_FROM_TRAMPOLINE
1882 TRANSFER_FROM_TRAMPOLINE
1884 #endif /* L_trampoline */
1889 #include "gbl-ctors.h"
1891 /* Some systems use __main in a way incompatible with its use in gcc, in these
1892 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1893 give the same symbol without quotes for an alternative entry point. You
1894 must define both, or neither. */
1896 #define NAME__MAIN "__main"
1897 #define SYMBOL__MAIN __main
1900 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
1901 #undef HAS_INIT_SECTION
1902 #define HAS_INIT_SECTION
1905 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1907 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1908 code to run constructors. In that case, we need to handle EH here, too. */
1910 #ifdef EH_FRAME_SECTION_NAME
1911 #include "unwind-dw2-fde.h"
1912 extern unsigned char __EH_FRAME_BEGIN__
[];
1915 /* Run all the global destructors on exit from the program. */
1918 __do_global_dtors (void)
1920 #ifdef DO_GLOBAL_DTORS_BODY
1921 DO_GLOBAL_DTORS_BODY
;
1923 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1930 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1932 static int completed
= 0;
1936 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1943 #ifndef HAS_INIT_SECTION
1944 /* Run all the global constructors on entry to the program. */
1947 __do_global_ctors (void)
1949 #ifdef EH_FRAME_SECTION_NAME
1951 static struct object object
;
1952 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1955 DO_GLOBAL_CTORS_BODY
;
1956 atexit (__do_global_dtors
);
1958 #endif /* no HAS_INIT_SECTION */
1960 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1961 /* Subroutine called automatically by `main'.
1962 Compiling a global function named `main'
1963 produces an automatic call to this function at the beginning.
1965 For many systems, this routine calls __do_global_ctors.
1966 For systems which support a .init section we use the .init section
1967 to run __do_global_ctors, so we need not do anything here. */
1969 extern void SYMBOL__MAIN (void);
1973 /* Support recursive calls to `main': run initializers just once. */
1974 static int initialized
;
1978 __do_global_ctors ();
1981 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1983 #endif /* L__main */
1984 #endif /* __CYGWIN__ */
1988 #include "gbl-ctors.h"
1990 /* Provide default definitions for the lists of constructors and
1991 destructors, so that we don't get linker errors. These symbols are
1992 intentionally bss symbols, so that gld and/or collect will provide
1993 the right values. */
1995 /* We declare the lists here with two elements each,
1996 so that they are valid empty lists if no other definition is loaded.
1998 If we are using the old "set" extensions to have the gnu linker
1999 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2000 must be in the bss/common section.
2002 Long term no port should use those extensions. But many still do. */
2003 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2004 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2005 func_ptr __CTOR_LIST__
[2] = {0, 0};
2006 func_ptr __DTOR_LIST__
[2] = {0, 0};
2008 func_ptr __CTOR_LIST__
[2];
2009 func_ptr __DTOR_LIST__
[2];
2011 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2012 #endif /* L_ctors */