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
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"
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} };
136 extern const fp_number_type __thenan_sf;
138 extern const fp_number_type __thenan_df;
142 static fp_number_type *
145 /* Discard the const qualifier... */
147 return (fp_number_type *) (& __thenan_sf);
149 return (fp_number_type *) (& __thenan_df);
155 isnan ( fp_number_type * x)
157 return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
162 isinf ( fp_number_type * x)
164 return x->class == CLASS_INFINITY;
171 iszero ( fp_number_type * x)
173 return x->class == CLASS_ZERO;
178 flip_sign ( fp_number_type * x)
183 extern FLO_type pack_d ( fp_number_type * );
185 #if defined(L_pack_df) || defined(L_pack_sf)
187 pack_d ( fp_number_type * src)
190 fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
191 int sign = src->sign;
194 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
196 /* We can't represent these values accurately. By using the
197 largest possible magnitude, we guarantee that the conversion
198 of infinity is at least as big as any finite number. */
200 fraction = ((fractype) 1 << FRACBITS) - 1;
202 else if (isnan (src))
205 if (src->class == CLASS_QNAN || 1)
207 fraction |= QUIET_NAN;
210 else if (isinf (src))
215 else if (iszero (src))
220 else if (fraction == 0)
226 if (src->normal_exp < NORMAL_EXPMIN)
229 /* Go straight to a zero representation if denormals are not
230 supported. The denormal handling would be harmless but
231 isn't unnecessary. */
234 #else /* NO_DENORMALS */
235 /* This number's exponent is too low to fit into the bits
236 available in the number, so we'll store 0 in the exponent and
237 shift the fraction to the right to make up for it. */
239 int shift = NORMAL_EXPMIN - src->normal_exp;
243 if (shift > FRAC_NBITS - NGARDS)
245 /* No point shifting, since it's more that 64 out. */
250 int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
251 fraction = (fraction >> shift) | lowbit;
253 if ((fraction & GARDMASK) == GARDMSB)
255 if ((fraction & (1 << NGARDS)))
256 fraction += GARDROUND + 1;
260 /* Add to the guards to round up. */
261 fraction += GARDROUND;
263 /* Perhaps the rounding means we now need to change the
264 exponent, because the fraction is no longer denormal. */
265 if (fraction >= IMPLICIT_1)
270 #endif /* NO_DENORMALS */
272 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
273 && src->normal_exp > EXPBIAS)
280 exp = src->normal_exp + EXPBIAS;
281 if (!ROUND_TOWARDS_ZERO)
283 /* IF the gard bits are the all zero, but the first, then we're
284 half way between two numbers, choose the one which makes the
285 lsb of the answer 0. */
286 if ((fraction & GARDMASK) == GARDMSB)
288 if (fraction & (1 << NGARDS))
289 fraction += GARDROUND + 1;
293 /* Add a one to the guards to round up */
294 fraction += GARDROUND;
296 if (fraction >= IMPLICIT_2)
304 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
306 /* Saturate on overflow. */
308 fraction = ((fractype) 1 << FRACBITS) - 1;
313 /* We previously used bitfields to store the number, but this doesn't
314 handle little/big endian systems conveniently, so use shifts and
316 #ifdef FLOAT_BIT_ORDER_MISMATCH
317 dst.bits.fraction = fraction;
319 dst.bits.sign = sign;
321 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
322 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
323 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
326 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
328 halffractype tmp = dst.words[0];
329 dst.words[0] = dst.words[1];
338 #if defined(L_unpack_df) || defined(L_unpack_sf)
340 unpack_d (FLO_union_type * src, fp_number_type * dst)
342 /* We previously used bitfields to store the number, but this doesn't
343 handle little/big endian systems conveniently, so use shifts and
349 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
350 FLO_union_type swapped;
352 swapped.words[0] = src->words[1];
353 swapped.words[1] = src->words[0];
357 #ifdef FLOAT_BIT_ORDER_MISMATCH
358 fraction = src->bits.fraction;
360 sign = src->bits.sign;
362 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - (fractype)1);
363 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
364 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
370 /* Hmm. Looks like 0 */
377 /* tastes like zero */
378 dst->class = CLASS_ZERO;
382 /* Zero exponent with nonzero fraction - it's denormalized,
383 so there isn't a leading implicit one - we'll shift it so
385 dst->normal_exp = exp - EXPBIAS + 1;
388 dst->class = CLASS_NUMBER;
390 while (fraction < IMPLICIT_1)
396 dst->fraction.ll = fraction;
399 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
404 /* Attached to a zero fraction - means infinity */
405 dst->class = CLASS_INFINITY;
409 /* Nonzero fraction, means nan */
410 if (fraction & QUIET_NAN)
412 dst->class = CLASS_QNAN;
416 dst->class = CLASS_SNAN;
418 /* Keep the fraction part as the nan number */
419 dst->fraction.ll = fraction;
424 /* Nothing strange about this number */
425 dst->normal_exp = exp - EXPBIAS;
426 dst->class = CLASS_NUMBER;
427 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
430 #endif /* L_unpack_df || L_unpack_sf */
432 #if defined(L_addsub_sf) || defined(L_addsub_df)
433 static fp_number_type *
434 _fpadd_parts (fp_number_type * a,
436 fp_number_type * tmp)
440 /* Put commonly used fields in local variables. */
456 /* Adding infinities with opposite signs yields a NaN. */
457 if (isinf (b) && a->sign != b->sign)
470 tmp->sign = a->sign & b->sign;
480 /* Got two numbers. shift the smaller and increment the exponent till
485 a_normal_exp = a->normal_exp;
486 b_normal_exp = b->normal_exp;
487 a_fraction = a->fraction.ll;
488 b_fraction = b->fraction.ll;
490 diff = a_normal_exp - b_normal_exp;
494 if (diff < FRAC_NBITS)
496 /* ??? This does shifts one bit at a time. Optimize. */
497 while (a_normal_exp > b_normal_exp)
502 while (b_normal_exp > a_normal_exp)
510 /* Somethings's up.. choose the biggest */
511 if (a_normal_exp > b_normal_exp)
513 b_normal_exp = a_normal_exp;
518 a_normal_exp = b_normal_exp;
524 if (a->sign != b->sign)
528 tfraction = -a_fraction + b_fraction;
532 tfraction = a_fraction - b_fraction;
537 tmp->normal_exp = a_normal_exp;
538 tmp->fraction.ll = tfraction;
543 tmp->normal_exp = a_normal_exp;
544 tmp->fraction.ll = -tfraction;
546 /* and renormalize it */
548 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
550 tmp->fraction.ll <<= 1;
557 tmp->normal_exp = a_normal_exp;
558 tmp->fraction.ll = a_fraction + b_fraction;
560 tmp->class = CLASS_NUMBER;
561 /* Now the fraction is added, we have to shift down to renormalize the
564 if (tmp->fraction.ll >= IMPLICIT_2)
566 LSHIFT (tmp->fraction.ll);
574 add (FLO_type arg_a, FLO_type arg_b)
580 FLO_union_type au, bu;
588 res = _fpadd_parts (&a, &b, &tmp);
594 sub (FLO_type arg_a, FLO_type arg_b)
600 FLO_union_type au, bu;
610 res = _fpadd_parts (&a, &b, &tmp);
614 #endif /* L_addsub_sf || L_addsub_df */
616 #if defined(L_mul_sf) || defined(L_mul_df)
617 static inline __attribute__ ((__always_inline__)) fp_number_type *
618 _fpmul_parts ( fp_number_type * a,
620 fp_number_type * tmp)
627 a->sign = a->sign != b->sign;
632 b->sign = a->sign != b->sign;
639 a->sign = a->sign != b->sign;
648 b->sign = a->sign != b->sign;
653 a->sign = a->sign != b->sign;
658 b->sign = a->sign != b->sign;
662 /* Calculate the mantissa by multiplying both numbers to get a
663 twice-as-wide number. */
665 #if defined(NO_DI_MODE)
667 fractype x = a->fraction.ll;
668 fractype ylow = b->fraction.ll;
672 /* ??? This does multiplies one bit at a time. Optimize. */
673 for (bit = 0; bit < FRAC_NBITS; bit++)
679 carry = (low += ylow) < ylow;
680 high += yhigh + carry;
692 /* Multiplying two USIs to get a UDI, we're safe. */
694 UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
696 high = answer >> BITS_PER_SI;
700 /* fractype is DImode, but we need the result to be twice as wide.
701 Assuming a widening multiply from DImode to TImode is not
702 available, build one by hand. */
704 USItype nl = a->fraction.ll;
705 USItype nh = a->fraction.ll >> BITS_PER_SI;
706 USItype ml = b->fraction.ll;
707 USItype mh = b->fraction.ll >> BITS_PER_SI;
708 UDItype pp_ll = (UDItype) ml * nl;
709 UDItype pp_hl = (UDItype) mh * nl;
710 UDItype pp_lh = (UDItype) ml * nh;
711 UDItype pp_hh = (UDItype) mh * nh;
714 UDItype ps_hh__ = pp_hl + pp_lh;
716 res2 += (UDItype)1 << BITS_PER_SI;
717 pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
718 res0 = pp_ll + pp_hl;
721 res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
728 tmp->normal_exp = a->normal_exp + b->normal_exp;
729 tmp->sign = a->sign != b->sign;
731 tmp->normal_exp += 2; /* ??????????????? */
733 tmp->normal_exp += 4; /* ??????????????? */
735 while (high >= IMPLICIT_2)
745 while (high < IMPLICIT_1)
754 /* rounding is tricky. if we only round if it won't make us round later. */
758 if (((high & GARDMASK) != GARDMSB)
759 && (((high + 1) & GARDMASK) == GARDMSB))
761 /* don't round, it gets done again later. */
769 if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
771 if (high & (1 << NGARDS))
773 /* half way, so round to even */
774 high += GARDROUND + 1;
778 /* but we really weren't half way */
779 high += GARDROUND + 1;
782 tmp->fraction.ll = high;
783 tmp->class = CLASS_NUMBER;
788 multiply (FLO_type arg_a, FLO_type arg_b)
794 FLO_union_type au, bu;
802 res = _fpmul_parts (&a, &b, &tmp);
806 #endif /* L_mul_sf || L_mul_df */
808 #if defined(L_div_sf) || defined(L_div_df)
809 static inline __attribute__ ((__always_inline__)) fp_number_type *
810 _fpdiv_parts (fp_number_type * a,
815 fractype denominator;
827 a->sign = a->sign ^ b->sign;
829 if (isinf (a) || iszero (a))
831 if (a->class == b->class)
844 a->class = CLASS_INFINITY;
848 /* Calculate the mantissa by multiplying both 64bit numbers to get a
852 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
855 a->normal_exp = a->normal_exp - b->normal_exp;
856 numerator = a->fraction.ll;
857 denominator = b->fraction.ll;
859 if (numerator < denominator)
861 /* Fraction will be less than 1.0 */
867 /* ??? Does divide one bit at a time. Optimize. */
870 if (numerator >= denominator)
873 numerator -= denominator;
879 if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
881 if (quotient & (1 << NGARDS))
883 /* half way, so round to even */
884 quotient += GARDROUND + 1;
888 /* but we really weren't half way, more bits exist */
889 quotient += GARDROUND + 1;
893 a->fraction.ll = quotient;
899 divide (FLO_type arg_a, FLO_type arg_b)
904 FLO_union_type au, bu;
912 res = _fpdiv_parts (&a, &b);
916 #endif /* L_div_sf || L_div_df */
918 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
919 /* according to the demo, fpcmp returns a comparison with 0... thus
926 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
929 /* either nan -> unordered. Must be checked outside of this routine. */
930 if (isnan (a) && isnan (b))
932 return 1; /* still unordered! */
936 if (isnan (a) || isnan (b))
938 return 1; /* how to indicate unordered compare? */
940 if (isinf (a) && isinf (b))
942 /* +inf > -inf, but +inf != +inf */
943 /* b \a| +inf(0)| -inf(1)
944 ______\+--------+--------
945 +inf(0)| a==b(0)| a<b(-1)
946 -------+--------+--------
947 -inf(1)| a>b(1) | a==b(0)
948 -------+--------+--------
949 So since unordered must be nonzero, just line up the columns...
951 return b->sign - a->sign;
953 /* but not both... */
956 return a->sign ? -1 : 1;
960 return b->sign ? 1 : -1;
962 if (iszero (a) && iszero (b))
968 return b->sign ? 1 : -1;
972 return a->sign ? -1 : 1;
974 /* now both are "normal". */
975 if (a->sign != b->sign)
978 return a->sign ? -1 : 1;
980 /* same sign; exponents? */
981 if (a->normal_exp > b->normal_exp)
983 return a->sign ? -1 : 1;
985 if (a->normal_exp < b->normal_exp)
987 return a->sign ? 1 : -1;
989 /* same exponents; check size. */
990 if (a->fraction.ll > b->fraction.ll)
992 return a->sign ? -1 : 1;
994 if (a->fraction.ll < b->fraction.ll)
996 return a->sign ? 1 : -1;
998 /* after all that, they're equal. */
1003 #if defined(L_compare_sf) || defined(L_compare_df)
1005 compare (FLO_type arg_a, FLO_type arg_b)
1009 FLO_union_type au, bu;
1017 return __fpcmp_parts (&a, &b);
1019 #endif /* L_compare_sf || L_compare_df */
1021 #ifndef US_SOFTWARE_GOFAST
1023 /* These should be optimized for their specific tasks someday. */
1025 #if defined(L_eq_sf) || defined(L_eq_df)
1027 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1031 FLO_union_type au, bu;
1039 if (isnan (&a) || isnan (&b))
1040 return 1; /* false, truth == 0 */
1042 return __fpcmp_parts (&a, &b) ;
1044 #endif /* L_eq_sf || L_eq_df */
1046 #if defined(L_ne_sf) || defined(L_ne_df)
1048 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1052 FLO_union_type au, bu;
1060 if (isnan (&a) || isnan (&b))
1061 return 1; /* true, truth != 0 */
1063 return __fpcmp_parts (&a, &b) ;
1065 #endif /* L_ne_sf || L_ne_df */
1067 #if defined(L_gt_sf) || defined(L_gt_df)
1069 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1073 FLO_union_type au, bu;
1081 if (isnan (&a) || isnan (&b))
1082 return -1; /* false, truth > 0 */
1084 return __fpcmp_parts (&a, &b);
1086 #endif /* L_gt_sf || L_gt_df */
1088 #if defined(L_ge_sf) || defined(L_ge_df)
1090 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1094 FLO_union_type au, bu;
1102 if (isnan (&a) || isnan (&b))
1103 return -1; /* false, truth >= 0 */
1104 return __fpcmp_parts (&a, &b) ;
1106 #endif /* L_ge_sf || L_ge_df */
1108 #if defined(L_lt_sf) || defined(L_lt_df)
1110 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1114 FLO_union_type au, bu;
1122 if (isnan (&a) || isnan (&b))
1123 return 1; /* false, truth < 0 */
1125 return __fpcmp_parts (&a, &b);
1127 #endif /* L_lt_sf || L_lt_df */
1129 #if defined(L_le_sf) || defined(L_le_df)
1131 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1135 FLO_union_type au, bu;
1143 if (isnan (&a) || isnan (&b))
1144 return 1; /* false, truth <= 0 */
1146 return __fpcmp_parts (&a, &b) ;
1148 #endif /* L_le_sf || L_le_df */
1150 #endif /* ! US_SOFTWARE_GOFAST */
1152 #if defined(L_unord_sf) || defined(L_unord_df)
1154 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1158 FLO_union_type au, bu;
1166 return (isnan (&a) || isnan (&b));
1168 #endif /* L_unord_sf || L_unord_df */
1170 #if defined(L_si_to_sf) || defined(L_si_to_df)
1172 si_to_float (SItype arg_a)
1176 in.class = CLASS_NUMBER;
1177 in.sign = arg_a < 0;
1180 in.class = CLASS_ZERO;
1184 in.normal_exp = FRACBITS + NGARDS;
1187 /* Special case for minint, since there is no +ve integer
1188 representation for it */
1189 if (arg_a == (- MAX_SI_INT - 1))
1191 return (FLO_type)(- MAX_SI_INT - 1);
1193 in.fraction.ll = (-arg_a);
1196 in.fraction.ll = arg_a;
1198 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1200 in.fraction.ll <<= 1;
1204 return pack_d (&in);
1206 #endif /* L_si_to_sf || L_si_to_df */
1208 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1210 usi_to_float (USItype arg_a)
1217 in.class = CLASS_ZERO;
1221 in.class = CLASS_NUMBER;
1222 in.normal_exp = FRACBITS + NGARDS;
1223 in.fraction.ll = arg_a;
1225 while (in.fraction.ll > (1LL << (FRACBITS + NGARDS)))
1227 in.fraction.ll >>= 1;
1230 while (in.fraction.ll < (1LL << (FRACBITS + NGARDS)))
1232 in.fraction.ll <<= 1;
1236 return pack_d (&in);
1240 #if defined(L_sf_to_si) || defined(L_df_to_si)
1242 float_to_si (FLO_type arg_a)
1255 /* get reasonable MAX_SI_INT... */
1257 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1258 /* it is a number, but a small one */
1259 if (a.normal_exp < 0)
1261 if (a.normal_exp > BITS_PER_SI - 2)
1262 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1263 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1264 return a.sign ? (-tmp) : (tmp);
1266 #endif /* L_sf_to_si || L_df_to_si */
1268 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1269 #ifdef US_SOFTWARE_GOFAST
1270 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1271 we also define them for GOFAST because the ones in libgcc2.c have the
1272 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1273 out of libgcc2.c. We can't define these here if not GOFAST because then
1274 there'd be duplicate copies. */
1277 float_to_usi (FLO_type arg_a)
1289 /* it is a negative number */
1292 /* get reasonable MAX_USI_INT... */
1295 /* it is a number, but a small one */
1296 if (a.normal_exp < 0)
1298 if (a.normal_exp > BITS_PER_SI - 1)
1300 else if (a.normal_exp > (FRACBITS + NGARDS))
1301 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1303 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1305 #endif /* US_SOFTWARE_GOFAST */
1306 #endif /* L_sf_to_usi || L_df_to_usi */
1308 #if defined(L_negate_sf) || defined(L_negate_df)
1310 negate (FLO_type arg_a)
1321 #endif /* L_negate_sf || L_negate_df */
1325 #if defined(L_make_sf)
1327 __make_fp(fp_class_type class,
1336 in.normal_exp = exp;
1337 in.fraction.ll = frac;
1338 return pack_d (&in);
1340 #endif /* L_make_sf */
1344 /* This enables one to build an fp library that supports float but not double.
1345 Otherwise, we would get an undefined reference to __make_dp.
1346 This is needed for some 8-bit ports that can't handle well values that
1347 are 8-bytes in size, so we just don't support double for them at all. */
1349 #if defined(L_sf_to_df)
1351 sf_to_df (SFtype arg_a)
1357 unpack_d (&au, &in);
1359 return __make_dp (in.class, in.sign, in.normal_exp,
1360 ((UDItype) in.fraction.ll) << F_D_BITOFF);
1362 #endif /* L_sf_to_df */
1364 #endif /* ! FLOAT_ONLY */
1369 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1371 #if defined(L_make_df)
1373 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1379 in.normal_exp = exp;
1380 in.fraction.ll = frac;
1381 return pack_d (&in);
1383 #endif /* L_make_df */
1385 #if defined(L_df_to_sf)
1387 df_to_sf (DFtype arg_a)
1394 unpack_d (&au, &in);
1396 sffrac = in.fraction.ll >> F_D_BITOFF;
1398 /* We set the lowest guard bit in SFFRAC if we discarded any non
1400 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1403 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1405 #endif /* L_df_to_sf */
1407 #endif /* ! FLOAT */
1408 #endif /* !EXTENDED_FLOAT_STUBS */