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, 2000, 2001
5 Free Software Foundation, Inc.
7 This file is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file with other programs, and to distribute
15 those programs without any restriction coming from the use of this
16 file. (The General Public License restrictions do apply in other
17 respects; for example, they cover modification of the file, and
18 distribution when not linked into another program.)
20 This file is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; see the file COPYING. If not, write to
27 the Free Software Foundation, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
30 /* As a special exception, if you link this library with other files,
31 some of which are compiled with GCC, to produce an executable,
32 this library does not by itself cause the resulting executable
33 to be covered by the GNU General Public License.
34 This exception does not however invalidate any other reasons why
35 the executable file might be covered by the GNU General Public License. */
37 /* This implements IEEE 754 format arithmetic, but does not provide a
38 mechanism for setting the rounding mode, or for generating or handling
41 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
42 Wilson, all of Cygnus Support. */
44 /* The intended way to use this file is to make two copies, add `#define FLOAT'
45 to one copy, then compile both copies and add them to libgcc.a. */
50 /* The following macros can be defined to change the behaviour of this file:
51 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
52 defined, then this file implements a `double', aka DFmode, fp library.
53 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
54 don't include float->double conversion which requires the double library.
55 This is useful only for machines which can't support doubles, e.g. some
57 CMPtype: Specify the type that floating point compares should return.
58 This defaults to SItype, aka int.
59 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
60 US Software goFast library. If this is not defined, the entry points use
61 the same names as libgcc1.c.
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 EXTENDED_FLOAT_STUBS
80 __truncxfsf2 (){ abort(); }
81 __extendsfxf2 (){ abort(); }
82 __addxf3 (){ abort(); }
83 __divxf3 (){ abort(); }
84 __eqxf2 (){ abort(); }
85 __extenddfxf2 (){ abort(); }
86 __gtxf2 (){ abort(); }
87 __lexf2 (){ abort(); }
88 __ltxf2 (){ abort(); }
89 __mulxf3 (){ abort(); }
90 __negxf2 (){ abort(); }
91 __nexf2 (){ abort(); }
92 __subxf3 (){ abort(); }
93 __truncxfdf2 (){ abort(); }
95 __trunctfsf2 (){ abort(); }
96 __extendsftf2 (){ abort(); }
97 __addtf3 (){ abort(); }
98 __divtf3 (){ abort(); }
99 __eqtf2 (){ abort(); }
100 __extenddftf2 (){ abort(); }
101 __gttf2 (){ abort(); }
102 __letf2 (){ abort(); }
103 __lttf2 (){ abort(); }
104 __multf3 (){ abort(); }
105 __negtf2 (){ abort(); }
106 __netf2 (){ abort(); }
107 __subtf3 (){ abort(); }
108 __trunctfdf2 (){ abort(); }
109 __gexf2 (){ abort(); }
110 __fixxfsi (){ abort(); }
111 __floatsixf (){ abort(); }
112 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
114 /* IEEE "special" number predicates */
123 #if defined L_thenan_sf
124 const fp_number_type __thenan_sf
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
125 #elif defined L_thenan_df
126 const fp_number_type __thenan_df
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
128 extern const fp_number_type __thenan_sf
;
130 extern const fp_number_type __thenan_df
;
134 static fp_number_type
*
137 /* Discard the const qualifier... */
139 return (fp_number_type
*) (& __thenan_sf
);
141 return (fp_number_type
*) (& __thenan_df
);
147 isnan ( fp_number_type
* x
)
149 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
154 isinf ( fp_number_type
* x
)
156 return x
->class == CLASS_INFINITY
;
163 iszero ( fp_number_type
* x
)
165 return x
->class == CLASS_ZERO
;
170 flip_sign ( fp_number_type
* x
)
175 extern FLO_type
pack_d ( fp_number_type
* );
177 #if defined(L_pack_df) || defined(L_pack_sf)
179 pack_d ( fp_number_type
* src
)
182 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
183 int sign
= src
->sign
;
189 if (src
->class == CLASS_QNAN
|| 1)
191 fraction
|= QUIET_NAN
;
194 else if (isinf (src
))
199 else if (iszero (src
))
204 else if (fraction
== 0)
210 if (src
->normal_exp
< NORMAL_EXPMIN
)
212 /* This number's exponent is too low to fit into the bits
213 available in the number, so we'll store 0 in the exponent and
214 shift the fraction to the right to make up for it. */
216 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
220 if (shift
> FRAC_NBITS
- NGARDS
)
222 /* No point shifting, since it's more that 64 out. */
227 int lowbit
= (fraction
& ((1 << shift
) - 1)) ? 1 : 0;
228 fraction
= (fraction
>> shift
) | lowbit
;
230 if ((fraction
& GARDMASK
) == GARDMSB
)
232 if ((fraction
& (1 << NGARDS
)))
233 fraction
+= GARDROUND
+ 1;
237 /* Add to the guards to round up. */
238 fraction
+= GARDROUND
;
240 /* Perhaps the rounding means we now need to change the
241 exponent, because the fraction is no longer denormal. */
242 if (fraction
>= IMPLICIT_1
)
248 else if (src
->normal_exp
> EXPBIAS
)
255 exp
= src
->normal_exp
+ EXPBIAS
;
256 /* IF the gard bits are the all zero, but the first, then we're
257 half way between two numbers, choose the one which makes the
258 lsb of the answer 0. */
259 if ((fraction
& GARDMASK
) == GARDMSB
)
261 if (fraction
& (1 << NGARDS
))
262 fraction
+= GARDROUND
+ 1;
266 /* Add a one to the guards to round up */
267 fraction
+= GARDROUND
;
269 if (fraction
>= IMPLICIT_2
)
278 /* We previously used bitfields to store the number, but this doesn't
279 handle little/big endian systems conveniently, so use shifts and
281 #ifdef FLOAT_BIT_ORDER_MISMATCH
282 dst
.bits
.fraction
= fraction
;
284 dst
.bits
.sign
= sign
;
286 dst
.value_raw
= fraction
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
287 dst
.value_raw
|= ((fractype
) (exp
& ((1 << EXPBITS
) - 1))) << FRACBITS
;
288 dst
.value_raw
|= ((fractype
) (sign
& 1)) << (FRACBITS
| EXPBITS
);
291 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
293 halffractype tmp
= dst
.words
[0];
294 dst
.words
[0] = dst
.words
[1];
303 #if defined(L_unpack_df) || defined(L_unpack_sf)
305 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
307 /* We previously used bitfields to store the number, but this doesn't
308 handle little/big endian systems conveniently, so use shifts and
314 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
315 FLO_union_type swapped
;
317 swapped
.words
[0] = src
->words
[1];
318 swapped
.words
[1] = src
->words
[0];
322 #ifdef FLOAT_BIT_ORDER_MISMATCH
323 fraction
= src
->bits
.fraction
;
325 sign
= src
->bits
.sign
;
327 fraction
= src
->value_raw
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
328 exp
= ((int)(src
->value_raw
>> FRACBITS
)) & ((1 << EXPBITS
) - 1);
329 sign
= ((int)(src
->value_raw
>> (FRACBITS
+ EXPBITS
))) & 1;
335 /* Hmm. Looks like 0 */
342 /* tastes like zero */
343 dst
->class = CLASS_ZERO
;
347 /* Zero exponent with non zero fraction - it's denormalized,
348 so there isn't a leading implicit one - we'll shift it so
350 dst
->normal_exp
= exp
- EXPBIAS
+ 1;
353 dst
->class = CLASS_NUMBER
;
355 while (fraction
< IMPLICIT_1
)
361 dst
->fraction
.ll
= fraction
;
364 else if (exp
== EXPMAX
)
369 /* Attached to a zero fraction - means infinity */
370 dst
->class = CLASS_INFINITY
;
374 /* Non zero fraction, means nan */
375 if (fraction
& QUIET_NAN
)
377 dst
->class = CLASS_QNAN
;
381 dst
->class = CLASS_SNAN
;
383 /* Keep the fraction part as the nan number */
384 dst
->fraction
.ll
= fraction
;
389 /* Nothing strange about this number */
390 dst
->normal_exp
= exp
- EXPBIAS
;
391 dst
->class = CLASS_NUMBER
;
392 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
395 #endif /* L_unpack_df || L_unpack_sf */
397 #if defined(L_addsub_sf) || defined(L_addsub_df)
398 static fp_number_type
*
399 _fpadd_parts (fp_number_type
* a
,
401 fp_number_type
* tmp
)
405 /* Put commonly used fields in local variables. */
421 /* Adding infinities with opposite signs yields a NaN. */
422 if (isinf (b
) && a
->sign
!= b
->sign
)
435 tmp
->sign
= a
->sign
& b
->sign
;
445 /* Got two numbers. shift the smaller and increment the exponent till
450 a_normal_exp
= a
->normal_exp
;
451 b_normal_exp
= b
->normal_exp
;
452 a_fraction
= a
->fraction
.ll
;
453 b_fraction
= b
->fraction
.ll
;
455 diff
= a_normal_exp
- b_normal_exp
;
459 if (diff
< FRAC_NBITS
)
461 /* ??? This does shifts one bit at a time. Optimize. */
462 while (a_normal_exp
> b_normal_exp
)
467 while (b_normal_exp
> a_normal_exp
)
475 /* Somethings's up.. choose the biggest */
476 if (a_normal_exp
> b_normal_exp
)
478 b_normal_exp
= a_normal_exp
;
483 a_normal_exp
= b_normal_exp
;
489 if (a
->sign
!= b
->sign
)
493 tfraction
= -a_fraction
+ b_fraction
;
497 tfraction
= a_fraction
- b_fraction
;
502 tmp
->normal_exp
= a_normal_exp
;
503 tmp
->fraction
.ll
= tfraction
;
508 tmp
->normal_exp
= a_normal_exp
;
509 tmp
->fraction
.ll
= -tfraction
;
511 /* and renormalize it */
513 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
515 tmp
->fraction
.ll
<<= 1;
522 tmp
->normal_exp
= a_normal_exp
;
523 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
525 tmp
->class = CLASS_NUMBER
;
526 /* Now the fraction is added, we have to shift down to renormalize the
529 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
531 LSHIFT (tmp
->fraction
.ll
);
539 add (FLO_type arg_a
, FLO_type arg_b
)
545 FLO_union_type au
, bu
;
553 res
= _fpadd_parts (&a
, &b
, &tmp
);
559 sub (FLO_type arg_a
, FLO_type arg_b
)
565 FLO_union_type au
, bu
;
575 res
= _fpadd_parts (&a
, &b
, &tmp
);
579 #endif /* L_addsub_sf || L_addsub_df */
581 #if defined(L_mul_sf) || defined(L_mul_df)
582 static INLINE fp_number_type
*
583 _fpmul_parts ( fp_number_type
* a
,
585 fp_number_type
* tmp
)
592 a
->sign
= a
->sign
!= b
->sign
;
597 b
->sign
= a
->sign
!= b
->sign
;
604 a
->sign
= a
->sign
!= b
->sign
;
613 b
->sign
= a
->sign
!= b
->sign
;
618 a
->sign
= a
->sign
!= b
->sign
;
623 b
->sign
= a
->sign
!= b
->sign
;
627 /* Calculate the mantissa by multiplying both numbers to get a
628 twice-as-wide number. */
630 #if defined(NO_DI_MODE)
632 fractype x
= a
->fraction
.ll
;
633 fractype ylow
= b
->fraction
.ll
;
637 /* ??? This does multiplies one bit at a time. Optimize. */
638 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
644 carry
= (low
+= ylow
) < ylow
;
645 high
+= yhigh
+ carry
;
657 /* Multiplying two USIs to get a UDI, we're safe. */
659 UDItype answer
= (UDItype
)a
->fraction
.ll
* (UDItype
)b
->fraction
.ll
;
661 high
= answer
>> BITS_PER_SI
;
665 /* fractype is DImode, but we need the result to be twice as wide.
666 Assuming a widening multiply from DImode to TImode is not
667 available, build one by hand. */
669 USItype nl
= a
->fraction
.ll
;
670 USItype nh
= a
->fraction
.ll
>> BITS_PER_SI
;
671 USItype ml
= b
->fraction
.ll
;
672 USItype mh
= b
->fraction
.ll
>> BITS_PER_SI
;
673 UDItype pp_ll
= (UDItype
) ml
* nl
;
674 UDItype pp_hl
= (UDItype
) mh
* nl
;
675 UDItype pp_lh
= (UDItype
) ml
* nh
;
676 UDItype pp_hh
= (UDItype
) mh
* nh
;
679 UDItype ps_hh__
= pp_hl
+ pp_lh
;
681 res2
+= (UDItype
)1 << BITS_PER_SI
;
682 pp_hl
= (UDItype
)(USItype
)ps_hh__
<< BITS_PER_SI
;
683 res0
= pp_ll
+ pp_hl
;
686 res2
+= (ps_hh__
>> BITS_PER_SI
) + pp_hh
;
693 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
694 tmp
->sign
= a
->sign
!= b
->sign
;
696 tmp
->normal_exp
+= 2; /* ??????????????? */
698 tmp
->normal_exp
+= 4; /* ??????????????? */
700 while (high
>= IMPLICIT_2
)
710 while (high
< IMPLICIT_1
)
719 /* rounding is tricky. if we only round if it won't make us round later. */
723 if (((high
& GARDMASK
) != GARDMSB
)
724 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
726 /* don't round, it gets done again later. */
734 if ((high
& GARDMASK
) == GARDMSB
)
736 if (high
& (1 << NGARDS
))
738 /* half way, so round to even */
739 high
+= GARDROUND
+ 1;
743 /* but we really weren't half way */
744 high
+= GARDROUND
+ 1;
747 tmp
->fraction
.ll
= high
;
748 tmp
->class = CLASS_NUMBER
;
753 multiply (FLO_type arg_a
, FLO_type arg_b
)
759 FLO_union_type au
, bu
;
767 res
= _fpmul_parts (&a
, &b
, &tmp
);
771 #endif /* L_mul_sf || L_mul_df */
773 #if defined(L_div_sf) || defined(L_div_df)
774 static INLINE fp_number_type
*
775 _fpdiv_parts (fp_number_type
* a
,
780 fractype denominator
;
792 a
->sign
= a
->sign
^ b
->sign
;
794 if (isinf (a
) || iszero (a
))
796 if (a
->class == b
->class)
809 a
->class = CLASS_INFINITY
;
813 /* Calculate the mantissa by multiplying both 64bit numbers to get a
817 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
820 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
821 numerator
= a
->fraction
.ll
;
822 denominator
= b
->fraction
.ll
;
824 if (numerator
< denominator
)
826 /* Fraction will be less than 1.0 */
832 /* ??? Does divide one bit at a time. Optimize. */
835 if (numerator
>= denominator
)
838 numerator
-= denominator
;
844 if ((quotient
& GARDMASK
) == GARDMSB
)
846 if (quotient
& (1 << NGARDS
))
848 /* half way, so round to even */
849 quotient
+= GARDROUND
+ 1;
853 /* but we really weren't half way, more bits exist */
854 quotient
+= GARDROUND
+ 1;
858 a
->fraction
.ll
= quotient
;
864 divide (FLO_type arg_a
, FLO_type arg_b
)
869 FLO_union_type au
, bu
;
877 res
= _fpdiv_parts (&a
, &b
);
881 #endif /* L_div_sf || L_div_df */
883 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
884 /* according to the demo, fpcmp returns a comparison with 0... thus
891 __fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
894 /* either nan -> unordered. Must be checked outside of this routine. */
895 if (isnan (a
) && isnan (b
))
897 return 1; /* still unordered! */
901 if (isnan (a
) || isnan (b
))
903 return 1; /* how to indicate unordered compare? */
905 if (isinf (a
) && isinf (b
))
907 /* +inf > -inf, but +inf != +inf */
908 /* b \a| +inf(0)| -inf(1)
909 ______\+--------+--------
910 +inf(0)| a==b(0)| a<b(-1)
911 -------+--------+--------
912 -inf(1)| a>b(1) | a==b(0)
913 -------+--------+--------
914 So since unordered must be non zero, just line up the columns...
916 return b
->sign
- a
->sign
;
918 /* but not both... */
921 return a
->sign
? -1 : 1;
925 return b
->sign
? 1 : -1;
927 if (iszero (a
) && iszero (b
))
933 return b
->sign
? 1 : -1;
937 return a
->sign
? -1 : 1;
939 /* now both are "normal". */
940 if (a
->sign
!= b
->sign
)
943 return a
->sign
? -1 : 1;
945 /* same sign; exponents? */
946 if (a
->normal_exp
> b
->normal_exp
)
948 return a
->sign
? -1 : 1;
950 if (a
->normal_exp
< b
->normal_exp
)
952 return a
->sign
? 1 : -1;
954 /* same exponents; check size. */
955 if (a
->fraction
.ll
> b
->fraction
.ll
)
957 return a
->sign
? -1 : 1;
959 if (a
->fraction
.ll
< b
->fraction
.ll
)
961 return a
->sign
? 1 : -1;
963 /* after all that, they're equal. */
968 #if defined(L_compare_sf) || defined(L_compare_df)
970 compare (FLO_type arg_a
, FLO_type arg_b
)
974 FLO_union_type au
, bu
;
982 return __fpcmp_parts (&a
, &b
);
984 #endif /* L_compare_sf || L_compare_df */
986 #ifndef US_SOFTWARE_GOFAST
988 /* These should be optimized for their specific tasks someday. */
990 #if defined(L_eq_sf) || defined(L_eq_df)
992 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
996 FLO_union_type au
, bu
;
1004 if (isnan (&a
) || isnan (&b
))
1005 return 1; /* false, truth == 0 */
1007 return __fpcmp_parts (&a
, &b
) ;
1009 #endif /* L_eq_sf || L_eq_df */
1011 #if defined(L_ne_sf) || defined(L_ne_df)
1013 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1017 FLO_union_type au
, bu
;
1025 if (isnan (&a
) || isnan (&b
))
1026 return 1; /* true, truth != 0 */
1028 return __fpcmp_parts (&a
, &b
) ;
1030 #endif /* L_ne_sf || L_ne_df */
1032 #if defined(L_gt_sf) || defined(L_gt_df)
1034 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1038 FLO_union_type au
, bu
;
1046 if (isnan (&a
) || isnan (&b
))
1047 return -1; /* false, truth > 0 */
1049 return __fpcmp_parts (&a
, &b
);
1051 #endif /* L_gt_sf || L_gt_df */
1053 #if defined(L_ge_sf) || defined(L_ge_df)
1055 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1059 FLO_union_type au
, bu
;
1067 if (isnan (&a
) || isnan (&b
))
1068 return -1; /* false, truth >= 0 */
1069 return __fpcmp_parts (&a
, &b
) ;
1071 #endif /* L_ge_sf || L_ge_df */
1073 #if defined(L_lt_sf) || defined(L_lt_df)
1075 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1079 FLO_union_type au
, bu
;
1087 if (isnan (&a
) || isnan (&b
))
1088 return 1; /* false, truth < 0 */
1090 return __fpcmp_parts (&a
, &b
);
1092 #endif /* L_lt_sf || L_lt_df */
1094 #if defined(L_le_sf) || defined(L_le_df)
1096 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1100 FLO_union_type au
, bu
;
1108 if (isnan (&a
) || isnan (&b
))
1109 return 1; /* false, truth <= 0 */
1111 return __fpcmp_parts (&a
, &b
) ;
1113 #endif /* L_le_sf || L_le_df */
1115 #if defined(L_unord_sf) || defined(L_unord_df)
1117 _unord_f2 (FLO_type arg_a
, FLO_type arg_b
)
1121 FLO_union_type au
, bu
;
1129 return (isnan (&a
) || isnan (&b
));
1131 #endif /* L_unord_sf || L_unord_df */
1133 #endif /* ! US_SOFTWARE_GOFAST */
1135 #if defined(L_si_to_sf) || defined(L_si_to_df)
1137 si_to_float (SItype arg_a
)
1141 in
.class = CLASS_NUMBER
;
1142 in
.sign
= arg_a
< 0;
1145 in
.class = CLASS_ZERO
;
1149 in
.normal_exp
= FRACBITS
+ NGARDS
;
1152 /* Special case for minint, since there is no +ve integer
1153 representation for it */
1154 if (arg_a
== (- MAX_SI_INT
- 1))
1156 return (FLO_type
)(- MAX_SI_INT
- 1);
1158 in
.fraction
.ll
= (-arg_a
);
1161 in
.fraction
.ll
= arg_a
;
1163 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1165 in
.fraction
.ll
<<= 1;
1169 return pack_d (&in
);
1171 #endif /* L_si_to_sf || L_si_to_df */
1173 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1175 usi_to_float (USItype arg_a
)
1182 in
.class = CLASS_ZERO
;
1186 in
.class = CLASS_NUMBER
;
1187 in
.normal_exp
= FRACBITS
+ NGARDS
;
1188 in
.fraction
.ll
= arg_a
;
1190 while (in
.fraction
.ll
> (1LL << (FRACBITS
+ NGARDS
)))
1192 in
.fraction
.ll
>>= 1;
1195 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1197 in
.fraction
.ll
<<= 1;
1201 return pack_d (&in
);
1205 #if defined(L_sf_to_si) || defined(L_df_to_si)
1207 float_to_si (FLO_type arg_a
)
1220 /* get reasonable MAX_SI_INT... */
1222 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1223 /* it is a number, but a small one */
1224 if (a
.normal_exp
< 0)
1226 if (a
.normal_exp
> BITS_PER_SI
- 2)
1227 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1228 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1229 return a
.sign
? (-tmp
) : (tmp
);
1231 #endif /* L_sf_to_si || L_df_to_si */
1233 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1234 #ifdef US_SOFTWARE_GOFAST
1235 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1236 we also define them for GOFAST because the ones in libgcc2.c have the
1237 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1238 out of libgcc2.c. We can't define these here if not GOFAST because then
1239 there'd be duplicate copies. */
1242 float_to_usi (FLO_type arg_a
)
1254 /* it is a negative number */
1257 /* get reasonable MAX_USI_INT... */
1260 /* it is a number, but a small one */
1261 if (a
.normal_exp
< 0)
1263 if (a
.normal_exp
> BITS_PER_SI
- 1)
1265 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1266 return a
.fraction
.ll
<< (a
.normal_exp
- (FRACBITS
+ NGARDS
));
1268 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1270 #endif /* US_SOFTWARE_GOFAST */
1271 #endif /* L_sf_to_usi || L_df_to_usi */
1273 #if defined(L_negate_sf) || defined(L_negate_df)
1275 negate (FLO_type arg_a
)
1286 #endif /* L_negate_sf || L_negate_df */
1290 #if defined(L_make_sf)
1292 __make_fp(fp_class_type
class,
1301 in
.normal_exp
= exp
;
1302 in
.fraction
.ll
= frac
;
1303 return pack_d (&in
);
1305 #endif /* L_make_sf */
1309 /* This enables one to build an fp library that supports float but not double.
1310 Otherwise, we would get an undefined reference to __make_dp.
1311 This is needed for some 8-bit ports that can't handle well values that
1312 are 8-bytes in size, so we just don't support double for them at all. */
1314 #if defined(L_sf_to_df)
1316 sf_to_df (SFtype arg_a
)
1322 unpack_d (&au
, &in
);
1324 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1325 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1327 #endif /* L_sf_to_df */
1329 #endif /* ! FLOAT_ONLY */
1334 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1336 #if defined(L_make_df)
1338 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1344 in
.normal_exp
= exp
;
1345 in
.fraction
.ll
= frac
;
1346 return pack_d (&in
);
1348 #endif /* L_make_df */
1350 #if defined(L_df_to_sf)
1352 df_to_sf (DFtype arg_a
)
1359 unpack_d (&au
, &in
);
1361 sffrac
= in
.fraction
.ll
>> F_D_BITOFF
;
1363 /* We set the lowest guard bit in SFFRAC if we discarded any non
1365 if ((in
.fraction
.ll
& (((USItype
) 1 << F_D_BITOFF
) - 1)) != 0)
1368 return __make_fp (in
.class, in
.sign
, in
.normal_exp
, sffrac
);
1370 #endif /* L_df_to_sf */
1372 #endif /* ! FLOAT */
1373 #endif /* !EXTENDED_FLOAT_STUBS */