Deleted Added
full compact
libgcc2.c (146906) libgcc2.c (169699)
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,
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.
4 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12

--- 8 unchanged lines hidden (view full) ---

21
22GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23WARRANTY; without even the implied warranty of MERCHANTABILITY or
24FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25for more details.
26
27You should have received a copy of the GNU General Public License
28along with GCC; see the file COPYING. If not, write to the Free
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12

--- 8 unchanged lines hidden (view full) ---

21
22GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23WARRANTY; without even the implied warranty of MERCHANTABILITY or
24FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25for more details.
26
27You should have received a copy of the GNU General Public License
28along with GCC; see the file COPYING. If not, write to the Free
29Software Foundation, 59 Temple Place - Suite 330, Boston, MA
3002111-1307, USA. */
29Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
3002110-1301, USA. */
31
31
32
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"
36
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
39 do not apply. */
40#include "tconfig.h"
41#include "tsystem.h"
42#include "coretypes.h"
43#include "tm.h"
44
32#include "tconfig.h"
33#include "tsystem.h"
34#include "coretypes.h"
35#include "tm.h"
36
45/* Don't use `fancy_abort' here even if config.h says to use it. */
46#ifdef abort
47#undef abort
48#endif
49
50#ifdef HAVE_GAS_HIDDEN
51#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
52#else
53#define ATTRIBUTE_HIDDEN
54#endif
55
37#ifdef HAVE_GAS_HIDDEN
38#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
39#else
40#define ATTRIBUTE_HIDDEN
41#endif
42
43#ifndef MIN_UNITS_PER_WORD
44#define MIN_UNITS_PER_WORD UNITS_PER_WORD
45#endif
46
47/* Work out the largest "word" size that we can deal with on this target. */
48#if MIN_UNITS_PER_WORD > 4
49# define LIBGCC2_MAX_UNITS_PER_WORD 8
50#elif (MIN_UNITS_PER_WORD > 2 \
51 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
52# define LIBGCC2_MAX_UNITS_PER_WORD 4
53#else
54# define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
55#endif
56
57/* Work out what word size we are using for this compilation.
58 The value can be set on the command line. */
59#ifndef LIBGCC2_UNITS_PER_WORD
60#define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
61#endif
62
63#if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
64
56#include "libgcc2.h"
57
58#ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
60#endif
61
62#if defined (L_negdi2)
63DWtype

--- 79 unchanged lines hidden (view full) ---

143 if (b >= 0 ? w > a : w < a)
144 abort ();
145
146 return w;
147}
148#endif
149
150#ifdef L_mulvsi3
65#include "libgcc2.h"
66
67#ifdef DECLARE_LIBRARY_RENAMES
68 DECLARE_LIBRARY_RENAMES
69#endif
70
71#if defined (L_negdi2)
72DWtype

--- 79 unchanged lines hidden (view full) ---

152 if (b >= 0 ? w > a : w < a)
153 abort ();
154
155 return w;
156}
157#endif
158
159#ifdef L_mulvsi3
151#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
152Wtype
153__mulvSI3 (Wtype a, Wtype b)
154{
155 const DWtype w = (DWtype) a * (DWtype) b;
156
160Wtype
161__mulvSI3 (Wtype a, Wtype b)
162{
163 const DWtype w = (DWtype) a * (DWtype) b;
164
157 if ((Wtype) (w >> WORD_SIZE) != (Wtype) w >> (WORD_SIZE - 1))
165 if ((Wtype) (w >> W_TYPE_SIZE) != (Wtype) w >> (W_TYPE_SIZE - 1))
158 abort ();
159
160 return w;
161}
162#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
163#undef WORD_SIZE
164#define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
165SItype

--- 102 unchanged lines hidden (view full) ---

268 abort ();
269#endif
270
271 return w;
272}
273#endif
274
275#ifdef L_mulvdi3
166 abort ();
167
168 return w;
169}
170#ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
171#undef WORD_SIZE
172#define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
173SItype

--- 102 unchanged lines hidden (view full) ---

276 abort ();
277#endif
278
279 return w;
280}
281#endif
282
283#ifdef L_mulvdi3
276#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
277DWtype
278__mulvDI3 (DWtype u, DWtype v)
279{
280 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
281 but the checked multiplication needs only two. */
282 const DWunion uu = {.ll = u};
283 const DWunion vv = {.ll = v};
284
284DWtype
285__mulvDI3 (DWtype u, DWtype v)
286{
287 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
288 but the checked multiplication needs only two. */
289 const DWunion uu = {.ll = u};
290 const DWunion vv = {.ll = v};
291
285 if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
292 if (__builtin_expect (uu.s.high == uu.s.low >> (W_TYPE_SIZE - 1), 1))
286 {
287 /* u fits in a single Wtype. */
293 {
294 /* u fits in a single Wtype. */
288 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
295 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
289 {
290 /* v fits in a single Wtype as well. */
291 /* A single multiplication. No overflow risk. */
292 return (DWtype) uu.s.low * (DWtype) vv.s.low;
293 }
294 else
295 {
296 /* Two multiplications. */
297 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
298 * (UDWtype) (UWtype) vv.s.low};
299 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
300 * (UDWtype) (UWtype) vv.s.high};
301
302 if (vv.s.high < 0)
303 w1.s.high -= uu.s.low;
304 if (uu.s.low < 0)
305 w1.ll -= vv.ll;
306 w1.ll += (UWtype) w0.s.high;
296 {
297 /* v fits in a single Wtype as well. */
298 /* A single multiplication. No overflow risk. */
299 return (DWtype) uu.s.low * (DWtype) vv.s.low;
300 }
301 else
302 {
303 /* Two multiplications. */
304 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
305 * (UDWtype) (UWtype) vv.s.low};
306 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
307 * (UDWtype) (UWtype) vv.s.high};
308
309 if (vv.s.high < 0)
310 w1.s.high -= uu.s.low;
311 if (uu.s.low < 0)
312 w1.ll -= vv.ll;
313 w1.ll += (UWtype) w0.s.high;
307 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
314 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
308 {
309 w0.s.high = w1.s.low;
310 return w0.ll;
311 }
312 }
313 }
314 else
315 {
315 {
316 w0.s.high = w1.s.low;
317 return w0.ll;
318 }
319 }
320 }
321 else
322 {
316 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
323 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
317 {
318 /* v fits into a single Wtype. */
319 /* Two multiplications. */
320 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
321 * (UDWtype) (UWtype) vv.s.low};
322 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
323 * (UDWtype) (UWtype) vv.s.low};
324
325 if (uu.s.high < 0)
326 w1.s.high -= vv.s.low;
327 if (vv.s.low < 0)
328 w1.ll -= uu.ll;
329 w1.ll += (UWtype) w0.s.high;
324 {
325 /* v fits into a single Wtype. */
326 /* Two multiplications. */
327 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
328 * (UDWtype) (UWtype) vv.s.low};
329 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
330 * (UDWtype) (UWtype) vv.s.low};
331
332 if (uu.s.high < 0)
333 w1.s.high -= vv.s.low;
334 if (vv.s.low < 0)
335 w1.ll -= uu.ll;
336 w1.ll += (UWtype) w0.s.high;
330 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
337 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
331 {
332 w0.s.high = w1.s.low;
333 return w0.ll;
334 }
335 }
336 else
337 {
338 /* A few sign checks and a single multiplication. */

--- 143 unchanged lines hidden (view full) ---

482 }
483
484 return w.ll;
485}
486#endif
487
488#ifdef L_ffssi2
489#undef int
338 {
339 w0.s.high = w1.s.low;
340 return w0.ll;
341 }
342 }
343 else
344 {
345 /* A few sign checks and a single multiplication. */

--- 143 unchanged lines hidden (view full) ---

489 }
490
491 return w.ll;
492}
493#endif
494
495#ifdef L_ffssi2
496#undef int
490extern int __ffsSI2 (UWtype u);
491int
492__ffsSI2 (UWtype u)
493{
494 UWtype count;
495
496 if (u == 0)
497 return 0;
498
499 count_trailing_zeros (count, u);
500 return count + 1;
501}
502#endif
503
504#ifdef L_ffsdi2
505#undef int
497int
498__ffsSI2 (UWtype u)
499{
500 UWtype count;
501
502 if (u == 0)
503 return 0;
504
505 count_trailing_zeros (count, u);
506 return count + 1;
507}
508#endif
509
510#ifdef L_ffsdi2
511#undef int
506extern int __ffsDI2 (DWtype u);
507int
508__ffsDI2 (DWtype u)
509{
510 const DWunion uu = {.ll = u};
511 UWtype word, count, add;
512
513 if (uu.s.low != 0)
514 word = uu.s.low, add = 0;

--- 40 unchanged lines hidden (view full) ---

555{
556 UWtype q, r;
557 UWtype c0, c1, b1;
558
559 if ((Wtype) d >= 0)
560 {
561 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
562 {
512int
513__ffsDI2 (DWtype u)
514{
515 const DWunion uu = {.ll = u};
516 UWtype word, count, add;
517
518 if (uu.s.low != 0)
519 word = uu.s.low, add = 0;

--- 40 unchanged lines hidden (view full) ---

560{
561 UWtype q, r;
562 UWtype c0, c1, b1;
563
564 if ((Wtype) d >= 0)
565 {
566 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
567 {
563 /* dividend, divisor, and quotient are nonnegative */
568 /* Dividend, divisor, and quotient are nonnegative. */
564 sdiv_qrnnd (q, r, a1, a0, d);
565 }
566 else
567 {
569 sdiv_qrnnd (q, r, a1, a0, d);
570 }
571 else
572 {
568 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
573 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
569 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
574 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
570 /* Divide (c1*2^32 + c0) by d */
575 /* Divide (c1*2^32 + c0) by d. */
571 sdiv_qrnnd (q, r, c1, c0, d);
576 sdiv_qrnnd (q, r, c1, c0, d);
572 /* Add 2^31 to quotient */
577 /* Add 2^31 to quotient. */
573 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
574 }
575 }
576 else
577 {
578 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
579 c1 = a1 >> 1; /* A/2 */
580 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);

--- 79 unchanged lines hidden (view full) ---

660#endif
661
662#if (defined (L_udivdi3) || defined (L_divdi3) || \
663 defined (L_umoddi3) || defined (L_moddi3))
664#define L_udivmoddi4
665#endif
666
667#ifdef L_clz
578 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
579 }
580 }
581 else
582 {
583 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
584 c1 = a1 >> 1; /* A/2 */
585 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);

--- 79 unchanged lines hidden (view full) ---

665#endif
666
667#if (defined (L_udivdi3) || defined (L_divdi3) || \
668 defined (L_umoddi3) || defined (L_moddi3))
669#define L_udivmoddi4
670#endif
671
672#ifdef L_clz
668const UQItype __clz_tab[] =
673const UQItype __clz_tab[256] =
669{
670 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
671 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
672 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
673 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
674 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
675 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
676 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
674{
675 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,
676 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,
677 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,
678 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,
679 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,
680 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,
681 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
677 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
682 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
678};
679#endif
680
681#ifdef L_clzsi2
682#undef int
683};
684#endif
685
686#ifdef L_clzsi2
687#undef int
683extern int __clzSI2 (UWtype x);
684int
685__clzSI2 (UWtype x)
686{
687 Wtype ret;
688
689 count_leading_zeros (ret, x);
690
691 return ret;
692}
693#endif
694
695#ifdef L_clzdi2
696#undef int
688int
689__clzSI2 (UWtype x)
690{
691 Wtype ret;
692
693 count_leading_zeros (ret, x);
694
695 return ret;
696}
697#endif
698
699#ifdef L_clzdi2
700#undef int
697extern int __clzDI2 (UDWtype x);
698int
699__clzDI2 (UDWtype x)
700{
701 const DWunion uu = {.ll = x};
702 UWtype word;
703 Wtype ret, add;
704
705 if (uu.s.high)
706 word = uu.s.high, add = 0;
707 else
708 word = uu.s.low, add = W_TYPE_SIZE;
709
710 count_leading_zeros (ret, word);
711 return ret + add;
712}
713#endif
714
715#ifdef L_ctzsi2
716#undef int
701int
702__clzDI2 (UDWtype x)
703{
704 const DWunion uu = {.ll = x};
705 UWtype word;
706 Wtype ret, add;
707
708 if (uu.s.high)
709 word = uu.s.high, add = 0;
710 else
711 word = uu.s.low, add = W_TYPE_SIZE;
712
713 count_leading_zeros (ret, word);
714 return ret + add;
715}
716#endif
717
718#ifdef L_ctzsi2
719#undef int
717extern int __ctzSI2 (UWtype x);
718int
719__ctzSI2 (UWtype x)
720{
721 Wtype ret;
722
723 count_trailing_zeros (ret, x);
724
725 return ret;
726}
727#endif
728
729#ifdef L_ctzdi2
730#undef int
720int
721__ctzSI2 (UWtype x)
722{
723 Wtype ret;
724
725 count_trailing_zeros (ret, x);
726
727 return ret;
728}
729#endif
730
731#ifdef L_ctzdi2
732#undef int
731extern int __ctzDI2 (UDWtype x);
732int
733__ctzDI2 (UDWtype x)
734{
735 const DWunion uu = {.ll = x};
736 UWtype word;
737 Wtype ret, add;
738
739 if (uu.s.low)
740 word = uu.s.low, add = 0;
741 else
742 word = uu.s.high, add = W_TYPE_SIZE;
743
744 count_trailing_zeros (ret, word);
745 return ret + add;
746}
747#endif
748
733int
734__ctzDI2 (UDWtype x)
735{
736 const DWunion uu = {.ll = x};
737 UWtype word;
738 Wtype ret, add;
739
740 if (uu.s.low)
741 word = uu.s.low, add = 0;
742 else
743 word = uu.s.high, add = W_TYPE_SIZE;
744
745 count_trailing_zeros (ret, word);
746 return ret + add;
747}
748#endif
749
749#if (defined (L_popcountsi2) || defined (L_popcountdi2) \
750 || defined (L_popcount_tab))
751extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
752#endif
753
754#ifdef L_popcount_tab
750#ifdef L_popcount_tab
755const UQItype __popcount_tab[] =
751const UQItype __popcount_tab[256] =
756{
757 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
758 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
759 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
760 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
761 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
762 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
763 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
752{
753 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,
754 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,
755 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,
756 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,
757 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,
758 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,
759 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
764 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
760 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
765};
766#endif
767
768#ifdef L_popcountsi2
769#undef int
761};
762#endif
763
764#ifdef L_popcountsi2
765#undef int
770extern int __popcountSI2 (UWtype x);
771int
772__popcountSI2 (UWtype x)
773{
766int
767__popcountSI2 (UWtype x)
768{
774 UWtype i, ret = 0;
769 int i, ret = 0;
775
776 for (i = 0; i < W_TYPE_SIZE; i += 8)
777 ret += __popcount_tab[(x >> i) & 0xff];
778
779 return ret;
780}
781#endif
782
783#ifdef L_popcountdi2
784#undef int
770
771 for (i = 0; i < W_TYPE_SIZE; i += 8)
772 ret += __popcount_tab[(x >> i) & 0xff];
773
774 return ret;
775}
776#endif
777
778#ifdef L_popcountdi2
779#undef int
785extern int __popcountDI2 (UDWtype x);
786int
787__popcountDI2 (UDWtype x)
788{
780int
781__popcountDI2 (UDWtype x)
782{
789 UWtype i, ret = 0;
783 int i, ret = 0;
790
791 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
792 ret += __popcount_tab[(x >> i) & 0xff];
793
794 return ret;
795}
796#endif
797
798#ifdef L_paritysi2
799#undef int
784
785 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
786 ret += __popcount_tab[(x >> i) & 0xff];
787
788 return ret;
789}
790#endif
791
792#ifdef L_paritysi2
793#undef int
800extern int __paritySI2 (UWtype x);
801int
802__paritySI2 (UWtype x)
803{
804#if W_TYPE_SIZE > 64
805# error "fill out the table"
806#endif
807#if W_TYPE_SIZE > 32
808 x ^= x >> 32;

--- 5 unchanged lines hidden (view full) ---

814 x ^= x >> 4;
815 x &= 0xf;
816 return (0x6996 >> x) & 1;
817}
818#endif
819
820#ifdef L_paritydi2
821#undef int
794int
795__paritySI2 (UWtype x)
796{
797#if W_TYPE_SIZE > 64
798# error "fill out the table"
799#endif
800#if W_TYPE_SIZE > 32
801 x ^= x >> 32;

--- 5 unchanged lines hidden (view full) ---

807 x ^= x >> 4;
808 x &= 0xf;
809 return (0x6996 >> x) & 1;
810}
811#endif
812
813#ifdef L_paritydi2
814#undef int
822extern int __parityDI2 (UDWtype x);
823int
824__parityDI2 (UDWtype x)
825{
826 const DWunion uu = {.ll = x};
827 UWtype nx = uu.s.low ^ uu.s.high;
828
829#if W_TYPE_SIZE > 64
830# error "fill out the table"

--- 265 unchanged lines hidden (view full) ---

1096 DWtype w;
1097
1098 if (uu.s.high < 0)
1099 c = ~c,
1100 uu.ll = -uu.ll;
1101 if (vv.s.high < 0)
1102 vv.ll = -vv.ll;
1103
815int
816__parityDI2 (UDWtype x)
817{
818 const DWunion uu = {.ll = x};
819 UWtype nx = uu.s.low ^ uu.s.high;
820
821#if W_TYPE_SIZE > 64
822# error "fill out the table"

--- 265 unchanged lines hidden (view full) ---

1088 DWtype w;
1089
1090 if (uu.s.high < 0)
1091 c = ~c,
1092 uu.ll = -uu.ll;
1093 if (vv.s.high < 0)
1094 vv.ll = -vv.ll;
1095
1104 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
1096 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
1105 if (c)
1106 w = -w;
1107
1108 return w;
1109}
1110#endif
1111
1112#ifdef L_umoddi3

--- 49 unchanged lines hidden (view full) ---

1162 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1163 return 0;
1164 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1165 return 2;
1166 return 1;
1167}
1168#endif
1169
1097 if (c)
1098 w = -w;
1099
1100 return w;
1101}
1102#endif
1103
1104#ifdef L_umoddi3

--- 49 unchanged lines hidden (view full) ---

1154 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1155 return 0;
1156 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1157 return 2;
1158 return 1;
1159}
1160#endif
1161
1170#if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1171#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1172#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1173
1162#if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
1174DWtype
1175__fixunstfDI (TFtype a)
1176{
1177 if (a < 0)
1178 return 0;
1179
1180 /* Compute high word of result, as a flonum. */
1163DWtype
1164__fixunstfDI (TFtype a)
1165{
1166 if (a < 0)
1167 return 0;
1168
1169 /* Compute high word of result, as a flonum. */
1181 const TFtype b = (a / HIGH_WORD_COEFF);
1170 const TFtype b = (a / Wtype_MAXp1_F);
1182 /* Convert that to fixed (but not to DWtype!),
1183 and shift it into the high word. */
1184 UDWtype v = (UWtype) b;
1171 /* Convert that to fixed (but not to DWtype!),
1172 and shift it into the high word. */
1173 UDWtype v = (UWtype) b;
1185 v <<= WORD_SIZE;
1174 v <<= W_TYPE_SIZE;
1186 /* Remove high part from the TFtype, leaving the low part as flonum. */
1187 a -= (TFtype)v;
1188 /* Convert that to fixed (but not to DWtype!) and add it in.
1189 Sometimes A comes out negative. This is significant, since
1190 A has more bits than a long int does. */
1191 if (a < 0)
1192 v -= (UWtype) (- a);
1193 else
1194 v += (UWtype) a;
1195 return v;
1196}
1197#endif
1198
1175 /* Remove high part from the TFtype, leaving the low part as flonum. */
1176 a -= (TFtype)v;
1177 /* Convert that to fixed (but not to DWtype!) and add it in.
1178 Sometimes A comes out negative. This is significant, since
1179 A has more bits than a long int does. */
1180 if (a < 0)
1181 v -= (UWtype) (- a);
1182 else
1183 v += (UWtype) a;
1184 return v;
1185}
1186#endif
1187
1199#if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1188#if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
1200DWtype
1201__fixtfdi (TFtype a)
1202{
1203 if (a < 0)
1204 return - __fixunstfDI (-a);
1205 return __fixunstfDI (a);
1206}
1207#endif
1208
1189DWtype
1190__fixtfdi (TFtype a)
1191{
1192 if (a < 0)
1193 return - __fixunstfDI (-a);
1194 return __fixunstfDI (a);
1195}
1196#endif
1197
1209#if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1210#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1211#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1212
1198#if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
1213DWtype
1214__fixunsxfDI (XFtype a)
1215{
1216 if (a < 0)
1217 return 0;
1218
1219 /* Compute high word of result, as a flonum. */
1199DWtype
1200__fixunsxfDI (XFtype a)
1201{
1202 if (a < 0)
1203 return 0;
1204
1205 /* Compute high word of result, as a flonum. */
1220 const XFtype b = (a / HIGH_WORD_COEFF);
1206 const XFtype b = (a / Wtype_MAXp1_F);
1221 /* Convert that to fixed (but not to DWtype!),
1222 and shift it into the high word. */
1223 UDWtype v = (UWtype) b;
1207 /* Convert that to fixed (but not to DWtype!),
1208 and shift it into the high word. */
1209 UDWtype v = (UWtype) b;
1224 v <<= WORD_SIZE;
1210 v <<= W_TYPE_SIZE;
1225 /* Remove high part from the XFtype, leaving the low part as flonum. */
1226 a -= (XFtype)v;
1227 /* Convert that to fixed (but not to DWtype!) and add it in.
1228 Sometimes A comes out negative. This is significant, since
1229 A has more bits than a long int does. */
1230 if (a < 0)
1231 v -= (UWtype) (- a);
1232 else
1233 v += (UWtype) a;
1234 return v;
1235}
1236#endif
1237
1211 /* Remove high part from the XFtype, leaving the low part as flonum. */
1212 a -= (XFtype)v;
1213 /* Convert that to fixed (but not to DWtype!) and add it in.
1214 Sometimes A comes out negative. This is significant, since
1215 A has more bits than a long int does. */
1216 if (a < 0)
1217 v -= (UWtype) (- a);
1218 else
1219 v += (UWtype) a;
1220 return v;
1221}
1222#endif
1223
1238#if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1224#if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
1239DWtype
1240__fixxfdi (XFtype a)
1241{
1242 if (a < 0)
1243 return - __fixunsxfDI (-a);
1244 return __fixunsxfDI (a);
1245}
1246#endif
1247
1225DWtype
1226__fixxfdi (XFtype a)
1227{
1228 if (a < 0)
1229 return - __fixunsxfDI (-a);
1230 return __fixunsxfDI (a);
1231}
1232#endif
1233
1248#ifdef L_fixunsdfdi
1249#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1250#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1251
1234#if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
1252DWtype
1253__fixunsdfDI (DFtype a)
1254{
1255 /* Get high part of result. The division here will just moves the radix
1256 point and will not cause any rounding. Then the conversion to integral
1257 type chops result as desired. */
1235DWtype
1236__fixunsdfDI (DFtype a)
1237{
1238 /* Get high part of result. The division here will just moves the radix
1239 point and will not cause any rounding. Then the conversion to integral
1240 type chops result as desired. */
1258 const UWtype hi = a / HIGH_WORD_COEFF;
1241 const UWtype hi = a / Wtype_MAXp1_F;
1259
1260 /* Get low part of result. Convert `hi' to floating type and scale it back,
1261 then subtract this from the number being converted. This leaves the low
1262 part. Convert that to integral type. */
1242
1243 /* Get low part of result. Convert `hi' to floating type and scale it back,
1244 then subtract this from the number being converted. This leaves the low
1245 part. Convert that to integral type. */
1263 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1246 const UWtype lo = a - (DFtype) hi * Wtype_MAXp1_F;
1264
1265 /* Assemble result from the two parts. */
1247
1248 /* Assemble result from the two parts. */
1266 return ((UDWtype) hi << WORD_SIZE) | lo;
1249 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1267}
1268#endif
1269
1250}
1251#endif
1252
1270#ifdef L_fixdfdi
1253#if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
1271DWtype
1272__fixdfdi (DFtype a)
1273{
1274 if (a < 0)
1275 return - __fixunsdfDI (-a);
1276 return __fixunsdfDI (a);
1277}
1278#endif
1279
1254DWtype
1255__fixdfdi (DFtype a)
1256{
1257 if (a < 0)
1258 return - __fixunsdfDI (-a);
1259 return __fixunsdfDI (a);
1260}
1261#endif
1262
1280#ifdef L_fixunssfdi
1281#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1282#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1283
1263#if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
1284DWtype
1264DWtype
1285__fixunssfDI (SFtype original_a)
1265__fixunssfDI (SFtype a)
1286{
1266{
1267#if LIBGCC2_HAS_DF_MODE
1287 /* Convert the SFtype to a DFtype, because that is surely not going
1288 to lose any bits. Some day someone else can write a faster version
1289 that avoids converting to DFtype, and verify it really works right. */
1268 /* Convert the SFtype to a DFtype, because that is surely not going
1269 to lose any bits. Some day someone else can write a faster version
1270 that avoids converting to DFtype, and verify it really works right. */
1290 const DFtype a = original_a;
1271 const DFtype dfa = a;
1291
1292 /* Get high part of result. The division here will just moves the radix
1293 point and will not cause any rounding. Then the conversion to integral
1294 type chops result as desired. */
1272
1273 /* Get high part of result. The division here will just moves the radix
1274 point and will not cause any rounding. Then the conversion to integral
1275 type chops result as desired. */
1295 const UWtype hi = a / HIGH_WORD_COEFF;
1276 const UWtype hi = dfa / Wtype_MAXp1_F;
1296
1297 /* Get low part of result. Convert `hi' to floating type and scale it back,
1298 then subtract this from the number being converted. This leaves the low
1299 part. Convert that to integral type. */
1277
1278 /* Get low part of result. Convert `hi' to floating type and scale it back,
1279 then subtract this from the number being converted. This leaves the low
1280 part. Convert that to integral type. */
1300 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1281 const UWtype lo = dfa - (DFtype) hi * Wtype_MAXp1_F;
1301
1302 /* Assemble result from the two parts. */
1282
1283 /* Assemble result from the two parts. */
1303 return ((UDWtype) hi << WORD_SIZE) | lo;
1284 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
1285#elif FLT_MANT_DIG < W_TYPE_SIZE
1286 if (a < 1)
1287 return 0;
1288 if (a < Wtype_MAXp1_F)
1289 return (UWtype)a;
1290 if (a < Wtype_MAXp1_F * Wtype_MAXp1_F)
1291 {
1292 /* Since we know that there are fewer significant bits in the SFmode
1293 quantity than in a word, we know that we can convert out all the
1294 significant bits in one step, and thus avoid losing bits. */
1295
1296 /* ??? This following loop essentially performs frexpf. If we could
1297 use the real libm function, or poke at the actual bits of the fp
1298 format, it would be significantly faster. */
1299
1300 UWtype shift = 0, counter;
1301 SFtype msb;
1302
1303 a /= Wtype_MAXp1_F;
1304 for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1)
1305 {
1306 SFtype counterf = (UWtype)1 << counter;
1307 if (a >= counterf)
1308 {
1309 shift |= counter;
1310 a /= counterf;
1311 }
1312 }
1313
1314 /* Rescale into the range of one word, extract the bits of that
1315 one word, and shift the result into position. */
1316 a *= Wtype_MAXp1_F;
1317 counter = a;
1318 return (DWtype)counter << shift;
1319 }
1320 return -1;
1321#else
1322# error
1323#endif
1304}
1305#endif
1306
1324}
1325#endif
1326
1307#ifdef L_fixsfdi
1327#if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
1308DWtype
1309__fixsfdi (SFtype a)
1310{
1311 if (a < 0)
1312 return - __fixunssfDI (-a);
1313 return __fixunssfDI (a);
1314}
1315#endif
1316
1328DWtype
1329__fixsfdi (SFtype a)
1330{
1331 if (a < 0)
1332 return - __fixunssfDI (-a);
1333 return __fixunssfDI (a);
1334}
1335#endif
1336
1317#if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1318#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1319#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1320#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1321
1337#if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
1322XFtype
1323__floatdixf (DWtype u)
1324{
1338XFtype
1339__floatdixf (DWtype u)
1340{
1325 XFtype d = (Wtype) (u >> WORD_SIZE);
1326 d *= HIGH_HALFWORD_COEFF;
1327 d *= HIGH_HALFWORD_COEFF;
1328 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1341#if W_TYPE_SIZE > XF_SIZE
1342# error
1343#endif
1344 XFtype d = (Wtype) (u >> W_TYPE_SIZE);
1345 d *= Wtype_MAXp1_F;
1346 d += (UWtype)u;
1347 return d;
1348}
1349#endif
1329
1350
1351#if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
1352XFtype
1353__floatundixf (UDWtype u)
1354{
1355#if W_TYPE_SIZE > XF_SIZE
1356# error
1357#endif
1358 XFtype d = (UWtype) (u >> W_TYPE_SIZE);
1359 d *= Wtype_MAXp1_F;
1360 d += (UWtype)u;
1330 return d;
1331}
1332#endif
1333
1361 return d;
1362}
1363#endif
1364
1334#if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1335#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1336#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1337#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1338
1365#if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
1339TFtype
1340__floatditf (DWtype u)
1341{
1366TFtype
1367__floatditf (DWtype u)
1368{
1342 TFtype d = (Wtype) (u >> WORD_SIZE);
1343 d *= HIGH_HALFWORD_COEFF;
1344 d *= HIGH_HALFWORD_COEFF;
1345 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1369#if W_TYPE_SIZE > TF_SIZE
1370# error
1371#endif
1372 TFtype d = (Wtype) (u >> W_TYPE_SIZE);
1373 d *= Wtype_MAXp1_F;
1374 d += (UWtype)u;
1375 return d;
1376}
1377#endif
1346
1378
1379#if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
1380TFtype
1381__floatunditf (UDWtype u)
1382{
1383#if W_TYPE_SIZE > TF_SIZE
1384# error
1385#endif
1386 TFtype d = (UWtype) (u >> W_TYPE_SIZE);
1387 d *= Wtype_MAXp1_F;
1388 d += (UWtype)u;
1347 return d;
1348}
1349#endif
1350
1389 return d;
1390}
1391#endif
1392
1351#ifdef L_floatdidf
1352#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1353#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1354#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1393#if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
1394 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
1395#define DI_SIZE (W_TYPE_SIZE * 2)
1396#define F_MODE_OK(SIZE) \
1397 (SIZE < DI_SIZE \
1398 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1399 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1400 The conversion from long double to float suffers from double \
1401 rounding, because we convert via double. In any case, the \
1402 fallback code is faster. */ \
1403 && !IS_IBM_EXTENDED (SIZE))
1404#if defined(L_floatdisf)
1405#define FUNC __floatdisf
1406#define FSTYPE SFtype
1407#define FSSIZE SF_SIZE
1408#else
1409#define FUNC __floatdidf
1410#define FSTYPE DFtype
1411#define FSSIZE DF_SIZE
1412#endif
1355
1413
1356DFtype
1357__floatdidf (DWtype u)
1414FSTYPE
1415FUNC (DWtype u)
1358{
1416{
1359 DFtype d = (Wtype) (u >> WORD_SIZE);
1360 d *= HIGH_HALFWORD_COEFF;
1361 d *= HIGH_HALFWORD_COEFF;
1362 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1417#if FSSIZE >= W_TYPE_SIZE
1418 /* When the word size is small, we never get any rounding error. */
1419 FSTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1420 f *= Wtype_MAXp1_F;
1421 f += (UWtype)u;
1422 return f;
1423#elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1424 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1425 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1363
1426
1364 return d;
1365}
1427#if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1428# define FSIZE DF_SIZE
1429# define FTYPE DFtype
1430#elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1431# define FSIZE XF_SIZE
1432# define FTYPE XFtype
1433#elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1434# define FSIZE TF_SIZE
1435# define FTYPE TFtype
1436#else
1437# error
1366#endif
1367
1438#endif
1439
1368#ifdef L_floatdisf
1369#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1370#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1371#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1440#define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1372
1441
1373#define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1374#define DF_SIZE DBL_MANT_DIG
1375#define SF_SIZE FLT_MANT_DIG
1442 /* Protect against double-rounding error.
1443 Represent any low-order bits, that might be truncated by a bit that
1444 won't be lost. The bit can go in anywhere below the rounding position
1445 of the FSTYPE. A fixed mask and bit position handles all usual
1446 configurations. */
1447 if (! (- ((DWtype) 1 << FSIZE) < u
1448 && u < ((DWtype) 1 << FSIZE)))
1449 {
1450 if ((UDWtype) u & (REP_BIT - 1))
1451 {
1452 u &= ~ (REP_BIT - 1);
1453 u |= REP_BIT;
1454 }
1455 }
1376
1456
1377SFtype
1378__floatdisf (DWtype u)
1457 /* Do the calculation in a wider type so that we don't lose any of
1458 the precision of the high word while multiplying it. */
1459 FTYPE f = (Wtype) (u >> W_TYPE_SIZE);
1460 f *= Wtype_MAXp1_F;
1461 f += (UWtype)u;
1462 return (FSTYPE) f;
1463#else
1464#if FSSIZE >= W_TYPE_SIZE - 2
1465# error
1466#endif
1467 /* Finally, the word size is larger than the number of bits in the
1468 required FSTYPE, and we've got no suitable wider type. The only
1469 way to avoid double rounding is to special case the
1470 extraction. */
1471
1472 /* If there are no high bits set, fall back to one conversion. */
1473 if ((Wtype)u == u)
1474 return (FSTYPE)(Wtype)u;
1475
1476 /* Otherwise, find the power of two. */
1477 Wtype hi = u >> W_TYPE_SIZE;
1478 if (hi < 0)
1479 hi = -hi;
1480
1481 UWtype count, shift;
1482 count_leading_zeros (count, hi);
1483
1484 /* No leading bits means u == minimum. */
1485 if (count == 0)
1486 return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2));
1487
1488 shift = 1 + W_TYPE_SIZE - count;
1489
1490 /* Shift down the most significant bits. */
1491 hi = u >> shift;
1492
1493 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1494 if (u & (((DWtype)1 << shift) - 1))
1495 hi |= 1;
1496
1497 /* Convert the one word of data, and rescale. */
1498 FSTYPE f = hi;
1499 f *= (UDWtype)1 << shift;
1500 return f;
1501#endif
1502}
1503#endif
1504
1505#if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
1506 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
1507#define DI_SIZE (W_TYPE_SIZE * 2)
1508#define F_MODE_OK(SIZE) \
1509 (SIZE < DI_SIZE \
1510 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
1511 /* Don't use IBM Extended Double TFmode for TI->SF calculations. \
1512 The conversion from long double to float suffers from double \
1513 rounding, because we convert via double. In any case, the \
1514 fallback code is faster. */ \
1515 && !IS_IBM_EXTENDED (SIZE))
1516#if defined(L_floatundisf)
1517#define FUNC __floatundisf
1518#define FSTYPE SFtype
1519#define FSSIZE SF_SIZE
1520#else
1521#define FUNC __floatundidf
1522#define FSTYPE DFtype
1523#define FSSIZE DF_SIZE
1524#endif
1525
1526FSTYPE
1527FUNC (UDWtype u)
1379{
1528{
1529#if FSSIZE >= W_TYPE_SIZE
1530 /* When the word size is small, we never get any rounding error. */
1531 FSTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1532 f *= Wtype_MAXp1_F;
1533 f += (UWtype)u;
1534 return f;
1535#elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE)) \
1536 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE)) \
1537 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1538
1539#if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (DF_SIZE))
1540# define FSIZE DF_SIZE
1541# define FTYPE DFtype
1542#elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (XF_SIZE))
1543# define FSIZE XF_SIZE
1544# define FTYPE XFtype
1545#elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (TF_SIZE))
1546# define FSIZE TF_SIZE
1547# define FTYPE TFtype
1548#else
1549# error
1550#endif
1551
1552#define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
1553
1380 /* Protect against double-rounding error.
1554 /* Protect against double-rounding error.
1381 Represent any low-order bits, that might be truncated in DFmode,
1382 by a bit that won't be lost. The bit can go in anywhere below the
1383 rounding position of the SFmode. A fixed mask and bit position
1384 handles all usual configurations. It doesn't handle the case
1385 of 128-bit DImode, however. */
1386 if (DF_SIZE < DI_SIZE
1387 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1555 Represent any low-order bits, that might be truncated by a bit that
1556 won't be lost. The bit can go in anywhere below the rounding position
1557 of the FSTYPE. A fixed mask and bit position handles all usual
1558 configurations. */
1559 if (u >= ((UDWtype) 1 << FSIZE))
1388 {
1560 {
1389#define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1390 if (! (- ((DWtype) 1 << DF_SIZE) < u
1391 && u < ((DWtype) 1 << DF_SIZE)))
1561 if ((UDWtype) u & (REP_BIT - 1))
1392 {
1562 {
1393 if ((UDWtype) u & (REP_BIT - 1))
1394 {
1395 u &= ~ (REP_BIT - 1);
1396 u |= REP_BIT;
1397 }
1563 u &= ~ (REP_BIT - 1);
1564 u |= REP_BIT;
1398 }
1399 }
1565 }
1566 }
1400 /* Do the calculation in DFmode
1401 so that we don't lose any of the precision of the high word
1402 while multiplying it. */
1403 DFtype f = (Wtype) (u >> WORD_SIZE);
1404 f *= HIGH_HALFWORD_COEFF;
1405 f *= HIGH_HALFWORD_COEFF;
1406 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1407
1567
1408 return (SFtype) f;
1568 /* Do the calculation in a wider type so that we don't lose any of
1569 the precision of the high word while multiplying it. */
1570 FTYPE f = (UWtype) (u >> W_TYPE_SIZE);
1571 f *= Wtype_MAXp1_F;
1572 f += (UWtype)u;
1573 return (FSTYPE) f;
1574#else
1575#if FSSIZE == W_TYPE_SIZE - 1
1576# error
1577#endif
1578 /* Finally, the word size is larger than the number of bits in the
1579 required FSTYPE, and we've got no suitable wider type. The only
1580 way to avoid double rounding is to special case the
1581 extraction. */
1582
1583 /* If there are no high bits set, fall back to one conversion. */
1584 if ((UWtype)u == u)
1585 return (FSTYPE)(UWtype)u;
1586
1587 /* Otherwise, find the power of two. */
1588 UWtype hi = u >> W_TYPE_SIZE;
1589
1590 UWtype count, shift;
1591 count_leading_zeros (count, hi);
1592
1593 shift = W_TYPE_SIZE - count;
1594
1595 /* Shift down the most significant bits. */
1596 hi = u >> shift;
1597
1598 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
1599 if (u & (((UDWtype)1 << shift) - 1))
1600 hi |= 1;
1601
1602 /* Convert the one word of data, and rescale. */
1603 FSTYPE f = hi;
1604 f *= (UDWtype)1 << shift;
1605 return f;
1606#endif
1409}
1410#endif
1411
1607}
1608#endif
1609
1412#if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1610#if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
1413/* Reenable the normal types, in case limits.h needs them. */
1414#undef char
1415#undef short
1416#undef int
1417#undef long
1418#undef unsigned
1419#undef float
1420#undef double

--- 5 unchanged lines hidden (view full) ---

1426__fixunsxfSI (XFtype a)
1427{
1428 if (a >= - (DFtype) Wtype_MIN)
1429 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1430 return (Wtype) a;
1431}
1432#endif
1433
1611/* Reenable the normal types, in case limits.h needs them. */
1612#undef char
1613#undef short
1614#undef int
1615#undef long
1616#undef unsigned
1617#undef float
1618#undef double

--- 5 unchanged lines hidden (view full) ---

1624__fixunsxfSI (XFtype a)
1625{
1626 if (a >= - (DFtype) Wtype_MIN)
1627 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1628 return (Wtype) a;
1629}
1630#endif
1631
1434#ifdef L_fixunsdfsi
1632#if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
1435/* Reenable the normal types, in case limits.h needs them. */
1436#undef char
1437#undef short
1438#undef int
1439#undef long
1440#undef unsigned
1441#undef float
1442#undef double

--- 5 unchanged lines hidden (view full) ---

1448__fixunsdfSI (DFtype a)
1449{
1450 if (a >= - (DFtype) Wtype_MIN)
1451 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1452 return (Wtype) a;
1453}
1454#endif
1455
1633/* Reenable the normal types, in case limits.h needs them. */
1634#undef char
1635#undef short
1636#undef int
1637#undef long
1638#undef unsigned
1639#undef float
1640#undef double

--- 5 unchanged lines hidden (view full) ---

1646__fixunsdfSI (DFtype a)
1647{
1648 if (a >= - (DFtype) Wtype_MIN)
1649 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1650 return (Wtype) a;
1651}
1652#endif
1653
1456#ifdef L_fixunssfsi
1654#if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
1457/* Reenable the normal types, in case limits.h needs them. */
1458#undef char
1459#undef short
1460#undef int
1461#undef long
1462#undef unsigned
1463#undef float
1464#undef double

--- 5 unchanged lines hidden (view full) ---

1470__fixunssfSI (SFtype a)
1471{
1472 if (a >= - (SFtype) Wtype_MIN)
1473 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1474 return (Wtype) a;
1475}
1476#endif
1477
1655/* Reenable the normal types, in case limits.h needs them. */
1656#undef char
1657#undef short
1658#undef int
1659#undef long
1660#undef unsigned
1661#undef float
1662#undef double

--- 5 unchanged lines hidden (view full) ---

1668__fixunssfSI (SFtype a)
1669{
1670 if (a >= - (SFtype) Wtype_MIN)
1671 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1672 return (Wtype) a;
1673}
1674#endif
1675
1676/* Integer power helper used from __builtin_powi for non-constant
1677 exponents. */
1678
1679#if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
1680 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
1681 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
1682 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
1683# if defined(L_powisf2)
1684# define TYPE SFtype
1685# define NAME __powisf2
1686# elif defined(L_powidf2)
1687# define TYPE DFtype
1688# define NAME __powidf2
1689# elif defined(L_powixf2)
1690# define TYPE XFtype
1691# define NAME __powixf2
1692# elif defined(L_powitf2)
1693# define TYPE TFtype
1694# define NAME __powitf2
1695# endif
1696
1697#undef int
1698#undef unsigned
1699TYPE
1700NAME (TYPE x, int m)
1701{
1702 unsigned int n = m < 0 ? -m : m;
1703 TYPE y = n % 2 ? x : 1;
1704 while (n >>= 1)
1705 {
1706 x = x * x;
1707 if (n % 2)
1708 y = y * x;
1709 }
1710 return m < 0 ? 1/y : y;
1711}
1712
1713#endif
1714
1715#if ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
1716 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
1717 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
1718 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
1719
1720#undef float
1721#undef double
1722#undef long
1723
1724#if defined(L_mulsc3) || defined(L_divsc3)
1725# define MTYPE SFtype
1726# define CTYPE SCtype
1727# define MODE sc
1728# define CEXT f
1729# define NOTRUNC __FLT_EVAL_METHOD__ == 0
1730#elif defined(L_muldc3) || defined(L_divdc3)
1731# define MTYPE DFtype
1732# define CTYPE DCtype
1733# define MODE dc
1734# if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64
1735# define CEXT l
1736# define NOTRUNC 1
1737# else
1738# define CEXT
1739# define NOTRUNC __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 1
1740# endif
1741#elif defined(L_mulxc3) || defined(L_divxc3)
1742# define MTYPE XFtype
1743# define CTYPE XCtype
1744# define MODE xc
1745# define CEXT l
1746# define NOTRUNC 1
1747#elif defined(L_multc3) || defined(L_divtc3)
1748# define MTYPE TFtype
1749# define CTYPE TCtype
1750# define MODE tc
1751# define CEXT l
1752# define NOTRUNC 1
1753#else
1754# error
1755#endif
1756
1757#define CONCAT3(A,B,C) _CONCAT3(A,B,C)
1758#define _CONCAT3(A,B,C) A##B##C
1759
1760#define CONCAT2(A,B) _CONCAT2(A,B)
1761#define _CONCAT2(A,B) A##B
1762
1763/* All of these would be present in a full C99 implementation of <math.h>
1764 and <complex.h>. Our problem is that only a few systems have such full
1765 implementations. Further, libgcc_s.so isn't currently linked against
1766 libm.so, and even for systems that do provide full C99, the extra overhead
1767 of all programs using libgcc having to link against libm. So avoid it. */
1768
1769#define isnan(x) __builtin_expect ((x) != (x), 0)
1770#define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
1771#define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
1772
1773#define INFINITY CONCAT2(__builtin_inf, CEXT) ()
1774#define I 1i
1775
1776/* Helpers to make the following code slightly less gross. */
1777#define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
1778#define FABS CONCAT2(__builtin_fabs, CEXT)
1779
1780/* Verify that MTYPE matches up with CEXT. */
1781extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1];
1782
1783/* Ensure that we've lost any extra precision. */
1784#if NOTRUNC
1785# define TRUNC(x)
1786#else
1787# define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
1788#endif
1789
1790#if defined(L_mulsc3) || defined(L_muldc3) \
1791 || defined(L_mulxc3) || defined(L_multc3)
1792
1793CTYPE
1794CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
1795{
1796 MTYPE ac, bd, ad, bc, x, y;
1797
1798 ac = a * c;
1799 bd = b * d;
1800 ad = a * d;
1801 bc = b * c;
1802
1803 TRUNC (ac);
1804 TRUNC (bd);
1805 TRUNC (ad);
1806 TRUNC (bc);
1807
1808 x = ac - bd;
1809 y = ad + bc;
1810
1811 if (isnan (x) && isnan (y))
1812 {
1813 /* Recover infinities that computed as NaN + iNaN. */
1814 _Bool recalc = 0;
1815 if (isinf (a) || isinf (b))
1816 {
1817 /* z is infinite. "Box" the infinity and change NaNs in
1818 the other factor to 0. */
1819 a = COPYSIGN (isinf (a) ? 1 : 0, a);
1820 b = COPYSIGN (isinf (b) ? 1 : 0, b);
1821 if (isnan (c)) c = COPYSIGN (0, c);
1822 if (isnan (d)) d = COPYSIGN (0, d);
1823 recalc = 1;
1824 }
1825 if (isinf (c) || isinf (d))
1826 {
1827 /* w is infinite. "Box" the infinity and change NaNs in
1828 the other factor to 0. */
1829 c = COPYSIGN (isinf (c) ? 1 : 0, c);
1830 d = COPYSIGN (isinf (d) ? 1 : 0, d);
1831 if (isnan (a)) a = COPYSIGN (0, a);
1832 if (isnan (b)) b = COPYSIGN (0, b);
1833 recalc = 1;
1834 }
1835 if (!recalc
1836 && (isinf (ac) || isinf (bd)
1837 || isinf (ad) || isinf (bc)))
1838 {
1839 /* Recover infinities from overflow by changing NaNs to 0. */
1840 if (isnan (a)) a = COPYSIGN (0, a);
1841 if (isnan (b)) b = COPYSIGN (0, b);
1842 if (isnan (c)) c = COPYSIGN (0, c);
1843 if (isnan (d)) d = COPYSIGN (0, d);
1844 recalc = 1;
1845 }
1846 if (recalc)
1847 {
1848 x = INFINITY * (a * c - b * d);
1849 y = INFINITY * (a * d + b * c);
1850 }
1851 }
1852
1853 return x + I * y;
1854}
1855#endif /* complex multiply */
1856
1857#if defined(L_divsc3) || defined(L_divdc3) \
1858 || defined(L_divxc3) || defined(L_divtc3)
1859
1860CTYPE
1861CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
1862{
1863 MTYPE denom, ratio, x, y;
1864
1865 /* ??? We can get better behavior from logarithmic scaling instead of
1866 the division. But that would mean starting to link libgcc against
1867 libm. We could implement something akin to ldexp/frexp as gcc builtins
1868 fairly easily... */
1869 if (FABS (c) < FABS (d))
1870 {
1871 ratio = c / d;
1872 denom = (c * ratio) + d;
1873 x = ((a * ratio) + b) / denom;
1874 y = ((b * ratio) - a) / denom;
1875 }
1876 else
1877 {
1878 ratio = d / c;
1879 denom = (d * ratio) + c;
1880 x = ((b * ratio) + a) / denom;
1881 y = (b - (a * ratio)) / denom;
1882 }
1883
1884 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
1885 are nonzero/zero, infinite/finite, and finite/infinite. */
1886 if (isnan (x) && isnan (y))
1887 {
1888 if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b)))
1889 {
1890 x = COPYSIGN (INFINITY, c) * a;
1891 y = COPYSIGN (INFINITY, c) * b;
1892 }
1893 else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d))
1894 {
1895 a = COPYSIGN (isinf (a) ? 1 : 0, a);
1896 b = COPYSIGN (isinf (b) ? 1 : 0, b);
1897 x = INFINITY * (a * c + b * d);
1898 y = INFINITY * (b * c - a * d);
1899 }
1900 else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b))
1901 {
1902 c = COPYSIGN (isinf (c) ? 1 : 0, c);
1903 d = COPYSIGN (isinf (d) ? 1 : 0, d);
1904 x = 0.0 * (a * c + b * d);
1905 y = 0.0 * (b * c - a * d);
1906 }
1907 }
1908
1909 return x + I * y;
1910}
1911#endif /* complex divide */
1912
1913#endif /* all complex float routines */
1914
1478/* From here on down, the routines use normal data types. */
1479
1480#define SItype bogus_type
1481#define USItype bogus_type
1482#define DItype bogus_type
1483#define UDItype bogus_type
1484#define SFtype bogus_type
1485#define DFtype bogus_type

--- 84 unchanged lines hidden (view full) ---

1570#endif /* L_enable_execute_stack */
1571
1572#ifdef L_trampoline
1573
1574/* Jump to a trampoline, loading the static chain address. */
1575
1576#if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1577
1915/* From here on down, the routines use normal data types. */
1916
1917#define SItype bogus_type
1918#define USItype bogus_type
1919#define DItype bogus_type
1920#define UDItype bogus_type
1921#define SFtype bogus_type
1922#define DFtype bogus_type

--- 84 unchanged lines hidden (view full) ---

2007#endif /* L_enable_execute_stack */
2008
2009#ifdef L_trampoline
2010
2011/* Jump to a trampoline, loading the static chain address. */
2012
2013#if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
2014
1578long
2015int
1579getpagesize (void)
1580{
1581#ifdef _ALPHA_
1582 return 8192;
1583#else
1584 return 4096;
1585#endif
1586}

--- 32 unchanged lines hidden (view full) ---

1619TRANSFER_FROM_TRAMPOLINE
1620#endif
1621#endif /* L_trampoline */
1622
1623#ifndef __CYGWIN__
1624#ifdef L__main
1625
1626#include "gbl-ctors.h"
2016getpagesize (void)
2017{
2018#ifdef _ALPHA_
2019 return 8192;
2020#else
2021 return 4096;
2022#endif
2023}

--- 32 unchanged lines hidden (view full) ---

2056TRANSFER_FROM_TRAMPOLINE
2057#endif
2058#endif /* L_trampoline */
2059
2060#ifndef __CYGWIN__
2061#ifdef L__main
2062
2063#include "gbl-ctors.h"
2064
1627/* Some systems use __main in a way incompatible with its use in gcc, in these
1628 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1629 give the same symbol without quotes for an alternative entry point. You
1630 must define both, or neither. */
1631#ifndef NAME__MAIN
1632#define NAME__MAIN "__main"
1633#define SYMBOL__MAIN __main
1634#endif
1635
2065/* Some systems use __main in a way incompatible with its use in gcc, in these
2066 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
2067 give the same symbol without quotes for an alternative entry point. You
2068 must define both, or neither. */
2069#ifndef NAME__MAIN
2070#define NAME__MAIN "__main"
2071#define SYMBOL__MAIN __main
2072#endif
2073
1636#ifdef INIT_SECTION_ASM_OP
2074#if defined (INIT_SECTION_ASM_OP) || defined (INIT_ARRAY_SECTION_ASM_OP)
1637#undef HAS_INIT_SECTION
1638#define HAS_INIT_SECTION
1639#endif
1640
1641#if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1642
1643/* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1644 code to run constructors. In that case, we need to handle EH here, too. */

--- 96 unchanged lines hidden (view full) ---

1741func_ptr __CTOR_LIST__[2] = {0, 0};
1742func_ptr __DTOR_LIST__[2] = {0, 0};
1743#else
1744func_ptr __CTOR_LIST__[2];
1745func_ptr __DTOR_LIST__[2];
1746#endif
1747#endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1748#endif /* L_ctors */
2075#undef HAS_INIT_SECTION
2076#define HAS_INIT_SECTION
2077#endif
2078
2079#if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
2080
2081/* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
2082 code to run constructors. In that case, we need to handle EH here, too. */

--- 96 unchanged lines hidden (view full) ---

2179func_ptr __CTOR_LIST__[2] = {0, 0};
2180func_ptr __DTOR_LIST__[2] = {0, 0};
2181#else
2182func_ptr __CTOR_LIST__[2];
2183func_ptr __DTOR_LIST__[2];
2184#endif
2185#endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2186#endif /* L_ctors */
1749
2187#endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */