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 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
;
184 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && (isnan (src
) || isinf (src
)))
186 /* We can't represent these values accurately. By using the
187 largest possible magnitude, we guarantee that the conversion
188 of infinity is at least as big as any finite number. */
190 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
192 else if (isnan (src
))
195 if (src
->class == CLASS_QNAN
|| 1)
197 fraction
|= QUIET_NAN
;
200 else if (isinf (src
))
205 else if (iszero (src
))
210 else if (fraction
== 0)
216 if (src
->normal_exp
< NORMAL_EXPMIN
)
219 /* Go straight to a zero representation if denormals are not
220 supported. The denormal handling would be harmless but
221 isn't unnecessary. */
224 #else /* NO_DENORMALS */
225 /* This number's exponent is too low to fit into the bits
226 available in the number, so we'll store 0 in the exponent and
227 shift the fraction to the right to make up for it. */
229 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
233 if (shift
> FRAC_NBITS
- NGARDS
)
235 /* No point shifting, since it's more that 64 out. */
240 int lowbit
= (fraction
& (((fractype
)1 << shift
) - 1)) ? 1 : 0;
241 fraction
= (fraction
>> shift
) | lowbit
;
243 if ((fraction
& GARDMASK
) == GARDMSB
)
245 if ((fraction
& (1 << NGARDS
)))
246 fraction
+= GARDROUND
+ 1;
250 /* Add to the guards to round up. */
251 fraction
+= GARDROUND
;
253 /* Perhaps the rounding means we now need to change the
254 exponent, because the fraction is no longer denormal. */
255 if (fraction
>= IMPLICIT_1
)
260 #endif /* NO_DENORMALS */
262 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
)
263 && src
->normal_exp
> EXPBIAS
)
270 exp
= src
->normal_exp
+ EXPBIAS
;
271 if (!ROUND_TOWARDS_ZERO
)
273 /* IF the gard bits are the all zero, but the first, then we're
274 half way between two numbers, choose the one which makes the
275 lsb of the answer 0. */
276 if ((fraction
& GARDMASK
) == GARDMSB
)
278 if (fraction
& (1 << NGARDS
))
279 fraction
+= GARDROUND
+ 1;
283 /* Add a one to the guards to round up */
284 fraction
+= GARDROUND
;
286 if (fraction
>= IMPLICIT_2
)
294 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
> EXPMAX
)
296 /* Saturate on overflow. */
298 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
303 /* We previously used bitfields to store the number, but this doesn't
304 handle little/big endian systems conveniently, so use shifts and
306 #ifdef FLOAT_BIT_ORDER_MISMATCH
307 dst
.bits
.fraction
= fraction
;
309 dst
.bits
.sign
= sign
;
311 dst
.value_raw
= fraction
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
312 dst
.value_raw
|= ((fractype
) (exp
& ((1 << EXPBITS
) - 1))) << FRACBITS
;
313 dst
.value_raw
|= ((fractype
) (sign
& 1)) << (FRACBITS
| EXPBITS
);
316 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
318 halffractype tmp
= dst
.words
[0];
319 dst
.words
[0] = dst
.words
[1];
328 #if defined(L_unpack_df) || defined(L_unpack_sf)
330 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
332 /* We previously used bitfields to store the number, but this doesn't
333 handle little/big endian systems conveniently, so use shifts and
339 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
340 FLO_union_type swapped
;
342 swapped
.words
[0] = src
->words
[1];
343 swapped
.words
[1] = src
->words
[0];
347 #ifdef FLOAT_BIT_ORDER_MISMATCH
348 fraction
= src
->bits
.fraction
;
350 sign
= src
->bits
.sign
;
352 fraction
= src
->value_raw
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
353 exp
= ((int)(src
->value_raw
>> FRACBITS
)) & ((1 << EXPBITS
) - 1);
354 sign
= ((int)(src
->value_raw
>> (FRACBITS
+ EXPBITS
))) & 1;
360 /* Hmm. Looks like 0 */
367 /* tastes like zero */
368 dst
->class = CLASS_ZERO
;
372 /* Zero exponent with non zero fraction - it's denormalized,
373 so there isn't a leading implicit one - we'll shift it so
375 dst
->normal_exp
= exp
- EXPBIAS
+ 1;
378 dst
->class = CLASS_NUMBER
;
380 while (fraction
< IMPLICIT_1
)
386 dst
->fraction
.ll
= fraction
;
389 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
== EXPMAX
)
394 /* Attached to a zero fraction - means infinity */
395 dst
->class = CLASS_INFINITY
;
399 /* Non zero fraction, means nan */
400 if (fraction
& QUIET_NAN
)
402 dst
->class = CLASS_QNAN
;
406 dst
->class = CLASS_SNAN
;
408 /* Keep the fraction part as the nan number */
409 dst
->fraction
.ll
= fraction
;
414 /* Nothing strange about this number */
415 dst
->normal_exp
= exp
- EXPBIAS
;
416 dst
->class = CLASS_NUMBER
;
417 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
420 #endif /* L_unpack_df || L_unpack_sf */
422 #if defined(L_addsub_sf) || defined(L_addsub_df)
423 static fp_number_type
*
424 _fpadd_parts (fp_number_type
* a
,
426 fp_number_type
* tmp
)
430 /* Put commonly used fields in local variables. */
446 /* Adding infinities with opposite signs yields a NaN. */
447 if (isinf (b
) && a
->sign
!= b
->sign
)
460 tmp
->sign
= a
->sign
& b
->sign
;
470 /* Got two numbers. shift the smaller and increment the exponent till
475 a_normal_exp
= a
->normal_exp
;
476 b_normal_exp
= b
->normal_exp
;
477 a_fraction
= a
->fraction
.ll
;
478 b_fraction
= b
->fraction
.ll
;
480 diff
= a_normal_exp
- b_normal_exp
;
484 if (diff
< FRAC_NBITS
)
486 /* ??? This does shifts one bit at a time. Optimize. */
487 while (a_normal_exp
> b_normal_exp
)
492 while (b_normal_exp
> a_normal_exp
)
500 /* Somethings's up.. choose the biggest */
501 if (a_normal_exp
> b_normal_exp
)
503 b_normal_exp
= a_normal_exp
;
508 a_normal_exp
= b_normal_exp
;
514 if (a
->sign
!= b
->sign
)
518 tfraction
= -a_fraction
+ b_fraction
;
522 tfraction
= a_fraction
- b_fraction
;
527 tmp
->normal_exp
= a_normal_exp
;
528 tmp
->fraction
.ll
= tfraction
;
533 tmp
->normal_exp
= a_normal_exp
;
534 tmp
->fraction
.ll
= -tfraction
;
536 /* and renormalize it */
538 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
540 tmp
->fraction
.ll
<<= 1;
547 tmp
->normal_exp
= a_normal_exp
;
548 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
550 tmp
->class = CLASS_NUMBER
;
551 /* Now the fraction is added, we have to shift down to renormalize the
554 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
556 LSHIFT (tmp
->fraction
.ll
);
564 add (FLO_type arg_a
, FLO_type arg_b
)
570 FLO_union_type au
, bu
;
578 res
= _fpadd_parts (&a
, &b
, &tmp
);
584 sub (FLO_type arg_a
, FLO_type arg_b
)
590 FLO_union_type au
, bu
;
600 res
= _fpadd_parts (&a
, &b
, &tmp
);
604 #endif /* L_addsub_sf || L_addsub_df */
606 #if defined(L_mul_sf) || defined(L_mul_df)
607 static INLINE fp_number_type
*
608 _fpmul_parts ( fp_number_type
* a
,
610 fp_number_type
* tmp
)
617 a
->sign
= a
->sign
!= b
->sign
;
622 b
->sign
= a
->sign
!= b
->sign
;
629 a
->sign
= a
->sign
!= b
->sign
;
638 b
->sign
= a
->sign
!= b
->sign
;
643 a
->sign
= a
->sign
!= b
->sign
;
648 b
->sign
= a
->sign
!= b
->sign
;
652 /* Calculate the mantissa by multiplying both numbers to get a
653 twice-as-wide number. */
655 #if defined(NO_DI_MODE)
657 fractype x
= a
->fraction
.ll
;
658 fractype ylow
= b
->fraction
.ll
;
662 /* ??? This does multiplies one bit at a time. Optimize. */
663 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
669 carry
= (low
+= ylow
) < ylow
;
670 high
+= yhigh
+ carry
;
682 /* Multiplying two USIs to get a UDI, we're safe. */
684 UDItype answer
= (UDItype
)a
->fraction
.ll
* (UDItype
)b
->fraction
.ll
;
686 high
= answer
>> BITS_PER_SI
;
690 /* fractype is DImode, but we need the result to be twice as wide.
691 Assuming a widening multiply from DImode to TImode is not
692 available, build one by hand. */
694 USItype nl
= a
->fraction
.ll
;
695 USItype nh
= a
->fraction
.ll
>> BITS_PER_SI
;
696 USItype ml
= b
->fraction
.ll
;
697 USItype mh
= b
->fraction
.ll
>> BITS_PER_SI
;
698 UDItype pp_ll
= (UDItype
) ml
* nl
;
699 UDItype pp_hl
= (UDItype
) mh
* nl
;
700 UDItype pp_lh
= (UDItype
) ml
* nh
;
701 UDItype pp_hh
= (UDItype
) mh
* nh
;
704 UDItype ps_hh__
= pp_hl
+ pp_lh
;
706 res2
+= (UDItype
)1 << BITS_PER_SI
;
707 pp_hl
= (UDItype
)(USItype
)ps_hh__
<< BITS_PER_SI
;
708 res0
= pp_ll
+ pp_hl
;
711 res2
+= (ps_hh__
>> BITS_PER_SI
) + pp_hh
;
718 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
719 tmp
->sign
= a
->sign
!= b
->sign
;
721 tmp
->normal_exp
+= 2; /* ??????????????? */
723 tmp
->normal_exp
+= 4; /* ??????????????? */
725 while (high
>= IMPLICIT_2
)
735 while (high
< IMPLICIT_1
)
744 /* rounding is tricky. if we only round if it won't make us round later. */
748 if (((high
& GARDMASK
) != GARDMSB
)
749 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
751 /* don't round, it gets done again later. */
759 if (!ROUND_TOWARDS_ZERO
&& (high
& GARDMASK
) == GARDMSB
)
761 if (high
& (1 << NGARDS
))
763 /* half way, so round to even */
764 high
+= GARDROUND
+ 1;
768 /* but we really weren't half way */
769 high
+= GARDROUND
+ 1;
772 tmp
->fraction
.ll
= high
;
773 tmp
->class = CLASS_NUMBER
;
778 multiply (FLO_type arg_a
, FLO_type arg_b
)
784 FLO_union_type au
, bu
;
792 res
= _fpmul_parts (&a
, &b
, &tmp
);
796 #endif /* L_mul_sf || L_mul_df */
798 #if defined(L_div_sf) || defined(L_div_df)
799 static INLINE fp_number_type
*
800 _fpdiv_parts (fp_number_type
* a
,
805 fractype denominator
;
817 a
->sign
= a
->sign
^ b
->sign
;
819 if (isinf (a
) || iszero (a
))
821 if (a
->class == b
->class)
834 a
->class = CLASS_INFINITY
;
838 /* Calculate the mantissa by multiplying both 64bit numbers to get a
842 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
845 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
846 numerator
= a
->fraction
.ll
;
847 denominator
= b
->fraction
.ll
;
849 if (numerator
< denominator
)
851 /* Fraction will be less than 1.0 */
857 /* ??? Does divide one bit at a time. Optimize. */
860 if (numerator
>= denominator
)
863 numerator
-= denominator
;
869 if (!ROUND_TOWARDS_ZERO
&& (quotient
& GARDMASK
) == GARDMSB
)
871 if (quotient
& (1 << NGARDS
))
873 /* half way, so round to even */
874 quotient
+= GARDROUND
+ 1;
878 /* but we really weren't half way, more bits exist */
879 quotient
+= GARDROUND
+ 1;
883 a
->fraction
.ll
= quotient
;
889 divide (FLO_type arg_a
, FLO_type arg_b
)
894 FLO_union_type au
, bu
;
902 res
= _fpdiv_parts (&a
, &b
);
906 #endif /* L_div_sf || L_div_df */
908 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
909 /* according to the demo, fpcmp returns a comparison with 0... thus
916 __fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
919 /* either nan -> unordered. Must be checked outside of this routine. */
920 if (isnan (a
) && isnan (b
))
922 return 1; /* still unordered! */
926 if (isnan (a
) || isnan (b
))
928 return 1; /* how to indicate unordered compare? */
930 if (isinf (a
) && isinf (b
))
932 /* +inf > -inf, but +inf != +inf */
933 /* b \a| +inf(0)| -inf(1)
934 ______\+--------+--------
935 +inf(0)| a==b(0)| a<b(-1)
936 -------+--------+--------
937 -inf(1)| a>b(1) | a==b(0)
938 -------+--------+--------
939 So since unordered must be non zero, just line up the columns...
941 return b
->sign
- a
->sign
;
943 /* but not both... */
946 return a
->sign
? -1 : 1;
950 return b
->sign
? 1 : -1;
952 if (iszero (a
) && iszero (b
))
958 return b
->sign
? 1 : -1;
962 return a
->sign
? -1 : 1;
964 /* now both are "normal". */
965 if (a
->sign
!= b
->sign
)
968 return a
->sign
? -1 : 1;
970 /* same sign; exponents? */
971 if (a
->normal_exp
> b
->normal_exp
)
973 return a
->sign
? -1 : 1;
975 if (a
->normal_exp
< b
->normal_exp
)
977 return a
->sign
? 1 : -1;
979 /* same exponents; check size. */
980 if (a
->fraction
.ll
> b
->fraction
.ll
)
982 return a
->sign
? -1 : 1;
984 if (a
->fraction
.ll
< b
->fraction
.ll
)
986 return a
->sign
? 1 : -1;
988 /* after all that, they're equal. */
993 #if defined(L_compare_sf) || defined(L_compare_df)
995 compare (FLO_type arg_a
, FLO_type arg_b
)
999 FLO_union_type au
, bu
;
1007 return __fpcmp_parts (&a
, &b
);
1009 #endif /* L_compare_sf || L_compare_df */
1011 #ifndef US_SOFTWARE_GOFAST
1013 /* These should be optimized for their specific tasks someday. */
1015 #if defined(L_eq_sf) || defined(L_eq_df)
1017 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
1021 FLO_union_type au
, bu
;
1029 if (isnan (&a
) || isnan (&b
))
1030 return 1; /* false, truth == 0 */
1032 return __fpcmp_parts (&a
, &b
) ;
1034 #endif /* L_eq_sf || L_eq_df */
1036 #if defined(L_ne_sf) || defined(L_ne_df)
1038 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1042 FLO_union_type au
, bu
;
1050 if (isnan (&a
) || isnan (&b
))
1051 return 1; /* true, truth != 0 */
1053 return __fpcmp_parts (&a
, &b
) ;
1055 #endif /* L_ne_sf || L_ne_df */
1057 #if defined(L_gt_sf) || defined(L_gt_df)
1059 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1063 FLO_union_type au
, bu
;
1071 if (isnan (&a
) || isnan (&b
))
1072 return -1; /* false, truth > 0 */
1074 return __fpcmp_parts (&a
, &b
);
1076 #endif /* L_gt_sf || L_gt_df */
1078 #if defined(L_ge_sf) || defined(L_ge_df)
1080 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1084 FLO_union_type au
, bu
;
1092 if (isnan (&a
) || isnan (&b
))
1093 return -1; /* false, truth >= 0 */
1094 return __fpcmp_parts (&a
, &b
) ;
1096 #endif /* L_ge_sf || L_ge_df */
1098 #if defined(L_lt_sf) || defined(L_lt_df)
1100 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1104 FLO_union_type au
, bu
;
1112 if (isnan (&a
) || isnan (&b
))
1113 return 1; /* false, truth < 0 */
1115 return __fpcmp_parts (&a
, &b
);
1117 #endif /* L_lt_sf || L_lt_df */
1119 #if defined(L_le_sf) || defined(L_le_df)
1121 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1125 FLO_union_type au
, bu
;
1133 if (isnan (&a
) || isnan (&b
))
1134 return 1; /* false, truth <= 0 */
1136 return __fpcmp_parts (&a
, &b
) ;
1138 #endif /* L_le_sf || L_le_df */
1140 #endif /* ! US_SOFTWARE_GOFAST */
1142 #if defined(L_unord_sf) || defined(L_unord_df)
1144 _unord_f2 (FLO_type arg_a
, FLO_type arg_b
)
1148 FLO_union_type au
, bu
;
1156 return (isnan (&a
) || isnan (&b
));
1158 #endif /* L_unord_sf || L_unord_df */
1160 #if defined(L_si_to_sf) || defined(L_si_to_df)
1162 si_to_float (SItype arg_a
)
1166 in
.class = CLASS_NUMBER
;
1167 in
.sign
= arg_a
< 0;
1170 in
.class = CLASS_ZERO
;
1174 in
.normal_exp
= FRACBITS
+ NGARDS
;
1177 /* Special case for minint, since there is no +ve integer
1178 representation for it */
1179 if (arg_a
== (- MAX_SI_INT
- 1))
1181 return (FLO_type
)(- MAX_SI_INT
- 1);
1183 in
.fraction
.ll
= (-arg_a
);
1186 in
.fraction
.ll
= arg_a
;
1188 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1190 in
.fraction
.ll
<<= 1;
1194 return pack_d (&in
);
1196 #endif /* L_si_to_sf || L_si_to_df */
1198 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1200 usi_to_float (USItype arg_a
)
1207 in
.class = CLASS_ZERO
;
1211 in
.class = CLASS_NUMBER
;
1212 in
.normal_exp
= FRACBITS
+ NGARDS
;
1213 in
.fraction
.ll
= arg_a
;
1215 while (in
.fraction
.ll
> (1LL << (FRACBITS
+ NGARDS
)))
1217 in
.fraction
.ll
>>= 1;
1220 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1222 in
.fraction
.ll
<<= 1;
1226 return pack_d (&in
);
1230 #if defined(L_sf_to_si) || defined(L_df_to_si)
1232 float_to_si (FLO_type arg_a
)
1245 /* get reasonable MAX_SI_INT... */
1247 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1248 /* it is a number, but a small one */
1249 if (a
.normal_exp
< 0)
1251 if (a
.normal_exp
> BITS_PER_SI
- 2)
1252 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1253 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1254 return a
.sign
? (-tmp
) : (tmp
);
1256 #endif /* L_sf_to_si || L_df_to_si */
1258 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1259 #ifdef US_SOFTWARE_GOFAST
1260 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1261 we also define them for GOFAST because the ones in libgcc2.c have the
1262 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1263 out of libgcc2.c. We can't define these here if not GOFAST because then
1264 there'd be duplicate copies. */
1267 float_to_usi (FLO_type arg_a
)
1279 /* it is a negative number */
1282 /* get reasonable MAX_USI_INT... */
1285 /* it is a number, but a small one */
1286 if (a
.normal_exp
< 0)
1288 if (a
.normal_exp
> BITS_PER_SI
- 1)
1290 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1291 return a
.fraction
.ll
<< (a
.normal_exp
- (FRACBITS
+ NGARDS
));
1293 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1295 #endif /* US_SOFTWARE_GOFAST */
1296 #endif /* L_sf_to_usi || L_df_to_usi */
1298 #if defined(L_negate_sf) || defined(L_negate_df)
1300 negate (FLO_type arg_a
)
1311 #endif /* L_negate_sf || L_negate_df */
1315 #if defined(L_make_sf)
1317 __make_fp(fp_class_type
class,
1326 in
.normal_exp
= exp
;
1327 in
.fraction
.ll
= frac
;
1328 return pack_d (&in
);
1330 #endif /* L_make_sf */
1334 /* This enables one to build an fp library that supports float but not double.
1335 Otherwise, we would get an undefined reference to __make_dp.
1336 This is needed for some 8-bit ports that can't handle well values that
1337 are 8-bytes in size, so we just don't support double for them at all. */
1339 #if defined(L_sf_to_df)
1341 sf_to_df (SFtype arg_a
)
1347 unpack_d (&au
, &in
);
1349 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1350 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1352 #endif /* L_sf_to_df */
1354 #endif /* ! FLOAT_ONLY */
1359 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1361 #if defined(L_make_df)
1363 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1369 in
.normal_exp
= exp
;
1370 in
.fraction
.ll
= frac
;
1371 return pack_d (&in
);
1373 #endif /* L_make_df */
1375 #if defined(L_df_to_sf)
1377 df_to_sf (DFtype arg_a
)
1384 unpack_d (&au
, &in
);
1386 sffrac
= in
.fraction
.ll
>> F_D_BITOFF
;
1388 /* We set the lowest guard bit in SFFRAC if we discarded any non
1390 if ((in
.fraction
.ll
& (((USItype
) 1 << F_D_BITOFF
) - 1)) != 0)
1393 return __make_fp (in
.class, in
.sign
, in
.normal_exp
, sffrac
);
1395 #endif /* L_df_to_sf */
1397 #endif /* ! FLOAT */
1398 #endif /* !EXTENDED_FLOAT_STUBS */