]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/rs6000/ppc64-fp.c
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, 2009 Free Software Foundation,
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 Under Section 7 of GPL version 3, you are granted additional
21 permissions described in the GCC Runtime Library Exception, version
22 3.1, as published by the Free Software Foundation.
24 You should have received a copy of the GNU General Public License and
25 a copy of the GCC Runtime Library Exception along with this program;
26 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
27 <http://www.gnu.org/licenses/>. */
29 #if defined(__powerpc64__) || defined (__64BIT__) || defined(__ppc64__)
31 #include "config/fp-bit.h"
33 extern DItype
__fixtfdi (TFtype
);
34 extern DItype
__fixdfdi (DFtype
);
35 extern DItype
__fixsfdi (SFtype
);
36 extern USItype
__fixunsdfsi (DFtype
);
37 extern USItype
__fixunssfsi (SFtype
);
38 extern TFtype
__floatditf (DItype
);
39 extern TFtype
__floatunditf (UDItype
);
40 extern DFtype
__floatdidf (DItype
);
41 extern DFtype
__floatundidf (UDItype
);
42 extern SFtype
__floatdisf (DItype
);
43 extern SFtype
__floatundisf (UDItype
);
44 extern DItype
__fixunstfdi (TFtype
);
46 static DItype
local_fixunssfdi (SFtype
);
47 static DItype
local_fixunsdfdi (DFtype
);
53 return - __fixunstfdi (-a
);
54 return __fixunstfdi (a
);
61 return - local_fixunsdfdi (-a
);
62 return local_fixunsdfdi (a
);
69 return - local_fixunssfdi (-a
);
70 return local_fixunssfdi (a
);
74 __fixunsdfsi (DFtype a
)
76 if (a
>= - (DFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
77 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
78 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
83 __fixunssfsi (SFtype a
)
85 if (a
>= - (SFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
86 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
87 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
92 __floatditf (DItype u
)
96 dh
= (SItype
) (u
>> (sizeof (SItype
) * 8));
97 dh
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
98 dl
= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
100 return (TFtype
) dh
+ (TFtype
) dl
;
104 __floatunditf (UDItype u
)
108 dh
= (USItype
) (u
>> (sizeof (SItype
) * 8));
109 dh
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
110 dl
= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
112 return (TFtype
) dh
+ (TFtype
) dl
;
116 __floatdidf (DItype u
)
120 d
= (SItype
) (u
>> (sizeof (SItype
) * 8));
121 d
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
122 d
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
128 __floatundidf (UDItype u
)
132 d
= (USItype
) (u
>> (sizeof (SItype
) * 8));
133 d
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
134 d
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
140 __floatdisf (DItype u
)
144 if (53 < (sizeof (DItype
) * 8)
145 && 53 > ((sizeof (DItype
) * 8) - 53 + 24))
147 if (! (- ((DItype
) 1 << 53) < u
148 && u
< ((DItype
) 1 << 53)))
150 if ((UDItype
) u
& (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1))
152 u
&= ~ (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1);
153 u
|= ((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53));
157 f
= (SItype
) (u
>> (sizeof (SItype
) * 8));
158 f
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
159 f
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
165 __floatundisf (UDItype u
)
169 if (53 < (sizeof (DItype
) * 8)
170 && 53 > ((sizeof (DItype
) * 8) - 53 + 24))
172 if (u
>= ((UDItype
) 1 << 53))
174 if ((UDItype
) u
& (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1))
176 u
&= ~ (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1);
177 u
|= ((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53));
181 f
= (USItype
) (u
>> (sizeof (SItype
) * 8));
182 f
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
183 f
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
189 __fixunstfdi (TFtype a
)
194 /* Compute high word of result, as a flonum. */
195 const TFtype b
= (a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8)));
196 /* Convert that to fixed (but not to DItype!),
197 and shift it into the high word. */
198 UDItype v
= (USItype
) b
;
199 v
<<= (sizeof (SItype
) * 8);
200 /* Remove high part from the TFtype, leaving the low part as flonum. */
202 /* Convert that to fixed (but not to DItype!) and add it in.
203 Sometimes A comes out negative. This is significant, since
204 A has more bits than a long int does. */
212 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
213 calls fixdfdi, which in turn calls calls fixunsdfdi. */
216 local_fixunsdfdi (DFtype a
)
220 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
221 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
222 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
225 /* This version is needed to prevent recursion; fixunssfdi in libgcc
226 calls fixsfdi, which in turn calls calls fixunssfdi. */
229 local_fixunssfdi (SFtype original_a
)
231 DFtype a
= original_a
;
234 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
235 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
236 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
239 #endif /* __powerpc64__ */