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, 2007, 2008, 2009, 2010, 2011
6 Free Software Foundation, Inc.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
28 /* This implements IEEE 754 format arithmetic, but does not provide a
29 mechanism for setting the rounding mode, or for generating or handling
32 The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
33 Wilson, all of Cygnus Support. */
35 /* The intended way to use this file is to make two copies, add `#define FLOAT'
36 to one copy, then compile both copies and add them to libgcc.a. */
38 /* The following macros can be defined to change the behaviour of this file:
39 FLOAT: Implement a `float', aka SFmode, fp library. If this is not
40 defined, then this file implements a `double', aka DFmode, fp library.
41 FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
42 don't include float->double conversion which requires the double library.
43 This is useful only for machines which can't support doubles, e.g. some
45 CMPtype: Specify the type that floating point compares should return.
46 This defaults to SItype, aka int.
47 US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
48 US Software goFast library. If this is not defined, the entry points use
49 the same names as libgcc1.c.
50 _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
51 two integers to the FLO_union_type.
52 NO_NANS: Disable nan and infinity handling
53 SMALL_MACHINE: Useful when operations on QIs and HIs are faster
57 typedef SFtype
__attribute__ ((mode (SF
)));
60 typedef DFtype
__attribute__ ((mode (DF
)));
64 typedef int HItype
__attribute__ ((mode (HI
)));
67 typedef int SItype
__attribute__ ((mode (SI
)));
70 typedef int DItype
__attribute__ ((mode (DI
)));
73 /* The type of the result of a fp compare */
75 #define CMPtype SItype
79 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
82 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
85 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
88 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
89 #define MAX_USI_INT ((USItype) ~0)
98 # define GARDROUND 0x3f
99 # define GARDMASK 0x7f
100 # define GARDMSB 0x40
104 # define EXPMAX (0xff)
105 # define QUIET_NAN 0x100000L
106 # define FRAC_NBITS 32
107 # define FRACHIGH 0x80000000L
108 # define FRACHIGH2 0xc0000000L
109 typedef USItype fractype
;
110 typedef UHItype halffractype
;
111 typedef SFtype FLO_type
;
112 typedef SItype intfrac
;
115 # define PREFIXFPDP dp
116 # define PREFIXSFDF df
118 # define GARDROUND 0x7f
119 # define GARDMASK 0xff
120 # define GARDMSB 0x80
122 # define EXPBIAS 1023
124 # define EXPMAX (0x7ff)
125 # define QUIET_NAN 0x8000000000000LL
126 # define FRAC_NBITS 64
127 # define FRACHIGH 0x8000000000000000LL
128 # define FRACHIGH2 0xc000000000000000LL
129 typedef UDItype fractype
;
130 typedef USItype halffractype
;
131 typedef DFtype FLO_type
;
132 typedef DItype intfrac
;
135 #ifdef US_SOFTWARE_GOFAST
139 # define multiply fpmul
140 # define divide fpdiv
141 # define compare fpcmp
142 # define si_to_float sitofp
143 # define float_to_si fptosi
144 # define float_to_usi fptoui
145 # define negate __negsf2
146 # define sf_to_df fptodp
147 # define dptofp dptofp
151 # define multiply dpmul
152 # define divide dpdiv
153 # define compare dpcmp
154 # define si_to_float litodp
155 # define float_to_si dptoli
156 # define float_to_usi dptoul
157 # define negate __negdf2
158 # define df_to_sf dptofp
162 # define add __addsf3
163 # define sub __subsf3
164 # define multiply __mulsf3
165 # define divide __divsf3
166 # define compare __cmpsf2
167 # define _eq_f2 __eqsf2
168 # define _ne_f2 __nesf2
169 # define _gt_f2 __gtsf2
170 # define _ge_f2 __gesf2
171 # define _lt_f2 __ltsf2
172 # define _le_f2 __lesf2
173 # define si_to_float __floatsisf
174 # define float_to_si __fixsfsi
175 # define float_to_usi __fixunssfsi
176 # define negate __negsf2
177 # define sf_to_df __extendsfdf2
179 # define add __adddf3
180 # define sub __subdf3
181 # define multiply __muldf3
182 # define divide __divdf3
183 # define compare __cmpdf2
184 # define _eq_f2 __eqdf2
185 # define _ne_f2 __nedf2
186 # define _gt_f2 __gtdf2
187 # define _ge_f2 __gedf2
188 # define _lt_f2 __ltdf2
189 # define _le_f2 __ledf2
190 # define si_to_float __floatsidf
191 # define float_to_si __fixdfsi
192 # define float_to_usi __fixunsdfsi
193 # define negate __negdf2
194 # define df_to_sf __truncdfsf2
200 #define INLINE __inline__
203 /* Preserve the sticky-bit when shifting fractions to the right. */
204 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
206 /* numeric parameters */
207 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
208 of a float and of a double. Assumes there are only two float types.
209 (double::FRAC_BITS+double::NGARGS-(float::FRAC_BITS-float::NGARDS))
211 #define F_D_BITOFF (52+8-(23+7))
214 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
215 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
216 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
251 #ifdef _DEBUG_BITFLOAT
256 #ifndef FLOAT_BIT_ORDER_MISMATCH
257 unsigned int sign
:1 __attribute__ ((packed
));
258 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
259 fractype fraction
:FRACBITS
__attribute__ ((packed
));
261 fractype fraction
:FRACBITS
__attribute__ ((packed
));
262 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
263 unsigned int sign
:1 __attribute__ ((packed
));
273 /* IEEE "special" number predicates */
283 static fp_number_type
*
286 static fp_number_type thenan
;
293 isnan ( fp_number_type
* x
)
295 return x
->class == CLASS_SNAN
|| x
->class == CLASS_QNAN
;
300 isinf ( fp_number_type
* x
)
302 return x
->class == CLASS_INFINITY
;
309 iszero ( fp_number_type
* x
)
311 return x
->class == CLASS_ZERO
;
316 flip_sign ( fp_number_type
* x
)
322 pack_d ( fp_number_type
* src
)
325 fractype fraction
= src
->fraction
.ll
; /* wasn't unsigned before? */
327 dst
.bits
.sign
= src
->sign
;
331 dst
.bits
.exp
= EXPMAX
;
332 dst
.bits
.fraction
= src
->fraction
.ll
;
333 if (src
->class == CLASS_QNAN
|| 1)
335 dst
.bits
.fraction
|= QUIET_NAN
;
338 else if (isinf (src
))
340 dst
.bits
.exp
= EXPMAX
;
341 dst
.bits
.fraction
= 0;
343 else if (iszero (src
))
346 dst
.bits
.fraction
= 0;
348 else if (fraction
== 0)
354 if (src
->normal_exp
< NORMAL_EXPMIN
)
356 /* This number's exponent is too low to fit into the bits
357 available in the number, so we'll store 0 in the exponent and
358 shift the fraction to the right to make up for it. */
360 int shift
= NORMAL_EXPMIN
- src
->normal_exp
;
364 if (shift
> FRAC_NBITS
- NGARDS
)
366 /* No point shifting, since it's more that 64 out. */
371 /* Shift by the value */
375 dst
.bits
.fraction
= fraction
;
377 else if (src
->normal_exp
> EXPBIAS
)
379 dst
.bits
.exp
= EXPMAX
;
380 dst
.bits
.fraction
= 0;
384 dst
.bits
.exp
= src
->normal_exp
+ EXPBIAS
;
385 /* IF the gard bits are the all zero, but the first, then we're
386 half way between two numbers, choose the one which makes the
387 lsb of the answer 0. */
388 if ((fraction
& GARDMASK
) == GARDMSB
)
390 if (fraction
& (1 << NGARDS
))
391 fraction
+= GARDROUND
+ 1;
395 /* Add a one to the guards to round up */
396 fraction
+= GARDROUND
;
398 if (fraction
>= IMPLICIT_2
)
404 dst
.bits
.fraction
= fraction
;
411 unpack_d (FLO_union_type
* src
, fp_number_type
* dst
)
413 fractype fraction
= src
->bits
.fraction
;
415 dst
->sign
= src
->bits
.sign
;
416 if (src
->bits
.exp
== 0)
418 /* Hmm. Looks like 0 */
421 /* tastes like zero */
422 dst
->class = CLASS_ZERO
;
426 /* Zero exponent with non zero fraction - it's denormalized,
427 so there isn't a leading implicit one - we'll shift it so
429 dst
->normal_exp
= src
->bits
.exp
- EXPBIAS
+ 1;
432 dst
->class = CLASS_NUMBER
;
434 while (fraction
< IMPLICIT_1
)
440 dst
->fraction
.ll
= fraction
;
443 else if (src
->bits
.exp
== EXPMAX
)
448 /* Attached to a zero fraction - means infinity */
449 dst
->class = CLASS_INFINITY
;
453 /* Non zero fraction, means nan */
456 dst
->class = CLASS_SNAN
;
460 dst
->class = CLASS_QNAN
;
462 /* Keep the fraction part as the nan number */
463 dst
->fraction
.ll
= fraction
;
468 /* Nothing strange about this number */
469 dst
->normal_exp
= src
->bits
.exp
- EXPBIAS
;
470 dst
->class = CLASS_NUMBER
;
471 dst
->fraction
.ll
= (fraction
<< NGARDS
) | IMPLICIT_1
;
475 static fp_number_type
*
476 _fpadd_parts (fp_number_type
* a
,
478 fp_number_type
* tmp
)
482 /* Put commonly used fields in local variables. */
498 /* Adding infinities with opposite signs yields a NaN. */
499 if (isinf (b
) && a
->sign
!= b
->sign
)
516 /* Got two numbers. shift the smaller and increment the exponent till
521 a_normal_exp
= a
->normal_exp
;
522 b_normal_exp
= b
->normal_exp
;
523 a_fraction
= a
->fraction
.ll
;
524 b_fraction
= b
->fraction
.ll
;
526 diff
= a_normal_exp
- b_normal_exp
;
530 if (diff
< FRAC_NBITS
)
532 /* ??? This does shifts one bit at a time. Optimize. */
533 while (a_normal_exp
> b_normal_exp
)
538 while (b_normal_exp
> a_normal_exp
)
546 /* Somethings's up.. choose the biggest */
547 if (a_normal_exp
> b_normal_exp
)
549 b_normal_exp
= a_normal_exp
;
554 a_normal_exp
= b_normal_exp
;
560 if (a
->sign
!= b
->sign
)
564 tfraction
= -a_fraction
+ b_fraction
;
568 tfraction
= a_fraction
- b_fraction
;
573 tmp
->normal_exp
= a_normal_exp
;
574 tmp
->fraction
.ll
= tfraction
;
579 tmp
->normal_exp
= a_normal_exp
;
580 tmp
->fraction
.ll
= -tfraction
;
582 /* and renormalize it */
584 while (tmp
->fraction
.ll
< IMPLICIT_1
&& tmp
->fraction
.ll
)
586 tmp
->fraction
.ll
<<= 1;
593 tmp
->normal_exp
= a_normal_exp
;
594 tmp
->fraction
.ll
= a_fraction
+ b_fraction
;
596 tmp
->class = CLASS_NUMBER
;
597 /* Now the fraction is added, we have to shift down to renormalize the
600 if (tmp
->fraction
.ll
>= IMPLICIT_2
)
602 LSHIFT (tmp
->fraction
.ll
);
610 add (FLO_type arg_a
, FLO_type arg_b
)
617 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
618 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
620 res
= _fpadd_parts (&a
, &b
, &tmp
);
626 sub (FLO_type arg_a
, FLO_type arg_b
)
633 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
634 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
638 res
= _fpadd_parts (&a
, &b
, &tmp
);
643 static fp_number_type
*
644 _fpmul_parts ( fp_number_type
* a
,
646 fp_number_type
* tmp
)
653 a
->sign
= a
->sign
!= b
->sign
;
658 b
->sign
= a
->sign
!= b
->sign
;
665 a
->sign
= a
->sign
!= b
->sign
;
674 b
->sign
= a
->sign
!= b
->sign
;
679 a
->sign
= a
->sign
!= b
->sign
;
684 b
->sign
= a
->sign
!= b
->sign
;
688 /* Calculate the mantissa by multiplying both 64bit numbers to get a
691 fractype x
= a
->fraction
.ll
;
692 fractype ylow
= b
->fraction
.ll
;
696 #if defined(NO_DI_MODE)
698 /* ??? This does multiplies one bit at a time. Optimize. */
699 for (bit
= 0; bit
< FRAC_NBITS
; bit
++)
705 carry
= (low
+= ylow
) < ylow
;
706 high
+= yhigh
+ carry
;
719 /* Multiplying two 32 bit numbers to get a 64 bit number on
720 a machine with DI, so we're safe */
722 DItype answer
= (DItype
)(a
->fraction
.ll
) * (DItype
)(b
->fraction
.ll
);
728 /* Doing a 64*64 to 128 */
730 UDItype nl
= a
->fraction
.ll
& 0xffffffff;
731 UDItype nh
= a
->fraction
.ll
>> 32;
732 UDItype ml
= b
->fraction
.ll
& 0xffffffff;
733 UDItype mh
= b
->fraction
.ll
>>32;
734 UDItype pp_ll
= ml
* nl
;
735 UDItype pp_hl
= mh
* nl
;
736 UDItype pp_lh
= ml
* nh
;
737 UDItype pp_hh
= mh
* nh
;
740 UDItype ps_hh__
= pp_hl
+ pp_lh
;
742 res2
+= 0x100000000LL
;
743 pp_hl
= (ps_hh__
<< 32) & 0xffffffff00000000LL
;
744 res0
= pp_ll
+ pp_hl
;
747 res2
+= ((ps_hh__
>> 32) & 0xffffffffL
) + pp_hh
;
754 tmp
->normal_exp
= a
->normal_exp
+ b
->normal_exp
;
755 tmp
->sign
= a
->sign
!= b
->sign
;
757 tmp
->normal_exp
+= 2; /* ??????????????? */
759 tmp
->normal_exp
+= 4; /* ??????????????? */
761 while (high
>= IMPLICIT_2
)
771 while (high
< IMPLICIT_1
)
780 /* rounding is tricky. if we only round if it won't make us round later. */
784 if (((high
& GARDMASK
) != GARDMSB
)
785 && (((high
+ 1) & GARDMASK
) == GARDMSB
))
787 /* don't round, it gets done again later. */
795 if ((high
& GARDMASK
) == GARDMSB
)
797 if (high
& (1 << NGARDS
))
799 /* half way, so round to even */
800 high
+= GARDROUND
+ 1;
804 /* but we really weren't half way */
805 high
+= GARDROUND
+ 1;
808 tmp
->fraction
.ll
= high
;
809 tmp
->class = CLASS_NUMBER
;
814 multiply (FLO_type arg_a
, FLO_type arg_b
)
821 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
822 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
824 res
= _fpmul_parts (&a
, &b
, &tmp
);
829 static fp_number_type
*
830 _fpdiv_parts (fp_number_type
* a
,
832 fp_number_type
* tmp
)
836 fractype r0
, r1
, y0
, y1
, bit
;
839 fractype denominator
;
851 if (isinf (a
) || iszero (a
))
853 if (a
->class == b
->class)
857 a
->sign
= a
->sign
^ b
->sign
;
867 a
->class = CLASS_INFINITY
;
871 /* Calculate the mantissa by multiplying both 64bit numbers to get a
875 intfrac d0
, d1
; /* weren't unsigned before ??? */
878 ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
881 a
->normal_exp
= a
->normal_exp
- b
->normal_exp
;
882 numerator
= a
->fraction
.ll
;
883 denominator
= b
->fraction
.ll
;
885 if (numerator
< denominator
)
887 /* Fraction will be less than 1.0 */
893 /* ??? Does divide one bit at a time. Optimize. */
896 if (numerator
>= denominator
)
899 numerator
-= denominator
;
905 if ((quotient
& GARDMASK
) == GARDMSB
)
907 if (quotient
& (1 << NGARDS
))
909 /* half way, so round to even */
910 quotient
+= GARDROUND
+ 1;
914 /* but we really weren't half way, more bits exist */
915 quotient
+= GARDROUND
+ 1;
919 a
->fraction
.ll
= quotient
;
925 divide (FLO_type arg_a
, FLO_type arg_b
)
932 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
933 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
935 res
= _fpdiv_parts (&a
, &b
, &tmp
);
940 /* according to the demo, fpcmp returns a comparison with 0... thus
947 _fpcmp_parts (fp_number_type
* a
, fp_number_type
* b
)
950 /* either nan -> unordered. Must be checked outside of this routine. */
951 if (isnan (a
) && isnan (b
))
953 return 1; /* still unordered! */
957 if (isnan (a
) || isnan (b
))
959 return 1; /* how to indicate unordered compare? */
961 if (isinf (a
) && isinf (b
))
963 /* +inf > -inf, but +inf != +inf */
964 /* b \a| +inf(0)| -inf(1)
965 ______\+--------+--------
966 +inf(0)| a==b(0)| a<b(-1)
967 -------+--------+--------
968 -inf(1)| a>b(1) | a==b(0)
969 -------+--------+--------
970 So since unordered must be non zero, just line up the columns...
972 return b
->sign
- a
->sign
;
974 /* but not both... */
977 return a
->sign
? -1 : 1;
981 return b
->sign
? 1 : -1;
983 if (iszero (a
) && iszero (b
))
989 return b
->sign
? 1 : -1;
993 return a
->sign
? -1 : 1;
995 /* now both are "normal". */
996 if (a
->sign
!= b
->sign
)
999 return a
->sign
? -1 : 1;
1001 /* same sign; exponents? */
1002 if (a
->normal_exp
> b
->normal_exp
)
1004 return a
->sign
? -1 : 1;
1006 if (a
->normal_exp
< b
->normal_exp
)
1008 return a
->sign
? 1 : -1;
1010 /* same exponents; check size. */
1011 if (a
->fraction
.ll
> b
->fraction
.ll
)
1013 return a
->sign
? -1 : 1;
1015 if (a
->fraction
.ll
< b
->fraction
.ll
)
1017 return a
->sign
? 1 : -1;
1019 /* after all that, they're equal. */
1024 compare (FLO_type arg_a
, FLO_type arg_b
)
1029 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1030 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1032 return _fpcmp_parts (&a
, &b
);
1035 #ifndef US_SOFTWARE_GOFAST
1037 /* These should be optimized for their specific tasks someday. */
1040 _eq_f2 (FLO_type arg_a
, FLO_type arg_b
)
1045 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1046 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1048 if (isnan (&a
) || isnan (&b
))
1049 return 1; /* false, truth == 0 */
1051 return _fpcmp_parts (&a
, &b
) ;
1055 _ne_f2 (FLO_type arg_a
, FLO_type arg_b
)
1060 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1061 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1063 if (isnan (&a
) || isnan (&b
))
1064 return 1; /* true, truth != 0 */
1066 return _fpcmp_parts (&a
, &b
) ;
1070 _gt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1075 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1076 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1078 if (isnan (&a
) || isnan (&b
))
1079 return -1; /* false, truth > 0 */
1081 return _fpcmp_parts (&a
, &b
);
1085 _ge_f2 (FLO_type arg_a
, FLO_type arg_b
)
1090 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1091 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1093 if (isnan (&a
) || isnan (&b
))
1094 return -1; /* false, truth >= 0 */
1095 return _fpcmp_parts (&a
, &b
) ;
1099 _lt_f2 (FLO_type arg_a
, FLO_type arg_b
)
1104 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1105 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1107 if (isnan (&a
) || isnan (&b
))
1108 return 1; /* false, truth < 0 */
1110 return _fpcmp_parts (&a
, &b
);
1114 _le_f2 (FLO_type arg_a
, FLO_type arg_b
)
1119 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1120 unpack_d ((FLO_union_type
*) & arg_b
, &b
);
1122 if (isnan (&a
) || isnan (&b
))
1123 return 1; /* false, truth <= 0 */
1125 return _fpcmp_parts (&a
, &b
) ;
1128 #endif /* ! US_SOFTWARE_GOFAST */
1131 si_to_float (SItype arg_a
)
1135 in
.class = CLASS_NUMBER
;
1136 in
.sign
= arg_a
< 0;
1139 in
.class = CLASS_ZERO
;
1143 in
.normal_exp
= FRACBITS
+ NGARDS
;
1146 /* Special case for minint, since there is no +ve integer
1147 representation for it */
1148 if (arg_a
== 0x80000000)
1150 return -2147483648.0;
1152 in
.fraction
.ll
= (-arg_a
);
1155 in
.fraction
.ll
= arg_a
;
1157 while (in
.fraction
.ll
< (1LL << (FRACBITS
+ NGARDS
)))
1159 in
.fraction
.ll
<<= 1;
1163 return pack_d (&in
);
1167 float_to_si (FLO_type arg_a
)
1172 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1177 /* get reasonable MAX_SI_INT... */
1179 return a
.sign
? MAX_SI_INT
: (-MAX_SI_INT
)-1;
1180 /* it is a number, but a small one */
1181 if (a
.normal_exp
< 0)
1183 if (a
.normal_exp
> 30)
1184 return a
.sign
? (-MAX_SI_INT
)-1 : MAX_SI_INT
;
1185 tmp
= a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1186 return a
.sign
? (-tmp
) : (tmp
);
1189 #ifdef US_SOFTWARE_GOFAST
1190 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1191 we also define them for GOFAST because the ones in libgcc2.c have the
1192 wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1193 out of libgcc2.c. We can't define these here if not GOFAST because then
1194 there'd be duplicate copies. */
1197 float_to_usi (FLO_type arg_a
)
1201 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1206 /* get reasonable MAX_USI_INT... */
1208 return a
.sign
? MAX_USI_INT
: 0;
1209 /* it is a negative number */
1212 /* it is a number, but a small one */
1213 if (a
.normal_exp
< 0)
1215 if (a
.normal_exp
> 31)
1217 else if (a
.normal_exp
> (FRACBITS
+ NGARDS
))
1218 return a
.fraction
.ll
<< ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1220 return a
.fraction
.ll
>> ((FRACBITS
+ NGARDS
) - a
.normal_exp
);
1225 negate (FLO_type arg_a
)
1229 unpack_d ((FLO_union_type
*) & arg_a
, &a
);
1237 __make_fp(fp_class_type
class,
1246 in
.normal_exp
= exp
;
1247 in
.fraction
.ll
= frac
;
1248 return pack_d (&in
);
1253 /* This enables one to build an fp library that supports float but not double.
1254 Otherwise, we would get an undefined reference to __make_dp.
1255 This is needed for some 8-bit ports that can't handle well values that
1256 are 8-bytes in size, so we just don't support double for them at all. */
1258 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype frac
);
1261 sf_to_df (SFtype arg_a
)
1265 unpack_d ((FLO_union_type
*) & arg_a
, &in
);
1266 return __make_dp (in
.class, in
.sign
, in
.normal_exp
,
1267 ((UDItype
) in
.fraction
.ll
) << F_D_BITOFF
);
1275 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
1278 __make_dp (fp_class_type
class, unsigned int sign
, int exp
, UDItype frac
)
1284 in
.normal_exp
= exp
;
1285 in
.fraction
.ll
= frac
;
1286 return pack_d (&in
);
1290 df_to_sf (DFtype arg_a
)
1294 unpack_d ((FLO_union_type
*) & arg_a
, &in
);
1295 return __make_fp (in
.class, in
.sign
, in
.normal_exp
,
1296 in
.fraction
.ll
>> F_D_BITOFF
);
This page took 0.057471 seconds and 4 git commands to generate.