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)
72 w
.s
.high
= -uu
.s
.high
- ((UWtype
) w
.s
.low
> 0);
80 __addvsi3 (Wtype a
, Wtype b
)
86 if (b
>= 0 ? w
< a
: w
> a
)
95 __addvdi3 (DWtype a
, DWtype b
)
101 if (b
>= 0 ? w
< a
: w
> a
)
110 __subvsi3 (Wtype a
, Wtype b
)
116 if (b
>= 0 ? w
> a
: w
< a
)
125 __subvdi3 (DWtype a
, DWtype b
)
131 if (b
>= 0 ? w
> a
: w
< a
)
139 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
141 __mulvsi3 (Wtype a
, Wtype b
)
145 w
= (DWtype
) a
* (DWtype
) b
;
147 if (((a
>= 0) == (b
>= 0))
148 ? (UDWtype
) w
> (UDWtype
) (((DWtype
) 1 << (WORD_SIZE
- 1)) - 1)
149 : (UDWtype
) w
< (UDWtype
) ((DWtype
) -1 << (WORD_SIZE
- 1)))
164 if (a
>= 0 ? w
> 0 : w
< 0)
179 if (a
>= 0 ? w
> 0 : w
< 0)
227 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
229 __mulvdi3 (DWtype u
, DWtype v
)
231 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
232 but the checked multiplication needs only two. */
238 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (WORD_SIZE
- 1), 1))
240 /* u fits in a single Wtype. */
241 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
243 /* v fits in a single Wtype as well. */
244 /* A single multiplication. No overflow risk. */
245 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
249 /* Two multiplications. */
252 w0
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
* (UDWtype
) (UWtype
) vv
.s
.low
;
253 w1
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
* (UDWtype
) (UWtype
) vv
.s
.high
;
255 w1
.s
.high
-= uu
.s
.low
;
258 w1
.ll
+= (UWtype
) w0
.s
.high
;
259 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
261 w0
.s
.high
= w1
.s
.low
;
268 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
270 /* v fits into a single Wtype. */
271 /* Two multiplications. */
274 w0
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
* (UDWtype
) (UWtype
) vv
.s
.low
;
275 w1
.ll
= (UDWtype
) (UWtype
) uu
.s
.high
* (UDWtype
) (UWtype
) vv
.s
.low
;
277 w1
.s
.high
-= vv
.s
.low
;
280 w1
.ll
+= (UWtype
) w0
.s
.high
;
281 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
283 w0
.s
.high
= w1
.s
.low
;
289 /* A few sign checks and a single multiplication. */
294 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
298 w
= (UDWtype
) (UWtype
) uu
.s
.low
299 * (UDWtype
) (UWtype
) vv
.s
.low
;
300 if (__builtin_expect (w
>= 0, 1))
306 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
310 ww
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
311 * (UDWtype
) (UWtype
) vv
.s
.low
;
312 ww
.s
.high
-= uu
.s
.low
;
313 if (__builtin_expect (ww
.s
.high
< 0, 1))
322 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
326 ww
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
327 * (UDWtype
) (UWtype
) vv
.s
.low
;
328 ww
.s
.high
-= vv
.s
.low
;
329 if (__builtin_expect (ww
.s
.high
< 0, 1))
335 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
339 ww
.ll
= (UDWtype
) (UWtype
) uu
.s
.low
340 * (UDWtype
) (UWtype
) vv
.s
.low
;
341 ww
.s
.high
-= uu
.s
.low
;
342 ww
.s
.high
-= vv
.s
.low
;
343 if (__builtin_expect (ww
.s
.high
>= 0, 1))
357 /* Unless shift functions are defined with full ANSI prototypes,
358 parameter b will be promoted to int if word_type is smaller than an int. */
361 __lshrdi3 (DWtype u
, word_type b
)
372 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
376 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
380 UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
382 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
383 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
392 __ashldi3 (DWtype u
, word_type b
)
403 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
407 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
411 UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
413 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
414 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
423 __ashrdi3 (DWtype u
, word_type b
)
434 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
437 /* w.s.high = 1..1 or 0..0 */
438 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
439 w
.s
.low
= uu
.s
.high
>> -bm
;
443 UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
445 w
.s
.high
= uu
.s
.high
>> b
;
446 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
455 extern int __ffsSI2 (UWtype u
);
464 count_trailing_zeros (count
, u
);
471 extern int __ffsDI2 (DWtype u
);
476 UWtype word
, count
, add
;
480 word
= uu
.s
.low
, add
= 0;
481 else if (uu
.s
.high
!= 0)
482 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
486 count_trailing_zeros (count
, word
);
487 return count
+ add
+ 1;
493 __muldi3 (DWtype u
, DWtype v
)
501 w
.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
);
502 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
503 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
509 #if (defined (L_udivdi3) || defined (L_divdi3) || \
510 defined (L_umoddi3) || defined (L_moddi3))
511 #if defined (sdiv_qrnnd)
512 #define L_udiv_w_sdiv
517 #if defined (sdiv_qrnnd)
518 #if (defined (L_udivdi3) || defined (L_divdi3) || \
519 defined (L_umoddi3) || defined (L_moddi3))
520 static inline __attribute__ ((__always_inline__
))
523 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
530 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
532 /* dividend, divisor, and quotient are nonnegative */
533 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
537 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
538 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
539 /* Divide (c1*2^32 + c0) by d */
540 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
541 /* Add 2^31 to quotient */
542 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
547 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
548 c1
= a1
>> 1; /* A/2 */
549 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
551 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
553 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
555 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
572 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
575 c0
= ~c0
; /* logical NOT */
577 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
579 q
= ~q
; /* (A/2)/b1 */
582 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
600 else /* Implies c1 = b1 */
601 { /* Hence a1 = d - 1 = 2*b1 - 1 */
619 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
621 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
622 UWtype a1
__attribute__ ((__unused__
)),
623 UWtype a0
__attribute__ ((__unused__
)),
624 UWtype d
__attribute__ ((__unused__
)))
631 #if (defined (L_udivdi3) || defined (L_divdi3) || \
632 defined (L_umoddi3) || defined (L_moddi3))
637 const UQItype __clz_tab
[] =
639 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,
640 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,
641 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,
642 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,
643 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,
644 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,
645 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,
646 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,
652 extern int __clzSI2 (UWtype x
);
658 count_leading_zeros (ret
, x
);
666 extern int __clzDI2 (UDWtype x
);
676 word
= uu
.s
.high
, add
= 0;
678 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
680 count_leading_zeros (ret
, word
);
687 extern int __ctzSI2 (UWtype x
);
693 count_trailing_zeros (ret
, x
);
701 extern int __ctzDI2 (UDWtype x
);
711 word
= uu
.s
.low
, add
= 0;
713 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
715 count_trailing_zeros (ret
, word
);
720 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
721 || defined (L_popcount_tab))
722 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
725 #ifdef L_popcount_tab
726 const UQItype __popcount_tab
[] =
728 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,
729 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,
730 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,
731 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,
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 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,
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 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,
741 extern int __popcountSI2 (UWtype x
);
743 __popcountSI2 (UWtype x
)
747 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
748 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
756 extern int __popcountDI2 (UDWtype x
);
758 __popcountDI2 (UDWtype x
)
762 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
763 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
771 extern int __paritySI2 (UWtype x
);
773 __paritySI2 (UWtype x
)
776 # error "fill out the table"
787 return (0x6996 >> x
) & 1;
793 extern int __parityDI2 (UDWtype x
);
795 __parityDI2 (UDWtype x
)
801 nx
= uu
.s
.low
^ uu
.s
.high
;
804 # error "fill out the table"
815 return (0x6996 >> nx
) & 1;
821 #if (defined (L_udivdi3) || defined (L_divdi3) || \
822 defined (L_umoddi3) || defined (L_moddi3))
823 static inline __attribute__ ((__always_inline__
))
826 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
831 UWtype d0
, d1
, n0
, n1
, n2
;
843 #if !UDIV_NEEDS_NORMALIZATION
850 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
853 /* Remainder in n0. */
860 d0
= 1 / d0
; /* Divide intentionally by zero. */
862 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
863 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
865 /* Remainder in n0. */
876 #else /* UDIV_NEEDS_NORMALIZATION */
884 count_leading_zeros (bm
, d0
);
888 /* Normalize, i.e. make the most significant bit of the
892 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
896 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
899 /* Remainder in n0 >> bm. */
906 d0
= 1 / d0
; /* Divide intentionally by zero. */
908 count_leading_zeros (bm
, d0
);
912 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
913 conclude (the most significant bit of n1 is set) /\ (the
914 leading quotient digit q1 = 1).
916 This special case is necessary, not an optimization.
917 (Shifts counts of W_TYPE_SIZE are undefined.) */
926 b
= W_TYPE_SIZE
- bm
;
930 n1
= (n1
<< bm
) | (n0
>> b
);
933 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
938 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
940 /* Remainder in n0 >> bm. */
950 #endif /* UDIV_NEEDS_NORMALIZATION */
961 /* Remainder in n1n0. */
973 count_leading_zeros (bm
, d1
);
976 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
977 conclude (the most significant bit of n1 is set) /\ (the
978 quotient digit q0 = 0 or 1).
980 This special case is necessary, not an optimization. */
982 /* The condition on the next line takes advantage of that
983 n1 >= d1 (true due to program flow). */
984 if (n1
> d1
|| n0
>= d0
)
987 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1006 b
= W_TYPE_SIZE
- bm
;
1008 d1
= (d1
<< bm
) | (d0
>> b
);
1011 n1
= (n1
<< bm
) | (n0
>> b
);
1014 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1015 umul_ppmm (m1
, m0
, q0
, d0
);
1017 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1020 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1025 /* Remainder in (n1n0 - m1m0) >> bm. */
1028 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1029 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1030 rr
.s
.high
= n1
>> bm
;
1045 __divdi3 (DWtype u
, DWtype v
)
1061 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1071 __moddi3 (DWtype u
, DWtype v
)
1086 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
1096 __umoddi3 (UDWtype u
, UDWtype v
)
1100 (void) __udivmoddi4 (u
, v
, &w
);
1108 __udivdi3 (UDWtype n
, UDWtype d
)
1110 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1116 __cmpdi2 (DWtype a
, DWtype b
)
1120 au
.ll
= a
, bu
.ll
= b
;
1122 if (au
.s
.high
< bu
.s
.high
)
1124 else if (au
.s
.high
> bu
.s
.high
)
1126 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1128 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1136 __ucmpdi2 (DWtype a
, DWtype b
)
1140 au
.ll
= a
, bu
.ll
= b
;
1142 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1144 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1146 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1148 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1154 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1155 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1156 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1159 __fixunstfDI (TFtype a
)
1167 /* Compute high word of result, as a flonum. */
1168 b
= (a
/ HIGH_WORD_COEFF
);
1169 /* Convert that to fixed (but not to DWtype!),
1170 and shift it into the high word. */
1173 /* Remove high part from the TFtype, leaving the low part as flonum. */
1175 /* Convert that to fixed (but not to DWtype!) and add it in.
1176 Sometimes A comes out negative. This is significant, since
1177 A has more bits than a long int does. */
1179 v
-= (UWtype
) (- a
);
1186 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1188 __fixtfdi (TFtype a
)
1191 return - __fixunstfDI (-a
);
1192 return __fixunstfDI (a
);
1196 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1197 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1198 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1201 __fixunsxfDI (XFtype a
)
1209 /* Compute high word of result, as a flonum. */
1210 b
= (a
/ HIGH_WORD_COEFF
);
1211 /* Convert that to fixed (but not to DWtype!),
1212 and shift it into the high word. */
1215 /* Remove high part from the XFtype, leaving the low part as flonum. */
1217 /* Convert that to fixed (but not to DWtype!) and add it in.
1218 Sometimes A comes out negative. This is significant, since
1219 A has more bits than a long int does. */
1221 v
-= (UWtype
) (- a
);
1228 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1230 __fixxfdi (XFtype a
)
1233 return - __fixunsxfDI (-a
);
1234 return __fixunsxfDI (a
);
1239 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1240 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1243 __fixunsdfDI (DFtype a
)
1247 /* Get high part of result. The division here will just moves the radix
1248 point and will not cause any rounding. Then the conversion to integral
1249 type chops result as desired. */
1250 hi
= a
/ HIGH_WORD_COEFF
;
1252 /* Get low part of result. Convert `hi' to floating type and scale it back,
1253 then subtract this from the number being converted. This leaves the low
1254 part. Convert that to integral type. */
1255 lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1257 /* Assemble result from the two parts. */
1258 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1264 __fixdfdi (DFtype a
)
1267 return - __fixunsdfDI (-a
);
1268 return __fixunsdfDI (a
);
1273 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1274 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1277 __fixunssfDI (SFtype original_a
)
1279 /* Convert the SFtype to a DFtype, because that is surely not going
1280 to lose any bits. Some day someone else can write a faster version
1281 that avoids converting to DFtype, and verify it really works right. */
1282 DFtype a
= original_a
;
1285 /* Get high part of result. The division here will just moves the radix
1286 point and will not cause any rounding. Then the conversion to integral
1287 type chops result as desired. */
1288 hi
= a
/ HIGH_WORD_COEFF
;
1290 /* Get low part of result. Convert `hi' to floating type and scale it back,
1291 then subtract this from the number being converted. This leaves the low
1292 part. Convert that to integral type. */
1293 lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1295 /* Assemble result from the two parts. */
1296 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1302 __fixsfdi (SFtype a
)
1305 return - __fixunssfDI (-a
);
1306 return __fixunssfDI (a
);
1310 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1311 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1312 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1313 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1316 __floatdixf (DWtype u
)
1320 d
= (Wtype
) (u
>> WORD_SIZE
);
1321 d
*= HIGH_HALFWORD_COEFF
;
1322 d
*= HIGH_HALFWORD_COEFF
;
1323 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1329 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1330 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1331 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1332 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1335 __floatditf (DWtype u
)
1339 d
= (Wtype
) (u
>> WORD_SIZE
);
1340 d
*= HIGH_HALFWORD_COEFF
;
1341 d
*= HIGH_HALFWORD_COEFF
;
1342 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1349 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1350 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1351 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1354 __floatdidf (DWtype u
)
1358 d
= (Wtype
) (u
>> WORD_SIZE
);
1359 d
*= HIGH_HALFWORD_COEFF
;
1360 d
*= HIGH_HALFWORD_COEFF
;
1361 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1368 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1369 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1370 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1372 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1373 #define DF_SIZE DBL_MANT_DIG
1374 #define SF_SIZE FLT_MANT_DIG
1377 __floatdisf (DWtype u
)
1379 /* Do the calculation in DFmode
1380 so that we don't lose any of the precision of the high word
1381 while multiplying it. */
1384 /* Protect against double-rounding error.
1385 Represent any low-order bits, that might be truncated in DFmode,
1386 by a bit that won't be lost. The bit can go in anywhere below the
1387 rounding position of the SFmode. A fixed mask and bit position
1388 handles all usual configurations. It doesn't handle the case
1389 of 128-bit DImode, however. */
1390 if (DF_SIZE
< DI_SIZE
1391 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1393 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1394 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1395 && u
< ((DWtype
) 1 << DF_SIZE
)))
1397 if ((UDWtype
) u
& (REP_BIT
- 1))
1399 u
&= ~ (REP_BIT
- 1);
1404 f
= (Wtype
) (u
>> WORD_SIZE
);
1405 f
*= HIGH_HALFWORD_COEFF
;
1406 f
*= HIGH_HALFWORD_COEFF
;
1407 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1413 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1414 /* Reenable the normal types, in case limits.h needs them. */
1427 __fixunsxfSI (XFtype a
)
1429 if (a
>= - (DFtype
) Wtype_MIN
)
1430 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1436 /* Reenable the normal types, in case limits.h needs them. */
1449 __fixunsdfSI (DFtype a
)
1451 if (a
>= - (DFtype
) Wtype_MIN
)
1452 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1458 /* Reenable the normal types, in case limits.h needs them. */
1471 __fixunssfSI (SFtype a
)
1473 if (a
>= - (SFtype
) Wtype_MIN
)
1474 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1479 /* From here on down, the routines use normal data types. */
1481 #define SItype bogus_type
1482 #define USItype bogus_type
1483 #define DItype bogus_type
1484 #define UDItype bogus_type
1485 #define SFtype bogus_type
1486 #define DFtype bogus_type
1504 /* Like bcmp except the sign is meaningful.
1505 Result is negative if S1 is less than S2,
1506 positive if S1 is greater, 0 if S1 and S2 are equal. */
1509 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1513 unsigned char c1
= *s1
++, c2
= *s2
++;
1523 /* __eprintf used to be used by GCC's private version of <assert.h>.
1524 We no longer provide that header, but this routine remains in libgcc.a
1525 for binary backward compatibility. Note that it is not included in
1526 the shared version of libgcc. */
1528 #ifndef inhibit_libc
1530 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1534 __eprintf (const char *string
, const char *expression
,
1535 unsigned int line
, const char *filename
)
1537 fprintf (stderr
, string
, expression
, line
, filename
);
1546 #ifdef L_clear_cache
1547 /* Clear part of an instruction cache. */
1550 __clear_cache (char *beg
__attribute__((__unused__
)),
1551 char *end
__attribute__((__unused__
)))
1553 #ifdef CLEAR_INSN_CACHE
1554 CLEAR_INSN_CACHE (beg
, end
);
1555 #endif /* CLEAR_INSN_CACHE */
1558 #endif /* L_clear_cache */
1562 /* Jump to a trampoline, loading the static chain address. */
1564 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1577 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1581 mprotect (char *addr
, int len
, int prot
)
1598 if (VirtualProtect (addr
, len
, np
, &op
))
1604 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1606 #ifdef TRANSFER_FROM_TRAMPOLINE
1607 TRANSFER_FROM_TRAMPOLINE
1609 #endif /* L_trampoline */
1614 #include "gbl-ctors.h"
1615 /* Some systems use __main in a way incompatible with its use in gcc, in these
1616 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1617 give the same symbol without quotes for an alternative entry point. You
1618 must define both, or neither. */
1620 #define NAME__MAIN "__main"
1621 #define SYMBOL__MAIN __main
1624 #ifdef INIT_SECTION_ASM_OP
1625 #undef HAS_INIT_SECTION
1626 #define HAS_INIT_SECTION
1629 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1631 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1632 code to run constructors. In that case, we need to handle EH here, too. */
1634 #ifdef EH_FRAME_SECTION_NAME
1635 #include "unwind-dw2-fde.h"
1636 extern unsigned char __EH_FRAME_BEGIN__
[];
1639 /* Run all the global destructors on exit from the program. */
1642 __do_global_dtors (void)
1644 #ifdef DO_GLOBAL_DTORS_BODY
1645 DO_GLOBAL_DTORS_BODY
;
1647 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1654 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1656 static int completed
= 0;
1660 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1667 #ifndef HAS_INIT_SECTION
1668 /* Run all the global constructors on entry to the program. */
1671 __do_global_ctors (void)
1673 #ifdef EH_FRAME_SECTION_NAME
1675 static struct object object
;
1676 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1679 DO_GLOBAL_CTORS_BODY
;
1680 atexit (__do_global_dtors
);
1682 #endif /* no HAS_INIT_SECTION */
1684 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1685 /* Subroutine called automatically by `main'.
1686 Compiling a global function named `main'
1687 produces an automatic call to this function at the beginning.
1689 For many systems, this routine calls __do_global_ctors.
1690 For systems which support a .init section we use the .init section
1691 to run __do_global_ctors, so we need not do anything here. */
1696 /* Support recursive calls to `main': run initializers just once. */
1697 static int initialized
;
1701 __do_global_ctors ();
1704 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1706 #endif /* L__main */
1707 #endif /* __CYGWIN__ */
1711 #include "gbl-ctors.h"
1713 /* Provide default definitions for the lists of constructors and
1714 destructors, so that we don't get linker errors. These symbols are
1715 intentionally bss symbols, so that gld and/or collect will provide
1716 the right values. */
1718 /* We declare the lists here with two elements each,
1719 so that they are valid empty lists if no other definition is loaded.
1721 If we are using the old "set" extensions to have the gnu linker
1722 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1723 must be in the bss/common section.
1725 Long term no port should use those extensions. But many still do. */
1726 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1727 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1728 func_ptr __CTOR_LIST__
[2] = {0, 0};
1729 func_ptr __DTOR_LIST__
[2] = {0, 0};
1731 func_ptr __CTOR_LIST__
[2];
1732 func_ptr __DTOR_LIST__
[2];
1734 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1735 #endif /* L_ctors */