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. */
49 /* The following macros can be defined to change the behavior 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 DECLARE_LIBRARY_RENAMES
78 DECLARE_LIBRARY_RENAMES
81 #ifdef EXTENDED_FLOAT_STUBS
82 extern void abort (void);
83 void __extendsfxf2 (void) { abort(); }
84 void __extenddfxf2 (void) { abort(); }
85 void __truncxfdf2 (void) { abort(); }
86 void __truncxfsf2 (void) { abort(); }
87 void __fixxfsi (void) { abort(); }
88 void __floatsixf (void) { abort(); }
89 void __addxf3 (void) { abort(); }
90 void __subxf3 (void) { abort(); }
91 void __mulxf3 (void) { abort(); }
92 void __divxf3 (void) { abort(); }
93 void __negxf2 (void) { abort(); }
94 void __eqxf2 (void) { abort(); }
95 void __nexf2 (void) { abort(); }
96 void __gtxf2 (void) { abort(); }
97 void __gexf2 (void) { abort(); }
98 void __lexf2 (void) { abort(); }
99 void __ltxf2 (void) { abort(); }
101 void __extendsftf2 (void) { abort(); }
102 void __extenddftf2 (void) { abort(); }
103 void __trunctfdf2 (void) { abort(); }
104 void __trunctfsf2 (void) { abort(); }
105 void __fixtfsi (void) { abort(); }
106 void __floatsitf (void) { abort(); }
107 void __addtf3 (void) { abort(); }
108 void __subtf3 (void) { abort(); }
109 void __multf3 (void) { abort(); }
110 void __divtf3 (void) { abort(); }
111 void __negtf2 (void) { abort(); }
112 void __eqtf2 (void) { abort(); }
113 void __netf2 (void) { abort(); }
114 void __gttf2 (void) { abort(); }
115 void __getf2 (void) { abort(); }
116 void __letf2 (void) { abort(); }
117 void __lttf2 (void) { abort(); }
118 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
120 /* IEEE "special" number predicates */
129 #if defined L_thenan_sf
130 const fp_number_type __thenan_sf
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
131 #elif defined L_thenan_df
132 const fp_number_type __thenan_df
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
134 extern const fp_number_type __thenan_sf
;
136 extern const fp_number_type __thenan_df
;
140 static fp_number_type
*
143 /* Discard the const qualifier... */
145 return (fp_number_type
*) (& __thenan_sf
);
147 return (fp_number_type
*) (& __thenan_df
);
153 isnan ( fp_number_type
* x
)
155 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
160 isinf ( fp_number_type
* x
)
162 return x
->class == CLASS_INFINITY
;
169 iszero ( fp_number_type
* x
)
171 return x
->class == CLASS_ZERO
;
176 flip_sign ( fp_number_type
* x
)
181 extern FLO_type
pack_d ( fp_number_type
* );
183 #if defined(L_pack_df) || defined(L_pack_sf)
185 pack_d ( fp_number_type
* src
)
188 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
189 int sign
= src
->sign
;
192 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && (isnan (src
) || isinf (src
)))
194 /* We can't represent these values accurately. By using the
195 largest possible magnitude, we guarantee that the conversion
196 of infinity is at least as big as any finite number. */
198 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
200 else if (isnan (src
))
203 if (src
->class == CLASS_QNAN
|| 1)
205 fraction
|= QUIET_NAN
;
208 else if (isinf (src
))
213 else if (iszero (src
))
218 else if (fraction
== 0)
224 if (src
->normal_exp
< NORMAL_EXPMIN
)
227 /* Go straight to a zero representation if denormals are not
228 supported. The denormal handling would be harmless but
229 isn't unnecessary. */
232 #else /* NO_DENORMALS */
233 /* This number's exponent is too low to fit into the bits
234 available in the number, so we'll store 0 in the exponent and
235 shift the fraction to the right to make up for it. */
237 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
241 if (shift
> FRAC_NBITS
- NGARDS
)
243 /* No point shifting, since it's more that 64 out. */
248 int lowbit
= (fraction
& (((fractype
)1 << shift
) - 1)) ? 1 : 0;
249 fraction
= (fraction
>> shift
) | lowbit
;
251 if ((fraction
& GARDMASK
) == GARDMSB
)
253 if ((fraction
& (1 << NGARDS
)))
254 fraction
+= GARDROUND
+ 1;
258 /* Add to the guards to round up. */
259 fraction
+= GARDROUND
;
261 /* Perhaps the rounding means we now need to change the
262 exponent, because the fraction is no longer denormal. */
263 if (fraction
>= IMPLICIT_1
)
268 #endif /* NO_DENORMALS */
270 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
)
271 && src
->normal_exp
> EXPBIAS
)
278 exp
= src
->normal_exp
+ EXPBIAS
;
279 if (!ROUND_TOWARDS_ZERO
)
281 /* IF the gard bits are the all zero, but the first, then we're
282 half way between two numbers, choose the one which makes the
283 lsb of the answer 0. */
284 if ((fraction
& GARDMASK
) == GARDMSB
)
286 if (fraction
& (1 << NGARDS
))
287 fraction
+= GARDROUND
+ 1;
291 /* Add a one to the guards to round up */
292 fraction
+= GARDROUND
;
294 if (fraction
>= IMPLICIT_2
)
302 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
> EXPMAX
)
304 /* Saturate on overflow. */
306 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
311 /* We previously used bitfields to store the number, but this doesn't
312 handle little/big endian systems conveniently, so use shifts and
314 #ifdef FLOAT_BIT_ORDER_MISMATCH
315 dst
.bits
.fraction
= fraction
;
317 dst
.bits
.sign
= sign
;
319 dst
.value_raw
= fraction
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
320 dst
.value_raw
|= ((fractype
) (exp
& ((1 << EXPBITS
) - 1))) << FRACBITS
;
321 dst
.value_raw
|= ((fractype
) (sign
& 1)) << (FRACBITS
| EXPBITS
);
324 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
326 halffractype tmp
= dst
.words
[0];
327 dst
.words
[0] = dst
.words
[1];
336 #if defined(L_unpack_df) || defined(L_unpack_sf)
338 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
340 /* We previously used bitfields to store the number, but this doesn't
341 handle little/big endian systems conveniently, so use shifts and
347 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
348 FLO_union_type swapped
;
350 swapped
.words
[0] = src
->words
[1];
351 swapped
.words
[1] = src
->words
[0];
355 #ifdef FLOAT_BIT_ORDER_MISMATCH
356 fraction
= src
->bits
.fraction
;
358 sign
= src
->bits
.sign
;
360 fraction
= src
->value_raw
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
361 exp
= ((int)(src
->value_raw
>> FRACBITS
)) & ((1 << EXPBITS
) - 1);
362 sign
= ((int)(src
->value_raw
>> (FRACBITS
+ EXPBITS
))) & 1;
368 /* Hmm. Looks like 0 */
375 /* tastes like zero */
376 dst
->class = CLASS_ZERO
;
380 /* Zero exponent with nonzero fraction - it's denormalized,
381 so there isn't a leading implicit one - we'll shift it so
383 dst
->normal_exp
= exp
- EXPBIAS
+ 1;
386 dst
->class = CLASS_NUMBER
;
388 while (fraction
< IMPLICIT_1
)
394 dst
->fraction
.ll
= fraction
;
397 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
== EXPMAX
)
402 /* Attached to a zero fraction - means infinity */
403 dst
->class = CLASS_INFINITY
;
407 /* Nonzero fraction, means nan */
408 if (fraction
& QUIET_NAN
)
410 dst
->class = CLASS_QNAN
;
414 dst
->class = CLASS_SNAN
;
416 /* Keep the fraction part as the nan number */
417 dst
->fraction
.ll
= fraction
;
422 /* Nothing strange about this number */
423 dst
->normal_exp
= exp
- EXPBIAS
;
424 dst
->class = CLASS_NUMBER
;
425 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
428 #endif /* L_unpack_df || L_unpack_sf */
430 #if defined(L_addsub_sf) || defined(L_addsub_df)
431 static fp_number_type
*
432 _fpadd_parts (fp_number_type
* a
,
434 fp_number_type
* tmp
)
438 /* Put commonly used fields in local variables. */
454 /* Adding infinities with opposite signs yields a NaN. */
455 if (isinf (b
) && a
->sign
!= b
->sign
)
468 tmp
->sign
= a
->sign
& b
->sign
;
478 /* Got two numbers. shift the smaller and increment the exponent till
483 a_normal_exp
= a
->normal_exp
;
484 b_normal_exp
= b
->normal_exp
;
485 a_fraction
= a
->fraction
.ll
;
486 b_fraction
= b
->fraction
.ll
;
488 diff
= a_normal_exp
- b_normal_exp
;
492 if (diff
< FRAC_NBITS
)
494 /* ??? This does shifts one bit at a time. Optimize. */
495 while (a_normal_exp
> b_normal_exp
)
500 while (b_normal_exp
> a_normal_exp
)
508 /* Somethings's up.. choose the biggest */
509 if (a_normal_exp
> b_normal_exp
)
511 b_normal_exp
= a_normal_exp
;
516 a_normal_exp
= b_normal_exp
;
522 if (a
->sign
!= b
->sign
)
526 tfraction
= -a_fraction
+ b_fraction
;
530 tfraction
= a_fraction
- b_fraction
;
535 tmp
->normal_exp
= a_normal_exp
;
536 tmp
->fraction
.ll
= tfraction
;
541 tmp
->normal_exp
= a_normal_exp
;
542 tmp
->fraction
.ll
= -tfraction
;
544 /* and renormalize it */
546 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
548 tmp
->fraction
.ll
<<= 1;
555 tmp
->normal_exp
= a_normal_exp
;
556 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
558 tmp
->class = CLASS_NUMBER
;
559 /* Now the fraction is added, we have to shift down to renormalize the
562 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
564 LSHIFT (tmp
->fraction
.ll
);
572 add (FLO_type arg_a
, FLO_type arg_b
)
578 FLO_union_type au
, bu
;
586 res
= _fpadd_parts (&a
, &b
, &tmp
);
592 sub (FLO_type arg_a
, FLO_type arg_b
)
598 FLO_union_type au
, bu
;
608 res
= _fpadd_parts (&a
, &b
, &tmp
);
612 #endif /* L_addsub_sf || L_addsub_df */
614 #if defined(L_mul_sf) || defined(L_mul_df)
615 static inline __attribute__ ((__always_inline__
)) fp_number_type
*
616 _fpmul_parts ( fp_number_type
* a
,
618 fp_number_type
* tmp
)
625 a
->sign
= a
->sign
!= b
->sign
;
630 b
->sign
= a
->sign
!= b
->sign
;
637 a
->sign
= a
->sign
!= b
->sign
;
646 b
->sign
= a
->sign
!= b
->sign
;
651 a
->sign
= a
->sign
!= b
->sign
;
656 b
->sign
= a
->sign
!= b
->sign
;
660 /* Calculate the mantissa by multiplying both numbers to get a
661 twice-as-wide number. */
663 #if defined(NO_DI_MODE)
665 fractype x
= a
->fraction
.ll
;
666 fractype ylow
= b
->fraction
.ll
;
670 /* ??? This does multiplies one bit at a time. Optimize. */
671 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
677 carry
= (low
+= ylow
) < ylow
;
678 high
+= yhigh
+ carry
;
690 /* Multiplying two USIs to get a UDI, we're safe. */
692 UDItype answer
= (UDItype
)a
->fraction
.ll
* (UDItype
)b
->fraction
.ll
;
694 high
= answer
>> BITS_PER_SI
;
698 /* fractype is DImode, but we need the result to be twice as wide.
699 Assuming a widening multiply from DImode to TImode is not
700 available, build one by hand. */
702 USItype nl
= a
->fraction
.ll
;
703 USItype nh
= a
->fraction
.ll
>> BITS_PER_SI
;
704 USItype ml
= b
->fraction
.ll
;
705 USItype mh
= b
->fraction
.ll
>> BITS_PER_SI
;
706 UDItype pp_ll
= (UDItype
) ml
* nl
;
707 UDItype pp_hl
= (UDItype
) mh
* nl
;
708 UDItype pp_lh
= (UDItype
) ml
* nh
;
709 UDItype pp_hh
= (UDItype
) mh
* nh
;
712 UDItype ps_hh__
= pp_hl
+ pp_lh
;
714 res2
+= (UDItype
)1 << BITS_PER_SI
;
715 pp_hl
= (UDItype
)(USItype
)ps_hh__
<< BITS_PER_SI
;
716 res0
= pp_ll
+ pp_hl
;
719 res2
+= (ps_hh__
>> BITS_PER_SI
) + pp_hh
;
726 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
727 tmp
->sign
= a
->sign
!= b
->sign
;
729 tmp
->normal_exp
+= 2; /* ??????????????? */
731 tmp
->normal_exp
+= 4; /* ??????????????? */
733 while (high
>= IMPLICIT_2
)
743 while (high
< IMPLICIT_1
)
752 /* rounding is tricky. if we only round if it won't make us round later. */
756 if (((high
& GARDMASK
) != GARDMSB
)
757 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
759 /* don't round, it gets done again later. */
767 if (!ROUND_TOWARDS_ZERO
&& (high
& GARDMASK
) == GARDMSB
)
769 if (high
& (1 << NGARDS
))
771 /* half way, so round to even */
772 high
+= GARDROUND
+ 1;
776 /* but we really weren't half way */
777 high
+= GARDROUND
+ 1;
780 tmp
->fraction
.ll
= high
;
781 tmp
->class = CLASS_NUMBER
;
786 multiply (FLO_type arg_a
, FLO_type arg_b
)
792 FLO_union_type au
, bu
;
800 res
= _fpmul_parts (&a
, &b
, &tmp
);
804 #endif /* L_mul_sf || L_mul_df */
806 #if defined(L_div_sf) || defined(L_div_df)
807 static inline __attribute__ ((__always_inline__
)) fp_number_type
*
808 _fpdiv_parts (fp_number_type
* a
,
813 fractype denominator
;
825 a
->sign
= a
->sign
^ b
->sign
;
827 if (isinf (a
) || iszero (a
))
829 if (a
->class == b
->class)
842 a
->class = CLASS_INFINITY
;
846 /* Calculate the mantissa by multiplying both 64bit numbers to get a
850 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
853 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
854 numerator
= a
->fraction
.ll
;
855 denominator
= b
->fraction
.ll
;
857 if (numerator
< denominator
)
859 /* Fraction will be less than 1.0 */
865 /* ??? Does divide one bit at a time. Optimize. */
868 if (numerator
>= denominator
)
871 numerator
-= denominator
;
877 if (!ROUND_TOWARDS_ZERO
&& (quotient
& GARDMASK
) == GARDMSB
)
879 if (quotient
& (1 << NGARDS
))
881 /* half way, so round to even */
882 quotient
+= GARDROUND
+ 1;
886 /* but we really weren't half way, more bits exist */
887 quotient
+= GARDROUND
+ 1;
891 a
->fraction
.ll
= quotient
;
897 divide (FLO_type arg_a
, FLO_type arg_b
)
902 FLO_union_type au
, bu
;
910 res
= _fpdiv_parts (&a
, &b
);
914 #endif /* L_div_sf || L_div_df */
916 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
917 /* according to the demo, fpcmp returns a comparison with 0... thus
924 __fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
927 /* either nan -> unordered. Must be checked outside of this routine. */
928 if (isnan (a
) && isnan (b
))
930 return 1; /* still unordered! */
934 if (isnan (a
) || isnan (b
))
936 return 1; /* how to indicate unordered compare? */
938 if (isinf (a
) && isinf (b
))
940 /* +inf > -inf, but +inf != +inf */
941 /* b \a| +inf(0)| -inf(1)
942 ______\+--------+--------
943 +inf(0)| a==b(0)| a<b(-1)
944 -------+--------+--------
945 -inf(1)| a>b(1) | a==b(0)
946 -------+--------+--------
947 So since unordered must be nonzero, just line up the columns...
949 return b
->sign
- a
->sign
;
951 /* but not both... */
954 return a
->sign
? -1 : 1;
958 return b
->sign
? 1 : -1;
960 if (iszero (a
) && iszero (b
))
966 return b
->sign
? 1 : -1;
970 return a
->sign
? -1 : 1;
972 /* now both are "normal". */
973 if (a
->sign
!= b
->sign
)
976 return a
->sign
? -1 : 1;
978 /* same sign; exponents? */
979 if (a
->normal_exp
> b
->normal_exp
)
981 return a
->sign
? -1 : 1;
983 if (a
->normal_exp
< b
->normal_exp
)
985 return a
->sign
? 1 : -1;
987 /* same exponents; check size. */
988 if (a
->fraction
.ll
> b
->fraction
.ll
)
990 return a
->sign
? -1 : 1;
992 if (a
->fraction
.ll
< b
->fraction
.ll
)
994 return a
->sign
? 1 : -1;
996 /* after all that, they're equal. */
1001 #if defined(L_compare_sf) || defined(L_compare_df)
1003 compare (FLO_type arg_a
, FLO_type arg_b
)
1007 FLO_union_type au
, bu
;
1015 return __fpcmp_parts (&a
, &b
);
1017 #endif /* L_compare_sf || L_compare_df */
1019 #ifndef US_SOFTWARE_GOFAST
1021 /* These should be optimized for their specific tasks someday. */
1023 #if defined(L_eq_sf) || defined(L_eq_df)
1025 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
1029 FLO_union_type au
, bu
;
1037 if (isnan (&a
) || isnan (&b
))
1038 return 1; /* false, truth == 0 */
1040 return __fpcmp_parts (&a
, &b
) ;
1042 #endif /* L_eq_sf || L_eq_df */
1044 #if defined(L_ne_sf) || defined(L_ne_df)
1046 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1050 FLO_union_type au
, bu
;
1058 if (isnan (&a
) || isnan (&b
))
1059 return 1; /* true, truth != 0 */
1061 return __fpcmp_parts (&a
, &b
) ;
1063 #endif /* L_ne_sf || L_ne_df */
1065 #if defined(L_gt_sf) || defined(L_gt_df)
1067 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1071 FLO_union_type au
, bu
;
1079 if (isnan (&a
) || isnan (&b
))
1080 return -1; /* false, truth > 0 */
1082 return __fpcmp_parts (&a
, &b
);
1084 #endif /* L_gt_sf || L_gt_df */
1086 #if defined(L_ge_sf) || defined(L_ge_df)
1088 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1092 FLO_union_type au
, bu
;
1100 if (isnan (&a
) || isnan (&b
))
1101 return -1; /* false, truth >= 0 */
1102 return __fpcmp_parts (&a
, &b
) ;
1104 #endif /* L_ge_sf || L_ge_df */
1106 #if defined(L_lt_sf) || defined(L_lt_df)
1108 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1112 FLO_union_type au
, bu
;
1120 if (isnan (&a
) || isnan (&b
))
1121 return 1; /* false, truth < 0 */
1123 return __fpcmp_parts (&a
, &b
);
1125 #endif /* L_lt_sf || L_lt_df */
1127 #if defined(L_le_sf) || defined(L_le_df)
1129 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1133 FLO_union_type au
, bu
;
1141 if (isnan (&a
) || isnan (&b
))
1142 return 1; /* false, truth <= 0 */
1144 return __fpcmp_parts (&a
, &b
) ;
1146 #endif /* L_le_sf || L_le_df */
1148 #endif /* ! US_SOFTWARE_GOFAST */
1150 #if defined(L_unord_sf) || defined(L_unord_df)
1152 _unord_f2 (FLO_type arg_a
, FLO_type arg_b
)
1156 FLO_union_type au
, bu
;
1164 return (isnan (&a
) || isnan (&b
));
1166 #endif /* L_unord_sf || L_unord_df */
1168 #if defined(L_si_to_sf) || defined(L_si_to_df)
1170 si_to_float (SItype arg_a
)
1174 in
.class = CLASS_NUMBER
;
1175 in
.sign
= arg_a
< 0;
1178 in
.class = CLASS_ZERO
;
1182 in
.normal_exp
= FRACBITS
+ NGARDS
;
1185 /* Special case for minint, since there is no +ve integer
1186 representation for it */
1187 if (arg_a
== (- MAX_SI_INT
- 1))
1189 return (FLO_type
)(- MAX_SI_INT
- 1);
1191 in
.fraction
.ll
= (-arg_a
);
1194 in
.fraction
.ll
= arg_a
;
1196 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1198 in
.fraction
.ll
<<= 1;
1202 return pack_d (&in
);
1204 #endif /* L_si_to_sf || L_si_to_df */
1206 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1208 usi_to_float (USItype arg_a
)
1215 in
.class = CLASS_ZERO
;
1219 in
.class = CLASS_NUMBER
;
1220 in
.normal_exp
= FRACBITS
+ NGARDS
;
1221 in
.fraction
.ll
= arg_a
;
1223 while (in
.fraction
.ll
> (1LL << (FRACBITS
+ NGARDS
)))
1225 in
.fraction
.ll
>>= 1;
1228 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1230 in
.fraction
.ll
<<= 1;
1234 return pack_d (&in
);
1238 #if defined(L_sf_to_si) || defined(L_df_to_si)
1240 float_to_si (FLO_type arg_a
)
1253 /* get reasonable MAX_SI_INT... */
1255 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1256 /* it is a number, but a small one */
1257 if (a
.normal_exp
< 0)
1259 if (a
.normal_exp
> BITS_PER_SI
- 2)
1260 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1261 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1262 return a
.sign
? (-tmp
) : (tmp
);
1264 #endif /* L_sf_to_si || L_df_to_si */
1266 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1267 #ifdef US_SOFTWARE_GOFAST
1268 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1269 we also define them for GOFAST because the ones in libgcc2.c have the
1270 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1271 out of libgcc2.c. We can't define these here if not GOFAST because then
1272 there'd be duplicate copies. */
1275 float_to_usi (FLO_type arg_a
)
1287 /* it is a negative number */
1290 /* get reasonable MAX_USI_INT... */
1293 /* it is a number, but a small one */
1294 if (a
.normal_exp
< 0)
1296 if (a
.normal_exp
> BITS_PER_SI
- 1)
1298 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1299 return a
.fraction
.ll
<< (a
.normal_exp
- (FRACBITS
+ NGARDS
));
1301 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1303 #endif /* US_SOFTWARE_GOFAST */
1304 #endif /* L_sf_to_usi || L_df_to_usi */
1306 #if defined(L_negate_sf) || defined(L_negate_df)
1308 negate (FLO_type arg_a
)
1319 #endif /* L_negate_sf || L_negate_df */
1323 #if defined(L_make_sf)
1325 __make_fp(fp_class_type
class,
1334 in
.normal_exp
= exp
;
1335 in
.fraction
.ll
= frac
;
1336 return pack_d (&in
);
1338 #endif /* L_make_sf */
1342 /* This enables one to build an fp library that supports float but not double.
1343 Otherwise, we would get an undefined reference to __make_dp.
1344 This is needed for some 8-bit ports that can't handle well values that
1345 are 8-bytes in size, so we just don't support double for them at all. */
1347 #if defined(L_sf_to_df)
1349 sf_to_df (SFtype arg_a
)
1355 unpack_d (&au
, &in
);
1357 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1358 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1360 #endif /* L_sf_to_df */
1362 #endif /* ! FLOAT_ONLY */
1367 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1369 #if defined(L_make_df)
1371 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1377 in
.normal_exp
= exp
;
1378 in
.fraction
.ll
= frac
;
1379 return pack_d (&in
);
1381 #endif /* L_make_df */
1383 #if defined(L_df_to_sf)
1385 df_to_sf (DFtype arg_a
)
1392 unpack_d (&au
, &in
);
1394 sffrac
= in
.fraction
.ll
>> F_D_BITOFF
;
1396 /* We set the lowest guard bit in SFFRAC if we discarded any non
1398 if ((in
.fraction
.ll
& (((USItype
) 1 << F_D_BITOFF
) - 1)) != 0)
1401 return __make_fp (in
.class, in
.sign
, in
.normal_exp
, sffrac
);
1403 #endif /* L_df_to_sf */
1405 #endif /* ! FLOAT */
1406 #endif /* !EXTENDED_FLOAT_STUBS */