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 __truncxfsf2 (){ abort(); }
83 __extendsfxf2 (){ abort(); }
84 __addxf3 (){ abort(); }
85 __divxf3 (){ abort(); }
86 __eqxf2 (){ abort(); }
87 __extenddfxf2 (){ abort(); }
88 __gtxf2 (){ abort(); }
89 __lexf2 (){ abort(); }
90 __ltxf2 (){ abort(); }
91 __mulxf3 (){ abort(); }
92 __negxf2 (){ abort(); }
93 __nexf2 (){ abort(); }
94 __subxf3 (){ abort(); }
95 __truncxfdf2 (){ abort(); }
97 __trunctfsf2 (){ abort(); }
98 __extendsftf2 (){ abort(); }
99 __addtf3 (){ abort(); }
100 __divtf3 (){ abort(); }
101 __eqtf2 (){ abort(); }
102 __extenddftf2 (){ abort(); }
103 __gttf2 (){ abort(); }
104 __letf2 (){ abort(); }
105 __lttf2 (){ abort(); }
106 __multf3 (){ abort(); }
107 __negtf2 (){ abort(); }
108 __netf2 (){ abort(); }
109 __subtf3 (){ abort(); }
110 __trunctfdf2 (){ abort(); }
111 __gexf2 (){ abort(); }
112 __fixxfsi (){ abort(); }
113 __floatsixf (){ abort(); }
114 #else /* !EXTENDED_FLOAT_STUBS, rest of file */
116 /* IEEE "special" number predicates */
125 #if defined L_thenan_sf
126 const fp_number_type __thenan_sf
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
127 #elif defined L_thenan_df
128 const fp_number_type __thenan_df
= { CLASS_SNAN
, 0, 0, {(fractype
) 0} };
130 extern const fp_number_type __thenan_sf
;
132 extern const fp_number_type __thenan_df
;
136 static fp_number_type
*
139 /* Discard the const qualifier... */
141 return (fp_number_type
*) (& __thenan_sf
);
143 return (fp_number_type
*) (& __thenan_df
);
149 isnan ( fp_number_type
* x
)
151 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
156 isinf ( fp_number_type
* x
)
158 return x
->class == CLASS_INFINITY
;
165 iszero ( fp_number_type
* x
)
167 return x
->class == CLASS_ZERO
;
172 flip_sign ( fp_number_type
* x
)
177 extern FLO_type
pack_d ( fp_number_type
* );
179 #if defined(L_pack_df) || defined(L_pack_sf)
181 pack_d ( fp_number_type
* src
)
184 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
185 int sign
= src
->sign
;
188 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && (isnan (src
) || isinf (src
)))
190 /* We can't represent these values accurately. By using the
191 largest possible magnitude, we guarantee that the conversion
192 of infinity is at least as big as any finite number. */
194 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
196 else if (isnan (src
))
199 if (src
->class == CLASS_QNAN
|| 1)
201 fraction
|= QUIET_NAN
;
204 else if (isinf (src
))
209 else if (iszero (src
))
214 else if (fraction
== 0)
220 if (src
->normal_exp
< NORMAL_EXPMIN
)
223 /* Go straight to a zero representation if denormals are not
224 supported. The denormal handling would be harmless but
225 isn't unnecessary. */
228 #else /* NO_DENORMALS */
229 /* This number's exponent is too low to fit into the bits
230 available in the number, so we'll store 0 in the exponent and
231 shift the fraction to the right to make up for it. */
233 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
237 if (shift
> FRAC_NBITS
- NGARDS
)
239 /* No point shifting, since it's more that 64 out. */
244 int lowbit
= (fraction
& (((fractype
)1 << shift
) - 1)) ? 1 : 0;
245 fraction
= (fraction
>> shift
) | lowbit
;
247 if ((fraction
& GARDMASK
) == GARDMSB
)
249 if ((fraction
& (1 << NGARDS
)))
250 fraction
+= GARDROUND
+ 1;
254 /* Add to the guards to round up. */
255 fraction
+= GARDROUND
;
257 /* Perhaps the rounding means we now need to change the
258 exponent, because the fraction is no longer denormal. */
259 if (fraction
>= IMPLICIT_1
)
264 #endif /* NO_DENORMALS */
266 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
)
267 && src
->normal_exp
> EXPBIAS
)
274 exp
= src
->normal_exp
+ EXPBIAS
;
275 if (!ROUND_TOWARDS_ZERO
)
277 /* IF the gard bits are the all zero, but the first, then we're
278 half way between two numbers, choose the one which makes the
279 lsb of the answer 0. */
280 if ((fraction
& GARDMASK
) == GARDMSB
)
282 if (fraction
& (1 << NGARDS
))
283 fraction
+= GARDROUND
+ 1;
287 /* Add a one to the guards to round up */
288 fraction
+= GARDROUND
;
290 if (fraction
>= IMPLICIT_2
)
298 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
> EXPMAX
)
300 /* Saturate on overflow. */
302 fraction
= ((fractype
) 1 << FRACBITS
) - 1;
307 /* We previously used bitfields to store the number, but this doesn't
308 handle little/big endian systems conveniently, so use shifts and
310 #ifdef FLOAT_BIT_ORDER_MISMATCH
311 dst
.bits
.fraction
= fraction
;
313 dst
.bits
.sign
= sign
;
315 dst
.value_raw
= fraction
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
316 dst
.value_raw
|= ((fractype
) (exp
& ((1 << EXPBITS
) - 1))) << FRACBITS
;
317 dst
.value_raw
|= ((fractype
) (sign
& 1)) << (FRACBITS
| EXPBITS
);
320 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
322 halffractype tmp
= dst
.words
[0];
323 dst
.words
[0] = dst
.words
[1];
332 #if defined(L_unpack_df) || defined(L_unpack_sf)
334 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
336 /* We previously used bitfields to store the number, but this doesn't
337 handle little/big endian systems conveniently, so use shifts and
343 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
344 FLO_union_type swapped
;
346 swapped
.words
[0] = src
->words
[1];
347 swapped
.words
[1] = src
->words
[0];
351 #ifdef FLOAT_BIT_ORDER_MISMATCH
352 fraction
= src
->bits
.fraction
;
354 sign
= src
->bits
.sign
;
356 fraction
= src
->value_raw
& ((((fractype
)1) << FRACBITS
) - (fractype
)1);
357 exp
= ((int)(src
->value_raw
>> FRACBITS
)) & ((1 << EXPBITS
) - 1);
358 sign
= ((int)(src
->value_raw
>> (FRACBITS
+ EXPBITS
))) & 1;
364 /* Hmm. Looks like 0 */
371 /* tastes like zero */
372 dst
->class = CLASS_ZERO
;
376 /* Zero exponent with nonzero fraction - it's denormalized,
377 so there isn't a leading implicit one - we'll shift it so
379 dst
->normal_exp
= exp
- EXPBIAS
+ 1;
382 dst
->class = CLASS_NUMBER
;
384 while (fraction
< IMPLICIT_1
)
390 dst
->fraction
.ll
= fraction
;
393 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS
) && exp
== EXPMAX
)
398 /* Attached to a zero fraction - means infinity */
399 dst
->class = CLASS_INFINITY
;
403 /* Nonzero fraction, means nan */
404 if (fraction
& QUIET_NAN
)
406 dst
->class = CLASS_QNAN
;
410 dst
->class = CLASS_SNAN
;
412 /* Keep the fraction part as the nan number */
413 dst
->fraction
.ll
= fraction
;
418 /* Nothing strange about this number */
419 dst
->normal_exp
= exp
- EXPBIAS
;
420 dst
->class = CLASS_NUMBER
;
421 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
424 #endif /* L_unpack_df || L_unpack_sf */
426 #if defined(L_addsub_sf) || defined(L_addsub_df)
427 static fp_number_type
*
428 _fpadd_parts (fp_number_type
* a
,
430 fp_number_type
* tmp
)
434 /* Put commonly used fields in local variables. */
450 /* Adding infinities with opposite signs yields a NaN. */
451 if (isinf (b
) && a
->sign
!= b
->sign
)
464 tmp
->sign
= a
->sign
& b
->sign
;
474 /* Got two numbers. shift the smaller and increment the exponent till
479 a_normal_exp
= a
->normal_exp
;
480 b_normal_exp
= b
->normal_exp
;
481 a_fraction
= a
->fraction
.ll
;
482 b_fraction
= b
->fraction
.ll
;
484 diff
= a_normal_exp
- b_normal_exp
;
488 if (diff
< FRAC_NBITS
)
490 /* ??? This does shifts one bit at a time. Optimize. */
491 while (a_normal_exp
> b_normal_exp
)
496 while (b_normal_exp
> a_normal_exp
)
504 /* Somethings's up.. choose the biggest */
505 if (a_normal_exp
> b_normal_exp
)
507 b_normal_exp
= a_normal_exp
;
512 a_normal_exp
= b_normal_exp
;
518 if (a
->sign
!= b
->sign
)
522 tfraction
= -a_fraction
+ b_fraction
;
526 tfraction
= a_fraction
- b_fraction
;
531 tmp
->normal_exp
= a_normal_exp
;
532 tmp
->fraction
.ll
= tfraction
;
537 tmp
->normal_exp
= a_normal_exp
;
538 tmp
->fraction
.ll
= -tfraction
;
540 /* and renormalize it */
542 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
544 tmp
->fraction
.ll
<<= 1;
551 tmp
->normal_exp
= a_normal_exp
;
552 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
554 tmp
->class = CLASS_NUMBER
;
555 /* Now the fraction is added, we have to shift down to renormalize the
558 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
560 LSHIFT (tmp
->fraction
.ll
);
568 add (FLO_type arg_a
, FLO_type arg_b
)
574 FLO_union_type au
, bu
;
582 res
= _fpadd_parts (&a
, &b
, &tmp
);
588 sub (FLO_type arg_a
, FLO_type arg_b
)
594 FLO_union_type au
, bu
;
604 res
= _fpadd_parts (&a
, &b
, &tmp
);
608 #endif /* L_addsub_sf || L_addsub_df */
610 #if defined(L_mul_sf) || defined(L_mul_df)
611 static inline __attribute__ ((__always_inline__
)) fp_number_type
*
612 _fpmul_parts ( fp_number_type
* a
,
614 fp_number_type
* tmp
)
621 a
->sign
= a
->sign
!= b
->sign
;
626 b
->sign
= a
->sign
!= b
->sign
;
633 a
->sign
= a
->sign
!= b
->sign
;
642 b
->sign
= a
->sign
!= b
->sign
;
647 a
->sign
= a
->sign
!= b
->sign
;
652 b
->sign
= a
->sign
!= b
->sign
;
656 /* Calculate the mantissa by multiplying both numbers to get a
657 twice-as-wide number. */
659 #if defined(NO_DI_MODE)
661 fractype x
= a
->fraction
.ll
;
662 fractype ylow
= b
->fraction
.ll
;
666 /* ??? This does multiplies one bit at a time. Optimize. */
667 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
673 carry
= (low
+= ylow
) < ylow
;
674 high
+= yhigh
+ carry
;
686 /* Multiplying two USIs to get a UDI, we're safe. */
688 UDItype answer
= (UDItype
)a
->fraction
.ll
* (UDItype
)b
->fraction
.ll
;
690 high
= answer
>> BITS_PER_SI
;
694 /* fractype is DImode, but we need the result to be twice as wide.
695 Assuming a widening multiply from DImode to TImode is not
696 available, build one by hand. */
698 USItype nl
= a
->fraction
.ll
;
699 USItype nh
= a
->fraction
.ll
>> BITS_PER_SI
;
700 USItype ml
= b
->fraction
.ll
;
701 USItype mh
= b
->fraction
.ll
>> BITS_PER_SI
;
702 UDItype pp_ll
= (UDItype
) ml
* nl
;
703 UDItype pp_hl
= (UDItype
) mh
* nl
;
704 UDItype pp_lh
= (UDItype
) ml
* nh
;
705 UDItype pp_hh
= (UDItype
) mh
* nh
;
708 UDItype ps_hh__
= pp_hl
+ pp_lh
;
710 res2
+= (UDItype
)1 << BITS_PER_SI
;
711 pp_hl
= (UDItype
)(USItype
)ps_hh__
<< BITS_PER_SI
;
712 res0
= pp_ll
+ pp_hl
;
715 res2
+= (ps_hh__
>> BITS_PER_SI
) + pp_hh
;
722 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
723 tmp
->sign
= a
->sign
!= b
->sign
;
725 tmp
->normal_exp
+= 2; /* ??????????????? */
727 tmp
->normal_exp
+= 4; /* ??????????????? */
729 while (high
>= IMPLICIT_2
)
739 while (high
< IMPLICIT_1
)
748 /* rounding is tricky. if we only round if it won't make us round later. */
752 if (((high
& GARDMASK
) != GARDMSB
)
753 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
755 /* don't round, it gets done again later. */
763 if (!ROUND_TOWARDS_ZERO
&& (high
& GARDMASK
) == GARDMSB
)
765 if (high
& (1 << NGARDS
))
767 /* half way, so round to even */
768 high
+= GARDROUND
+ 1;
772 /* but we really weren't half way */
773 high
+= GARDROUND
+ 1;
776 tmp
->fraction
.ll
= high
;
777 tmp
->class = CLASS_NUMBER
;
782 multiply (FLO_type arg_a
, FLO_type arg_b
)
788 FLO_union_type au
, bu
;
796 res
= _fpmul_parts (&a
, &b
, &tmp
);
800 #endif /* L_mul_sf || L_mul_df */
802 #if defined(L_div_sf) || defined(L_div_df)
803 static inline __attribute__ ((__always_inline__
)) fp_number_type
*
804 _fpdiv_parts (fp_number_type
* a
,
809 fractype denominator
;
821 a
->sign
= a
->sign
^ b
->sign
;
823 if (isinf (a
) || iszero (a
))
825 if (a
->class == b
->class)
838 a
->class = CLASS_INFINITY
;
842 /* Calculate the mantissa by multiplying both 64bit numbers to get a
846 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
849 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
850 numerator
= a
->fraction
.ll
;
851 denominator
= b
->fraction
.ll
;
853 if (numerator
< denominator
)
855 /* Fraction will be less than 1.0 */
861 /* ??? Does divide one bit at a time. Optimize. */
864 if (numerator
>= denominator
)
867 numerator
-= denominator
;
873 if (!ROUND_TOWARDS_ZERO
&& (quotient
& GARDMASK
) == GARDMSB
)
875 if (quotient
& (1 << NGARDS
))
877 /* half way, so round to even */
878 quotient
+= GARDROUND
+ 1;
882 /* but we really weren't half way, more bits exist */
883 quotient
+= GARDROUND
+ 1;
887 a
->fraction
.ll
= quotient
;
893 divide (FLO_type arg_a
, FLO_type arg_b
)
898 FLO_union_type au
, bu
;
906 res
= _fpdiv_parts (&a
, &b
);
910 #endif /* L_div_sf || L_div_df */
912 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df)
913 /* according to the demo, fpcmp returns a comparison with 0... thus
920 __fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
923 /* either nan -> unordered. Must be checked outside of this routine. */
924 if (isnan (a
) && isnan (b
))
926 return 1; /* still unordered! */
930 if (isnan (a
) || isnan (b
))
932 return 1; /* how to indicate unordered compare? */
934 if (isinf (a
) && isinf (b
))
936 /* +inf > -inf, but +inf != +inf */
937 /* b \a| +inf(0)| -inf(1)
938 ______\+--------+--------
939 +inf(0)| a==b(0)| a<b(-1)
940 -------+--------+--------
941 -inf(1)| a>b(1) | a==b(0)
942 -------+--------+--------
943 So since unordered must be nonzero, just line up the columns...
945 return b
->sign
- a
->sign
;
947 /* but not both... */
950 return a
->sign
? -1 : 1;
954 return b
->sign
? 1 : -1;
956 if (iszero (a
) && iszero (b
))
962 return b
->sign
? 1 : -1;
966 return a
->sign
? -1 : 1;
968 /* now both are "normal". */
969 if (a
->sign
!= b
->sign
)
972 return a
->sign
? -1 : 1;
974 /* same sign; exponents? */
975 if (a
->normal_exp
> b
->normal_exp
)
977 return a
->sign
? -1 : 1;
979 if (a
->normal_exp
< b
->normal_exp
)
981 return a
->sign
? 1 : -1;
983 /* same exponents; check size. */
984 if (a
->fraction
.ll
> b
->fraction
.ll
)
986 return a
->sign
? -1 : 1;
988 if (a
->fraction
.ll
< b
->fraction
.ll
)
990 return a
->sign
? 1 : -1;
992 /* after all that, they're equal. */
997 #if defined(L_compare_sf) || defined(L_compare_df)
999 compare (FLO_type arg_a
, FLO_type arg_b
)
1003 FLO_union_type au
, bu
;
1011 return __fpcmp_parts (&a
, &b
);
1013 #endif /* L_compare_sf || L_compare_df */
1015 #ifndef US_SOFTWARE_GOFAST
1017 /* These should be optimized for their specific tasks someday. */
1019 #if defined(L_eq_sf) || defined(L_eq_df)
1021 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
1025 FLO_union_type au
, bu
;
1033 if (isnan (&a
) || isnan (&b
))
1034 return 1; /* false, truth == 0 */
1036 return __fpcmp_parts (&a
, &b
) ;
1038 #endif /* L_eq_sf || L_eq_df */
1040 #if defined(L_ne_sf) || defined(L_ne_df)
1042 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1046 FLO_union_type au
, bu
;
1054 if (isnan (&a
) || isnan (&b
))
1055 return 1; /* true, truth != 0 */
1057 return __fpcmp_parts (&a
, &b
) ;
1059 #endif /* L_ne_sf || L_ne_df */
1061 #if defined(L_gt_sf) || defined(L_gt_df)
1063 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1067 FLO_union_type au
, bu
;
1075 if (isnan (&a
) || isnan (&b
))
1076 return -1; /* false, truth > 0 */
1078 return __fpcmp_parts (&a
, &b
);
1080 #endif /* L_gt_sf || L_gt_df */
1082 #if defined(L_ge_sf) || defined(L_ge_df)
1084 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1088 FLO_union_type au
, bu
;
1096 if (isnan (&a
) || isnan (&b
))
1097 return -1; /* false, truth >= 0 */
1098 return __fpcmp_parts (&a
, &b
) ;
1100 #endif /* L_ge_sf || L_ge_df */
1102 #if defined(L_lt_sf) || defined(L_lt_df)
1104 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1108 FLO_union_type au
, bu
;
1116 if (isnan (&a
) || isnan (&b
))
1117 return 1; /* false, truth < 0 */
1119 return __fpcmp_parts (&a
, &b
);
1121 #endif /* L_lt_sf || L_lt_df */
1123 #if defined(L_le_sf) || defined(L_le_df)
1125 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1129 FLO_union_type au
, bu
;
1137 if (isnan (&a
) || isnan (&b
))
1138 return 1; /* false, truth <= 0 */
1140 return __fpcmp_parts (&a
, &b
) ;
1142 #endif /* L_le_sf || L_le_df */
1144 #endif /* ! US_SOFTWARE_GOFAST */
1146 #if defined(L_unord_sf) || defined(L_unord_df)
1148 _unord_f2 (FLO_type arg_a
, FLO_type arg_b
)
1152 FLO_union_type au
, bu
;
1160 return (isnan (&a
) || isnan (&b
));
1162 #endif /* L_unord_sf || L_unord_df */
1164 #if defined(L_si_to_sf) || defined(L_si_to_df)
1166 si_to_float (SItype arg_a
)
1170 in
.class = CLASS_NUMBER
;
1171 in
.sign
= arg_a
< 0;
1174 in
.class = CLASS_ZERO
;
1178 in
.normal_exp
= FRACBITS
+ NGARDS
;
1181 /* Special case for minint, since there is no +ve integer
1182 representation for it */
1183 if (arg_a
== (- MAX_SI_INT
- 1))
1185 return (FLO_type
)(- MAX_SI_INT
- 1);
1187 in
.fraction
.ll
= (-arg_a
);
1190 in
.fraction
.ll
= arg_a
;
1192 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1194 in
.fraction
.ll
<<= 1;
1198 return pack_d (&in
);
1200 #endif /* L_si_to_sf || L_si_to_df */
1202 #if defined(L_usi_to_sf) || defined(L_usi_to_df)
1204 usi_to_float (USItype arg_a
)
1211 in
.class = CLASS_ZERO
;
1215 in
.class = CLASS_NUMBER
;
1216 in
.normal_exp
= FRACBITS
+ NGARDS
;
1217 in
.fraction
.ll
= arg_a
;
1219 while (in
.fraction
.ll
> (1LL << (FRACBITS
+ NGARDS
)))
1221 in
.fraction
.ll
>>= 1;
1224 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1226 in
.fraction
.ll
<<= 1;
1230 return pack_d (&in
);
1234 #if defined(L_sf_to_si) || defined(L_df_to_si)
1236 float_to_si (FLO_type arg_a
)
1249 /* get reasonable MAX_SI_INT... */
1251 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1252 /* it is a number, but a small one */
1253 if (a
.normal_exp
< 0)
1255 if (a
.normal_exp
> BITS_PER_SI
- 2)
1256 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1257 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1258 return a
.sign
? (-tmp
) : (tmp
);
1260 #endif /* L_sf_to_si || L_df_to_si */
1262 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
1263 #ifdef US_SOFTWARE_GOFAST
1264 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1265 we also define them for GOFAST because the ones in libgcc2.c have the
1266 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1267 out of libgcc2.c. We can't define these here if not GOFAST because then
1268 there'd be duplicate copies. */
1271 float_to_usi (FLO_type arg_a
)
1283 /* it is a negative number */
1286 /* get reasonable MAX_USI_INT... */
1289 /* it is a number, but a small one */
1290 if (a
.normal_exp
< 0)
1292 if (a
.normal_exp
> BITS_PER_SI
- 1)
1294 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1295 return a
.fraction
.ll
<< (a
.normal_exp
- (FRACBITS
+ NGARDS
));
1297 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1299 #endif /* US_SOFTWARE_GOFAST */
1300 #endif /* L_sf_to_usi || L_df_to_usi */
1302 #if defined(L_negate_sf) || defined(L_negate_df)
1304 negate (FLO_type arg_a
)
1315 #endif /* L_negate_sf || L_negate_df */
1319 #if defined(L_make_sf)
1321 __make_fp(fp_class_type
class,
1330 in
.normal_exp
= exp
;
1331 in
.fraction
.ll
= frac
;
1332 return pack_d (&in
);
1334 #endif /* L_make_sf */
1338 /* This enables one to build an fp library that supports float but not double.
1339 Otherwise, we would get an undefined reference to __make_dp.
1340 This is needed for some 8-bit ports that can't handle well values that
1341 are 8-bytes in size, so we just don't support double for them at all. */
1343 #if defined(L_sf_to_df)
1345 sf_to_df (SFtype arg_a
)
1351 unpack_d (&au
, &in
);
1353 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1354 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1356 #endif /* L_sf_to_df */
1358 #endif /* ! FLOAT_ONLY */
1363 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1365 #if defined(L_make_df)
1367 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1373 in
.normal_exp
= exp
;
1374 in
.fraction
.ll
= frac
;
1375 return pack_d (&in
);
1377 #endif /* L_make_df */
1379 #if defined(L_df_to_sf)
1381 df_to_sf (DFtype arg_a
)
1388 unpack_d (&au
, &in
);
1390 sffrac
= in
.fraction
.ll
>> F_D_BITOFF
;
1392 /* We set the lowest guard bit in SFFRAC if we discarded any non
1394 if ((in
.fraction
.ll
& (((USItype
) 1 << F_D_BITOFF
) - 1)) != 0)
1397 return __make_fp (in
.class, in
.sign
, in
.normal_exp
, sffrac
);
1399 #endif /* L_df_to_sf */
1401 #endif /* ! FLOAT */
1402 #endif /* !EXTENDED_FLOAT_STUBS */