1 /* This is a software floating point library which can be used instead of
2 the floating point routines in libgcc1.c for targets without hardware
4 Copyright (C) 1994-1998, 2000 Free Software Foundation, Inc.
6 This file is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file with other programs, and to distribute
14 those programs without any restriction coming from the use of this
15 file. (The General Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into another program.)
19 This file is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
29 /* As a special exception, if you link this library with other files,
30 some of which are compiled with GCC, to produce an executable,
31 this library does not by itself cause the resulting executable
32 to be covered by the GNU General Public License.
33 This exception does not however invalidate any other reasons why
34 the executable file might be covered by the GNU General Public License. */
36 /* This implements IEEE 754 format arithmetic, but does not provide a
37 mechanism for setting the rounding mode, or for generating or handling
40 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
41 Wilson, all of Cygnus Support. */
43 /* The intended way to use this file is to make two copies, add `#define FLOAT'
44 to one copy, then compile both copies and add them to libgcc.a. */
46 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
47 from this file are compiled via additional -D options.
49 This avoids the need to pull in the entire fp emulation library
50 when only a small number of functions are needed.
52 If FINE_GRAINED_LIBRARIES is not defined, then compile every
54 #ifndef FINE_GRAINED_LIBRARIES
65 #define L_fpcmp_parts_sf
66 #define L_fpcmp_parts_df
102 /* The following macros can be defined to change the behaviour of this file:
103 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
104 defined, then this file implements a `double', aka DFmode, fp library.
105 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
106 don't include float->double conversion which requires the double library.
107 This is useful only for machines which can't support doubles, e.g. some
109 CMPtype: Specify the type that floating point compares should return.
110 This defaults to SItype, aka int.
111 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
112 US Software goFast library. If this is not defined, the entry points use
113 the same names as libgcc1.c.
114 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
115 two integers to the FLO_union_type.
116 NO_NANS: Disable nan and infinity handling
117 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
120 /* We don't currently support extended floats (long doubles) on machines
121 without hardware to deal with them.
123 These stubs are just to keep the linker from complaining about unresolved
124 references which can be pulled in from libio & libstdc++, even if the
125 user isn't using long doubles. However, they may generate an unresolved
126 external to abort if abort is not used by the function, and the stubs
127 are referenced from within libc, since libgcc goes before and after the
130 #ifdef EXTENDED_FLOAT_STUBS
131 __truncxfsf2 (){ abort(); }
132 __extendsfxf2 (){ abort(); }
133 __addxf3 (){ abort(); }
134 __divxf3 (){ abort(); }
135 __eqxf2 (){ abort(); }
136 __extenddfxf2 (){ abort(); }
137 __gtxf2 (){ abort(); }
138 __lexf2 (){ abort(); }
139 __ltxf2 (){ abort(); }
140 __mulxf3 (){ abort(); }
141 __negxf2 (){ abort(); }
142 __nexf2 (){ abort(); }
143 __subxf3 (){ abort(); }
144 __truncxfdf2 (){ abort(); }
146 __trunctfsf2 (){ abort(); }
147 __extendsftf2 (){ abort(); }
148 __addtf3 (){ abort(); }
149 __divtf3 (){ abort(); }
150 __eqtf2 (){ abort(); }
151 __extenddftf2 (){ abort(); }
152 __gttf2 (){ abort(); }
153 __letf2 (){ abort(); }
154 __lttf2 (){ abort(); }
155 __multf3 (){ abort(); }
156 __negtf2 (){ abort(); }
157 __netf2 (){ abort(); }
158 __subtf3 (){ abort(); }
159 __trunctfdf2 (){ abort(); }
160 __gexf2 (){ abort(); }
161 __fixxfsi (){ abort(); }
162 __floatsixf (){ abort(); }
163 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
166 typedef float SFtype __attribute__ ((mode (SF)));
167 typedef float DFtype __attribute__ ((mode (DF)));
169 typedef int HItype __attribute__ ((mode (HI)));
170 typedef int SItype __attribute__ ((mode (SI)));
171 typedef int DItype __attribute__ ((mode (DI)));
173 /* The type of the result of a fp compare */
175 #define CMPtype SItype
178 typedef unsigned int UHItype __attribute__ ((mode (HI)));
179 typedef unsigned int USItype __attribute__ ((mode (SI)));
180 typedef unsigned int UDItype __attribute__ ((mode (DI)));
182 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
183 #define MAX_USI_INT ((USItype) ~0)
192 # define GARDROUND 0x3f
193 # define GARDMASK 0x7f
194 # define GARDMSB 0x40
198 # define EXPMAX (0xff)
199 # define QUIET_NAN 0x100000L
200 # define FRAC_NBITS 32
201 # define FRACHIGH 0x80000000L
202 # define FRACHIGH2 0xc0000000L
203 # define pack_d __pack_f
204 # define unpack_d __unpack_f
205 # define __fpcmp_parts __fpcmp_parts_f
206 typedef USItype fractype;
207 typedef UHItype halffractype;
208 typedef SFtype FLO_type;
209 typedef SItype intfrac;
212 # define PREFIXFPDP dp
213 # define PREFIXSFDF df
215 # define GARDROUND 0x7f
216 # define GARDMASK 0xff
217 # define GARDMSB 0x80
219 # define EXPBIAS 1023
221 # define EXPMAX (0x7ff)
222 # define QUIET_NAN 0x8000000000000LL
223 # define FRAC_NBITS 64
224 # define FRACHIGH 0x8000000000000000LL
225 # define FRACHIGH2 0xc000000000000000LL
226 # define pack_d __pack_d
227 # define unpack_d __unpack_d
228 # define __fpcmp_parts __fpcmp_parts_d
229 typedef UDItype fractype;
230 typedef USItype halffractype;
231 typedef DFtype FLO_type;
232 typedef DItype intfrac;
235 #ifdef US_SOFTWARE_GOFAST
239 # define multiply fpmul
240 # define divide fpdiv
241 # define compare fpcmp
242 # define si_to_float sitofp
243 # define float_to_si fptosi
244 # define float_to_usi fptoui
245 # define negate __negsf2
246 # define sf_to_df fptodp
247 # define dptofp dptofp
251 # define multiply dpmul
252 # define divide dpdiv
253 # define compare dpcmp
254 # define si_to_float litodp
255 # define float_to_si dptoli
256 # define float_to_usi dptoul
257 # define negate __negdf2
258 # define df_to_sf dptofp
262 # define add __addsf3
263 # define sub __subsf3
264 # define multiply __mulsf3
265 # define divide __divsf3
266 # define compare __cmpsf2
267 # define _eq_f2 __eqsf2
268 # define _ne_f2 __nesf2
269 # define _gt_f2 __gtsf2
270 # define _ge_f2 __gesf2
271 # define _lt_f2 __ltsf2
272 # define _le_f2 __lesf2
273 # define _unord_f2 __unordsf2
274 # define si_to_float __floatsisf
275 # define float_to_si __fixsfsi
276 # define float_to_usi __fixunssfsi
277 # define negate __negsf2
278 # define sf_to_df __extendsfdf2
280 # define add __adddf3
281 # define sub __subdf3
282 # define multiply __muldf3
283 # define divide __divdf3
284 # define compare __cmpdf2
285 # define _eq_f2 __eqdf2
286 # define _ne_f2 __nedf2
287 # define _gt_f2 __gtdf2
288 # define _ge_f2 __gedf2
289 # define _lt_f2 __ltdf2
290 # define _le_f2 __ledf2
291 # define _unord_f2 __unorddf2
292 # define si_to_float __floatsidf
293 # define float_to_si __fixdfsi
294 # define float_to_usi __fixunsdfsi
295 # define negate __negdf2
296 # define df_to_sf __truncdfsf2
302 #define INLINE __inline__
305 /* Preserve the sticky-bit when shifting fractions to the right. */
306 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
308 /* numeric parameters */
309 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
310 of a float and of a double. Assumes there are only two float types.
311 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
313 #define F_D_BITOFF (52+8-(23+7))
316 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
317 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
318 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
356 halffractype words[2];
359 #ifdef FLOAT_BIT_ORDER_MISMATCH
362 fractype fraction:FRACBITS __attribute__ ((packed));
363 unsigned int exp:EXPBITS __attribute__ ((packed));
364 unsigned int sign:1 __attribute__ ((packed));
369 #ifdef _DEBUG_BITFLOAT
372 unsigned int sign:1 __attribute__ ((packed));
373 unsigned int exp:EXPBITS __attribute__ ((packed));
374 fractype fraction:FRACBITS __attribute__ ((packed));
380 fractype fraction:FRACBITS __attribute__ ((packed));
381 unsigned int exp:EXPBITS __attribute__ ((packed));
382 unsigned int sign:1 __attribute__ ((packed));
392 /* IEEE "special" number predicates */
401 #if defined L_thenan_sf
402 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, (fractype) 0 };
403 #elif defined L_thenan_df
404 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, (fractype) 0 };
406 extern const fp_number_type __thenan_sf;
408 extern const fp_number_type __thenan_df;
412 static fp_number_type *
415 /* Discard the const qualifier... */
417 return (fp_number_type *) (& __thenan_sf);
419 return (fp_number_type *) (& __thenan_df);
425 isnan ( fp_number_type * x)
427 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
432 isinf ( fp_number_type * x)
434 return x->class == CLASS_INFINITY;
441 iszero ( fp_number_type * x)
443 return x->class == CLASS_ZERO;
448 flip_sign ( fp_number_type * x)
453 extern FLO_type pack_d ( fp_number_type * );
455 #if defined(L_pack_df) || defined(L_pack_sf)
457 pack_d ( fp_number_type * src)
460 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
461 int sign = src->sign;
467 if (src->class == CLASS_QNAN || 1)
469 fraction |= QUIET_NAN;
472 else if (isinf (src))
477 else if (iszero (src))
482 else if (fraction == 0)
488 if (src->normal_exp < NORMAL_EXPMIN)
490 /* This number's exponent is too low to fit into the bits
491 available in the number, so we'll store 0 in the exponent and
492 shift the fraction to the right to make up for it. */
494 int shift = NORMAL_EXPMIN - src->normal_exp;
498 if (shift > FRAC_NBITS - NGARDS)
500 /* No point shifting, since it's more that 64 out. */
505 /* Shift by the value */
510 else if (src->normal_exp > EXPBIAS)
517 exp = src->normal_exp + EXPBIAS;
518 /* IF the gard bits are the all zero, but the first, then we're
519 half way between two numbers, choose the one which makes the
520 lsb of the answer 0. */
521 if ((fraction & GARDMASK) == GARDMSB)
523 if (fraction & (1 << NGARDS))
524 fraction += GARDROUND + 1;
528 /* Add a one to the guards to round up */
529 fraction += GARDROUND;
531 if (fraction >= IMPLICIT_2)
540 /* We previously used bitfields to store the number, but this doesn't
541 handle little/big endian systems conveniently, so use shifts and
543 #ifdef FLOAT_BIT_ORDER_MISMATCH
544 dst.bits.fraction = fraction;
546 dst.bits.sign = sign;
548 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
549 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
550 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
553 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
555 halffractype tmp = dst.words[0];
556 dst.words[0] = dst.words[1];
565 extern void unpack_d (FLO_union_type *, fp_number_type *);
567 #if defined(L_unpack_df) || defined(L_unpack_sf)
569 unpack_d (FLO_union_type * src, fp_number_type * dst)
571 /* We previously used bitfields to store the number, but this doesn't
572 handle little/big endian systems conveniently, so use shifts and
578 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
579 FLO_union_type swapped;
581 swapped.words[0] = src->words[1];
582 swapped.words[1] = src->words[0];
586 #ifdef FLOAT_BIT_ORDER_MISMATCH
587 fraction = src->bits.fraction;
589 sign = src->bits.sign;
591 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
592 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
593 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
599 /* Hmm. Looks like 0 */
602 /* tastes like zero */
603 dst->class = CLASS_ZERO;
607 /* Zero exponent with non zero fraction - it's denormalized,
608 so there isn't a leading implicit one - we'll shift it so
610 dst->normal_exp = exp - EXPBIAS + 1;
613 dst->class = CLASS_NUMBER;
615 while (fraction < IMPLICIT_1)
621 dst->fraction.ll = fraction;
624 else if (exp == EXPMAX)
629 /* Attached to a zero fraction - means infinity */
630 dst->class = CLASS_INFINITY;
634 /* Non zero fraction, means nan */
635 if (fraction & QUIET_NAN)
637 dst->class = CLASS_QNAN;
641 dst->class = CLASS_SNAN;
643 /* Keep the fraction part as the nan number */
644 dst->fraction.ll = fraction;
649 /* Nothing strange about this number */
650 dst->normal_exp = exp - EXPBIAS;
651 dst->class = CLASS_NUMBER;
652 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
657 #if defined(L_addsub_sf) || defined(L_addsub_df)
658 static fp_number_type *
659 _fpadd_parts (fp_number_type * a,
661 fp_number_type * tmp)
665 /* Put commonly used fields in local variables. */
681 /* Adding infinities with opposite signs yields a NaN. */
682 if (isinf (b) && a->sign != b->sign)
695 tmp->sign = a->sign & b->sign;
705 /* Got two numbers. shift the smaller and increment the exponent till
710 a_normal_exp = a->normal_exp;
711 b_normal_exp = b->normal_exp;
712 a_fraction = a->fraction.ll;
713 b_fraction = b->fraction.ll;
715 diff = a_normal_exp - b_normal_exp;
719 if (diff < FRAC_NBITS)
721 /* ??? This does shifts one bit at a time. Optimize. */
722 while (a_normal_exp > b_normal_exp)
727 while (b_normal_exp > a_normal_exp)
735 /* Somethings's up.. choose the biggest */
736 if (a_normal_exp > b_normal_exp)
738 b_normal_exp = a_normal_exp;
743 a_normal_exp = b_normal_exp;
749 if (a->sign != b->sign)
753 tfraction = -a_fraction + b_fraction;
757 tfraction = a_fraction - b_fraction;
762 tmp->normal_exp = a_normal_exp;
763 tmp->fraction.ll = tfraction;
768 tmp->normal_exp = a_normal_exp;
769 tmp->fraction.ll = -tfraction;
771 /* and renormalize it */
773 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
775 tmp->fraction.ll <<= 1;
782 tmp->normal_exp = a_normal_exp;
783 tmp->fraction.ll = a_fraction + b_fraction;
785 tmp->class = CLASS_NUMBER;
786 /* Now the fraction is added, we have to shift down to renormalize the
789 if (tmp->fraction.ll >= IMPLICIT_2)
791 LSHIFT (tmp->fraction.ll);
799 add (FLO_type arg_a, FLO_type arg_b)
805 FLO_union_type au, bu;
813 res = _fpadd_parts (&a, &b, &tmp);
819 sub (FLO_type arg_a, FLO_type arg_b)
825 FLO_union_type au, bu;
835 res = _fpadd_parts (&a, &b, &tmp);
841 #if defined(L_mul_sf) || defined(L_mul_df)
842 static INLINE fp_number_type *
843 _fpmul_parts ( fp_number_type * a,
845 fp_number_type * tmp)
852 a->sign = a->sign != b->sign;
857 b->sign = a->sign != b->sign;
864 a->sign = a->sign != b->sign;
873 b->sign = a->sign != b->sign;
878 a->sign = a->sign != b->sign;
883 b->sign = a->sign != b->sign;
887 /* Calculate the mantissa by multiplying both 64bit numbers to get a
890 #if defined(NO_DI_MODE)
892 fractype x = a->fraction.ll;
893 fractype ylow = b->fraction.ll;
897 /* ??? This does multiplies one bit at a time. Optimize. */
898 for (bit = 0; bit < FRAC_NBITS; bit++)
904 carry = (low += ylow) < ylow;
905 high += yhigh + carry;
918 /* Multiplying two 32 bit numbers to get a 64 bit number on
919 a machine with DI, so we're safe */
921 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
927 /* Doing a 64*64 to 128 */
929 UDItype nl = a->fraction.ll & 0xffffffff;
930 UDItype nh = a->fraction.ll >> 32;
931 UDItype ml = b->fraction.ll & 0xffffffff;
932 UDItype mh = b->fraction.ll >>32;
933 UDItype pp_ll = ml * nl;
934 UDItype pp_hl = mh * nl;
935 UDItype pp_lh = ml * nh;
936 UDItype pp_hh = mh * nh;
939 UDItype ps_hh__ = pp_hl + pp_lh;
941 res2 += 0x100000000LL;
942 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
943 res0 = pp_ll + pp_hl;
946 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
953 tmp->normal_exp = a->normal_exp + b->normal_exp;
954 tmp->sign = a->sign != b->sign;
956 tmp->normal_exp += 2; /* ??????????????? */
958 tmp->normal_exp += 4; /* ??????????????? */
960 while (high >= IMPLICIT_2)
970 while (high < IMPLICIT_1)
979 /* rounding is tricky. if we only round if it won't make us round later. */
983 if (((high & GARDMASK) != GARDMSB)
984 && (((high + 1) & GARDMASK) == GARDMSB))
986 /* don't round, it gets done again later. */
994 if ((high & GARDMASK) == GARDMSB)
996 if (high & (1 << NGARDS))
998 /* half way, so round to even */
999 high += GARDROUND + 1;
1003 /* but we really weren't half way */
1004 high += GARDROUND + 1;
1007 tmp->fraction.ll = high;
1008 tmp->class = CLASS_NUMBER;
1013 multiply (FLO_type arg_a, FLO_type arg_b)
1018 fp_number_type *res;
1019 FLO_union_type au, bu;
1027 res = _fpmul_parts (&a, &b, &tmp);
1029 return pack_d (res);
1033 #if defined(L_div_sf) || defined(L_div_df)
1034 static INLINE fp_number_type *
1035 _fpdiv_parts (fp_number_type * a,
1040 fractype denominator;
1052 a->sign = a->sign ^ b->sign;
1054 if (isinf (a) || iszero (a))
1056 if (a->class == b->class)
1069 a->class = CLASS_INFINITY;
1073 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1077 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1080 a->normal_exp = a->normal_exp - b->normal_exp;
1081 numerator = a->fraction.ll;
1082 denominator = b->fraction.ll;
1084 if (numerator < denominator)
1086 /* Fraction will be less than 1.0 */
1092 /* ??? Does divide one bit at a time. Optimize. */
1095 if (numerator >= denominator)
1098 numerator -= denominator;
1104 if ((quotient & GARDMASK) == GARDMSB)
1106 if (quotient & (1 << NGARDS))
1108 /* half way, so round to even */
1109 quotient += GARDROUND + 1;
1113 /* but we really weren't half way, more bits exist */
1114 quotient += GARDROUND + 1;
1118 a->fraction.ll = quotient;
1124 divide (FLO_type arg_a, FLO_type arg_b)
1128 fp_number_type *res;
1129 FLO_union_type au, bu;
1137 res = _fpdiv_parts (&a, &b);
1139 return pack_d (res);
1143 int __fpcmp_parts (fp_number_type * a, fp_number_type *b);
1145 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
1146 /* according to the demo, fpcmp returns a comparison with 0... thus
1153 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1156 /* either nan -> unordered. Must be checked outside of this routine. */
1157 if (isnan (a) && isnan (b))
1159 return 1; /* still unordered! */
1163 if (isnan (a) || isnan (b))
1165 return 1; /* how to indicate unordered compare? */
1167 if (isinf (a) && isinf (b))
1169 /* +inf > -inf, but +inf != +inf */
1170 /* b \a| +inf(0)| -inf(1)
1171 ______\+--------+--------
1172 +inf(0)| a==b(0)| a<b(-1)
1173 -------+--------+--------
1174 -inf(1)| a>b(1) | a==b(0)
1175 -------+--------+--------
1176 So since unordered must be non zero, just line up the columns...
1178 return b->sign - a->sign;
1180 /* but not both... */
1183 return a->sign ? -1 : 1;
1187 return b->sign ? 1 : -1;
1189 if (iszero (a) && iszero (b))
1195 return b->sign ? 1 : -1;
1199 return a->sign ? -1 : 1;
1201 /* now both are "normal". */
1202 if (a->sign != b->sign)
1204 /* opposite signs */
1205 return a->sign ? -1 : 1;
1207 /* same sign; exponents? */
1208 if (a->normal_exp > b->normal_exp)
1210 return a->sign ? -1 : 1;
1212 if (a->normal_exp < b->normal_exp)
1214 return a->sign ? 1 : -1;
1216 /* same exponents; check size. */
1217 if (a->fraction.ll > b->fraction.ll)
1219 return a->sign ? -1 : 1;
1221 if (a->fraction.ll < b->fraction.ll)
1223 return a->sign ? 1 : -1;
1225 /* after all that, they're equal. */
1230 #if defined(L_compare_sf) || defined(L_compare_df)
1232 compare (FLO_type arg_a, FLO_type arg_b)
1236 FLO_union_type au, bu;
1244 return __fpcmp_parts (&a, &b);
1248 #ifndef US_SOFTWARE_GOFAST
1250 /* These should be optimized for their specific tasks someday. */
1252 #if defined(L_eq_sf) || defined(L_eq_df)
1254 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1258 FLO_union_type au, bu;
1266 if (isnan (&a) || isnan (&b))
1267 return 1; /* false, truth == 0 */
1269 return __fpcmp_parts (&a, &b) ;
1273 #if defined(L_ne_sf) || defined(L_ne_df)
1275 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1279 FLO_union_type au, bu;
1287 if (isnan (&a) || isnan (&b))
1288 return 1; /* true, truth != 0 */
1290 return __fpcmp_parts (&a, &b) ;
1294 #if defined(L_gt_sf) || defined(L_gt_df)
1296 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1300 FLO_union_type au, bu;
1308 if (isnan (&a) || isnan (&b))
1309 return -1; /* false, truth > 0 */
1311 return __fpcmp_parts (&a, &b);
1315 #if defined(L_ge_sf) || defined(L_ge_df)
1317 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1321 FLO_union_type au, bu;
1329 if (isnan (&a) || isnan (&b))
1330 return -1; /* false, truth >= 0 */
1331 return __fpcmp_parts (&a, &b) ;
1335 #if defined(L_lt_sf) || defined(L_lt_df)
1337 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1341 FLO_union_type au, bu;
1349 if (isnan (&a) || isnan (&b))
1350 return 1; /* false, truth < 0 */
1352 return __fpcmp_parts (&a, &b);
1356 #if defined(L_le_sf) || defined(L_le_df)
1358 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1362 FLO_union_type au, bu;
1370 if (isnan (&a) || isnan (&b))
1371 return 1; /* false, truth <= 0 */
1373 return __fpcmp_parts (&a, &b) ;
1377 #if defined(L_unord_sf) || defined(L_unord_df)
1379 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1383 FLO_union_type au, bu;
1391 return (isnan (&a) || isnan (&b);
1395 #endif /* ! US_SOFTWARE_GOFAST */
1397 #if defined(L_si_to_sf) || defined(L_si_to_df)
1399 si_to_float (SItype arg_a)
1403 in.class = CLASS_NUMBER;
1404 in.sign = arg_a < 0;
1407 in.class = CLASS_ZERO;
1411 in.normal_exp = FRACBITS + NGARDS;
1414 /* Special case for minint, since there is no +ve integer
1415 representation for it */
1416 if (arg_a == (SItype) 0x80000000)
1418 return -2147483648.0;
1420 in.fraction.ll = (-arg_a);
1423 in.fraction.ll = arg_a;
1425 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1427 in.fraction.ll <<= 1;
1431 return pack_d (&in);
1435 #if defined(L_sf_to_si) || defined(L_df_to_si)
1437 float_to_si (FLO_type arg_a)
1450 /* get reasonable MAX_SI_INT... */
1452 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1453 /* it is a number, but a small one */
1454 if (a.normal_exp < 0)
1456 if (a.normal_exp > 30)
1457 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1458 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1459 return a.sign ? (-tmp) : (tmp);
1463 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1464 #ifdef US_SOFTWARE_GOFAST
1465 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1466 we also define them for GOFAST because the ones in libgcc2.c have the
1467 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1468 out of libgcc2.c. We can't define these here if not GOFAST because then
1469 there'd be duplicate copies. */
1472 float_to_usi (FLO_type arg_a)
1484 /* it is a negative number */
1487 /* get reasonable MAX_USI_INT... */
1490 /* it is a number, but a small one */
1491 if (a.normal_exp < 0)
1493 if (a.normal_exp > 31)
1495 else if (a.normal_exp > (FRACBITS + NGARDS))
1496 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1498 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1503 #if defined(L_negate_sf) || defined(L_negate_df)
1505 negate (FLO_type arg_a)
1520 #if defined(L_make_sf)
1522 __make_fp(fp_class_type class,
1531 in.normal_exp = exp;
1532 in.fraction.ll = frac;
1533 return pack_d (&in);
1539 /* This enables one to build an fp library that supports float but not double.
1540 Otherwise, we would get an undefined reference to __make_dp.
1541 This is needed for some 8-bit ports that can't handle well values that
1542 are 8-bytes in size, so we just don't support double for them at all. */
1544 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1546 #if defined(L_sf_to_df)
1548 sf_to_df (SFtype arg_a)
1554 unpack_d (&au, &in);
1556 return __make_dp (in.class, in.sign, in.normal_exp,
1557 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1566 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1568 #if defined(L_make_df)
1570 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1576 in.normal_exp = exp;
1577 in.fraction.ll = frac;
1578 return pack_d (&in);
1582 #if defined(L_df_to_sf)
1584 df_to_sf (DFtype arg_a)
1591 unpack_d (&au, &in);
1593 sffrac = in.fraction.ll >> F_D_BITOFF;
1595 /* We set the lowest guard bit in SFFRAC if we discarded any non
1597 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1600 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1605 #endif /* !EXTENDED_FLOAT_STUBS */