1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
5 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 In addition to the permissions in the GNU General Public License, the
15 Free Software Foundation gives you unlimited permission to link the
16 compiled version of this file into combinations with other programs,
17 and to distribute those combinations without any restriction coming
18 from the use of this file. (The General Public License restrictions
19 do apply in other respects; for example, they cover modification of
20 the file, and distribution when not linked into a combine
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING. If not, write to the Free
30 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "coretypes.h"
38 #ifdef HAVE_GAS_HIDDEN
39 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
41 #define ATTRIBUTE_HIDDEN
44 #ifndef MIN_UNITS_PER_WORD
45 #define MIN_UNITS_PER_WORD UNITS_PER_WORD
48 /* Work out the largest "word" size that we can deal with on this target. */
49 #if MIN_UNITS_PER_WORD > 4
50 # define LIBGCC2_MAX_UNITS_PER_WORD 8
51 #elif (MIN_UNITS_PER_WORD > 2 \
52 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
53 # define LIBGCC2_MAX_UNITS_PER_WORD 4
55 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
58 /* Work out what word size we are using for this compilation.
59 The value can be set on the command line. */
60 #ifndef LIBGCC2_UNITS_PER_WORD
61 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
64 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
68 #ifdef DECLARE_LIBRARY_RENAMES
69 DECLARE_LIBRARY_RENAMES
72 #if defined (L_negdi2)
76 const DWunion uu
= {.ll
= u
};
77 const DWunion w
= { {.low
= -uu
.s
.low
,
78 .high
= -uu
.s
.high
- ((UWtype
) -uu
.s
.low
> 0) } };
86 __addvSI3 (Wtype a
, Wtype b
)
88 const Wtype w
= (UWtype
) a
+ (UWtype
) b
;
90 if (b
>= 0 ? w
< a
: w
> a
)
95 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
97 __addvsi3 (SItype a
, SItype b
)
99 const SItype w
= (USItype
) a
+ (USItype
) b
;
101 if (b
>= 0 ? w
< a
: w
> a
)
106 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
111 __addvDI3 (DWtype a
, DWtype b
)
113 const DWtype w
= (UDWtype
) a
+ (UDWtype
) b
;
115 if (b
>= 0 ? w
< a
: w
> a
)
124 __subvSI3 (Wtype a
, Wtype b
)
126 const Wtype w
= (UWtype
) a
- (UWtype
) b
;
128 if (b
>= 0 ? w
> a
: w
< a
)
133 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
135 __subvsi3 (SItype a
, SItype b
)
137 const SItype w
= (USItype
) a
- (USItype
) b
;
139 if (b
>= 0 ? w
> a
: w
< a
)
144 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
149 __subvDI3 (DWtype a
, DWtype b
)
151 const DWtype w
= (UDWtype
) a
- (UDWtype
) b
;
153 if (b
>= 0 ? w
> a
: w
< a
)
162 __mulvSI3 (Wtype a
, Wtype b
)
164 const DWtype w
= (DWtype
) a
* (DWtype
) b
;
166 if ((Wtype
) (w
>> W_TYPE_SIZE
) != (Wtype
) w
>> (W_TYPE_SIZE
- 1))
171 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
173 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
175 __mulvsi3 (SItype a
, SItype b
)
177 const DItype w
= (DItype
) a
* (DItype
) b
;
179 if ((SItype
) (w
>> WORD_SIZE
) != (SItype
) w
>> (WORD_SIZE
-1))
184 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
191 const Wtype w
= -(UWtype
) a
;
193 if (a
>= 0 ? w
> 0 : w
< 0)
198 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
202 const SItype w
= -(USItype
) a
;
204 if (a
>= 0 ? w
> 0 : w
< 0)
209 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
216 const DWtype w
= -(UDWtype
) a
;
218 if (a
>= 0 ? w
> 0 : w
< 0)
243 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
261 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
286 __mulvDI3 (DWtype u
, DWtype v
)
288 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
289 but the checked multiplication needs only two. */
290 const DWunion uu
= {.ll
= u
};
291 const DWunion vv
= {.ll
= v
};
293 if (__builtin_expect (uu
.s
.high
== uu
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
295 /* u fits in a single Wtype. */
296 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
298 /* v fits in a single Wtype as well. */
299 /* A single multiplication. No overflow risk. */
300 return (DWtype
) uu
.s
.low
* (DWtype
) vv
.s
.low
;
304 /* Two multiplications. */
305 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
306 * (UDWtype
) (UWtype
) vv
.s
.low
};
307 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
308 * (UDWtype
) (UWtype
) vv
.s
.high
};
311 w1
.s
.high
-= uu
.s
.low
;
314 w1
.ll
+= (UWtype
) w0
.s
.high
;
315 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
317 w0
.s
.high
= w1
.s
.low
;
324 if (__builtin_expect (vv
.s
.high
== vv
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
326 /* v fits into a single Wtype. */
327 /* Two multiplications. */
328 DWunion w0
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
329 * (UDWtype
) (UWtype
) vv
.s
.low
};
330 DWunion w1
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.high
331 * (UDWtype
) (UWtype
) vv
.s
.low
};
334 w1
.s
.high
-= vv
.s
.low
;
337 w1
.ll
+= (UWtype
) w0
.s
.high
;
338 if (__builtin_expect (w1
.s
.high
== w1
.s
.low
>> (W_TYPE_SIZE
- 1), 1))
340 w0
.s
.high
= w1
.s
.low
;
346 /* A few sign checks and a single multiplication. */
351 if (uu
.s
.high
== 0 && vv
.s
.high
== 0)
353 const DWtype w
= (UDWtype
) (UWtype
) uu
.s
.low
354 * (UDWtype
) (UWtype
) vv
.s
.low
;
355 if (__builtin_expect (w
>= 0, 1))
361 if (uu
.s
.high
== 0 && vv
.s
.high
== (Wtype
) -1)
363 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
364 * (UDWtype
) (UWtype
) vv
.s
.low
};
366 ww
.s
.high
-= uu
.s
.low
;
367 if (__builtin_expect (ww
.s
.high
< 0, 1))
376 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== 0)
378 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
379 * (UDWtype
) (UWtype
) vv
.s
.low
};
381 ww
.s
.high
-= vv
.s
.low
;
382 if (__builtin_expect (ww
.s
.high
< 0, 1))
388 if (uu
.s
.high
== (Wtype
) -1 && vv
.s
.high
== (Wtype
) - 1)
390 DWunion ww
= {.ll
= (UDWtype
) (UWtype
) uu
.s
.low
391 * (UDWtype
) (UWtype
) vv
.s
.low
};
393 ww
.s
.high
-= uu
.s
.low
;
394 ww
.s
.high
-= vv
.s
.low
;
395 if (__builtin_expect (ww
.s
.high
>= 0, 1))
409 /* Unless shift functions are defined with full ANSI prototypes,
410 parameter b will be promoted to int if shift_count_type is smaller than an int. */
413 __lshrdi3 (DWtype u
, shift_count_type b
)
418 const DWunion uu
= {.ll
= u
};
419 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
425 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
429 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
431 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
432 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
441 __ashldi3 (DWtype u
, shift_count_type b
)
446 const DWunion uu
= {.ll
= u
};
447 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
453 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
457 const UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
459 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
460 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
469 __ashrdi3 (DWtype u
, shift_count_type b
)
474 const DWunion uu
= {.ll
= u
};
475 const shift_count_type bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
480 /* w.s.high = 1..1 or 0..0 */
481 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
482 w
.s
.low
= uu
.s
.high
>> -bm
;
486 const UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
488 w
.s
.high
= uu
.s
.high
>> b
;
489 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
498 __bswapsi2 (SItype u
)
500 return ((((u
) & 0xff000000) >> 24)
501 | (((u
) & 0x00ff0000) >> 8)
502 | (((u
) & 0x0000ff00) << 8)
503 | (((u
) & 0x000000ff) << 24));
508 __bswapdi2 (DItype u
)
510 return ((((u
) & 0xff00000000000000ull
) >> 56)
511 | (((u
) & 0x00ff000000000000ull
) >> 40)
512 | (((u
) & 0x0000ff0000000000ull
) >> 24)
513 | (((u
) & 0x000000ff00000000ull
) >> 8)
514 | (((u
) & 0x00000000ff000000ull
) << 8)
515 | (((u
) & 0x0000000000ff0000ull
) << 24)
516 | (((u
) & 0x000000000000ff00ull
) << 40)
517 | (((u
) & 0x00000000000000ffull
) << 56));
530 count_trailing_zeros (count
, u
);
540 const DWunion uu
= {.ll
= u
};
541 UWtype word
, count
, add
;
544 word
= uu
.s
.low
, add
= 0;
545 else if (uu
.s
.high
!= 0)
546 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
550 count_trailing_zeros (count
, word
);
551 return count
+ add
+ 1;
557 __muldi3 (DWtype u
, DWtype v
)
559 const DWunion uu
= {.ll
= u
};
560 const DWunion vv
= {.ll
= v
};
561 DWunion w
= {.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
)};
563 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
564 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
570 #if (defined (L_udivdi3) || defined (L_divdi3) || \
571 defined (L_umoddi3) || defined (L_moddi3))
572 #if defined (sdiv_qrnnd)
573 #define L_udiv_w_sdiv
578 #if defined (sdiv_qrnnd)
579 #if (defined (L_udivdi3) || defined (L_divdi3) || \
580 defined (L_umoddi3) || defined (L_moddi3))
581 static inline __attribute__ ((__always_inline__
))
584 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
591 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
593 /* Dividend, divisor, and quotient are nonnegative. */
594 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
598 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
599 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
600 /* Divide (c1*2^32 + c0) by d. */
601 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
602 /* Add 2^31 to quotient. */
603 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
608 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
609 c1
= a1
>> 1; /* A/2 */
610 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
612 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
614 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
616 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
633 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
636 c0
= ~c0
; /* logical NOT */
638 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
640 q
= ~q
; /* (A/2)/b1 */
643 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
661 else /* Implies c1 = b1 */
662 { /* Hence a1 = d - 1 = 2*b1 - 1 */
680 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
682 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
683 UWtype a1
__attribute__ ((__unused__
)),
684 UWtype a0
__attribute__ ((__unused__
)),
685 UWtype d
__attribute__ ((__unused__
)))
692 #if (defined (L_udivdi3) || defined (L_divdi3) || \
693 defined (L_umoddi3) || defined (L_moddi3))
698 const UQItype __clz_tab
[256] =
700 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,
701 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,
702 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,
703 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,
704 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,
705 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,
706 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,
707 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
718 count_leading_zeros (ret
, x
);
729 const DWunion uu
= {.ll
= x
};
734 word
= uu
.s
.high
, add
= 0;
736 word
= uu
.s
.low
, add
= W_TYPE_SIZE
;
738 count_leading_zeros (ret
, word
);
750 count_trailing_zeros (ret
, x
);
761 const DWunion uu
= {.ll
= x
};
766 word
= uu
.s
.low
, add
= 0;
768 word
= uu
.s
.high
, add
= W_TYPE_SIZE
;
770 count_trailing_zeros (ret
, word
);
775 #ifdef L_popcount_tab
776 const UQItype __popcount_tab
[256] =
778 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,
779 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,
780 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,
781 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,
782 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,
783 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,
784 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,
785 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
792 __popcountSI2 (UWtype x
)
796 for (i
= 0; i
< W_TYPE_SIZE
; i
+= 8)
797 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
806 __popcountDI2 (UDWtype x
)
810 for (i
= 0; i
< 2*W_TYPE_SIZE
; i
+= 8)
811 ret
+= __popcount_tab
[(x
>> i
) & 0xff];
820 __paritySI2 (UWtype x
)
823 # error "fill out the table"
834 return (0x6996 >> x
) & 1;
841 __parityDI2 (UDWtype x
)
843 const DWunion uu
= {.ll
= x
};
844 UWtype nx
= uu
.s
.low
^ uu
.s
.high
;
847 # error "fill out the table"
858 return (0x6996 >> nx
) & 1;
864 #if (defined (L_udivdi3) || defined (L_divdi3) || \
865 defined (L_umoddi3) || defined (L_moddi3))
866 static inline __attribute__ ((__always_inline__
))
869 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
871 const DWunion nn
= {.ll
= n
};
872 const DWunion dd
= {.ll
= d
};
874 UWtype d0
, d1
, n0
, n1
, n2
;
883 #if !UDIV_NEEDS_NORMALIZATION
890 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
893 /* Remainder in n0. */
900 d0
= 1 / d0
; /* Divide intentionally by zero. */
902 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
903 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
905 /* Remainder in n0. */
916 #else /* UDIV_NEEDS_NORMALIZATION */
924 count_leading_zeros (bm
, d0
);
928 /* Normalize, i.e. make the most significant bit of the
932 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
936 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
939 /* Remainder in n0 >> bm. */
946 d0
= 1 / d0
; /* Divide intentionally by zero. */
948 count_leading_zeros (bm
, d0
);
952 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
953 conclude (the most significant bit of n1 is set) /\ (the
954 leading quotient digit q1 = 1).
956 This special case is necessary, not an optimization.
957 (Shifts counts of W_TYPE_SIZE are undefined.) */
966 b
= W_TYPE_SIZE
- bm
;
970 n1
= (n1
<< bm
) | (n0
>> b
);
973 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
978 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
980 /* Remainder in n0 >> bm. */
990 #endif /* UDIV_NEEDS_NORMALIZATION */
1001 /* Remainder in n1n0. */
1013 count_leading_zeros (bm
, d1
);
1016 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
1017 conclude (the most significant bit of n1 is set) /\ (the
1018 quotient digit q0 = 0 or 1).
1020 This special case is necessary, not an optimization. */
1022 /* The condition on the next line takes advantage of that
1023 n1 >= d1 (true due to program flow). */
1024 if (n1
> d1
|| n0
>= d0
)
1027 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
1046 b
= W_TYPE_SIZE
- bm
;
1048 d1
= (d1
<< bm
) | (d0
>> b
);
1051 n1
= (n1
<< bm
) | (n0
>> b
);
1054 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
1055 umul_ppmm (m1
, m0
, q0
, d0
);
1057 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
1060 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
1065 /* Remainder in (n1n0 - m1m0) >> bm. */
1068 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
1069 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
1070 rr
.s
.high
= n1
>> bm
;
1077 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
1084 __divdi3 (DWtype u
, DWtype v
)
1087 DWunion uu
= {.ll
= u
};
1088 DWunion vv
= {.ll
= v
};
1098 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
1108 __moddi3 (DWtype u
, DWtype v
)
1111 DWunion uu
= {.ll
= u
};
1112 DWunion vv
= {.ll
= v
};
1121 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*)&w
);
1131 __umoddi3 (UDWtype u
, UDWtype v
)
1135 (void) __udivmoddi4 (u
, v
, &w
);
1143 __udivdi3 (UDWtype n
, UDWtype d
)
1145 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
1151 __cmpdi2 (DWtype a
, DWtype b
)
1153 const DWunion au
= {.ll
= a
};
1154 const DWunion bu
= {.ll
= b
};
1156 if (au
.s
.high
< bu
.s
.high
)
1158 else if (au
.s
.high
> bu
.s
.high
)
1160 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1162 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1170 __ucmpdi2 (DWtype a
, DWtype b
)
1172 const DWunion au
= {.ll
= a
};
1173 const DWunion bu
= {.ll
= b
};
1175 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
1177 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
1179 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
1181 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
1187 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1189 __fixunstfDI (TFtype a
)
1194 /* Compute high word of result, as a flonum. */
1195 const TFtype b
= (a
/ Wtype_MAXp1_F
);
1196 /* Convert that to fixed (but not to DWtype!),
1197 and shift it into the high word. */
1198 UDWtype v
= (UWtype
) b
;
1200 /* Remove high part from the TFtype, leaving the low part as flonum. */
1202 /* Convert that to fixed (but not to DWtype!) and add it in.
1203 Sometimes A comes out negative. This is significant, since
1204 A has more bits than a long int does. */
1206 v
-= (UWtype
) (- a
);
1213 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1215 __fixtfdi (TFtype a
)
1218 return - __fixunstfDI (-a
);
1219 return __fixunstfDI (a
);
1223 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1225 __fixunsxfDI (XFtype a
)
1230 /* Compute high word of result, as a flonum. */
1231 const XFtype b
= (a
/ Wtype_MAXp1_F
);
1232 /* Convert that to fixed (but not to DWtype!),
1233 and shift it into the high word. */
1234 UDWtype v
= (UWtype
) b
;
1236 /* Remove high part from the XFtype, leaving the low part as flonum. */
1238 /* Convert that to fixed (but not to DWtype!) and add it in.
1239 Sometimes A comes out negative. This is significant, since
1240 A has more bits than a long int does. */
1242 v
-= (UWtype
) (- a
);
1249 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1251 __fixxfdi (XFtype a
)
1254 return - __fixunsxfDI (-a
);
1255 return __fixunsxfDI (a
);
1259 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1261 __fixunsdfDI (DFtype a
)
1263 /* Get high part of result. The division here will just moves the radix
1264 point and will not cause any rounding. Then the conversion to integral
1265 type chops result as desired. */
1266 const UWtype hi
= a
/ Wtype_MAXp1_F
;
1268 /* Get low part of result. Convert `hi' to floating type and scale it back,
1269 then subtract this from the number being converted. This leaves the low
1270 part. Convert that to integral type. */
1271 const UWtype lo
= a
- (DFtype
) hi
* Wtype_MAXp1_F
;
1273 /* Assemble result from the two parts. */
1274 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1278 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1280 __fixdfdi (DFtype a
)
1283 return - __fixunsdfDI (-a
);
1284 return __fixunsdfDI (a
);
1288 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1290 __fixunssfDI (SFtype a
)
1292 #if LIBGCC2_HAS_DF_MODE
1293 /* Convert the SFtype to a DFtype, because that is surely not going
1294 to lose any bits. Some day someone else can write a faster version
1295 that avoids converting to DFtype, and verify it really works right. */
1296 const DFtype dfa
= a
;
1298 /* Get high part of result. The division here will just moves the radix
1299 point and will not cause any rounding. Then the conversion to integral
1300 type chops result as desired. */
1301 const UWtype hi
= dfa
/ Wtype_MAXp1_F
;
1303 /* Get low part of result. Convert `hi' to floating type and scale it back,
1304 then subtract this from the number being converted. This leaves the low
1305 part. Convert that to integral type. */
1306 const UWtype lo
= dfa
- (DFtype
) hi
* Wtype_MAXp1_F
;
1308 /* Assemble result from the two parts. */
1309 return ((UDWtype
) hi
<< W_TYPE_SIZE
) | lo
;
1310 #elif FLT_MANT_DIG < W_TYPE_SIZE
1313 if (a
< Wtype_MAXp1_F
)
1315 if (a
< Wtype_MAXp1_F
* Wtype_MAXp1_F
)
1317 /* Since we know that there are fewer significant bits in the SFmode
1318 quantity than in a word, we know that we can convert out all the
1319 significant bits in one step, and thus avoid losing bits. */
1321 /* ??? This following loop essentially performs frexpf. If we could
1322 use the real libm function, or poke at the actual bits of the fp
1323 format, it would be significantly faster. */
1325 UWtype shift
= 0, counter
;
1329 for (counter
= W_TYPE_SIZE
/ 2; counter
!= 0; counter
>>= 1)
1331 SFtype counterf
= (UWtype
)1 << counter
;
1339 /* Rescale into the range of one word, extract the bits of that
1340 one word, and shift the result into position. */
1343 return (DWtype
)counter
<< shift
;
1352 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1354 __fixsfdi (SFtype a
)
1357 return - __fixunssfDI (-a
);
1358 return __fixunssfDI (a
);
1362 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1364 __floatdixf (DWtype u
)
1366 #if W_TYPE_SIZE > XF_SIZE
1369 XFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1376 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1378 __floatundixf (UDWtype u
)
1380 #if W_TYPE_SIZE > XF_SIZE
1383 XFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1390 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1392 __floatditf (DWtype u
)
1394 #if W_TYPE_SIZE > TF_SIZE
1397 TFtype d
= (Wtype
) (u
>> W_TYPE_SIZE
);
1404 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1406 __floatunditf (UDWtype u
)
1408 #if W_TYPE_SIZE > TF_SIZE
1411 TFtype d
= (UWtype
) (u
>> W_TYPE_SIZE
);
1418 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1419 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1420 #define DI_SIZE (W_TYPE_SIZE * 2)
1421 #define F_MODE_OK(SIZE) \
1423 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1424 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1425 #if defined(L_floatdisf)
1426 #define FUNC __floatdisf
1427 #define FSTYPE SFtype
1428 #define FSSIZE SF_SIZE
1430 #define FUNC __floatdidf
1431 #define FSTYPE DFtype
1432 #define FSSIZE DF_SIZE
1438 #if FSSIZE >= W_TYPE_SIZE
1439 /* When the word size is small, we never get any rounding error. */
1440 FSTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1444 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1445 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1446 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1448 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1449 # define FSIZE DF_SIZE
1450 # define FTYPE DFtype
1451 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1452 # define FSIZE XF_SIZE
1453 # define FTYPE XFtype
1454 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1455 # define FSIZE TF_SIZE
1456 # define FTYPE TFtype
1461 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1463 /* Protect against double-rounding error.
1464 Represent any low-order bits, that might be truncated by a bit that
1465 won't be lost. The bit can go in anywhere below the rounding position
1466 of the FSTYPE. A fixed mask and bit position handles all usual
1468 if (! (- ((DWtype
) 1 << FSIZE
) < u
1469 && u
< ((DWtype
) 1 << FSIZE
)))
1471 if ((UDWtype
) u
& (REP_BIT
- 1))
1473 u
&= ~ (REP_BIT
- 1);
1478 /* Do the calculation in a wider type so that we don't lose any of
1479 the precision of the high word while multiplying it. */
1480 FTYPE f
= (Wtype
) (u
>> W_TYPE_SIZE
);
1485 #if FSSIZE >= W_TYPE_SIZE - 2
1488 /* Finally, the word size is larger than the number of bits in the
1489 required FSTYPE, and we've got no suitable wider type. The only
1490 way to avoid double rounding is to special case the
1493 /* If there are no high bits set, fall back to one conversion. */
1495 return (FSTYPE
)(Wtype
)u
;
1497 /* Otherwise, find the power of two. */
1498 Wtype hi
= u
>> W_TYPE_SIZE
;
1502 UWtype count
, shift
;
1503 count_leading_zeros (count
, hi
);
1505 /* No leading bits means u == minimum. */
1507 return -(Wtype_MAXp1_F
* (Wtype_MAXp1_F
/ 2));
1509 shift
= 1 + W_TYPE_SIZE
- count
;
1511 /* Shift down the most significant bits. */
1514 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1515 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1518 /* Convert the one word of data, and rescale. */
1520 if (shift
== W_TYPE_SIZE
)
1522 /* The following two cases could be merged if we knew that the target
1523 supported a native unsigned->float conversion. More often, we only
1524 have a signed conversion, and have to add extra fixup code. */
1525 else if (shift
== W_TYPE_SIZE
- 1)
1526 e
= Wtype_MAXp1_F
/ 2;
1528 e
= (Wtype
)1 << shift
;
1534 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1535 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1536 #define DI_SIZE (W_TYPE_SIZE * 2)
1537 #define F_MODE_OK(SIZE) \
1539 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1540 && !AVOID_FP_TYPE_CONVERSION(SIZE))
1541 #if defined(L_floatundisf)
1542 #define FUNC __floatundisf
1543 #define FSTYPE SFtype
1544 #define FSSIZE SF_SIZE
1546 #define FUNC __floatundidf
1547 #define FSTYPE DFtype
1548 #define FSSIZE DF_SIZE
1554 #if FSSIZE >= W_TYPE_SIZE
1555 /* When the word size is small, we never get any rounding error. */
1556 FSTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1560 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1561 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1562 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1564 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1565 # define FSIZE DF_SIZE
1566 # define FTYPE DFtype
1567 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1568 # define FSIZE XF_SIZE
1569 # define FTYPE XFtype
1570 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1571 # define FSIZE TF_SIZE
1572 # define FTYPE TFtype
1577 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1579 /* Protect against double-rounding error.
1580 Represent any low-order bits, that might be truncated by a bit that
1581 won't be lost. The bit can go in anywhere below the rounding position
1582 of the FSTYPE. A fixed mask and bit position handles all usual
1584 if (u
>= ((UDWtype
) 1 << FSIZE
))
1586 if ((UDWtype
) u
& (REP_BIT
- 1))
1588 u
&= ~ (REP_BIT
- 1);
1593 /* Do the calculation in a wider type so that we don't lose any of
1594 the precision of the high word while multiplying it. */
1595 FTYPE f
= (UWtype
) (u
>> W_TYPE_SIZE
);
1600 #if FSSIZE == W_TYPE_SIZE - 1
1603 /* Finally, the word size is larger than the number of bits in the
1604 required FSTYPE, and we've got no suitable wider type. The only
1605 way to avoid double rounding is to special case the
1608 /* If there are no high bits set, fall back to one conversion. */
1610 return (FSTYPE
)(UWtype
)u
;
1612 /* Otherwise, find the power of two. */
1613 UWtype hi
= u
>> W_TYPE_SIZE
;
1615 UWtype count
, shift
;
1616 count_leading_zeros (count
, hi
);
1618 shift
= W_TYPE_SIZE
- count
;
1620 /* Shift down the most significant bits. */
1623 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1624 if ((UWtype
)u
<< (W_TYPE_SIZE
- shift
))
1627 /* Convert the one word of data, and rescale. */
1629 if (shift
== W_TYPE_SIZE
)
1631 /* The following two cases could be merged if we knew that the target
1632 supported a native unsigned->float conversion. More often, we only
1633 have a signed conversion, and have to add extra fixup code. */
1634 else if (shift
== W_TYPE_SIZE
- 1)
1635 e
= Wtype_MAXp1_F
/ 2;
1637 e
= (Wtype
)1 << shift
;
1643 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1644 /* Reenable the normal types, in case limits.h needs them. */
1657 __fixunsxfSI (XFtype a
)
1659 if (a
>= - (DFtype
) Wtype_MIN
)
1660 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1665 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1666 /* Reenable the normal types, in case limits.h needs them. */
1679 __fixunsdfSI (DFtype a
)
1681 if (a
>= - (DFtype
) Wtype_MIN
)
1682 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1687 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1688 /* Reenable the normal types, in case limits.h needs them. */
1701 __fixunssfSI (SFtype a
)
1703 if (a
>= - (SFtype
) Wtype_MIN
)
1704 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1709 /* Integer power helper used from __builtin_powi for non-constant
1712 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1713 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1714 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1715 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1716 # if defined(L_powisf2)
1717 # define TYPE SFtype
1718 # define NAME __powisf2
1719 # elif defined(L_powidf2)
1720 # define TYPE DFtype
1721 # define NAME __powidf2
1722 # elif defined(L_powixf2)
1723 # define TYPE XFtype
1724 # define NAME __powixf2
1725 # elif defined(L_powitf2)
1726 # define TYPE TFtype
1727 # define NAME __powitf2
1733 NAME (TYPE x
, int m
)
1735 unsigned int n
= m
< 0 ? -m
: m
;
1736 TYPE y
= n
% 2 ? x
: 1;
1743 return m
< 0 ? 1/y
: y
;
1748 #if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1749 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1750 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1751 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1757 #if defined(L_mulsc3) || defined(L_divsc3)
1758 # define MTYPE SFtype
1759 # define CTYPE SCtype
1762 # define NOTRUNC __FLT_EVAL_METHOD__ == 0
1763 #elif defined(L_muldc3) || defined(L_divdc3)
1764 # define MTYPE DFtype
1765 # define CTYPE DCtype
1767 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1772 # define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1774 #elif defined(L_mulxc3) || defined(L_divxc3)
1775 # define MTYPE XFtype
1776 # define CTYPE XCtype
1780 #elif defined(L_multc3) || defined(L_divtc3)
1781 # define MTYPE TFtype
1782 # define CTYPE TCtype
1784 # if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
1787 # define CEXT LIBGCC2_TF_CEXT
1794 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1795 #define _CONCAT3(A,B,C) A##B##C
1797 #define CONCAT2(A,B) _CONCAT2(A,B)
1798 #define _CONCAT2(A,B) A##B
1800 /* All of these would be present in a full C99 implementation of <math.h>
1801 and <complex.h>. Our problem is that only a few systems have such full
1802 implementations. Further, libgcc_s.so isn't currently linked against
1803 libm.so, and even for systems that do provide full C99, the extra overhead
1804 of all programs using libgcc having to link against libm. So avoid it. */
1806 #define isnan(x) __builtin_expect ((x) != (x), 0)
1807 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1808 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1810 #define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1813 /* Helpers to make the following code slightly less gross. */
1814 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1815 #define FABS CONCAT2(__builtin_fabs, CEXT)
1817 /* Verify that MTYPE matches up with CEXT. */
1818 extern void *compile_type_assert
[sizeof(INFINITY
) == sizeof(MTYPE
) ? 1 : -1];
1820 /* Ensure that we've lost any extra precision. */
1824 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1827 #if defined(L_mulsc3) || defined(L_muldc3) \
1828 || defined(L_mulxc3) || defined(L_multc3)
1831 CONCAT3(__mul
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1833 MTYPE ac
, bd
, ad
, bc
, x
, y
;
1849 if (isnan (x
) && isnan (y
))
1851 /* Recover infinities that computed as NaN + iNaN. */
1853 if (isinf (a
) || isinf (b
))
1855 /* z is infinite. "Box" the infinity and change NaNs in
1856 the other factor to 0. */
1857 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1858 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1859 if (isnan (c
)) c
= COPYSIGN (0, c
);
1860 if (isnan (d
)) d
= COPYSIGN (0, d
);
1863 if (isinf (c
) || isinf (d
))
1865 /* w is infinite. "Box" the infinity and change NaNs in
1866 the other factor to 0. */
1867 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1868 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1869 if (isnan (a
)) a
= COPYSIGN (0, a
);
1870 if (isnan (b
)) b
= COPYSIGN (0, b
);
1874 && (isinf (ac
) || isinf (bd
)
1875 || isinf (ad
) || isinf (bc
)))
1877 /* Recover infinities from overflow by changing NaNs to 0. */
1878 if (isnan (a
)) a
= COPYSIGN (0, a
);
1879 if (isnan (b
)) b
= COPYSIGN (0, b
);
1880 if (isnan (c
)) c
= COPYSIGN (0, c
);
1881 if (isnan (d
)) d
= COPYSIGN (0, d
);
1886 x
= INFINITY
* (a
* c
- b
* d
);
1887 y
= INFINITY
* (a
* d
+ b
* c
);
1895 #endif /* complex multiply */
1897 #if defined(L_divsc3) || defined(L_divdc3) \
1898 || defined(L_divxc3) || defined(L_divtc3)
1901 CONCAT3(__div
,MODE
,3) (MTYPE a
, MTYPE b
, MTYPE c
, MTYPE d
)
1903 MTYPE denom
, ratio
, x
, y
;
1906 /* ??? We can get better behavior from logarithmic scaling instead of
1907 the division. But that would mean starting to link libgcc against
1908 libm. We could implement something akin to ldexp/frexp as gcc builtins
1910 if (FABS (c
) < FABS (d
))
1913 denom
= (c
* ratio
) + d
;
1914 x
= ((a
* ratio
) + b
) / denom
;
1915 y
= ((b
* ratio
) - a
) / denom
;
1920 denom
= (d
* ratio
) + c
;
1921 x
= ((b
* ratio
) + a
) / denom
;
1922 y
= (b
- (a
* ratio
)) / denom
;
1925 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1926 are nonzero/zero, infinite/finite, and finite/infinite. */
1927 if (isnan (x
) && isnan (y
))
1929 if (c
== 0.0 && d
== 0.0 && (!isnan (a
) || !isnan (b
)))
1931 x
= COPYSIGN (INFINITY
, c
) * a
;
1932 y
= COPYSIGN (INFINITY
, c
) * b
;
1934 else if ((isinf (a
) || isinf (b
)) && isfinite (c
) && isfinite (d
))
1936 a
= COPYSIGN (isinf (a
) ? 1 : 0, a
);
1937 b
= COPYSIGN (isinf (b
) ? 1 : 0, b
);
1938 x
= INFINITY
* (a
* c
+ b
* d
);
1939 y
= INFINITY
* (b
* c
- a
* d
);
1941 else if ((isinf (c
) || isinf (d
)) && isfinite (a
) && isfinite (b
))
1943 c
= COPYSIGN (isinf (c
) ? 1 : 0, c
);
1944 d
= COPYSIGN (isinf (d
) ? 1 : 0, d
);
1945 x
= 0.0 * (a
* c
+ b
* d
);
1946 y
= 0.0 * (b
* c
- a
* d
);
1954 #endif /* complex divide */
1956 #endif /* all complex float routines */
1958 /* From here on down, the routines use normal data types. */
1960 #define SItype bogus_type
1961 #define USItype bogus_type
1962 #define DItype bogus_type
1963 #define UDItype bogus_type
1964 #define SFtype bogus_type
1965 #define DFtype bogus_type
1983 /* Like bcmp except the sign is meaningful.
1984 Result is negative if S1 is less than S2,
1985 positive if S1 is greater, 0 if S1 and S2 are equal. */
1988 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1992 const unsigned char c1
= *s1
++, c2
= *s2
++;
2002 /* __eprintf used to be used by GCC's private version of <assert.h>.
2003 We no longer provide that header, but this routine remains in libgcc.a
2004 for binary backward compatibility. Note that it is not included in
2005 the shared version of libgcc. */
2007 #ifndef inhibit_libc
2009 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
2013 __eprintf (const char *string
, const char *expression
,
2014 unsigned int line
, const char *filename
)
2016 fprintf (stderr
, string
, expression
, line
, filename
);
2025 #ifdef L_clear_cache
2026 /* Clear part of an instruction cache. */
2029 __clear_cache (char *beg
__attribute__((__unused__
)),
2030 char *end
__attribute__((__unused__
)))
2032 #ifdef CLEAR_INSN_CACHE
2033 CLEAR_INSN_CACHE (beg
, end
);
2034 #endif /* CLEAR_INSN_CACHE */
2037 #endif /* L_clear_cache */
2039 #ifdef L_enable_execute_stack
2040 /* Attempt to turn on execute permission for the stack. */
2042 #ifdef ENABLE_EXECUTE_STACK
2043 ENABLE_EXECUTE_STACK
2046 __enable_execute_stack (void *addr
__attribute__((__unused__
)))
2048 #endif /* ENABLE_EXECUTE_STACK */
2050 #endif /* L_enable_execute_stack */
2054 /* Jump to a trampoline, loading the static chain address. */
2056 #if defined(WINNT) && ! defined(__CYGWIN__)
2069 mprotect (char *addr
, int len
, int prot
)
2088 if (VirtualProtect (addr
, len
, np
, &op
))
2094 #endif /* WINNT && ! __CYGWIN__ */
2096 #ifdef TRANSFER_FROM_TRAMPOLINE
2097 TRANSFER_FROM_TRAMPOLINE
2099 #endif /* L_trampoline */
2104 #include "gbl-ctors.h"
2106 /* Some systems use __main in a way incompatible with its use in gcc, in these
2107 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2108 give the same symbol without quotes for an alternative entry point. You
2109 must define both, or neither. */
2111 #define NAME__MAIN "__main"
2112 #define SYMBOL__MAIN __main
2115 #if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
2116 #undef HAS_INIT_SECTION
2117 #define HAS_INIT_SECTION
2120 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2122 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2123 code to run constructors. In that case, we need to handle EH here, too. */
2125 #ifdef EH_FRAME_SECTION_NAME
2126 #include "unwind-dw2-fde.h"
2127 extern unsigned char __EH_FRAME_BEGIN__
[];
2130 /* Run all the global destructors on exit from the program. */
2133 __do_global_dtors (void)
2135 #ifdef DO_GLOBAL_DTORS_BODY
2136 DO_GLOBAL_DTORS_BODY
;
2138 static func_ptr
*p
= __DTOR_LIST__
+ 1;
2145 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
2147 static int completed
= 0;
2151 __deregister_frame_info (__EH_FRAME_BEGIN__
);
2158 #ifndef HAS_INIT_SECTION
2159 /* Run all the global constructors on entry to the program. */
2162 __do_global_ctors (void)
2164 #ifdef EH_FRAME_SECTION_NAME
2166 static struct object object
;
2167 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
2170 DO_GLOBAL_CTORS_BODY
;
2171 atexit (__do_global_dtors
);
2173 #endif /* no HAS_INIT_SECTION */
2175 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
2176 /* Subroutine called automatically by `main'.
2177 Compiling a global function named `main'
2178 produces an automatic call to this function at the beginning.
2180 For many systems, this routine calls __do_global_ctors.
2181 For systems which support a .init section we use the .init section
2182 to run __do_global_ctors, so we need not do anything here. */
2184 extern void SYMBOL__MAIN (void);
2188 /* Support recursive calls to `main': run initializers just once. */
2189 static int initialized
;
2193 __do_global_ctors ();
2196 #endif /* no HAS_INIT_SECTION or INVOKE__main */
2198 #endif /* L__main */
2199 #endif /* __CYGWIN__ */
2203 #include "gbl-ctors.h"
2205 /* Provide default definitions for the lists of constructors and
2206 destructors, so that we don't get linker errors. These symbols are
2207 intentionally bss symbols, so that gld and/or collect will provide
2208 the right values. */
2210 /* We declare the lists here with two elements each,
2211 so that they are valid empty lists if no other definition is loaded.
2213 If we are using the old "set" extensions to have the gnu linker
2214 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
2215 must be in the bss/common section.
2217 Long term no port should use those extensions. But many still do. */
2218 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2219 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
2220 func_ptr __CTOR_LIST__
[2] = {0, 0};
2221 func_ptr __DTOR_LIST__
[2] = {0, 0};
2223 func_ptr __CTOR_LIST__
[2];
2224 func_ptr __DTOR_LIST__
[2];
2226 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2227 #endif /* L_ctors */
2228 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */