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
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. */
49 /* The following macros can be defined to change the behaviour of this file:
50 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
51 defined, then this file implements a `double', aka DFmode, fp library.
52 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
53 don't include float->double conversion which requires the double library.
54 This is useful only for machines which can't support doubles, e.g. some
56 CMPtype: Specify the type that floating point compares should return.
57 This defaults to SItype, aka int.
58 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
59 US Software goFast library.
60 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
61 two integers to the FLO_union_type.
62 NO_DENORMALS: Disable handling of denormals.
63 NO_NANS: Disable nan and infinity handling
64 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
67 /* We don't currently support extended floats (long doubles) on machines
68 without hardware to deal with them.
70 These stubs are just to keep the linker from complaining about unresolved
71 references which can be pulled in from libio & libstdc++, even if the
72 user isn't using long doubles. However, they may generate an unresolved
73 external to abort if abort is not used by the function, and the stubs
74 are referenced from within libc, since libgcc goes before and after the
77 #ifdef EXTENDED_FLOAT_STUBS
78 __truncxfsf2 (){ abort(); }
79 __extendsfxf2 (){ abort(); }
80 __addxf3 (){ abort(); }
81 __divxf3 (){ abort(); }
82 __eqxf2 (){ abort(); }
83 __extenddfxf2 (){ abort(); }
84 __gtxf2 (){ abort(); }
85 __lexf2 (){ abort(); }
86 __ltxf2 (){ abort(); }
87 __mulxf3 (){ abort(); }
88 __negxf2 (){ abort(); }
89 __nexf2 (){ abort(); }
90 __subxf3 (){ abort(); }
91 __truncxfdf2 (){ abort(); }
93 __trunctfsf2 (){ abort(); }
94 __extendsftf2 (){ abort(); }
95 __addtf3 (){ abort(); }
96 __divtf3 (){ abort(); }
97 __eqtf2 (){ abort(); }
98 __extenddftf2 (){ abort(); }
99 __gttf2 (){ abort(); }
100 __letf2 (){ abort(); }
101 __lttf2 (){ abort(); }
102 __multf3 (){ abort(); }
103 __negtf2 (){ abort(); }
104 __netf2 (){ abort(); }
105 __subtf3 (){ abort(); }
106 __trunctfdf2 (){ abort(); }
107 __gexf2 (){ abort(); }
108 __fixxfsi (){ abort(); }
109 __floatsixf (){ abort(); }
110 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
112 /* IEEE "special" number predicates */
121 #if defined L_thenan_sf
122 const fp_number_type __thenan_sf
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
123 #elif defined L_thenan_df
124 const fp_number_type __thenan_df
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
126 extern const fp_number_type __thenan_sf
;
128 extern const fp_number_type __thenan_df
;
132 static fp_number_type
*
135 /* Discard the const qualifier... */
137 return (fp_number_type
*) (& __thenan_sf
);
139 return (fp_number_type
*) (& __thenan_df
);
145 isnan ( fp_number_type
* x
)
147 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
152 isinf ( fp_number_type
* x
)
154 return x
->class == CLASS_INFINITY
;
161 iszero ( fp_number_type
* x
)
163 return x
->class == CLASS_ZERO
;
168 flip_sign ( fp_number_type
* x
)
173 extern FLO_type
pack_d ( fp_number_type
* );
175 #if defined(L_pack_df) || defined(L_pack_sf)
177 pack_d ( fp_number_type
* src
)
180 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
181 int sign
= src
->sign
;
187 if (src
->class == CLASS_QNAN
|| 1)
189 fraction
|= QUIET_NAN
;
192 else if (isinf (src
))
197 else if (iszero (src
))
202 else if (fraction
== 0)
208 if (src
->normal_exp
< NORMAL_EXPMIN
)
210 /* This number's exponent is too low to fit into the bits
211 available in the number, so we'll store 0 in the exponent and
212 shift the fraction to the right to make up for it. */
214 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
218 if (shift
> FRAC_NBITS
- NGARDS
)
220 /* No point shifting, since it's more that 64 out. */
225 int lowbit
= (fraction
& (((fractype
)1 << shift
) - 1)) ? 1 : 0;
226 fraction
= (fraction
>> shift
) | lowbit
;
228 if ((fraction
& GARDMASK
) == GARDMSB
)
230 if ((fraction
& (1 << NGARDS
)))
231 fraction
+= GARDROUND
+ 1;
235 /* Add to the guards to round up. */
236 fraction
+= GARDROUND
;
238 /* Perhaps the rounding means we now need to change the
239 exponent, because the fraction is no longer denormal. */
240 if (fraction
>= IMPLICIT_1
)
246 else if (src
->normal_exp
> EXPBIAS
)
253 exp
= src
->normal_exp
+ EXPBIAS
;
254 /* IF the gard bits are the all zero, but the first, then we're
255 half way between two numbers, choose the one which makes the
256 lsb of the answer 0. */
257 if ((fraction
& GARDMASK
) == GARDMSB
)
259 if (fraction
& (1 << NGARDS
))
260 fraction
+= GARDROUND
+ 1;
264 /* Add a one to the guards to round up */
265 fraction
+= GARDROUND
;
267 if (fraction
>= IMPLICIT_2
)
276 /* We previously used bitfields to store the number, but this doesn't
277 handle little/big endian systems conveniently, so use shifts and
279 #ifdef FLOAT_BIT_ORDER_MISMATCH
280 dst
.bits
.fraction
= fraction
;
282 dst
.bits
.sign
= sign
;
284 dst
.value_raw
= fraction
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
285 dst
.value_raw
|= ((fractype
) (exp
& ((1 << EXPBITS
) - 1))) << FRACBITS
;
286 dst
.value_raw
|= ((fractype
) (sign
& 1)) << (FRACBITS
| EXPBITS
);
289 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
291 halffractype tmp
= dst
.words
[0];
292 dst
.words
[0] = dst
.words
[1];
301 #if defined(L_unpack_df) || defined(L_unpack_sf)
303 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
305 /* We previously used bitfields to store the number, but this doesn't
306 handle little/big endian systems conveniently, so use shifts and
312 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
313 FLO_union_type swapped
;
315 swapped
.words
[0] = src
->words
[1];
316 swapped
.words
[1] = src
->words
[0];
320 #ifdef FLOAT_BIT_ORDER_MISMATCH
321 fraction
= src
->bits
.fraction
;
323 sign
= src
->bits
.sign
;
325 fraction
= src
->value_raw
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
326 exp
= ((int)(src
->value_raw
>> FRACBITS
)) & ((1 << EXPBITS
) - 1);
327 sign
= ((int)(src
->value_raw
>> (FRACBITS
+ EXPBITS
))) & 1;
333 /* Hmm. Looks like 0 */
340 /* tastes like zero */
341 dst
->class = CLASS_ZERO
;
345 /* Zero exponent with non zero fraction - it's denormalized,
346 so there isn't a leading implicit one - we'll shift it so
348 dst
->normal_exp
= exp
- EXPBIAS
+ 1;
351 dst
->class = CLASS_NUMBER
;
353 while (fraction
< IMPLICIT_1
)
359 dst
->fraction
.ll
= fraction
;
362 else if (exp
== EXPMAX
)
367 /* Attached to a zero fraction - means infinity */
368 dst
->class = CLASS_INFINITY
;
372 /* Non zero fraction, means nan */
373 if (fraction
& QUIET_NAN
)
375 dst
->class = CLASS_QNAN
;
379 dst
->class = CLASS_SNAN
;
381 /* Keep the fraction part as the nan number */
382 dst
->fraction
.ll
= fraction
;
387 /* Nothing strange about this number */
388 dst
->normal_exp
= exp
- EXPBIAS
;
389 dst
->class = CLASS_NUMBER
;
390 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
393 #endif /* L_unpack_df || L_unpack_sf */
395 #if defined(L_addsub_sf) || defined(L_addsub_df)
396 static fp_number_type
*
397 _fpadd_parts (fp_number_type
* a
,
399 fp_number_type
* tmp
)
403 /* Put commonly used fields in local variables. */
419 /* Adding infinities with opposite signs yields a NaN. */
420 if (isinf (b
) && a
->sign
!= b
->sign
)
433 tmp
->sign
= a
->sign
& b
->sign
;
443 /* Got two numbers. shift the smaller and increment the exponent till
448 a_normal_exp
= a
->normal_exp
;
449 b_normal_exp
= b
->normal_exp
;
450 a_fraction
= a
->fraction
.ll
;
451 b_fraction
= b
->fraction
.ll
;
453 diff
= a_normal_exp
- b_normal_exp
;
457 if (diff
< FRAC_NBITS
)
459 /* ??? This does shifts one bit at a time. Optimize. */
460 while (a_normal_exp
> b_normal_exp
)
465 while (b_normal_exp
> a_normal_exp
)
473 /* Somethings's up.. choose the biggest */
474 if (a_normal_exp
> b_normal_exp
)
476 b_normal_exp
= a_normal_exp
;
481 a_normal_exp
= b_normal_exp
;
487 if (a
->sign
!= b
->sign
)
491 tfraction
= -a_fraction
+ b_fraction
;
495 tfraction
= a_fraction
- b_fraction
;
500 tmp
->normal_exp
= a_normal_exp
;
501 tmp
->fraction
.ll
= tfraction
;
506 tmp
->normal_exp
= a_normal_exp
;
507 tmp
->fraction
.ll
= -tfraction
;
509 /* and renormalize it */
511 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
513 tmp
->fraction
.ll
<<= 1;
520 tmp
->normal_exp
= a_normal_exp
;
521 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
523 tmp
->class = CLASS_NUMBER
;
524 /* Now the fraction is added, we have to shift down to renormalize the
527 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
529 LSHIFT (tmp
->fraction
.ll
);
537 add (FLO_type arg_a
, FLO_type arg_b
)
543 FLO_union_type au
, bu
;
551 res
= _fpadd_parts (&a
, &b
, &tmp
);
557 sub (FLO_type arg_a
, FLO_type arg_b
)
563 FLO_union_type au
, bu
;
573 res
= _fpadd_parts (&a
, &b
, &tmp
);
577 #endif /* L_addsub_sf || L_addsub_df */
579 #if defined(L_mul_sf) || defined(L_mul_df)
580 static INLINE fp_number_type
*
581 _fpmul_parts ( fp_number_type
* a
,
583 fp_number_type
* tmp
)
590 a
->sign
= a
->sign
!= b
->sign
;
595 b
->sign
= a
->sign
!= b
->sign
;
602 a
->sign
= a
->sign
!= b
->sign
;
611 b
->sign
= a
->sign
!= b
->sign
;
616 a
->sign
= a
->sign
!= b
->sign
;
621 b
->sign
= a
->sign
!= b
->sign
;
625 /* Calculate the mantissa by multiplying both numbers to get a
626 twice-as-wide number. */
628 #if defined(NO_DI_MODE)
630 fractype x
= a
->fraction
.ll
;
631 fractype ylow
= b
->fraction
.ll
;
635 /* ??? This does multiplies one bit at a time. Optimize. */
636 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
642 carry
= (low
+= ylow
) < ylow
;
643 high
+= yhigh
+ carry
;
655 /* Multiplying two USIs to get a UDI, we're safe. */
657 UDItype answer
= (UDItype
)a
->fraction
.ll
* (UDItype
)b
->fraction
.ll
;
659 high
= answer
>> BITS_PER_SI
;
663 /* fractype is DImode, but we need the result to be twice as wide.
664 Assuming a widening multiply from DImode to TImode is not
665 available, build one by hand. */
667 USItype nl
= a
->fraction
.ll
;
668 USItype nh
= a
->fraction
.ll
>> BITS_PER_SI
;
669 USItype ml
= b
->fraction
.ll
;
670 USItype mh
= b
->fraction
.ll
>> BITS_PER_SI
;
671 UDItype pp_ll
= (UDItype
) ml
* nl
;
672 UDItype pp_hl
= (UDItype
) mh
* nl
;
673 UDItype pp_lh
= (UDItype
) ml
* nh
;
674 UDItype pp_hh
= (UDItype
) mh
* nh
;
677 UDItype ps_hh__
= pp_hl
+ pp_lh
;
679 res2
+= (UDItype
)1 << BITS_PER_SI
;
680 pp_hl
= (UDItype
)(USItype
)ps_hh__
<< BITS_PER_SI
;
681 res0
= pp_ll
+ pp_hl
;
684 res2
+= (ps_hh__
>> BITS_PER_SI
) + pp_hh
;
691 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
692 tmp
->sign
= a
->sign
!= b
->sign
;
694 tmp
->normal_exp
+= 2; /* ??????????????? */
696 tmp
->normal_exp
+= 4; /* ??????????????? */
698 while (high
>= IMPLICIT_2
)
708 while (high
< IMPLICIT_1
)
717 /* rounding is tricky. if we only round if it won't make us round later. */
721 if (((high
& GARDMASK
) != GARDMSB
)
722 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
724 /* don't round, it gets done again later. */
732 if ((high
& GARDMASK
) == GARDMSB
)
734 if (high
& (1 << NGARDS
))
736 /* half way, so round to even */
737 high
+= GARDROUND
+ 1;
741 /* but we really weren't half way */
742 high
+= GARDROUND
+ 1;
745 tmp
->fraction
.ll
= high
;
746 tmp
->class = CLASS_NUMBER
;
751 multiply (FLO_type arg_a
, FLO_type arg_b
)
757 FLO_union_type au
, bu
;
765 res
= _fpmul_parts (&a
, &b
, &tmp
);
769 #endif /* L_mul_sf || L_mul_df */
771 #if defined(L_div_sf) || defined(L_div_df)
772 static INLINE fp_number_type
*
773 _fpdiv_parts (fp_number_type
* a
,
778 fractype denominator
;
790 a
->sign
= a
->sign
^ b
->sign
;
792 if (isinf (a
) || iszero (a
))
794 if (a
->class == b
->class)
807 a
->class = CLASS_INFINITY
;
811 /* Calculate the mantissa by multiplying both 64bit numbers to get a
815 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
818 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
819 numerator
= a
->fraction
.ll
;
820 denominator
= b
->fraction
.ll
;
822 if (numerator
< denominator
)
824 /* Fraction will be less than 1.0 */
830 /* ??? Does divide one bit at a time. Optimize. */
833 if (numerator
>= denominator
)
836 numerator
-= denominator
;
842 if ((quotient
& GARDMASK
) == GARDMSB
)
844 if (quotient
& (1 << NGARDS
))
846 /* half way, so round to even */
847 quotient
+= GARDROUND
+ 1;
851 /* but we really weren't half way, more bits exist */
852 quotient
+= GARDROUND
+ 1;
856 a
->fraction
.ll
= quotient
;
862 divide (FLO_type arg_a
, FLO_type arg_b
)
867 FLO_union_type au
, bu
;
875 res
= _fpdiv_parts (&a
, &b
);
879 #endif /* L_div_sf || L_div_df */
881 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
882 /* according to the demo, fpcmp returns a comparison with 0... thus
889 __fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
892 /* either nan -> unordered. Must be checked outside of this routine. */
893 if (isnan (a
) && isnan (b
))
895 return 1; /* still unordered! */
899 if (isnan (a
) || isnan (b
))
901 return 1; /* how to indicate unordered compare? */
903 if (isinf (a
) && isinf (b
))
905 /* +inf > -inf, but +inf != +inf */
906 /* b \a| +inf(0)| -inf(1)
907 ______\+--------+--------
908 +inf(0)| a==b(0)| a<b(-1)
909 -------+--------+--------
910 -inf(1)| a>b(1) | a==b(0)
911 -------+--------+--------
912 So since unordered must be non zero, just line up the columns...
914 return b
->sign
- a
->sign
;
916 /* but not both... */
919 return a
->sign
? -1 : 1;
923 return b
->sign
? 1 : -1;
925 if (iszero (a
) && iszero (b
))
931 return b
->sign
? 1 : -1;
935 return a
->sign
? -1 : 1;
937 /* now both are "normal". */
938 if (a
->sign
!= b
->sign
)
941 return a
->sign
? -1 : 1;
943 /* same sign; exponents? */
944 if (a
->normal_exp
> b
->normal_exp
)
946 return a
->sign
? -1 : 1;
948 if (a
->normal_exp
< b
->normal_exp
)
950 return a
->sign
? 1 : -1;
952 /* same exponents; check size. */
953 if (a
->fraction
.ll
> b
->fraction
.ll
)
955 return a
->sign
? -1 : 1;
957 if (a
->fraction
.ll
< b
->fraction
.ll
)
959 return a
->sign
? 1 : -1;
961 /* after all that, they're equal. */
966 #if defined(L_compare_sf) || defined(L_compare_df)
968 compare (FLO_type arg_a
, FLO_type arg_b
)
972 FLO_union_type au
, bu
;
980 return __fpcmp_parts (&a
, &b
);
982 #endif /* L_compare_sf || L_compare_df */
984 #ifndef US_SOFTWARE_GOFAST
986 /* These should be optimized for their specific tasks someday. */
988 #if defined(L_eq_sf) || defined(L_eq_df)
990 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
994 FLO_union_type au
, bu
;
1002 if (isnan (&a
) || isnan (&b
))
1003 return 1; /* false, truth == 0 */
1005 return __fpcmp_parts (&a
, &b
) ;
1007 #endif /* L_eq_sf || L_eq_df */
1009 #if defined(L_ne_sf) || defined(L_ne_df)
1011 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1015 FLO_union_type au
, bu
;
1023 if (isnan (&a
) || isnan (&b
))
1024 return 1; /* true, truth != 0 */
1026 return __fpcmp_parts (&a
, &b
) ;
1028 #endif /* L_ne_sf || L_ne_df */
1030 #if defined(L_gt_sf) || defined(L_gt_df)
1032 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1036 FLO_union_type au
, bu
;
1044 if (isnan (&a
) || isnan (&b
))
1045 return -1; /* false, truth > 0 */
1047 return __fpcmp_parts (&a
, &b
);
1049 #endif /* L_gt_sf || L_gt_df */
1051 #if defined(L_ge_sf) || defined(L_ge_df)
1053 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1057 FLO_union_type au
, bu
;
1065 if (isnan (&a
) || isnan (&b
))
1066 return -1; /* false, truth >= 0 */
1067 return __fpcmp_parts (&a
, &b
) ;
1069 #endif /* L_ge_sf || L_ge_df */
1071 #if defined(L_lt_sf) || defined(L_lt_df)
1073 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1077 FLO_union_type au
, bu
;
1085 if (isnan (&a
) || isnan (&b
))
1086 return 1; /* false, truth < 0 */
1088 return __fpcmp_parts (&a
, &b
);
1090 #endif /* L_lt_sf || L_lt_df */
1092 #if defined(L_le_sf) || defined(L_le_df)
1094 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1098 FLO_union_type au
, bu
;
1106 if (isnan (&a
) || isnan (&b
))
1107 return 1; /* false, truth <= 0 */
1109 return __fpcmp_parts (&a
, &b
) ;
1111 #endif /* L_le_sf || L_le_df */
1113 #if defined(L_unord_sf) || defined(L_unord_df)
1115 _unord_f2 (FLO_type arg_a
, FLO_type arg_b
)
1119 FLO_union_type au
, bu
;
1127 return (isnan (&a
) || isnan (&b
));
1129 #endif /* L_unord_sf || L_unord_df */
1131 #endif /* ! US_SOFTWARE_GOFAST */
1133 #if defined(L_si_to_sf) || defined(L_si_to_df)
1135 si_to_float (SItype arg_a
)
1139 in
.class = CLASS_NUMBER
;
1140 in
.sign
= arg_a
< 0;
1143 in
.class = CLASS_ZERO
;
1147 in
.normal_exp
= FRACBITS
+ NGARDS
;
1150 /* Special case for minint, since there is no +ve integer
1151 representation for it */
1152 if (arg_a
== (- MAX_SI_INT
- 1))
1154 return (FLO_type
)(- MAX_SI_INT
- 1);
1156 in
.fraction
.ll
= (-arg_a
);
1159 in
.fraction
.ll
= arg_a
;
1161 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1163 in
.fraction
.ll
<<= 1;
1167 return pack_d (&in
);
1169 #endif /* L_si_to_sf || L_si_to_df */
1171 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1173 usi_to_float (USItype arg_a
)
1180 in
.class = CLASS_ZERO
;
1184 in
.class = CLASS_NUMBER
;
1185 in
.normal_exp
= FRACBITS
+ NGARDS
;
1186 in
.fraction
.ll
= arg_a
;
1188 while (in
.fraction
.ll
> (1LL << (FRACBITS
+ NGARDS
)))
1190 in
.fraction
.ll
>>= 1;
1193 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1195 in
.fraction
.ll
<<= 1;
1199 return pack_d (&in
);
1203 #if defined(L_sf_to_si) || defined(L_df_to_si)
1205 float_to_si (FLO_type arg_a
)
1218 /* get reasonable MAX_SI_INT... */
1220 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1221 /* it is a number, but a small one */
1222 if (a
.normal_exp
< 0)
1224 if (a
.normal_exp
> BITS_PER_SI
- 2)
1225 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1226 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1227 return a
.sign
? (-tmp
) : (tmp
);
1229 #endif /* L_sf_to_si || L_df_to_si */
1231 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1232 #ifdef US_SOFTWARE_GOFAST
1233 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1234 we also define them for GOFAST because the ones in libgcc2.c have the
1235 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1236 out of libgcc2.c. We can't define these here if not GOFAST because then
1237 there'd be duplicate copies. */
1240 float_to_usi (FLO_type arg_a
)
1252 /* it is a negative number */
1255 /* get reasonable MAX_USI_INT... */
1258 /* it is a number, but a small one */
1259 if (a
.normal_exp
< 0)
1261 if (a
.normal_exp
> BITS_PER_SI
- 1)
1263 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1264 return a
.fraction
.ll
<< (a
.normal_exp
- (FRACBITS
+ NGARDS
));
1266 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1268 #endif /* US_SOFTWARE_GOFAST */
1269 #endif /* L_sf_to_usi || L_df_to_usi */
1271 #if defined(L_negate_sf) || defined(L_negate_df)
1273 negate (FLO_type arg_a
)
1284 #endif /* L_negate_sf || L_negate_df */
1288 #if defined(L_make_sf)
1290 __make_fp(fp_class_type
class,
1299 in
.normal_exp
= exp
;
1300 in
.fraction
.ll
= frac
;
1301 return pack_d (&in
);
1303 #endif /* L_make_sf */
1307 /* This enables one to build an fp library that supports float but not double.
1308 Otherwise, we would get an undefined reference to __make_dp.
1309 This is needed for some 8-bit ports that can't handle well values that
1310 are 8-bytes in size, so we just don't support double for them at all. */
1312 #if defined(L_sf_to_df)
1314 sf_to_df (SFtype arg_a
)
1320 unpack_d (&au
, &in
);
1322 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1323 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1325 #endif /* L_sf_to_df */
1327 #endif /* ! FLOAT_ONLY */
1332 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1334 #if defined(L_make_df)
1336 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1342 in
.normal_exp
= exp
;
1343 in
.fraction
.ll
= frac
;
1344 return pack_d (&in
);
1346 #endif /* L_make_df */
1348 #if defined(L_df_to_sf)
1350 df_to_sf (DFtype arg_a
)
1357 unpack_d (&au
, &in
);
1359 sffrac
= in
.fraction
.ll
>> F_D_BITOFF
;
1361 /* We set the lowest guard bit in SFFRAC if we discarded any non
1363 if ((in
.fraction
.ll
& (((USItype
) 1 << F_D_BITOFF
) - 1)) != 0)
1366 return __make_fp (in
.class, in
.sign
, in
.normal_exp
, sffrac
);
1368 #endif /* L_df_to_sf */
1370 #endif /* ! FLOAT */
1371 #endif /* !EXTENDED_FLOAT_STUBS */