1 the niosii-gnutools-src-5.1.tgz release from altera is missing a lot of
2 core gcc files, this patch adds them back in
4 --- ./gcc/gcc/config/nios2/crti.asm
5 +++ ./gcc/gcc/config/nios2/crti.asm
9 + by Jonah Graham (jgraham@altera.com)
11 +This file is free software; you can redistribute it and/or modify it
12 +under the terms of the GNU General Public License as published by the
13 +Free Software Foundation; either version 2, or (at your option) any
16 +In addition to the permissions in the GNU General Public License, the
17 +Free Software Foundation gives you unlimited permission to link the
18 +compiled version of this file with other programs, and to distribute
19 +those programs without any restriction coming from the use of this
20 +file. (The General Public License restrictions do apply in other
21 +respects; for example, they cover modification of the file, and
22 +distribution when not linked into another program.)
24 +This file is distributed in the hope that it will be useful, but
25 +WITHOUT ANY WARRANTY; without even the implied warranty of
26 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 +General Public License for more details.
29 +You should have received a copy of the GNU General Public License
30 +along with this program; see the file COPYING. If not, write to
31 +the Free Software Foundation, 59 Temple Place - Suite 330,
32 +Boston, MA 02111-1307, USA.
34 + As a special exception, if you link this library with files
35 + compiled with GCC to produce an executable, this does not cause
36 + the resulting executable to be covered by the GNU General Public License.
37 + This exception does not however invalidate any other reasons why
38 + the executable file might be covered by the GNU General Public License.
41 +This file just make a stack frame for the contents of the .fini and
42 +.init sections. Users may put any desired instructions in those
46 +While technically any code can be put in the init and fini sections
47 +most stuff will not work other than stuff which obeys the call frame
48 +and ABI. All the call-preserved registers are saved, the call clobbered
49 +registers should have been saved by the code calling init and fini.
51 +See crtstuff.c for an example of code that inserts itself in the
52 +init and fini sections.
54 +See crt0.s for the code that calls init and fini.
95 --- ./gcc/gcc/config/nios2/crtn.asm
96 +++ ./gcc/gcc/config/nios2/crtn.asm
100 + by Jonah Graham (jgraham@altera.com)
102 +This file is free software; you can redistribute it and/or modify it
103 +under the terms of the GNU General Public License as published by the
104 +Free Software Foundation; either version 2, or (at your option) any
107 +In addition to the permissions in the GNU General Public License, the
108 +Free Software Foundation gives you unlimited permission to link the
109 +compiled version of this file with other programs, and to distribute
110 +those programs without any restriction coming from the use of this
111 +file. (The General Public License restrictions do apply in other
112 +respects; for example, they cover modification of the file, and
113 +distribution when not linked into another program.)
115 +This file is distributed in the hope that it will be useful, but
116 +WITHOUT ANY WARRANTY; without even the implied warranty of
117 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
118 +General Public License for more details.
120 +You should have received a copy of the GNU General Public License
121 +along with this program; see the file COPYING. If not, write to
122 +the Free Software Foundation, 59 Temple Place - Suite 330,
123 +Boston, MA 02111-1307, USA.
125 + As a special exception, if you link this library with files
126 + compiled with GCC to produce an executable, this does not cause
127 + the resulting executable to be covered by the GNU General Public License.
128 + This exception does not however invalidate any other reasons why
129 + the executable file might be covered by the GNU General Public License.
132 +This file just makes sure that the .fini and .init sections do in
133 +fact return. Users may put any desired instructions in those sections.
134 +This file is the last thing linked into any executable.
168 --- ./gcc/gcc/config/nios2/lib2-divmod-hi.c
169 +++ ./gcc/gcc/config/nios2/lib2-divmod-hi.c
172 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
173 + supposedly valid even though this is a "target" file. */
174 +#include "auto-host.h"
177 +#include "tconfig.h"
178 +#include "tsystem.h"
179 +#include "coretypes.h"
183 +/* Don't use `fancy_abort' here even if config.h says to use it. */
189 +#ifdef HAVE_GAS_HIDDEN
190 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
192 +#define ATTRIBUTE_HIDDEN
195 +#include "libgcc2.h"
197 +extern HItype __modhi3 (HItype, HItype);
198 +extern HItype __divhi3 (HItype, HItype);
199 +extern HItype __umodhi3 (HItype, HItype);
200 +extern HItype __udivhi3 (HItype, HItype);
202 +static UHItype udivmodhi4(UHItype, UHItype, word_type);
205 +udivmodhi4(UHItype num, UHItype den, word_type modwanted)
210 + while (den < num && bit && !(den & (1L<<15)))
225 + if (modwanted) return num;
231 +__divhi3 (HItype a, HItype b)
248 + res = udivmodhi4 (a, b, 0);
258 +__modhi3 (HItype a, HItype b)
272 + res = udivmodhi4 (a, b, 1);
282 +__udivhi3 (HItype a, HItype b)
284 + return udivmodhi4 (a, b, 0);
289 +__umodhi3 (HItype a, HItype b)
291 + return udivmodhi4 (a, b, 1);
294 --- ./gcc/gcc/config/nios2/lib2-divmod.c
295 +++ ./gcc/gcc/config/nios2/lib2-divmod.c
298 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
299 + supposedly valid even though this is a "target" file. */
300 +#include "auto-host.h"
303 +#include "tconfig.h"
304 +#include "tsystem.h"
305 +#include "coretypes.h"
309 +/* Don't use `fancy_abort' here even if config.h says to use it. */
315 +#ifdef HAVE_GAS_HIDDEN
316 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
318 +#define ATTRIBUTE_HIDDEN
321 +#include "libgcc2.h"
323 +extern SItype __modsi3 (SItype, SItype);
324 +extern SItype __divsi3 (SItype, SItype);
325 +extern SItype __umodsi3 (SItype, SItype);
326 +extern SItype __udivsi3 (SItype, SItype);
328 +static USItype udivmodsi4(USItype, USItype, word_type);
330 +/* 16-bit SI divide and modulo as used in NIOS */
334 +udivmodsi4(USItype num, USItype den, word_type modwanted)
339 + while (den < num && bit && !(den & (1L<<31)))
354 + if (modwanted) return num;
360 +__divsi3 (SItype a, SItype b)
377 + res = udivmodsi4 (a, b, 0);
387 +__modsi3 (SItype a, SItype b)
401 + res = udivmodsi4 (a, b, 1);
411 +__udivsi3 (SItype a, SItype b)
413 + return udivmodsi4 (a, b, 0);
418 +__umodsi3 (SItype a, SItype b)
420 + return udivmodsi4 (a, b, 1);
423 --- ./gcc/gcc/config/nios2/lib2-divtable.c
424 +++ ./gcc/gcc/config/nios2/lib2-divtable.c
427 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
428 + supposedly valid even though this is a "target" file. */
429 +#include "auto-host.h"
432 +#include "tconfig.h"
433 +#include "tsystem.h"
434 +#include "coretypes.h"
438 +/* Don't use `fancy_abort' here even if config.h says to use it. */
444 +#ifdef HAVE_GAS_HIDDEN
445 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
447 +#define ATTRIBUTE_HIDDEN
450 +#include "libgcc2.h"
452 +UQItype __divsi3_table[] =
454 + 0, 0/1, 0/2, 0/3, 0/4, 0/5, 0/6, 0/7, 0/8, 0/9, 0/10, 0/11, 0/12, 0/13, 0/14, 0/15,
455 + 0, 1/1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15,
456 + 0, 2/1, 2/2, 2/3, 2/4, 2/5, 2/6, 2/7, 2/8, 2/9, 2/10, 2/11, 2/12, 2/13, 2/14, 2/15,
457 + 0, 3/1, 3/2, 3/3, 3/4, 3/5, 3/6, 3/7, 3/8, 3/9, 3/10, 3/11, 3/12, 3/13, 3/14, 3/15,
458 + 0, 4/1, 4/2, 4/3, 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/10, 4/11, 4/12, 4/13, 4/14, 4/15,
459 + 0, 5/1, 5/2, 5/3, 5/4, 5/5, 5/6, 5/7, 5/8, 5/9, 5/10, 5/11, 5/12, 5/13, 5/14, 5/15,
460 + 0, 6/1, 6/2, 6/3, 6/4, 6/5, 6/6, 6/7, 6/8, 6/9, 6/10, 6/11, 6/12, 6/13, 6/14, 6/15,
461 + 0, 7/1, 7/2, 7/3, 7/4, 7/5, 7/6, 7/7, 7/8, 7/9, 7/10, 7/11, 7/12, 7/13, 7/14, 7/15,
462 + 0, 8/1, 8/2, 8/3, 8/4, 8/5, 8/6, 8/7, 8/8, 8/9, 8/10, 8/11, 8/12, 8/13, 8/14, 8/15,
463 + 0, 9/1, 9/2, 9/3, 9/4, 9/5, 9/6, 9/7, 9/8, 9/9, 9/10, 9/11, 9/12, 9/13, 9/14, 9/15,
464 + 0, 10/1, 10/2, 10/3, 10/4, 10/5, 10/6, 10/7, 10/8, 10/9, 10/10, 10/11, 10/12, 10/13, 10/14, 10/15,
465 + 0, 11/1, 11/2, 11/3, 11/4, 11/5, 11/6, 11/7, 11/8, 11/9, 11/10, 11/11, 11/12, 11/13, 11/14, 11/15,
466 + 0, 12/1, 12/2, 12/3, 12/4, 12/5, 12/6, 12/7, 12/8, 12/9, 12/10, 12/11, 12/12, 12/13, 12/14, 12/15,
467 + 0, 13/1, 13/2, 13/3, 13/4, 13/5, 13/6, 13/7, 13/8, 13/9, 13/10, 13/11, 13/12, 13/13, 13/14, 13/15,
468 + 0, 14/1, 14/2, 14/3, 14/4, 14/5, 14/6, 14/7, 14/8, 14/9, 14/10, 14/11, 14/12, 14/13, 14/14, 14/15,
469 + 0, 15/1, 15/2, 15/3, 15/4, 15/5, 15/6, 15/7, 15/8, 15/9, 15/10, 15/11, 15/12, 15/13, 15/14, 15/15,
472 --- ./gcc/gcc/config/nios2/lib2-mul.c
473 +++ ./gcc/gcc/config/nios2/lib2-mul.c
475 +/* while we are debugging (ie compile outside of gcc build)
476 + disable gcc specific headers */
477 +#ifndef DEBUG_MULSI3
480 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
481 + supposedly valid even though this is a "target" file. */
482 +#include "auto-host.h"
485 +#include "tconfig.h"
486 +#include "tsystem.h"
487 +#include "coretypes.h"
491 +/* Don't use `fancy_abort' here even if config.h says to use it. */
497 +#ifdef HAVE_GAS_HIDDEN
498 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
500 +#define ATTRIBUTE_HIDDEN
503 +#include "libgcc2.h"
507 +#define USItype unsigned int
511 +extern SItype __mulsi3 (SItype, SItype);
514 +__mulsi3 (SItype a, SItype b)
532 +TODO: Choose best alternative implementation.
535 +__divsi3 (SItype a, SItype b)
542 + if (a & (1L << cnt))
563 + for (i = -1000; i < 1000; i++)
564 + for (j = -1000; j < 1000; j++)
566 + int expect = i * j;
567 + int actual = A__divsi3 (i, j);
568 + if (expect != actual)
570 + printf ("error: %d * %d = %d not %d\n", i, j, expect, actual);
578 --- ./gcc/gcc/config/nios2/nios2-dp-bit.c
579 +++ ./gcc/gcc/config/nios2/nios2-dp-bit.c
582 +/* This is a software floating point library which can be used
583 + for targets without hardware floating point.
584 + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
585 + Free Software Foundation, Inc.
587 +This file is free software; you can redistribute it and/or modify it
588 +under the terms of the GNU General Public License as published by the
589 +Free Software Foundation; either version 2, or (at your option) any
592 +In addition to the permissions in the GNU General Public License, the
593 +Free Software Foundation gives you unlimited permission to link the
594 +compiled version of this file with other programs, and to distribute
595 +those programs without any restriction coming from the use of this
596 +file. (The General Public License restrictions do apply in other
597 +respects; for example, they cover modification of the file, and
598 +distribution when not linked into another program.)
600 +This file is distributed in the hope that it will be useful, but
601 +WITHOUT ANY WARRANTY; without even the implied warranty of
602 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
603 +General Public License for more details.
605 +You should have received a copy of the GNU General Public License
606 +along with this program; see the file COPYING. If not, write to
607 +the Free Software Foundation, 59 Temple Place - Suite 330,
608 +Boston, MA 02111-1307, USA. */
610 +/* As a special exception, if you link this library with other files,
611 + some of which are compiled with GCC, to produce an executable,
612 + this library does not by itself cause the resulting executable
613 + to be covered by the GNU General Public License.
614 + This exception does not however invalidate any other reasons why
615 + the executable file might be covered by the GNU General Public License. */
617 +/* This implements IEEE 754 format arithmetic, but does not provide a
618 + mechanism for setting the rounding mode, or for generating or handling
621 + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
622 + Wilson, all of Cygnus Support. */
624 +/* The intended way to use this file is to make two copies, add `#define FLOAT'
625 + to one copy, then compile both copies and add them to libgcc.a. */
627 +#include "tconfig.h"
628 +#include "coretypes.h"
630 +#include "config/fp-bit.h"
632 +/* The following macros can be defined to change the behavior of this file:
633 + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
634 + defined, then this file implements a `double', aka DFmode, fp library.
635 + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
636 + don't include float->double conversion which requires the double library.
637 + This is useful only for machines which can't support doubles, e.g. some
639 + CMPtype: Specify the type that floating point compares should return.
640 + This defaults to SItype, aka int.
641 + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
642 + US Software goFast library.
643 + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
644 + two integers to the FLO_union_type.
645 + NO_DENORMALS: Disable handling of denormals.
646 + NO_NANS: Disable nan and infinity handling
647 + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
650 +/* We don't currently support extended floats (long doubles) on machines
651 + without hardware to deal with them.
653 + These stubs are just to keep the linker from complaining about unresolved
654 + references which can be pulled in from libio & libstdc++, even if the
655 + user isn't using long doubles. However, they may generate an unresolved
656 + external to abort if abort is not used by the function, and the stubs
657 + are referenced from within libc, since libgcc goes before and after the
660 +#ifdef DECLARE_LIBRARY_RENAMES
661 + DECLARE_LIBRARY_RENAMES
664 +#ifdef EXTENDED_FLOAT_STUBS
665 +extern void abort (void);
666 +void __extendsfxf2 (void) { abort(); }
667 +void __extenddfxf2 (void) { abort(); }
668 +void __truncxfdf2 (void) { abort(); }
669 +void __truncxfsf2 (void) { abort(); }
670 +void __fixxfsi (void) { abort(); }
671 +void __floatsixf (void) { abort(); }
672 +void __addxf3 (void) { abort(); }
673 +void __subxf3 (void) { abort(); }
674 +void __mulxf3 (void) { abort(); }
675 +void __divxf3 (void) { abort(); }
676 +void __negxf2 (void) { abort(); }
677 +void __eqxf2 (void) { abort(); }
678 +void __nexf2 (void) { abort(); }
679 +void __gtxf2 (void) { abort(); }
680 +void __gexf2 (void) { abort(); }
681 +void __lexf2 (void) { abort(); }
682 +void __ltxf2 (void) { abort(); }
684 +void __extendsftf2 (void) { abort(); }
685 +void __extenddftf2 (void) { abort(); }
686 +void __trunctfdf2 (void) { abort(); }
687 +void __trunctfsf2 (void) { abort(); }
688 +void __fixtfsi (void) { abort(); }
689 +void __floatsitf (void) { abort(); }
690 +void __addtf3 (void) { abort(); }
691 +void __subtf3 (void) { abort(); }
692 +void __multf3 (void) { abort(); }
693 +void __divtf3 (void) { abort(); }
694 +void __negtf2 (void) { abort(); }
695 +void __eqtf2 (void) { abort(); }
696 +void __netf2 (void) { abort(); }
697 +void __gttf2 (void) { abort(); }
698 +void __getf2 (void) { abort(); }
699 +void __letf2 (void) { abort(); }
700 +void __lttf2 (void) { abort(); }
701 +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
703 +/* IEEE "special" number predicates */
712 +#if defined L_thenan_sf
713 +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
714 +#elif defined L_thenan_df
715 +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
716 +#elif defined L_thenan_tf
717 +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
718 +#elif defined TFLOAT
719 +extern const fp_number_type __thenan_tf;
721 +extern const fp_number_type __thenan_sf;
723 +extern const fp_number_type __thenan_df;
727 +static fp_number_type *
730 + /* Discard the const qualifier... */
732 + return (fp_number_type *) (& __thenan_tf);
734 + return (fp_number_type *) (& __thenan_sf);
736 + return (fp_number_type *) (& __thenan_df);
742 +isnan ( fp_number_type * x)
744 + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
749 +isinf ( fp_number_type * x)
751 + return x->class == CLASS_INFINITY;
754 +#endif /* NO_NANS */
758 +iszero ( fp_number_type * x)
760 + return x->class == CLASS_ZERO;
765 +flip_sign ( fp_number_type * x)
767 + x->sign = !x->sign;
770 +extern FLO_type pack_d ( fp_number_type * );
772 +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
774 +pack_d ( fp_number_type * src)
776 + FLO_union_type dst;
777 + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
778 + int sign = src->sign;
781 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
783 + /* We can't represent these values accurately. By using the
784 + largest possible magnitude, we guarantee that the conversion
785 + of infinity is at least as big as any finite number. */
787 + fraction = ((fractype) 1 << FRACBITS) - 1;
789 + else if (isnan (src))
792 + if (src->class == CLASS_QNAN || 1)
794 +#ifdef QUIET_NAN_NEGATED
795 + fraction |= QUIET_NAN - 1;
797 + fraction |= QUIET_NAN;
801 + else if (isinf (src))
806 + else if (iszero (src))
811 + else if (fraction == 0)
817 + if (src->normal_exp < NORMAL_EXPMIN)
820 + /* Go straight to a zero representation if denormals are not
821 + supported. The denormal handling would be harmless but
822 + isn't unnecessary. */
825 +#else /* NO_DENORMALS */
826 + /* This number's exponent is too low to fit into the bits
827 + available in the number, so we'll store 0 in the exponent and
828 + shift the fraction to the right to make up for it. */
830 + int shift = NORMAL_EXPMIN - src->normal_exp;
834 + if (shift > FRAC_NBITS - NGARDS)
836 + /* No point shifting, since it's more that 64 out. */
841 + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
842 + fraction = (fraction >> shift) | lowbit;
844 + if ((fraction & GARDMASK) == GARDMSB)
846 + if ((fraction & (1 << NGARDS)))
847 + fraction += GARDROUND + 1;
851 + /* Add to the guards to round up. */
852 + fraction += GARDROUND;
854 + /* Perhaps the rounding means we now need to change the
855 + exponent, because the fraction is no longer denormal. */
856 + if (fraction >= IMPLICIT_1)
860 + fraction >>= NGARDS;
861 +#endif /* NO_DENORMALS */
863 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
864 + && src->normal_exp > EXPBIAS)
871 + exp = src->normal_exp + EXPBIAS;
872 + if (!ROUND_TOWARDS_ZERO)
874 + /* IF the gard bits are the all zero, but the first, then we're
875 + half way between two numbers, choose the one which makes the
876 + lsb of the answer 0. */
877 + if ((fraction & GARDMASK) == GARDMSB)
879 + if (fraction & (1 << NGARDS))
880 + fraction += GARDROUND + 1;
884 + /* Add a one to the guards to round up */
885 + fraction += GARDROUND;
887 + if (fraction >= IMPLICIT_2)
893 + fraction >>= NGARDS;
895 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
897 + /* Saturate on overflow. */
899 + fraction = ((fractype) 1 << FRACBITS) - 1;
904 + /* We previously used bitfields to store the number, but this doesn't
905 + handle little/big endian systems conveniently, so use shifts and
907 +#ifdef FLOAT_BIT_ORDER_MISMATCH
908 + dst.bits.fraction = fraction;
909 + dst.bits.exp = exp;
910 + dst.bits.sign = sign;
912 +# if defined TFLOAT && defined HALFFRACBITS
914 + halffractype high, low, unity;
915 + int lowsign, lowexp;
917 + unity = (halffractype) 1 << HALFFRACBITS;
919 + /* Set HIGH to the high double's significand, masking out the implicit 1.
920 + Set LOW to the low double's full significand. */
921 + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
922 + low = fraction & (unity * 2 - 1);
924 + /* Get the initial sign and exponent of the low double. */
925 + lowexp = exp - HALFFRACBITS - 1;
928 + /* HIGH should be rounded like a normal double, making |LOW| <=
929 + 0.5 ULP of HIGH. Assume round-to-nearest. */
931 + if (low > unity || (low == unity && (high & 1) == 1))
933 + /* Round HIGH up and adjust LOW to match. */
937 + /* May make it infinite, but that's OK. */
941 + low = unity * 2 - low;
945 + high |= (halffractype) exp << HALFFRACBITS;
946 + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
948 + if (exp == EXPMAX || exp == 0 || low == 0)
952 + while (lowexp > 0 && low < unity)
960 + halffractype roundmsb, round;
963 + shift = 1 - lowexp;
964 + roundmsb = (1 << (shift - 1));
965 + round = low & ((roundmsb << 1) - 1);
970 + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
974 + /* LOW rounds up to the smallest normal number. */
980 + low |= (halffractype) lowexp << HALFFRACBITS;
981 + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
983 + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
986 + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
987 + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
988 + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
992 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
995 + qrtrfractype tmp1 = dst.words[0];
996 + qrtrfractype tmp2 = dst.words[1];
997 + dst.words[0] = dst.words[3];
998 + dst.words[1] = dst.words[2];
999 + dst.words[2] = tmp2;
1000 + dst.words[3] = tmp1;
1004 + halffractype tmp = dst.words[0];
1005 + dst.words[0] = dst.words[1];
1006 + dst.words[1] = tmp;
1015 +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
1017 +unpack_d (FLO_union_type * src, fp_number_type * dst)
1019 + /* We previously used bitfields to store the number, but this doesn't
1020 + handle little/big endian systems conveniently, so use shifts and
1022 + fractype fraction;
1026 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
1027 + FLO_union_type swapped;
1030 + swapped.words[0] = src->words[3];
1031 + swapped.words[1] = src->words[2];
1032 + swapped.words[2] = src->words[1];
1033 + swapped.words[3] = src->words[0];
1035 + swapped.words[0] = src->words[1];
1036 + swapped.words[1] = src->words[0];
1041 +#ifdef FLOAT_BIT_ORDER_MISMATCH
1042 + fraction = src->bits.fraction;
1043 + exp = src->bits.exp;
1044 + sign = src->bits.sign;
1046 +# if defined TFLOAT && defined HALFFRACBITS
1048 + halffractype high, low;
1050 + high = src->value_raw >> HALFSHIFT;
1051 + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
1053 + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
1054 + fraction <<= FRACBITS - HALFFRACBITS;
1055 + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
1056 + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
1058 + if (exp != EXPMAX && exp != 0 && low != 0)
1060 + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
1061 + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
1065 + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
1067 + xlow |= (((halffractype)1) << HALFFRACBITS);
1070 + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
1073 + else if (shift < 0)
1075 + if (sign == lowsign)
1077 + else if (fraction >= xlow)
1081 + /* The high part is a power of two but the full number is lower.
1082 + This code will leave the implicit 1 in FRACTION, but we'd
1083 + have added that below anyway. */
1084 + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
1090 + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
1091 + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
1092 + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
1099 + /* Hmm. Looks like 0 */
1101 +#ifdef NO_DENORMALS
1106 + /* tastes like zero */
1107 + dst->class = CLASS_ZERO;
1111 + /* Zero exponent with nonzero fraction - it's denormalized,
1112 + so there isn't a leading implicit one - we'll shift it so
1114 + dst->normal_exp = exp - EXPBIAS + 1;
1115 + fraction <<= NGARDS;
1117 + dst->class = CLASS_NUMBER;
1119 + while (fraction < IMPLICIT_1)
1122 + dst->normal_exp--;
1125 + dst->fraction.ll = fraction;
1128 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
1130 + /* Huge exponent*/
1131 + if (fraction == 0)
1133 + /* Attached to a zero fraction - means infinity */
1134 + dst->class = CLASS_INFINITY;
1138 + /* Nonzero fraction, means nan */
1139 +#ifdef QUIET_NAN_NEGATED
1140 + if ((fraction & QUIET_NAN) == 0)
1142 + if (fraction & QUIET_NAN)
1145 + dst->class = CLASS_QNAN;
1149 + dst->class = CLASS_SNAN;
1151 + /* Keep the fraction part as the nan number */
1152 + dst->fraction.ll = fraction;
1157 + /* Nothing strange about this number */
1158 + dst->normal_exp = exp - EXPBIAS;
1159 + dst->class = CLASS_NUMBER;
1160 + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
1163 +#endif /* L_unpack_df || L_unpack_sf */
1165 +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
1166 +static fp_number_type *
1167 +_fpadd_parts (fp_number_type * a,
1168 + fp_number_type * b,
1169 + fp_number_type * tmp)
1171 + intfrac tfraction;
1173 + /* Put commonly used fields in local variables. */
1176 + fractype a_fraction;
1177 + fractype b_fraction;
1189 + /* Adding infinities with opposite signs yields a NaN. */
1190 + if (isinf (b) && a->sign != b->sign)
1203 + tmp->sign = a->sign & b->sign;
1213 + /* Got two numbers. shift the smaller and increment the exponent till
1214 + they're the same */
1218 + a_normal_exp = a->normal_exp;
1219 + b_normal_exp = b->normal_exp;
1220 + a_fraction = a->fraction.ll;
1221 + b_fraction = b->fraction.ll;
1223 + diff = a_normal_exp - b_normal_exp;
1227 + if (diff < FRAC_NBITS)
1229 + /* ??? This does shifts one bit at a time. Optimize. */
1230 + while (a_normal_exp > b_normal_exp)
1233 + LSHIFT (b_fraction);
1235 + while (b_normal_exp > a_normal_exp)
1238 + LSHIFT (a_fraction);
1243 + /* Somethings's up.. choose the biggest */
1244 + if (a_normal_exp > b_normal_exp)
1246 + b_normal_exp = a_normal_exp;
1251 + a_normal_exp = b_normal_exp;
1257 + if (a->sign != b->sign)
1261 + tfraction = -a_fraction + b_fraction;
1265 + tfraction = a_fraction - b_fraction;
1267 + if (tfraction >= 0)
1270 + tmp->normal_exp = a_normal_exp;
1271 + tmp->fraction.ll = tfraction;
1276 + tmp->normal_exp = a_normal_exp;
1277 + tmp->fraction.ll = -tfraction;
1279 + /* and renormalize it */
1281 + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
1283 + tmp->fraction.ll <<= 1;
1284 + tmp->normal_exp--;
1289 + tmp->sign = a->sign;
1290 + tmp->normal_exp = a_normal_exp;
1291 + tmp->fraction.ll = a_fraction + b_fraction;
1293 + tmp->class = CLASS_NUMBER;
1294 + /* Now the fraction is added, we have to shift down to renormalize the
1297 + if (tmp->fraction.ll >= IMPLICIT_2)
1299 + LSHIFT (tmp->fraction.ll);
1300 + tmp->normal_exp++;
1307 +add (FLO_type arg_a, FLO_type arg_b)
1311 + fp_number_type tmp;
1312 + fp_number_type *res;
1313 + FLO_union_type au, bu;
1318 + unpack_d (&au, &a);
1319 + unpack_d (&bu, &b);
1321 + res = _fpadd_parts (&a, &b, &tmp);
1323 + return pack_d (res);
1327 +sub (FLO_type arg_a, FLO_type arg_b)
1331 + fp_number_type tmp;
1332 + fp_number_type *res;
1333 + FLO_union_type au, bu;
1338 + unpack_d (&au, &a);
1339 + unpack_d (&bu, &b);
1343 + res = _fpadd_parts (&a, &b, &tmp);
1345 + return pack_d (res);
1347 +#endif /* L_addsub_sf || L_addsub_df */
1349 +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
1350 +static inline __attribute__ ((__always_inline__)) fp_number_type *
1351 +_fpmul_parts ( fp_number_type * a,
1352 + fp_number_type * b,
1353 + fp_number_type * tmp)
1356 + fractype high = 0;
1360 + a->sign = a->sign != b->sign;
1365 + b->sign = a->sign != b->sign;
1372 + a->sign = a->sign != b->sign;
1381 + b->sign = a->sign != b->sign;
1386 + a->sign = a->sign != b->sign;
1391 + b->sign = a->sign != b->sign;
1395 + /* Calculate the mantissa by multiplying both numbers to get a
1396 + twice-as-wide number. */
1398 +#if defined(NO_DI_MODE) || defined(TFLOAT)
1400 + fractype x = a->fraction.ll;
1401 + fractype ylow = b->fraction.ll;
1402 + fractype yhigh = 0;
1405 + /* ??? This does multiplies one bit at a time. Optimize. */
1406 + for (bit = 0; bit < FRAC_NBITS; bit++)
1412 + carry = (low += ylow) < ylow;
1413 + high += yhigh + carry;
1416 + if (ylow & FRACHIGH)
1424 +#elif defined(FLOAT)
1425 + /* Multiplying two USIs to get a UDI, we're safe. */
1427 + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
1429 + high = answer >> BITS_PER_SI;
1433 + /* fractype is DImode, but we need the result to be twice as wide.
1434 + Assuming a widening multiply from DImode to TImode is not
1435 + available, build one by hand. */
1437 + USItype nl = a->fraction.ll;
1438 + USItype nh = a->fraction.ll >> BITS_PER_SI;
1439 + USItype ml = b->fraction.ll;
1440 + USItype mh = b->fraction.ll >> BITS_PER_SI;
1441 + UDItype pp_ll = (UDItype) ml * nl;
1442 + UDItype pp_hl = (UDItype) mh * nl;
1443 + UDItype pp_lh = (UDItype) ml * nh;
1444 + UDItype pp_hh = (UDItype) mh * nh;
1447 + UDItype ps_hh__ = pp_hl + pp_lh;
1448 + if (ps_hh__ < pp_hl)
1449 + res2 += (UDItype)1 << BITS_PER_SI;
1450 + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
1451 + res0 = pp_ll + pp_hl;
1454 + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
1461 + tmp->normal_exp = a->normal_exp + b->normal_exp
1462 + + FRAC_NBITS - (FRACBITS + NGARDS);
1463 + tmp->sign = a->sign != b->sign;
1464 + while (high >= IMPLICIT_2)
1466 + tmp->normal_exp++;
1474 + while (high < IMPLICIT_1)
1476 + tmp->normal_exp--;
1479 + if (low & FRACHIGH)
1483 + /* rounding is tricky. if we only round if it won't make us round later. */
1485 + if (low & FRACHIGH2)
1487 + if (((high & GARDMASK) != GARDMSB)
1488 + && (((high + 1) & GARDMASK) == GARDMSB))
1490 + /* don't round, it gets done again later. */
1498 + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
1500 + if (high & (1 << NGARDS))
1502 + /* half way, so round to even */
1503 + high += GARDROUND + 1;
1507 + /* but we really weren't half way */
1508 + high += GARDROUND + 1;
1511 + tmp->fraction.ll = high;
1512 + tmp->class = CLASS_NUMBER;
1517 +multiply (FLO_type arg_a, FLO_type arg_b)
1521 + fp_number_type tmp;
1522 + fp_number_type *res;
1523 + FLO_union_type au, bu;
1528 + unpack_d (&au, &a);
1529 + unpack_d (&bu, &b);
1531 + res = _fpmul_parts (&a, &b, &tmp);
1533 + return pack_d (res);
1535 +#endif /* L_mul_sf || L_mul_df */
1537 +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
1538 +static inline __attribute__ ((__always_inline__)) fp_number_type *
1539 +_fpdiv_parts (fp_number_type * a,
1540 + fp_number_type * b)
1543 + fractype numerator;
1544 + fractype denominator;
1545 + fractype quotient;
1556 + a->sign = a->sign ^ b->sign;
1558 + if (isinf (a) || iszero (a))
1560 + if (a->class == b->class)
1567 + a->fraction.ll = 0;
1568 + a->normal_exp = 0;
1573 + a->class = CLASS_INFINITY;
1577 + /* Calculate the mantissa by multiplying both 64bit numbers to get a
1581 + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1584 + a->normal_exp = a->normal_exp - b->normal_exp;
1585 + numerator = a->fraction.ll;
1586 + denominator = b->fraction.ll;
1588 + if (numerator < denominator)
1590 + /* Fraction will be less than 1.0 */
1596 + /* ??? Does divide one bit at a time. Optimize. */
1599 + if (numerator >= denominator)
1602 + numerator -= denominator;
1608 + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
1610 + if (quotient & (1 << NGARDS))
1612 + /* half way, so round to even */
1613 + quotient += GARDROUND + 1;
1615 + else if (numerator)
1617 + /* but we really weren't half way, more bits exist */
1618 + quotient += GARDROUND + 1;
1622 + a->fraction.ll = quotient;
1628 +divide (FLO_type arg_a, FLO_type arg_b)
1632 + fp_number_type *res;
1633 + FLO_union_type au, bu;
1638 + unpack_d (&au, &a);
1639 + unpack_d (&bu, &b);
1641 + res = _fpdiv_parts (&a, &b);
1643 + return pack_d (res);
1645 +#endif /* L_div_sf || L_div_df */
1647 +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
1648 + || defined(L_fpcmp_parts_tf)
1649 +/* according to the demo, fpcmp returns a comparison with 0... thus
1656 +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
1659 + /* either nan -> unordered. Must be checked outside of this routine. */
1660 + if (isnan (a) && isnan (b))
1662 + return 1; /* still unordered! */
1666 + if (isnan (a) || isnan (b))
1668 + return 1; /* how to indicate unordered compare? */
1670 + if (isinf (a) && isinf (b))
1672 + /* +inf > -inf, but +inf != +inf */
1673 + /* b \a| +inf(0)| -inf(1)
1674 + ______\+--------+--------
1675 + +inf(0)| a==b(0)| a<b(-1)
1676 + -------+--------+--------
1677 + -inf(1)| a>b(1) | a==b(0)
1678 + -------+--------+--------
1679 + So since unordered must be nonzero, just line up the columns...
1681 + return b->sign - a->sign;
1683 + /* but not both... */
1686 + return a->sign ? -1 : 1;
1690 + return b->sign ? 1 : -1;
1692 + if (iszero (a) && iszero (b))
1698 + return b->sign ? 1 : -1;
1702 + return a->sign ? -1 : 1;
1704 + /* now both are "normal". */
1705 + if (a->sign != b->sign)
1707 + /* opposite signs */
1708 + return a->sign ? -1 : 1;
1710 + /* same sign; exponents? */
1711 + if (a->normal_exp > b->normal_exp)
1713 + return a->sign ? -1 : 1;
1715 + if (a->normal_exp < b->normal_exp)
1717 + return a->sign ? 1 : -1;
1719 + /* same exponents; check size. */
1720 + if (a->fraction.ll > b->fraction.ll)
1722 + return a->sign ? -1 : 1;
1724 + if (a->fraction.ll < b->fraction.ll)
1726 + return a->sign ? 1 : -1;
1728 + /* after all that, they're equal. */
1733 +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
1735 +compare (FLO_type arg_a, FLO_type arg_b)
1739 + FLO_union_type au, bu;
1744 + unpack_d (&au, &a);
1745 + unpack_d (&bu, &b);
1747 + return __fpcmp_parts (&a, &b);
1749 +#endif /* L_compare_sf || L_compare_df */
1751 +#ifndef US_SOFTWARE_GOFAST
1753 +/* These should be optimized for their specific tasks someday. */
1755 +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
1757 +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
1761 + FLO_union_type au, bu;
1766 + unpack_d (&au, &a);
1767 + unpack_d (&bu, &b);
1769 + if (isnan (&a) || isnan (&b))
1770 + return 1; /* false, truth == 0 */
1772 + return __fpcmp_parts (&a, &b) ;
1774 +#endif /* L_eq_sf || L_eq_df */
1776 +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
1778 +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
1782 + FLO_union_type au, bu;
1787 + unpack_d (&au, &a);
1788 + unpack_d (&bu, &b);
1790 + if (isnan (&a) || isnan (&b))
1791 + return 1; /* true, truth != 0 */
1793 + return __fpcmp_parts (&a, &b) ;
1795 +#endif /* L_ne_sf || L_ne_df */
1797 +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
1799 +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
1803 + FLO_union_type au, bu;
1808 + unpack_d (&au, &a);
1809 + unpack_d (&bu, &b);
1811 + if (isnan (&a) || isnan (&b))
1812 + return -1; /* false, truth > 0 */
1814 + return __fpcmp_parts (&a, &b);
1816 +#endif /* L_gt_sf || L_gt_df */
1818 +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
1820 +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
1824 + FLO_union_type au, bu;
1829 + unpack_d (&au, &a);
1830 + unpack_d (&bu, &b);
1832 + if (isnan (&a) || isnan (&b))
1833 + return -1; /* false, truth >= 0 */
1834 + return __fpcmp_parts (&a, &b) ;
1836 +#endif /* L_ge_sf || L_ge_df */
1838 +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
1840 +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
1844 + FLO_union_type au, bu;
1849 + unpack_d (&au, &a);
1850 + unpack_d (&bu, &b);
1852 + if (isnan (&a) || isnan (&b))
1853 + return 1; /* false, truth < 0 */
1855 + return __fpcmp_parts (&a, &b);
1857 +#endif /* L_lt_sf || L_lt_df */
1859 +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
1861 +_le_f2 (FLO_type arg_a, FLO_type arg_b)
1865 + FLO_union_type au, bu;
1870 + unpack_d (&au, &a);
1871 + unpack_d (&bu, &b);
1873 + if (isnan (&a) || isnan (&b))
1874 + return 1; /* false, truth <= 0 */
1876 + return __fpcmp_parts (&a, &b) ;
1878 +#endif /* L_le_sf || L_le_df */
1880 +#endif /* ! US_SOFTWARE_GOFAST */
1882 +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
1884 +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
1888 + FLO_union_type au, bu;
1893 + unpack_d (&au, &a);
1894 + unpack_d (&bu, &b);
1896 + return (isnan (&a) || isnan (&b));
1898 +#endif /* L_unord_sf || L_unord_df */
1900 +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
1902 +si_to_float (SItype arg_a)
1904 + fp_number_type in;
1906 + in.class = CLASS_NUMBER;
1907 + in.sign = arg_a < 0;
1910 + in.class = CLASS_ZERO;
1914 + in.normal_exp = FRACBITS + NGARDS;
1917 + /* Special case for minint, since there is no +ve integer
1918 + representation for it */
1919 + if (arg_a == (- MAX_SI_INT - 1))
1921 + return (FLO_type)(- MAX_SI_INT - 1);
1923 + in.fraction.ll = (-arg_a);
1926 + in.fraction.ll = arg_a;
1928 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1930 + in.fraction.ll <<= 1;
1931 + in.normal_exp -= 1;
1934 + return pack_d (&in);
1936 +#endif /* L_si_to_sf || L_si_to_df */
1938 +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
1940 +usi_to_float (USItype arg_a)
1942 + fp_number_type in;
1947 + in.class = CLASS_ZERO;
1951 + in.class = CLASS_NUMBER;
1952 + in.normal_exp = FRACBITS + NGARDS;
1953 + in.fraction.ll = arg_a;
1955 + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
1957 + in.fraction.ll >>= 1;
1958 + in.normal_exp += 1;
1960 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1962 + in.fraction.ll <<= 1;
1963 + in.normal_exp -= 1;
1966 + return pack_d (&in);
1970 +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
1972 +float_to_si (FLO_type arg_a)
1976 + FLO_union_type au;
1979 + unpack_d (&au, &a);
1985 + /* get reasonable MAX_SI_INT... */
1987 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1988 + /* it is a number, but a small one */
1989 + if (a.normal_exp < 0)
1991 + if (a.normal_exp > BITS_PER_SI - 2)
1992 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1993 + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1994 + return a.sign ? (-tmp) : (tmp);
1996 +#endif /* L_sf_to_si || L_df_to_si */
1998 +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
1999 +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
2000 +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
2001 + we also define them for GOFAST because the ones in libgcc2.c have the
2002 + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
2003 + out of libgcc2.c. We can't define these here if not GOFAST because then
2004 + there'd be duplicate copies. */
2007 +float_to_usi (FLO_type arg_a)
2010 + FLO_union_type au;
2013 + unpack_d (&au, &a);
2019 + /* it is a negative number */
2022 + /* get reasonable MAX_USI_INT... */
2024 + return MAX_USI_INT;
2025 + /* it is a number, but a small one */
2026 + if (a.normal_exp < 0)
2028 + if (a.normal_exp > BITS_PER_SI - 1)
2029 + return MAX_USI_INT;
2030 + else if (a.normal_exp > (FRACBITS + NGARDS))
2031 + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
2033 + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
2035 +#endif /* US_SOFTWARE_GOFAST */
2036 +#endif /* L_sf_to_usi || L_df_to_usi */
2038 +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
2040 +negate (FLO_type arg_a)
2043 + FLO_union_type au;
2046 + unpack_d (&au, &a);
2049 + return pack_d (&a);
2051 +#endif /* L_negate_sf || L_negate_df */
2055 +#if defined(L_make_sf)
2057 +__make_fp(fp_class_type class,
2058 + unsigned int sign,
2062 + fp_number_type in;
2066 + in.normal_exp = exp;
2067 + in.fraction.ll = frac;
2068 + return pack_d (&in);
2070 +#endif /* L_make_sf */
2074 +/* This enables one to build an fp library that supports float but not double.
2075 + Otherwise, we would get an undefined reference to __make_dp.
2076 + This is needed for some 8-bit ports that can't handle well values that
2077 + are 8-bytes in size, so we just don't support double for them at all. */
2079 +#if defined(L_sf_to_df)
2081 +sf_to_df (SFtype arg_a)
2083 + fp_number_type in;
2084 + FLO_union_type au;
2087 + unpack_d (&au, &in);
2089 + return __make_dp (in.class, in.sign, in.normal_exp,
2090 + ((UDItype) in.fraction.ll) << F_D_BITOFF);
2092 +#endif /* L_sf_to_df */
2094 +#if defined(L_sf_to_tf) && defined(TMODES)
2096 +sf_to_tf (SFtype arg_a)
2098 + fp_number_type in;
2099 + FLO_union_type au;
2102 + unpack_d (&au, &in);
2104 + return __make_tp (in.class, in.sign, in.normal_exp,
2105 + ((UTItype) in.fraction.ll) << F_T_BITOFF);
2107 +#endif /* L_sf_to_df */
2109 +#endif /* ! FLOAT_ONLY */
2114 +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
2116 +#if defined(L_make_df)
2118 +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
2120 + fp_number_type in;
2124 + in.normal_exp = exp;
2125 + in.fraction.ll = frac;
2126 + return pack_d (&in);
2128 +#endif /* L_make_df */
2130 +#if defined(L_df_to_sf)
2132 +df_to_sf (DFtype arg_a)
2134 + fp_number_type in;
2136 + FLO_union_type au;
2139 + unpack_d (&au, &in);
2141 + sffrac = in.fraction.ll >> F_D_BITOFF;
2143 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2145 + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
2148 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
2150 +#endif /* L_df_to_sf */
2152 +#if defined(L_df_to_tf) && defined(TMODES) \
2153 + && !defined(FLOAT) && !defined(TFLOAT)
2155 +df_to_tf (DFtype arg_a)
2157 + fp_number_type in;
2158 + FLO_union_type au;
2161 + unpack_d (&au, &in);
2163 + return __make_tp (in.class, in.sign, in.normal_exp,
2164 + ((UTItype) in.fraction.ll) << D_T_BITOFF);
2166 +#endif /* L_sf_to_df */
2169 +#if defined(L_make_tf)
2171 +__make_tp(fp_class_type class,
2172 + unsigned int sign,
2176 + fp_number_type in;
2180 + in.normal_exp = exp;
2181 + in.fraction.ll = frac;
2182 + return pack_d (&in);
2184 +#endif /* L_make_tf */
2186 +#if defined(L_tf_to_df)
2188 +tf_to_df (TFtype arg_a)
2190 + fp_number_type in;
2192 + FLO_union_type au;
2195 + unpack_d (&au, &in);
2197 + sffrac = in.fraction.ll >> D_T_BITOFF;
2199 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2201 + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
2204 + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
2206 +#endif /* L_tf_to_df */
2208 +#if defined(L_tf_to_sf)
2210 +tf_to_sf (TFtype arg_a)
2212 + fp_number_type in;
2214 + FLO_union_type au;
2217 + unpack_d (&au, &in);
2219 + sffrac = in.fraction.ll >> F_T_BITOFF;
2221 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2223 + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
2226 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
2228 +#endif /* L_tf_to_sf */
2229 +#endif /* TFLOAT */
2231 +#endif /* ! FLOAT */
2232 +#endif /* !EXTENDED_FLOAT_STUBS */
2233 --- ./gcc/gcc/config/nios2/nios2-fp-bit.c
2234 +++ ./gcc/gcc/config/nios2/nios2-fp-bit.c
2237 +/* This is a software floating point library which can be used
2238 + for targets without hardware floating point.
2239 + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
2240 + Free Software Foundation, Inc.
2242 +This file is free software; you can redistribute it and/or modify it
2243 +under the terms of the GNU General Public License as published by the
2244 +Free Software Foundation; either version 2, or (at your option) any
2247 +In addition to the permissions in the GNU General Public License, the
2248 +Free Software Foundation gives you unlimited permission to link the
2249 +compiled version of this file with other programs, and to distribute
2250 +those programs without any restriction coming from the use of this
2251 +file. (The General Public License restrictions do apply in other
2252 +respects; for example, they cover modification of the file, and
2253 +distribution when not linked into another program.)
2255 +This file is distributed in the hope that it will be useful, but
2256 +WITHOUT ANY WARRANTY; without even the implied warranty of
2257 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2258 +General Public License for more details.
2260 +You should have received a copy of the GNU General Public License
2261 +along with this program; see the file COPYING. If not, write to
2262 +the Free Software Foundation, 59 Temple Place - Suite 330,
2263 +Boston, MA 02111-1307, USA. */
2265 +/* As a special exception, if you link this library with other files,
2266 + some of which are compiled with GCC, to produce an executable,
2267 + this library does not by itself cause the resulting executable
2268 + to be covered by the GNU General Public License.
2269 + This exception does not however invalidate any other reasons why
2270 + the executable file might be covered by the GNU General Public License. */
2272 +/* This implements IEEE 754 format arithmetic, but does not provide a
2273 + mechanism for setting the rounding mode, or for generating or handling
2276 + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
2277 + Wilson, all of Cygnus Support. */
2279 +/* The intended way to use this file is to make two copies, add `#define FLOAT'
2280 + to one copy, then compile both copies and add them to libgcc.a. */
2282 +#include "tconfig.h"
2283 +#include "coretypes.h"
2285 +#include "config/fp-bit.h"
2287 +/* The following macros can be defined to change the behavior of this file:
2288 + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
2289 + defined, then this file implements a `double', aka DFmode, fp library.
2290 + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
2291 + don't include float->double conversion which requires the double library.
2292 + This is useful only for machines which can't support doubles, e.g. some
2294 + CMPtype: Specify the type that floating point compares should return.
2295 + This defaults to SItype, aka int.
2296 + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
2297 + US Software goFast library.
2298 + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
2299 + two integers to the FLO_union_type.
2300 + NO_DENORMALS: Disable handling of denormals.
2301 + NO_NANS: Disable nan and infinity handling
2302 + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
2305 +/* We don't currently support extended floats (long doubles) on machines
2306 + without hardware to deal with them.
2308 + These stubs are just to keep the linker from complaining about unresolved
2309 + references which can be pulled in from libio & libstdc++, even if the
2310 + user isn't using long doubles. However, they may generate an unresolved
2311 + external to abort if abort is not used by the function, and the stubs
2312 + are referenced from within libc, since libgcc goes before and after the
2313 + system library. */
2315 +#ifdef DECLARE_LIBRARY_RENAMES
2316 + DECLARE_LIBRARY_RENAMES
2319 +#ifdef EXTENDED_FLOAT_STUBS
2320 +extern void abort (void);
2321 +void __extendsfxf2 (void) { abort(); }
2322 +void __extenddfxf2 (void) { abort(); }
2323 +void __truncxfdf2 (void) { abort(); }
2324 +void __truncxfsf2 (void) { abort(); }
2325 +void __fixxfsi (void) { abort(); }
2326 +void __floatsixf (void) { abort(); }
2327 +void __addxf3 (void) { abort(); }
2328 +void __subxf3 (void) { abort(); }
2329 +void __mulxf3 (void) { abort(); }
2330 +void __divxf3 (void) { abort(); }
2331 +void __negxf2 (void) { abort(); }
2332 +void __eqxf2 (void) { abort(); }
2333 +void __nexf2 (void) { abort(); }
2334 +void __gtxf2 (void) { abort(); }
2335 +void __gexf2 (void) { abort(); }
2336 +void __lexf2 (void) { abort(); }
2337 +void __ltxf2 (void) { abort(); }
2339 +void __extendsftf2 (void) { abort(); }
2340 +void __extenddftf2 (void) { abort(); }
2341 +void __trunctfdf2 (void) { abort(); }
2342 +void __trunctfsf2 (void) { abort(); }
2343 +void __fixtfsi (void) { abort(); }
2344 +void __floatsitf (void) { abort(); }
2345 +void __addtf3 (void) { abort(); }
2346 +void __subtf3 (void) { abort(); }
2347 +void __multf3 (void) { abort(); }
2348 +void __divtf3 (void) { abort(); }
2349 +void __negtf2 (void) { abort(); }
2350 +void __eqtf2 (void) { abort(); }
2351 +void __netf2 (void) { abort(); }
2352 +void __gttf2 (void) { abort(); }
2353 +void __getf2 (void) { abort(); }
2354 +void __letf2 (void) { abort(); }
2355 +void __lttf2 (void) { abort(); }
2356 +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
2358 +/* IEEE "special" number predicates */
2367 +#if defined L_thenan_sf
2368 +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2369 +#elif defined L_thenan_df
2370 +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2371 +#elif defined L_thenan_tf
2372 +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2373 +#elif defined TFLOAT
2374 +extern const fp_number_type __thenan_tf;
2375 +#elif defined FLOAT
2376 +extern const fp_number_type __thenan_sf;
2378 +extern const fp_number_type __thenan_df;
2382 +static fp_number_type *
2385 + /* Discard the const qualifier... */
2387 + return (fp_number_type *) (& __thenan_tf);
2388 +#elif defined FLOAT
2389 + return (fp_number_type *) (& __thenan_sf);
2391 + return (fp_number_type *) (& __thenan_df);
2397 +isnan ( fp_number_type * x)
2399 + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
2404 +isinf ( fp_number_type * x)
2406 + return x->class == CLASS_INFINITY;
2409 +#endif /* NO_NANS */
2413 +iszero ( fp_number_type * x)
2415 + return x->class == CLASS_ZERO;
2420 +flip_sign ( fp_number_type * x)
2422 + x->sign = !x->sign;
2425 +extern FLO_type pack_d ( fp_number_type * );
2427 +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
2429 +pack_d ( fp_number_type * src)
2431 + FLO_union_type dst;
2432 + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
2433 + int sign = src->sign;
2436 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
2438 + /* We can't represent these values accurately. By using the
2439 + largest possible magnitude, we guarantee that the conversion
2440 + of infinity is at least as big as any finite number. */
2442 + fraction = ((fractype) 1 << FRACBITS) - 1;
2444 + else if (isnan (src))
2447 + if (src->class == CLASS_QNAN || 1)
2449 +#ifdef QUIET_NAN_NEGATED
2450 + fraction |= QUIET_NAN - 1;
2452 + fraction |= QUIET_NAN;
2456 + else if (isinf (src))
2461 + else if (iszero (src))
2466 + else if (fraction == 0)
2472 + if (src->normal_exp < NORMAL_EXPMIN)
2474 +#ifdef NO_DENORMALS
2475 + /* Go straight to a zero representation if denormals are not
2476 + supported. The denormal handling would be harmless but
2477 + isn't unnecessary. */
2480 +#else /* NO_DENORMALS */
2481 + /* This number's exponent is too low to fit into the bits
2482 + available in the number, so we'll store 0 in the exponent and
2483 + shift the fraction to the right to make up for it. */
2485 + int shift = NORMAL_EXPMIN - src->normal_exp;
2489 + if (shift > FRAC_NBITS - NGARDS)
2491 + /* No point shifting, since it's more that 64 out. */
2496 + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
2497 + fraction = (fraction >> shift) | lowbit;
2499 + if ((fraction & GARDMASK) == GARDMSB)
2501 + if ((fraction & (1 << NGARDS)))
2502 + fraction += GARDROUND + 1;
2506 + /* Add to the guards to round up. */
2507 + fraction += GARDROUND;
2509 + /* Perhaps the rounding means we now need to change the
2510 + exponent, because the fraction is no longer denormal. */
2511 + if (fraction >= IMPLICIT_1)
2515 + fraction >>= NGARDS;
2516 +#endif /* NO_DENORMALS */
2518 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
2519 + && src->normal_exp > EXPBIAS)
2526 + exp = src->normal_exp + EXPBIAS;
2527 + if (!ROUND_TOWARDS_ZERO)
2529 + /* IF the gard bits are the all zero, but the first, then we're
2530 + half way between two numbers, choose the one which makes the
2531 + lsb of the answer 0. */
2532 + if ((fraction & GARDMASK) == GARDMSB)
2534 + if (fraction & (1 << NGARDS))
2535 + fraction += GARDROUND + 1;
2539 + /* Add a one to the guards to round up */
2540 + fraction += GARDROUND;
2542 + if (fraction >= IMPLICIT_2)
2548 + fraction >>= NGARDS;
2550 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
2552 + /* Saturate on overflow. */
2554 + fraction = ((fractype) 1 << FRACBITS) - 1;
2559 + /* We previously used bitfields to store the number, but this doesn't
2560 + handle little/big endian systems conveniently, so use shifts and
2562 +#ifdef FLOAT_BIT_ORDER_MISMATCH
2563 + dst.bits.fraction = fraction;
2564 + dst.bits.exp = exp;
2565 + dst.bits.sign = sign;
2567 +# if defined TFLOAT && defined HALFFRACBITS
2569 + halffractype high, low, unity;
2570 + int lowsign, lowexp;
2572 + unity = (halffractype) 1 << HALFFRACBITS;
2574 + /* Set HIGH to the high double's significand, masking out the implicit 1.
2575 + Set LOW to the low double's full significand. */
2576 + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
2577 + low = fraction & (unity * 2 - 1);
2579 + /* Get the initial sign and exponent of the low double. */
2580 + lowexp = exp - HALFFRACBITS - 1;
2583 + /* HIGH should be rounded like a normal double, making |LOW| <=
2584 + 0.5 ULP of HIGH. Assume round-to-nearest. */
2586 + if (low > unity || (low == unity && (high & 1) == 1))
2588 + /* Round HIGH up and adjust LOW to match. */
2590 + if (high == unity)
2592 + /* May make it infinite, but that's OK. */
2596 + low = unity * 2 - low;
2600 + high |= (halffractype) exp << HALFFRACBITS;
2601 + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
2603 + if (exp == EXPMAX || exp == 0 || low == 0)
2607 + while (lowexp > 0 && low < unity)
2615 + halffractype roundmsb, round;
2618 + shift = 1 - lowexp;
2619 + roundmsb = (1 << (shift - 1));
2620 + round = low & ((roundmsb << 1) - 1);
2625 + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
2629 + /* LOW rounds up to the smallest normal number. */
2635 + low |= (halffractype) lowexp << HALFFRACBITS;
2636 + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
2638 + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
2641 + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
2642 + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
2643 + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
2647 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
2650 + qrtrfractype tmp1 = dst.words[0];
2651 + qrtrfractype tmp2 = dst.words[1];
2652 + dst.words[0] = dst.words[3];
2653 + dst.words[1] = dst.words[2];
2654 + dst.words[2] = tmp2;
2655 + dst.words[3] = tmp1;
2659 + halffractype tmp = dst.words[0];
2660 + dst.words[0] = dst.words[1];
2661 + dst.words[1] = tmp;
2670 +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
2672 +unpack_d (FLO_union_type * src, fp_number_type * dst)
2674 + /* We previously used bitfields to store the number, but this doesn't
2675 + handle little/big endian systems conveniently, so use shifts and
2677 + fractype fraction;
2681 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
2682 + FLO_union_type swapped;
2685 + swapped.words[0] = src->words[3];
2686 + swapped.words[1] = src->words[2];
2687 + swapped.words[2] = src->words[1];
2688 + swapped.words[3] = src->words[0];
2690 + swapped.words[0] = src->words[1];
2691 + swapped.words[1] = src->words[0];
2696 +#ifdef FLOAT_BIT_ORDER_MISMATCH
2697 + fraction = src->bits.fraction;
2698 + exp = src->bits.exp;
2699 + sign = src->bits.sign;
2701 +# if defined TFLOAT && defined HALFFRACBITS
2703 + halffractype high, low;
2705 + high = src->value_raw >> HALFSHIFT;
2706 + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
2708 + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
2709 + fraction <<= FRACBITS - HALFFRACBITS;
2710 + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
2711 + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
2713 + if (exp != EXPMAX && exp != 0 && low != 0)
2715 + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
2716 + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
2720 + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
2722 + xlow |= (((halffractype)1) << HALFFRACBITS);
2725 + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
2728 + else if (shift < 0)
2730 + if (sign == lowsign)
2732 + else if (fraction >= xlow)
2736 + /* The high part is a power of two but the full number is lower.
2737 + This code will leave the implicit 1 in FRACTION, but we'd
2738 + have added that below anyway. */
2739 + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
2745 + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
2746 + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
2747 + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
2754 + /* Hmm. Looks like 0 */
2756 +#ifdef NO_DENORMALS
2761 + /* tastes like zero */
2762 + dst->class = CLASS_ZERO;
2766 + /* Zero exponent with nonzero fraction - it's denormalized,
2767 + so there isn't a leading implicit one - we'll shift it so
2769 + dst->normal_exp = exp - EXPBIAS + 1;
2770 + fraction <<= NGARDS;
2772 + dst->class = CLASS_NUMBER;
2774 + while (fraction < IMPLICIT_1)
2777 + dst->normal_exp--;
2780 + dst->fraction.ll = fraction;
2783 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
2785 + /* Huge exponent*/
2786 + if (fraction == 0)
2788 + /* Attached to a zero fraction - means infinity */
2789 + dst->class = CLASS_INFINITY;
2793 + /* Nonzero fraction, means nan */
2794 +#ifdef QUIET_NAN_NEGATED
2795 + if ((fraction & QUIET_NAN) == 0)
2797 + if (fraction & QUIET_NAN)
2800 + dst->class = CLASS_QNAN;
2804 + dst->class = CLASS_SNAN;
2806 + /* Keep the fraction part as the nan number */
2807 + dst->fraction.ll = fraction;
2812 + /* Nothing strange about this number */
2813 + dst->normal_exp = exp - EXPBIAS;
2814 + dst->class = CLASS_NUMBER;
2815 + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
2818 +#endif /* L_unpack_df || L_unpack_sf */
2820 +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
2821 +static fp_number_type *
2822 +_fpadd_parts (fp_number_type * a,
2823 + fp_number_type * b,
2824 + fp_number_type * tmp)
2826 + intfrac tfraction;
2828 + /* Put commonly used fields in local variables. */
2831 + fractype a_fraction;
2832 + fractype b_fraction;
2844 + /* Adding infinities with opposite signs yields a NaN. */
2845 + if (isinf (b) && a->sign != b->sign)
2858 + tmp->sign = a->sign & b->sign;
2868 + /* Got two numbers. shift the smaller and increment the exponent till
2869 + they're the same */
2873 + a_normal_exp = a->normal_exp;
2874 + b_normal_exp = b->normal_exp;
2875 + a_fraction = a->fraction.ll;
2876 + b_fraction = b->fraction.ll;
2878 + diff = a_normal_exp - b_normal_exp;
2882 + if (diff < FRAC_NBITS)
2884 + /* ??? This does shifts one bit at a time. Optimize. */
2885 + while (a_normal_exp > b_normal_exp)
2888 + LSHIFT (b_fraction);
2890 + while (b_normal_exp > a_normal_exp)
2893 + LSHIFT (a_fraction);
2898 + /* Somethings's up.. choose the biggest */
2899 + if (a_normal_exp > b_normal_exp)
2901 + b_normal_exp = a_normal_exp;
2906 + a_normal_exp = b_normal_exp;
2912 + if (a->sign != b->sign)
2916 + tfraction = -a_fraction + b_fraction;
2920 + tfraction = a_fraction - b_fraction;
2922 + if (tfraction >= 0)
2925 + tmp->normal_exp = a_normal_exp;
2926 + tmp->fraction.ll = tfraction;
2931 + tmp->normal_exp = a_normal_exp;
2932 + tmp->fraction.ll = -tfraction;
2934 + /* and renormalize it */
2936 + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
2938 + tmp->fraction.ll <<= 1;
2939 + tmp->normal_exp--;
2944 + tmp->sign = a->sign;
2945 + tmp->normal_exp = a_normal_exp;
2946 + tmp->fraction.ll = a_fraction + b_fraction;
2948 + tmp->class = CLASS_NUMBER;
2949 + /* Now the fraction is added, we have to shift down to renormalize the
2952 + if (tmp->fraction.ll >= IMPLICIT_2)
2954 + LSHIFT (tmp->fraction.ll);
2955 + tmp->normal_exp++;
2962 +add (FLO_type arg_a, FLO_type arg_b)
2966 + fp_number_type tmp;
2967 + fp_number_type *res;
2968 + FLO_union_type au, bu;
2973 + unpack_d (&au, &a);
2974 + unpack_d (&bu, &b);
2976 + res = _fpadd_parts (&a, &b, &tmp);
2978 + return pack_d (res);
2982 +sub (FLO_type arg_a, FLO_type arg_b)
2986 + fp_number_type tmp;
2987 + fp_number_type *res;
2988 + FLO_union_type au, bu;
2993 + unpack_d (&au, &a);
2994 + unpack_d (&bu, &b);
2998 + res = _fpadd_parts (&a, &b, &tmp);
3000 + return pack_d (res);
3002 +#endif /* L_addsub_sf || L_addsub_df */
3004 +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
3005 +static inline __attribute__ ((__always_inline__)) fp_number_type *
3006 +_fpmul_parts ( fp_number_type * a,
3007 + fp_number_type * b,
3008 + fp_number_type * tmp)
3011 + fractype high = 0;
3015 + a->sign = a->sign != b->sign;
3020 + b->sign = a->sign != b->sign;
3027 + a->sign = a->sign != b->sign;
3036 + b->sign = a->sign != b->sign;
3041 + a->sign = a->sign != b->sign;
3046 + b->sign = a->sign != b->sign;
3050 + /* Calculate the mantissa by multiplying both numbers to get a
3051 + twice-as-wide number. */
3053 +#if defined(NO_DI_MODE) || defined(TFLOAT)
3055 + fractype x = a->fraction.ll;
3056 + fractype ylow = b->fraction.ll;
3057 + fractype yhigh = 0;
3060 + /* ??? This does multiplies one bit at a time. Optimize. */
3061 + for (bit = 0; bit < FRAC_NBITS; bit++)
3067 + carry = (low += ylow) < ylow;
3068 + high += yhigh + carry;
3071 + if (ylow & FRACHIGH)
3079 +#elif defined(FLOAT)
3080 + /* Multiplying two USIs to get a UDI, we're safe. */
3082 + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
3084 + high = answer >> BITS_PER_SI;
3088 + /* fractype is DImode, but we need the result to be twice as wide.
3089 + Assuming a widening multiply from DImode to TImode is not
3090 + available, build one by hand. */
3092 + USItype nl = a->fraction.ll;
3093 + USItype nh = a->fraction.ll >> BITS_PER_SI;
3094 + USItype ml = b->fraction.ll;
3095 + USItype mh = b->fraction.ll >> BITS_PER_SI;
3096 + UDItype pp_ll = (UDItype) ml * nl;
3097 + UDItype pp_hl = (UDItype) mh * nl;
3098 + UDItype pp_lh = (UDItype) ml * nh;
3099 + UDItype pp_hh = (UDItype) mh * nh;
3102 + UDItype ps_hh__ = pp_hl + pp_lh;
3103 + if (ps_hh__ < pp_hl)
3104 + res2 += (UDItype)1 << BITS_PER_SI;
3105 + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
3106 + res0 = pp_ll + pp_hl;
3109 + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
3116 + tmp->normal_exp = a->normal_exp + b->normal_exp
3117 + + FRAC_NBITS - (FRACBITS + NGARDS);
3118 + tmp->sign = a->sign != b->sign;
3119 + while (high >= IMPLICIT_2)
3121 + tmp->normal_exp++;
3129 + while (high < IMPLICIT_1)
3131 + tmp->normal_exp--;
3134 + if (low & FRACHIGH)
3138 + /* rounding is tricky. if we only round if it won't make us round later. */
3140 + if (low & FRACHIGH2)
3142 + if (((high & GARDMASK) != GARDMSB)
3143 + && (((high + 1) & GARDMASK) == GARDMSB))
3145 + /* don't round, it gets done again later. */
3153 + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
3155 + if (high & (1 << NGARDS))
3157 + /* half way, so round to even */
3158 + high += GARDROUND + 1;
3162 + /* but we really weren't half way */
3163 + high += GARDROUND + 1;
3166 + tmp->fraction.ll = high;
3167 + tmp->class = CLASS_NUMBER;
3172 +multiply (FLO_type arg_a, FLO_type arg_b)
3176 + fp_number_type tmp;
3177 + fp_number_type *res;
3178 + FLO_union_type au, bu;
3183 + unpack_d (&au, &a);
3184 + unpack_d (&bu, &b);
3186 + res = _fpmul_parts (&a, &b, &tmp);
3188 + return pack_d (res);
3190 +#endif /* L_mul_sf || L_mul_df */
3192 +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
3193 +static inline __attribute__ ((__always_inline__)) fp_number_type *
3194 +_fpdiv_parts (fp_number_type * a,
3195 + fp_number_type * b)
3198 + fractype numerator;
3199 + fractype denominator;
3200 + fractype quotient;
3211 + a->sign = a->sign ^ b->sign;
3213 + if (isinf (a) || iszero (a))
3215 + if (a->class == b->class)
3222 + a->fraction.ll = 0;
3223 + a->normal_exp = 0;
3228 + a->class = CLASS_INFINITY;
3232 + /* Calculate the mantissa by multiplying both 64bit numbers to get a
3236 + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
3239 + a->normal_exp = a->normal_exp - b->normal_exp;
3240 + numerator = a->fraction.ll;
3241 + denominator = b->fraction.ll;
3243 + if (numerator < denominator)
3245 + /* Fraction will be less than 1.0 */
3251 + /* ??? Does divide one bit at a time. Optimize. */
3254 + if (numerator >= denominator)
3257 + numerator -= denominator;
3263 + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
3265 + if (quotient & (1 << NGARDS))
3267 + /* half way, so round to even */
3268 + quotient += GARDROUND + 1;
3270 + else if (numerator)
3272 + /* but we really weren't half way, more bits exist */
3273 + quotient += GARDROUND + 1;
3277 + a->fraction.ll = quotient;
3283 +divide (FLO_type arg_a, FLO_type arg_b)
3287 + fp_number_type *res;
3288 + FLO_union_type au, bu;
3293 + unpack_d (&au, &a);
3294 + unpack_d (&bu, &b);
3296 + res = _fpdiv_parts (&a, &b);
3298 + return pack_d (res);
3300 +#endif /* L_div_sf || L_div_df */
3302 +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
3303 + || defined(L_fpcmp_parts_tf)
3304 +/* according to the demo, fpcmp returns a comparison with 0... thus
3311 +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
3314 + /* either nan -> unordered. Must be checked outside of this routine. */
3315 + if (isnan (a) && isnan (b))
3317 + return 1; /* still unordered! */
3321 + if (isnan (a) || isnan (b))
3323 + return 1; /* how to indicate unordered compare? */
3325 + if (isinf (a) && isinf (b))
3327 + /* +inf > -inf, but +inf != +inf */
3328 + /* b \a| +inf(0)| -inf(1)
3329 + ______\+--------+--------
3330 + +inf(0)| a==b(0)| a<b(-1)
3331 + -------+--------+--------
3332 + -inf(1)| a>b(1) | a==b(0)
3333 + -------+--------+--------
3334 + So since unordered must be nonzero, just line up the columns...
3336 + return b->sign - a->sign;
3338 + /* but not both... */
3341 + return a->sign ? -1 : 1;
3345 + return b->sign ? 1 : -1;
3347 + if (iszero (a) && iszero (b))
3353 + return b->sign ? 1 : -1;
3357 + return a->sign ? -1 : 1;
3359 + /* now both are "normal". */
3360 + if (a->sign != b->sign)
3362 + /* opposite signs */
3363 + return a->sign ? -1 : 1;
3365 + /* same sign; exponents? */
3366 + if (a->normal_exp > b->normal_exp)
3368 + return a->sign ? -1 : 1;
3370 + if (a->normal_exp < b->normal_exp)
3372 + return a->sign ? 1 : -1;
3374 + /* same exponents; check size. */
3375 + if (a->fraction.ll > b->fraction.ll)
3377 + return a->sign ? -1 : 1;
3379 + if (a->fraction.ll < b->fraction.ll)
3381 + return a->sign ? 1 : -1;
3383 + /* after all that, they're equal. */
3388 +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
3390 +compare (FLO_type arg_a, FLO_type arg_b)
3394 + FLO_union_type au, bu;
3399 + unpack_d (&au, &a);
3400 + unpack_d (&bu, &b);
3402 + return __fpcmp_parts (&a, &b);
3404 +#endif /* L_compare_sf || L_compare_df */
3406 +#ifndef US_SOFTWARE_GOFAST
3408 +/* These should be optimized for their specific tasks someday. */
3410 +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
3412 +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
3416 + FLO_union_type au, bu;
3421 + unpack_d (&au, &a);
3422 + unpack_d (&bu, &b);
3424 + if (isnan (&a) || isnan (&b))
3425 + return 1; /* false, truth == 0 */
3427 + return __fpcmp_parts (&a, &b) ;
3429 +#endif /* L_eq_sf || L_eq_df */
3431 +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
3433 +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
3437 + FLO_union_type au, bu;
3442 + unpack_d (&au, &a);
3443 + unpack_d (&bu, &b);
3445 + if (isnan (&a) || isnan (&b))
3446 + return 1; /* true, truth != 0 */
3448 + return __fpcmp_parts (&a, &b) ;
3450 +#endif /* L_ne_sf || L_ne_df */
3452 +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
3454 +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
3458 + FLO_union_type au, bu;
3463 + unpack_d (&au, &a);
3464 + unpack_d (&bu, &b);
3466 + if (isnan (&a) || isnan (&b))
3467 + return -1; /* false, truth > 0 */
3469 + return __fpcmp_parts (&a, &b);
3471 +#endif /* L_gt_sf || L_gt_df */
3473 +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
3475 +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
3479 + FLO_union_type au, bu;
3484 + unpack_d (&au, &a);
3485 + unpack_d (&bu, &b);
3487 + if (isnan (&a) || isnan (&b))
3488 + return -1; /* false, truth >= 0 */
3489 + return __fpcmp_parts (&a, &b) ;
3491 +#endif /* L_ge_sf || L_ge_df */
3493 +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
3495 +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
3499 + FLO_union_type au, bu;
3504 + unpack_d (&au, &a);
3505 + unpack_d (&bu, &b);
3507 + if (isnan (&a) || isnan (&b))
3508 + return 1; /* false, truth < 0 */
3510 + return __fpcmp_parts (&a, &b);
3512 +#endif /* L_lt_sf || L_lt_df */
3514 +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
3516 +_le_f2 (FLO_type arg_a, FLO_type arg_b)
3520 + FLO_union_type au, bu;
3525 + unpack_d (&au, &a);
3526 + unpack_d (&bu, &b);
3528 + if (isnan (&a) || isnan (&b))
3529 + return 1; /* false, truth <= 0 */
3531 + return __fpcmp_parts (&a, &b) ;
3533 +#endif /* L_le_sf || L_le_df */
3535 +#endif /* ! US_SOFTWARE_GOFAST */
3537 +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
3539 +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
3543 + FLO_union_type au, bu;
3548 + unpack_d (&au, &a);
3549 + unpack_d (&bu, &b);
3551 + return (isnan (&a) || isnan (&b));
3553 +#endif /* L_unord_sf || L_unord_df */
3555 +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
3557 +si_to_float (SItype arg_a)
3559 + fp_number_type in;
3561 + in.class = CLASS_NUMBER;
3562 + in.sign = arg_a < 0;
3565 + in.class = CLASS_ZERO;
3569 + in.normal_exp = FRACBITS + NGARDS;
3572 + /* Special case for minint, since there is no +ve integer
3573 + representation for it */
3574 + if (arg_a == (- MAX_SI_INT - 1))
3576 + return (FLO_type)(- MAX_SI_INT - 1);
3578 + in.fraction.ll = (-arg_a);
3581 + in.fraction.ll = arg_a;
3583 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
3585 + in.fraction.ll <<= 1;
3586 + in.normal_exp -= 1;
3589 + return pack_d (&in);
3591 +#endif /* L_si_to_sf || L_si_to_df */
3593 +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
3595 +usi_to_float (USItype arg_a)
3597 + fp_number_type in;
3602 + in.class = CLASS_ZERO;
3606 + in.class = CLASS_NUMBER;
3607 + in.normal_exp = FRACBITS + NGARDS;
3608 + in.fraction.ll = arg_a;
3610 + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
3612 + in.fraction.ll >>= 1;
3613 + in.normal_exp += 1;
3615 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
3617 + in.fraction.ll <<= 1;
3618 + in.normal_exp -= 1;
3621 + return pack_d (&in);
3625 +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
3627 +float_to_si (FLO_type arg_a)
3631 + FLO_union_type au;
3634 + unpack_d (&au, &a);
3640 + /* get reasonable MAX_SI_INT... */
3642 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
3643 + /* it is a number, but a small one */
3644 + if (a.normal_exp < 0)
3646 + if (a.normal_exp > BITS_PER_SI - 2)
3647 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
3648 + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
3649 + return a.sign ? (-tmp) : (tmp);
3651 +#endif /* L_sf_to_si || L_df_to_si */
3653 +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
3654 +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
3655 +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
3656 + we also define them for GOFAST because the ones in libgcc2.c have the
3657 + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
3658 + out of libgcc2.c. We can't define these here if not GOFAST because then
3659 + there'd be duplicate copies. */
3662 +float_to_usi (FLO_type arg_a)
3665 + FLO_union_type au;
3668 + unpack_d (&au, &a);
3674 + /* it is a negative number */
3677 + /* get reasonable MAX_USI_INT... */
3679 + return MAX_USI_INT;
3680 + /* it is a number, but a small one */
3681 + if (a.normal_exp < 0)
3683 + if (a.normal_exp > BITS_PER_SI - 1)
3684 + return MAX_USI_INT;
3685 + else if (a.normal_exp > (FRACBITS + NGARDS))
3686 + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
3688 + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
3690 +#endif /* US_SOFTWARE_GOFAST */
3691 +#endif /* L_sf_to_usi || L_df_to_usi */
3693 +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
3695 +negate (FLO_type arg_a)
3698 + FLO_union_type au;
3701 + unpack_d (&au, &a);
3704 + return pack_d (&a);
3706 +#endif /* L_negate_sf || L_negate_df */
3710 +#if defined(L_make_sf)
3712 +__make_fp(fp_class_type class,
3713 + unsigned int sign,
3717 + fp_number_type in;
3721 + in.normal_exp = exp;
3722 + in.fraction.ll = frac;
3723 + return pack_d (&in);
3725 +#endif /* L_make_sf */
3729 +/* This enables one to build an fp library that supports float but not double.
3730 + Otherwise, we would get an undefined reference to __make_dp.
3731 + This is needed for some 8-bit ports that can't handle well values that
3732 + are 8-bytes in size, so we just don't support double for them at all. */
3734 +#if defined(L_sf_to_df)
3736 +sf_to_df (SFtype arg_a)
3738 + fp_number_type in;
3739 + FLO_union_type au;
3742 + unpack_d (&au, &in);
3744 + return __make_dp (in.class, in.sign, in.normal_exp,
3745 + ((UDItype) in.fraction.ll) << F_D_BITOFF);
3747 +#endif /* L_sf_to_df */
3749 +#if defined(L_sf_to_tf) && defined(TMODES)
3751 +sf_to_tf (SFtype arg_a)
3753 + fp_number_type in;
3754 + FLO_union_type au;
3757 + unpack_d (&au, &in);
3759 + return __make_tp (in.class, in.sign, in.normal_exp,
3760 + ((UTItype) in.fraction.ll) << F_T_BITOFF);
3762 +#endif /* L_sf_to_df */
3764 +#endif /* ! FLOAT_ONLY */
3769 +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
3771 +#if defined(L_make_df)
3773 +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
3775 + fp_number_type in;
3779 + in.normal_exp = exp;
3780 + in.fraction.ll = frac;
3781 + return pack_d (&in);
3783 +#endif /* L_make_df */
3785 +#if defined(L_df_to_sf)
3787 +df_to_sf (DFtype arg_a)
3789 + fp_number_type in;
3791 + FLO_union_type au;
3794 + unpack_d (&au, &in);
3796 + sffrac = in.fraction.ll >> F_D_BITOFF;
3798 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3800 + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
3803 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
3805 +#endif /* L_df_to_sf */
3807 +#if defined(L_df_to_tf) && defined(TMODES) \
3808 + && !defined(FLOAT) && !defined(TFLOAT)
3810 +df_to_tf (DFtype arg_a)
3812 + fp_number_type in;
3813 + FLO_union_type au;
3816 + unpack_d (&au, &in);
3818 + return __make_tp (in.class, in.sign, in.normal_exp,
3819 + ((UTItype) in.fraction.ll) << D_T_BITOFF);
3821 +#endif /* L_sf_to_df */
3824 +#if defined(L_make_tf)
3826 +__make_tp(fp_class_type class,
3827 + unsigned int sign,
3831 + fp_number_type in;
3835 + in.normal_exp = exp;
3836 + in.fraction.ll = frac;
3837 + return pack_d (&in);
3839 +#endif /* L_make_tf */
3841 +#if defined(L_tf_to_df)
3843 +tf_to_df (TFtype arg_a)
3845 + fp_number_type in;
3847 + FLO_union_type au;
3850 + unpack_d (&au, &in);
3852 + sffrac = in.fraction.ll >> D_T_BITOFF;
3854 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3856 + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
3859 + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
3861 +#endif /* L_tf_to_df */
3863 +#if defined(L_tf_to_sf)
3865 +tf_to_sf (TFtype arg_a)
3867 + fp_number_type in;
3869 + FLO_union_type au;
3872 + unpack_d (&au, &in);
3874 + sffrac = in.fraction.ll >> F_T_BITOFF;
3876 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3878 + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
3881 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
3883 +#endif /* L_tf_to_sf */
3884 +#endif /* TFLOAT */
3886 +#endif /* ! FLOAT */
3887 +#endif /* !EXTENDED_FLOAT_STUBS */
3888 --- ./gcc/gcc/libgcc2.c
3889 +++ ./gcc/gcc/libgcc2.c
3891 +/* More subroutines needed by GCC output code on some machines. */
3892 +/* Compile this one with gcc. */
3893 +/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3894 + 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3896 +This file is part of GCC.
3898 +GCC is free software; you can redistribute it and/or modify it under
3899 +the terms of the GNU General Public License as published by the Free
3900 +Software Foundation; either version 2, or (at your option) any later
3903 +In addition to the permissions in the GNU General Public License, the
3904 +Free Software Foundation gives you unlimited permission to link the
3905 +compiled version of this file into combinations with other programs,
3906 +and to distribute those combinations without any restriction coming
3907 +from the use of this file. (The General Public License restrictions
3908 +do apply in other respects; for example, they cover modification of
3909 +the file, and distribution when not linked into a combine
3912 +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
3913 +WARRANTY; without even the implied warranty of MERCHANTABILITY or
3914 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3917 +You should have received a copy of the GNU General Public License
3918 +along with GCC; see the file COPYING. If not, write to the Free
3919 +Software Foundation, 59 Temple Place - Suite 330, Boston, MA
3920 +02111-1307, USA. */
3923 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
3924 + supposedly valid even though this is a "target" file. */
3925 +#include "auto-host.h"
3927 +/* It is incorrect to include config.h here, because this file is being
3928 + compiled for the target, and hence definitions concerning only the host
3930 +#include "tconfig.h"
3931 +#include "tsystem.h"
3932 +#include "coretypes.h"
3935 +/* Don't use `fancy_abort' here even if config.h says to use it. */
3940 +#ifdef HAVE_GAS_HIDDEN
3941 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
3943 +#define ATTRIBUTE_HIDDEN
3946 +#include "libgcc2.h"
3948 +#ifdef DECLARE_LIBRARY_RENAMES
3949 + DECLARE_LIBRARY_RENAMES
3952 +#if defined (L_negdi2)
3954 +__negdi2 (DWtype u)
3956 + const DWunion uu = {.ll = u};
3957 + const DWunion w = { {.low = -uu.s.low,
3958 + .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
3966 +__addvsi3 (Wtype a, Wtype b)
3968 + const Wtype w = a + b;
3970 + if (b >= 0 ? w < a : w > a)
3979 +__addvdi3 (DWtype a, DWtype b)
3981 + const DWtype w = a + b;
3983 + if (b >= 0 ? w < a : w > a)
3992 +__subvsi3 (Wtype a, Wtype b)
3994 + const DWtype w = a - b;
3996 + if (b >= 0 ? w > a : w < a)
4005 +__subvdi3 (DWtype a, DWtype b)
4007 + const DWtype w = a - b;
4009 + if (b >= 0 ? w > a : w < a)
4017 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
4019 +__mulvsi3 (Wtype a, Wtype b)
4021 + const DWtype w = (DWtype) a * (DWtype) b;
4023 + if (((a >= 0) == (b >= 0))
4024 + ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1)
4025 + : (UDWtype) w < (UDWtype) ((DWtype) -1 << (WORD_SIZE - 1)))
4034 +__negvsi2 (Wtype a)
4036 + const Wtype w = -a;
4038 + if (a >= 0 ? w > 0 : w < 0)
4047 +__negvdi2 (DWtype a)
4049 + const DWtype w = -a;
4051 + if (a >= 0 ? w > 0 : w < 0)
4060 +__absvsi2 (Wtype a)
4066 + w = __negvsi2 (a);
4080 +__absvdi2 (DWtype a)
4086 + w = __negvdi2 (a);
4099 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
4101 +__mulvdi3 (DWtype u, DWtype v)
4103 + /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
4104 + but the checked multiplication needs only two. */
4105 + const DWunion uu = {.ll = u};
4106 + const DWunion vv = {.ll = v};
4108 + if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
4110 + /* u fits in a single Wtype. */
4111 + if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
4113 + /* v fits in a single Wtype as well. */
4114 + /* A single multiplication. No overflow risk. */
4115 + return (DWtype) uu.s.low * (DWtype) vv.s.low;
4119 + /* Two multiplications. */
4120 + DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
4121 + * (UDWtype) (UWtype) vv.s.low};
4122 + DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
4123 + * (UDWtype) (UWtype) vv.s.high};
4125 + if (vv.s.high < 0)
4126 + w1.s.high -= uu.s.low;
4129 + w1.ll += (UWtype) w0.s.high;
4130 + if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
4132 + w0.s.high = w1.s.low;
4139 + if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
4141 + /* v fits into a single Wtype. */
4142 + /* Two multiplications. */
4143 + DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
4144 + * (UDWtype) (UWtype) vv.s.low};
4145 + DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
4146 + * (UDWtype) (UWtype) vv.s.low};
4148 + if (uu.s.high < 0)
4149 + w1.s.high -= vv.s.low;
4152 + w1.ll += (UWtype) w0.s.high;
4153 + if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
4155 + w0.s.high = w1.s.low;
4161 + /* A few sign checks and a single multiplication. */
4162 + if (uu.s.high >= 0)
4164 + if (vv.s.high >= 0)
4166 + if (uu.s.high == 0 && vv.s.high == 0)
4168 + const DWtype w = (UDWtype) (UWtype) uu.s.low
4169 + * (UDWtype) (UWtype) vv.s.low;
4170 + if (__builtin_expect (w >= 0, 1))
4176 + if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
4178 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4179 + * (UDWtype) (UWtype) vv.s.low};
4181 + ww.s.high -= uu.s.low;
4182 + if (__builtin_expect (ww.s.high < 0, 1))
4189 + if (vv.s.high >= 0)
4191 + if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
4193 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4194 + * (UDWtype) (UWtype) vv.s.low};
4196 + ww.s.high -= vv.s.low;
4197 + if (__builtin_expect (ww.s.high < 0, 1))
4203 + if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
4205 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4206 + * (UDWtype) (UWtype) vv.s.low};
4208 + ww.s.high -= uu.s.low;
4209 + ww.s.high -= vv.s.low;
4210 + if (__builtin_expect (ww.s.high >= 0, 1))
4224 +/* Unless shift functions are defined with full ANSI prototypes,
4225 + parameter b will be promoted to int if word_type is smaller than an int. */
4228 +__lshrdi3 (DWtype u, word_type b)
4233 + const DWunion uu = {.ll = u};
4234 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4240 + w.s.low = (UWtype) uu.s.high >> -bm;
4244 + const UWtype carries = (UWtype) uu.s.high << bm;
4246 + w.s.high = (UWtype) uu.s.high >> b;
4247 + w.s.low = ((UWtype) uu.s.low >> b) | carries;
4256 +__ashldi3 (DWtype u, word_type b)
4261 + const DWunion uu = {.ll = u};
4262 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4268 + w.s.high = (UWtype) uu.s.low << -bm;
4272 + const UWtype carries = (UWtype) uu.s.low >> bm;
4274 + w.s.low = (UWtype) uu.s.low << b;
4275 + w.s.high = ((UWtype) uu.s.high << b) | carries;
4284 +__ashrdi3 (DWtype u, word_type b)
4289 + const DWunion uu = {.ll = u};
4290 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4295 + /* w.s.high = 1..1 or 0..0 */
4296 + w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
4297 + w.s.low = uu.s.high >> -bm;
4301 + const UWtype carries = (UWtype) uu.s.high << bm;
4303 + w.s.high = uu.s.high >> b;
4304 + w.s.low = ((UWtype) uu.s.low >> b) | carries;
4313 +extern int __ffsSI2 (UWtype u);
4315 +__ffsSI2 (UWtype u)
4322 + count_trailing_zeros (count, u);
4329 +extern int __ffsDI2 (DWtype u);
4331 +__ffsDI2 (DWtype u)
4333 + const DWunion uu = {.ll = u};
4334 + UWtype word, count, add;
4336 + if (uu.s.low != 0)
4337 + word = uu.s.low, add = 0;
4338 + else if (uu.s.high != 0)
4339 + word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
4343 + count_trailing_zeros (count, word);
4344 + return count + add + 1;
4350 +__muldi3 (DWtype u, DWtype v)
4352 + const DWunion uu = {.ll = u};
4353 + const DWunion vv = {.ll = v};
4354 + DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
4356 + w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
4357 + + (UWtype) uu.s.high * (UWtype) vv.s.low);
4363 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4364 + defined (L_umoddi3) || defined (L_moddi3))
4365 +#if defined (sdiv_qrnnd)
4366 +#define L_udiv_w_sdiv
4370 +#ifdef L_udiv_w_sdiv
4371 +#if defined (sdiv_qrnnd)
4372 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4373 + defined (L_umoddi3) || defined (L_moddi3))
4374 +static inline __attribute__ ((__always_inline__))
4377 +__udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
4380 + UWtype c0, c1, b1;
4382 + if ((Wtype) d >= 0)
4384 + if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
4386 + /* dividend, divisor, and quotient are nonnegative */
4387 + sdiv_qrnnd (q, r, a1, a0, d);
4391 + /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
4392 + sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
4393 + /* Divide (c1*2^32 + c0) by d */
4394 + sdiv_qrnnd (q, r, c1, c0, d);
4395 + /* Add 2^31 to quotient */
4396 + q += (UWtype) 1 << (W_TYPE_SIZE - 1);
4401 + b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
4402 + c1 = a1 >> 1; /* A/2 */
4403 + c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
4405 + if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
4407 + sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
4409 + r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
4414 + else if (q - r <= d)
4426 + else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
4428 + c1 = (b1 - 1) - c1;
4429 + c0 = ~c0; /* logical NOT */
4431 + sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
4433 + q = ~q; /* (A/2)/b1 */
4436 + r = 2*r + (a0 & 1); /* A/(2*b1) */
4442 + else if (q - r <= d)
4454 + else /* Implies c1 = b1 */
4455 + { /* Hence a1 = d - 1 = 2*b1 - 1 */
4473 +/* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
4475 +__udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
4476 + UWtype a1 __attribute__ ((__unused__)),
4477 + UWtype a0 __attribute__ ((__unused__)),
4478 + UWtype d __attribute__ ((__unused__)))
4485 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4486 + defined (L_umoddi3) || defined (L_moddi3))
4487 +#define L_udivmoddi4
4491 +const UQItype __clz_tab[] =
4493 + 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,
4494 + 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,
4495 + 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,
4496 + 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,
4497 + 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,
4498 + 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,
4499 + 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,
4500 + 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,
4506 +extern int __clzSI2 (UWtype x);
4508 +__clzSI2 (UWtype x)
4512 + count_leading_zeros (ret, x);
4520 +extern int __clzDI2 (UDWtype x);
4522 +__clzDI2 (UDWtype x)
4524 + const DWunion uu = {.ll = x};
4529 + word = uu.s.high, add = 0;
4531 + word = uu.s.low, add = W_TYPE_SIZE;
4533 + count_leading_zeros (ret, word);
4540 +extern int __ctzSI2 (UWtype x);
4542 +__ctzSI2 (UWtype x)
4546 + count_trailing_zeros (ret, x);
4554 +extern int __ctzDI2 (UDWtype x);
4556 +__ctzDI2 (UDWtype x)
4558 + const DWunion uu = {.ll = x};
4563 + word = uu.s.low, add = 0;
4565 + word = uu.s.high, add = W_TYPE_SIZE;
4567 + count_trailing_zeros (ret, word);
4572 +#if (defined (L_popcountsi2) || defined (L_popcountdi2) \
4573 + || defined (L_popcount_tab))
4574 +extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
4577 +#ifdef L_popcount_tab
4578 +const UQItype __popcount_tab[] =
4580 + 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,
4581 + 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,
4582 + 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,
4583 + 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,
4584 + 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,
4585 + 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,
4586 + 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,
4587 + 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,
4591 +#ifdef L_popcountsi2
4593 +extern int __popcountSI2 (UWtype x);
4595 +__popcountSI2 (UWtype x)
4597 + UWtype i, ret = 0;
4599 + for (i = 0; i < W_TYPE_SIZE; i += 8)
4600 + ret += __popcount_tab[(x >> i) & 0xff];
4606 +#ifdef L_popcountdi2
4608 +extern int __popcountDI2 (UDWtype x);
4610 +__popcountDI2 (UDWtype x)
4612 + UWtype i, ret = 0;
4614 + for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
4615 + ret += __popcount_tab[(x >> i) & 0xff];
4623 +extern int __paritySI2 (UWtype x);
4625 +__paritySI2 (UWtype x)
4627 +#if W_TYPE_SIZE > 64
4628 +# error "fill out the table"
4630 +#if W_TYPE_SIZE > 32
4633 +#if W_TYPE_SIZE > 16
4639 + return (0x6996 >> x) & 1;
4645 +extern int __parityDI2 (UDWtype x);
4647 +__parityDI2 (UDWtype x)
4649 + const DWunion uu = {.ll = x};
4650 + UWtype nx = uu.s.low ^ uu.s.high;
4652 +#if W_TYPE_SIZE > 64
4653 +# error "fill out the table"
4655 +#if W_TYPE_SIZE > 32
4658 +#if W_TYPE_SIZE > 16
4664 + return (0x6996 >> nx) & 1;
4668 +#ifdef L_udivmoddi4
4670 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4671 + defined (L_umoddi3) || defined (L_moddi3))
4672 +static inline __attribute__ ((__always_inline__))
4675 +__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
4677 + const DWunion nn = {.ll = n};
4678 + const DWunion dd = {.ll = d};
4680 + UWtype d0, d1, n0, n1, n2;
4689 +#if !UDIV_NEEDS_NORMALIZATION
4694 + /* 0q = nn / 0D */
4696 + udiv_qrnnd (q0, n0, n1, n0, d0);
4699 + /* Remainder in n0. */
4703 + /* qq = NN / 0d */
4706 + d0 = 1 / d0; /* Divide intentionally by zero. */
4708 + udiv_qrnnd (q1, n1, 0, n1, d0);
4709 + udiv_qrnnd (q0, n0, n1, n0, d0);
4711 + /* Remainder in n0. */
4722 +#else /* UDIV_NEEDS_NORMALIZATION */
4728 + /* 0q = nn / 0D */
4730 + count_leading_zeros (bm, d0);
4734 + /* Normalize, i.e. make the most significant bit of the
4735 + denominator set. */
4738 + n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
4742 + udiv_qrnnd (q0, n0, n1, n0, d0);
4745 + /* Remainder in n0 >> bm. */
4749 + /* qq = NN / 0d */
4752 + d0 = 1 / d0; /* Divide intentionally by zero. */
4754 + count_leading_zeros (bm, d0);
4758 + /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
4759 + conclude (the most significant bit of n1 is set) /\ (the
4760 + leading quotient digit q1 = 1).
4762 + This special case is necessary, not an optimization.
4763 + (Shifts counts of W_TYPE_SIZE are undefined.) */
4772 + b = W_TYPE_SIZE - bm;
4776 + n1 = (n1 << bm) | (n0 >> b);
4779 + udiv_qrnnd (q1, n1, n2, n1, d0);
4784 + udiv_qrnnd (q0, n0, n1, n0, d0);
4786 + /* Remainder in n0 >> bm. */
4791 + rr.s.low = n0 >> bm;
4796 +#endif /* UDIV_NEEDS_NORMALIZATION */
4802 + /* 00 = nn / DD */
4807 + /* Remainder in n1n0. */
4817 + /* 0q = NN / dd */
4819 + count_leading_zeros (bm, d1);
4822 + /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
4823 + conclude (the most significant bit of n1 is set) /\ (the
4824 + quotient digit q0 = 0 or 1).
4826 + This special case is necessary, not an optimization. */
4828 + /* The condition on the next line takes advantage of that
4829 + n1 >= d1 (true due to program flow). */
4830 + if (n1 > d1 || n0 >= d0)
4833 + sub_ddmmss (n1, n0, n1, n0, d1, d0);
4852 + b = W_TYPE_SIZE - bm;
4854 + d1 = (d1 << bm) | (d0 >> b);
4857 + n1 = (n1 << bm) | (n0 >> b);
4860 + udiv_qrnnd (q0, n1, n2, n1, d1);
4861 + umul_ppmm (m1, m0, q0, d0);
4863 + if (m1 > n1 || (m1 == n1 && m0 > n0))
4866 + sub_ddmmss (m1, m0, m1, m0, d1, d0);
4871 + /* Remainder in (n1n0 - m1m0) >> bm. */
4874 + sub_ddmmss (n1, n0, n1, n0, m1, m0);
4875 + rr.s.low = (n1 << b) | (n0 >> bm);
4876 + rr.s.high = n1 >> bm;
4883 + const DWunion ww = {{.low = q0, .high = q1}};
4890 +__divdi3 (DWtype u, DWtype v)
4893 + DWunion uu = {.ll = u};
4894 + DWunion vv = {.ll = v};
4897 + if (uu.s.high < 0)
4900 + if (vv.s.high < 0)
4904 + w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
4914 +__moddi3 (DWtype u, DWtype v)
4917 + DWunion uu = {.ll = u};
4918 + DWunion vv = {.ll = v};
4921 + if (uu.s.high < 0)
4924 + if (vv.s.high < 0)
4927 + (void) __udivmoddi4 (uu.ll, vv.ll, &w);
4937 +__umoddi3 (UDWtype u, UDWtype v)
4941 + (void) __udivmoddi4 (u, v, &w);
4949 +__udivdi3 (UDWtype n, UDWtype d)
4951 + return __udivmoddi4 (n, d, (UDWtype *) 0);
4957 +__cmpdi2 (DWtype a, DWtype b)
4959 + const DWunion au = {.ll = a};
4960 + const DWunion bu = {.ll = b};
4962 + if (au.s.high < bu.s.high)
4964 + else if (au.s.high > bu.s.high)
4966 + if ((UWtype) au.s.low < (UWtype) bu.s.low)
4968 + else if ((UWtype) au.s.low > (UWtype) bu.s.low)
4976 +__ucmpdi2 (DWtype a, DWtype b)
4978 + const DWunion au = {.ll = a};
4979 + const DWunion bu = {.ll = b};
4981 + if ((UWtype) au.s.high < (UWtype) bu.s.high)
4983 + else if ((UWtype) au.s.high > (UWtype) bu.s.high)
4985 + if ((UWtype) au.s.low < (UWtype) bu.s.low)
4987 + else if ((UWtype) au.s.low > (UWtype) bu.s.low)
4993 +#if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
4994 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
4995 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
4998 +__fixunstfDI (TFtype a)
5003 + /* Compute high word of result, as a flonum. */
5004 + const TFtype b = (a / HIGH_WORD_COEFF);
5005 + /* Convert that to fixed (but not to DWtype!),
5006 + and shift it into the high word. */
5007 + UDWtype v = (UWtype) b;
5009 + /* Remove high part from the TFtype, leaving the low part as flonum. */
5011 + /* Convert that to fixed (but not to DWtype!) and add it in.
5012 + Sometimes A comes out negative. This is significant, since
5013 + A has more bits than a long int does. */
5015 + v -= (UWtype) (- a);
5022 +#if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
5024 +__fixtfdi (TFtype a)
5027 + return - __fixunstfDI (-a);
5028 + return __fixunstfDI (a);
5032 +#if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
5033 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5034 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5037 +__fixunsxfDI (XFtype a)
5042 + /* Compute high word of result, as a flonum. */
5043 + const XFtype b = (a / HIGH_WORD_COEFF);
5044 + /* Convert that to fixed (but not to DWtype!),
5045 + and shift it into the high word. */
5046 + UDWtype v = (UWtype) b;
5048 + /* Remove high part from the XFtype, leaving the low part as flonum. */
5050 + /* Convert that to fixed (but not to DWtype!) and add it in.
5051 + Sometimes A comes out negative. This is significant, since
5052 + A has more bits than a long int does. */
5054 + v -= (UWtype) (- a);
5061 +#if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
5063 +__fixxfdi (XFtype a)
5066 + return - __fixunsxfDI (-a);
5067 + return __fixunsxfDI (a);
5071 +#ifdef L_fixunsdfdi
5072 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5073 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5076 +__fixunsdfDI (DFtype a)
5078 + /* Get high part of result. The division here will just moves the radix
5079 + point and will not cause any rounding. Then the conversion to integral
5080 + type chops result as desired. */
5081 + const UWtype hi = a / HIGH_WORD_COEFF;
5083 + /* Get low part of result. Convert `hi' to floating type and scale it back,
5084 + then subtract this from the number being converted. This leaves the low
5085 + part. Convert that to integral type. */
5086 + const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
5088 + /* Assemble result from the two parts. */
5089 + return ((UDWtype) hi << WORD_SIZE) | lo;
5095 +__fixdfdi (DFtype a)
5098 + return - __fixunsdfDI (-a);
5099 + return __fixunsdfDI (a);
5103 +#ifdef L_fixunssfdi
5104 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5105 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5108 +__fixunssfDI (SFtype original_a)
5110 + /* Convert the SFtype to a DFtype, because that is surely not going
5111 + to lose any bits. Some day someone else can write a faster version
5112 + that avoids converting to DFtype, and verify it really works right. */
5113 + const DFtype a = original_a;
5115 + /* Get high part of result. The division here will just moves the radix
5116 + point and will not cause any rounding. Then the conversion to integral
5117 + type chops result as desired. */
5118 + const UWtype hi = a / HIGH_WORD_COEFF;
5120 + /* Get low part of result. Convert `hi' to floating type and scale it back,
5121 + then subtract this from the number being converted. This leaves the low
5122 + part. Convert that to integral type. */
5123 + const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
5125 + /* Assemble result from the two parts. */
5126 + return ((UDWtype) hi << WORD_SIZE) | lo;
5132 +__fixsfdi (SFtype a)
5135 + return - __fixunssfDI (-a);
5136 + return __fixunssfDI (a);
5140 +#if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
5141 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5142 +#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
5143 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5146 +__floatdixf (DWtype u)
5148 + XFtype d = (Wtype) (u >> WORD_SIZE);
5149 + d *= HIGH_HALFWORD_COEFF;
5150 + d *= HIGH_HALFWORD_COEFF;
5151 + d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
5157 +#if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
5158 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5159 +#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
5160 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5163 +__floatditf (DWtype u)
5165 + TFtype d = (Wtype) (u >> WORD_SIZE);
5166 + d *= HIGH_HALFWORD_COEFF;
5167 + d *= HIGH_HALFWORD_COEFF;
5168 + d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
5175 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5176 +#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
5177 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5180 +__floatdidf (DWtype u)
5182 + DFtype d = (Wtype) (u >> WORD_SIZE);
5183 + d *= HIGH_HALFWORD_COEFF;
5184 + d *= HIGH_HALFWORD_COEFF;
5185 + d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
5192 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
5193 +#define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
5194 +#define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
5196 +#define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
5197 +#define DF_SIZE DBL_MANT_DIG
5198 +#define SF_SIZE FLT_MANT_DIG
5201 +__floatdisf (DWtype u)
5203 + /* Protect against double-rounding error.
5204 + Represent any low-order bits, that might be truncated in DFmode,
5205 + by a bit that won't be lost. The bit can go in anywhere below the
5206 + rounding position of the SFmode. A fixed mask and bit position
5207 + handles all usual configurations. It doesn't handle the case
5208 + of 128-bit DImode, however. */
5209 + if (DF_SIZE < DI_SIZE
5210 + && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
5212 +#define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
5213 + if (! (- ((DWtype) 1 << DF_SIZE) < u
5214 + && u < ((DWtype) 1 << DF_SIZE)))
5216 + if ((UDWtype) u & (REP_BIT - 1))
5218 + u &= ~ (REP_BIT - 1);
5223 + /* Do the calculation in DFmode
5224 + so that we don't lose any of the precision of the high word
5225 + while multiplying it. */
5226 + DFtype f = (Wtype) (u >> WORD_SIZE);
5227 + f *= HIGH_HALFWORD_COEFF;
5228 + f *= HIGH_HALFWORD_COEFF;
5229 + f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
5231 + return (SFtype) f;
5235 +#if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
5236 +/* Reenable the normal types, in case limits.h needs them. */
5246 +#include <limits.h>
5249 +__fixunsxfSI (XFtype a)
5251 + if (a >= - (DFtype) Wtype_MIN)
5252 + return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
5257 +#ifdef L_fixunsdfsi
5258 +/* Reenable the normal types, in case limits.h needs them. */
5268 +#include <limits.h>
5271 +__fixunsdfSI (DFtype a)
5273 + if (a >= - (DFtype) Wtype_MIN)
5274 + return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
5279 +#ifdef L_fixunssfsi
5280 +/* Reenable the normal types, in case limits.h needs them. */
5290 +#include <limits.h>
5293 +__fixunssfSI (SFtype a)
5295 + if (a >= - (SFtype) Wtype_MIN)
5296 + return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
5301 +/* From here on down, the routines use normal data types. */
5303 +#define SItype bogus_type
5304 +#define USItype bogus_type
5305 +#define DItype bogus_type
5306 +#define UDItype bogus_type
5307 +#define SFtype bogus_type
5308 +#define DFtype bogus_type
5326 +/* Like bcmp except the sign is meaningful.
5327 + Result is negative if S1 is less than S2,
5328 + positive if S1 is greater, 0 if S1 and S2 are equal. */
5331 +__gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
5335 + const unsigned char c1 = *s1++, c2 = *s2++;
5345 +/* __eprintf used to be used by GCC's private version of <assert.h>.
5346 + We no longer provide that header, but this routine remains in libgcc.a
5347 + for binary backward compatibility. Note that it is not included in
5348 + the shared version of libgcc. */
5350 +#ifndef inhibit_libc
5352 +#undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
5356 +__eprintf (const char *string, const char *expression,
5357 + unsigned int line, const char *filename)
5359 + fprintf (stderr, string, expression, line, filename);
5368 +#ifdef L_clear_cache
5369 +/* Clear part of an instruction cache. */
5372 +__clear_cache (char *beg __attribute__((__unused__)),
5373 + char *end __attribute__((__unused__)))
5375 +#ifdef CLEAR_INSN_CACHE
5376 + CLEAR_INSN_CACHE (beg, end);
5377 +#endif /* CLEAR_INSN_CACHE */
5380 +#endif /* L_clear_cache */
5382 +#ifdef L_trampoline
5384 +/* Jump to a trampoline, loading the static chain address. */
5386 +#if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
5399 +extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
5403 +mprotect (char *addr, int len, int prot)
5409 + else if (prot == 5)
5411 + else if (prot == 4)
5413 + else if (prot == 3)
5415 + else if (prot == 1)
5417 + else if (prot == 0)
5420 + if (VirtualProtect (addr, len, np, &op))
5426 +#endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
5428 +#ifdef TRANSFER_FROM_TRAMPOLINE
5429 +TRANSFER_FROM_TRAMPOLINE
5431 +#endif /* L_trampoline */
5436 +#include "gbl-ctors.h"
5437 +/* Some systems use __main in a way incompatible with its use in gcc, in these
5438 + cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
5439 + give the same symbol without quotes for an alternative entry point. You
5440 + must define both, or neither. */
5442 +#define NAME__MAIN "__main"
5443 +#define SYMBOL__MAIN __main
5446 +#ifdef INIT_SECTION_ASM_OP
5447 +#undef HAS_INIT_SECTION
5448 +#define HAS_INIT_SECTION
5451 +#if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
5453 +/* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
5454 + code to run constructors. In that case, we need to handle EH here, too. */
5456 +#ifdef EH_FRAME_SECTION_NAME
5457 +#include "unwind-dw2-fde.h"
5458 +extern unsigned char __EH_FRAME_BEGIN__[];
5461 +/* Run all the global destructors on exit from the program. */
5464 +__do_global_dtors (void)
5466 +#ifdef DO_GLOBAL_DTORS_BODY
5467 + DO_GLOBAL_DTORS_BODY;
5469 + static func_ptr *p = __DTOR_LIST__ + 1;
5476 +#if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
5478 + static int completed = 0;
5482 + __deregister_frame_info (__EH_FRAME_BEGIN__);
5489 +#ifndef HAS_INIT_SECTION
5490 +/* Run all the global constructors on entry to the program. */
5493 +__do_global_ctors (void)
5495 +#ifdef EH_FRAME_SECTION_NAME
5497 + static struct object object;
5498 + __register_frame_info (__EH_FRAME_BEGIN__, &object);
5501 + DO_GLOBAL_CTORS_BODY;
5502 + atexit (__do_global_dtors);
5504 +#endif /* no HAS_INIT_SECTION */
5506 +#if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
5507 +/* Subroutine called automatically by `main'.
5508 + Compiling a global function named `main'
5509 + produces an automatic call to this function at the beginning.
5511 + For many systems, this routine calls __do_global_ctors.
5512 + For systems which support a .init section we use the .init section
5513 + to run __do_global_ctors, so we need not do anything here. */
5515 +extern void SYMBOL__MAIN (void);
5517 +SYMBOL__MAIN (void)
5519 + /* Support recursive calls to `main': run initializers just once. */
5520 + static int initialized;
5521 + if (! initialized)
5524 + __do_global_ctors ();
5527 +#endif /* no HAS_INIT_SECTION or INVOKE__main */
5529 +#endif /* L__main */
5530 +#endif /* __CYGWIN__ */
5534 +#include "gbl-ctors.h"
5536 +/* Provide default definitions for the lists of constructors and
5537 + destructors, so that we don't get linker errors. These symbols are
5538 + intentionally bss symbols, so that gld and/or collect will provide
5539 + the right values. */
5541 +/* We declare the lists here with two elements each,
5542 + so that they are valid empty lists if no other definition is loaded.
5544 + If we are using the old "set" extensions to have the gnu linker
5545 + collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
5546 + must be in the bss/common section.
5548 + Long term no port should use those extensions. But many still do. */
5549 +#if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
5550 +#if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
5551 +func_ptr __CTOR_LIST__[2] = {0, 0};
5552 +func_ptr __DTOR_LIST__[2] = {0, 0};
5554 +func_ptr __CTOR_LIST__[2];
5555 +func_ptr __DTOR_LIST__[2];
5557 +#endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
5558 +#endif /* L_ctors */
5560 --- ./gcc/gcc/libgcc2.h
5561 +++ ./gcc/gcc/libgcc2.h
5563 +/* Header file for libgcc2.c. */
5564 +/* Copyright (C) 2000, 2001
5565 + Free Software Foundation, Inc.
5567 +This file is part of GCC.
5569 +GCC is free software; you can redistribute it and/or modify it under
5570 +the terms of the GNU General Public License as published by the Free
5571 +Software Foundation; either version 2, or (at your option) any later
5574 +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
5575 +WARRANTY; without even the implied warranty of MERCHANTABILITY or
5576 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5579 +You should have received a copy of the GNU General Public License
5580 +along with GCC; see the file COPYING. If not, write to the Free
5581 +Software Foundation, 59 Temple Place - Suite 330, Boston, MA
5582 +02111-1307, USA. */
5584 +/* As a special exception, if you link this library with other files,
5585 + some of which are compiled with GCC, to produce an executable,
5586 + this library does not by itself cause the resulting executable
5587 + to be covered by the GNU General Public License.
5588 + This exception does not however invalidate any other reasons why
5589 + the executable file might be covered by the GNU General Public License. */
5592 +#ifndef GCC_LIBGCC2_H
5593 +#define GCC_LIBGCC2_H
5595 +extern int __gcc_bcmp (const unsigned char *, const unsigned char *, size_t);
5596 +extern void __clear_cache (char *, char *);
5597 +extern void __eprintf (const char *, const char *, unsigned int, const char *)
5598 + __attribute__ ((__noreturn__));
5600 +struct exception_descriptor;
5601 +extern short int __get_eh_table_language (struct exception_descriptor *);
5602 +extern short int __get_eh_table_version (struct exception_descriptor *);
5604 +/* Permit the tm.h file to select the endianness to use just for this
5605 + file. This is used when the endianness is determined when the
5606 + compiler is run. */
5608 +#ifndef LIBGCC2_WORDS_BIG_ENDIAN
5609 +#define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
5612 +#ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE
5613 +#define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
5616 +#ifndef MIN_UNITS_PER_WORD
5617 +#define MIN_UNITS_PER_WORD UNITS_PER_WORD
5620 +/* In the first part of this file, we are interfacing to calls generated
5621 + by the compiler itself. These calls pass values into these routines
5622 + which have very specific modes (rather than very specific types), and
5623 + these compiler-generated calls also expect any return values to have
5624 + very specific modes (rather than very specific types). Thus, we need
5625 + to avoid using regular C language type names in this part of the file
5626 + because the sizes for those types can be configured to be anything.
5627 + Instead we use the following special type names. */
5629 +typedef int QItype __attribute__ ((mode (QI)));
5630 +typedef unsigned int UQItype __attribute__ ((mode (QI)));
5631 +typedef int HItype __attribute__ ((mode (HI)));
5632 +typedef unsigned int UHItype __attribute__ ((mode (HI)));
5633 +#if MIN_UNITS_PER_WORD > 1
5634 +/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */
5635 +typedef int SItype __attribute__ ((mode (SI)));
5636 +typedef unsigned int USItype __attribute__ ((mode (SI)));
5637 +#if LONG_LONG_TYPE_SIZE > 32
5638 +/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */
5639 +typedef int DItype __attribute__ ((mode (DI)));
5640 +typedef unsigned int UDItype __attribute__ ((mode (DI)));
5641 +#if MIN_UNITS_PER_WORD > 4
5642 +/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */
5643 +typedef int TItype __attribute__ ((mode (TI)));
5644 +typedef unsigned int UTItype __attribute__ ((mode (TI)));
5649 +#if BITS_PER_UNIT == 8
5651 +typedef float SFtype __attribute__ ((mode (SF)));
5652 +typedef float DFtype __attribute__ ((mode (DF)));
5654 +#if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
5655 +typedef float XFtype __attribute__ ((mode (XF)));
5657 +#if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
5658 +typedef float TFtype __attribute__ ((mode (TF)));
5661 +#else /* BITS_PER_UNIT != 8 */
5663 +/* On dsp's there are usually qf/hf/tqf modes used instead of the above.
5664 + For now we don't support them in libgcc2.c. */
5669 +#undef L_fixunsdfdi
5670 +#undef L_fixunsdfsi
5671 +#undef L_fixunssfdi
5672 +#undef L_fixunssfsi
5673 +#undef L_fixunstfdi
5674 +#undef L_fixunsxfdi
5675 +#undef L_fixunsxfsi
5682 +#endif /* BITS_PER_UNIT != 8 */
5684 +typedef int word_type __attribute__ ((mode (__word__)));
5686 +/* Make sure that we don't accidentally use any normal C language built-in
5687 + type names in the first part of this file. Instead we want to use *only*
5688 + the type names defined above. The following macro definitions insure
5689 + that if we *do* accidentally use some normal C language built-in type name,
5690 + we will get a syntax error. */
5692 +#define char bogus_type
5693 +#define short bogus_type
5694 +#define int bogus_type
5695 +#define long bogus_type
5696 +#define unsigned bogus_type
5697 +#define float bogus_type
5698 +#define double bogus_type
5700 +#if MIN_UNITS_PER_WORD > 4
5701 +#define W_TYPE_SIZE (8 * BITS_PER_UNIT)
5702 +#define Wtype DItype
5703 +#define UWtype UDItype
5704 +#define HWtype DItype
5705 +#define UHWtype UDItype
5706 +#define DWtype TItype
5707 +#define UDWtype UTItype
5708 +#define __NW(a,b) __ ## a ## di ## b
5709 +#define __NDW(a,b) __ ## a ## ti ## b
5710 +#elif MIN_UNITS_PER_WORD > 2 \
5711 + || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32)
5712 +#define W_TYPE_SIZE (4 * BITS_PER_UNIT)
5713 +#define Wtype SItype
5714 +#define UWtype USItype
5715 +#define HWtype SItype
5716 +#define UHWtype USItype
5717 +#define DWtype DItype
5718 +#define UDWtype UDItype
5719 +#define __NW(a,b) __ ## a ## si ## b
5720 +#define __NDW(a,b) __ ## a ## di ## b
5721 +#elif MIN_UNITS_PER_WORD > 1
5722 +#define W_TYPE_SIZE (2 * BITS_PER_UNIT)
5723 +#define Wtype HItype
5724 +#define UWtype UHItype
5725 +#define HWtype HItype
5726 +#define UHWtype UHItype
5727 +#define DWtype SItype
5728 +#define UDWtype USItype
5729 +#define __NW(a,b) __ ## a ## hi ## b
5730 +#define __NDW(a,b) __ ## a ## si ## b
5732 +#define W_TYPE_SIZE BITS_PER_UNIT
5733 +#define Wtype QItype
5734 +#define UWtype UQItype
5735 +#define HWtype QItype
5736 +#define UHWtype UQItype
5737 +#define DWtype HItype
5738 +#define UDWtype UHItype
5739 +#define __NW(a,b) __ ## a ## qi ## b
5740 +#define __NDW(a,b) __ ## a ## hi ## b
5743 +#define Wtype_MAX ((Wtype)(((UWtype)1 << (W_TYPE_SIZE - 1)) - 1))
5744 +#define Wtype_MIN (- Wtype_MAX - 1)
5746 +#define __muldi3 __NDW(mul,3)
5747 +#define __divdi3 __NDW(div,3)
5748 +#define __udivdi3 __NDW(udiv,3)
5749 +#define __moddi3 __NDW(mod,3)
5750 +#define __umoddi3 __NDW(umod,3)
5751 +#define __negdi2 __NDW(neg,2)
5752 +#define __lshrdi3 __NDW(lshr,3)
5753 +#define __ashldi3 __NDW(ashl,3)
5754 +#define __ashrdi3 __NDW(ashr,3)
5755 +#define __cmpdi2 __NDW(cmp,2)
5756 +#define __ucmpdi2 __NDW(ucmp,2)
5757 +#define __udivmoddi4 __NDW(udivmod,4)
5758 +#define __fixunstfDI __NDW(fixunstf,)
5759 +#define __fixtfdi __NDW(fixtf,)
5760 +#define __fixunsxfDI __NDW(fixunsxf,)
5761 +#define __fixxfdi __NDW(fixxf,)
5762 +#define __fixunsdfDI __NDW(fixunsdf,)
5763 +#define __fixdfdi __NDW(fixdf,)
5764 +#define __fixunssfDI __NDW(fixunssf,)
5765 +#define __fixsfdi __NDW(fixsf,)
5766 +#define __floatdixf __NDW(float,xf)
5767 +#define __floatditf __NDW(float,tf)
5768 +#define __floatdidf __NDW(float,df)
5769 +#define __floatdisf __NDW(float,sf)
5770 +#define __fixunsxfSI __NW(fixunsxf,)
5771 +#define __fixunstfSI __NW(fixunstf,)
5772 +#define __fixunsdfSI __NW(fixunsdf,)
5773 +#define __fixunssfSI __NW(fixunssf,)
5775 +#define __ffsSI2 __NW(ffs,2)
5776 +#define __clzSI2 __NW(clz,2)
5777 +#define __ctzSI2 __NW(ctz,2)
5778 +#define __popcountSI2 __NW(popcount,2)
5779 +#define __paritySI2 __NW(parity,2)
5780 +#define __ffsDI2 __NDW(ffs,2)
5781 +#define __clzDI2 __NDW(clz,2)
5782 +#define __ctzDI2 __NDW(ctz,2)
5783 +#define __popcountDI2 __NDW(popcount,2)
5784 +#define __parityDI2 __NDW(parity,2)
5786 +extern DWtype __muldi3 (DWtype, DWtype);
5787 +extern DWtype __divdi3 (DWtype, DWtype);
5788 +extern UDWtype __udivdi3 (UDWtype, UDWtype);
5789 +extern UDWtype __umoddi3 (UDWtype, UDWtype);
5790 +extern DWtype __moddi3 (DWtype, DWtype);
5792 +/* __udivmoddi4 is static inline when building other libgcc2 portions. */
5793 +#if (!defined (L_udivdi3) && !defined (L_divdi3) && \
5794 + !defined (L_umoddi3) && !defined (L_moddi3))
5795 +extern UDWtype __udivmoddi4 (UDWtype, UDWtype, UDWtype *);
5798 +/* __negdi2 is static inline when building other libgcc2 portions. */
5799 +#if !defined(L_divdi3) && !defined(L_moddi3)
5800 +extern DWtype __negdi2 (DWtype);
5803 +extern DWtype __lshrdi3 (DWtype, word_type);
5804 +extern DWtype __ashldi3 (DWtype, word_type);
5805 +extern DWtype __ashrdi3 (DWtype, word_type);
5807 +/* __udiv_w_sdiv is static inline when building other libgcc2 portions. */
5808 +#if (!defined(L_udivdi3) && !defined(L_divdi3) && \
5809 + !defined(L_umoddi3) && !defined(L_moddi3))
5810 +extern UWtype __udiv_w_sdiv (UWtype *, UWtype, UWtype, UWtype);
5813 +extern word_type __cmpdi2 (DWtype, DWtype);
5814 +extern word_type __ucmpdi2 (DWtype, DWtype);
5816 +extern Wtype __absvsi2 (Wtype);
5817 +extern DWtype __absvdi2 (DWtype);
5818 +extern Wtype __addvsi3 (Wtype, Wtype);
5819 +extern DWtype __addvdi3 (DWtype, DWtype);
5820 +extern Wtype __subvsi3 (Wtype, Wtype);
5821 +extern DWtype __subvdi3 (DWtype, DWtype);
5822 +extern Wtype __mulvsi3 (Wtype, Wtype);
5823 +extern DWtype __mulvdi3 (DWtype, DWtype);
5824 +extern Wtype __negvsi2 (Wtype);
5825 +extern DWtype __negvdi2 (DWtype);
5827 +#if BITS_PER_UNIT == 8
5828 +extern DWtype __fixdfdi (DFtype);
5829 +extern DWtype __fixsfdi (SFtype);
5830 +extern DFtype __floatdidf (DWtype);
5831 +extern SFtype __floatdisf (DWtype);
5832 +extern UWtype __fixunsdfSI (DFtype);
5833 +extern UWtype __fixunssfSI (SFtype);
5834 +extern DWtype __fixunsdfDI (DFtype);
5835 +extern DWtype __fixunssfDI (SFtype);
5837 +#if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
5838 +extern DWtype __fixxfdi (XFtype);
5839 +extern DWtype __fixunsxfDI (XFtype);
5840 +extern XFtype __floatdixf (DWtype);
5841 +extern UWtype __fixunsxfSI (XFtype);
5844 +#if LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128
5845 +extern DWtype __fixunstfDI (TFtype);
5846 +extern DWtype __fixtfdi (TFtype);
5847 +extern TFtype __floatditf (DWtype);
5849 +#endif /* BITS_PER_UNIT == 8 */
5851 +/* DWstructs are pairs of Wtype values in the order determined by
5852 + LIBGCC2_WORDS_BIG_ENDIAN. */
5854 +#if LIBGCC2_WORDS_BIG_ENDIAN
5855 + struct DWstruct {Wtype high, low;};
5857 + struct DWstruct {Wtype low, high;};
5860 +/* We need this union to unpack/pack DImode values, since we don't have
5861 + any arithmetic yet. Incoming DImode parameters are stored into the
5862 + `ll' field, and the unpacked result is read from the struct `s'. */
5866 + struct DWstruct s;
5870 +#include "longlong.h"
5872 +#endif /* ! GCC_LIBGCC2_H */
5873 --- ./gcc/gcc/longlong.h
5874 +++ ./gcc/gcc/longlong.h
5876 +/* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
5877 + Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000
5878 + Free Software Foundation, Inc.
5880 + This definition file is free software; you can redistribute it
5881 + and/or modify it under the terms of the GNU General Public
5882 + License as published by the Free Software Foundation; either
5883 + version 2, or (at your option) any later version.
5885 + This definition file is distributed in the hope that it will be
5886 + useful, but WITHOUT ANY WARRANTY; without even the implied
5887 + warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5888 + See the GNU General Public License for more details.
5890 + You should have received a copy of the GNU General Public License
5891 + along with this program; if not, write to the Free Software
5892 + Foundation, Inc., 59 Temple Place - Suite 330,
5893 + Boston, MA 02111-1307, USA. */
5895 +/* You have to define the following before including this file:
5897 + UWtype -- An unsigned type, default type for operations (typically a "word")
5898 + UHWtype -- An unsigned type, at least half the size of UWtype.
5899 + UDWtype -- An unsigned type, at least twice as large a UWtype
5900 + W_TYPE_SIZE -- size in bits of UWtype
5902 + UQItype -- Unsigned 8 bit type.
5903 + SItype, USItype -- Signed and unsigned 32 bit types.
5904 + DItype, UDItype -- Signed and unsigned 64 bit types.
5906 + On a 32 bit machine UWtype should typically be USItype;
5907 + on a 64 bit machine, UWtype should typically be UDItype.
5910 +#define __BITS4 (W_TYPE_SIZE / 4)
5911 +#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
5912 +#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
5913 +#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
5915 +#ifndef W_TYPE_SIZE
5916 +#define W_TYPE_SIZE 32
5917 +#define UWtype USItype
5918 +#define UHWtype USItype
5919 +#define UDWtype UDItype
5922 +/* Define auxiliary asm macros.
5924 + 1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
5925 + UWtype integers MULTIPLER and MULTIPLICAND, and generates a two UWtype
5926 + word product in HIGH_PROD and LOW_PROD.
5928 + 2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
5929 + UDWtype product. This is just a variant of umul_ppmm.
5931 + 3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
5932 + denominator) divides a UDWtype, composed by the UWtype integers
5933 + HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
5934 + in QUOTIENT and the remainder in REMAINDER. HIGH_NUMERATOR must be less
5935 + than DENOMINATOR for correct operation. If, in addition, the most
5936 + significant bit of DENOMINATOR must be 1, then the pre-processor symbol
5937 + UDIV_NEEDS_NORMALIZATION is defined to 1.
5939 + 4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
5940 + denominator). Like udiv_qrnnd but the numbers are signed. The quotient
5941 + is rounded towards 0.
5943 + 5) count_leading_zeros(count, x) counts the number of zero-bits from the
5944 + msb to the first nonzero bit in the UWtype X. This is the number of
5945 + steps X needs to be shifted left to set the msb. Undefined for X == 0,
5946 + unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.
5948 + 6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
5949 + from the least significant end.
5951 + 7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
5952 + high_addend_2, low_addend_2) adds two UWtype integers, composed by
5953 + HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
5954 + respectively. The result is placed in HIGH_SUM and LOW_SUM. Overflow
5955 + (i.e. carry out) is not stored anywhere, and is lost.
5957 + 8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
5958 + high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
5959 + composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
5960 + LOW_SUBTRAHEND_2 respectively. The result is placed in HIGH_DIFFERENCE
5961 + and LOW_DIFFERENCE. Overflow (i.e. carry out) is not stored anywhere,
5964 + If any of these macros are left undefined for a particular CPU,
5965 + C macros are used. */
5967 +/* The CPUs come in alphabetical order below.
5969 + Please add support for more CPUs here, or improve the current support
5970 + for the CPUs below!
5971 + (E.g. WE32100, IBM360.) */
5973 +#if defined (__GNUC__) && !defined (NO_ASM)
5975 +/* We sometimes need to clobber "cc" with gcc2, but that would not be
5976 + understood by gcc1. Use cpp to avoid major code duplication. */
5978 +#define __CLOBBER_CC
5979 +#define __AND_CLOBBER_CC
5980 +#else /* __GNUC__ >= 2 */
5981 +#define __CLOBBER_CC : "cc"
5982 +#define __AND_CLOBBER_CC , "cc"
5983 +#endif /* __GNUC__ < 2 */
5985 +#if defined (__alpha) && W_TYPE_SIZE == 64
5986 +#define umul_ppmm(ph, pl, m0, m1) \
5988 + UDItype __m0 = (m0), __m1 = (m1); \
5989 + (ph) = __builtin_alpha_umulh (__m0, __m1); \
5990 + (pl) = __m0 * __m1; \
5992 +#define UMUL_TIME 46
5993 +#ifndef LONGLONG_STANDALONE
5994 +#define udiv_qrnnd(q, r, n1, n0, d) \
5995 + do { UDItype __r; \
5996 + (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
5999 +extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
6000 +#define UDIV_TIME 220
6001 +#endif /* LONGLONG_STANDALONE */
6002 +#ifdef __alpha_cix__
6003 +#define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clzl (X))
6004 +#define count_trailing_zeros(COUNT,X) ((COUNT) = __builtin_ctzl (X))
6005 +#define COUNT_LEADING_ZEROS_0 64
6007 +extern const UQItype __clz_tab[] ATTRIBUTE_HIDDEN;
6008 +#define count_leading_zeros(COUNT,X) \
6010 + UDItype __xr = (X), __t, __a; \
6011 + __t = __builtin_alpha_cmpbge (0, __xr); \
6012 + __a = __clz_tab[__t ^ 0xff] - 1; \
6013 + __t = __builtin_alpha_extbl (__xr, __a); \
6014 + (COUNT) = 64 - (__clz_tab[__t] + __a*8); \
6016 +#define count_trailing_zeros(COUNT,X) \
6018 + UDItype __xr = (X), __t, __a; \
6019 + __t = __builtin_alpha_cmpbge (0, __xr); \
6020 + __t = ~__t & -~__t; \
6021 + __a = ((__t & 0xCC) != 0) * 2; \
6022 + __a += ((__t & 0xF0) != 0) * 4; \
6023 + __a += ((__t & 0xAA) != 0); \
6024 + __t = __builtin_alpha_extbl (__xr, __a); \
6027 + __a += ((__t & 0xCC) != 0) * 2; \
6028 + __a += ((__t & 0xF0) != 0) * 4; \
6029 + __a += ((__t & 0xAA) != 0); \
6032 +#endif /* __alpha_cix__ */
6033 +#endif /* __alpha */
6035 +#if defined (__arc__) && W_TYPE_SIZE == 32
6036 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6037 + __asm__ ("add.f %1, %4, %5\n\tadc %0, %2, %3" \
6038 + : "=r" ((USItype) (sh)), \
6039 + "=&r" ((USItype) (sl)) \
6040 + : "%r" ((USItype) (ah)), \
6041 + "rIJ" ((USItype) (bh)), \
6042 + "%r" ((USItype) (al)), \
6043 + "rIJ" ((USItype) (bl)))
6044 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6045 + __asm__ ("sub.f %1, %4, %5\n\tsbc %0, %2, %3" \
6046 + : "=r" ((USItype) (sh)), \
6047 + "=&r" ((USItype) (sl)) \
6048 + : "r" ((USItype) (ah)), \
6049 + "rIJ" ((USItype) (bh)), \
6050 + "r" ((USItype) (al)), \
6051 + "rIJ" ((USItype) (bl)))
6052 +/* Call libgcc routine. */
6053 +#define umul_ppmm(w1, w0, u, v) \
6056 + __w.ll = __umulsidi3 (u, v); \
6057 + w1 = __w.s.high; \
6060 +#define __umulsidi3 __umulsidi3
6061 +UDItype __umulsidi3 (USItype, USItype);
6064 +#if defined (__arm__) && W_TYPE_SIZE == 32
6065 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6066 + __asm__ ("adds %1, %4, %5\n\tadc %0, %2, %3" \
6067 + : "=r" ((USItype) (sh)), \
6068 + "=&r" ((USItype) (sl)) \
6069 + : "%r" ((USItype) (ah)), \
6070 + "rI" ((USItype) (bh)), \
6071 + "%r" ((USItype) (al)), \
6072 + "rI" ((USItype) (bl)))
6073 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6074 + __asm__ ("subs %1, %4, %5\n\tsbc %0, %2, %3" \
6075 + : "=r" ((USItype) (sh)), \
6076 + "=&r" ((USItype) (sl)) \
6077 + : "r" ((USItype) (ah)), \
6078 + "rI" ((USItype) (bh)), \
6079 + "r" ((USItype) (al)), \
6080 + "rI" ((USItype) (bl)))
6081 +#define umul_ppmm(xh, xl, a, b) \
6082 +{register USItype __t0, __t1, __t2; \
6083 + __asm__ ("%@ Inlined umul_ppmm\n" \
6084 + " mov %2, %5, lsr #16\n" \
6085 + " mov %0, %6, lsr #16\n" \
6086 + " bic %3, %5, %2, lsl #16\n" \
6087 + " bic %4, %6, %0, lsl #16\n" \
6088 + " mul %1, %3, %4\n" \
6089 + " mul %4, %2, %4\n" \
6090 + " mul %3, %0, %3\n" \
6091 + " mul %0, %2, %0\n" \
6092 + " adds %3, %4, %3\n" \
6093 + " addcs %0, %0, #65536\n" \
6094 + " adds %1, %1, %3, lsl #16\n" \
6095 + " adc %0, %0, %3, lsr #16" \
6096 + : "=&r" ((USItype) (xh)), \
6097 + "=r" ((USItype) (xl)), \
6098 + "=&r" (__t0), "=&r" (__t1), "=r" (__t2) \
6099 + : "r" ((USItype) (a)), \
6100 + "r" ((USItype) (b)));}
6101 +#define UMUL_TIME 20
6102 +#define UDIV_TIME 100
6103 +#endif /* __arm__ */
6105 +#if defined (__hppa) && W_TYPE_SIZE == 32
6106 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6107 + __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \
6108 + : "=r" ((USItype) (sh)), \
6109 + "=&r" ((USItype) (sl)) \
6110 + : "%rM" ((USItype) (ah)), \
6111 + "rM" ((USItype) (bh)), \
6112 + "%rM" ((USItype) (al)), \
6113 + "rM" ((USItype) (bl)))
6114 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6115 + __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0" \
6116 + : "=r" ((USItype) (sh)), \
6117 + "=&r" ((USItype) (sl)) \
6118 + : "rM" ((USItype) (ah)), \
6119 + "rM" ((USItype) (bh)), \
6120 + "rM" ((USItype) (al)), \
6121 + "rM" ((USItype) (bl)))
6122 +#if defined (_PA_RISC1_1)
6123 +#define umul_ppmm(w1, w0, u, v) \
6128 + struct {USItype __w1, __w0;} __w1w0; \
6130 + __asm__ ("xmpyu %1,%2,%0" \
6131 + : "=x" (__t.__f) \
6132 + : "x" ((USItype) (u)), \
6133 + "x" ((USItype) (v))); \
6134 + (w1) = __t.__w1w0.__w1; \
6135 + (w0) = __t.__w1w0.__w0; \
6137 +#define UMUL_TIME 8
6139 +#define UMUL_TIME 30
6141 +#define UDIV_TIME 40
6142 +#define count_leading_zeros(count, x) \
6147 +" extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
6148 +" extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n"\
6149 +" ldo 16(%0),%0 ; Yes. Perform add.\n" \
6150 +" extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
6151 +" extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n"\
6152 +" ldo 8(%0),%0 ; Yes. Perform add.\n" \
6153 +" extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
6154 +" extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n"\
6155 +" ldo 4(%0),%0 ; Yes. Perform add.\n" \
6156 +" extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
6157 +" extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n"\
6158 +" ldo 2(%0),%0 ; Yes. Perform add.\n" \
6159 +" extru %1,30,1,%1 ; Extract bit 1.\n" \
6160 +" sub %0,%1,%0 ; Subtract it.\n" \
6161 + : "=r" (count), "=r" (__tmp) : "1" (x)); \
6165 +#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
6166 +#define smul_ppmm(xh, xl, m0, m1) \
6168 + union {DItype __ll; \
6169 + struct {USItype __h, __l;} __i; \
6171 + __asm__ ("lr %N0,%1\n\tmr %0,%2" \
6172 + : "=&r" (__x.__ll) \
6173 + : "r" (m0), "r" (m1)); \
6174 + (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
6176 +#define sdiv_qrnnd(q, r, n1, n0, d) \
6178 + union {DItype __ll; \
6179 + struct {USItype __h, __l;} __i; \
6181 + __x.__i.__h = n1; __x.__i.__l = n0; \
6182 + __asm__ ("dr %0,%2" \
6183 + : "=r" (__x.__ll) \
6184 + : "0" (__x.__ll), "r" (d)); \
6185 + (q) = __x.__i.__l; (r) = __x.__i.__h; \
6189 +#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
6190 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6191 + __asm__ ("addl %5,%1\n\tadcl %3,%0" \
6192 + : "=r" ((USItype) (sh)), \
6193 + "=&r" ((USItype) (sl)) \
6194 + : "%0" ((USItype) (ah)), \
6195 + "g" ((USItype) (bh)), \
6196 + "%1" ((USItype) (al)), \
6197 + "g" ((USItype) (bl)))
6198 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6199 + __asm__ ("subl %5,%1\n\tsbbl %3,%0" \
6200 + : "=r" ((USItype) (sh)), \
6201 + "=&r" ((USItype) (sl)) \
6202 + : "0" ((USItype) (ah)), \
6203 + "g" ((USItype) (bh)), \
6204 + "1" ((USItype) (al)), \
6205 + "g" ((USItype) (bl)))
6206 +#define umul_ppmm(w1, w0, u, v) \
6207 + __asm__ ("mull %3" \
6208 + : "=a" ((USItype) (w0)), \
6209 + "=d" ((USItype) (w1)) \
6210 + : "%0" ((USItype) (u)), \
6211 + "rm" ((USItype) (v)))
6212 +#define udiv_qrnnd(q, r, n1, n0, dv) \
6213 + __asm__ ("divl %4" \
6214 + : "=a" ((USItype) (q)), \
6215 + "=d" ((USItype) (r)) \
6216 + : "0" ((USItype) (n0)), \
6217 + "1" ((USItype) (n1)), \
6218 + "rm" ((USItype) (dv)))
6219 +#define count_leading_zeros(count, x) \
6221 + USItype __cbtmp; \
6222 + __asm__ ("bsrl %1,%0" \
6223 + : "=r" (__cbtmp) : "rm" ((USItype) (x))); \
6224 + (count) = __cbtmp ^ 31; \
6226 +#define count_trailing_zeros(count, x) \
6227 + __asm__ ("bsfl %1,%0" : "=r" (count) : "rm" ((USItype)(x)))
6228 +#define UMUL_TIME 40
6229 +#define UDIV_TIME 40
6232 +#if defined (__i960__) && W_TYPE_SIZE == 32
6233 +#define umul_ppmm(w1, w0, u, v) \
6234 + ({union {UDItype __ll; \
6235 + struct {USItype __l, __h;} __i; \
6237 + __asm__ ("emul %2,%1,%0" \
6238 + : "=d" (__xx.__ll) \
6239 + : "%dI" ((USItype) (u)), \
6240 + "dI" ((USItype) (v))); \
6241 + (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
6242 +#define __umulsidi3(u, v) \
6244 + __asm__ ("emul %2,%1,%0" \
6246 + : "%dI" ((USItype) (u)), \
6247 + "dI" ((USItype) (v))); \
6249 +#endif /* __i960__ */
6251 +#if defined (__M32R__) && W_TYPE_SIZE == 32
6252 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6253 + /* The cmp clears the condition bit. */ \
6254 + __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3" \
6255 + : "=r" ((USItype) (sh)), \
6256 + "=&r" ((USItype) (sl)) \
6257 + : "0" ((USItype) (ah)), \
6258 + "r" ((USItype) (bh)), \
6259 + "1" ((USItype) (al)), \
6260 + "r" ((USItype) (bl)) \
6262 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6263 + /* The cmp clears the condition bit. */ \
6264 + __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3" \
6265 + : "=r" ((USItype) (sh)), \
6266 + "=&r" ((USItype) (sl)) \
6267 + : "0" ((USItype) (ah)), \
6268 + "r" ((USItype) (bh)), \
6269 + "1" ((USItype) (al)), \
6270 + "r" ((USItype) (bl)) \
6272 +#endif /* __M32R__ */
6274 +#if defined (__mc68000__) && W_TYPE_SIZE == 32
6275 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6276 + __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0" \
6277 + : "=d" ((USItype) (sh)), \
6278 + "=&d" ((USItype) (sl)) \
6279 + : "%0" ((USItype) (ah)), \
6280 + "d" ((USItype) (bh)), \
6281 + "%1" ((USItype) (al)), \
6282 + "g" ((USItype) (bl)))
6283 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6284 + __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0" \
6285 + : "=d" ((USItype) (sh)), \
6286 + "=&d" ((USItype) (sl)) \
6287 + : "0" ((USItype) (ah)), \
6288 + "d" ((USItype) (bh)), \
6289 + "1" ((USItype) (al)), \
6290 + "g" ((USItype) (bl)))
6292 +/* The '020, '030, '040 and CPU32 have 32x32->64 and 64/32->32q-32r. */
6293 +#if defined (__mc68020__) || defined(mc68020) \
6294 + || defined(__mc68030__) || defined(mc68030) \
6295 + || defined(__mc68040__) || defined(mc68040) \
6296 + || defined(__mcpu32__) || defined(mcpu32)
6297 +#define umul_ppmm(w1, w0, u, v) \
6298 + __asm__ ("mulu%.l %3,%1:%0" \
6299 + : "=d" ((USItype) (w0)), \
6300 + "=d" ((USItype) (w1)) \
6301 + : "%0" ((USItype) (u)), \
6302 + "dmi" ((USItype) (v)))
6303 +#define UMUL_TIME 45
6304 +#define udiv_qrnnd(q, r, n1, n0, d) \
6305 + __asm__ ("divu%.l %4,%1:%0" \
6306 + : "=d" ((USItype) (q)), \
6307 + "=d" ((USItype) (r)) \
6308 + : "0" ((USItype) (n0)), \
6309 + "1" ((USItype) (n1)), \
6310 + "dmi" ((USItype) (d)))
6311 +#define UDIV_TIME 90
6312 +#define sdiv_qrnnd(q, r, n1, n0, d) \
6313 + __asm__ ("divs%.l %4,%1:%0" \
6314 + : "=d" ((USItype) (q)), \
6315 + "=d" ((USItype) (r)) \
6316 + : "0" ((USItype) (n0)), \
6317 + "1" ((USItype) (n1)), \
6318 + "dmi" ((USItype) (d)))
6320 +#else /* not mc68020 */
6321 +#if defined(__mcoldfire__)
6322 +#define umul_ppmm(xh, xl, a, b) \
6323 + __asm__ ("| Inlined umul_ppmm\n" \
6324 + " move%.l %2,%/d0\n" \
6325 + " move%.l %3,%/d1\n" \
6326 + " move%.l %/d0,%/d2\n" \
6328 + " move%.l %/d1,%/d3\n" \
6330 + " move%.w %/d2,%/d4\n" \
6331 + " mulu %/d3,%/d4\n" \
6332 + " mulu %/d1,%/d2\n" \
6333 + " mulu %/d0,%/d3\n" \
6334 + " mulu %/d0,%/d1\n" \
6335 + " move%.l %/d4,%/d0\n" \
6336 + " clr%.w %/d0\n" \
6338 + " add%.l %/d0,%/d2\n" \
6339 + " add%.l %/d3,%/d2\n" \
6341 + " add%.l %#65536,%/d1\n" \
6342 + "1: swap %/d2\n" \
6343 + " moveq %#0,%/d0\n" \
6344 + " move%.w %/d2,%/d0\n" \
6345 + " move%.w %/d4,%/d2\n" \
6346 + " move%.l %/d2,%1\n" \
6347 + " add%.l %/d1,%/d0\n" \
6348 + " move%.l %/d0,%0" \
6349 + : "=g" ((USItype) (xh)), \
6350 + "=g" ((USItype) (xl)) \
6351 + : "g" ((USItype) (a)), \
6352 + "g" ((USItype) (b)) \
6353 + : "d0", "d1", "d2", "d3", "d4")
6354 +#define UMUL_TIME 100
6355 +#define UDIV_TIME 400
6356 +#else /* not ColdFire */
6357 +/* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX. */
6358 +#define umul_ppmm(xh, xl, a, b) \
6359 + __asm__ ("| Inlined umul_ppmm\n" \
6360 + " move%.l %2,%/d0\n" \
6361 + " move%.l %3,%/d1\n" \
6362 + " move%.l %/d0,%/d2\n" \
6364 + " move%.l %/d1,%/d3\n" \
6366 + " move%.w %/d2,%/d4\n" \
6367 + " mulu %/d3,%/d4\n" \
6368 + " mulu %/d1,%/d2\n" \
6369 + " mulu %/d0,%/d3\n" \
6370 + " mulu %/d0,%/d1\n" \
6371 + " move%.l %/d4,%/d0\n" \
6372 + " eor%.w %/d0,%/d0\n" \
6374 + " add%.l %/d0,%/d2\n" \
6375 + " add%.l %/d3,%/d2\n" \
6377 + " add%.l %#65536,%/d1\n" \
6378 + "1: swap %/d2\n" \
6379 + " moveq %#0,%/d0\n" \
6380 + " move%.w %/d2,%/d0\n" \
6381 + " move%.w %/d4,%/d2\n" \
6382 + " move%.l %/d2,%1\n" \
6383 + " add%.l %/d1,%/d0\n" \
6384 + " move%.l %/d0,%0" \
6385 + : "=g" ((USItype) (xh)), \
6386 + "=g" ((USItype) (xl)) \
6387 + : "g" ((USItype) (a)), \
6388 + "g" ((USItype) (b)) \
6389 + : "d0", "d1", "d2", "d3", "d4")
6390 +#define UMUL_TIME 100
6391 +#define UDIV_TIME 400
6392 +#endif /* not ColdFire */
6393 +#endif /* not mc68020 */
6395 +/* The '020, '030, '040 and '060 have bitfield insns.
6396 + cpu32 disguises as a 68020, but lacks them. */
6397 +#if ( defined (__mc68020__) || defined(mc68020) \
6398 + || defined(__mc68030__) || defined(mc68030) \
6399 + || defined(__mc68040__) || defined(mc68040) \
6400 + || defined(__mc68060__) || defined(mc68060) ) \
6401 + && !defined(__mcpu32__)
6402 +#define count_leading_zeros(count, x) \
6403 + __asm__ ("bfffo %1{%b2:%b2},%0" \
6404 + : "=d" ((USItype) (count)) \
6405 + : "od" ((USItype) (x)), "n" (0))
6407 +#endif /* mc68000 */
6409 +#if defined (__m88000__) && W_TYPE_SIZE == 32
6410 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6411 + __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3" \
6412 + : "=r" ((USItype) (sh)), \
6413 + "=&r" ((USItype) (sl)) \
6414 + : "%rJ" ((USItype) (ah)), \
6415 + "rJ" ((USItype) (bh)), \
6416 + "%rJ" ((USItype) (al)), \
6417 + "rJ" ((USItype) (bl)))
6418 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6419 + __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3" \
6420 + : "=r" ((USItype) (sh)), \
6421 + "=&r" ((USItype) (sl)) \
6422 + : "rJ" ((USItype) (ah)), \
6423 + "rJ" ((USItype) (bh)), \
6424 + "rJ" ((USItype) (al)), \
6425 + "rJ" ((USItype) (bl)))
6426 +#define count_leading_zeros(count, x) \
6428 + USItype __cbtmp; \
6429 + __asm__ ("ff1 %0,%1" \
6430 + : "=r" (__cbtmp) \
6431 + : "r" ((USItype) (x))); \
6432 + (count) = __cbtmp ^ 31; \
6434 +#define COUNT_LEADING_ZEROS_0 63 /* sic */
6435 +#if defined (__mc88110__)
6436 +#define umul_ppmm(wh, wl, u, v) \
6438 + union {UDItype __ll; \
6439 + struct {USItype __h, __l;} __i; \
6441 + __asm__ ("mulu.d %0,%1,%2" \
6442 + : "=r" (__xx.__ll) \
6443 + : "r" ((USItype) (u)), \
6444 + "r" ((USItype) (v))); \
6445 + (wh) = __xx.__i.__h; \
6446 + (wl) = __xx.__i.__l; \
6448 +#define udiv_qrnnd(q, r, n1, n0, d) \
6449 + ({union {UDItype __ll; \
6450 + struct {USItype __h, __l;} __i; \
6453 + __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
6454 + __asm__ ("divu.d %0,%1,%2" \
6456 + : "r" (__xx.__ll), \
6457 + "r" ((USItype) (d))); \
6458 + (r) = (n0) - __q * (d); (q) = __q; })
6459 +#define UMUL_TIME 5
6460 +#define UDIV_TIME 25
6462 +#define UMUL_TIME 17
6463 +#define UDIV_TIME 150
6464 +#endif /* __mc88110__ */
6465 +#endif /* __m88000__ */
6467 +#if defined (__mips__) && W_TYPE_SIZE == 32
6468 +#define umul_ppmm(w1, w0, u, v) \
6469 + __asm__ ("multu %2,%3" \
6470 + : "=l" ((USItype) (w0)), \
6471 + "=h" ((USItype) (w1)) \
6472 + : "d" ((USItype) (u)), \
6473 + "d" ((USItype) (v)))
6474 +#define UMUL_TIME 10
6475 +#define UDIV_TIME 100
6476 +#endif /* __mips__ */
6478 +#if defined (__ns32000__) && W_TYPE_SIZE == 32
6479 +#define umul_ppmm(w1, w0, u, v) \
6480 + ({union {UDItype __ll; \
6481 + struct {USItype __l, __h;} __i; \
6483 + __asm__ ("meid %2,%0" \
6484 + : "=g" (__xx.__ll) \
6485 + : "%0" ((USItype) (u)), \
6486 + "g" ((USItype) (v))); \
6487 + (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
6488 +#define __umulsidi3(u, v) \
6490 + __asm__ ("meid %2,%0" \
6492 + : "%0" ((USItype) (u)), \
6493 + "g" ((USItype) (v))); \
6495 +#define udiv_qrnnd(q, r, n1, n0, d) \
6496 + ({union {UDItype __ll; \
6497 + struct {USItype __l, __h;} __i; \
6499 + __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
6500 + __asm__ ("deid %2,%0" \
6501 + : "=g" (__xx.__ll) \
6502 + : "0" (__xx.__ll), \
6503 + "g" ((USItype) (d))); \
6504 + (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
6505 +#define count_trailing_zeros(count,x) \
6507 + __asm__ ("ffsd %2,%0" \
6508 + : "=r" ((USItype) (count)) \
6509 + : "0" ((USItype) 0), \
6510 + "r" ((USItype) (x))); \
6512 +#endif /* __ns32000__ */
6514 +/* FIXME: We should test _IBMR2 here when we add assembly support for the
6515 + system vendor compilers.
6516 + FIXME: What's needed for gcc PowerPC VxWorks? __vxworks__ is not good
6517 + enough, since that hits ARM and m68k too. */
6518 +#if (defined (_ARCH_PPC) /* AIX */ \
6519 + || defined (_ARCH_PWR) /* AIX */ \
6520 + || defined (_ARCH_COM) /* AIX */ \
6521 + || defined (__powerpc__) /* gcc */ \
6522 + || defined (__POWERPC__) /* BEOS */ \
6523 + || defined (__ppc__) /* Darwin */ \
6524 + || defined (PPC) /* GNU/Linux, SysV */ \
6525 + ) && W_TYPE_SIZE == 32
6526 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6528 + if (__builtin_constant_p (bh) && (bh) == 0) \
6529 + __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
6530 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
6531 + else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
6532 + __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
6533 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
6535 + __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
6536 + : "=r" (sh), "=&r" (sl) \
6537 + : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
6539 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6541 + if (__builtin_constant_p (ah) && (ah) == 0) \
6542 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
6543 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
6544 + else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0) \
6545 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
6546 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
6547 + else if (__builtin_constant_p (bh) && (bh) == 0) \
6548 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
6549 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
6550 + else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0) \
6551 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
6552 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
6554 + __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
6555 + : "=r" (sh), "=&r" (sl) \
6556 + : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
6558 +#define count_leading_zeros(count, x) \
6559 + __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
6560 +#define COUNT_LEADING_ZEROS_0 32
6561 +#if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
6562 + || defined (__ppc__) || defined (PPC)
6563 +#define umul_ppmm(ph, pl, m0, m1) \
6565 + USItype __m0 = (m0), __m1 = (m1); \
6566 + __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
6567 + (pl) = __m0 * __m1; \
6569 +#define UMUL_TIME 15
6570 +#define smul_ppmm(ph, pl, m0, m1) \
6572 + SItype __m0 = (m0), __m1 = (m1); \
6573 + __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
6574 + (pl) = __m0 * __m1; \
6576 +#define SMUL_TIME 14
6577 +#define UDIV_TIME 120
6578 +#elif defined (_ARCH_PWR)
6579 +#define UMUL_TIME 8
6580 +#define smul_ppmm(xh, xl, m0, m1) \
6581 + __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
6582 +#define SMUL_TIME 4
6583 +#define sdiv_qrnnd(q, r, nh, nl, d) \
6584 + __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
6585 +#define UDIV_TIME 100
6587 +#endif /* 32-bit POWER architecture variants. */
6589 +/* We should test _IBMR2 here when we add assembly support for the system
6590 + vendor compilers. */
6591 +#if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
6592 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6594 + if (__builtin_constant_p (bh) && (bh) == 0) \
6595 + __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2" \
6596 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
6597 + else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
6598 + __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2" \
6599 + : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
6601 + __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3" \
6602 + : "=r" (sh), "=&r" (sl) \
6603 + : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)); \
6605 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6607 + if (__builtin_constant_p (ah) && (ah) == 0) \
6608 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2" \
6609 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
6610 + else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0) \
6611 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2" \
6612 + : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
6613 + else if (__builtin_constant_p (bh) && (bh) == 0) \
6614 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2" \
6615 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
6616 + else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0) \
6617 + __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2" \
6618 + : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
6620 + __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2" \
6621 + : "=r" (sh), "=&r" (sl) \
6622 + : "r" (ah), "r" (bh), "rI" (al), "r" (bl)); \
6624 +#define count_leading_zeros(count, x) \
6625 + __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
6626 +#define COUNT_LEADING_ZEROS_0 64
6627 +#define umul_ppmm(ph, pl, m0, m1) \
6629 + UDItype __m0 = (m0), __m1 = (m1); \
6630 + __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
6631 + (pl) = __m0 * __m1; \
6633 +#define UMUL_TIME 15
6634 +#define smul_ppmm(ph, pl, m0, m1) \
6636 + DItype __m0 = (m0), __m1 = (m1); \
6637 + __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1)); \
6638 + (pl) = __m0 * __m1; \
6640 +#define SMUL_TIME 14 /* ??? */
6641 +#define UDIV_TIME 120 /* ??? */
6642 +#endif /* 64-bit PowerPC. */
6644 +#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
6645 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6646 + __asm__ ("a %1,%5\n\tae %0,%3" \
6647 + : "=r" ((USItype) (sh)), \
6648 + "=&r" ((USItype) (sl)) \
6649 + : "%0" ((USItype) (ah)), \
6650 + "r" ((USItype) (bh)), \
6651 + "%1" ((USItype) (al)), \
6652 + "r" ((USItype) (bl)))
6653 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6654 + __asm__ ("s %1,%5\n\tse %0,%3" \
6655 + : "=r" ((USItype) (sh)), \
6656 + "=&r" ((USItype) (sl)) \
6657 + : "0" ((USItype) (ah)), \
6658 + "r" ((USItype) (bh)), \
6659 + "1" ((USItype) (al)), \
6660 + "r" ((USItype) (bl)))
6661 +#define umul_ppmm(ph, pl, m0, m1) \
6663 + USItype __m0 = (m0), __m1 = (m1); \
6683 +" cas %0,r2,r0\n" \
6685 + : "=r" ((USItype) (ph)), \
6686 + "=r" ((USItype) (pl)) \
6690 + (ph) += ((((SItype) __m0 >> 31) & __m1) \
6691 + + (((SItype) __m1 >> 31) & __m0)); \
6693 +#define UMUL_TIME 20
6694 +#define UDIV_TIME 200
6695 +#define count_leading_zeros(count, x) \
6697 + if ((x) >= 0x10000) \
6698 + __asm__ ("clz %0,%1" \
6699 + : "=r" ((USItype) (count)) \
6700 + : "r" ((USItype) (x) >> 16)); \
6703 + __asm__ ("clz %0,%1" \
6704 + : "=r" ((USItype) (count)) \
6705 + : "r" ((USItype) (x))); \
6711 +#if defined (__sh2__) && W_TYPE_SIZE == 32
6712 +#define umul_ppmm(w1, w0, u, v) \
6714 + "dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \
6715 + : "=r" ((USItype)(w1)), \
6716 + "=r" ((USItype)(w0)) \
6717 + : "r" ((USItype)(u)), \
6718 + "r" ((USItype)(v)) \
6720 +#define UMUL_TIME 5
6723 +#if defined (__SH5__) && __SHMEDIA__ && W_TYPE_SIZE == 32
6724 +#define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
6725 +#define count_leading_zeros(count, x) \
6728 + UDItype x_ = (USItype)(x); \
6731 + __asm__ ("nsb %1, %0" : "=r" (c_) : "r" (x_)); \
6732 + (count) = c_ - 31; \
6735 +#define COUNT_LEADING_ZEROS_0 32
6738 +#if defined (__sparc__) && !defined (__arch64__) && !defined (__sparcv9) \
6739 + && W_TYPE_SIZE == 32
6740 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6741 + __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0" \
6742 + : "=r" ((USItype) (sh)), \
6743 + "=&r" ((USItype) (sl)) \
6744 + : "%rJ" ((USItype) (ah)), \
6745 + "rI" ((USItype) (bh)), \
6746 + "%rJ" ((USItype) (al)), \
6747 + "rI" ((USItype) (bl)) \
6749 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6750 + __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0" \
6751 + : "=r" ((USItype) (sh)), \
6752 + "=&r" ((USItype) (sl)) \
6753 + : "rJ" ((USItype) (ah)), \
6754 + "rI" ((USItype) (bh)), \
6755 + "rJ" ((USItype) (al)), \
6756 + "rI" ((USItype) (bl)) \
6758 +#if defined (__sparc_v8__)
6759 +#define umul_ppmm(w1, w0, u, v) \
6760 + __asm__ ("umul %2,%3,%1;rd %%y,%0" \
6761 + : "=r" ((USItype) (w1)), \
6762 + "=r" ((USItype) (w0)) \
6763 + : "r" ((USItype) (u)), \
6764 + "r" ((USItype) (v)))
6765 +#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
6766 + __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
6767 + : "=&r" ((USItype) (__q)), \
6768 + "=&r" ((USItype) (__r)) \
6769 + : "r" ((USItype) (__n1)), \
6770 + "r" ((USItype) (__n0)), \
6771 + "r" ((USItype) (__d)))
6773 +#if defined (__sparclite__)
6774 +/* This has hardware multiply but not divide. It also has two additional
6775 + instructions scan (ffs from high bit) and divscc. */
6776 +#define umul_ppmm(w1, w0, u, v) \
6777 + __asm__ ("umul %2,%3,%1;rd %%y,%0" \
6778 + : "=r" ((USItype) (w1)), \
6779 + "=r" ((USItype) (w0)) \
6780 + : "r" ((USItype) (u)), \
6781 + "r" ((USItype) (v)))
6782 +#define udiv_qrnnd(q, r, n1, n0, d) \
6783 + __asm__ ("! Inlined udiv_qrnnd\n" \
6784 +" wr %%g0,%2,%%y ! Not a delayed write for sparclite\n" \
6786 +" divscc %3,%4,%%g1\n" \
6787 +" divscc %%g1,%4,%%g1\n" \
6788 +" divscc %%g1,%4,%%g1\n" \
6789 +" divscc %%g1,%4,%%g1\n" \
6790 +" divscc %%g1,%4,%%g1\n" \
6791 +" divscc %%g1,%4,%%g1\n" \
6792 +" divscc %%g1,%4,%%g1\n" \
6793 +" divscc %%g1,%4,%%g1\n" \
6794 +" divscc %%g1,%4,%%g1\n" \
6795 +" divscc %%g1,%4,%%g1\n" \
6796 +" divscc %%g1,%4,%%g1\n" \
6797 +" divscc %%g1,%4,%%g1\n" \
6798 +" divscc %%g1,%4,%%g1\n" \
6799 +" divscc %%g1,%4,%%g1\n" \
6800 +" divscc %%g1,%4,%%g1\n" \
6801 +" divscc %%g1,%4,%%g1\n" \
6802 +" divscc %%g1,%4,%%g1\n" \
6803 +" divscc %%g1,%4,%%g1\n" \
6804 +" divscc %%g1,%4,%%g1\n" \
6805 +" divscc %%g1,%4,%%g1\n" \
6806 +" divscc %%g1,%4,%%g1\n" \
6807 +" divscc %%g1,%4,%%g1\n" \
6808 +" divscc %%g1,%4,%%g1\n" \
6809 +" divscc %%g1,%4,%%g1\n" \
6810 +" divscc %%g1,%4,%%g1\n" \
6811 +" divscc %%g1,%4,%%g1\n" \
6812 +" divscc %%g1,%4,%%g1\n" \
6813 +" divscc %%g1,%4,%%g1\n" \
6814 +" divscc %%g1,%4,%%g1\n" \
6815 +" divscc %%g1,%4,%%g1\n" \
6816 +" divscc %%g1,%4,%%g1\n" \
6817 +" divscc %%g1,%4,%0\n" \
6820 +" add %1,%4,%1\n" \
6821 +"1: ! End of inline udiv_qrnnd" \
6822 + : "=r" ((USItype) (q)), \
6823 + "=r" ((USItype) (r)) \
6824 + : "r" ((USItype) (n1)), \
6825 + "r" ((USItype) (n0)), \
6826 + "rI" ((USItype) (d)) \
6827 + : "g1" __AND_CLOBBER_CC)
6828 +#define UDIV_TIME 37
6829 +#define count_leading_zeros(count, x) \
6831 + __asm__ ("scan %1,1,%0" \
6832 + : "=r" ((USItype) (count)) \
6833 + : "r" ((USItype) (x))); \
6835 +/* Early sparclites return 63 for an argument of 0, but they warn that future
6836 + implementations might change this. Therefore, leave COUNT_LEADING_ZEROS_0
6839 +/* SPARC without integer multiplication and divide instructions.
6840 + (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
6841 +#define umul_ppmm(w1, w0, u, v) \
6842 + __asm__ ("! Inlined umul_ppmm\n" \
6843 +" wr %%g0,%2,%%y ! SPARC has 0-3 delay insn after a wr\n"\
6844 +" sra %3,31,%%o5 ! Don't move this insn\n" \
6845 +" and %2,%%o5,%%o5 ! Don't move this insn\n" \
6846 +" andcc %%g0,0,%%g1 ! Don't move this insn\n" \
6847 +" mulscc %%g1,%3,%%g1\n" \
6848 +" mulscc %%g1,%3,%%g1\n" \
6849 +" mulscc %%g1,%3,%%g1\n" \
6850 +" mulscc %%g1,%3,%%g1\n" \
6851 +" mulscc %%g1,%3,%%g1\n" \
6852 +" mulscc %%g1,%3,%%g1\n" \
6853 +" mulscc %%g1,%3,%%g1\n" \
6854 +" mulscc %%g1,%3,%%g1\n" \
6855 +" mulscc %%g1,%3,%%g1\n" \
6856 +" mulscc %%g1,%3,%%g1\n" \
6857 +" mulscc %%g1,%3,%%g1\n" \
6858 +" mulscc %%g1,%3,%%g1\n" \
6859 +" mulscc %%g1,%3,%%g1\n" \
6860 +" mulscc %%g1,%3,%%g1\n" \
6861 +" mulscc %%g1,%3,%%g1\n" \
6862 +" mulscc %%g1,%3,%%g1\n" \
6863 +" mulscc %%g1,%3,%%g1\n" \
6864 +" mulscc %%g1,%3,%%g1\n" \
6865 +" mulscc %%g1,%3,%%g1\n" \
6866 +" mulscc %%g1,%3,%%g1\n" \
6867 +" mulscc %%g1,%3,%%g1\n" \
6868 +" mulscc %%g1,%3,%%g1\n" \
6869 +" mulscc %%g1,%3,%%g1\n" \
6870 +" mulscc %%g1,%3,%%g1\n" \
6871 +" mulscc %%g1,%3,%%g1\n" \
6872 +" mulscc %%g1,%3,%%g1\n" \
6873 +" mulscc %%g1,%3,%%g1\n" \
6874 +" mulscc %%g1,%3,%%g1\n" \
6875 +" mulscc %%g1,%3,%%g1\n" \
6876 +" mulscc %%g1,%3,%%g1\n" \
6877 +" mulscc %%g1,%3,%%g1\n" \
6878 +" mulscc %%g1,%3,%%g1\n" \
6879 +" mulscc %%g1,0,%%g1\n" \
6880 +" add %%g1,%%o5,%0\n" \
6882 + : "=r" ((USItype) (w1)), \
6883 + "=r" ((USItype) (w0)) \
6884 + : "%rI" ((USItype) (u)), \
6885 + "r" ((USItype) (v)) \
6886 + : "g1", "o5" __AND_CLOBBER_CC)
6887 +#define UMUL_TIME 39 /* 39 instructions */
6888 +/* It's quite necessary to add this much assembler for the sparc.
6889 + The default udiv_qrnnd (in C) is more than 10 times slower! */
6890 +#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
6891 + __asm__ ("! Inlined udiv_qrnnd\n" \
6893 +" subcc %1,%2,%%g0\n" \
6895 +" addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
6896 +" sub %1,%2,%1 ! this kills msb of n\n" \
6897 +" addx %1,%1,%1 ! so this can't give carry\n" \
6898 +" subcc %%g1,1,%%g1\n" \
6900 +" subcc %1,%2,%%g0\n" \
6902 +" addxcc %0,%0,%0 ! shift n1n0 and a q-bit in lsb\n" \
6904 +" sub %1,%2,%1 ! this kills msb of n\n" \
6905 +"4: sub %1,%2,%1\n" \
6906 +"5: addxcc %1,%1,%1\n" \
6908 +" subcc %%g1,1,%%g1\n" \
6909 +"! Got carry from n. Subtract next step to cancel this carry.\n" \
6911 +" addcc %0,%0,%0 ! shift n1n0 and a 0-bit in lsb\n" \
6912 +" sub %1,%2,%1\n" \
6913 +"3: xnor %0,0,%0\n" \
6914 +" ! End of inline udiv_qrnnd" \
6915 + : "=&r" ((USItype) (__q)), \
6916 + "=&r" ((USItype) (__r)) \
6917 + : "r" ((USItype) (__d)), \
6918 + "1" ((USItype) (__n1)), \
6919 + "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
6920 +#define UDIV_TIME (3+7*32) /* 7 instructions/iteration. 32 iterations. */
6921 +#endif /* __sparclite__ */
6922 +#endif /* __sparc_v8__ */
6923 +#endif /* sparc32 */
6925 +#if ((defined (__sparc__) && defined (__arch64__)) || defined (__sparcv9)) \
6926 + && W_TYPE_SIZE == 64
6927 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6928 + __asm__ ("addcc %r4,%5,%1\n\t" \
6929 + "add %r2,%3,%0\n\t" \
6930 + "bcs,a,pn %%xcc, 1f\n\t" \
6931 + "add %0, 1, %0\n" \
6933 + : "=r" ((UDItype)(sh)), \
6934 + "=&r" ((UDItype)(sl)) \
6935 + : "%rJ" ((UDItype)(ah)), \
6936 + "rI" ((UDItype)(bh)), \
6937 + "%rJ" ((UDItype)(al)), \
6938 + "rI" ((UDItype)(bl)) \
6941 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
6942 + __asm__ ("subcc %r4,%5,%1\n\t" \
6943 + "sub %r2,%3,%0\n\t" \
6944 + "bcs,a,pn %%xcc, 1f\n\t" \
6945 + "sub %0, 1, %0\n\t" \
6947 + : "=r" ((UDItype)(sh)), \
6948 + "=&r" ((UDItype)(sl)) \
6949 + : "rJ" ((UDItype)(ah)), \
6950 + "rI" ((UDItype)(bh)), \
6951 + "rJ" ((UDItype)(al)), \
6952 + "rI" ((UDItype)(bl)) \
6955 +#define umul_ppmm(wh, wl, u, v) \
6957 + UDItype tmp1, tmp2, tmp3, tmp4; \
6958 + __asm__ __volatile__ ( \
6959 + "srl %7,0,%3\n\t" \
6960 + "mulx %3,%6,%1\n\t" \
6961 + "srlx %6,32,%2\n\t" \
6962 + "mulx %2,%3,%4\n\t" \
6963 + "sllx %4,32,%5\n\t" \
6964 + "srl %6,0,%3\n\t" \
6965 + "sub %1,%5,%5\n\t" \
6966 + "srlx %5,32,%5\n\t" \
6967 + "addcc %4,%5,%4\n\t" \
6968 + "srlx %7,32,%5\n\t" \
6969 + "mulx %3,%5,%3\n\t" \
6970 + "mulx %2,%5,%5\n\t" \
6971 + "sethi %%hi(0x80000000),%2\n\t" \
6972 + "addcc %4,%3,%4\n\t" \
6973 + "srlx %4,32,%4\n\t" \
6974 + "add %2,%2,%2\n\t" \
6975 + "movcc %%xcc,%%g0,%2\n\t" \
6976 + "addcc %5,%4,%5\n\t" \
6977 + "sllx %3,32,%3\n\t" \
6978 + "add %1,%3,%1\n\t" \
6980 + : "=r" ((UDItype)(wh)), \
6981 + "=&r" ((UDItype)(wl)), \
6982 + "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4) \
6983 + : "r" ((UDItype)(u)), \
6984 + "r" ((UDItype)(v)) \
6987 +#define UMUL_TIME 96
6988 +#define UDIV_TIME 230
6989 +#endif /* sparc64 */
6991 +#if defined (__vax__) && W_TYPE_SIZE == 32
6992 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
6993 + __asm__ ("addl2 %5,%1\n\tadwc %3,%0" \
6994 + : "=g" ((USItype) (sh)), \
6995 + "=&g" ((USItype) (sl)) \
6996 + : "%0" ((USItype) (ah)), \
6997 + "g" ((USItype) (bh)), \
6998 + "%1" ((USItype) (al)), \
6999 + "g" ((USItype) (bl)))
7000 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
7001 + __asm__ ("subl2 %5,%1\n\tsbwc %3,%0" \
7002 + : "=g" ((USItype) (sh)), \
7003 + "=&g" ((USItype) (sl)) \
7004 + : "0" ((USItype) (ah)), \
7005 + "g" ((USItype) (bh)), \
7006 + "1" ((USItype) (al)), \
7007 + "g" ((USItype) (bl)))
7008 +#define umul_ppmm(xh, xl, m0, m1) \
7012 + struct {USItype __l, __h;} __i; \
7014 + USItype __m0 = (m0), __m1 = (m1); \
7015 + __asm__ ("emul %1,%2,$0,%0" \
7016 + : "=r" (__xx.__ll) \
7019 + (xh) = __xx.__i.__h; \
7020 + (xl) = __xx.__i.__l; \
7021 + (xh) += ((((SItype) __m0 >> 31) & __m1) \
7022 + + (((SItype) __m1 >> 31) & __m0)); \
7024 +#define sdiv_qrnnd(q, r, n1, n0, d) \
7026 + union {DItype __ll; \
7027 + struct {SItype __l, __h;} __i; \
7029 + __xx.__i.__h = n1; __xx.__i.__l = n0; \
7030 + __asm__ ("ediv %3,%2,%0,%1" \
7031 + : "=g" (q), "=g" (r) \
7032 + : "g" (__xx.__ll), "g" (d)); \
7034 +#endif /* __vax__ */
7036 +#if defined (__z8000__) && W_TYPE_SIZE == 16
7037 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
7038 + __asm__ ("add %H1,%H5\n\tadc %H0,%H3" \
7039 + : "=r" ((unsigned int)(sh)), \
7040 + "=&r" ((unsigned int)(sl)) \
7041 + : "%0" ((unsigned int)(ah)), \
7042 + "r" ((unsigned int)(bh)), \
7043 + "%1" ((unsigned int)(al)), \
7044 + "rQR" ((unsigned int)(bl)))
7045 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
7046 + __asm__ ("sub %H1,%H5\n\tsbc %H0,%H3" \
7047 + : "=r" ((unsigned int)(sh)), \
7048 + "=&r" ((unsigned int)(sl)) \
7049 + : "0" ((unsigned int)(ah)), \
7050 + "r" ((unsigned int)(bh)), \
7051 + "1" ((unsigned int)(al)), \
7052 + "rQR" ((unsigned int)(bl)))
7053 +#define umul_ppmm(xh, xl, m0, m1) \
7055 + union {long int __ll; \
7056 + struct {unsigned int __h, __l;} __i; \
7058 + unsigned int __m0 = (m0), __m1 = (m1); \
7059 + __asm__ ("mult %S0,%H3" \
7060 + : "=r" (__xx.__i.__h), \
7061 + "=r" (__xx.__i.__l) \
7064 + (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
7065 + (xh) += ((((signed int) __m0 >> 15) & __m1) \
7066 + + (((signed int) __m1 >> 15) & __m0)); \
7068 +#endif /* __z8000__ */
7070 +#endif /* __GNUC__ */
7072 +/* If this machine has no inline assembler, use C macros. */
7074 +#if !defined (add_ssaaaa)
7075 +#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
7078 + __x = (al) + (bl); \
7079 + (sh) = (ah) + (bh) + (__x < (al)); \
7084 +#if !defined (sub_ddmmss)
7085 +#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
7088 + __x = (al) - (bl); \
7089 + (sh) = (ah) - (bh) - (__x > (al)); \
7094 +/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
7096 +#if !defined (umul_ppmm) && defined (smul_ppmm)
7097 +#define umul_ppmm(w1, w0, u, v) \
7100 + UWtype __xm0 = (u), __xm1 = (v); \
7101 + smul_ppmm (__w1, w0, __xm0, __xm1); \
7102 + (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1) \
7103 + + (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0); \
7107 +/* If we still don't have umul_ppmm, define it using plain C. */
7108 +#if !defined (umul_ppmm)
7109 +#define umul_ppmm(w1, w0, u, v) \
7111 + UWtype __x0, __x1, __x2, __x3; \
7112 + UHWtype __ul, __vl, __uh, __vh; \
7114 + __ul = __ll_lowpart (u); \
7115 + __uh = __ll_highpart (u); \
7116 + __vl = __ll_lowpart (v); \
7117 + __vh = __ll_highpart (v); \
7119 + __x0 = (UWtype) __ul * __vl; \
7120 + __x1 = (UWtype) __ul * __vh; \
7121 + __x2 = (UWtype) __uh * __vl; \
7122 + __x3 = (UWtype) __uh * __vh; \
7124 + __x1 += __ll_highpart (__x0);/* this can't give carry */ \
7125 + __x1 += __x2; /* but this indeed can */ \
7126 + if (__x1 < __x2) /* did we get it? */ \
7127 + __x3 += __ll_B; /* yes, add it in the proper pos. */ \
7129 + (w1) = __x3 + __ll_highpart (__x1); \
7130 + (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
7134 +#if !defined (__umulsidi3)
7135 +#define __umulsidi3(u, v) \
7137 + umul_ppmm (__w.s.high, __w.s.low, u, v); \
7141 +/* Define this unconditionally, so it can be used for debugging. */
7142 +#define __udiv_qrnnd_c(q, r, n1, n0, d) \
7144 + UWtype __d1, __d0, __q1, __q0; \
7145 + UWtype __r1, __r0, __m; \
7146 + __d1 = __ll_highpart (d); \
7147 + __d0 = __ll_lowpart (d); \
7149 + __r1 = (n1) % __d1; \
7150 + __q1 = (n1) / __d1; \
7151 + __m = (UWtype) __q1 * __d0; \
7152 + __r1 = __r1 * __ll_B | __ll_highpart (n0); \
7155 + __q1--, __r1 += (d); \
7156 + if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
7158 + __q1--, __r1 += (d); \
7162 + __r0 = __r1 % __d1; \
7163 + __q0 = __r1 / __d1; \
7164 + __m = (UWtype) __q0 * __d0; \
7165 + __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
7168 + __q0--, __r0 += (d); \
7169 + if (__r0 >= (d)) \
7171 + __q0--, __r0 += (d); \
7175 + (q) = (UWtype) __q1 * __ll_B | __q0; \
7179 +/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
7180 + __udiv_w_sdiv (defined in libgcc or elsewhere). */
7181 +#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
7182 +#define udiv_qrnnd(q, r, nh, nl, d) \
7185 + (q) = __udiv_w_sdiv (&__r, nh, nl, d); \
7190 +/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
7191 +#if !defined (udiv_qrnnd)
7192 +#define UDIV_NEEDS_NORMALIZATION 1
7193 +#define udiv_qrnnd __udiv_qrnnd_c
7196 +#if !defined (count_leading_zeros)
7197 +extern const UQItype __clz_tab[] ATTRIBUTE_HIDDEN;
7198 +#define count_leading_zeros(count, x) \
7200 + UWtype __xr = (x); \
7203 + if (W_TYPE_SIZE <= 32) \
7205 + __a = __xr < ((UWtype)1<<2*__BITS4) \
7206 + ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4) \
7207 + : (__xr < ((UWtype)1<<3*__BITS4) ? 2*__BITS4 : 3*__BITS4); \
7211 + for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
7212 + if (((__xr >> __a) & 0xff) != 0) \
7216 + (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
7218 +#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
7221 +#if !defined (count_trailing_zeros)
7222 +/* Define count_trailing_zeros using count_leading_zeros. The latter might be
7223 + defined in asm, but if it is not, the C version above is good enough. */
7224 +#define count_trailing_zeros(count, x) \
7226 + UWtype __ctz_x = (x); \
7228 + count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
7229 + (count) = W_TYPE_SIZE - 1 - __ctz_c; \
7233 +#ifndef UDIV_NEEDS_NORMALIZATION
7234 +#define UDIV_NEEDS_NORMALIZATION 0