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_DENORMALS: Disable handling of denormals.
118 NO_NANS: Disable nan and infinity handling
119 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
122 /* We don't currently support extended floats (long doubles) on machines
123 without hardware to deal with them.
125 These stubs are just to keep the linker from complaining about unresolved
126 references which can be pulled in from libio & libstdc++, even if the
127 user isn't using long doubles. However, they may generate an unresolved
128 external to abort if abort is not used by the function, and the stubs
129 are referenced from within libc, since libgcc goes before and after the
132 #ifdef EXTENDED_FLOAT_STUBS
133 __truncxfsf2 (){ abort(); }
134 __extendsfxf2 (){ abort(); }
135 __addxf3 (){ abort(); }
136 __divxf3 (){ abort(); }
137 __eqxf2 (){ abort(); }
138 __extenddfxf2 (){ abort(); }
139 __gtxf2 (){ abort(); }
140 __lexf2 (){ abort(); }
141 __ltxf2 (){ abort(); }
142 __mulxf3 (){ abort(); }
143 __negxf2 (){ abort(); }
144 __nexf2 (){ abort(); }
145 __subxf3 (){ abort(); }
146 __truncxfdf2 (){ abort(); }
148 __trunctfsf2 (){ abort(); }
149 __extendsftf2 (){ abort(); }
150 __addtf3 (){ abort(); }
151 __divtf3 (){ abort(); }
152 __eqtf2 (){ abort(); }
153 __extenddftf2 (){ abort(); }
154 __gttf2 (){ abort(); }
155 __letf2 (){ abort(); }
156 __lttf2 (){ abort(); }
157 __multf3 (){ abort(); }
158 __negtf2 (){ abort(); }
159 __netf2 (){ abort(); }
160 __subtf3 (){ abort(); }
161 __trunctfdf2 (){ abort(); }
162 __gexf2 (){ abort(); }
163 __fixxfsi (){ abort(); }
164 __floatsixf (){ abort(); }
165 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
168 typedef float SFtype __attribute__ ((mode (SF)));
169 typedef float DFtype __attribute__ ((mode (DF)));
171 typedef int HItype __attribute__ ((mode (HI)));
172 typedef int SItype __attribute__ ((mode (SI)));
173 typedef int DItype __attribute__ ((mode (DI)));
175 /* The type of the result of a fp compare */
177 #define CMPtype SItype
180 typedef unsigned int UHItype __attribute__ ((mode (HI)));
181 typedef unsigned int USItype __attribute__ ((mode (SI)));
182 typedef unsigned int UDItype __attribute__ ((mode (DI)));
184 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
185 #define MAX_USI_INT ((USItype) ~0)
194 # define GARDROUND 0x3f
195 # define GARDMASK 0x7f
196 # define GARDMSB 0x40
200 # define EXPMAX (0xff)
201 # define QUIET_NAN 0x100000L
202 # define FRAC_NBITS 32
203 # define FRACHIGH 0x80000000L
204 # define FRACHIGH2 0xc0000000L
205 # define pack_d __pack_f
206 # define unpack_d __unpack_f
207 # define __fpcmp_parts __fpcmp_parts_f
208 typedef USItype fractype;
209 typedef UHItype halffractype;
210 typedef SFtype FLO_type;
211 typedef SItype intfrac;
214 # define PREFIXFPDP dp
215 # define PREFIXSFDF df
217 # define GARDROUND 0x7f
218 # define GARDMASK 0xff
219 # define GARDMSB 0x80
221 # define EXPBIAS 1023
223 # define EXPMAX (0x7ff)
224 # define QUIET_NAN 0x8000000000000LL
225 # define FRAC_NBITS 64
226 # define FRACHIGH 0x8000000000000000LL
227 # define FRACHIGH2 0xc000000000000000LL
228 # define pack_d __pack_d
229 # define unpack_d __unpack_d
230 # define __fpcmp_parts __fpcmp_parts_d
231 typedef UDItype fractype;
232 typedef USItype halffractype;
233 typedef DFtype FLO_type;
234 typedef DItype intfrac;
237 #ifdef US_SOFTWARE_GOFAST
241 # define multiply fpmul
242 # define divide fpdiv
243 # define compare fpcmp
244 # define si_to_float sitofp
245 # define float_to_si fptosi
246 # define float_to_usi fptoui
247 # define negate __negsf2
248 # define sf_to_df fptodp
249 # define dptofp dptofp
253 # define multiply dpmul
254 # define divide dpdiv
255 # define compare dpcmp
256 # define si_to_float litodp
257 # define float_to_si dptoli
258 # define float_to_usi dptoul
259 # define negate __negdf2
260 # define df_to_sf dptofp
264 # define add __addsf3
265 # define sub __subsf3
266 # define multiply __mulsf3
267 # define divide __divsf3
268 # define compare __cmpsf2
269 # define _eq_f2 __eqsf2
270 # define _ne_f2 __nesf2
271 # define _gt_f2 __gtsf2
272 # define _ge_f2 __gesf2
273 # define _lt_f2 __ltsf2
274 # define _le_f2 __lesf2
275 # define _unord_f2 __unordsf2
276 # define si_to_float __floatsisf
277 # define float_to_si __fixsfsi
278 # define float_to_usi __fixunssfsi
279 # define negate __negsf2
280 # define sf_to_df __extendsfdf2
282 # define add __adddf3
283 # define sub __subdf3
284 # define multiply __muldf3
285 # define divide __divdf3
286 # define compare __cmpdf2
287 # define _eq_f2 __eqdf2
288 # define _ne_f2 __nedf2
289 # define _gt_f2 __gtdf2
290 # define _ge_f2 __gedf2
291 # define _lt_f2 __ltdf2
292 # define _le_f2 __ledf2
293 # define _unord_f2 __unorddf2
294 # define si_to_float __floatsidf
295 # define float_to_si __fixdfsi
296 # define float_to_usi __fixunsdfsi
297 # define negate __negdf2
298 # define df_to_sf __truncdfsf2
304 #define INLINE __inline__
307 /* Preserve the sticky-bit when shifting fractions to the right. */
308 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
310 /* numeric parameters */
311 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
312 of a float and of a double. Assumes there are only two float types.
313 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
315 #define F_D_BITOFF (52+8-(23+7))
318 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
319 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
320 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
358 halffractype words[2];
361 #ifdef FLOAT_BIT_ORDER_MISMATCH
364 fractype fraction:FRACBITS __attribute__ ((packed));
365 unsigned int exp:EXPBITS __attribute__ ((packed));
366 unsigned int sign:1 __attribute__ ((packed));
371 #ifdef _DEBUG_BITFLOAT
374 unsigned int sign:1 __attribute__ ((packed));
375 unsigned int exp:EXPBITS __attribute__ ((packed));
376 fractype fraction:FRACBITS __attribute__ ((packed));
382 fractype fraction:FRACBITS __attribute__ ((packed));
383 unsigned int exp:EXPBITS __attribute__ ((packed));
384 unsigned int sign:1 __attribute__ ((packed));
394 /* IEEE "special" number predicates */
403 #if defined L_thenan_sf
404 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, (fractype) 0 };
405 #elif defined L_thenan_df
406 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, (fractype) 0 };
408 extern const fp_number_type __thenan_sf;
410 extern const fp_number_type __thenan_df;
414 static fp_number_type *
417 /* Discard the const qualifier... */
419 return (fp_number_type *) (& __thenan_sf);
421 return (fp_number_type *) (& __thenan_df);
427 isnan ( fp_number_type * x)
429 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
434 isinf ( fp_number_type * x)
436 return x->class == CLASS_INFINITY;
443 iszero ( fp_number_type * x)
445 return x->class == CLASS_ZERO;
450 flip_sign ( fp_number_type * x)
455 extern FLO_type pack_d ( fp_number_type * );
457 #if defined(L_pack_df) || defined(L_pack_sf)
459 pack_d ( fp_number_type * src)
462 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
463 int sign = src->sign;
469 if (src->class == CLASS_QNAN || 1)
471 fraction |= QUIET_NAN;
474 else if (isinf (src))
479 else if (iszero (src))
484 else if (fraction == 0)
490 if (src->normal_exp < NORMAL_EXPMIN)
492 /* This number's exponent is too low to fit into the bits
493 available in the number, so we'll store 0 in the exponent and
494 shift the fraction to the right to make up for it. */
496 int shift = NORMAL_EXPMIN - src->normal_exp;
500 if (shift > FRAC_NBITS - NGARDS)
502 /* No point shifting, since it's more that 64 out. */
507 int lowbit = (fraction & ((1 << shift) - 1)) ? 1 : 0;
508 fraction = (fraction >> shift) | lowbit;
510 if ((fraction & GARDMASK) == GARDMSB)
512 if ((fraction & (1 << NGARDS)))
513 fraction += GARDROUND + 1;
517 /* Add to the guards to round up. */
518 fraction += GARDROUND;
520 /* Perhaps the rounding means we now need to change the
521 exponent, because the fraction is no longer denormal. */
522 if (fraction >= IMPLICIT_1)
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 */
624 /* tastes like zero */
625 dst->class = CLASS_ZERO;
629 /* Zero exponent with non zero fraction - it's denormalized,
630 so there isn't a leading implicit one - we'll shift it so
632 dst->normal_exp = exp - EXPBIAS + 1;
635 dst->class = CLASS_NUMBER;
637 while (fraction < IMPLICIT_1)
643 dst->fraction.ll = fraction;
646 else if (exp == EXPMAX)
651 /* Attached to a zero fraction - means infinity */
652 dst->class = CLASS_INFINITY;
656 /* Non zero fraction, means nan */
657 if (fraction & QUIET_NAN)
659 dst->class = CLASS_QNAN;
663 dst->class = CLASS_SNAN;
665 /* Keep the fraction part as the nan number */
666 dst->fraction.ll = fraction;
671 /* Nothing strange about this number */
672 dst->normal_exp = exp - EXPBIAS;
673 dst->class = CLASS_NUMBER;
674 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
679 #if defined(L_addsub_sf) || defined(L_addsub_df)
680 static fp_number_type *
681 _fpadd_parts (fp_number_type * a,
683 fp_number_type * tmp)
687 /* Put commonly used fields in local variables. */
703 /* Adding infinities with opposite signs yields a NaN. */
704 if (isinf (b) && a->sign != b->sign)
717 tmp->sign = a->sign & b->sign;
727 /* Got two numbers. shift the smaller and increment the exponent till
732 a_normal_exp = a->normal_exp;
733 b_normal_exp = b->normal_exp;
734 a_fraction = a->fraction.ll;
735 b_fraction = b->fraction.ll;
737 diff = a_normal_exp - b_normal_exp;
741 if (diff < FRAC_NBITS)
743 /* ??? This does shifts one bit at a time. Optimize. */
744 while (a_normal_exp > b_normal_exp)
749 while (b_normal_exp > a_normal_exp)
757 /* Somethings's up.. choose the biggest */
758 if (a_normal_exp > b_normal_exp)
760 b_normal_exp = a_normal_exp;
765 a_normal_exp = b_normal_exp;
771 if (a->sign != b->sign)
775 tfraction = -a_fraction + b_fraction;
779 tfraction = a_fraction - b_fraction;
784 tmp->normal_exp = a_normal_exp;
785 tmp->fraction.ll = tfraction;
790 tmp->normal_exp = a_normal_exp;
791 tmp->fraction.ll = -tfraction;
793 /* and renormalize it */
795 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
797 tmp->fraction.ll <<= 1;
804 tmp->normal_exp = a_normal_exp;
805 tmp->fraction.ll = a_fraction + b_fraction;
807 tmp->class = CLASS_NUMBER;
808 /* Now the fraction is added, we have to shift down to renormalize the
811 if (tmp->fraction.ll >= IMPLICIT_2)
813 LSHIFT (tmp->fraction.ll);
821 add (FLO_type arg_a, FLO_type arg_b)
827 FLO_union_type au, bu;
835 res = _fpadd_parts (&a, &b, &tmp);
841 sub (FLO_type arg_a, FLO_type arg_b)
847 FLO_union_type au, bu;
857 res = _fpadd_parts (&a, &b, &tmp);
863 #if defined(L_mul_sf) || defined(L_mul_df)
864 static INLINE fp_number_type *
865 _fpmul_parts ( fp_number_type * a,
867 fp_number_type * tmp)
874 a->sign = a->sign != b->sign;
879 b->sign = a->sign != b->sign;
886 a->sign = a->sign != b->sign;
895 b->sign = a->sign != b->sign;
900 a->sign = a->sign != b->sign;
905 b->sign = a->sign != b->sign;
909 /* Calculate the mantissa by multiplying both 64bit numbers to get a
912 #if defined(NO_DI_MODE)
914 fractype x = a->fraction.ll;
915 fractype ylow = b->fraction.ll;
919 /* ??? This does multiplies one bit at a time. Optimize. */
920 for (bit = 0; bit < FRAC_NBITS; bit++)
926 carry = (low += ylow) < ylow;
927 high += yhigh + carry;
940 /* Multiplying two 32 bit numbers to get a 64 bit number on
941 a machine with DI, so we're safe */
943 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
949 /* Doing a 64*64 to 128 */
951 UDItype nl = a->fraction.ll & 0xffffffff;
952 UDItype nh = a->fraction.ll >> 32;
953 UDItype ml = b->fraction.ll & 0xffffffff;
954 UDItype mh = b->fraction.ll >>32;
955 UDItype pp_ll = ml * nl;
956 UDItype pp_hl = mh * nl;
957 UDItype pp_lh = ml * nh;
958 UDItype pp_hh = mh * nh;
961 UDItype ps_hh__ = pp_hl + pp_lh;
963 res2 += 0x100000000LL;
964 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
965 res0 = pp_ll + pp_hl;
968 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
975 tmp->normal_exp = a->normal_exp + b->normal_exp;
976 tmp->sign = a->sign != b->sign;
978 tmp->normal_exp += 2; /* ??????????????? */
980 tmp->normal_exp += 4; /* ??????????????? */
982 while (high >= IMPLICIT_2)
992 while (high < IMPLICIT_1)
1001 /* rounding is tricky. if we only round if it won't make us round later. */
1003 if (low & FRACHIGH2)
1005 if (((high & GARDMASK) != GARDMSB)
1006 && (((high + 1) & GARDMASK) == GARDMSB))
1008 /* don't round, it gets done again later. */
1016 if ((high & GARDMASK) == GARDMSB)
1018 if (high & (1 << NGARDS))
1020 /* half way, so round to even */
1021 high += GARDROUND + 1;
1025 /* but we really weren't half way */
1026 high += GARDROUND + 1;
1029 tmp->fraction.ll = high;
1030 tmp->class = CLASS_NUMBER;
1035 multiply (FLO_type arg_a, FLO_type arg_b)
1040 fp_number_type *res;
1041 FLO_union_type au, bu;
1049 res = _fpmul_parts (&a, &b, &tmp);
1051 return pack_d (res);
1055 #if defined(L_div_sf) || defined(L_div_df)
1056 static INLINE fp_number_type *
1057 _fpdiv_parts (fp_number_type * a,
1062 fractype denominator;
1074 a->sign = a->sign ^ b->sign;
1076 if (isinf (a) || iszero (a))
1078 if (a->class == b->class)
1091 a->class = CLASS_INFINITY;
1095 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1099 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1102 a->normal_exp = a->normal_exp - b->normal_exp;
1103 numerator = a->fraction.ll;
1104 denominator = b->fraction.ll;
1106 if (numerator < denominator)
1108 /* Fraction will be less than 1.0 */
1114 /* ??? Does divide one bit at a time. Optimize. */
1117 if (numerator >= denominator)
1120 numerator -= denominator;
1126 if ((quotient & GARDMASK) == GARDMSB)
1128 if (quotient & (1 << NGARDS))
1130 /* half way, so round to even */
1131 quotient += GARDROUND + 1;
1135 /* but we really weren't half way, more bits exist */
1136 quotient += GARDROUND + 1;
1140 a->fraction.ll = quotient;
1146 divide (FLO_type arg_a, FLO_type arg_b)
1150 fp_number_type *res;
1151 FLO_union_type au, bu;
1159 res = _fpdiv_parts (&a, &b);
1161 return pack_d (res);
1165 int __fpcmp_parts (fp_number_type * a, fp_number_type *b);
1167 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
1168 /* according to the demo, fpcmp returns a comparison with 0... thus
1175 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1178 /* either nan -> unordered. Must be checked outside of this routine. */
1179 if (isnan (a) && isnan (b))
1181 return 1; /* still unordered! */
1185 if (isnan (a) || isnan (b))
1187 return 1; /* how to indicate unordered compare? */
1189 if (isinf (a) && isinf (b))
1191 /* +inf > -inf, but +inf != +inf */
1192 /* b \a| +inf(0)| -inf(1)
1193 ______\+--------+--------
1194 +inf(0)| a==b(0)| a<b(-1)
1195 -------+--------+--------
1196 -inf(1)| a>b(1) | a==b(0)
1197 -------+--------+--------
1198 So since unordered must be non zero, just line up the columns...
1200 return b->sign - a->sign;
1202 /* but not both... */
1205 return a->sign ? -1 : 1;
1209 return b->sign ? 1 : -1;
1211 if (iszero (a) && iszero (b))
1217 return b->sign ? 1 : -1;
1221 return a->sign ? -1 : 1;
1223 /* now both are "normal". */
1224 if (a->sign != b->sign)
1226 /* opposite signs */
1227 return a->sign ? -1 : 1;
1229 /* same sign; exponents? */
1230 if (a->normal_exp > b->normal_exp)
1232 return a->sign ? -1 : 1;
1234 if (a->normal_exp < b->normal_exp)
1236 return a->sign ? 1 : -1;
1238 /* same exponents; check size. */
1239 if (a->fraction.ll > b->fraction.ll)
1241 return a->sign ? -1 : 1;
1243 if (a->fraction.ll < b->fraction.ll)
1245 return a->sign ? 1 : -1;
1247 /* after all that, they're equal. */
1252 #if defined(L_compare_sf) || defined(L_compare_df)
1254 compare (FLO_type arg_a, FLO_type arg_b)
1258 FLO_union_type au, bu;
1266 return __fpcmp_parts (&a, &b);
1270 #ifndef US_SOFTWARE_GOFAST
1272 /* These should be optimized for their specific tasks someday. */
1274 #if defined(L_eq_sf) || defined(L_eq_df)
1276 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1280 FLO_union_type au, bu;
1288 if (isnan (&a) || isnan (&b))
1289 return 1; /* false, truth == 0 */
1291 return __fpcmp_parts (&a, &b) ;
1295 #if defined(L_ne_sf) || defined(L_ne_df)
1297 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1301 FLO_union_type au, bu;
1309 if (isnan (&a) || isnan (&b))
1310 return 1; /* true, truth != 0 */
1312 return __fpcmp_parts (&a, &b) ;
1316 #if defined(L_gt_sf) || defined(L_gt_df)
1318 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1322 FLO_union_type au, bu;
1330 if (isnan (&a) || isnan (&b))
1331 return -1; /* false, truth > 0 */
1333 return __fpcmp_parts (&a, &b);
1337 #if defined(L_ge_sf) || defined(L_ge_df)
1339 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1343 FLO_union_type au, bu;
1351 if (isnan (&a) || isnan (&b))
1352 return -1; /* false, truth >= 0 */
1353 return __fpcmp_parts (&a, &b) ;
1357 #if defined(L_lt_sf) || defined(L_lt_df)
1359 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1363 FLO_union_type au, bu;
1371 if (isnan (&a) || isnan (&b))
1372 return 1; /* false, truth < 0 */
1374 return __fpcmp_parts (&a, &b);
1378 #if defined(L_le_sf) || defined(L_le_df)
1380 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1384 FLO_union_type au, bu;
1392 if (isnan (&a) || isnan (&b))
1393 return 1; /* false, truth <= 0 */
1395 return __fpcmp_parts (&a, &b) ;
1399 #if defined(L_unord_sf) || defined(L_unord_df)
1401 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1405 FLO_union_type au, bu;
1413 return (isnan (&a) || isnan (&b));
1417 #endif /* ! US_SOFTWARE_GOFAST */
1419 #if defined(L_si_to_sf) || defined(L_si_to_df)
1421 si_to_float (SItype arg_a)
1425 in.class = CLASS_NUMBER;
1426 in.sign = arg_a < 0;
1429 in.class = CLASS_ZERO;
1433 in.normal_exp = FRACBITS + NGARDS;
1436 /* Special case for minint, since there is no +ve integer
1437 representation for it */
1438 if (arg_a == (SItype) 0x80000000)
1440 return -2147483648.0;
1442 in.fraction.ll = (-arg_a);
1445 in.fraction.ll = arg_a;
1447 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1449 in.fraction.ll <<= 1;
1453 return pack_d (&in);
1457 #if defined(L_sf_to_si) || defined(L_df_to_si)
1459 float_to_si (FLO_type arg_a)
1472 /* get reasonable MAX_SI_INT... */
1474 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1475 /* it is a number, but a small one */
1476 if (a.normal_exp < 0)
1478 if (a.normal_exp > 30)
1479 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1480 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1481 return a.sign ? (-tmp) : (tmp);
1485 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1486 #ifdef US_SOFTWARE_GOFAST
1487 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1488 we also define them for GOFAST because the ones in libgcc2.c have the
1489 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1490 out of libgcc2.c. We can't define these here if not GOFAST because then
1491 there'd be duplicate copies. */
1494 float_to_usi (FLO_type arg_a)
1506 /* it is a negative number */
1509 /* get reasonable MAX_USI_INT... */
1512 /* it is a number, but a small one */
1513 if (a.normal_exp < 0)
1515 if (a.normal_exp > 31)
1517 else if (a.normal_exp > (FRACBITS + NGARDS))
1518 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1520 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1525 #if defined(L_negate_sf) || defined(L_negate_df)
1527 negate (FLO_type arg_a)
1542 #if defined(L_make_sf)
1544 __make_fp(fp_class_type class,
1553 in.normal_exp = exp;
1554 in.fraction.ll = frac;
1555 return pack_d (&in);
1561 /* This enables one to build an fp library that supports float but not double.
1562 Otherwise, we would get an undefined reference to __make_dp.
1563 This is needed for some 8-bit ports that can't handle well values that
1564 are 8-bytes in size, so we just don't support double for them at all. */
1566 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1568 #if defined(L_sf_to_df)
1570 sf_to_df (SFtype arg_a)
1576 unpack_d (&au, &in);
1578 return __make_dp (in.class, in.sign, in.normal_exp,
1579 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1588 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1590 #if defined(L_make_df)
1592 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1598 in.normal_exp = exp;
1599 in.fraction.ll = frac;
1600 return pack_d (&in);
1604 #if defined(L_df_to_sf)
1606 df_to_sf (DFtype arg_a)
1613 unpack_d (&au, &in);
1615 sffrac = in.fraction.ll >> F_D_BITOFF;
1617 /* We set the lowest guard bit in SFFRAC if we discarded any non
1619 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1622 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1627 #endif /* !EXTENDED_FLOAT_STUBS */