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 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
95 /* The following macros can be defined to change the behaviour of this file:
96 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
97 defined, then this file implements a `double', aka DFmode, fp library.
98 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
99 don't include float->double conversion which requires the double library.
100 This is useful only for machines which can't support doubles, e.g. some
102 CMPtype: Specify the type that floating point compares should return.
103 This defaults to SItype, aka int.
104 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
105 US Software goFast library. If this is not defined, the entry points use
106 the same names as libgcc1.c.
107 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
108 two integers to the FLO_union_type.
109 NO_NANS: Disable nan and infinity handling
110 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
113 /* We don't currently support extended floats (long doubles) on machines
114 without hardware to deal with them.
116 These stubs are just to keep the linker from complaining about unresolved
117 references which can be pulled in from libio & libstdc++, even if the
118 user isn't using long doubles. However, they may generate an unresolved
119 external to abort if abort is not used by the function, and the stubs
120 are referenced from within libc, since libgcc goes before and after the
123 #ifdef EXTENDED_FLOAT_STUBS
124 __truncxfsf2 (){ abort(); }
125 __extendsfxf2 (){ abort(); }
126 __addxf3 (){ abort(); }
127 __divxf3 (){ abort(); }
128 __eqxf2 (){ abort(); }
129 __extenddfxf2 (){ abort(); }
130 __gtxf2 (){ abort(); }
131 __lexf2 (){ abort(); }
132 __ltxf2 (){ abort(); }
133 __mulxf3 (){ abort(); }
134 __negxf2 (){ abort(); }
135 __nexf2 (){ abort(); }
136 __subxf3 (){ abort(); }
137 __truncxfdf2 (){ abort(); }
139 __trunctfsf2 (){ abort(); }
140 __extendsftf2 (){ abort(); }
141 __addtf3 (){ abort(); }
142 __divtf3 (){ abort(); }
143 __eqtf2 (){ abort(); }
144 __extenddftf2 (){ abort(); }
145 __gttf2 (){ abort(); }
146 __letf2 (){ abort(); }
147 __lttf2 (){ abort(); }
148 __multf3 (){ abort(); }
149 __negtf2 (){ abort(); }
150 __netf2 (){ abort(); }
151 __subtf3 (){ abort(); }
152 __trunctfdf2 (){ abort(); }
153 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
156 typedef SFtype __attribute__ ((mode (SF)));
157 typedef DFtype __attribute__ ((mode (DF)));
159 typedef int HItype __attribute__ ((mode (HI)));
160 typedef int SItype __attribute__ ((mode (SI)));
161 typedef int DItype __attribute__ ((mode (DI)));
163 /* The type of the result of a fp compare */
165 #define CMPtype SItype
168 typedef unsigned int UHItype __attribute__ ((mode (HI)));
169 typedef unsigned int USItype __attribute__ ((mode (SI)));
170 typedef unsigned int UDItype __attribute__ ((mode (DI)));
172 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
173 #define MAX_USI_INT ((USItype) ~0)
182 # define GARDROUND 0x3f
183 # define GARDMASK 0x7f
184 # define GARDMSB 0x40
188 # define EXPMAX (0xff)
189 # define QUIET_NAN 0x100000L
190 # define FRAC_NBITS 32
191 # define FRACHIGH 0x80000000L
192 # define FRACHIGH2 0xc0000000L
193 # define pack_d __pack_f
194 # define unpack_d __unpack_f
195 # define __fpcmp_parts __fpcmp_parts_f
196 typedef USItype fractype;
197 typedef UHItype halffractype;
198 typedef SFtype FLO_type;
199 typedef SItype intfrac;
202 # define PREFIXFPDP dp
203 # define PREFIXSFDF df
205 # define GARDROUND 0x7f
206 # define GARDMASK 0xff
207 # define GARDMSB 0x80
209 # define EXPBIAS 1023
211 # define EXPMAX (0x7ff)
212 # define QUIET_NAN 0x8000000000000LL
213 # define FRAC_NBITS 64
214 # define FRACHIGH 0x8000000000000000LL
215 # define FRACHIGH2 0xc000000000000000LL
216 # define pack_d __pack_d
217 # define unpack_d __unpack_d
218 # define __fpcmp_parts __fpcmp_parts_d
219 typedef UDItype fractype;
220 typedef USItype halffractype;
221 typedef DFtype FLO_type;
222 typedef DItype intfrac;
225 #ifdef US_SOFTWARE_GOFAST
229 # define multiply fpmul
230 # define divide fpdiv
231 # define compare fpcmp
232 # define si_to_float sitofp
233 # define float_to_si fptosi
234 # define float_to_usi fptoui
235 # define negate __negsf2
236 # define sf_to_df fptodp
237 # define dptofp dptofp
241 # define multiply dpmul
242 # define divide dpdiv
243 # define compare dpcmp
244 # define si_to_float litodp
245 # define float_to_si dptoli
246 # define float_to_usi dptoul
247 # define negate __negdf2
248 # define df_to_sf dptofp
252 # define add __addsf3
253 # define sub __subsf3
254 # define multiply __mulsf3
255 # define divide __divsf3
256 # define compare __cmpsf2
257 # define _eq_f2 __eqsf2
258 # define _ne_f2 __nesf2
259 # define _gt_f2 __gtsf2
260 # define _ge_f2 __gesf2
261 # define _lt_f2 __ltsf2
262 # define _le_f2 __lesf2
263 # define si_to_float __floatsisf
264 # define float_to_si __fixsfsi
265 # define float_to_usi __fixunssfsi
266 # define negate __negsf2
267 # define sf_to_df __extendsfdf2
269 # define add __adddf3
270 # define sub __subdf3
271 # define multiply __muldf3
272 # define divide __divdf3
273 # define compare __cmpdf2
274 # define _eq_f2 __eqdf2
275 # define _ne_f2 __nedf2
276 # define _gt_f2 __gtdf2
277 # define _ge_f2 __gedf2
278 # define _lt_f2 __ltdf2
279 # define _le_f2 __ledf2
280 # define si_to_float __floatsidf
281 # define float_to_si __fixdfsi
282 # define float_to_usi __fixunsdfsi
283 # define negate __negdf2
284 # define df_to_sf __truncdfsf2
290 #define INLINE __inline__
293 /* Preserve the sticky-bit when shifting fractions to the right. */
294 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
296 /* numeric parameters */
297 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
298 of a float and of a double. Assumes there are only two float types.
299 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
301 #define F_D_BITOFF (52+8-(23+7))
304 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
305 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
306 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
344 halffractype words[2];
347 #ifdef FLOAT_BIT_ORDER_MISMATCH
350 fractype fraction:FRACBITS __attribute__ ((packed));
351 unsigned int exp:EXPBITS __attribute__ ((packed));
352 unsigned int sign:1 __attribute__ ((packed));
357 #ifdef _DEBUG_BITFLOAT
360 unsigned int sign:1 __attribute__ ((packed));
361 unsigned int exp:EXPBITS __attribute__ ((packed));
362 fractype fraction:FRACBITS __attribute__ ((packed));
368 fractype fraction:FRACBITS __attribute__ ((packed));
369 unsigned int exp:EXPBITS __attribute__ ((packed));
370 unsigned int sign:1 __attribute__ ((packed));
380 /* IEEE "special" number predicates */
390 static fp_number_type *
393 static fp_number_type thenan;
400 isnan ( fp_number_type * x)
402 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
407 isinf ( fp_number_type * x)
409 return x->class == CLASS_INFINITY;
416 iszero ( fp_number_type * x)
418 return x->class == CLASS_ZERO;
423 flip_sign ( fp_number_type * x)
428 extern FLO_type pack_d ( fp_number_type * );
430 #if defined(L_pack_df) || defined(L_pack_sf)
432 pack_d ( fp_number_type * src)
435 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
436 int sign = src->sign;
442 if (src->class == CLASS_QNAN || 1)
444 fraction |= QUIET_NAN;
447 else if (isinf (src))
452 else if (iszero (src))
457 else if (fraction == 0)
464 if (src->normal_exp < NORMAL_EXPMIN)
466 /* This number's exponent is too low to fit into the bits
467 available in the number, so we'll store 0 in the exponent and
468 shift the fraction to the right to make up for it. */
470 int shift = NORMAL_EXPMIN - src->normal_exp;
474 if (shift > FRAC_NBITS - NGARDS)
476 /* No point shifting, since it's more that 64 out. */
481 /* Shift by the value */
486 else if (src->normal_exp > EXPBIAS)
493 exp = src->normal_exp + EXPBIAS;
494 /* IF the gard bits are the all zero, but the first, then we're
495 half way between two numbers, choose the one which makes the
496 lsb of the answer 0. */
497 if ((fraction & GARDMASK) == GARDMSB)
499 if (fraction & (1 << NGARDS))
500 fraction += GARDROUND + 1;
504 /* Add a one to the guards to round up */
505 fraction += GARDROUND;
507 if (fraction >= IMPLICIT_2)
516 /* We previously used bitfields to store the number, but this doesn't
517 handle little/big endian systems conveniently, so use shifts and
519 #ifdef FLOAT_BIT_ORDER_MISMATCH
520 dst.bits.fraction = fraction;
522 dst.bits.sign = sign;
524 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
525 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
526 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
529 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
531 halffractype tmp = dst.words[0];
532 dst.words[0] = dst.words[1];
541 extern void unpack_d (FLO_union_type *, fp_number_type *);
543 #if defined(L_unpack_df) || defined(L_unpack_sf)
545 unpack_d (FLO_union_type * src, fp_number_type * dst)
547 /* We previously used bitfields to store the number, but this doesn't
548 handle little/big endian systems conveniently, so use shifts and
554 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
555 FLO_union_type swapped;
557 swapped.words[0] = src->words[1];
558 swapped.words[1] = src->words[0];
562 #ifdef FLOAT_BIT_ORDER_MISMATCH
563 fraction = src->bits.fraction;
565 sign = src->bits.sign;
567 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
568 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
569 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
575 /* Hmm. Looks like 0 */
578 /* tastes like zero */
579 dst->class = CLASS_ZERO;
583 /* Zero exponent with non zero fraction - it's denormalized,
584 so there isn't a leading implicit one - we'll shift it so
586 dst->normal_exp = exp - EXPBIAS + 1;
589 dst->class = CLASS_NUMBER;
591 while (fraction < IMPLICIT_1)
597 dst->fraction.ll = fraction;
600 else if (exp == EXPMAX)
605 /* Attached to a zero fraction - means infinity */
606 dst->class = CLASS_INFINITY;
610 /* Non zero fraction, means nan */
611 if (fraction & QUIET_NAN)
613 dst->class = CLASS_QNAN;
617 dst->class = CLASS_SNAN;
619 /* Keep the fraction part as the nan number */
620 dst->fraction.ll = fraction;
625 /* Nothing strange about this number */
626 dst->normal_exp = exp - EXPBIAS;
627 dst->class = CLASS_NUMBER;
628 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
633 #if defined(L_addsub_sf) || defined(L_addsub_df)
634 static fp_number_type *
635 _fpadd_parts (fp_number_type * a,
637 fp_number_type * tmp)
641 /* Put commonly used fields in local variables. */
657 /* Adding infinities with opposite signs yields a NaN. */
658 if (isinf (b) && a->sign != b->sign)
671 tmp->sign = a->sign & b->sign;
681 /* Got two numbers. shift the smaller and increment the exponent till
686 a_normal_exp = a->normal_exp;
687 b_normal_exp = b->normal_exp;
688 a_fraction = a->fraction.ll;
689 b_fraction = b->fraction.ll;
691 diff = a_normal_exp - b_normal_exp;
695 if (diff < FRAC_NBITS)
697 /* ??? This does shifts one bit at a time. Optimize. */
698 while (a_normal_exp > b_normal_exp)
703 while (b_normal_exp > a_normal_exp)
711 /* Somethings's up.. choose the biggest */
712 if (a_normal_exp > b_normal_exp)
714 b_normal_exp = a_normal_exp;
719 a_normal_exp = b_normal_exp;
725 if (a->sign != b->sign)
729 tfraction = -a_fraction + b_fraction;
733 tfraction = a_fraction - b_fraction;
738 tmp->normal_exp = a_normal_exp;
739 tmp->fraction.ll = tfraction;
744 tmp->normal_exp = a_normal_exp;
745 tmp->fraction.ll = -tfraction;
747 /* and renormalize it */
749 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
751 tmp->fraction.ll <<= 1;
758 tmp->normal_exp = a_normal_exp;
759 tmp->fraction.ll = a_fraction + b_fraction;
761 tmp->class = CLASS_NUMBER;
762 /* Now the fraction is added, we have to shift down to renormalize the
765 if (tmp->fraction.ll >= IMPLICIT_2)
767 LSHIFT (tmp->fraction.ll);
775 add (FLO_type arg_a, FLO_type arg_b)
782 unpack_d ((FLO_union_type *) & arg_a, &a);
783 unpack_d ((FLO_union_type *) & arg_b, &b);
785 res = _fpadd_parts (&a, &b, &tmp);
791 sub (FLO_type arg_a, FLO_type arg_b)
798 unpack_d ((FLO_union_type *) & arg_a, &a);
799 unpack_d ((FLO_union_type *) & arg_b, &b);
803 res = _fpadd_parts (&a, &b, &tmp);
809 #if defined(L_mul_sf) || defined(L_mul_df)
810 static INLINE fp_number_type *
811 _fpmul_parts ( fp_number_type * a,
813 fp_number_type * tmp)
820 a->sign = a->sign != b->sign;
825 b->sign = a->sign != b->sign;
832 a->sign = a->sign != b->sign;
841 b->sign = a->sign != b->sign;
846 a->sign = a->sign != b->sign;
851 b->sign = a->sign != b->sign;
855 /* Calculate the mantissa by multiplying both 64bit numbers to get a
858 #if defined(NO_DI_MODE)
860 fractype x = a->fraction.ll;
861 fractype ylow = b->fraction.ll;
865 /* ??? This does multiplies one bit at a time. Optimize. */
866 for (bit = 0; bit < FRAC_NBITS; bit++)
872 carry = (low += ylow) < ylow;
873 high += yhigh + carry;
886 /* Multiplying two 32 bit numbers to get a 64 bit number on
887 a machine with DI, so we're safe */
889 DItype answer = (DItype)(a->fraction.ll) * (DItype)(b->fraction.ll);
895 /* Doing a 64*64 to 128 */
897 UDItype nl = a->fraction.ll & 0xffffffff;
898 UDItype nh = a->fraction.ll >> 32;
899 UDItype ml = b->fraction.ll & 0xffffffff;
900 UDItype mh = b->fraction.ll >>32;
901 UDItype pp_ll = ml * nl;
902 UDItype pp_hl = mh * nl;
903 UDItype pp_lh = ml * nh;
904 UDItype pp_hh = mh * nh;
907 UDItype ps_hh__ = pp_hl + pp_lh;
909 res2 += 0x100000000LL;
910 pp_hl = (ps_hh__ << 32) & 0xffffffff00000000LL;
911 res0 = pp_ll + pp_hl;
914 res2 += ((ps_hh__ >> 32) & 0xffffffffL) + pp_hh;
921 tmp->normal_exp = a->normal_exp + b->normal_exp;
922 tmp->sign = a->sign != b->sign;
924 tmp->normal_exp += 2; /* ??????????????? */
926 tmp->normal_exp += 4; /* ??????????????? */
928 while (high >= IMPLICIT_2)
938 while (high < IMPLICIT_1)
947 /* rounding is tricky. if we only round if it won't make us round later. */
951 if (((high & GARDMASK) != GARDMSB)
952 && (((high + 1) & GARDMASK) == GARDMSB))
954 /* don't round, it gets done again later. */
962 if ((high & GARDMASK) == GARDMSB)
964 if (high & (1 << NGARDS))
966 /* half way, so round to even */
967 high += GARDROUND + 1;
971 /* but we really weren't half way */
972 high += GARDROUND + 1;
975 tmp->fraction.ll = high;
976 tmp->class = CLASS_NUMBER;
981 multiply (FLO_type arg_a, FLO_type arg_b)
988 unpack_d ((FLO_union_type *) & arg_a, &a);
989 unpack_d ((FLO_union_type *) & arg_b, &b);
991 res = _fpmul_parts (&a, &b, &tmp);
997 #if defined(L_div_sf) || defined(L_div_df)
998 static INLINE fp_number_type *
999 _fpdiv_parts (fp_number_type * a,
1001 fp_number_type * tmp)
1005 fractype denominator;
1017 a->sign = a->sign ^ b->sign;
1019 if (isinf (a) || iszero (a))
1021 if (a->class == b->class)
1034 a->class = CLASS_INFINITY;
1038 /* Calculate the mantissa by multiplying both 64bit numbers to get a
1042 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1045 a->normal_exp = a->normal_exp - b->normal_exp;
1046 numerator = a->fraction.ll;
1047 denominator = b->fraction.ll;
1049 if (numerator < denominator)
1051 /* Fraction will be less than 1.0 */
1057 /* ??? Does divide one bit at a time. Optimize. */
1060 if (numerator >= denominator)
1063 numerator -= denominator;
1069 if ((quotient & GARDMASK) == GARDMSB)
1071 if (quotient & (1 << NGARDS))
1073 /* half way, so round to even */
1074 quotient += GARDROUND + 1;
1078 /* but we really weren't half way, more bits exist */
1079 quotient += GARDROUND + 1;
1083 a->fraction.ll = quotient;
1089 divide (FLO_type arg_a, FLO_type arg_b)
1094 fp_number_type *res;
1096 unpack_d ((FLO_union_type *) & arg_a, &a);
1097 unpack_d ((FLO_union_type *) & arg_b, &b);
1099 res = _fpdiv_parts (&a, &b, &tmp);
1101 return pack_d (res);
1105 int __fpcmp_parts (fp_number_type * a, fp_number_type *b);
1107 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
1108 /* according to the demo, fpcmp returns a comparison with 0... thus
1115 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1118 /* either nan -> unordered. Must be checked outside of this routine. */
1119 if (isnan (a) && isnan (b))
1121 return 1; /* still unordered! */
1125 if (isnan (a) || isnan (b))
1127 return 1; /* how to indicate unordered compare? */
1129 if (isinf (a) && isinf (b))
1131 /* +inf > -inf, but +inf != +inf */
1132 /* b \a| +inf(0)| -inf(1)
1133 ______\+--------+--------
1134 +inf(0)| a==b(0)| a<b(-1)
1135 -------+--------+--------
1136 -inf(1)| a>b(1) | a==b(0)
1137 -------+--------+--------
1138 So since unordered must be non zero, just line up the columns...
1140 return b->sign - a->sign;
1142 /* but not both... */
1145 return a->sign ? -1 : 1;
1149 return b->sign ? 1 : -1;
1151 if (iszero (a) && iszero (b))
1157 return b->sign ? 1 : -1;
1161 return a->sign ? -1 : 1;
1163 /* now both are "normal". */
1164 if (a->sign != b->sign)
1166 /* opposite signs */
1167 return a->sign ? -1 : 1;
1169 /* same sign; exponents? */
1170 if (a->normal_exp > b->normal_exp)
1172 return a->sign ? -1 : 1;
1174 if (a->normal_exp < b->normal_exp)
1176 return a->sign ? 1 : -1;
1178 /* same exponents; check size. */
1179 if (a->fraction.ll > b->fraction.ll)
1181 return a->sign ? -1 : 1;
1183 if (a->fraction.ll < b->fraction.ll)
1185 return a->sign ? 1 : -1;
1187 /* after all that, they're equal. */
1192 #if defined(L_compare_sf) || defined(L_compare_df)
1194 compare (FLO_type arg_a, FLO_type arg_b)
1199 unpack_d ((FLO_union_type *) & arg_a, &a);
1200 unpack_d ((FLO_union_type *) & arg_b, &b);
1202 return __fpcmp_parts (&a, &b);
1206 #ifndef US_SOFTWARE_GOFAST
1208 /* These should be optimized for their specific tasks someday. */
1210 #if defined(L_eq_sf) || defined(L_eq_df)
1212 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1217 unpack_d ((FLO_union_type *) & arg_a, &a);
1218 unpack_d ((FLO_union_type *) & arg_b, &b);
1220 if (isnan (&a) || isnan (&b))
1221 return 1; /* false, truth == 0 */
1223 return __fpcmp_parts (&a, &b) ;
1227 #if defined(L_ne_sf) || defined(L_ne_df)
1229 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1234 unpack_d ((FLO_union_type *) & arg_a, &a);
1235 unpack_d ((FLO_union_type *) & arg_b, &b);
1237 if (isnan (&a) || isnan (&b))
1238 return 1; /* true, truth != 0 */
1240 return __fpcmp_parts (&a, &b) ;
1244 #if defined(L_gt_sf) || defined(L_gt_df)
1246 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1251 unpack_d ((FLO_union_type *) & arg_a, &a);
1252 unpack_d ((FLO_union_type *) & arg_b, &b);
1254 if (isnan (&a) || isnan (&b))
1255 return -1; /* false, truth > 0 */
1257 return __fpcmp_parts (&a, &b);
1261 #if defined(L_ge_sf) || defined(L_ge_df)
1263 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1268 unpack_d ((FLO_union_type *) & arg_a, &a);
1269 unpack_d ((FLO_union_type *) & arg_b, &b);
1271 if (isnan (&a) || isnan (&b))
1272 return -1; /* false, truth >= 0 */
1273 return __fpcmp_parts (&a, &b) ;
1277 #if defined(L_lt_sf) || defined(L_lt_df)
1279 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1284 unpack_d ((FLO_union_type *) & arg_a, &a);
1285 unpack_d ((FLO_union_type *) & arg_b, &b);
1287 if (isnan (&a) || isnan (&b))
1288 return 1; /* false, truth < 0 */
1290 return __fpcmp_parts (&a, &b);
1294 #if defined(L_le_sf) || defined(L_le_df)
1296 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1301 unpack_d ((FLO_union_type *) & arg_a, &a);
1302 unpack_d ((FLO_union_type *) & arg_b, &b);
1304 if (isnan (&a) || isnan (&b))
1305 return 1; /* false, truth <= 0 */
1307 return __fpcmp_parts (&a, &b) ;
1311 #endif /* ! US_SOFTWARE_GOFAST */
1313 #if defined(L_si_to_sf) || defined(L_si_to_df)
1315 si_to_float (SItype arg_a)
1319 in.class = CLASS_NUMBER;
1320 in.sign = arg_a < 0;
1323 in.class = CLASS_ZERO;
1327 in.normal_exp = FRACBITS + NGARDS;
1330 /* Special case for minint, since there is no +ve integer
1331 representation for it */
1332 if (arg_a == 0x80000000)
1334 return -2147483648.0;
1336 in.fraction.ll = (-arg_a);
1339 in.fraction.ll = arg_a;
1341 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1343 in.fraction.ll <<= 1;
1347 return pack_d (&in);
1351 #if defined(L_sf_to_si) || defined(L_df_to_si)
1353 float_to_si (FLO_type arg_a)
1358 unpack_d ((FLO_union_type *) & arg_a, &a);
1363 /* get reasonable MAX_SI_INT... */
1365 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1366 /* it is a number, but a small one */
1367 if (a.normal_exp < 0)
1369 if (a.normal_exp > 30)
1370 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1371 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1372 return a.sign ? (-tmp) : (tmp);
1376 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1377 #ifdef US_SOFTWARE_GOFAST
1378 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1379 we also define them for GOFAST because the ones in libgcc2.c have the
1380 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1381 out of libgcc2.c. We can't define these here if not GOFAST because then
1382 there'd be duplicate copies. */
1385 float_to_usi (FLO_type arg_a)
1389 unpack_d ((FLO_union_type *) & arg_a, &a);
1394 /* it is a negative number */
1397 /* get reasonable MAX_USI_INT... */
1400 /* it is a number, but a small one */
1401 if (a.normal_exp < 0)
1403 if (a.normal_exp > 31)
1405 else if (a.normal_exp > (FRACBITS + NGARDS))
1406 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1408 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1413 #if defined(L_negate_sf) || defined(L_negate_df)
1415 negate (FLO_type arg_a)
1419 unpack_d ((FLO_union_type *) & arg_a, &a);
1427 #if defined(L_make_sf)
1429 __make_fp(fp_class_type class,
1438 in.normal_exp = exp;
1439 in.fraction.ll = frac;
1440 return pack_d (&in);
1446 /* This enables one to build an fp library that supports float but not double.
1447 Otherwise, we would get an undefined reference to __make_dp.
1448 This is needed for some 8-bit ports that can't handle well values that
1449 are 8-bytes in size, so we just don't support double for them at all. */
1451 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype frac);
1453 #if defined(L_sf_to_df)
1455 sf_to_df (SFtype arg_a)
1459 unpack_d ((FLO_union_type *) & arg_a, &in);
1460 return __make_dp (in.class, in.sign, in.normal_exp,
1461 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1470 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1472 #if defined(L_make_df)
1474 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1480 in.normal_exp = exp;
1481 in.fraction.ll = frac;
1482 return pack_d (&in);
1486 #if defined(L_df_to_sf)
1488 df_to_sf (DFtype arg_a)
1493 unpack_d ((FLO_union_type *) & arg_a, &in);
1495 sffrac = in.fraction.ll >> F_D_BITOFF;
1497 /* We set the lowest guard bit in SFFRAC if we discarded any non
1499 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1502 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1507 #endif /* !EXTENDED_FLOAT_STUBS */