1 /* This is a software floating point library which can be used
2 for targets without hardware floating point.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003
4 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. */
47 #include "coretypes.h"
49 #include "config/fp-bit.h"
51 /* The following macros can be defined to change the behavior of this file:
52 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
53 defined, then this file implements a `double', aka DFmode, fp library.
54 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
55 don't include float->double conversion which requires the double library.
56 This is useful only for machines which can't support doubles, e.g. some
58 CMPtype: Specify the type that floating point compares should return.
59 This defaults to SItype, aka int.
60 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
61 US Software goFast library.
62 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
63 two integers to the FLO_union_type.
64 NO_DENORMALS: Disable handling of denormals.
65 NO_NANS: Disable nan and infinity handling
66 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
69 /* We don't currently support extended floats (long doubles) on machines
70 without hardware to deal with them.
72 These stubs are just to keep the linker from complaining about unresolved
73 references which can be pulled in from libio & libstdc++, even if the
74 user isn't using long doubles. However, they may generate an unresolved
75 external to abort if abort is not used by the function, and the stubs
76 are referenced from within libc, since libgcc goes before and after the
79 #ifdef DECLARE_LIBRARY_RENAMES
80 DECLARE_LIBRARY_RENAMES
83 #ifdef EXTENDED_FLOAT_STUBS
84 extern void abort (void);
85 void __extendsfxf2 (void) { abort(); }
86 void __extenddfxf2 (void) { abort(); }
87 void __truncxfdf2 (void) { abort(); }
88 void __truncxfsf2 (void) { abort(); }
89 void __fixxfsi (void) { abort(); }
90 void __floatsixf (void) { abort(); }
91 void __addxf3 (void) { abort(); }
92 void __subxf3 (void) { abort(); }
93 void __mulxf3 (void) { abort(); }
94 void __divxf3 (void) { abort(); }
95 void __negxf2 (void) { abort(); }
96 void __eqxf2 (void) { abort(); }
97 void __nexf2 (void) { abort(); }
98 void __gtxf2 (void) { abort(); }
99 void __gexf2 (void) { abort(); }
100 void __lexf2 (void) { abort(); }
101 void __ltxf2 (void) { abort(); }
103 void __extendsftf2 (void) { abort(); }
104 void __extenddftf2 (void) { abort(); }
105 void __trunctfdf2 (void) { abort(); }
106 void __trunctfsf2 (void) { abort(); }
107 void __fixtfsi (void) { abort(); }
108 void __floatsitf (void) { abort(); }
109 void __addtf3 (void) { abort(); }
110 void __subtf3 (void) { abort(); }
111 void __multf3 (void) { abort(); }
112 void __divtf3 (void) { abort(); }
113 void __negtf2 (void) { abort(); }
114 void __eqtf2 (void) { abort(); }
115 void __netf2 (void) { abort(); }
116 void __gttf2 (void) { abort(); }
117 void __getf2 (void) { abort(); }
118 void __letf2 (void) { abort(); }
119 void __lttf2 (void) { abort(); }
120 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
122 /* IEEE "special" number predicates */
131 #if defined L_thenan_sf
132 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
133 #elif defined L_thenan_df
134 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
135 #elif defined L_thenan_tf
136 const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
138 extern const fp_number_type __thenan_tf;
140 extern const fp_number_type __thenan_sf;
142 extern const fp_number_type __thenan_df;
146 static fp_number_type *
149 /* Discard the const qualifier... */
151 return (fp_number_type *) (& __thenan_tf);
153 return (fp_number_type *) (& __thenan_sf);
155 return (fp_number_type *) (& __thenan_df);
161 isnan ( fp_number_type * x)
163 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
168 isinf ( fp_number_type * x)
170 return x->class == CLASS_INFINITY;
177 iszero ( fp_number_type * x)
179 return x->class == CLASS_ZERO;
184 flip_sign ( fp_number_type * x)
189 extern FLO_type pack_d ( fp_number_type * );
191 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
193 pack_d ( fp_number_type * src)
196 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
197 int sign = src->sign;
200 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
202 /* We can't represent these values accurately. By using the
203 largest possible magnitude, we guarantee that the conversion
204 of infinity is at least as big as any finite number. */
206 fraction = ((fractype) 1 << FRACBITS) - 1;
208 else if (isnan (src))
211 if (src->class == CLASS_QNAN || 1)
213 #ifdef QUIET_NAN_NEGATED
214 fraction |= QUIET_NAN - 1;
216 fraction |= QUIET_NAN;
220 else if (isinf (src))
225 else if (iszero (src))
230 else if (fraction == 0)
236 if (src->normal_exp < NORMAL_EXPMIN)
239 /* Go straight to a zero representation if denormals are not
240 supported. The denormal handling would be harmless but
241 isn't unnecessary. */
244 #else /* NO_DENORMALS */
245 /* This number's exponent is too low to fit into the bits
246 available in the number, so we'll store 0 in the exponent and
247 shift the fraction to the right to make up for it. */
249 int shift = NORMAL_EXPMIN - src->normal_exp;
253 if (shift > FRAC_NBITS - NGARDS)
255 /* No point shifting, since it's more that 64 out. */
260 int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
261 fraction = (fraction >> shift) | lowbit;
263 if ((fraction & GARDMASK) == GARDMSB)
265 if ((fraction & (1 << NGARDS)))
266 fraction += GARDROUND + 1;
270 /* Add to the guards to round up. */
271 fraction += GARDROUND;
273 /* Perhaps the rounding means we now need to change the
274 exponent, because the fraction is no longer denormal. */
275 if (fraction >= IMPLICIT_1)
280 #endif /* NO_DENORMALS */
282 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
283 && src->normal_exp > EXPBIAS)
290 exp = src->normal_exp + EXPBIAS;
291 if (!ROUND_TOWARDS_ZERO)
293 /* IF the gard bits are the all zero, but the first, then we're
294 half way between two numbers, choose the one which makes the
295 lsb of the answer 0. */
296 if ((fraction & GARDMASK) == GARDMSB)
298 if (fraction & (1 << NGARDS))
299 fraction += GARDROUND + 1;
303 /* Add a one to the guards to round up */
304 fraction += GARDROUND;
306 if (fraction >= IMPLICIT_2)
314 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
316 /* Saturate on overflow. */
318 fraction = ((fractype) 1 << FRACBITS) - 1;
323 /* We previously used bitfields to store the number, but this doesn't
324 handle little/big endian systems conveniently, so use shifts and
326 #ifdef FLOAT_BIT_ORDER_MISMATCH
327 dst.bits.fraction = fraction;
329 dst.bits.sign = sign;
331 # if defined TFLOAT && defined HALFFRACBITS
333 halffractype high, low, unity;
336 unity = (halffractype) 1 << HALFFRACBITS;
338 /* Set HIGH to the high double's significand, masking out the implicit 1.
339 Set LOW to the low double's full significand. */
340 high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
341 low = fraction & (unity * 2 - 1);
343 /* Get the initial sign and exponent of the low double. */
344 lowexp = exp - HALFFRACBITS - 1;
347 /* HIGH should be rounded like a normal double, making |LOW| <=
348 0.5 ULP of HIGH. Assume round-to-nearest. */
350 if (low > unity || (low == unity && (high & 1) == 1))
352 /* Round HIGH up and adjust LOW to match. */
356 /* May make it infinite, but that's OK. */
360 low = unity * 2 - low;
364 high |= (halffractype) exp << HALFFRACBITS;
365 high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
367 if (exp == EXPMAX || exp == 0 || low == 0)
371 while (lowexp > 0 && low < unity)
379 halffractype roundmsb, round;
383 roundmsb = (1 << (shift - 1));
384 round = low & ((roundmsb << 1) - 1);
389 if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
393 /* LOW rounds up to the smallest normal number. */
399 low |= (halffractype) lowexp << HALFFRACBITS;
400 low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
402 dst.value_raw = ((fractype) high << HALFSHIFT) | low;
405 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
406 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
407 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
411 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
414 qrtrfractype tmp1 = dst.words[0];
415 qrtrfractype tmp2 = dst.words[1];
416 dst.words[0] = dst.words[3];
417 dst.words[1] = dst.words[2];
423 halffractype tmp = dst.words[0];
424 dst.words[0] = dst.words[1];
434 #if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
436 unpack_d (FLO_union_type * src, fp_number_type * dst)
438 /* We previously used bitfields to store the number, but this doesn't
439 handle little/big endian systems conveniently, so use shifts and
445 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
446 FLO_union_type swapped;
449 swapped.words[0] = src->words[3];
450 swapped.words[1] = src->words[2];
451 swapped.words[2] = src->words[1];
452 swapped.words[3] = src->words[0];
454 swapped.words[0] = src->words[1];
455 swapped.words[1] = src->words[0];
460 #ifdef FLOAT_BIT_ORDER_MISMATCH
461 fraction = src->bits.fraction;
463 sign = src->bits.sign;
465 # if defined TFLOAT && defined HALFFRACBITS
467 halffractype high, low;
469 high = src->value_raw >> HALFSHIFT;
470 low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
472 fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
473 fraction <<= FRACBITS - HALFFRACBITS;
474 exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
475 sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
477 if (exp != EXPMAX && exp != 0 && low != 0)
479 int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
480 int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
484 xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
486 xlow |= (((halffractype)1) << HALFFRACBITS);
489 shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
496 else if (fraction >= xlow)
500 /* The high part is a power of two but the full number is lower.
501 This code will leave the implicit 1 in FRACTION, but we'd
502 have added that below anyway. */
503 fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
509 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
510 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
511 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
518 /* Hmm. Looks like 0 */
525 /* tastes like zero */
526 dst->class = CLASS_ZERO;
530 /* Zero exponent with nonzero fraction - it's denormalized,
531 so there isn't a leading implicit one - we'll shift it so
533 dst->normal_exp = exp - EXPBIAS + 1;
536 dst->class = CLASS_NUMBER;
538 while (fraction < IMPLICIT_1)
544 dst->fraction.ll = fraction;
547 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
552 /* Attached to a zero fraction - means infinity */
553 dst->class = CLASS_INFINITY;
557 /* Nonzero fraction, means nan */
558 #ifdef QUIET_NAN_NEGATED
559 if ((fraction & QUIET_NAN) == 0)
561 if (fraction & QUIET_NAN)
564 dst->class = CLASS_QNAN;
568 dst->class = CLASS_SNAN;
570 /* Keep the fraction part as the nan number */
571 dst->fraction.ll = fraction;
576 /* Nothing strange about this number */
577 dst->normal_exp = exp - EXPBIAS;
578 dst->class = CLASS_NUMBER;
579 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
582 #endif /* L_unpack_df || L_unpack_sf */
584 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
585 static fp_number_type *
586 _fpadd_parts (fp_number_type * a,
588 fp_number_type * tmp)
592 /* Put commonly used fields in local variables. */
608 /* Adding infinities with opposite signs yields a NaN. */
609 if (isinf (b) && a->sign != b->sign)
622 tmp->sign = a->sign & b->sign;
632 /* Got two numbers. shift the smaller and increment the exponent till
637 a_normal_exp = a->normal_exp;
638 b_normal_exp = b->normal_exp;
639 a_fraction = a->fraction.ll;
640 b_fraction = b->fraction.ll;
642 diff = a_normal_exp - b_normal_exp;
646 if (diff < FRAC_NBITS)
648 /* ??? This does shifts one bit at a time. Optimize. */
649 while (a_normal_exp > b_normal_exp)
654 while (b_normal_exp > a_normal_exp)
662 /* Somethings's up.. choose the biggest */
663 if (a_normal_exp > b_normal_exp)
665 b_normal_exp = a_normal_exp;
670 a_normal_exp = b_normal_exp;
676 if (a->sign != b->sign)
680 tfraction = -a_fraction + b_fraction;
684 tfraction = a_fraction - b_fraction;
689 tmp->normal_exp = a_normal_exp;
690 tmp->fraction.ll = tfraction;
695 tmp->normal_exp = a_normal_exp;
696 tmp->fraction.ll = -tfraction;
698 /* and renormalize it */
700 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
702 tmp->fraction.ll <<= 1;
709 tmp->normal_exp = a_normal_exp;
710 tmp->fraction.ll = a_fraction + b_fraction;
712 tmp->class = CLASS_NUMBER;
713 /* Now the fraction is added, we have to shift down to renormalize the
716 if (tmp->fraction.ll >= IMPLICIT_2)
718 LSHIFT (tmp->fraction.ll);
726 add (FLO_type arg_a, FLO_type arg_b)
732 FLO_union_type au, bu;
740 res = _fpadd_parts (&a, &b, &tmp);
746 sub (FLO_type arg_a, FLO_type arg_b)
752 FLO_union_type au, bu;
762 res = _fpadd_parts (&a, &b, &tmp);
766 #endif /* L_addsub_sf || L_addsub_df */
768 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
769 static inline __attribute__ ((__always_inline__)) fp_number_type *
770 _fpmul_parts ( fp_number_type * a,
772 fp_number_type * tmp)
779 a->sign = a->sign != b->sign;
784 b->sign = a->sign != b->sign;
791 a->sign = a->sign != b->sign;
800 b->sign = a->sign != b->sign;
805 a->sign = a->sign != b->sign;
810 b->sign = a->sign != b->sign;
814 /* Calculate the mantissa by multiplying both numbers to get a
815 twice-as-wide number. */
817 #if defined(NO_DI_MODE) || defined(TFLOAT)
819 fractype x = a->fraction.ll;
820 fractype ylow = b->fraction.ll;
824 /* ??? This does multiplies one bit at a time. Optimize. */
825 for (bit = 0; bit < FRAC_NBITS; bit++)
831 carry = (low += ylow) < ylow;
832 high += yhigh + carry;
844 /* Multiplying two USIs to get a UDI, we're safe. */
846 UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
848 high = answer >> BITS_PER_SI;
852 /* fractype is DImode, but we need the result to be twice as wide.
853 Assuming a widening multiply from DImode to TImode is not
854 available, build one by hand. */
856 USItype nl = a->fraction.ll;
857 USItype nh = a->fraction.ll >> BITS_PER_SI;
858 USItype ml = b->fraction.ll;
859 USItype mh = b->fraction.ll >> BITS_PER_SI;
860 UDItype pp_ll = (UDItype) ml * nl;
861 UDItype pp_hl = (UDItype) mh * nl;
862 UDItype pp_lh = (UDItype) ml * nh;
863 UDItype pp_hh = (UDItype) mh * nh;
866 UDItype ps_hh__ = pp_hl + pp_lh;
868 res2 += (UDItype)1 << BITS_PER_SI;
869 pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
870 res0 = pp_ll + pp_hl;
873 res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
880 tmp->normal_exp = a->normal_exp + b->normal_exp
881 + FRAC_NBITS - (FRACBITS + NGARDS);
882 tmp->sign = a->sign != b->sign;
883 while (high >= IMPLICIT_2)
893 while (high < IMPLICIT_1)
902 /* rounding is tricky. if we only round if it won't make us round later. */
906 if (((high & GARDMASK) != GARDMSB)
907 && (((high + 1) & GARDMASK) == GARDMSB))
909 /* don't round, it gets done again later. */
917 if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
919 if (high & (1 << NGARDS))
921 /* half way, so round to even */
922 high += GARDROUND + 1;
926 /* but we really weren't half way */
927 high += GARDROUND + 1;
930 tmp->fraction.ll = high;
931 tmp->class = CLASS_NUMBER;
936 multiply (FLO_type arg_a, FLO_type arg_b)
942 FLO_union_type au, bu;
950 res = _fpmul_parts (&a, &b, &tmp);
954 #endif /* L_mul_sf || L_mul_df */
956 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
957 static inline __attribute__ ((__always_inline__)) fp_number_type *
958 _fpdiv_parts (fp_number_type * a,
963 fractype denominator;
975 a->sign = a->sign ^ b->sign;
977 if (isinf (a) || iszero (a))
979 if (a->class == b->class)
992 a->class = CLASS_INFINITY;
996 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1000 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1003 a->normal_exp = a->normal_exp - b->normal_exp;
1004 numerator = a->fraction.ll;
1005 denominator = b->fraction.ll;
1007 if (numerator < denominator)
1009 /* Fraction will be less than 1.0 */
1015 /* ??? Does divide one bit at a time. Optimize. */
1018 if (numerator >= denominator)
1021 numerator -= denominator;
1027 if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
1029 if (quotient & (1 << NGARDS))
1031 /* half way, so round to even */
1032 quotient += GARDROUND + 1;
1036 /* but we really weren't half way, more bits exist */
1037 quotient += GARDROUND + 1;
1041 a->fraction.ll = quotient;
1047 divide (FLO_type arg_a, FLO_type arg_b)
1051 fp_number_type *res;
1052 FLO_union_type au, bu;
1060 res = _fpdiv_parts (&a, &b);
1062 return pack_d (res);
1064 #endif /* L_div_sf || L_div_df */
1066 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
1067 || defined(L_fpcmp_parts_tf)
1068 /* according to the demo, fpcmp returns a comparison with 0... thus
1075 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1078 /* either nan -> unordered. Must be checked outside of this routine. */
1079 if (isnan (a) && isnan (b))
1081 return 1; /* still unordered! */
1085 if (isnan (a) || isnan (b))
1087 return 1; /* how to indicate unordered compare? */
1089 if (isinf (a) && isinf (b))
1091 /* +inf > -inf, but +inf != +inf */
1092 /* b \a| +inf(0)| -inf(1)
1093 ______\+--------+--------
1094 +inf(0)| a==b(0)| a<b(-1)
1095 -------+--------+--------
1096 -inf(1)| a>b(1) | a==b(0)
1097 -------+--------+--------
1098 So since unordered must be nonzero, just line up the columns...
1100 return b->sign - a->sign;
1102 /* but not both... */
1105 return a->sign ? -1 : 1;
1109 return b->sign ? 1 : -1;
1111 if (iszero (a) && iszero (b))
1117 return b->sign ? 1 : -1;
1121 return a->sign ? -1 : 1;
1123 /* now both are "normal". */
1124 if (a->sign != b->sign)
1126 /* opposite signs */
1127 return a->sign ? -1 : 1;
1129 /* same sign; exponents? */
1130 if (a->normal_exp > b->normal_exp)
1132 return a->sign ? -1 : 1;
1134 if (a->normal_exp < b->normal_exp)
1136 return a->sign ? 1 : -1;
1138 /* same exponents; check size. */
1139 if (a->fraction.ll > b->fraction.ll)
1141 return a->sign ? -1 : 1;
1143 if (a->fraction.ll < b->fraction.ll)
1145 return a->sign ? 1 : -1;
1147 /* after all that, they're equal. */
1152 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
1154 compare (FLO_type arg_a, FLO_type arg_b)
1158 FLO_union_type au, bu;
1166 return __fpcmp_parts (&a, &b);
1168 #endif /* L_compare_sf || L_compare_df */
1170 #ifndef US_SOFTWARE_GOFAST
1172 /* These should be optimized for their specific tasks someday. */
1174 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
1176 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1180 FLO_union_type au, bu;
1188 if (isnan (&a) || isnan (&b))
1189 return 1; /* false, truth == 0 */
1191 return __fpcmp_parts (&a, &b) ;
1193 #endif /* L_eq_sf || L_eq_df */
1195 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
1197 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1201 FLO_union_type au, bu;
1209 if (isnan (&a) || isnan (&b))
1210 return 1; /* true, truth != 0 */
1212 return __fpcmp_parts (&a, &b) ;
1214 #endif /* L_ne_sf || L_ne_df */
1216 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
1218 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1222 FLO_union_type au, bu;
1230 if (isnan (&a) || isnan (&b))
1231 return -1; /* false, truth > 0 */
1233 return __fpcmp_parts (&a, &b);
1235 #endif /* L_gt_sf || L_gt_df */
1237 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
1239 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1243 FLO_union_type au, bu;
1251 if (isnan (&a) || isnan (&b))
1252 return -1; /* false, truth >= 0 */
1253 return __fpcmp_parts (&a, &b) ;
1255 #endif /* L_ge_sf || L_ge_df */
1257 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
1259 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1263 FLO_union_type au, bu;
1271 if (isnan (&a) || isnan (&b))
1272 return 1; /* false, truth < 0 */
1274 return __fpcmp_parts (&a, &b);
1276 #endif /* L_lt_sf || L_lt_df */
1278 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
1280 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1284 FLO_union_type au, bu;
1292 if (isnan (&a) || isnan (&b))
1293 return 1; /* false, truth <= 0 */
1295 return __fpcmp_parts (&a, &b) ;
1297 #endif /* L_le_sf || L_le_df */
1299 #endif /* ! US_SOFTWARE_GOFAST */
1301 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
1303 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1307 FLO_union_type au, bu;
1315 return (isnan (&a) || isnan (&b));
1317 #endif /* L_unord_sf || L_unord_df */
1319 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
1321 si_to_float (SItype arg_a)
1325 in.class = CLASS_NUMBER;
1326 in.sign = arg_a < 0;
1329 in.class = CLASS_ZERO;
1333 in.normal_exp = FRACBITS + NGARDS;
1336 /* Special case for minint, since there is no +ve integer
1337 representation for it */
1338 if (arg_a == (- MAX_SI_INT - 1))
1340 return (FLO_type)(- MAX_SI_INT - 1);
1342 in.fraction.ll = (-arg_a);
1345 in.fraction.ll = arg_a;
1347 while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1349 in.fraction.ll <<= 1;
1353 return pack_d (&in);
1355 #endif /* L_si_to_sf || L_si_to_df */
1357 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
1359 usi_to_float (USItype arg_a)
1366 in.class = CLASS_ZERO;
1370 in.class = CLASS_NUMBER;
1371 in.normal_exp = FRACBITS + NGARDS;
1372 in.fraction.ll = arg_a;
1374 while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
1376 in.fraction.ll >>= 1;
1379 while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1381 in.fraction.ll <<= 1;
1385 return pack_d (&in);
1389 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
1391 float_to_si (FLO_type arg_a)
1404 /* get reasonable MAX_SI_INT... */
1406 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1407 /* it is a number, but a small one */
1408 if (a.normal_exp < 0)
1410 if (a.normal_exp > BITS_PER_SI - 2)
1411 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1412 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1413 return a.sign ? (-tmp) : (tmp);
1415 #endif /* L_sf_to_si || L_df_to_si */
1417 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
1418 #if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
1419 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1420 we also define them for GOFAST because the ones in libgcc2.c have the
1421 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1422 out of libgcc2.c. We can't define these here if not GOFAST because then
1423 there'd be duplicate copies. */
1426 float_to_usi (FLO_type arg_a)
1438 /* it is a negative number */
1441 /* get reasonable MAX_USI_INT... */
1444 /* it is a number, but a small one */
1445 if (a.normal_exp < 0)
1447 if (a.normal_exp > BITS_PER_SI - 1)
1449 else if (a.normal_exp > (FRACBITS + NGARDS))
1450 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1452 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1454 #endif /* US_SOFTWARE_GOFAST */
1455 #endif /* L_sf_to_usi || L_df_to_usi */
1457 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
1459 negate (FLO_type arg_a)
1470 #endif /* L_negate_sf || L_negate_df */
1474 #if defined(L_make_sf)
1476 __make_fp(fp_class_type class,
1485 in.normal_exp = exp;
1486 in.fraction.ll = frac;
1487 return pack_d (&in);
1489 #endif /* L_make_sf */
1493 /* This enables one to build an fp library that supports float but not double.
1494 Otherwise, we would get an undefined reference to __make_dp.
1495 This is needed for some 8-bit ports that can't handle well values that
1496 are 8-bytes in size, so we just don't support double for them at all. */
1498 #if defined(L_sf_to_df)
1500 sf_to_df (SFtype arg_a)
1506 unpack_d (&au, &in);
1508 return __make_dp (in.class, in.sign, in.normal_exp,
1509 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1511 #endif /* L_sf_to_df */
1513 #if defined(L_sf_to_tf) && defined(TMODES)
1515 sf_to_tf (SFtype arg_a)
1521 unpack_d (&au, &in);
1523 return __make_tp (in.class, in.sign, in.normal_exp,
1524 ((UTItype) in.fraction.ll) << F_T_BITOFF);
1526 #endif /* L_sf_to_df */
1528 #endif /* ! FLOAT_ONLY */
1533 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1535 #if defined(L_make_df)
1537 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1543 in.normal_exp = exp;
1544 in.fraction.ll = frac;
1545 return pack_d (&in);
1547 #endif /* L_make_df */
1549 #if defined(L_df_to_sf)
1551 df_to_sf (DFtype arg_a)
1558 unpack_d (&au, &in);
1560 sffrac = in.fraction.ll >> F_D_BITOFF;
1562 /* We set the lowest guard bit in SFFRAC if we discarded any non
1564 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1567 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1569 #endif /* L_df_to_sf */
1571 #if defined(L_df_to_tf) && defined(TMODES) \
1572 && !defined(FLOAT) && !defined(TFLOAT)
1574 df_to_tf (DFtype arg_a)
1580 unpack_d (&au, &in);
1582 return __make_tp (in.class, in.sign, in.normal_exp,
1583 ((UTItype) in.fraction.ll) << D_T_BITOFF);
1585 #endif /* L_sf_to_df */
1588 #if defined(L_make_tf)
1590 __make_tp(fp_class_type class,
1599 in.normal_exp = exp;
1600 in.fraction.ll = frac;
1601 return pack_d (&in);
1603 #endif /* L_make_tf */
1605 #if defined(L_tf_to_df)
1607 tf_to_df (TFtype arg_a)
1614 unpack_d (&au, &in);
1616 sffrac = in.fraction.ll >> D_T_BITOFF;
1618 /* We set the lowest guard bit in SFFRAC if we discarded any non
1620 if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
1623 return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
1625 #endif /* L_tf_to_df */
1627 #if defined(L_tf_to_sf)
1629 tf_to_sf (TFtype arg_a)
1636 unpack_d (&au, &in);
1638 sffrac = in.fraction.ll >> F_T_BITOFF;
1640 /* We set the lowest guard bit in SFFRAC if we discarded any non
1642 if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
1645 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1647 #endif /* L_tf_to_sf */
1650 #endif /* ! FLOAT */
1651 #endif /* !EXTENDED_FLOAT_STUBS */