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 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 /* The following macros can be defined to change the behaviour of this file:
47 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
48 defined, then this file implements a `double', aka DFmode, fp library.
49 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
50 don't include float->double conversion which requires the double library.
51 This is useful only for machines which can't support doubles, e.g. some
53 CMPtype: Specify the type that floating point compares should return.
54 This defaults to SItype, aka int.
55 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
56 US Software goFast library. If this is not defined, the entry points use
57 the same names as libgcc1.c.
58 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
59 two integers to the FLO_union_type.
60 NO_NANS: Disable nan and infinity handling
61 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
64 /* We don't currently support extended floats (long doubles) on machines
65 without hardware to deal with them.
67 These stubs are just to keep the linker from complaining about unresolved
68 references which can be pulled in from libio & libstdc++, even if the
69 user isn't using long doubles. However, they may generate an unresolved
70 external to abort if abort is not used by the function, and the stubs
71 are referenced from within libc, since libgcc goes before and after the
74 #ifdef EXTENDED_FLOAT_STUBS
75 __truncxfsf2 (){ abort(); }
76 __extendsfxf2 (){ abort(); }
77 __addxf3 (){ abort(); }
78 __divxf3 (){ abort(); }
79 __eqxf2 (){ abort(); }
80 __extenddfxf2 (){ abort(); }
81 __gtxf2 (){ abort(); }
82 __lexf2 (){ abort(); }
83 __ltxf2 (){ abort(); }
84 __mulxf3 (){ abort(); }
85 __negxf2 (){ abort(); }
86 __nexf2 (){ abort(); }
87 __subxf3 (){ abort(); }
88 __truncxfdf2 (){ abort(); }
90 __trunctfsf2 (){ abort(); }
91 __extendsftf2 (){ abort(); }
92 __addtf3 (){ abort(); }
93 __divtf3 (){ abort(); }
94 __eqtf2 (){ abort(); }
95 __extenddftf2 (){ abort(); }
96 __gttf2 (){ abort(); }
97 __letf2 (){ abort(); }
98 __lttf2 (){ abort(); }
99 __multf3 (){ abort(); }
100 __negtf2 (){ abort(); }
101 __netf2 (){ abort(); }
102 __subtf3 (){ abort(); }
103 __trunctfdf2 (){ abort(); }
104 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
107 typedef SFtype __attribute__ ((mode (SF)));
108 typedef DFtype __attribute__ ((mode (DF)));
110 typedef int HItype __attribute__ ((mode (HI)));
111 typedef int SItype __attribute__ ((mode (SI)));
112 typedef int DItype __attribute__ ((mode (DI)));
114 /* The type of the result of a fp compare */
116 #define CMPtype SItype
119 typedef unsigned int UHItype __attribute__ ((mode (HI)));
120 typedef unsigned int USItype __attribute__ ((mode (SI)));
121 typedef unsigned int UDItype __attribute__ ((mode (DI)));
123 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
124 #define MAX_USI_INT ((USItype) ~0)
133 # define GARDROUND 0x3f
134 # define GARDMASK 0x7f
135 # define GARDMSB 0x40
139 # define EXPMAX (0xff)
140 # define QUIET_NAN 0x100000L
141 # define FRAC_NBITS 32
142 # define FRACHIGH 0x80000000L
143 # define FRACHIGH2 0xc0000000L
144 # define pack_d pack_f
145 # define unpack_d unpack_f
146 typedef USItype fractype;
147 typedef UHItype halffractype;
148 typedef SFtype FLO_type;
149 typedef SItype intfrac;
152 # define PREFIXFPDP dp
153 # define PREFIXSFDF df
155 # define GARDROUND 0x7f
156 # define GARDMASK 0xff
157 # define GARDMSB 0x80
159 # define EXPBIAS 1023
161 # define EXPMAX (0x7ff)
162 # define QUIET_NAN 0x8000000000000LL
163 # define FRAC_NBITS 64
164 # define FRACHIGH 0x8000000000000000LL
165 # define FRACHIGH2 0xc000000000000000LL
166 typedef UDItype fractype;
167 typedef USItype halffractype;
168 typedef DFtype FLO_type;
169 typedef DItype intfrac;
172 #ifdef US_SOFTWARE_GOFAST
176 # define multiply fpmul
177 # define divide fpdiv
178 # define compare fpcmp
179 # define si_to_float sitofp
180 # define float_to_si fptosi
181 # define float_to_usi fptoui
182 # define negate __negsf2
183 # define sf_to_df fptodp
184 # define dptofp dptofp
188 # define multiply dpmul
189 # define divide dpdiv
190 # define compare dpcmp
191 # define si_to_float litodp
192 # define float_to_si dptoli
193 # define float_to_usi dptoul
194 # define negate __negdf2
195 # define df_to_sf dptofp
199 # define add __addsf3
200 # define sub __subsf3
201 # define multiply __mulsf3
202 # define divide __divsf3
203 # define compare __cmpsf2
204 # define _eq_f2 __eqsf2
205 # define _ne_f2 __nesf2
206 # define _gt_f2 __gtsf2
207 # define _ge_f2 __gesf2
208 # define _lt_f2 __ltsf2
209 # define _le_f2 __lesf2
210 # define si_to_float __floatsisf
211 # define float_to_si __fixsfsi
212 # define float_to_usi __fixunssfsi
213 # define negate __negsf2
214 # define sf_to_df __extendsfdf2
216 # define add __adddf3
217 # define sub __subdf3
218 # define multiply __muldf3
219 # define divide __divdf3
220 # define compare __cmpdf2
221 # define _eq_f2 __eqdf2
222 # define _ne_f2 __nedf2
223 # define _gt_f2 __gtdf2
224 # define _ge_f2 __gedf2
225 # define _lt_f2 __ltdf2
226 # define _le_f2 __ledf2
227 # define si_to_float __floatsidf
228 # define float_to_si __fixdfsi
229 # define float_to_usi __fixunsdfsi
230 # define negate __negdf2
231 # define df_to_sf __truncdfsf2
236 #define INLINE __inline__
238 /* Preserve the sticky-bit when shifting fractions to the right. */
239 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
241 /* numeric parameters */
242 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
243 of a float and of a double. Assumes there are only two float types.
244 (double::FRAC_BITS+double::NGARGS-(float::FRAC_BITS-float::NGARDS))
246 #define F_D_BITOFF (52+8-(23+7))
249 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
250 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
251 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
289 halffractype words[2];
292 #ifdef FLOAT_BIT_ORDER_MISMATCH
295 fractype fraction:FRACBITS __attribute__ ((packed));
296 unsigned int exp:EXPBITS __attribute__ ((packed));
297 unsigned int sign:1 __attribute__ ((packed));
302 #ifdef _DEBUG_BITFLOAT
305 unsigned int sign:1 __attribute__ ((packed));
306 unsigned int exp:EXPBITS __attribute__ ((packed));
307 fractype fraction:FRACBITS __attribute__ ((packed));
313 fractype fraction:FRACBITS __attribute__ ((packed));
314 unsigned int exp:EXPBITS __attribute__ ((packed));
315 unsigned int sign:1 __attribute__ ((packed));
325 /* IEEE "special" number predicates */
335 static fp_number_type *
338 static fp_number_type thenan;
345 isnan ( fp_number_type * x)
347 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
352 isinf ( fp_number_type * x)
354 return x->class == CLASS_INFINITY;
361 iszero ( fp_number_type * x)
363 return x->class == CLASS_ZERO;
368 flip_sign ( fp_number_type * x)
374 pack_d ( fp_number_type * src)
377 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
378 int sign = src->sign;
384 if (src->class == CLASS_QNAN || 1)
386 fraction |= QUIET_NAN;
389 else if (isinf (src))
394 else if (iszero (src))
399 else if (fraction == 0)
406 if (src->normal_exp < NORMAL_EXPMIN)
408 /* This number's exponent is too low to fit into the bits
409 available in the number, so we'll store 0 in the exponent and
410 shift the fraction to the right to make up for it. */
412 int shift = NORMAL_EXPMIN - src->normal_exp;
416 if (shift > FRAC_NBITS - NGARDS)
418 /* No point shifting, since it's more that 64 out. */
423 /* Shift by the value */
428 else if (src->normal_exp > EXPBIAS)
435 exp = src->normal_exp + EXPBIAS;
436 /* IF the gard bits are the all zero, but the first, then we're
437 half way between two numbers, choose the one which makes the
438 lsb of the answer 0. */
439 if ((fraction & GARDMASK) == GARDMSB)
441 if (fraction & (1 << NGARDS))
442 fraction += GARDROUND + 1;
446 /* Add a one to the guards to round up */
447 fraction += GARDROUND;
449 if (fraction >= IMPLICIT_2)
458 /* We previously used bitfields to store the number, but this doesn't
459 handle little/big endian systems conviently, so use shifts and
461 #ifdef FLOAT_BIT_ORDER_MISMATCH
462 dst.bits.fraction = fraction;
464 dst.bits.sign = sign;
466 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
467 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
468 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
471 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
473 halffractype tmp = dst.words[0];
474 dst.words[0] = dst.words[1];
483 unpack_d (FLO_union_type * src, fp_number_type * dst)
485 /* We previously used bitfields to store the number, but this doesn't
486 handle little/big endian systems conviently, so use shifts and
492 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
493 FLO_union_type swapped;
495 swapped.words[0] = src->words[1];
496 swapped.words[1] = src->words[0];
500 #ifdef FLOAT_BIT_ORDER_MISMATCH
501 fraction = src->bits.fraction;
503 sign = src->bits.sign;
505 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
506 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
507 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
513 /* Hmm. Looks like 0 */
516 /* tastes like zero */
517 dst->class = CLASS_ZERO;
521 /* Zero exponent with non zero fraction - it's denormalized,
522 so there isn't a leading implicit one - we'll shift it so
524 dst->normal_exp = exp - EXPBIAS + 1;
527 dst->class = CLASS_NUMBER;
529 while (fraction < IMPLICIT_1)
535 dst->fraction.ll = fraction;
538 else if (exp == EXPMAX)
543 /* Attached to a zero fraction - means infinity */
544 dst->class = CLASS_INFINITY;
548 /* Non zero fraction, means nan */
551 dst->class = CLASS_SNAN;
555 dst->class = CLASS_QNAN;
557 /* Keep the fraction part as the nan number */
558 dst->fraction.ll = fraction;
563 /* Nothing strange about this number */
564 dst->normal_exp = exp - EXPBIAS;
565 dst->class = CLASS_NUMBER;
566 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
570 static fp_number_type *
571 _fpadd_parts (fp_number_type * a,
573 fp_number_type * tmp)
577 /* Put commonly used fields in local variables. */
593 /* Adding infinities with opposite signs yields a NaN. */
594 if (isinf (b) && a->sign != b->sign)
611 /* Got two numbers. shift the smaller and increment the exponent till
616 a_normal_exp = a->normal_exp;
617 b_normal_exp = b->normal_exp;
618 a_fraction = a->fraction.ll;
619 b_fraction = b->fraction.ll;
621 diff = a_normal_exp - b_normal_exp;
625 if (diff < FRAC_NBITS)
627 /* ??? This does shifts one bit at a time. Optimize. */
628 while (a_normal_exp > b_normal_exp)
633 while (b_normal_exp > a_normal_exp)
641 /* Somethings's up.. choose the biggest */
642 if (a_normal_exp > b_normal_exp)
644 b_normal_exp = a_normal_exp;
649 a_normal_exp = b_normal_exp;
655 if (a->sign != b->sign)
659 tfraction = -a_fraction + b_fraction;
663 tfraction = a_fraction - b_fraction;
668 tmp->normal_exp = a_normal_exp;
669 tmp->fraction.ll = tfraction;
674 tmp->normal_exp = a_normal_exp;
675 tmp->fraction.ll = -tfraction;
677 /* and renormalize it */
679 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
681 tmp->fraction.ll <<= 1;
688 tmp->normal_exp = a_normal_exp;
689 tmp->fraction.ll = a_fraction + b_fraction;
691 tmp->class = CLASS_NUMBER;
692 /* Now the fraction is added, we have to shift down to renormalize the
695 if (tmp->fraction.ll >= IMPLICIT_2)
697 LSHIFT (tmp->fraction.ll);
705 add (FLO_type arg_a, FLO_type arg_b)
712 unpack_d ((FLO_union_type *) & arg_a, &a);
713 unpack_d ((FLO_union_type *) & arg_b, &b);
715 res = _fpadd_parts (&a, &b, &tmp);
721 sub (FLO_type arg_a, FLO_type arg_b)
728 unpack_d ((FLO_union_type *) & arg_a, &a);
729 unpack_d ((FLO_union_type *) & arg_b, &b);
733 res = _fpadd_parts (&a, &b, &tmp);
738 static fp_number_type *
739 _fpmul_parts ( fp_number_type * a,
741 fp_number_type * tmp)
748 a->sign = a->sign != b->sign;
753 b->sign = a->sign != b->sign;
760 a->sign = a->sign != b->sign;
769 b->sign = a->sign != b->sign;
774 a->sign = a->sign != b->sign;
779 b->sign = a->sign != b->sign;
783 /* Calculate the mantissa by multiplying both 64bit numbers to get a
786 fractype x = a->fraction.ll;
787 fractype ylow = b->fraction.ll;
791 #if defined(NO_DI_MODE)
793 /* ??? This does multiplies one bit at a time. Optimize. */
794 for (bit = 0; bit < FRAC_NBITS; bit++)
800 carry = (low += ylow) < ylow;
801 high += yhigh + carry;
814 /* Multiplying two 32 bit numbers to get a 64 bit number on
815 a machine with DI, so we're safe */
817 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
823 /* Doing a 64*64 to 128 */
825 UDItype nl = a->fraction.ll & 0xffffffff;
826 UDItype nh = a->fraction.ll >> 32;
827 UDItype ml = b->fraction.ll & 0xffffffff;
828 UDItype mh = b->fraction.ll >>32;
829 UDItype pp_ll = ml * nl;
830 UDItype pp_hl = mh * nl;
831 UDItype pp_lh = ml * nh;
832 UDItype pp_hh = mh * nh;
835 UDItype ps_hh__ = pp_hl + pp_lh;
837 res2 += 0x100000000LL;
838 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
839 res0 = pp_ll + pp_hl;
842 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
849 tmp->normal_exp = a->normal_exp + b->normal_exp;
850 tmp->sign = a->sign != b->sign;
852 tmp->normal_exp += 2; /* ??????????????? */
854 tmp->normal_exp += 4; /* ??????????????? */
856 while (high >= IMPLICIT_2)
866 while (high < IMPLICIT_1)
875 /* rounding is tricky. if we only round if it won't make us round later. */
879 if (((high & GARDMASK) != GARDMSB)
880 && (((high + 1) & GARDMASK) == GARDMSB))
882 /* don't round, it gets done again later. */
890 if ((high & GARDMASK) == GARDMSB)
892 if (high & (1 << NGARDS))
894 /* half way, so round to even */
895 high += GARDROUND + 1;
899 /* but we really weren't half way */
900 high += GARDROUND + 1;
903 tmp->fraction.ll = high;
904 tmp->class = CLASS_NUMBER;
909 multiply (FLO_type arg_a, FLO_type arg_b)
916 unpack_d ((FLO_union_type *) & arg_a, &a);
917 unpack_d ((FLO_union_type *) & arg_b, &b);
919 res = _fpmul_parts (&a, &b, &tmp);
924 static fp_number_type *
925 _fpdiv_parts (fp_number_type * a,
927 fp_number_type * tmp)
931 fractype r0, r1, y0, y1, bit;
934 fractype denominator;
947 a->sign = a->sign ^ b->sign;
949 if (isinf (a) || iszero (a))
951 if (a->class == b->class)
964 a->class = CLASS_INFINITY;
968 /* Calculate the mantissa by multiplying both 64bit numbers to get a
972 intfrac d0, d1; /* weren't unsigned before ??? */
975 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
978 a->normal_exp = a->normal_exp - b->normal_exp;
979 numerator = a->fraction.ll;
980 denominator = b->fraction.ll;
982 if (numerator < denominator)
984 /* Fraction will be less than 1.0 */
990 /* ??? Does divide one bit at a time. Optimize. */
993 if (numerator >= denominator)
996 numerator -= denominator;
1002 if ((quotient & GARDMASK) == GARDMSB)
1004 if (quotient & (1 << NGARDS))
1006 /* half way, so round to even */
1007 quotient += GARDROUND + 1;
1011 /* but we really weren't half way, more bits exist */
1012 quotient += GARDROUND + 1;
1016 a->fraction.ll = quotient;
1022 divide (FLO_type arg_a, FLO_type arg_b)
1027 fp_number_type *res;
1029 unpack_d ((FLO_union_type *) & arg_a, &a);
1030 unpack_d ((FLO_union_type *) & arg_b, &b);
1032 res = _fpdiv_parts (&a, &b, &tmp);
1034 return pack_d (res);
1037 /* according to the demo, fpcmp returns a comparison with 0... thus
1044 _fpcmp_parts (fp_number_type * a, fp_number_type * b)
1047 /* either nan -> unordered. Must be checked outside of this routine. */
1048 if (isnan (a) && isnan (b))
1050 return 1; /* still unordered! */
1054 if (isnan (a) || isnan (b))
1056 return 1; /* how to indicate unordered compare? */
1058 if (isinf (a) && isinf (b))
1060 /* +inf > -inf, but +inf != +inf */
1061 /* b \a| +inf(0)| -inf(1)
1062 ______\+--------+--------
1063 +inf(0)| a==b(0)| a<b(-1)
1064 -------+--------+--------
1065 -inf(1)| a>b(1) | a==b(0)
1066 -------+--------+--------
1067 So since unordered must be non zero, just line up the columns...
1069 return b->sign - a->sign;
1071 /* but not both... */
1074 return a->sign ? -1 : 1;
1078 return b->sign ? 1 : -1;
1080 if (iszero (a) && iszero (b))
1086 return b->sign ? 1 : -1;
1090 return a->sign ? -1 : 1;
1092 /* now both are "normal". */
1093 if (a->sign != b->sign)
1095 /* opposite signs */
1096 return a->sign ? -1 : 1;
1098 /* same sign; exponents? */
1099 if (a->normal_exp > b->normal_exp)
1101 return a->sign ? -1 : 1;
1103 if (a->normal_exp < b->normal_exp)
1105 return a->sign ? 1 : -1;
1107 /* same exponents; check size. */
1108 if (a->fraction.ll > b->fraction.ll)
1110 return a->sign ? -1 : 1;
1112 if (a->fraction.ll < b->fraction.ll)
1114 return a->sign ? 1 : -1;
1116 /* after all that, they're equal. */
1121 compare (FLO_type arg_a, FLO_type arg_b)
1126 unpack_d ((FLO_union_type *) & arg_a, &a);
1127 unpack_d ((FLO_union_type *) & arg_b, &b);
1129 return _fpcmp_parts (&a, &b);
1132 #ifndef US_SOFTWARE_GOFAST
1134 /* These should be optimized for their specific tasks someday. */
1137 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1142 unpack_d ((FLO_union_type *) & arg_a, &a);
1143 unpack_d ((FLO_union_type *) & arg_b, &b);
1145 if (isnan (&a) || isnan (&b))
1146 return 1; /* false, truth == 0 */
1148 return _fpcmp_parts (&a, &b) ;
1152 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1157 unpack_d ((FLO_union_type *) & arg_a, &a);
1158 unpack_d ((FLO_union_type *) & arg_b, &b);
1160 if (isnan (&a) || isnan (&b))
1161 return 1; /* true, truth != 0 */
1163 return _fpcmp_parts (&a, &b) ;
1167 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1172 unpack_d ((FLO_union_type *) & arg_a, &a);
1173 unpack_d ((FLO_union_type *) & arg_b, &b);
1175 if (isnan (&a) || isnan (&b))
1176 return -1; /* false, truth > 0 */
1178 return _fpcmp_parts (&a, &b);
1182 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1187 unpack_d ((FLO_union_type *) & arg_a, &a);
1188 unpack_d ((FLO_union_type *) & arg_b, &b);
1190 if (isnan (&a) || isnan (&b))
1191 return -1; /* false, truth >= 0 */
1192 return _fpcmp_parts (&a, &b) ;
1196 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1201 unpack_d ((FLO_union_type *) & arg_a, &a);
1202 unpack_d ((FLO_union_type *) & arg_b, &b);
1204 if (isnan (&a) || isnan (&b))
1205 return 1; /* false, truth < 0 */
1207 return _fpcmp_parts (&a, &b);
1211 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1216 unpack_d ((FLO_union_type *) & arg_a, &a);
1217 unpack_d ((FLO_union_type *) & arg_b, &b);
1219 if (isnan (&a) || isnan (&b))
1220 return 1; /* false, truth <= 0 */
1222 return _fpcmp_parts (&a, &b) ;
1225 #endif /* ! US_SOFTWARE_GOFAST */
1228 si_to_float (SItype arg_a)
1232 in.class = CLASS_NUMBER;
1233 in.sign = arg_a < 0;
1236 in.class = CLASS_ZERO;
1240 in.normal_exp = FRACBITS + NGARDS;
1243 /* Special case for minint, since there is no +ve integer
1244 representation for it */
1245 if (arg_a == 0x80000000)
1247 return -2147483648.0;
1249 in.fraction.ll = (-arg_a);
1252 in.fraction.ll = arg_a;
1254 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1256 in.fraction.ll <<= 1;
1260 return pack_d (&in);
1264 float_to_si (FLO_type arg_a)
1269 unpack_d ((FLO_union_type *) & arg_a, &a);
1274 /* get reasonable MAX_SI_INT... */
1276 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1277 /* it is a number, but a small one */
1278 if (a.normal_exp < 0)
1280 if (a.normal_exp > 30)
1281 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1282 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1283 return a.sign ? (-tmp) : (tmp);
1286 #ifdef US_SOFTWARE_GOFAST
1287 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1288 we also define them for GOFAST because the ones in libgcc2.c have the
1289 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1290 out of libgcc2.c. We can't define these here if not GOFAST because then
1291 there'd be duplicate copies. */
1294 float_to_usi (FLO_type arg_a)
1298 unpack_d ((FLO_union_type *) & arg_a, &a);
1303 /* it is a negative number */
1306 /* get reasonable MAX_USI_INT... */
1309 /* it is a number, but a small one */
1310 if (a.normal_exp < 0)
1312 if (a.normal_exp > 31)
1314 else if (a.normal_exp > (FRACBITS + NGARDS))
1315 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1317 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1322 negate (FLO_type arg_a)
1326 unpack_d ((FLO_union_type *) & arg_a, &a);
1334 __make_fp(fp_class_type class,
1343 in.normal_exp = exp;
1344 in.fraction.ll = frac;
1345 return pack_d (&in);
1350 /* This enables one to build an fp library that supports float but not double.
1351 Otherwise, we would get an undefined reference to __make_dp.
1352 This is needed for some 8-bit ports that can't handle well values that
1353 are 8-bytes in size, so we just don't support double for them at all. */
1355 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1358 sf_to_df (SFtype arg_a)
1362 unpack_d ((FLO_union_type *) & arg_a, &in);
1363 return __make_dp (in.class, in.sign, in.normal_exp,
1364 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1372 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1375 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1381 in.normal_exp = exp;
1382 in.fraction.ll = frac;
1383 return pack_d (&in);
1387 df_to_sf (DFtype arg_a)
1392 unpack_d ((FLO_union_type *) & arg_a, &in);
1394 sffrac = in.fraction.ll >> F_D_BITOFF;
1396 /* We set the lowest guard bit in SFFRAC if we discarded any non
1398 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1401 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1405 #endif /* !EXTENDED_FLOAT_STUBS */