1 /* Functions needed for soft-float on powerpc64-linux, copied from
2 libgcc2.c with macros expanded to force the use of specific types.
4 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
5 2000, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 In addition to the permissions in the GNU General Public License, the
15 Free Software Foundation gives you unlimited permission to link the
16 compiled version of this file into combinations with other programs,
17 and to distribute those combinations without any restriction coming
18 from the use of this file. (The General Public License restrictions
19 do apply in other respects; for example, they cover modification of
20 the file, and distribution when not linked into a combine
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING. If not, write to the Free
30 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
33 #if defined(__powerpc64__) || defined (__64BIT__)
35 #include "config/fp-bit.h"
37 extern DItype
__fixtfdi (TFtype
);
38 extern DItype
__fixdfdi (DFtype
);
39 extern DItype
__fixsfdi (SFtype
);
40 extern USItype
__fixunsdfsi (DFtype
);
41 extern USItype
__fixunssfsi (SFtype
);
42 extern TFtype
__floatditf (DItype
);
43 extern DFtype
__floatdidf (DItype
);
44 extern SFtype
__floatdisf (DItype
);
45 extern DItype
__fixunstfdi (TFtype
);
47 static DItype
local_fixunssfdi (SFtype
);
48 static DItype
local_fixunsdfdi (DFtype
);
54 return - __fixunstfdi (-a
);
55 return __fixunstfdi (a
);
62 return - local_fixunsdfdi (-a
);
63 return local_fixunsdfdi (a
);
70 return - local_fixunssfdi (-a
);
71 return local_fixunssfdi (a
);
75 __fixunsdfsi (DFtype a
)
77 if (a
>= - (DFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
78 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
79 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
84 __fixunssfsi (SFtype a
)
86 if (a
>= - (SFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
87 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
88 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
93 __floatditf (DItype u
)
97 dh
= (SItype
) (u
>> (sizeof (SItype
) * 8));
98 dh
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
99 dl
= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
101 return (TFtype
) dh
+ (TFtype
) dl
;
105 __floatdidf (DItype u
)
109 d
= (SItype
) (u
>> (sizeof (SItype
) * 8));
110 d
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
111 d
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
117 __floatdisf (DItype u
)
121 if (53 < (sizeof (DItype
) * 8)
122 && 53 > ((sizeof (DItype
) * 8) - 53 + 24))
124 if (! (- ((DItype
) 1 << 53) < u
125 && u
< ((DItype
) 1 << 53)))
127 if ((UDItype
) u
& (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1))
129 u
&= ~ (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1);
130 u
|= ((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53));
134 f
= (SItype
) (u
>> (sizeof (SItype
) * 8));
135 f
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
136 f
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
142 __fixunstfdi (TFtype a
)
147 /* Compute high word of result, as a flonum. */
148 const TFtype b
= (a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8)));
149 /* Convert that to fixed (but not to DItype!),
150 and shift it into the high word. */
151 UDItype v
= (USItype
) b
;
152 v
<<= (sizeof (SItype
) * 8);
153 /* Remove high part from the TFtype, leaving the low part as flonum. */
155 /* Convert that to fixed (but not to DItype!) and add it in.
156 Sometimes A comes out negative. This is significant, since
157 A has more bits than a long int does. */
165 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
166 calls fixdfdi, which in turn calls calls fixunsdfdi. */
169 local_fixunsdfdi (DFtype a
)
173 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
174 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
175 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
178 /* This version is needed to prevent recursion; fixunssfdi in libgcc
179 calls fixsfdi, which in turn calls calls fixunssfdi. */
182 local_fixunssfdi (SFtype original_a
)
184 DFtype a
= original_a
;
187 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
188 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
189 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
192 #endif /* __powerpc64__ */