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,