1 /* This is a software floating point library which can be used instead of
2 the floating point routines in libgcc1.c for targets without hardware
4 Copyright (C) 1994-1998, 2000 Free Software Foundation, Inc.
6 This file is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file with other programs, and to distribute
14 those programs without any restriction coming from the use of this
15 file. (The General Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into another program.)
19 This file is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
29 /* As a special exception, if you link this library with other files,
30 some of which are compiled with GCC, to produce an executable,
31 this library does not by itself cause the resulting executable
32 to be covered by the GNU General Public License.
33 This exception does not however invalidate any other reasons why
34 the executable file might be covered by the GNU General Public License. */
36 /* This implements IEEE 754 format arithmetic, but does not provide a
37 mechanism for setting the rounding mode, or for generating or handling
40 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
41 Wilson, all of Cygnus Support. */
43 /* The intended way to use this file is to make two copies, add `#define FLOAT'
44 to one copy, then compile both copies and add them to libgcc.a. */
46 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
47 from this file are compiled via additional -D options.
49 This avoids the need to pull in the entire fp emulation library
50 when only a small number of functions are needed.
52 If FINE_GRAINED_LIBRARIES is not defined, then compile every
54 #ifndef FINE_GRAINED_LIBRARIES
65 #define L_fpcmp_parts_sf
66 #define L_fpcmp_parts_df
102 /* The following macros can be defined to change the behaviour of this file:
103 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
104 defined, then this file implements a `double', aka DFmode, fp library.
105 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
106 don't include float->double conversion which requires the double library.
107 This is useful only for machines which can't support doubles, e.g. some
109 CMPtype: Specify the type that floating point compares should return.
110 This defaults to SItype, aka int.
111 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
112 US Software goFast library. If this is not defined, the entry points use
113 the same names as libgcc1.c.
114 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
115 two integers to the FLO_union_type.
116 NO_NANS: Disable nan and infinity handling
117 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
120 /* We don't currently support extended floats (long doubles) on machines
121 without hardware to deal with them.
123 These stubs are just to keep the linker from complaining about unresolved
124 references which can be pulled in from libio & libstdc++, even if the
125 user isn't using long doubles. However, they may generate an unresolved
126 external to abort if abort is not used by the function, and the stubs
127 are referenced from within libc, since libgcc goes before and after the
130 #ifdef EXTENDED_FLOAT_STUBS
131 __truncxfsf2 (){ abort(); }
132 __extendsfxf2 (){ abort(); }
133 __addxf3 (){ abort(); }
134 __divxf3 (){ abort(); }
135 __eqxf2 (){ abort(); }
136 __extenddfxf2 (){ abort(); }
137 __gtxf2 (){ abort(); }
138 __lexf2 (){ abort(); }
139 __ltxf2 (){ abort(); }
140 __mulxf3 (){ abort(); }
141 __negxf2 (){ abort(); }
142 __nexf2 (){ abort(); }
143 __subxf3 (){ abort(); }
144 __truncxfdf2 (){ abort(); }
146 __trunctfsf2 (){ abort(); }
147 __extendsftf2 (){ abort(); }
148 __addtf3 (){ abort(); }
149 __divtf3 (){ abort(); }
150 __eqtf2 (){ abort(); }
151 __extenddftf2 (){ abort(); }
152 __gttf2 (){ abort(); }
153 __letf2 (){ abort(); }
154 __lttf2 (){ abort(); }
155 __multf3 (){ abort(); }
156 __negtf2 (){ abort(); }
157 __netf2 (){ abort(); }
158 __subtf3 (){ abort(); }
159 __trunctfdf2 (){ abort(); }
160 __gexf2 (){ abort(); }
161 __fixxfsi (){ abort(); }
162 __floatsixf (){ abort(); }
163 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
166 typedef float SFtype __attribute__ ((mode (SF)));
167 typedef float DFtype __attribute__ ((mode (DF)));
169 typedef int HItype __attribute__ ((mode (HI)));
170 typedef int SItype __attribute__ ((mode (SI)));
171 typedef int DItype __attribute__ ((mode (DI)));
173 /* The type of the result of a fp compare */
175 #define CMPtype SItype
178 typedef unsigned int UHItype __attribute__ ((mode (HI)));
179 typedef unsigned int USItype __attribute__ ((mode (SI)));
180 typedef unsigned int UDItype __attribute__ ((mode (DI)));
182 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
183 #define MAX_USI_INT ((USItype) ~0)
192 # define GARDROUND 0x3f
193 # define GARDMASK 0x7f
194 # define GARDMSB 0x40
198 # define EXPMAX (0xff)
199 # define QUIET_NAN 0x100000L
200 # define FRAC_NBITS 32
201 # define FRACHIGH 0x80000000L
202 # define FRACHIGH2 0xc0000000L
203 # define pack_d __pack_f
204 # define unpack_d __unpack_f
205 # define __fpcmp_parts __fpcmp_parts_f
206 typedef USItype fractype;
207 typedef UHItype halffractype;
208 typedef SFtype FLO_type;
209 typedef SItype intfrac;
212 # define PREFIXFPDP dp
213 # define PREFIXSFDF df
215 # define GARDROUND 0x7f
216 # define GARDMASK 0xff
217 # define GARDMSB 0x80
219 # define EXPBIAS 1023
221 # define EXPMAX (0x7ff)
222 # define QUIET_NAN 0x8000000000000LL
223 # define FRAC_NBITS 64
224 # define FRACHIGH 0x8000000000000000LL
225 # define FRACHIGH2 0xc000000000000000LL
226 # define pack_d __pack_d
227 # define unpack_d __unpack_d
228 # define __fpcmp_parts __fpcmp_parts_d
229 typedef UDItype fractype;
230 typedef USItype halffractype;
231 typedef DFtype FLO_type;
232 typedef DItype intfrac;
235 #ifdef US_SOFTWARE_GOFAST
239 # define multiply fpmul
240 # define divide fpdiv
241 # define compare fpcmp
242 # define si_to_float sitofp
243 # define float_to_si fptosi
244 # define float_to_usi fptoui
245 # define negate __negsf2
246 # define sf_to_df fptodp
247 # define dptofp dptofp
251 # define multiply dpmul
252 # define divide dpdiv
253 # define compare dpcmp
254 # define si_to_float litodp
255 # define float_to_si dptoli
256 # define float_to_usi dptoul
257 # define negate __negdf2
258 # define df_to_sf dptofp
262 # define add __addsf3
263 # define sub __subsf3
264 # define multiply __mulsf3
265 # define divide __divsf3
266 # define compare __cmpsf2
267 # define _eq_f2 __eqsf2
268 # define _ne_f2 __nesf2
269 # define _gt_f2 __gtsf2
270 # define _ge_f2 __gesf2
271 # define _lt_f2 __ltsf2
272 # define _le_f2 __lesf2
273 # define _unord_f2 __unordsf2
274 # define si_to_float __floatsisf
275 # define float_to_si __fixsfsi
276 # define float_to_usi __fixunssfsi
277 # define negate __negsf2
278 # define sf_to_df __extendsfdf2
280 # define add __adddf3
281 # define sub __subdf3
282 # define multiply __muldf3
283 # define divide __divdf3
284 # define compare __cmpdf2
285 # define _eq_f2 __eqdf2
286 # define _ne_f2 __nedf2
287 # define _gt_f2 __gtdf2
288 # define _ge_f2 __gedf2
289 # define _lt_f2 __ltdf2
290 # define _le_f2 __ledf2
291 # define _unord_f2 __unorddf2
292 # define si_to_float __floatsidf
293 # define float_to_si __fixdfsi
294 # define float_to_usi __fixunsdfsi
295 # define negate __negdf2
296 # define df_to_sf __truncdfsf2
302 #define INLINE __inline__
305 /* Preserve the sticky-bit when shifting fractions to the right. */
306 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
308 /* numeric parameters */
309 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
310 of a float and of a double. Assumes there are only two float types.
311 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
313 #define F_D_BITOFF (52+8-(23+7))
316 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
317 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
318 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
356 halffractype words[2];
359 #ifdef FLOAT_BIT_ORDER_MISMATCH
362 fractype fraction:FRACBITS __attribute__ ((packed));
363 unsigned int exp:EXPBITS __attribute__ ((packed));
364 unsigned int sign:1 __attribute__ ((packed));
369 #ifdef _DEBUG_BITFLOAT
372 unsigned int sign:1 __attribute__ ((packed));
373 unsigned int exp:EXPBITS __attribute__ ((packed));
374 fractype fraction:FRACBITS __attribute__ ((packed));
380 fractype fraction:FRACBITS __attribute__ ((packed));
381 unsigned int exp:EXPBITS __attribute__ ((packed));
382 unsigned int sign:1 __attribute__ ((packed));
392 /* IEEE "special" number predicates */
401 #if defined L_thenan_sf
402 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, (fractype) 0 };
403 #elif defined L_thenan_df
404 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, (fractype) 0 };
406 extern const fp_number_type __thenan_sf;
408 extern const fp_number_type __thenan_df;
412 static fp_number_type *
415 /* Discard the const qualifier... */
417 return (fp_number_type *) (& __thenan_sf);
419 return (fp_number_type *) (& __thenan_df);
425 isnan ( fp_number_type * x)
427 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
432 isinf ( fp_number_type * x)
434 return x->class == CLASS_INFINITY;
441 iszero ( fp_number_type * x)
443 return x->class == CLASS_ZERO;
448 flip_sign ( fp_number_type * x)
453 extern FLO_type pack_d ( fp_number_type * );
455 #if defined(L_pack_df) || defined(L_pack_sf)
457 pack_d ( fp_number_type * src)
460 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
461 int sign = src->sign;
467 if (src->class == CLASS_QNAN || 1)
469 fraction |= QUIET_NAN;
472 else if (isinf (src))
477 else if (iszero (src))
482 else if (fraction == 0)
488 if (src->normal_exp < NORMAL_EXPMIN)
490 /* This number's exponent is too low to fit into the bits
491 available in the number, so we'll store 0 in the exponent and
492 shift the fraction to the right to make up for it. */
494 int shift = NORMAL_EXPMIN - src->normal_exp;
498 if (shift > FRAC_NBITS - NGARDS)
500 /* No point shifting, since it's more that 64 out. */
505 int lowbit = (fraction & ((1 << shift) - 1)) ? 1 : 0;
506 fraction = (fraction >> shift) | lowbit;
508 if ((fraction & GARDMASK) == GARDMSB)
510 if ((fraction & (1 << NGARDS)))
511 fraction += GARDROUND + 1;
515 /* Add to the guards to round up. */
516 fraction += GARDROUND;
518 /* Perhaps the rounding means we now need to change the
520 if (fraction >= IMPLICIT_2)
527 else if (src->normal_exp > EXPBIAS)
534 exp = src->normal_exp + EXPBIAS;
535 /* IF the gard bits are the all zero, but the first, then we're
536 half way between two numbers, choose the one which makes the
537 lsb of the answer 0. */
538 if ((fraction & GARDMASK) == GARDMSB)
540 if (fraction & (1 << NGARDS))
541 fraction += GARDROUND + 1;
545 /* Add a one to the guards to round up */
546 fraction += GARDROUND;
548 if (fraction >= IMPLICIT_2)
557 /* We previously used bitfields to store the number, but this doesn't
558 handle little/big endian systems conveniently, so use shifts and
560 #ifdef FLOAT_BIT_ORDER_MISMATCH
561 dst.bits.fraction = fraction;
563 dst.bits.sign = sign;
565 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
566 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
567 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
570 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
572 halffractype tmp = dst.words[0];
573 dst.words[0] = dst.words[1];
582 extern void unpack_d (FLO_union_type *, fp_number_type *);
584 #if defined(L_unpack_df) || defined(L_unpack_sf)
586 unpack_d (FLO_union_type * src, fp_number_type * dst)
588 /* We previously used bitfields to store the number, but this doesn't
589 handle little/big endian systems conveniently, so use shifts and
595 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
596 FLO_union_type swapped;
598 swapped.words[0] = src->words[1];
599 swapped.words[1] = src->words[0];
603 #ifdef FLOAT_BIT_ORDER_MISMATCH
604 fraction = src->bits.fraction;
606 sign = src->bits.sign;
608 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
609 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
610 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
616 /* Hmm. Looks like 0 */
619 /* tastes like zero */
620 dst->class = CLASS_ZERO;
624 /* Zero exponent with non zero fraction - it's denormalized,
625 so there isn't a leading implicit one - we'll shift it so
627 dst->normal_exp = exp - EXPBIAS + 1;
630 dst->class = CLASS_NUMBER;
632 while (fraction < IMPLICIT_1)
638 dst->fraction.ll = fraction;
641 else if (exp == EXPMAX)
646 /* Attached to a zero fraction - means infinity */
647 dst->class = CLASS_INFINITY;
651 /* Non zero fraction, means nan */
652 if (fraction & QUIET_NAN)
654 dst->class = CLASS_QNAN;
658 dst->class = CLASS_SNAN;
660 /* Keep the fraction part as the nan number */
661 dst->fraction.ll = fraction;
666 /* Nothing strange about this number */
667 dst->normal_exp = exp - EXPBIAS;
668 dst->class = CLASS_NUMBER;
669 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
674 #if defined(L_addsub_sf) || defined(L_addsub_df)
675 static fp_number_type *
676 _fpadd_parts (fp_number_type * a,
678 fp_number_type * tmp)
682 /* Put commonly used fields in local variables. */
698 /* Adding infinities with opposite signs yields a NaN. */
699 if (isinf (b) && a->sign != b->sign)
712 tmp->sign = a->sign & b->sign;
722 /* Got two numbers. shift the smaller and increment the exponent till
727 a_normal_exp = a->normal_exp;
728 b_normal_exp = b->normal_exp;
729 a_fraction = a->fraction.ll;
730 b_fraction = b->fraction.ll;
732 diff = a_normal_exp - b_normal_exp;
736 if (diff < FRAC_NBITS)
738 /* ??? This does shifts one bit at a time. Optimize. */
739 while (a_normal_exp > b_normal_exp)
744 while (b_normal_exp > a_normal_exp)
752 /* Somethings's up.. choose the biggest */
753 if (a_normal_exp > b_normal_exp)
755 b_normal_exp = a_normal_exp;
760 a_normal_exp = b_normal_exp;
766 if (a->sign != b->sign)
770 tfraction = -a_fraction + b_fraction;
774 tfraction = a_fraction - b_fraction;
779 tmp->normal_exp = a_normal_exp;
780 tmp->fraction.ll = tfraction;
785 tmp->normal_exp = a_normal_exp;
786 tmp->fraction.ll = -tfraction;
788 /* and renormalize it */
790 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
792 tmp->fraction.ll <<= 1;
799 tmp->normal_exp = a_normal_exp;
800 tmp->fraction.ll = a_fraction + b_fraction;
802 tmp->class = CLASS_NUMBER;
803 /* Now the fraction is added, we have to shift down to renormalize the
806 if (tmp->fraction.ll >= IMPLICIT_2)
808 LSHIFT (tmp->fraction.ll);
816 add (FLO_type arg_a, FLO_type arg_b)
822 FLO_union_type au, bu;
830 res = _fpadd_parts (&a, &b, &tmp);
836 sub (FLO_type arg_a, FLO_type arg_b)
842 FLO_union_type au, bu;
852 res = _fpadd_parts (&a, &b, &tmp);
858 #if defined(L_mul_sf) || defined(L_mul_df)
859 static INLINE fp_number_type *
860 _fpmul_parts ( fp_number_type * a,
862 fp_number_type * tmp)
869 a->sign = a->sign != b->sign;
874 b->sign = a->sign != b->sign;
881 a->sign = a->sign != b->sign;
890 b->sign = a->sign != b->sign;
895 a->sign = a->sign != b->sign;
900 b->sign = a->sign != b->sign;
904 /* Calculate the mantissa by multiplying both 64bit numbers to get a
907 #if defined(NO_DI_MODE)
909 fractype x = a->fraction.ll;
910 fractype ylow = b->fraction.ll;
914 /* ??? This does multiplies one bit at a time. Optimize. */
915 for (bit = 0; bit < FRAC_NBITS; bit++)
921 carry = (low += ylow) < ylow;
922 high += yhigh + carry;
935 /* Multiplying two 32 bit numbers to get a 64 bit number on
936 a machine with DI, so we're safe */
938 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
944 /* Doing a 64*64 to 128 */
946 UDItype nl = a->fraction.ll & 0xffffffff;
947 UDItype nh = a->fraction.ll >> 32;
948 UDItype ml = b->fraction.ll & 0xffffffff;
949 UDItype mh = b->fraction.ll >>32;
950 UDItype pp_ll = ml * nl;
951 UDItype pp_hl = mh * nl;
952 UDItype pp_lh = ml * nh;
953 UDItype pp_hh = mh * nh;
956 UDItype ps_hh__ = pp_hl + pp_lh;
958 res2 += 0x100000000LL;
959 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
960 res0 = pp_ll + pp_hl;
963 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
970 tmp->normal_exp = a->normal_exp + b->normal_exp;
971 tmp->sign = a->sign != b->sign;
973 tmp->normal_exp += 2; /* ??????????????? */
975 tmp->normal_exp += 4; /* ??????????????? */
977 while (high >= IMPLICIT_2)
987 while (high < IMPLICIT_1)
996 /* rounding is tricky. if we only round if it won't make us round later. */
1000 if (((high & GARDMASK) != GARDMSB)
1001 && (((high + 1) & GARDMASK) == GARDMSB))
1003 /* don't round, it gets done again later. */
1011 if ((high & GARDMASK) == GARDMSB)
1013 if (high & (1 << NGARDS))
1015 /* half way, so round to even */
1016 high += GARDROUND + 1;
1020 /* but we really weren't half way */
1021 high += GARDROUND + 1;
1024 tmp->fraction.ll = high;
1025 tmp->class = CLASS_NUMBER;
1030 multiply (FLO_type arg_a, FLO_type arg_b)
1035 fp_number_type *res;
1036 FLO_union_type au, bu;
1044 res = _fpmul_parts (&a, &b, &tmp);
1046 return pack_d (res);
1050 #if defined(L_div_sf) || defined(L_div_df)
1051 static INLINE fp_number_type *
1052 _fpdiv_parts (fp_number_type * a,
1057 fractype denominator;
1069 a->sign = a->sign ^ b->sign;
1071 if (isinf (a) || iszero (a))
1073 if (a->class == b->class)
1086 a->class = CLASS_INFINITY;
1090 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1094 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1097 a->normal_exp = a->normal_exp - b->normal_exp;
1098 numerator = a->fraction.ll;
1099 denominator = b->fraction.ll;
1101 if (numerator < denominator)
1103 /* Fraction will be less than 1.0 */
1109 /* ??? Does divide one bit at a time. Optimize. */
1112 if (numerator >= denominator)
1115 numerator -= denominator;
1121 if ((quotient & GARDMASK) == GARDMSB)
1123 if (quotient & (1 << NGARDS))
1125 /* half way, so round to even */
1126 quotient += GARDROUND + 1;
1130 /* but we really weren't half way, more bits exist */
1131 quotient += GARDROUND + 1;
1135 a->fraction.ll = quotient;
1141 divide (FLO_type arg_a, FLO_type arg_b)
1145 fp_number_type *res;
1146 FLO_union_type au, bu;
1154 res = _fpdiv_parts (&a, &b);
1156 return pack_d (res);
1160 int __fpcmp_parts (fp_number_type * a, fp_number_type *b);
1162 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
1163 /* according to the demo, fpcmp returns a comparison with 0... thus
1170 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1173 /* either nan -> unordered. Must be checked outside of this routine. */
1174 if (isnan (a) && isnan (b))
1176 return 1; /* still unordered! */
1180 if (isnan (a) || isnan (b))
1182 return 1; /* how to indicate unordered compare? */
1184 if (isinf (a) && isinf (b))
1186 /* +inf > -inf, but +inf != +inf */
1187 /* b \a| +inf(0)| -inf(1)
1188 ______\+--------+--------
1189 +inf(0)| a==b(0)| a<b(-1)
1190 -------+--------+--------
1191 -inf(1)| a>b(1) | a==b(0)
1192 -------+--------+--------
1193 So since unordered must be non zero, just line up the columns...
1195 return b->sign - a->sign;
1197 /* but not both... */
1200 return a->sign ? -1 : 1;
1204 return b->sign ? 1 : -1;
1206 if (iszero (a) && iszero (b))
1212 return b->sign ? 1 : -1;
1216 return a->sign ? -1 : 1;
1218 /* now both are "normal". */
1219 if (a->sign != b->sign)
1221 /* opposite signs */
1222 return a->sign ? -1 : 1;
1224 /* same sign; exponents? */
1225 if (a->normal_exp > b->normal_exp)
1227 return a->sign ? -1 : 1;
1229 if (a->normal_exp < b->normal_exp)
1231 return a->sign ? 1 : -1;
1233 /* same exponents; check size. */
1234 if (a->fraction.ll > b->fraction.ll)
1236 return a->sign ? -1 : 1;
1238 if (a->fraction.ll < b->fraction.ll)
1240 return a->sign ? 1 : -1;
1242 /* after all that, they're equal. */
1247 #if defined(L_compare_sf) || defined(L_compare_df)
1249 compare (FLO_type arg_a, FLO_type arg_b)
1253 FLO_union_type au, bu;
1261 return __fpcmp_parts (&a, &b);
1265 #ifndef US_SOFTWARE_GOFAST
1267 /* These should be optimized for their specific tasks someday. */
1269 #if defined(L_eq_sf) || defined(L_eq_df)
1271 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1275 FLO_union_type au, bu;
1283 if (isnan (&a) || isnan (&b))
1284 return 1; /* false, truth == 0 */
1286 return __fpcmp_parts (&a, &b) ;
1290 #if defined(L_ne_sf) || defined(L_ne_df)
1292 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1296 FLO_union_type au, bu;
1304 if (isnan (&a) || isnan (&b))
1305 return 1; /* true, truth != 0 */
1307 return __fpcmp_parts (&a, &b) ;
1311 #if defined(L_gt_sf) || defined(L_gt_df)
1313 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1317 FLO_union_type au, bu;
1325 if (isnan (&a) || isnan (&b))
1326 return -1; /* false, truth > 0 */
1328 return __fpcmp_parts (&a, &b);
1332 #if defined(L_ge_sf) || defined(L_ge_df)
1334 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1338 FLO_union_type au, bu;
1346 if (isnan (&a) || isnan (&b))
1347 return -1; /* false, truth >= 0 */
1348 return __fpcmp_parts (&a, &b) ;
1352 #if defined(L_lt_sf) || defined(L_lt_df)
1354 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1358 FLO_union_type au, bu;
1366 if (isnan (&a) || isnan (&b))
1367 return 1; /* false, truth < 0 */
1369 return __fpcmp_parts (&a, &b);
1373 #if defined(L_le_sf) || defined(L_le_df)
1375 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1379 FLO_union_type au, bu;
1387 if (isnan (&a) || isnan (&b))
1388 return 1; /* false, truth <= 0 */
1390 return __fpcmp_parts (&a, &b) ;
1394 #if defined(L_unord_sf) || defined(L_unord_df)
1396 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1400 FLO_union_type au, bu;
1408 return (isnan (&a) || isnan (&b));
1412 #endif /* ! US_SOFTWARE_GOFAST */
1414 #if defined(L_si_to_sf) || defined(L_si_to_df)
1416 si_to_float (SItype arg_a)
1420 in.class = CLASS_NUMBER;
1421 in.sign = arg_a < 0;
1424 in.class = CLASS_ZERO;
1428 in.normal_exp = FRACBITS + NGARDS;
1431 /* Special case for minint, since there is no +ve integer
1432 representation for it */
1433 if (arg_a == (SItype) 0x80000000)
1435 return -2147483648.0;
1437 in.fraction.ll = (-arg_a);
1440 in.fraction.ll = arg_a;
1442 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1444 in.fraction.ll <<= 1;
1448 return pack_d (&in);
1452 #if defined(L_sf_to_si) || defined(L_df_to_si)
1454 float_to_si (FLO_type arg_a)
1467 /* get reasonable MAX_SI_INT... */
1469 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1470 /* it is a number, but a small one */
1471 if (a.normal_exp < 0)
1473 if (a.normal_exp > 30)
1474 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1475 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1476 return a.sign ? (-tmp) : (tmp);
1480 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1481 #ifdef US_SOFTWARE_GOFAST
1482 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1483 we also define them for GOFAST because the ones in libgcc2.c have the
1484 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1485 out of libgcc2.c. We can't define these here if not GOFAST because then
1486 there'd be duplicate copies. */
1489 float_to_usi (FLO_type arg_a)
1501 /* it is a negative number */
1504 /* get reasonable MAX_USI_INT... */
1507 /* it is a number, but a small one */
1508 if (a.normal_exp < 0)
1510 if (a.normal_exp > 31)
1512 else if (a.normal_exp > (FRACBITS + NGARDS))
1513 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1515 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1520 #if defined(L_negate_sf) || defined(L_negate_df)
1522 negate (FLO_type arg_a)
1537 #if defined(L_make_sf)
1539 __make_fp(fp_class_type class,
1548 in.normal_exp = exp;
1549 in.fraction.ll = frac;
1550 return pack_d (&in);
1556 /* This enables one to build an fp library that supports float but not double.
1557 Otherwise, we would get an undefined reference to __make_dp.
1558 This is needed for some 8-bit ports that can't handle well values that
1559 are 8-bytes in size, so we just don't support double for them at all. */
1561 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1563 #if defined(L_sf_to_df)
1565 sf_to_df (SFtype arg_a)
1571 unpack_d (&au, &in);
1573 return __make_dp (in.class, in.sign, in.normal_exp,
1574 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1583 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1585 #if defined(L_make_df)
1587 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1593 in.normal_exp = exp;
1594 in.fraction.ll = frac;
1595 return pack_d (&in);
1599 #if defined(L_df_to_sf)
1601 df_to_sf (DFtype arg_a)
1608 unpack_d (&au, &in);
1610 sffrac = in.fraction.ll >> F_D_BITOFF;
1612 /* We set the lowest guard bit in SFFRAC if we discarded any non
1614 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1617 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1622 #endif /* !EXTENDED_FLOAT_STUBS */