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, 1995, 1996, 1997, 1998,
5 2000 Free Software Foundation, Inc.
7 This file is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file with other programs, and to distribute
15 those programs without any restriction coming from the use of this
16 file. (The General Public License restrictions do apply in other
17 respects; for example, they cover modification of the file, and
18 distribution when not linked into another program.)
20 This file is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; see the file COPYING. If not, write to
27 the Free Software Foundation, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
30 /* As a special exception, if you link this library with other files,
31 some of which are compiled with GCC, to produce an executable,
32 this library does not by itself cause the resulting executable
33 to be covered by the GNU General Public License.
34 This exception does not however invalidate any other reasons why
35 the executable file might be covered by the GNU General Public License. */
37 /* This implements IEEE 754 format arithmetic, but does not provide a
38 mechanism for setting the rounding mode, or for generating or handling
41 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
42 Wilson, all of Cygnus Support. */
44 /* The intended way to use this file is to make two copies, add `#define FLOAT'
45 to one copy, then compile both copies and add them to libgcc.a. */
47 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
48 from this file are compiled via additional -D options.
50 This avoids the need to pull in the entire fp emulation library
51 when only a small number of functions are needed.
53 If FINE_GRAINED_LIBRARIES is not defined, then compile every
55 #ifndef FINE_GRAINED_LIBRARIES
66 #define L_fpcmp_parts_sf
67 #define L_fpcmp_parts_df
103 /* The following macros can be defined to change the behaviour of this file:
104 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
105 defined, then this file implements a `double', aka DFmode, fp library.
106 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
107 don't include float->double conversion which requires the double library.
108 This is useful only for machines which can't support doubles, e.g. some
110 CMPtype: Specify the type that floating point compares should return.
111 This defaults to SItype, aka int.
112 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
113 US Software goFast library. If this is not defined, the entry points use
114 the same names as libgcc1.c.
115 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
116 two integers to the FLO_union_type.
117 NO_NANS: Disable nan and infinity handling
118 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
121 /* We don't currently support extended floats (long doubles) on machines
122 without hardware to deal with them.
124 These stubs are just to keep the linker from complaining about unresolved
125 references which can be pulled in from libio & libstdc++, even if the
126 user isn't using long doubles. However, they may generate an unresolved
127 external to abort if abort is not used by the function, and the stubs
128 are referenced from within libc, since libgcc goes before and after the
131 #ifdef EXTENDED_FLOAT_STUBS
132 __truncxfsf2 (){ abort(); }
133 __extendsfxf2 (){ abort(); }
134 __addxf3 (){ abort(); }
135 __divxf3 (){ abort(); }
136 __eqxf2 (){ abort(); }
137 __extenddfxf2 (){ abort(); }
138 __gtxf2 (){ abort(); }
139 __lexf2 (){ abort(); }
140 __ltxf2 (){ abort(); }
141 __mulxf3 (){ abort(); }
142 __negxf2 (){ abort(); }
143 __nexf2 (){ abort(); }
144 __subxf3 (){ abort(); }
145 __truncxfdf2 (){ abort(); }
147 __trunctfsf2 (){ abort(); }
148 __extendsftf2 (){ abort(); }
149 __addtf3 (){ abort(); }
150 __divtf3 (){ abort(); }
151 __eqtf2 (){ abort(); }
152 __extenddftf2 (){ abort(); }
153 __gttf2 (){ abort(); }
154 __letf2 (){ abort(); }
155 __lttf2 (){ abort(); }
156 __multf3 (){ abort(); }
157 __negtf2 (){ abort(); }
158 __netf2 (){ abort(); }
159 __subtf3 (){ abort(); }
160 __trunctfdf2 (){ abort(); }
161 __gexf2 (){ abort(); }
162 __fixxfsi (){ abort(); }
163 __floatsixf (){ abort(); }
164 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
167 typedef float SFtype __attribute__ ((mode (SF)));
168 typedef float DFtype __attribute__ ((mode (DF)));
170 typedef int HItype __attribute__ ((mode (HI)));
171 typedef int SItype __attribute__ ((mode (SI)));
172 typedef int DItype __attribute__ ((mode (DI)));
174 /* The type of the result of a fp compare */
176 #define CMPtype SItype
179 typedef unsigned int UHItype __attribute__ ((mode (HI)));
180 typedef unsigned int USItype __attribute__ ((mode (SI)));
181 typedef unsigned int UDItype __attribute__ ((mode (DI)));
183 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
184 #define MAX_USI_INT ((USItype) ~0)
193 # define GARDROUND 0x3f
194 # define GARDMASK 0x7f
195 # define GARDMSB 0x40
199 # define EXPMAX (0xff)
200 # define QUIET_NAN 0x100000L
201 # define FRAC_NBITS 32
202 # define FRACHIGH 0x80000000L
203 # define FRACHIGH2 0xc0000000L
204 # define pack_d __pack_f
205 # define unpack_d __unpack_f
206 # define __fpcmp_parts __fpcmp_parts_f
207 typedef USItype fractype;
208 typedef UHItype halffractype;
209 typedef SFtype FLO_type;
210 typedef SItype intfrac;
213 # define PREFIXFPDP dp
214 # define PREFIXSFDF df
216 # define GARDROUND 0x7f
217 # define GARDMASK 0xff
218 # define GARDMSB 0x80
220 # define EXPBIAS 1023
222 # define EXPMAX (0x7ff)
223 # define QUIET_NAN 0x8000000000000LL
224 # define FRAC_NBITS 64
225 # define FRACHIGH 0x8000000000000000LL
226 # define FRACHIGH2 0xc000000000000000LL
227 # define pack_d __pack_d
228 # define unpack_d __unpack_d
229 # define __fpcmp_parts __fpcmp_parts_d
230 typedef UDItype fractype;
231 typedef USItype halffractype;
232 typedef DFtype FLO_type;
233 typedef DItype intfrac;
236 #ifdef US_SOFTWARE_GOFAST
240 # define multiply fpmul
241 # define divide fpdiv
242 # define compare fpcmp
243 # define si_to_float sitofp
244 # define float_to_si fptosi
245 # define float_to_usi fptoui
246 # define negate __negsf2
247 # define sf_to_df fptodp
248 # define dptofp dptofp
252 # define multiply dpmul
253 # define divide dpdiv
254 # define compare dpcmp
255 # define si_to_float litodp
256 # define float_to_si dptoli
257 # define float_to_usi dptoul
258 # define negate __negdf2
259 # define df_to_sf dptofp
263 # define add __addsf3
264 # define sub __subsf3
265 # define multiply __mulsf3
266 # define divide __divsf3
267 # define compare __cmpsf2
268 # define _eq_f2 __eqsf2
269 # define _ne_f2 __nesf2
270 # define _gt_f2 __gtsf2
271 # define _ge_f2 __gesf2
272 # define _lt_f2 __ltsf2
273 # define _le_f2 __lesf2
274 # define _unord_f2 __unordsf2
275 # define si_to_float __floatsisf
276 # define float_to_si __fixsfsi
277 # define float_to_usi __fixunssfsi
278 # define negate __negsf2
279 # define sf_to_df __extendsfdf2
281 # define add __adddf3
282 # define sub __subdf3
283 # define multiply __muldf3
284 # define divide __divdf3
285 # define compare __cmpdf2
286 # define _eq_f2 __eqdf2
287 # define _ne_f2 __nedf2
288 # define _gt_f2 __gtdf2
289 # define _ge_f2 __gedf2
290 # define _lt_f2 __ltdf2
291 # define _le_f2 __ledf2
292 # define _unord_f2 __unorddf2
293 # define si_to_float __floatsidf
294 # define float_to_si __fixdfsi
295 # define float_to_usi __fixunsdfsi
296 # define negate __negdf2
297 # define df_to_sf __truncdfsf2
303 #define INLINE __inline__
306 /* Preserve the sticky-bit when shifting fractions to the right. */
307 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
309 /* numeric parameters */
310 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
311 of a float and of a double. Assumes there are only two float types.
312 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
314 #define F_D_BITOFF (52+8-(23+7))
317 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
318 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
319 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
357 halffractype words[2];
360 #ifdef FLOAT_BIT_ORDER_MISMATCH
363 fractype fraction:FRACBITS __attribute__ ((packed));
364 unsigned int exp:EXPBITS __attribute__ ((packed));
365 unsigned int sign:1 __attribute__ ((packed));
370 #ifdef _DEBUG_BITFLOAT
373 unsigned int sign:1 __attribute__ ((packed));
374 unsigned int exp:EXPBITS __attribute__ ((packed));
375 fractype fraction:FRACBITS __attribute__ ((packed));
381 fractype fraction:FRACBITS __attribute__ ((packed));
382 unsigned int exp:EXPBITS __attribute__ ((packed));
383 unsigned int sign:1 __attribute__ ((packed));
393 /* IEEE "special" number predicates */
402 #if defined L_thenan_sf
403 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, (fractype) 0 };
404 #elif defined L_thenan_df
405 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, (fractype) 0 };
407 extern const fp_number_type __thenan_sf;
409 extern const fp_number_type __thenan_df;
413 static fp_number_type *
416 /* Discard the const qualifier... */
418 return (fp_number_type *) (& __thenan_sf);
420 return (fp_number_type *) (& __thenan_df);
426 isnan ( fp_number_type * x)
428 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
433 isinf ( fp_number_type * x)
435 return x->class == CLASS_INFINITY;
442 iszero ( fp_number_type * x)
444 return x->class == CLASS_ZERO;
449 flip_sign ( fp_number_type * x)
454 extern FLO_type pack_d ( fp_number_type * );
456 #if defined(L_pack_df) || defined(L_pack_sf)
458 pack_d ( fp_number_type * src)
461 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
462 int sign = src->sign;
468 if (src->class == CLASS_QNAN || 1)
470 fraction |= QUIET_NAN;
473 else if (isinf (src))
478 else if (iszero (src))
483 else if (fraction == 0)
489 if (src->normal_exp < NORMAL_EXPMIN)
491 /* This number's exponent is too low to fit into the bits
492 available in the number, so we'll store 0 in the exponent and
493 shift the fraction to the right to make up for it. */
495 int shift = NORMAL_EXPMIN - src->normal_exp;
499 if (shift > FRAC_NBITS - NGARDS)
501 /* No point shifting, since it's more that 64 out. */
506 int lowbit = (fraction & ((1 << shift) - 1)) ? 1 : 0;
507 fraction = (fraction >> shift) | lowbit;
509 if ((fraction & GARDMASK) == GARDMSB)
511 if ((fraction & (1 << NGARDS)))
512 fraction += GARDROUND + 1;
516 /* Add to the guards to round up. */
517 fraction += GARDROUND;
519 /* Perhaps the rounding means we now need to change the
521 if (fraction >= IMPLICIT_2)
528 else if (src->normal_exp > EXPBIAS)
535 exp = src->normal_exp + EXPBIAS;
536 /* IF the gard bits are the all zero, but the first, then we're
537 half way between two numbers, choose the one which makes the
538 lsb of the answer 0. */
539 if ((fraction & GARDMASK) == GARDMSB)
541 if (fraction & (1 << NGARDS))
542 fraction += GARDROUND + 1;
546 /* Add a one to the guards to round up */
547 fraction += GARDROUND;
549 if (fraction >= IMPLICIT_2)
558 /* We previously used bitfields to store the number, but this doesn't
559 handle little/big endian systems conveniently, so use shifts and
561 #ifdef FLOAT_BIT_ORDER_MISMATCH
562 dst.bits.fraction = fraction;
564 dst.bits.sign = sign;
566 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
567 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
568 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
571 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
573 halffractype tmp = dst.words[0];
574 dst.words[0] = dst.words[1];
583 extern void unpack_d (FLO_union_type *, fp_number_type *);
585 #if defined(L_unpack_df) || defined(L_unpack_sf)
587 unpack_d (FLO_union_type * src, fp_number_type * dst)
589 /* We previously used bitfields to store the number, but this doesn't
590 handle little/big endian systems conveniently, so use shifts and
596 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
597 FLO_union_type swapped;
599 swapped.words[0] = src->words[1];
600 swapped.words[1] = src->words[0];
604 #ifdef FLOAT_BIT_ORDER_MISMATCH
605 fraction = src->bits.fraction;
607 sign = src->bits.sign;
609 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
610 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
611 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
617 /* Hmm. Looks like 0 */
620 /* tastes like zero */
621 dst->class = CLASS_ZERO;
625 /* Zero exponent with non zero fraction - it's denormalized,
626 so there isn't a leading implicit one - we'll shift it so
628 dst->normal_exp = exp - EXPBIAS + 1;
631 dst->class = CLASS_NUMBER;
633 while (fraction < IMPLICIT_1)
639 dst->fraction.ll = fraction;
642 else if (exp == EXPMAX)
647 /* Attached to a zero fraction - means infinity */
648 dst->class = CLASS_INFINITY;
652 /* Non zero fraction, means nan */
653 if (fraction & QUIET_NAN)
655 dst->class = CLASS_QNAN;
659 dst->class = CLASS_SNAN;
661 /* Keep the fraction part as the nan number */
662 dst->fraction.ll = fraction;
667 /* Nothing strange about this number */
668 dst->normal_exp = exp - EXPBIAS;
669 dst->class = CLASS_NUMBER;
670 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
675 #if defined(L_addsub_sf) || defined(L_addsub_df)
676 static fp_number_type *
677 _fpadd_parts (fp_number_type * a,
679 fp_number_type * tmp)
683 /* Put commonly used fields in local variables. */
699 /* Adding infinities with opposite signs yields a NaN. */
700 if (isinf (b) && a->sign != b->sign)
713 tmp->sign = a->sign & b->sign;
723 /* Got two numbers. shift the smaller and increment the exponent till
728 a_normal_exp = a->normal_exp;
729 b_normal_exp = b->normal_exp;
730 a_fraction = a->fraction.ll;
731 b_fraction = b->fraction.ll;
733 diff = a_normal_exp - b_normal_exp;
737 if (diff < FRAC_NBITS)
739 /* ??? This does shifts one bit at a time. Optimize. */
740 while (a_normal_exp > b_normal_exp)
745 while (b_normal_exp > a_normal_exp)
753 /* Somethings's up.. choose the biggest */
754 if (a_normal_exp > b_normal_exp)
756 b_normal_exp = a_normal_exp;
761 a_normal_exp = b_normal_exp;
767 if (a->sign != b->sign)
771 tfraction = -a_fraction + b_fraction;
775 tfraction = a_fraction - b_fraction;
780 tmp->normal_exp = a_normal_exp;
781 tmp->fraction.ll = tfraction;
786 tmp->normal_exp = a_normal_exp;
787 tmp->fraction.ll = -tfraction;
789 /* and renormalize it */
791 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
793 tmp->fraction.ll <<= 1;
800 tmp->normal_exp = a_normal_exp;
801 tmp->fraction.ll = a_fraction + b_fraction;
803 tmp->class = CLASS_NUMBER;
804 /* Now the fraction is added, we have to shift down to renormalize the
807 if (tmp->fraction.ll >= IMPLICIT_2)
809 LSHIFT (tmp->fraction.ll);
817 add (FLO_type arg_a, FLO_type arg_b)
823 FLO_union_type au, bu;
831 res = _fpadd_parts (&a, &b, &tmp);
837 sub (FLO_type arg_a, FLO_type arg_b)
843 FLO_union_type au, bu;
853 res = _fpadd_parts (&a, &b, &tmp);
859 #if defined(L_mul_sf) || defined(L_mul_df)
860 static INLINE fp_number_type *
861 _fpmul_parts ( fp_number_type * a,
863 fp_number_type * tmp)
870 a->sign = a->sign != b->sign;
875 b->sign = a->sign != b->sign;
882 a->sign = a->sign != b->sign;
891 b->sign = a->sign != b->sign;
896 a->sign = a->sign != b->sign;
901 b->sign = a->sign != b->sign;
905 /* Calculate the mantissa by multiplying both 64bit numbers to get a
908 #if defined(NO_DI_MODE)
910 fractype x = a->fraction.ll;
911 fractype ylow = b->fraction.ll;
915 /* ??? This does multiplies one bit at a time. Optimize. */
916 for (bit = 0; bit < FRAC_NBITS; bit++)
922 carry = (low += ylow) < ylow;
923 high += yhigh + carry;
936 /* Multiplying two 32 bit numbers to get a 64 bit number on
937 a machine with DI, so we're safe */
939 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
945 /* Doing a 64*64 to 128 */
947 UDItype nl = a->fraction.ll & 0xffffffff;
948 UDItype nh = a->fraction.ll >> 32;
949 UDItype ml = b->fraction.ll & 0xffffffff;
950 UDItype mh = b->fraction.ll >>32;
951 UDItype pp_ll = ml * nl;
952 UDItype pp_hl = mh * nl;
953 UDItype pp_lh = ml * nh;
954 UDItype pp_hh = mh * nh;
957 UDItype ps_hh__ = pp_hl + pp_lh;
959 res2 += 0x100000000LL;
960 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
961 res0 = pp_ll + pp_hl;
964 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
971 tmp->normal_exp = a->normal_exp + b->normal_exp;
972 tmp->sign = a->sign != b->sign;
974 tmp->normal_exp += 2; /* ??????????????? */
976 tmp->normal_exp += 4; /* ??????????????? */
978 while (high >= IMPLICIT_2)
988 while (high < IMPLICIT_1)
997 /* rounding is tricky. if we only round if it won't make us round later. */
1001 if (((high & GARDMASK) != GARDMSB)
1002 && (((high + 1) & GARDMASK) == GARDMSB))
1004 /* don't round, it gets done again later. */
1012 if ((high & GARDMASK) == GARDMSB)
1014 if (high & (1 << NGARDS))
1016 /* half way, so round to even */
1017 high += GARDROUND + 1;
1021 /* but we really weren't half way */
1022 high += GARDROUND + 1;
1025 tmp->fraction.ll = high;
1026 tmp->class = CLASS_NUMBER;
1031 multiply (FLO_type arg_a, FLO_type arg_b)
1036 fp_number_type *res;
1037 FLO_union_type au, bu;
1045 res = _fpmul_parts (&a, &b, &tmp);
1047 return pack_d (res);
1051 #if defined(L_div_sf) || defined(L_div_df)
1052 static INLINE fp_number_type *
1053 _fpdiv_parts (fp_number_type * a,
1058 fractype denominator;
1070 a->sign = a->sign ^ b->sign;
1072 if (isinf (a) || iszero (a))
1074 if (a->class == b->class)
1087 a->class = CLASS_INFINITY;
1091 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1095 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1098 a->normal_exp = a->normal_exp - b->normal_exp;
1099 numerator = a->fraction.ll;
1100 denominator = b->fraction.ll;
1102 if (numerator < denominator)
1104 /* Fraction will be less than 1.0 */
1110 /* ??? Does divide one bit at a time. Optimize. */
1113 if (numerator >= denominator)
1116 numerator -= denominator;
1122 if ((quotient & GARDMASK) == GARDMSB)
1124 if (quotient & (1 << NGARDS))
1126 /* half way, so round to even */
1127 quotient += GARDROUND + 1;
1131 /* but we really weren't half way, more bits exist */
1132 quotient += GARDROUND + 1;
1136 a->fraction.ll = quotient;
1142 divide (FLO_type arg_a, FLO_type arg_b)
1146 fp_number_type *res;
1147 FLO_union_type au, bu;
1155 res = _fpdiv_parts (&a, &b);
1157 return pack_d (res);
1161 int __fpcmp_parts (fp_number_type * a, fp_number_type *b);
1163 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
1164 /* according to the demo, fpcmp returns a comparison with 0... thus
1171 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1174 /* either nan -> unordered. Must be checked outside of this routine. */
1175 if (isnan (a) && isnan (b))
1177 return 1; /* still unordered! */
1181 if (isnan (a) || isnan (b))
1183 return 1; /* how to indicate unordered compare? */
1185 if (isinf (a) && isinf (b))
1187 /* +inf > -inf, but +inf != +inf */
1188 /* b \a| +inf(0)| -inf(1)
1189 ______\+--------+--------
1190 +inf(0)| a==b(0)| a<b(-1)
1191 -------+--------+--------
1192 -inf(1)| a>b(1) | a==b(0)
1193 -------+--------+--------
1194 So since unordered must be non zero, just line up the columns...
1196 return b->sign - a->sign;
1198 /* but not both... */
1201 return a->sign ? -1 : 1;
1205 return b->sign ? 1 : -1;
1207 if (iszero (a) && iszero (b))
1213 return b->sign ? 1 : -1;
1217 return a->sign ? -1 : 1;
1219 /* now both are "normal". */
1220 if (a->sign != b->sign)
1222 /* opposite signs */
1223 return a->sign ? -1 : 1;
1225 /* same sign; exponents? */
1226 if (a->normal_exp > b->normal_exp)
1228 return a->sign ? -1 : 1;
1230 if (a->normal_exp < b->normal_exp)
1232 return a->sign ? 1 : -1;
1234 /* same exponents; check size. */
1235 if (a->fraction.ll > b->fraction.ll)
1237 return a->sign ? -1 : 1;
1239 if (a->fraction.ll < b->fraction.ll)
1241 return a->sign ? 1 : -1;
1243 /* after all that, they're equal. */
1248 #if defined(L_compare_sf) || defined(L_compare_df)
1250 compare (FLO_type arg_a, FLO_type arg_b)
1254 FLO_union_type au, bu;
1262 return __fpcmp_parts (&a, &b);
1266 #ifndef US_SOFTWARE_GOFAST
1268 /* These should be optimized for their specific tasks someday. */
1270 #if defined(L_eq_sf) || defined(L_eq_df)
1272 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1276 FLO_union_type au, bu;
1284 if (isnan (&a) || isnan (&b))
1285 return 1; /* false, truth == 0 */
1287 return __fpcmp_parts (&a, &b) ;
1291 #if defined(L_ne_sf) || defined(L_ne_df)
1293 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1297 FLO_union_type au, bu;
1305 if (isnan (&a) || isnan (&b))
1306 return 1; /* true, truth != 0 */
1308 return __fpcmp_parts (&a, &b) ;
1312 #if defined(L_gt_sf) || defined(L_gt_df)
1314 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1318 FLO_union_type au, bu;
1326 if (isnan (&a) || isnan (&b))
1327 return -1; /* false, truth > 0 */
1329 return __fpcmp_parts (&a, &b);
1333 #if defined(L_ge_sf) || defined(L_ge_df)
1335 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1339 FLO_union_type au, bu;
1347 if (isnan (&a) || isnan (&b))
1348 return -1; /* false, truth >= 0 */
1349 return __fpcmp_parts (&a, &b) ;
1353 #if defined(L_lt_sf) || defined(L_lt_df)
1355 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1359 FLO_union_type au, bu;
1367 if (isnan (&a) || isnan (&b))
1368 return 1; /* false, truth < 0 */
1370 return __fpcmp_parts (&a, &b);
1374 #if defined(L_le_sf) || defined(L_le_df)
1376 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1380 FLO_union_type au, bu;
1388 if (isnan (&a) || isnan (&b))
1389 return 1; /* false, truth <= 0 */
1391 return __fpcmp_parts (&a, &b) ;
1395 #if defined(L_unord_sf) || defined(L_unord_df)
1397 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1401 FLO_union_type au, bu;
1409 return (isnan (&a) || isnan (&b));
1413 #endif /* ! US_SOFTWARE_GOFAST */
1415 #if defined(L_si_to_sf) || defined(L_si_to_df)
1417 si_to_float (SItype arg_a)
1421 in.class = CLASS_NUMBER;
1422 in.sign = arg_a < 0;
1425 in.class = CLASS_ZERO;
1429 in.normal_exp = FRACBITS + NGARDS;
1432 /* Special case for minint, since there is no +ve integer
1433 representation for it */
1434 if (arg_a == (SItype) 0x80000000)
1436 return -2147483648.0;
1438 in.fraction.ll = (-arg_a);
1441 in.fraction.ll = arg_a;
1443 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1445 in.fraction.ll <<= 1;
1449 return pack_d (&in);
1453 #if defined(L_sf_to_si) || defined(L_df_to_si)
1455 float_to_si (FLO_type arg_a)
1468 /* get reasonable MAX_SI_INT... */
1470 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1471 /* it is a number, but a small one */
1472 if (a.normal_exp < 0)
1474 if (a.normal_exp > 30)
1475 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1476 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1477 return a.sign ? (-tmp) : (tmp);
1481 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1482 #ifdef US_SOFTWARE_GOFAST
1483 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1484 we also define them for GOFAST because the ones in libgcc2.c have the
1485 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1486 out of libgcc2.c. We can't define these here if not GOFAST because then
1487 there'd be duplicate copies. */
1490 float_to_usi (FLO_type arg_a)
1502 /* it is a negative number */
1505 /* get reasonable MAX_USI_INT... */
1508 /* it is a number, but a small one */
1509 if (a.normal_exp < 0)
1511 if (a.normal_exp > 31)
1513 else if (a.normal_exp > (FRACBITS + NGARDS))
1514 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1516 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1521 #if defined(L_negate_sf) || defined(L_negate_df)
1523 negate (FLO_type arg_a)
1538 #if defined(L_make_sf)
1540 __make_fp(fp_class_type class,
1549 in.normal_exp = exp;
1550 in.fraction.ll = frac;
1551 return pack_d (&in);
1557 /* This enables one to build an fp library that supports float but not double.
1558 Otherwise, we would get an undefined reference to __make_dp.
1559 This is needed for some 8-bit ports that can't handle well values that
1560 are 8-bytes in size, so we just don't support double for them at all. */
1562 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1564 #if defined(L_sf_to_df)
1566 sf_to_df (SFtype arg_a)
1572 unpack_d (&au, &in);
1574 return __make_dp (in.class, in.sign, in.normal_exp,
1575 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1584 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1586 #if defined(L_make_df)
1588 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1594 in.normal_exp = exp;
1595 in.fraction.ll = frac;
1596 return pack_d (&in);
1600 #if defined(L_df_to_sf)
1602 df_to_sf (DFtype arg_a)
1609 unpack_d (&au, &in);
1611 sffrac = in.fraction.ll >> F_D_BITOFF;
1613 /* We set the lowest guard bit in SFFRAC if we discarded any non
1615 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1618 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1623 #endif /* !EXTENDED_FLOAT_STUBS */