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 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, 59 Temple Place - Suite 330, Boston, MA
33 /* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
34 supposedly valid even though this is a "target" file. */
35 #include "auto-host.h"
37 /* It is incorrect to include config.h here, because this file is being
38 compiled for the target, and hence definitions concerning only the host
42 #include "coretypes.h"
45 /* Don't use `fancy_abort' here even if config.h says to use it. */
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
53 #define ATTRIBUTE_HIDDEN
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
= a
+ 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
= a
+ 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
= a
+ b
;
105 if (b
>= 0 ? w
< a
: w
> a
)
114 __subvSI3 (Wtype a
, Wtype b
)
116 const Wtype w
= a
- 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
= a
- 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
= a
- b
;
143 if (b
>= 0 ? w
> a
: w
< a
)
151 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
153 __mulvSI3 (Wtype a
, Wtype b
)
155 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
157 if ((Wtype
) (w
>> WORD_SIZE
) != (Wtype
) w
>> (WORD_SIZE
- 1))
162 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
164 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
166 __mulvsi3 (SItype a
, SItype b
)
168 const DItype w
= (DItype
) a
* (DItype
) b
;
170 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
175 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
184 if (a
>= 0 ? w
> 0 : w
< 0)
189 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
195 if (a
>= 0 ? w
> 0 : w
< 0)
200 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
209 if (a
>= 0 ? w
> 0 : w
< 0)
234 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
252 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
276 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
278 __mulvDI3 (DWtype u
, DWtype v
)
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu
= {.ll
= u
};
283 const DWunion vv
= {.ll
= v
};
285 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (WORD_SIZE
- 1), 1))
287 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
296 /* Two multiplications. */
297 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
298 * (UDWtype
) (UWtype
) vv
.s
.low
};
299 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
300 * (UDWtype
) (UWtype
) vv
.s
.high
};
303 w1
.s
.high
-= uu
.s
.low
;
306 w1
.ll
+= (UWtype
) w0
.s
.high
;
307 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
309 w0
.s
.high
= w1
.s
.low
;
316 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
321 * (UDWtype
) (UWtype
) vv
.s
.low
};
322 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
323 * (UDWtype
) (UWtype
) vv
.s
.low
};
326 w1
.s
.high
-= vv
.s
.low
;
329 w1
.ll
+= (UWtype
) w0
.s
.high
;
330 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
332 w0
.s
.high
= w1
.s
.low
;
338 /* A few sign checks and a single multiplication. */
343 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
345 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
346 * (UDWtype
) (UWtype
) vv
.s
.low
;
347 if (__builtin_expect (w
>= 0, 1))
353 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
355 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
356 * (UDWtype
) (UWtype
) vv
.s
.low
};
358 ww
.s
.high
-= uu
.s
.low
;
359 if (__builtin_expect (ww
.s
.high
< 0, 1))
368 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
370 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
371 * (UDWtype
) (UWtype
) vv
.s
.low
};
373 ww
.s
.high
-= vv
.s
.low
;
374 if (__builtin_expect (ww
.s
.high
< 0, 1))
380 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
382 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
383 * (UDWtype
) (UWtype
) vv
.s
.low
};
385 ww
.s
.high
-= uu
.s
.low
;
386 ww
.s
.high
-= vv
.s
.low
;
387 if (__builtin_expect (ww
.s
.high
>= 0, 1))
401 /* Unless shift functions are defined with full ANSI prototypes,
402 parameter b will be promoted to int if word_type is smaller than an int. */
405 __lshrdi3 (DWtype u
, word_type b
)
410 const DWunion uu
= {.ll
= u
};
411 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
417 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
421 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
423 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
424 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
433 __ashldi3 (DWtype u
, word_type b
)
438 const DWunion uu
= {.ll
= u
};
439 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
445 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
449 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
451 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
452 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
461 __ashrdi3 (DWtype u
, word_type b
)
466 const DWunion uu
= {.ll
= u
};
467 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
472 /* w.s.high = 1..1 or 0..0 */
473 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
474 w
.s
.low
= uu
.s
.high
>> -bm
;
478 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
480 w
.s
.high
= uu
.s
.high
>> b
;
481 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
490 extern int __ffsSI2 (UWtype u
);
499 count_trailing_zeros (count
, u
);
506 extern int __ffsDI2 (DWtype u
);
510 const DWunion uu
= {.ll
= u
};
511 UWtype word
, count
, add
;
514 word
= uu
.s
.low
, add
= 0;
515 else if (uu
.s
.high
!= 0)
516 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
520 count_trailing_zeros (count
, word
);
521 return count
+ add
+ 1;
527 __muldi3 (DWtype u
, DWtype v
)
529 const DWunion uu
= {.ll
= u
};
530 const DWunion vv
= {.ll
= v
};
531 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
533 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
534 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
540 #if (defined (L_udivdi3) || defined (L_divdi3) || \
541 defined (L_umoddi3) || defined (L_moddi3))
542 #if defined (sdiv_qrnnd)
543 #define L_udiv_w_sdiv
548 #if defined (sdiv_qrnnd)
549 #if (defined (L_udivdi3) || defined (L_divdi3) || \
550 defined (L_umoddi3) || defined (L_moddi3))
551 static inline __attribute__ ((__always_inline__
))
554 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
561 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
563 /* dividend, divisor, and quotient are nonnegative */
564 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
568 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
569 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
570 /* Divide (c1*2^32 + c0) by d */
571 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
572 /* Add 2^31 to quotient */
573 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
578 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
579 c1
= a1
>> 1; /* A/2 */
580 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
582 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
584 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
586 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
603 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
606 c0
= ~c0
; /* logical NOT */
608 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
610 q
= ~q
; /* (A/2)/b1 */
613 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
631 else /* Implies c1 = b1 */
632 { /* Hence a1 = d - 1 = 2*b1 - 1 */
650 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
652 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
653 UWtype a1
__attribute__ ((__unused__
)),
654 UWtype a0
__attribute__ ((__unused__
)),
655 UWtype d
__attribute__ ((__unused__
)))
662 #if (defined (L_udivdi3) || defined (L_divdi3) || \
663 defined (L_umoddi3) || defined (L_moddi3))
668 const UQItype __clz_tab
[] =
670 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,
671 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,
672 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,
673 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,
674 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,
675 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,
676 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,
677 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,
683 extern int __clzSI2 (UWtype x
);
689 count_leading_zeros (ret
, x
);
697 extern int __clzDI2 (UDWtype x
);
701 const DWunion uu
= {.ll
= x
};
706 word
= uu
.s
.high
, add
= 0;
708 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
710 count_leading_zeros (ret
, word
);
717 extern int __ctzSI2 (UWtype x
);
723 count_trailing_zeros (ret
, x
);
731 extern int __ctzDI2 (UDWtype x
);
735 const DWunion uu
= {.ll
= x
};
740 word
= uu
.s
.low
, add
= 0;
742 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
744 count_trailing_zeros (ret
, word
);
749 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
750 || defined (L_popcount_tab))
751 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
754 #ifdef L_popcount_tab
755 const UQItype __popcount_tab
[] =
757 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,
758 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,
759 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,
760 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,
761 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,
762 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,
763 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,
764 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,
770 extern int __popcountSI2 (UWtype x
);
772 __popcountSI2 (UWtype x
)
776 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
777 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
785 extern int __popcountDI2 (UDWtype x
);
787 __popcountDI2 (UDWtype x
)
791 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
792 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
800 extern int __paritySI2 (UWtype x
);
802 __paritySI2 (UWtype x
)
805 # error "fill out the table"
816 return (0x6996 >> x
) & 1;
822 extern int __parityDI2 (UDWtype x
);
824 __parityDI2 (UDWtype x
)
826 const DWunion uu
= {.ll
= x
};
827 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
830 # error "fill out the table"
841 return (0x6996 >> nx
) & 1;
847 #if (defined (L_udivdi3) || defined (L_divdi3) || \
848 defined (L_umoddi3) || defined (L_moddi3))
849 static inline __attribute__ ((__always_inline__
))
852 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
854 const DWunion nn
= {.ll
= n
};
855 const DWunion dd
= {.ll
= d
};
857 UWtype d0
, d1
, n0
, n1
, n2
;
866 #if !UDIV_NEEDS_NORMALIZATION
873 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
876 /* Remainder in n0. */
883 d0
= 1 / d0
; /* Divide intentionally by zero. */
885 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
886 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
888 /* Remainder in n0. */
899 #else /* UDIV_NEEDS_NORMALIZATION */
907 count_leading_zeros (bm
, d0
);
911 /* Normalize, i.e. make the most significant bit of the
915 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
919 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
922 /* Remainder in n0 >> bm. */
929 d0
= 1 / d0
; /* Divide intentionally by zero. */
931 count_leading_zeros (bm
, d0
);
935 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
936 conclude (the most significant bit of n1 is set) /\ (the
937 leading quotient digit q1 = 1).
939 This special case is necessary, not an optimization.
940 (Shifts counts of W_TYPE_SIZE are undefined.) */
949 b
= W_TYPE_SIZE
- bm
;
953 n1
= (n1
<< bm
) | (n0
>> b
);
956 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
961 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
963 /* Remainder in n0 >> bm. */
973 #endif /* UDIV_NEEDS_NORMALIZATION */
984 /* Remainder in n1n0. */
996 count_leading_zeros (bm
, d1
);
999 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1000 conclude (the most significant bit of n1 is set) /\ (the
1001 quotient digit q0 = 0 or 1).
1003 This special case is necessary, not an optimization. */
1005 /* The condition on the next line takes advantage of that
1006 n1 >= d1 (true due to program flow). */
1007 if (n1
> d1
|| n0
>= d0
)
1010 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1029 b
= W_TYPE_SIZE
- bm
;
1031 d1
= (d1
<< bm
) | (d0
>> b
);
1034 n1
= (n1
<< bm
) | (n0
>> b
);
1037 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1038 umul_ppmm (m1
, m0
, q0
, d0
);
1040 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1043 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1048 /* Remainder in (n1n0 - m1m0) >> bm. */
1051 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1052 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1053 rr
.s
.high
= n1
>> bm
;
1060 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1067 __divdi3 (DWtype u
, DWtype v
)
1070 DWunion uu
= {.ll
= u
};
1071 DWunion vv
= {.ll
= v
};
1081 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1091 __moddi3 (DWtype u
, DWtype v
)
1094 DWunion uu
= {.ll
= u
};
1095 DWunion vv
= {.ll
= v
};
1104 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
1114 __umoddi3 (UDWtype u
, UDWtype v
)
1118 (void) __udivmoddi4 (u
, v
, &w
);
1126 __udivdi3 (UDWtype n
, UDWtype d
)
1128 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1134 __cmpdi2 (DWtype a
, DWtype b
)
1136 const DWunion au
= {.ll
= a
};
1137 const DWunion bu
= {.ll
= b
};
1139 if (au
.s
.high
< bu
.s
.high
)
1141 else if (au
.s
.high
> bu
.s
.high
)
1143 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1145 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1153 __ucmpdi2 (DWtype a
, DWtype b
)
1155 const DWunion au
= {.ll
= a
};
1156 const DWunion bu
= {.ll
= b
};
1158 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1160 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1162 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1164 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1170 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1171 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1172 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1175 __fixunstfDI (TFtype a
)
1180 /* Compute high word of result, as a flonum. */
1181 const TFtype b
= (a
/ HIGH_WORD_COEFF
);
1182 /* Convert that to fixed (but not to DWtype!),
1183 and shift it into the high word. */
1184 UDWtype v
= (UWtype
) b
;
1186 /* Remove high part from the TFtype, leaving the low part as flonum. */
1188 /* Convert that to fixed (but not to DWtype!) and add it in.
1189 Sometimes A comes out negative. This is significant, since
1190 A has more bits than a long int does. */
1192 v
-= (UWtype
) (- a
);
1199 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1201 __fixtfdi (TFtype a
)
1204 return - __fixunstfDI (-a
);
1205 return __fixunstfDI (a
);
1209 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1210 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1211 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1214 __fixunsxfDI (XFtype a
)
1219 /* Compute high word of result, as a flonum. */
1220 const XFtype b
= (a
/ HIGH_WORD_COEFF
);
1221 /* Convert that to fixed (but not to DWtype!),
1222 and shift it into the high word. */
1223 UDWtype v
= (UWtype
) b
;
1225 /* Remove high part from the XFtype, leaving the low part as flonum. */
1227 /* Convert that to fixed (but not to DWtype!) and add it in.
1228 Sometimes A comes out negative. This is significant, since
1229 A has more bits than a long int does. */
1231 v
-= (UWtype
) (- a
);
1238 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1240 __fixxfdi (XFtype a
)
1243 return - __fixunsxfDI (-a
);
1244 return __fixunsxfDI (a
);
1249 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1250 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1253 __fixunsdfDI (DFtype a
)
1255 /* Get high part of result. The division here will just moves the radix
1256 point and will not cause any rounding. Then the conversion to integral
1257 type chops result as desired. */
1258 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1260 /* Get low part of result. Convert `hi' to floating type and scale it back,
1261 then subtract this from the number being converted. This leaves the low
1262 part. Convert that to integral type. */
1263 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1265 /* Assemble result from the two parts. */
1266 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1272 __fixdfdi (DFtype a
)
1275 return - __fixunsdfDI (-a
);
1276 return __fixunsdfDI (a
);
1281 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1282 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1285 __fixunssfDI (SFtype original_a
)
1287 /* Convert the SFtype to a DFtype, because that is surely not going
1288 to lose any bits. Some day someone else can write a faster version
1289 that avoids converting to DFtype, and verify it really works right. */
1290 const DFtype a
= original_a
;
1292 /* Get high part of result. The division here will just moves the radix
1293 point and will not cause any rounding. Then the conversion to integral
1294 type chops result as desired. */
1295 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1297 /* Get low part of result. Convert `hi' to floating type and scale it back,
1298 then subtract this from the number being converted. This leaves the low
1299 part. Convert that to integral type. */
1300 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1302 /* Assemble result from the two parts. */
1303 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1309 __fixsfdi (SFtype a
)
1312 return - __fixunssfDI (-a
);
1313 return __fixunssfDI (a
);
1317 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1318 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1319 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1320 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1323 __floatdixf (DWtype u
)
1325 XFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1326 d
*= HIGH_HALFWORD_COEFF
;
1327 d
*= HIGH_HALFWORD_COEFF
;
1328 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1334 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1335 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1336 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1337 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1340 __floatditf (DWtype u
)
1342 TFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1343 d
*= HIGH_HALFWORD_COEFF
;
1344 d
*= HIGH_HALFWORD_COEFF
;
1345 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1352 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1353 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1354 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1357 __floatdidf (DWtype u
)
1359 DFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1360 d
*= HIGH_HALFWORD_COEFF
;
1361 d
*= HIGH_HALFWORD_COEFF
;
1362 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1369 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1370 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1371 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1373 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1374 #define DF_SIZE DBL_MANT_DIG
1375 #define SF_SIZE FLT_MANT_DIG
1378 __floatdisf (DWtype u
)
1380 /* Protect against double-rounding error.
1381 Represent any low-order bits, that might be truncated in DFmode,
1382 by a bit that won't be lost. The bit can go in anywhere below the
1383 rounding position of the SFmode. A fixed mask and bit position
1384 handles all usual configurations. It doesn't handle the case
1385 of 128-bit DImode, however. */
1386 if (DF_SIZE
< DI_SIZE
1387 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1389 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1390 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1391 && u
< ((DWtype
) 1 << DF_SIZE
)))
1393 if ((UDWtype
) u
& (REP_BIT
- 1))
1395 u
&= ~ (REP_BIT
- 1);
1400 /* Do the calculation in DFmode
1401 so that we don't lose any of the precision of the high word
1402 while multiplying it. */
1403 DFtype f
= (Wtype
) (u
>> WORD_SIZE
);
1404 f
*= HIGH_HALFWORD_COEFF
;
1405 f
*= HIGH_HALFWORD_COEFF
;
1406 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1412 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1413 /* Reenable the normal types, in case limits.h needs them. */
1426 __fixunsxfSI (XFtype a
)
1428 if (a
>= - (DFtype
) Wtype_MIN
)
1429 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1435 /* Reenable the normal types, in case limits.h needs them. */
1448 __fixunsdfSI (DFtype a
)
1450 if (a
>= - (DFtype
) Wtype_MIN
)
1451 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1457 /* Reenable the normal types, in case limits.h needs them. */
1470 __fixunssfSI (SFtype a
)
1472 if (a
>= - (SFtype
) Wtype_MIN
)
1473 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1478 /* From here on down, the routines use normal data types. */
1480 #define SItype bogus_type
1481 #define USItype bogus_type
1482 #define DItype bogus_type
1483 #define UDItype bogus_type
1484 #define SFtype bogus_type
1485 #define DFtype bogus_type
1503 /* Like bcmp except the sign is meaningful.
1504 Result is negative if S1 is less than S2,
1505 positive if S1 is greater, 0 if S1 and S2 are equal. */
1508 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1512 const unsigned char c1
= *s1
++, c2
= *s2
++;
1522 /* __eprintf used to be used by GCC's private version of <assert.h>.
1523 We no longer provide that header, but this routine remains in libgcc.a
1524 for binary backward compatibility. Note that it is not included in
1525 the shared version of libgcc. */
1527 #ifndef inhibit_libc
1529 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1533 __eprintf (const char *string
, const char *expression
,
1534 unsigned int line
, const char *filename
)
1536 fprintf (stderr
, string
, expression
, line
, filename
);
1545 #ifdef L_clear_cache
1546 /* Clear part of an instruction cache. */
1549 __clear_cache (char *beg
__attribute__((__unused__
)),
1550 char *end
__attribute__((__unused__
)))
1552 #ifdef CLEAR_INSN_CACHE
1553 CLEAR_INSN_CACHE (beg
, end
);
1554 #endif /* CLEAR_INSN_CACHE */
1557 #endif /* L_clear_cache */
1559 #ifdef L_enable_execute_stack
1560 /* Attempt to turn on execute permission for the stack. */
1562 #ifdef ENABLE_EXECUTE_STACK
1563 ENABLE_EXECUTE_STACK
1566 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
1568 #endif /* ENABLE_EXECUTE_STACK */
1570 #endif /* L_enable_execute_stack */
1574 /* Jump to a trampoline, loading the static chain address. */
1576 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1589 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1593 mprotect (char *addr
, int len
, int prot
)
1610 if (VirtualProtect (addr
, len
, np
, &op
))
1616 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1618 #ifdef TRANSFER_FROM_TRAMPOLINE
1619 TRANSFER_FROM_TRAMPOLINE
1621 #endif /* L_trampoline */
1626 #include "gbl-ctors.h"
1627 /* Some systems use __main in a way incompatible with its use in gcc, in these
1628 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1629 give the same symbol without quotes for an alternative entry point. You
1630 must define both, or neither. */
1632 #define NAME__MAIN "__main"
1633 #define SYMBOL__MAIN __main
1636 #ifdef INIT_SECTION_ASM_OP
1637 #undef HAS_INIT_SECTION
1638 #define HAS_INIT_SECTION
1641 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1643 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1644 code to run constructors. In that case, we need to handle EH here, too. */
1646 #ifdef EH_FRAME_SECTION_NAME
1647 #include "unwind-dw2-fde.h"
1648 extern unsigned char __EH_FRAME_BEGIN__
[];
1651 /* Run all the global destructors on exit from the program. */
1654 __do_global_dtors (void)
1656 #ifdef DO_GLOBAL_DTORS_BODY
1657 DO_GLOBAL_DTORS_BODY
;
1659 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1666 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1668 static int completed
= 0;
1672 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1679 #ifndef HAS_INIT_SECTION
1680 /* Run all the global constructors on entry to the program. */
1683 __do_global_ctors (void)
1685 #ifdef EH_FRAME_SECTION_NAME
1687 static struct object object
;
1688 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1691 DO_GLOBAL_CTORS_BODY
;
1692 atexit (__do_global_dtors
);
1694 #endif /* no HAS_INIT_SECTION */
1696 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1697 /* Subroutine called automatically by `main'.
1698 Compiling a global function named `main'
1699 produces an automatic call to this function at the beginning.
1701 For many systems, this routine calls __do_global_ctors.
1702 For systems which support a .init section we use the .init section
1703 to run __do_global_ctors, so we need not do anything here. */
1705 extern void SYMBOL__MAIN (void);
1709 /* Support recursive calls to `main': run initializers just once. */
1710 static int initialized
;
1714 __do_global_ctors ();
1717 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1719 #endif /* L__main */
1720 #endif /* __CYGWIN__ */
1724 #include "gbl-ctors.h"
1726 /* Provide default definitions for the lists of constructors and
1727 destructors, so that we don't get linker errors. These symbols are
1728 intentionally bss symbols, so that gld and/or collect will provide
1729 the right values. */
1731 /* We declare the lists here with two elements each,
1732 so that they are valid empty lists if no other definition is loaded.
1734 If we are using the old "set" extensions to have the gnu linker
1735 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1736 must be in the bss/common section.
1738 Long term no port should use those extensions. But many still do. */
1739 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1740 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1741 func_ptr __CTOR_LIST__
[2] = {0, 0};
1742 func_ptr __DTOR_LIST__
[2] = {0, 0};
1744 func_ptr __CTOR_LIST__
[2];
1745 func_ptr __DTOR_LIST__
[2];
1747 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1748 #endif /* L_ctors */