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
5 /* Copyright (C) 1994-2018 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* As a special exception, if you link this library with other files,
21 some of which are compiled with GCC, to produce an executable,
22 this library does not by itself cause the resulting executable
23 to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why
25 the executable file might be covered by the GNU General Public License. */
27 /* This implements IEEE 754 format arithmetic, but does not provide a
28 mechanism for setting the rounding mode, or for generating or handling
31 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
32 Wilson, all of Cygnus Support. */
34 /* The intended way to use this file is to make two copies, add `#define FLOAT'
35 to one copy, then compile both copies and add them to libgcc.a. */
37 /* The following macros can be defined to change the behaviour of this file:
38 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
39 defined, then this file implements a `double', aka DFmode, fp library.
40 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
41 don't include float->double conversion which requires the double library.
42 This is useful only for machines which can't support doubles, e.g. some
44 CMPtype: Specify the type that floating point compares should return.
45 This defaults to SItype, aka int.
46 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
47 US Software goFast library. If this is not defined, the entry points use
48 the same names as libgcc1.c.
49 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
50 two integers to the FLO_union_type.
51 NO_NANS: Disable nan and infinity handling
52 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
56 typedef SFtype
__attribute__ ((mode (SF
)));
59 typedef DFtype
__attribute__ ((mode (DF
)));
63 typedef int HItype
__attribute__ ((mode (HI
)));
66 typedef int SItype
__attribute__ ((mode (SI
)));
69 typedef int DItype
__attribute__ ((mode (DI
)));
72 /* The type of the result of a fp compare */
74 #define CMPtype SItype
78 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
81 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
84 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
87 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
88 #define MAX_USI_INT ((USItype) ~0)
97 # define GARDROUND 0x3f
98 # define GARDMASK 0x7f
103 # define EXPMAX (0xff)
104 # define QUIET_NAN 0x100000L
105 # define FRAC_NBITS 32
106 # define FRACHIGH 0x80000000L
107 # define FRACHIGH2 0xc0000000L
108 typedef USItype fractype
;
109 typedef UHItype halffractype
;
110 typedef SFtype FLO_type
;
111 typedef SItype intfrac
;
114 # define PREFIXFPDP dp
115 # define PREFIXSFDF df
117 # define GARDROUND 0x7f
118 # define GARDMASK 0xff
119 # define GARDMSB 0x80
121 # define EXPBIAS 1023
123 # define EXPMAX (0x7ff)
124 # define QUIET_NAN 0x8000000000000LL
125 # define FRAC_NBITS 64
126 # define FRACHIGH 0x8000000000000000LL
127 # define FRACHIGH2 0xc000000000000000LL
128 typedef UDItype fractype
;
129 typedef USItype halffractype
;
130 typedef DFtype FLO_type
;
131 typedef DItype intfrac
;
134 #ifdef US_SOFTWARE_GOFAST
138 # define multiply fpmul
139 # define divide fpdiv
140 # define compare fpcmp
141 # define si_to_float sitofp
142 # define float_to_si fptosi
143 # define float_to_usi fptoui
144 # define negate __negsf2
145 # define sf_to_df fptodp
146 # define dptofp dptofp
150 # define multiply dpmul
151 # define divide dpdiv
152 # define compare dpcmp
153 # define si_to_float litodp
154 # define float_to_si dptoli
155 # define float_to_usi dptoul
156 # define negate __negdf2
157 # define df_to_sf dptofp
161 # define add __addsf3
162 # define sub __subsf3
163 # define multiply __mulsf3
164 # define divide __divsf3
165 # define compare __cmpsf2
166 # define _eq_f2 __eqsf2
167 # define _ne_f2 __nesf2
168 # define _gt_f2 __gtsf2
169 # define _ge_f2 __gesf2
170 # define _lt_f2 __ltsf2
171 # define _le_f2 __lesf2
172 # define si_to_float __floatsisf
173 # define float_to_si __fixsfsi
174 # define float_to_usi __fixunssfsi
175 # define negate __negsf2
176 # define sf_to_df __extendsfdf2
178 # define add __adddf3
179 # define sub __subdf3
180 # define multiply __muldf3
181 # define divide __divdf3
182 # define compare __cmpdf2
183 # define _eq_f2 __eqdf2
184 # define _ne_f2 __nedf2
185 # define _gt_f2 __gtdf2
186 # define _ge_f2 __gedf2
187 # define _lt_f2 __ltdf2
188 # define _le_f2 __ledf2
189 # define si_to_float __floatsidf
190 # define float_to_si __fixdfsi
191 # define float_to_usi __fixunsdfsi
192 # define negate __negdf2
193 # define df_to_sf __truncdfsf2
199 #define INLINE __inline__
202 /* Preserve the sticky-bit when shifting fractions to the right. */
203 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
205 /* numeric parameters */
206 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
207 of a float and of a double. Assumes there are only two float types.
208 (double::FRAC_BITS+double::NGARGS-(float::FRAC_BITS-float::NGARDS))
210 #define F_D_BITOFF (52+8-(23+7))
213 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
214 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
215 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
250 #ifdef _DEBUG_BITFLOAT
255 #ifndef FLOAT_BIT_ORDER_MISMATCH
256 unsigned int sign
:1 __attribute__ ((packed
));
257 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
258 fractype fraction
:FRACBITS
__attribute__ ((packed
));
260 fractype fraction
:FRACBITS
__attribute__ ((packed
));
261 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
262 unsigned int sign
:1 __attribute__ ((packed
));
272 /* IEEE "special" number predicates */
282 static fp_number_type
*
285 static fp_number_type thenan
;
292 isnan ( fp_number_type
* x
)
294 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
299 isinf ( fp_number_type
* x
)
301 return x
->class == CLASS_INFINITY
;
308 iszero ( fp_number_type
* x
)
310 return x
->class == CLASS_ZERO
;
315 flip_sign ( fp_number_type
* x
)
321 pack_d ( fp_number_type
* src
)
324 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
326 dst
.bits
.sign
= src
->sign
;
330 dst
.bits
.exp
= EXPMAX
;
331 dst
.bits
.fraction
= src
->fraction
.ll
;
332 if (src
->class == CLASS_QNAN
|| 1)
334 dst
.bits
.fraction
|= QUIET_NAN
;
337 else if (isinf (src
))
339 dst
.bits
.exp
= EXPMAX
;
340 dst
.bits
.fraction
= 0;
342 else if (iszero (src
))
345 dst
.bits
.fraction
= 0;
347 else if (fraction
== 0)
353 if (src
->normal_exp
< NORMAL_EXPMIN
)
355 /* This number's exponent is too low to fit into the bits
356 available in the number, so we'll store 0 in the exponent and
357 shift the fraction to the right to make up for it. */
359 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
363 if (shift
> FRAC_NBITS
- NGARDS
)
365 /* No point shifting, since it's more that 64 out. */
370 /* Shift by the value */
374 dst
.bits
.fraction
= fraction
;
376 else if (src
->normal_exp
> EXPBIAS
)
378 dst
.bits
.exp
= EXPMAX
;
379 dst
.bits
.fraction
= 0;
383 dst
.bits
.exp
= src
->normal_exp
+ EXPBIAS
;
384 /* IF the gard bits are the all zero, but the first, then we're
385 half way between two numbers, choose the one which makes the
386 lsb of the answer 0. */
387 if ((fraction
& GARDMASK
) == GARDMSB
)
389 if (fraction
& (1 << NGARDS
))
390 fraction
+= GARDROUND
+ 1;
394 /* Add a one to the guards to round up */
395 fraction
+= GARDROUND
;
397 if (fraction
>= IMPLICIT_2
)
403 dst
.bits
.fraction
= fraction
;
410 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
412 fractype fraction
= src
->bits
.fraction
;
414 dst
->sign
= src
->bits
.sign
;
415 if (src
->bits
.exp
== 0)
417 /* Hmm. Looks like 0 */
420 /* tastes like zero */
421 dst
->class = CLASS_ZERO
;
425 /* Zero exponent with non zero fraction - it's denormalized,
426 so there isn't a leading implicit one - we'll shift it so
428 dst
->normal_exp
= src
->bits
.exp
- EXPBIAS
+ 1;
431 dst
->class = CLASS_NUMBER
;
433 while (fraction
< IMPLICIT_1
)
439 dst
->fraction
.ll
= fraction
;
442 else if (src
->bits
.exp
== EXPMAX
)
447 /* Attached to a zero fraction - means infinity */
448 dst
->class = CLASS_INFINITY
;
452 /* Non zero fraction, means nan */
455 dst
->class = CLASS_SNAN
;
459 dst
->class = CLASS_QNAN
;
461 /* Keep the fraction part as the nan number */
462 dst
->fraction
.ll
= fraction
;
467 /* Nothing strange about this number */
468 dst
->normal_exp
= src
->bits
.exp
- EXPBIAS
;
469 dst
->class = CLASS_NUMBER
;
470 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
474 static fp_number_type
*
475 _fpadd_parts (fp_number_type
* a
,
477 fp_number_type
* tmp
)
481 /* Put commonly used fields in local variables. */
497 /* Adding infinities with opposite signs yields a NaN. */
498 if (isinf (b
) && a
->sign
!= b
->sign
)
515 /* Got two numbers. shift the smaller and increment the exponent till
520 a_normal_exp
= a
->normal_exp
;
521 b_normal_exp
= b
->normal_exp
;
522 a_fraction
= a
->fraction
.ll
;
523 b_fraction
= b
->fraction
.ll
;
525 diff
= a_normal_exp
- b_normal_exp
;
529 if (diff
< FRAC_NBITS
)
531 /* ??? This does shifts one bit at a time. Optimize. */
532 while (a_normal_exp
> b_normal_exp
)
537 while (b_normal_exp
> a_normal_exp
)
545 /* Somethings's up.. choose the biggest */
546 if (a_normal_exp
> b_normal_exp
)
548 b_normal_exp
= a_normal_exp
;
553 a_normal_exp
= b_normal_exp
;
559 if (a
->sign
!= b
->sign
)
563 tfraction
= -a_fraction
+ b_fraction
;
567 tfraction
= a_fraction
- b_fraction
;
572 tmp
->normal_exp
= a_normal_exp
;
573 tmp
->fraction
.ll
= tfraction
;
578 tmp
->normal_exp
= a_normal_exp
;
579 tmp
->fraction
.ll
= -tfraction
;
581 /* and renormalize it */
583 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
585 tmp
->fraction
.ll
<<= 1;
592 tmp
->normal_exp
= a_normal_exp
;
593 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
595 tmp
->class = CLASS_NUMBER
;
596 /* Now the fraction is added, we have to shift down to renormalize the
599 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
601 LSHIFT (tmp
->fraction
.ll
);
609 add (FLO_type arg_a
, FLO_type arg_b
)
616 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
617 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
619 res
= _fpadd_parts (&a
, &b
, &tmp
);
625 sub (FLO_type arg_a
, FLO_type arg_b
)
632 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
633 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
637 res
= _fpadd_parts (&a
, &b
, &tmp
);
642 static fp_number_type
*
643 _fpmul_parts ( fp_number_type
* a
,
645 fp_number_type
* tmp
)
652 a
->sign
= a
->sign
!= b
->sign
;
657 b
->sign
= a
->sign
!= b
->sign
;
664 a
->sign
= a
->sign
!= b
->sign
;
673 b
->sign
= a
->sign
!= b
->sign
;
678 a
->sign
= a
->sign
!= b
->sign
;
683 b
->sign
= a
->sign
!= b
->sign
;
687 /* Calculate the mantissa by multiplying both 64bit numbers to get a
690 fractype x
= a
->fraction
.ll
;
691 fractype ylow
= b
->fraction
.ll
;
695 #if defined(NO_DI_MODE)
697 /* ??? This does multiplies one bit at a time. Optimize. */
698 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
704 carry
= (low
+= ylow
) < ylow
;
705 high
+= yhigh
+ carry
;
718 /* Multiplying two 32 bit numbers to get a 64 bit number on
719 a machine with DI, so we're safe */
721 DItype answer
= (DItype
)(a
->fraction
.ll
) * (DItype
)(b
->fraction
.ll
);
727 /* Doing a 64*64 to 128 */
729 UDItype nl
= a
->fraction
.ll
& 0xffffffff;
730 UDItype nh
= a
->fraction
.ll
>> 32;
731 UDItype ml
= b
->fraction
.ll
& 0xffffffff;
732 UDItype mh
= b
->fraction
.ll
>>32;
733 UDItype pp_ll
= ml
* nl
;
734 UDItype pp_hl
= mh
* nl
;
735 UDItype pp_lh
= ml
* nh
;
736 UDItype pp_hh
= mh
* nh
;
739 UDItype ps_hh__
= pp_hl
+ pp_lh
;
741 res2
+= 0x100000000LL
;
742 pp_hl
= (ps_hh__
<< 32) & 0xffffffff00000000LL
;
743 res0
= pp_ll
+ pp_hl
;
746 res2
+= ((ps_hh__
>> 32) & 0xffffffffL
) + pp_hh
;
753 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
754 tmp
->sign
= a
->sign
!= b
->sign
;
756 tmp
->normal_exp
+= 2; /* ??????????????? */
758 tmp
->normal_exp
+= 4; /* ??????????????? */
760 while (high
>= IMPLICIT_2
)
770 while (high
< IMPLICIT_1
)
779 /* rounding is tricky. if we only round if it won't make us round later. */
783 if (((high
& GARDMASK
) != GARDMSB
)
784 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
786 /* don't round, it gets done again later. */
794 if ((high
& GARDMASK
) == GARDMSB
)
796 if (high
& (1 << NGARDS
))
798 /* half way, so round to even */
799 high
+= GARDROUND
+ 1;
803 /* but we really weren't half way */
804 high
+= GARDROUND
+ 1;
807 tmp
->fraction
.ll
= high
;
808 tmp
->class = CLASS_NUMBER
;
813 multiply (FLO_type arg_a
, FLO_type arg_b
)
820 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
821 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
823 res
= _fpmul_parts (&a
, &b
, &tmp
);
828 static fp_number_type
*
829 _fpdiv_parts (fp_number_type
* a
,
831 fp_number_type
* tmp
)
835 fractype r0
, r1
, y0
, y1
, bit
;
838 fractype denominator
;
850 if (isinf (a
) || iszero (a
))
852 if (a
->class == b
->class)
856 a
->sign
= a
->sign
^ b
->sign
;
866 a
->class = CLASS_INFINITY
;
870 /* Calculate the mantissa by multiplying both 64bit numbers to get a
874 intfrac d0
, d1
; /* weren't unsigned before ??? */
877 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
880 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
881 numerator
= a
->fraction
.ll
;
882 denominator
= b
->fraction
.ll
;
884 if (numerator
< denominator
)
886 /* Fraction will be less than 1.0 */
892 /* ??? Does divide one bit at a time. Optimize. */
895 if (numerator
>= denominator
)
898 numerator
-= denominator
;
904 if ((quotient
& GARDMASK
) == GARDMSB
)
906 if (quotient
& (1 << NGARDS
))
908 /* half way, so round to even */
909 quotient
+= GARDROUND
+ 1;
913 /* but we really weren't half way, more bits exist */
914 quotient
+= GARDROUND
+ 1;
918 a
->fraction
.ll
= quotient
;
924 divide (FLO_type arg_a
, FLO_type arg_b
)
931 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
932 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
934 res
= _fpdiv_parts (&a
, &b
, &tmp
);
939 /* according to the demo, fpcmp returns a comparison with 0... thus
946 _fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
949 /* either nan -> unordered. Must be checked outside of this routine. */
950 if (isnan (a
) && isnan (b
))
952 return 1; /* still unordered! */
956 if (isnan (a
) || isnan (b
))
958 return 1; /* how to indicate unordered compare? */
960 if (isinf (a
) && isinf (b
))
962 /* +inf > -inf, but +inf != +inf */
963 /* b \a| +inf(0)| -inf(1)
964 ______\+--------+--------
965 +inf(0)| a==b(0)| a<b(-1)
966 -------+--------+--------
967 -inf(1)| a>b(1) | a==b(0)
968 -------+--------+--------
969 So since unordered must be non zero, just line up the columns...
971 return b
->sign
- a
->sign
;
973 /* but not both... */
976 return a
->sign
? -1 : 1;
980 return b
->sign
? 1 : -1;
982 if (iszero (a
) && iszero (b
))
988 return b
->sign
? 1 : -1;
992 return a
->sign
? -1 : 1;
994 /* now both are "normal". */
995 if (a
->sign
!= b
->sign
)
998 return a
->sign
? -1 : 1;
1000 /* same sign; exponents? */
1001 if (a
->normal_exp
> b
->normal_exp
)
1003 return a
->sign
? -1 : 1;
1005 if (a
->normal_exp
< b
->normal_exp
)
1007 return a
->sign
? 1 : -1;
1009 /* same exponents; check size. */
1010 if (a
->fraction
.ll
> b
->fraction
.ll
)
1012 return a
->sign
? -1 : 1;
1014 if (a
->fraction
.ll
< b
->fraction
.ll
)
1016 return a
->sign
? 1 : -1;
1018 /* after all that, they're equal. */
1023 compare (FLO_type arg_a
, FLO_type arg_b
)
1028 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1029 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1031 return _fpcmp_parts (&a
, &b
);
1034 #ifndef US_SOFTWARE_GOFAST
1036 /* These should be optimized for their specific tasks someday. */
1039 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
1044 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1045 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1047 if (isnan (&a
) || isnan (&b
))
1048 return 1; /* false, truth == 0 */
1050 return _fpcmp_parts (&a
, &b
) ;
1054 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1059 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1060 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1062 if (isnan (&a
) || isnan (&b
))
1063 return 1; /* true, truth != 0 */
1065 return _fpcmp_parts (&a
, &b
) ;
1069 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1074 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1075 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1077 if (isnan (&a
) || isnan (&b
))
1078 return -1; /* false, truth > 0 */
1080 return _fpcmp_parts (&a
, &b
);
1084 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1089 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1090 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1092 if (isnan (&a
) || isnan (&b
))
1093 return -1; /* false, truth >= 0 */
1094 return _fpcmp_parts (&a
, &b
) ;
1098 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1103 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1104 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1106 if (isnan (&a
) || isnan (&b
))
1107 return 1; /* false, truth < 0 */
1109 return _fpcmp_parts (&a
, &b
);
1113 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1118 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1119 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1121 if (isnan (&a
) || isnan (&b
))
1122 return 1; /* false, truth <= 0 */
1124 return _fpcmp_parts (&a
, &b
) ;
1127 #endif /* ! US_SOFTWARE_GOFAST */
1130 si_to_float (SItype arg_a
)
1134 in
.class = CLASS_NUMBER
;
1135 in
.sign
= arg_a
< 0;
1138 in
.class = CLASS_ZERO
;
1142 in
.normal_exp
= FRACBITS
+ NGARDS
;
1145 /* Special case for minint, since there is no +ve integer
1146 representation for it */
1147 if (arg_a
== 0x80000000)
1149 return -2147483648.0;
1151 in
.fraction
.ll
= (-arg_a
);
1154 in
.fraction
.ll
= arg_a
;
1156 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1158 in
.fraction
.ll
<<= 1;
1162 return pack_d (&in
);
1166 float_to_si (FLO_type arg_a
)
1171 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1176 /* get reasonable MAX_SI_INT... */
1178 return a
.sign
? MAX_SI_INT
: (-MAX_SI_INT
)-1;
1179 /* it is a number, but a small one */
1180 if (a
.normal_exp
< 0)
1182 if (a
.normal_exp
> 30)
1183 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1184 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1185 return a
.sign
? (-tmp
) : (tmp
);
1188 #ifdef US_SOFTWARE_GOFAST
1189 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1190 we also define them for GOFAST because the ones in libgcc2.c have the
1191 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1192 out of libgcc2.c. We can't define these here if not GOFAST because then
1193 there'd be duplicate copies. */
1196 float_to_usi (FLO_type arg_a
)
1200 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1205 /* get reasonable MAX_USI_INT... */
1207 return a
.sign
? MAX_USI_INT
: 0;
1208 /* it is a negative number */
1211 /* it is a number, but a small one */
1212 if (a
.normal_exp
< 0)
1214 if (a
.normal_exp
> 31)
1216 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1217 return a
.fraction
.ll
<< ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1219 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1224 negate (FLO_type arg_a
)
1228 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1236 __make_fp(fp_class_type
class,
1245 in
.normal_exp
= exp
;
1246 in
.fraction
.ll
= frac
;
1247 return pack_d (&in
);
1252 /* This enables one to build an fp library that supports float but not double.
1253 Otherwise, we would get an undefined reference to __make_dp.
1254 This is needed for some 8-bit ports that can't handle well values that
1255 are 8-bytes in size, so we just don't support double for them at all. */
1257 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype frac
);
1260 sf_to_df (SFtype arg_a
)
1264 unpack_d ((FLO_union_type
*) & arg_a
, &in
);
1265 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1266 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1274 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1277 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1283 in
.normal_exp
= exp
;
1284 in
.fraction
.ll
= frac
;
1285 return pack_d (&in
);
1289 df_to_sf (DFtype arg_a
)
1293 unpack_d ((FLO_union_type
*) & arg_a
, &in
);
1294 return __make_fp (in
.class, in
.sign
, in
.normal_exp
,
1295 in
.fraction
.ll
>> F_D_BITOFF
);