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
)
89 __addvdi3 (DWtype a
, DWtype b
)
91 const DWtype w
= a
+ b
;
93 if (b
>= 0 ? w
< a
: w
> a
)
102 __subvsi3 (Wtype a
, Wtype b
)
104 const DWtype w
= a
- b
;
106 if (b
>= 0 ? w
> a
: w
< a
)
115 __subvdi3 (DWtype a
, DWtype b
)
117 const DWtype w
= a
- b
;
119 if (b
>= 0 ? w
> a
: w
< a
)
127 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
129 __mulvsi3 (Wtype a
, Wtype b
)
131 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
133 if ((Wtype
) (w
>> WORD_SIZE
) != (Wtype
) w
>> (WORD_SIZE
- 1))
146 if (a
>= 0 ? w
> 0 : w
< 0)
159 if (a
>= 0 ? w
> 0 : w
< 0)
207 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
209 __mulvdi3 (DWtype u
, DWtype v
)
211 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
212 but the checked multiplication needs only two. */
213 const DWunion uu
= {.ll
= u
};
214 const DWunion vv
= {.ll
= v
};
216 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (WORD_SIZE
- 1), 1))
218 /* u fits in a single Wtype. */
219 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
221 /* v fits in a single Wtype as well. */
222 /* A single multiplication. No overflow risk. */
223 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
227 /* Two multiplications. */
228 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
229 * (UDWtype
) (UWtype
) vv
.s
.low
};
230 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
231 * (UDWtype
) (UWtype
) vv
.s
.high
};
234 w1
.s
.high
-= uu
.s
.low
;
237 w1
.ll
+= (UWtype
) w0
.s
.high
;
238 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
240 w0
.s
.high
= w1
.s
.low
;
247 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
249 /* v fits into a single Wtype. */
250 /* Two multiplications. */
251 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
252 * (UDWtype
) (UWtype
) vv
.s
.low
};
253 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
254 * (UDWtype
) (UWtype
) vv
.s
.low
};
257 w1
.s
.high
-= vv
.s
.low
;
260 w1
.ll
+= (UWtype
) w0
.s
.high
;
261 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
263 w0
.s
.high
= w1
.s
.low
;
269 /* A few sign checks and a single multiplication. */
274 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
276 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
277 * (UDWtype
) (UWtype
) vv
.s
.low
;
278 if (__builtin_expect (w
>= 0, 1))
284 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
286 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
287 * (UDWtype
) (UWtype
) vv
.s
.low
};
289 ww
.s
.high
-= uu
.s
.low
;
290 if (__builtin_expect (ww
.s
.high
< 0, 1))
299 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
301 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
302 * (UDWtype
) (UWtype
) vv
.s
.low
};
304 ww
.s
.high
-= vv
.s
.low
;
305 if (__builtin_expect (ww
.s
.high
< 0, 1))
311 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
313 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
314 * (UDWtype
) (UWtype
) vv
.s
.low
};
316 ww
.s
.high
-= uu
.s
.low
;
317 ww
.s
.high
-= vv
.s
.low
;
318 if (__builtin_expect (ww
.s
.high
>= 0, 1))
332 /* Unless shift functions are defined with full ANSI prototypes,
333 parameter b will be promoted to int if word_type is smaller than an int. */
336 __lshrdi3 (DWtype u
, word_type b
)
341 const DWunion uu
= {.ll
= u
};
342 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
348 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
352 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
354 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
355 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
364 __ashldi3 (DWtype u
, word_type b
)
369 const DWunion uu
= {.ll
= u
};
370 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
376 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
380 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
382 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
383 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
392 __ashrdi3 (DWtype u
, word_type b
)
397 const DWunion uu
= {.ll
= u
};
398 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
403 /* w.s.high = 1..1 or 0..0 */
404 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
405 w
.s
.low
= uu
.s
.high
>> -bm
;
409 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
411 w
.s
.high
= uu
.s
.high
>> b
;
412 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
421 extern int __ffsSI2 (UWtype u
);
430 count_trailing_zeros (count
, u
);
437 extern int __ffsDI2 (DWtype u
);
441 const DWunion uu
= {.ll
= u
};
442 UWtype word
, count
, add
;
445 word
= uu
.s
.low
, add
= 0;
446 else if (uu
.s
.high
!= 0)
447 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
451 count_trailing_zeros (count
, word
);
452 return count
+ add
+ 1;
458 __muldi3 (DWtype u
, DWtype v
)
460 const DWunion uu
= {.ll
= u
};
461 const DWunion vv
= {.ll
= v
};
462 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
464 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
465 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
471 #if (defined (L_udivdi3) || defined (L_divdi3) || \
472 defined (L_umoddi3) || defined (L_moddi3))
473 #if defined (sdiv_qrnnd)
474 #define L_udiv_w_sdiv
479 #if defined (sdiv_qrnnd)
480 #if (defined (L_udivdi3) || defined (L_divdi3) || \
481 defined (L_umoddi3) || defined (L_moddi3))
482 static inline __attribute__ ((__always_inline__
))
485 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
492 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
494 /* dividend, divisor, and quotient are nonnegative */
495 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
499 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
500 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
501 /* Divide (c1*2^32 + c0) by d */
502 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
503 /* Add 2^31 to quotient */
504 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
509 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
510 c1
= a1
>> 1; /* A/2 */
511 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
513 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
515 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
517 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
534 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
537 c0
= ~c0
; /* logical NOT */
539 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
541 q
= ~q
; /* (A/2)/b1 */
544 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
562 else /* Implies c1 = b1 */
563 { /* Hence a1 = d - 1 = 2*b1 - 1 */
581 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
583 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
584 UWtype a1
__attribute__ ((__unused__
)),
585 UWtype a0
__attribute__ ((__unused__
)),
586 UWtype d
__attribute__ ((__unused__
)))
593 #if (defined (L_udivdi3) || defined (L_divdi3) || \
594 defined (L_umoddi3) || defined (L_moddi3))
599 const UQItype __clz_tab
[] =
601 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,
602 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,
603 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,
604 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,
605 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,
606 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,
607 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,
608 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,
614 extern int __clzSI2 (UWtype x
);
620 count_leading_zeros (ret
, x
);
628 extern int __clzDI2 (UDWtype x
);
632 const DWunion uu
= {.ll
= x
};
637 word
= uu
.s
.high
, add
= 0;
639 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
641 count_leading_zeros (ret
, word
);
648 extern int __ctzSI2 (UWtype x
);
654 count_trailing_zeros (ret
, x
);
662 extern int __ctzDI2 (UDWtype x
);
666 const DWunion uu
= {.ll
= x
};
671 word
= uu
.s
.low
, add
= 0;
673 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
675 count_trailing_zeros (ret
, word
);
680 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
681 || defined (L_popcount_tab))
682 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
685 #ifdef L_popcount_tab
686 const UQItype __popcount_tab
[] =
688 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,
689 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,
690 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,
691 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,
692 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,
693 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,
694 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,
695 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,
701 extern int __popcountSI2 (UWtype x
);
703 __popcountSI2 (UWtype x
)
707 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
708 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
716 extern int __popcountDI2 (UDWtype x
);
718 __popcountDI2 (UDWtype x
)
722 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
723 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
731 extern int __paritySI2 (UWtype x
);
733 __paritySI2 (UWtype x
)
736 # error "fill out the table"
747 return (0x6996 >> x
) & 1;
753 extern int __parityDI2 (UDWtype x
);
755 __parityDI2 (UDWtype x
)
757 const DWunion uu
= {.ll
= x
};
758 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
761 # error "fill out the table"
772 return (0x6996 >> nx
) & 1;
778 #if (defined (L_udivdi3) || defined (L_divdi3) || \
779 defined (L_umoddi3) || defined (L_moddi3))
780 static inline __attribute__ ((__always_inline__
))
783 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
785 const DWunion nn
= {.ll
= n
};
786 const DWunion dd
= {.ll
= d
};
788 UWtype d0
, d1
, n0
, n1
, n2
;
797 #if !UDIV_NEEDS_NORMALIZATION
804 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
807 /* Remainder in n0. */
814 d0
= 1 / d0
; /* Divide intentionally by zero. */
816 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
817 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
819 /* Remainder in n0. */
830 #else /* UDIV_NEEDS_NORMALIZATION */
838 count_leading_zeros (bm
, d0
);
842 /* Normalize, i.e. make the most significant bit of the
846 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
850 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
853 /* Remainder in n0 >> bm. */
860 d0
= 1 / d0
; /* Divide intentionally by zero. */
862 count_leading_zeros (bm
, d0
);
866 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
867 conclude (the most significant bit of n1 is set) /\ (the
868 leading quotient digit q1 = 1).
870 This special case is necessary, not an optimization.
871 (Shifts counts of W_TYPE_SIZE are undefined.) */
880 b
= W_TYPE_SIZE
- bm
;
884 n1
= (n1
<< bm
) | (n0
>> b
);
887 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
892 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
894 /* Remainder in n0 >> bm. */
904 #endif /* UDIV_NEEDS_NORMALIZATION */
915 /* Remainder in n1n0. */
927 count_leading_zeros (bm
, d1
);
930 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
931 conclude (the most significant bit of n1 is set) /\ (the
932 quotient digit q0 = 0 or 1).
934 This special case is necessary, not an optimization. */
936 /* The condition on the next line takes advantage of that
937 n1 >= d1 (true due to program flow). */
938 if (n1
> d1
|| n0
>= d0
)
941 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
960 b
= W_TYPE_SIZE
- bm
;
962 d1
= (d1
<< bm
) | (d0
>> b
);
965 n1
= (n1
<< bm
) | (n0
>> b
);
968 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
969 umul_ppmm (m1
, m0
, q0
, d0
);
971 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
974 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
979 /* Remainder in (n1n0 - m1m0) >> bm. */
982 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
983 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
984 rr
.s
.high
= n1
>> bm
;
991 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
998 __divdi3 (DWtype u
, DWtype v
)
1001 DWunion uu
= {.ll
= u
};
1002 DWunion vv
= {.ll
= v
};
1012 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1022 __moddi3 (DWtype u
, DWtype v
)
1025 DWunion uu
= {.ll
= u
};
1026 DWunion vv
= {.ll
= v
};
1035 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
1045 __umoddi3 (UDWtype u
, UDWtype v
)
1049 (void) __udivmoddi4 (u
, v
, &w
);
1057 __udivdi3 (UDWtype n
, UDWtype d
)
1059 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1065 __cmpdi2 (DWtype a
, DWtype b
)
1067 const DWunion au
= {.ll
= a
};
1068 const DWunion bu
= {.ll
= b
};
1070 if (au
.s
.high
< bu
.s
.high
)
1072 else if (au
.s
.high
> bu
.s
.high
)
1074 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1076 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1084 __ucmpdi2 (DWtype a
, DWtype b
)
1086 const DWunion au
= {.ll
= a
};
1087 const DWunion bu
= {.ll
= b
};
1089 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1091 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1093 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1095 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1101 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1102 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1103 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1106 __fixunstfDI (TFtype a
)
1111 /* Compute high word of result, as a flonum. */
1112 const TFtype b
= (a
/ HIGH_WORD_COEFF
);
1113 /* Convert that to fixed (but not to DWtype!),
1114 and shift it into the high word. */
1115 UDWtype v
= (UWtype
) b
;
1117 /* Remove high part from the TFtype, leaving the low part as flonum. */
1119 /* Convert that to fixed (but not to DWtype!) and add it in.
1120 Sometimes A comes out negative. This is significant, since
1121 A has more bits than a long int does. */
1123 v
-= (UWtype
) (- a
);
1130 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1132 __fixtfdi (TFtype a
)
1135 return - __fixunstfDI (-a
);
1136 return __fixunstfDI (a
);
1140 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1141 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1142 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1145 __fixunsxfDI (XFtype a
)
1150 /* Compute high word of result, as a flonum. */
1151 const XFtype b
= (a
/ HIGH_WORD_COEFF
);
1152 /* Convert that to fixed (but not to DWtype!),
1153 and shift it into the high word. */
1154 UDWtype v
= (UWtype
) b
;
1156 /* Remove high part from the XFtype, leaving the low part as flonum. */
1158 /* Convert that to fixed (but not to DWtype!) and add it in.
1159 Sometimes A comes out negative. This is significant, since
1160 A has more bits than a long int does. */
1162 v
-= (UWtype
) (- a
);
1169 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1171 __fixxfdi (XFtype a
)
1174 return - __fixunsxfDI (-a
);
1175 return __fixunsxfDI (a
);
1180 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1181 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1184 __fixunsdfDI (DFtype a
)
1186 /* Get high part of result. The division here will just moves the radix
1187 point and will not cause any rounding. Then the conversion to integral
1188 type chops result as desired. */
1189 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1191 /* Get low part of result. Convert `hi' to floating type and scale it back,
1192 then subtract this from the number being converted. This leaves the low
1193 part. Convert that to integral type. */
1194 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1196 /* Assemble result from the two parts. */
1197 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1203 __fixdfdi (DFtype a
)
1206 return - __fixunsdfDI (-a
);
1207 return __fixunsdfDI (a
);
1212 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1213 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1216 __fixunssfDI (SFtype original_a
)
1218 /* Convert the SFtype to a DFtype, because that is surely not going
1219 to lose any bits. Some day someone else can write a faster version
1220 that avoids converting to DFtype, and verify it really works right. */
1221 const DFtype a
= original_a
;
1223 /* Get high part of result. The division here will just moves the radix
1224 point and will not cause any rounding. Then the conversion to integral
1225 type chops result as desired. */
1226 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1228 /* Get low part of result. Convert `hi' to floating type and scale it back,
1229 then subtract this from the number being converted. This leaves the low
1230 part. Convert that to integral type. */
1231 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1233 /* Assemble result from the two parts. */
1234 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1240 __fixsfdi (SFtype a
)
1243 return - __fixunssfDI (-a
);
1244 return __fixunssfDI (a
);
1248 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1249 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1250 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1251 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1254 __floatdixf (DWtype u
)
1256 XFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1257 d
*= HIGH_HALFWORD_COEFF
;
1258 d
*= HIGH_HALFWORD_COEFF
;
1259 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1265 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1266 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1267 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1268 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1271 __floatditf (DWtype u
)
1273 TFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1274 d
*= HIGH_HALFWORD_COEFF
;
1275 d
*= HIGH_HALFWORD_COEFF
;
1276 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1283 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1284 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1285 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1288 __floatdidf (DWtype u
)
1290 DFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1291 d
*= HIGH_HALFWORD_COEFF
;
1292 d
*= HIGH_HALFWORD_COEFF
;
1293 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1300 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1301 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1302 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1304 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1305 #define DF_SIZE DBL_MANT_DIG
1306 #define SF_SIZE FLT_MANT_DIG
1309 __floatdisf (DWtype u
)
1311 /* Protect against double-rounding error.
1312 Represent any low-order bits, that might be truncated in DFmode,
1313 by a bit that won't be lost. The bit can go in anywhere below the
1314 rounding position of the SFmode. A fixed mask and bit position
1315 handles all usual configurations. It doesn't handle the case
1316 of 128-bit DImode, however. */
1317 if (DF_SIZE
< DI_SIZE
1318 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1320 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1321 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1322 && u
< ((DWtype
) 1 << DF_SIZE
)))
1324 if ((UDWtype
) u
& (REP_BIT
- 1))
1326 u
&= ~ (REP_BIT
- 1);
1331 /* Do the calculation in DFmode
1332 so that we don't lose any of the precision of the high word
1333 while multiplying it. */
1334 DFtype f
= (Wtype
) (u
>> WORD_SIZE
);
1335 f
*= HIGH_HALFWORD_COEFF
;
1336 f
*= HIGH_HALFWORD_COEFF
;
1337 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1343 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1344 /* Reenable the normal types, in case limits.h needs them. */
1357 __fixunsxfSI (XFtype a
)
1359 if (a
>= - (DFtype
) Wtype_MIN
)
1360 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1366 /* Reenable the normal types, in case limits.h needs them. */
1379 __fixunsdfSI (DFtype a
)
1381 if (a
>= - (DFtype
) Wtype_MIN
)
1382 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1388 /* Reenable the normal types, in case limits.h needs them. */
1401 __fixunssfSI (SFtype a
)
1403 if (a
>= - (SFtype
) Wtype_MIN
)
1404 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1409 /* From here on down, the routines use normal data types. */
1411 #define SItype bogus_type
1412 #define USItype bogus_type
1413 #define DItype bogus_type
1414 #define UDItype bogus_type
1415 #define SFtype bogus_type
1416 #define DFtype bogus_type
1434 /* Like bcmp except the sign is meaningful.
1435 Result is negative if S1 is less than S2,
1436 positive if S1 is greater, 0 if S1 and S2 are equal. */
1439 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1443 const unsigned char c1
= *s1
++, c2
= *s2
++;
1453 /* __eprintf used to be used by GCC's private version of <assert.h>.
1454 We no longer provide that header, but this routine remains in libgcc.a
1455 for binary backward compatibility. Note that it is not included in
1456 the shared version of libgcc. */
1458 #ifndef inhibit_libc
1460 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1464 __eprintf (const char *string
, const char *expression
,
1465 unsigned int line
, const char *filename
)
1467 fprintf (stderr
, string
, expression
, line
, filename
);
1476 #ifdef L_clear_cache
1477 /* Clear part of an instruction cache. */
1480 __clear_cache (char *beg
__attribute__((__unused__
)),
1481 char *end
__attribute__((__unused__
)))
1483 #ifdef CLEAR_INSN_CACHE
1484 CLEAR_INSN_CACHE (beg
, end
);
1485 #endif /* CLEAR_INSN_CACHE */
1488 #endif /* L_clear_cache */
1492 /* Jump to a trampoline, loading the static chain address. */
1494 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1507 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1511 mprotect (char *addr
, int len
, int prot
)
1528 if (VirtualProtect (addr
, len
, np
, &op
))
1534 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1536 #ifdef TRANSFER_FROM_TRAMPOLINE
1537 TRANSFER_FROM_TRAMPOLINE
1539 #endif /* L_trampoline */
1544 #include "gbl-ctors.h"
1545 /* Some systems use __main in a way incompatible with its use in gcc, in these
1546 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1547 give the same symbol without quotes for an alternative entry point. You
1548 must define both, or neither. */
1550 #define NAME__MAIN "__main"
1551 #define SYMBOL__MAIN __main
1554 #ifdef INIT_SECTION_ASM_OP
1555 #undef HAS_INIT_SECTION
1556 #define HAS_INIT_SECTION
1559 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1561 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1562 code to run constructors. In that case, we need to handle EH here, too. */
1564 #ifdef EH_FRAME_SECTION_NAME
1565 #include "unwind-dw2-fde.h"
1566 extern unsigned char __EH_FRAME_BEGIN__
[];
1569 /* Run all the global destructors on exit from the program. */
1572 __do_global_dtors (void)
1574 #ifdef DO_GLOBAL_DTORS_BODY
1575 DO_GLOBAL_DTORS_BODY
;
1577 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1584 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1586 static int completed
= 0;
1590 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1597 #ifndef HAS_INIT_SECTION
1598 /* Run all the global constructors on entry to the program. */
1601 __do_global_ctors (void)
1603 #ifdef EH_FRAME_SECTION_NAME
1605 static struct object object
;
1606 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1609 DO_GLOBAL_CTORS_BODY
;
1610 atexit (__do_global_dtors
);
1612 #endif /* no HAS_INIT_SECTION */
1614 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1615 /* Subroutine called automatically by `main'.
1616 Compiling a global function named `main'
1617 produces an automatic call to this function at the beginning.
1619 For many systems, this routine calls __do_global_ctors.
1620 For systems which support a .init section we use the .init section
1621 to run __do_global_ctors, so we need not do anything here. */
1623 extern void SYMBOL__MAIN (void);
1627 /* Support recursive calls to `main': run initializers just once. */
1628 static int initialized
;
1632 __do_global_ctors ();
1635 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1637 #endif /* L__main */
1638 #endif /* __CYGWIN__ */
1642 #include "gbl-ctors.h"
1644 /* Provide default definitions for the lists of constructors and
1645 destructors, so that we don't get linker errors. These symbols are
1646 intentionally bss symbols, so that gld and/or collect will provide
1647 the right values. */
1649 /* We declare the lists here with two elements each,
1650 so that they are valid empty lists if no other definition is loaded.
1652 If we are using the old "set" extensions to have the gnu linker
1653 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1654 must be in the bss/common section.
1656 Long term no port should use those extensions. But many still do. */
1657 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1658 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1659 func_ptr __CTOR_LIST__
[2] = {0, 0};
1660 func_ptr __DTOR_LIST__
[2] = {0, 0};
1662 func_ptr __CTOR_LIST__
[2];
1663 func_ptr __DTOR_LIST__
[2];
1665 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1666 #endif /* L_ctors */