📄 900-nios2.patch
字号:
+#else+#define ATTRIBUTE_HIDDEN+#endif++#include "libgcc2.h"++#else+#define SItype int+#define USItype unsigned int+#endif+++extern SItype __mulsi3 (SItype, SItype);++SItype+__mulsi3 (SItype a, SItype b)+{+ SItype res = 0;+ USItype cnt = a;+ + while (cnt)+ {+ if (cnt & 1)+ {+ res += b; + }+ b <<= 1;+ cnt >>= 1;+ }+ + return res;+}+/*+TODO: Choose best alternative implementation.++SItype+__divsi3 (SItype a, SItype b)+{+ SItype res = 0;+ USItype cnt = 0;+ + while (cnt < 32)+ {+ if (a & (1L << cnt))+ {+ res += b; + }+ b <<= 1;+ cnt++;+ }+ + return res;+}+*/+++#ifdef DEBUG_MULSI3++int+main ()+{+ int i, j;+ int error = 0;+ + for (i = -1000; i < 1000; i++)+ for (j = -1000; j < 1000; j++)+ {+ int expect = i * j;+ int actual = A__divsi3 (i, j);+ if (expect != actual)+ {+ printf ("error: %d * %d = %d not %d\n", i, j, expect, actual);+ error = 1;+ }+ }++ return error;+}+#endif--- gcc-3.4.3/gcc/config/nios2/nios2-dp-bit.c+++ gcc-3.4.3-nios2/gcc/config/nios2/nios2-dp-bit.c@@ -0,0 +1,1652 @@++/* This is a software floating point library which can be used+ for targets without hardware floating point. + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004+ Free Software Foundation, Inc.++This file is free software; you can redistribute it and/or modify it+under the terms of the GNU General Public License as published by the+Free Software Foundation; either version 2, or (at your option) any+later version.++In addition to the permissions in the GNU General Public License, the+Free Software Foundation gives you unlimited permission to link the+compiled version of this file with other programs, and to distribute+those programs without any restriction coming from the use of this+file. (The General Public License restrictions do apply in other+respects; for example, they cover modification of the file, and+distribution when not linked into another program.)++This file is distributed in the hope that it will be useful, but+WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program; see the file COPYING. If not, write to+the Free Software Foundation, 59 Temple Place - Suite 330,+Boston, MA 02111-1307, USA. */++/* As a special exception, if you link this library with other files,+ some of which are compiled with GCC, to produce an executable,+ this library does not by itself cause the resulting executable+ to be covered by the GNU General Public License.+ This exception does not however invalidate any other reasons why+ the executable file might be covered by the GNU General Public License. */++/* This implements IEEE 754 format arithmetic, but does not provide a+ mechanism for setting the rounding mode, or for generating or handling+ exceptions.++ The original code by Steve Chamberlain, hacked by Mark Eichin and Jim+ Wilson, all of Cygnus Support. */++/* The intended way to use this file is to make two copies, add `#define FLOAT'+ to one copy, then compile both copies and add them to libgcc.a. */++#include "tconfig.h"+#include "coretypes.h"+#include "tm.h"+#include "config/fp-bit.h"++/* The following macros can be defined to change the behavior of this file:+ FLOAT: Implement a `float', aka SFmode, fp library. If this is not+ defined, then this file implements a `double', aka DFmode, fp library.+ FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.+ don't include float->double conversion which requires the double library.+ This is useful only for machines which can't support doubles, e.g. some+ 8-bit processors.+ CMPtype: Specify the type that floating point compares should return.+ This defaults to SItype, aka int.+ US_SOFTWARE_GOFAST: This makes all entry points use the same names as the+ US Software goFast library.+ _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding+ two integers to the FLO_union_type.+ NO_DENORMALS: Disable handling of denormals.+ NO_NANS: Disable nan and infinity handling+ SMALL_MACHINE: Useful when operations on QIs and HIs are faster+ than on an SI */++/* We don't currently support extended floats (long doubles) on machines+ without hardware to deal with them.++ These stubs are just to keep the linker from complaining about unresolved+ references which can be pulled in from libio & libstdc++, even if the+ user isn't using long doubles. However, they may generate an unresolved+ external to abort if abort is not used by the function, and the stubs+ are referenced from within libc, since libgcc goes before and after the+ system library. */++#ifdef DECLARE_LIBRARY_RENAMES+ DECLARE_LIBRARY_RENAMES+#endif++#ifdef EXTENDED_FLOAT_STUBS+extern void abort (void);+void __extendsfxf2 (void) { abort(); }+void __extenddfxf2 (void) { abort(); }+void __truncxfdf2 (void) { abort(); }+void __truncxfsf2 (void) { abort(); }+void __fixxfsi (void) { abort(); }+void __floatsixf (void) { abort(); }+void __addxf3 (void) { abort(); }+void __subxf3 (void) { abort(); }+void __mulxf3 (void) { abort(); }+void __divxf3 (void) { abort(); }+void __negxf2 (void) { abort(); }+void __eqxf2 (void) { abort(); }+void __nexf2 (void) { abort(); }+void __gtxf2 (void) { abort(); }+void __gexf2 (void) { abort(); }+void __lexf2 (void) { abort(); }+void __ltxf2 (void) { abort(); }++void __extendsftf2 (void) { abort(); }+void __extenddftf2 (void) { abort(); }+void __trunctfdf2 (void) { abort(); }+void __trunctfsf2 (void) { abort(); }+void __fixtfsi (void) { abort(); }+void __floatsitf (void) { abort(); }+void __addtf3 (void) { abort(); }+void __subtf3 (void) { abort(); }+void __multf3 (void) { abort(); }+void __divtf3 (void) { abort(); }+void __negtf2 (void) { abort(); }+void __eqtf2 (void) { abort(); }+void __netf2 (void) { abort(); }+void __gttf2 (void) { abort(); }+void __getf2 (void) { abort(); }+void __letf2 (void) { abort(); }+void __lttf2 (void) { abort(); }+#else /* !EXTENDED_FLOAT_STUBS, rest of file */++/* IEEE "special" number predicates */++#ifdef NO_NANS++#define nan() 0+#define isnan(x) 0+#define isinf(x) 0+#else++#if defined L_thenan_sf+const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };+#elif defined L_thenan_df+const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };+#elif defined L_thenan_tf+const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };+#elif defined TFLOAT+extern const fp_number_type __thenan_tf;+#elif defined FLOAT+extern const fp_number_type __thenan_sf;+#else+extern const fp_number_type __thenan_df;+#endif++INLINE+static fp_number_type *+nan (void)+{+ /* Discard the const qualifier... */+#ifdef TFLOAT+ return (fp_number_type *) (& __thenan_tf);+#elif defined FLOAT + return (fp_number_type *) (& __thenan_sf);+#else+ return (fp_number_type *) (& __thenan_df);+#endif+}++INLINE+static int+isnan ( fp_number_type * x)+{+ return x->class == CLASS_SNAN || x->class == CLASS_QNAN;+}++INLINE+static int+isinf ( fp_number_type * x)+{+ return x->class == CLASS_INFINITY;+}++#endif /* NO_NANS */++INLINE+static int+iszero ( fp_number_type * x)+{+ return x->class == CLASS_ZERO;+}++INLINE +static void+flip_sign ( fp_number_type * x)+{+ x->sign = !x->sign;+}++extern FLO_type pack_d ( fp_number_type * );++#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)+FLO_type+pack_d ( fp_number_type * src)+{+ FLO_union_type dst;+ fractype fraction = src->fraction.ll; /* wasn't unsigned before? */+ int sign = src->sign;+ int exp = 0;++ if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))+ {+ /* We can't represent these values accurately. By using the+ largest possible magnitude, we guarantee that the conversion+ of infinity is at least as big as any finite number. */+ exp = EXPMAX;+ fraction = ((fractype) 1 << FRACBITS) - 1;+ }+ else if (isnan (src))+ {+ exp = EXPMAX;+ if (src->class == CLASS_QNAN || 1)+ {+#ifdef QUIET_NAN_NEGATED+ fraction |= QUIET_NAN - 1;+#else+ fraction |= QUIET_NAN;+#endif+ }+ }+ else if (isinf (src))+ {+ exp = EXPMAX;+ fraction = 0;+ }+ else if (iszero (src))+ {+ exp = 0;+ fraction = 0;+ }+ else if (fraction == 0)+ {+ exp = 0;+ }+ else+ {+ if (src->normal_exp < NORMAL_EXPMIN)+ {+#ifdef NO_DENORMALS+ /* Go straight to a zero representation if denormals are not+ supported. The denormal handling would be harmless but+ isn't unnecessary. */+ exp = 0;+ fraction = 0;+#else /* NO_DENORMALS */+ /* This number's exponent is too low to fit into the bits+ available in the number, so we'll store 0 in the exponent and+ shift the fraction to the right to make up for it. */++ int shift = NORMAL_EXPMIN - src->normal_exp;++ exp = 0;++ if (shift > FRAC_NBITS - NGARDS)+ {+ /* No point shifting, since it's more that 64 out. */+ fraction = 0;+ }+ else+ {+ int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;+ fraction = (fraction >> shift) | lowbit;+ }+ if ((fraction & GARDMASK) == GARDMSB)+ {+ if ((fraction & (1 << NGARDS)))+ fraction += GARDROUND + 1;+ }+ else+ {+ /* Add to the guards to round up. */+ fraction += GARDROUND;+ }+ /* Perhaps the rounding means we now need to change the+ exponent, because the fraction is no longer denormal. */+ if (fraction >= IMPLICIT_1)+ {+ exp += 1;+ }+ fraction >>= NGARDS;+#endif /* NO_DENORMALS */+ }+ else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)+ && src->normal_exp > EXPBIAS)+ {+ exp = EXPMAX;+ fraction = 0;+ }+ else+ {+ exp = src->normal_exp + EXPBIAS;+ if (!ROUND_TOWARDS_ZERO)+ {+ /* IF the gard bits are the all zero, but the first, then we're+ half way between two numbers, choose the one which makes the+ lsb of the answer 0. */+ if ((fraction & GARDMASK) == GARDMSB)+ {+ if (fraction & (1 << NGARDS))+ fraction += GARDROUND + 1;+ }+ else+ {+ /* Add a one to the guards to round up */+ fraction += GARDROUND;+ }+ if (fraction >= IMPLICIT_2)+ {+ fraction >>= 1;+ exp += 1;+ }+ }+ fraction >>= NGARDS;++ if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)+ {+ /* Saturate on overflow. */+ exp = EXPMAX;+ fraction = ((fractype) 1 << FRACBITS) - 1;+ }+ }+ }++ /* We previously used bitfields to store the number, but this doesn't+ handle little/big endian systems conveniently, so use shifts and+ masks */+#ifdef FLOAT_BIT_ORDER_MISMATCH+ dst.bits.fraction = fraction;+ dst.bits.exp = exp;+ dst.bits.sign = sign;+#else+# if defined TFLOAT && defined HALFFRACBITS+ {+ halffractype high, low, unity;+ int lowsign, lowexp;++ unity = (halffractype) 1 << HALFFRACBITS;++ /* Set HIGH to the high double's significand, masking out the implicit 1.+ Set LOW to the low double's full significand. */+ high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);+ low = fraction & (unity * 2 - 1);++ /* Get the initial sign and exponent of the low double. */+ lowexp = exp - HALFFRACBITS - 1;+ lowsign = sign;++ /* HIGH should be rounded like a normal double, making |LOW| <=+ 0.5 ULP of HIGH. Assume round-to-nearest. */+ if (exp < EXPMAX)+ if (low > unity || (low == unity && (high & 1) == 1))+ {+ /* Round HIGH up and adjust LOW to match. */+ high++;+ if (high == unity)+ {+ /* May make it infinite, but that's OK. */+ high = 0;+ exp++;+ }+ low = unity * 2 - low;+ lowsign ^= 1;+ }++ high |= (halffractype) exp << HALFFRACBITS;+ high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);++ if (exp == EXPMAX || exp == 0 || low == 0)+ low = 0;+ else+ {+ while (lowexp > 0 && low < unity)+ {+ low <<= 1;+ lowexp--;+ }++ if (lowexp <= 0)+ {+ halffractype roundmsb, round;+ int shift;++ shift = 1 - lowexp;+ roundmsb = (1 << (shift - 1));+ round = low & ((roundmsb << 1) - 1);++ low >>= shift;+ lowexp = 0;++ if (round > roundmsb || (round == roundmsb && (low & 1) == 1))+ {+ low++;+ if (low == unity)+ /* LOW rounds up to the smallest normal number. */+ lowexp++;+ }+ }++ low &= unity - 1;+ low |= (halffractype) lowexp << HALFFRACBITS;+ low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);+ }+ dst.value_raw = ((fractype) high << HALFSHIFT) | low;+ }+# else+ dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);+ dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;+ dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);+# endif+#endif++#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)+#ifdef TFLOAT+ {+ qrtrfractype tmp1 = dst.words[0];+ qrtrfractype tmp2 = dst.words[1];+ dst.words[0] = dst.words[3];+ dst.words[1] = dst.words[2];+ dst.words[2] = tmp2;+ dst.words[3] = tmp1;+ }+#else+ {+ halffractype tmp = dst.words[0];+ dst.words[0] = dst.words[1];+ dst.words[1] = tmp;+ }+#endif+#endif++ return dst.value;+}+#endif++#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)+void+unpack_d (FLO_union_type * src, fp_number_type * dst)+{+ /* We previously used bitfields to store the number, but this doesn't+ handle little/big endian systems conveniently, so use shifts and+ masks */+ fractype fraction;+ int exp;+ int sign;++#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)+ FLO_union_type swapped;++#ifdef TFLOAT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -