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 (((a
>= 0) == (b
>= 0))
134 ? (UDWtype
) w
> (UDWtype
) (((DWtype
) 1 << (WORD_SIZE
- 1)) - 1)
135 : (UDWtype
) w
< (UDWtype
) ((DWtype
) -1 << (WORD_SIZE
- 1)))
148 if (a
>= 0 ? w
> 0 : w
< 0)
161 if (a
>= 0 ? w
> 0 : w
< 0)
209 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
211 __mulvdi3 (DWtype u
, DWtype v
)
213 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
214 but the checked multiplication needs only two. */
215 const DWunion uu
= {.ll
= u
};
216 const DWunion vv
= {.ll
= v
};
218 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (WORD_SIZE
- 1), 1))
220 /* u fits in a single Wtype. */
221 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
223 /* v fits in a single Wtype as well. */
224 /* A single multiplication. No overflow risk. */
225 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
229 /* Two multiplications. */
230 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
231 * (UDWtype
) (UWtype
) vv
.s
.low
};
232 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
233 * (UDWtype
) (UWtype
) vv
.s
.high
};
236 w1
.s
.high
-= uu
.s
.low
;
239 w1
.ll
+= (UWtype
) w0
.s
.high
;
240 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
242 w0
.s
.high
= w1
.s
.low
;
249 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (WORD_SIZE
- 1), 1))
251 /* v fits into a single Wtype. */
252 /* Two multiplications. */
253 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
254 * (UDWtype
) (UWtype
) vv
.s
.low
};
255 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
256 * (UDWtype
) (UWtype
) vv
.s
.low
};
259 w1
.s
.high
-= vv
.s
.low
;
262 w1
.ll
+= (UWtype
) w0
.s
.high
;
263 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (WORD_SIZE
- 1), 1))
265 w0
.s
.high
= w1
.s
.low
;
271 /* A few sign checks and a single multiplication. */
276 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
278 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
279 * (UDWtype
) (UWtype
) vv
.s
.low
;
280 if (__builtin_expect (w
>= 0, 1))
286 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
288 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
289 * (UDWtype
) (UWtype
) vv
.s
.low
};
291 ww
.s
.high
-= uu
.s
.low
;
292 if (__builtin_expect (ww
.s
.high
< 0, 1))
301 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
303 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
304 * (UDWtype
) (UWtype
) vv
.s
.low
};
306 ww
.s
.high
-= vv
.s
.low
;
307 if (__builtin_expect (ww
.s
.high
< 0, 1))
313 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
315 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
316 * (UDWtype
) (UWtype
) vv
.s
.low
};
318 ww
.s
.high
-= uu
.s
.low
;
319 ww
.s
.high
-= vv
.s
.low
;
320 if (__builtin_expect (ww
.s
.high
>= 0, 1))
334 /* Unless shift functions are defined with full ANSI prototypes,
335 parameter b will be promoted to int if word_type is smaller than an int. */
338 __lshrdi3 (DWtype u
, word_type b
)
343 const DWunion uu
= {.ll
= u
};
344 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
350 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
354 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
356 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
357 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
366 __ashldi3 (DWtype u
, word_type b
)
371 const DWunion uu
= {.ll
= u
};
372 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
378 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
382 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
384 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
385 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
394 __ashrdi3 (DWtype u
, word_type b
)
399 const DWunion uu
= {.ll
= u
};
400 const word_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
405 /* w.s.high = 1..1 or 0..0 */
406 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
407 w
.s
.low
= uu
.s
.high
>> -bm
;
411 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
413 w
.s
.high
= uu
.s
.high
>> b
;
414 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
423 extern int __ffsSI2 (UWtype u
);
432 count_trailing_zeros (count
, u
);
439 extern int __ffsDI2 (DWtype u
);
443 const DWunion uu
= {.ll
= u
};
444 UWtype word
, count
, add
;
447 word
= uu
.s
.low
, add
= 0;
448 else if (uu
.s
.high
!= 0)
449 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
453 count_trailing_zeros (count
, word
);
454 return count
+ add
+ 1;
460 __muldi3 (DWtype u
, DWtype v
)
462 const DWunion uu
= {.ll
= u
};
463 const DWunion vv
= {.ll
= v
};
464 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
466 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
467 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
473 #if (defined (L_udivdi3) || defined (L_divdi3) || \
474 defined (L_umoddi3) || defined (L_moddi3))
475 #if defined (sdiv_qrnnd)
476 #define L_udiv_w_sdiv
481 #if defined (sdiv_qrnnd)
482 #if (defined (L_udivdi3) || defined (L_divdi3) || \
483 defined (L_umoddi3) || defined (L_moddi3))
484 static inline __attribute__ ((__always_inline__
))
487 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
494 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
496 /* dividend, divisor, and quotient are nonnegative */
497 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
501 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
502 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
503 /* Divide (c1*2^32 + c0) by d */
504 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
505 /* Add 2^31 to quotient */
506 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
511 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
512 c1
= a1
>> 1; /* A/2 */
513 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
515 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
517 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
519 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
536 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
539 c0
= ~c0
; /* logical NOT */
541 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
543 q
= ~q
; /* (A/2)/b1 */
546 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
564 else /* Implies c1 = b1 */
565 { /* Hence a1 = d - 1 = 2*b1 - 1 */
583 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
585 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
586 UWtype a1
__attribute__ ((__unused__
)),
587 UWtype a0
__attribute__ ((__unused__
)),
588 UWtype d
__attribute__ ((__unused__
)))
595 #if (defined (L_udivdi3) || defined (L_divdi3) || \
596 defined (L_umoddi3) || defined (L_moddi3))
601 const UQItype __clz_tab
[] =
603 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,
604 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,
605 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,
606 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,
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,
609 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,
610 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,
616 extern int __clzSI2 (UWtype x
);
622 count_leading_zeros (ret
, x
);
630 extern int __clzDI2 (UDWtype x
);
634 const DWunion uu
= {.ll
= x
};
639 word
= uu
.s
.high
, add
= 0;
641 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
643 count_leading_zeros (ret
, word
);
650 extern int __ctzSI2 (UWtype x
);
656 count_trailing_zeros (ret
, x
);
664 extern int __ctzDI2 (UDWtype x
);
668 const DWunion uu
= {.ll
= x
};
673 word
= uu
.s
.low
, add
= 0;
675 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
677 count_trailing_zeros (ret
, word
);
682 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
683 || defined (L_popcount_tab))
684 extern const UQItype __popcount_tab
[] ATTRIBUTE_HIDDEN
;
687 #ifdef L_popcount_tab
688 const UQItype __popcount_tab
[] =
690 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,
691 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,
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 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,
695 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,
696 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,
697 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,
703 extern int __popcountSI2 (UWtype x
);
705 __popcountSI2 (UWtype x
)
709 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
710 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
718 extern int __popcountDI2 (UDWtype x
);
720 __popcountDI2 (UDWtype x
)
724 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
725 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
733 extern int __paritySI2 (UWtype x
);
735 __paritySI2 (UWtype x
)
738 # error "fill out the table"
749 return (0x6996 >> x
) & 1;
755 extern int __parityDI2 (UDWtype x
);
757 __parityDI2 (UDWtype x
)
759 const DWunion uu
= {.ll
= x
};
760 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
763 # error "fill out the table"
774 return (0x6996 >> nx
) & 1;
780 #if (defined (L_udivdi3) || defined (L_divdi3) || \
781 defined (L_umoddi3) || defined (L_moddi3))
782 static inline __attribute__ ((__always_inline__
))
785 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
787 const DWunion nn
= {.ll
= n
};
788 const DWunion dd
= {.ll
= d
};
790 UWtype d0
, d1
, n0
, n1
, n2
;
799 #if !UDIV_NEEDS_NORMALIZATION
806 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
809 /* Remainder in n0. */
816 d0
= 1 / d0
; /* Divide intentionally by zero. */
818 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
819 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
821 /* Remainder in n0. */
832 #else /* UDIV_NEEDS_NORMALIZATION */
840 count_leading_zeros (bm
, d0
);
844 /* Normalize, i.e. make the most significant bit of the
848 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
852 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
855 /* Remainder in n0 >> bm. */
862 d0
= 1 / d0
; /* Divide intentionally by zero. */
864 count_leading_zeros (bm
, d0
);
868 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
869 conclude (the most significant bit of n1 is set) /\ (the
870 leading quotient digit q1 = 1).
872 This special case is necessary, not an optimization.
873 (Shifts counts of W_TYPE_SIZE are undefined.) */
882 b
= W_TYPE_SIZE
- bm
;
886 n1
= (n1
<< bm
) | (n0
>> b
);
889 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
894 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
896 /* Remainder in n0 >> bm. */
906 #endif /* UDIV_NEEDS_NORMALIZATION */
917 /* Remainder in n1n0. */
929 count_leading_zeros (bm
, d1
);
932 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
933 conclude (the most significant bit of n1 is set) /\ (the
934 quotient digit q0 = 0 or 1).
936 This special case is necessary, not an optimization. */
938 /* The condition on the next line takes advantage of that
939 n1 >= d1 (true due to program flow). */
940 if (n1
> d1
|| n0
>= d0
)
943 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
962 b
= W_TYPE_SIZE
- bm
;
964 d1
= (d1
<< bm
) | (d0
>> b
);
967 n1
= (n1
<< bm
) | (n0
>> b
);
970 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
971 umul_ppmm (m1
, m0
, q0
, d0
);
973 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
976 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
981 /* Remainder in (n1n0 - m1m0) >> bm. */
984 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
985 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
986 rr
.s
.high
= n1
>> bm
;
993 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1000 __divdi3 (DWtype u
, DWtype v
)
1003 DWunion uu
= {.ll
= u
};
1004 DWunion vv
= {.ll
= v
};
1014 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1024 __moddi3 (DWtype u
, DWtype v
)
1027 DWunion uu
= {.ll
= u
};
1028 DWunion vv
= {.ll
= v
};
1037 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
1047 __umoddi3 (UDWtype u
, UDWtype v
)
1051 (void) __udivmoddi4 (u
, v
, &w
);
1059 __udivdi3 (UDWtype n
, UDWtype d
)
1061 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1067 __cmpdi2 (DWtype a
, DWtype b
)
1069 const DWunion au
= {.ll
= a
};
1070 const DWunion bu
= {.ll
= b
};
1072 if (au
.s
.high
< bu
.s
.high
)
1074 else if (au
.s
.high
> bu
.s
.high
)
1076 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1078 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1086 __ucmpdi2 (DWtype a
, DWtype b
)
1088 const DWunion au
= {.ll
= a
};
1089 const DWunion bu
= {.ll
= b
};
1091 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1093 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1095 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1097 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1103 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1104 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1105 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1108 __fixunstfDI (TFtype a
)
1113 /* Compute high word of result, as a flonum. */
1114 const TFtype b
= (a
/ HIGH_WORD_COEFF
);
1115 /* Convert that to fixed (but not to DWtype!),
1116 and shift it into the high word. */
1117 UDWtype v
= (UWtype
) b
;
1119 /* Remove high part from the TFtype, leaving the low part as flonum. */
1121 /* Convert that to fixed (but not to DWtype!) and add it in.
1122 Sometimes A comes out negative. This is significant, since
1123 A has more bits than a long int does. */
1125 v
-= (UWtype
) (- a
);
1132 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1134 __fixtfdi (TFtype a
)
1137 return - __fixunstfDI (-a
);
1138 return __fixunstfDI (a
);
1142 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1143 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1144 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1147 __fixunsxfDI (XFtype a
)
1152 /* Compute high word of result, as a flonum. */
1153 const XFtype b
= (a
/ HIGH_WORD_COEFF
);
1154 /* Convert that to fixed (but not to DWtype!),
1155 and shift it into the high word. */
1156 UDWtype v
= (UWtype
) b
;
1158 /* Remove high part from the XFtype, leaving the low part as flonum. */
1160 /* Convert that to fixed (but not to DWtype!) and add it in.
1161 Sometimes A comes out negative. This is significant, since
1162 A has more bits than a long int does. */
1164 v
-= (UWtype
) (- a
);
1171 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1173 __fixxfdi (XFtype a
)
1176 return - __fixunsxfDI (-a
);
1177 return __fixunsxfDI (a
);
1182 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1183 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1186 __fixunsdfDI (DFtype a
)
1188 /* Get high part of result. The division here will just moves the radix
1189 point and will not cause any rounding. Then the conversion to integral
1190 type chops result as desired. */
1191 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1193 /* Get low part of result. Convert `hi' to floating type and scale it back,
1194 then subtract this from the number being converted. This leaves the low
1195 part. Convert that to integral type. */
1196 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1198 /* Assemble result from the two parts. */
1199 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1205 __fixdfdi (DFtype a
)
1208 return - __fixunsdfDI (-a
);
1209 return __fixunsdfDI (a
);
1214 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1215 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1218 __fixunssfDI (SFtype original_a
)
1220 /* Convert the SFtype to a DFtype, because that is surely not going
1221 to lose any bits. Some day someone else can write a faster version
1222 that avoids converting to DFtype, and verify it really works right. */
1223 const DFtype a
= original_a
;
1225 /* Get high part of result. The division here will just moves the radix
1226 point and will not cause any rounding. Then the conversion to integral
1227 type chops result as desired. */
1228 const UWtype hi
= a
/ HIGH_WORD_COEFF
;
1230 /* Get low part of result. Convert `hi' to floating type and scale it back,
1231 then subtract this from the number being converted. This leaves the low
1232 part. Convert that to integral type. */
1233 const UWtype lo
= (a
- ((DFtype
) hi
) * HIGH_WORD_COEFF
);
1235 /* Assemble result from the two parts. */
1236 return ((UDWtype
) hi
<< WORD_SIZE
) | lo
;
1242 __fixsfdi (SFtype a
)
1245 return - __fixunssfDI (-a
);
1246 return __fixunssfDI (a
);
1250 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1251 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1252 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1253 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1256 __floatdixf (DWtype u
)
1258 XFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1259 d
*= HIGH_HALFWORD_COEFF
;
1260 d
*= HIGH_HALFWORD_COEFF
;
1261 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1267 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1268 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1269 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1270 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1273 __floatditf (DWtype u
)
1275 TFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1276 d
*= HIGH_HALFWORD_COEFF
;
1277 d
*= HIGH_HALFWORD_COEFF
;
1278 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1285 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1286 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1287 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1290 __floatdidf (DWtype u
)
1292 DFtype d
= (Wtype
) (u
>> WORD_SIZE
);
1293 d
*= HIGH_HALFWORD_COEFF
;
1294 d
*= HIGH_HALFWORD_COEFF
;
1295 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1302 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1303 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1304 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1306 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1307 #define DF_SIZE DBL_MANT_DIG
1308 #define SF_SIZE FLT_MANT_DIG
1311 __floatdisf (DWtype u
)
1313 /* Protect against double-rounding error.
1314 Represent any low-order bits, that might be truncated in DFmode,
1315 by a bit that won't be lost. The bit can go in anywhere below the
1316 rounding position of the SFmode. A fixed mask and bit position
1317 handles all usual configurations. It doesn't handle the case
1318 of 128-bit DImode, however. */
1319 if (DF_SIZE
< DI_SIZE
1320 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1322 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1323 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1324 && u
< ((DWtype
) 1 << DF_SIZE
)))
1326 if ((UDWtype
) u
& (REP_BIT
- 1))
1328 u
&= ~ (REP_BIT
- 1);
1333 /* Do the calculation in DFmode
1334 so that we don't lose any of the precision of the high word
1335 while multiplying it. */
1336 DFtype f
= (Wtype
) (u
>> WORD_SIZE
);
1337 f
*= HIGH_HALFWORD_COEFF
;
1338 f
*= HIGH_HALFWORD_COEFF
;
1339 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1345 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1346 /* Reenable the normal types, in case limits.h needs them. */
1359 __fixunsxfSI (XFtype a
)
1361 if (a
>= - (DFtype
) Wtype_MIN
)
1362 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1368 /* Reenable the normal types, in case limits.h needs them. */
1381 __fixunsdfSI (DFtype a
)
1383 if (a
>= - (DFtype
) Wtype_MIN
)
1384 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1390 /* Reenable the normal types, in case limits.h needs them. */
1403 __fixunssfSI (SFtype a
)
1405 if (a
>= - (SFtype
) Wtype_MIN
)
1406 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1411 /* From here on down, the routines use normal data types. */
1413 #define SItype bogus_type
1414 #define USItype bogus_type
1415 #define DItype bogus_type
1416 #define UDItype bogus_type
1417 #define SFtype bogus_type
1418 #define DFtype bogus_type
1436 /* Like bcmp except the sign is meaningful.
1437 Result is negative if S1 is less than S2,
1438 positive if S1 is greater, 0 if S1 and S2 are equal. */
1441 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1445 const unsigned char c1
= *s1
++, c2
= *s2
++;
1455 /* __eprintf used to be used by GCC's private version of <assert.h>.
1456 We no longer provide that header, but this routine remains in libgcc.a
1457 for binary backward compatibility. Note that it is not included in
1458 the shared version of libgcc. */
1460 #ifndef inhibit_libc
1462 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1466 __eprintf (const char *string
, const char *expression
,
1467 unsigned int line
, const char *filename
)
1469 fprintf (stderr
, string
, expression
, line
, filename
);
1478 #ifdef L_clear_cache
1479 /* Clear part of an instruction cache. */
1482 __clear_cache (char *beg
__attribute__((__unused__
)),
1483 char *end
__attribute__((__unused__
)))
1485 #ifdef CLEAR_INSN_CACHE
1486 CLEAR_INSN_CACHE (beg
, end
);
1487 #endif /* CLEAR_INSN_CACHE */
1490 #endif /* L_clear_cache */
1494 /* Jump to a trampoline, loading the static chain address. */
1496 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1509 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1513 mprotect (char *addr
, int len
, int prot
)
1530 if (VirtualProtect (addr
, len
, np
, &op
))
1536 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1538 #ifdef TRANSFER_FROM_TRAMPOLINE
1539 TRANSFER_FROM_TRAMPOLINE
1541 #endif /* L_trampoline */
1546 #include "gbl-ctors.h"
1547 /* Some systems use __main in a way incompatible with its use in gcc, in these
1548 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1549 give the same symbol without quotes for an alternative entry point. You
1550 must define both, or neither. */
1552 #define NAME__MAIN "__main"
1553 #define SYMBOL__MAIN __main
1556 #ifdef INIT_SECTION_ASM_OP
1557 #undef HAS_INIT_SECTION
1558 #define HAS_INIT_SECTION
1561 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1563 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1564 code to run constructors. In that case, we need to handle EH here, too. */
1566 #ifdef EH_FRAME_SECTION_NAME
1567 #include "unwind-dw2-fde.h"
1568 extern unsigned char __EH_FRAME_BEGIN__
[];
1571 /* Run all the global destructors on exit from the program. */
1574 __do_global_dtors (void)
1576 #ifdef DO_GLOBAL_DTORS_BODY
1577 DO_GLOBAL_DTORS_BODY
;
1579 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1586 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1588 static int completed
= 0;
1592 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1599 #ifndef HAS_INIT_SECTION
1600 /* Run all the global constructors on entry to the program. */
1603 __do_global_ctors (void)
1605 #ifdef EH_FRAME_SECTION_NAME
1607 static struct object object
;
1608 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1611 DO_GLOBAL_CTORS_BODY
;
1612 atexit (__do_global_dtors
);
1614 #endif /* no HAS_INIT_SECTION */
1616 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1617 /* Subroutine called automatically by `main'.
1618 Compiling a global function named `main'
1619 produces an automatic call to this function at the beginning.
1621 For many systems, this routine calls __do_global_ctors.
1622 For systems which support a .init section we use the .init section
1623 to run __do_global_ctors, so we need not do anything here. */
1625 extern void SYMBOL__MAIN (void);
1629 /* Support recursive calls to `main': run initializers just once. */
1630 static int initialized
;
1634 __do_global_ctors ();
1637 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1639 #endif /* L__main */
1640 #endif /* __CYGWIN__ */
1644 #include "gbl-ctors.h"
1646 /* Provide default definitions for the lists of constructors and
1647 destructors, so that we don't get linker errors. These symbols are
1648 intentionally bss symbols, so that gld and/or collect will provide
1649 the right values. */
1651 /* We declare the lists here with two elements each,
1652 so that they are valid empty lists if no other definition is loaded.
1654 If we are using the old "set" extensions to have the gnu linker
1655 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1656 must be in the bss/common section.
1658 Long term no port should use those extensions. But many still do. */
1659 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1660 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1661 func_ptr __CTOR_LIST__
[2] = {0, 0};
1662 func_ptr __DTOR_LIST__
[2] = {0, 0};
1664 func_ptr __CTOR_LIST__
[2];
1665 func_ptr __DTOR_LIST__
[2];
1667 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1668 #endif /* L_ctors */