]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/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-2020 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #if defined(__powerpc64__) || defined (__64BIT__) || defined(__ppc64__)
31 extern DItype
__fixtfdi (TFtype
);
32 extern DItype
__fixdfdi (DFtype
);
33 extern DItype
__fixsfdi (SFtype
);
34 extern USItype
__fixunsdfsi (DFtype
);
35 extern USItype
__fixunssfsi (SFtype
);
36 extern TFtype
__floatditf (DItype
);
37 extern TFtype
__floatunditf (UDItype
);
38 extern DFtype
__floatdidf (DItype
);
39 extern DFtype
__floatundidf (UDItype
);
40 extern SFtype
__floatdisf (DItype
);
41 extern SFtype
__floatundisf (UDItype
);
42 extern DItype
__fixunstfdi (TFtype
);
44 static DItype
local_fixunssfdi (SFtype
);
45 static DItype
local_fixunsdfdi (DFtype
);
51 return - __fixunstfdi (-a
);
52 return __fixunstfdi (a
);
59 return - local_fixunsdfdi (-a
);
60 return local_fixunsdfdi (a
);
67 return - local_fixunssfdi (-a
);
68 return local_fixunssfdi (a
);
72 __fixunsdfsi (DFtype a
)
74 if (a
>= - (DFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
75 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
76 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
81 __fixunssfsi (SFtype a
)
83 if (a
>= - (SFtype
) (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
84 return (SItype
) (a
+ (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1))
85 - (- ((SItype
)(((USItype
)1 << ((4 * 8) - 1)) - 1)) - 1);
90 __floatditf (DItype u
)
94 dh
= (SItype
) (u
>> (sizeof (SItype
) * 8));
95 dh
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
96 dl
= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
98 return (TFtype
) dh
+ (TFtype
) dl
;
102 __floatunditf (UDItype u
)
106 dh
= (USItype
) (u
>> (sizeof (SItype
) * 8));
107 dh
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
108 dl
= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
110 return (TFtype
) dh
+ (TFtype
) dl
;
114 __floatdidf (DItype u
)
118 d
= (SItype
) (u
>> (sizeof (SItype
) * 8));
119 d
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
120 d
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
126 __floatundidf (UDItype u
)
130 d
= (USItype
) (u
>> (sizeof (SItype
) * 8));
131 d
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
132 d
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
138 __floatdisf (DItype u
)
142 if (53 < (sizeof (DItype
) * 8)
143 && 53 > ((sizeof (DItype
) * 8) - 53 + 24))
145 if (! (- ((DItype
) 1 << 53) < u
146 && u
< ((DItype
) 1 << 53)))
148 if ((UDItype
) u
& (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1))
150 u
&= ~ (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1);
151 u
|= ((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53));
155 f
= (SItype
) (u
>> (sizeof (SItype
) * 8));
156 f
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
157 f
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
163 __floatundisf (UDItype u
)
167 if (53 < (sizeof (DItype
) * 8)
168 && 53 > ((sizeof (DItype
) * 8) - 53 + 24))
170 if (u
>= ((UDItype
) 1 << 53))
172 if ((UDItype
) u
& (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1))
174 u
&= ~ (((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53)) - 1);
175 u
|= ((UDItype
) 1 << ((sizeof (DItype
) * 8) - 53));
179 f
= (USItype
) (u
>> (sizeof (SItype
) * 8));
180 f
*= 2.0 * (((UDItype
) 1) << ((sizeof (SItype
) * 8) - 1));
181 f
+= (USItype
) (u
& ((((UDItype
) 1) << (sizeof (SItype
) * 8)) - 1));
187 __fixunstfdi (TFtype a
)
192 /* Compute high word of result, as a flonum. */
193 const TFtype b
= (a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8)));
194 /* Convert that to fixed (but not to DItype!),
195 and shift it into the high word. */
196 UDItype v
= (USItype
) b
;
197 v
<<= (sizeof (SItype
) * 8);
198 /* Remove high part from the TFtype, leaving the low part as flonum. */
200 /* Convert that to fixed (but not to DItype!) and add it in.
201 Sometimes A comes out negative. This is significant, since
202 A has more bits than a long int does. */
210 /* This version is needed to prevent recursion; fixunsdfdi in libgcc
211 calls fixdfdi, which in turn calls calls fixunsdfdi. */
214 local_fixunsdfdi (DFtype a
)
218 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
219 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
220 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
223 /* This version is needed to prevent recursion; fixunssfdi in libgcc
224 calls fixsfdi, which in turn calls calls fixunssfdi. */
227 local_fixunssfdi (SFtype original_a
)
229 DFtype a
= original_a
;
232 hi
= a
/ (((UDItype
) 1) << (sizeof (SItype
) * 8));
233 lo
= (a
- ((DFtype
) hi
) * (((UDItype
) 1) << (sizeof (SItype
) * 8)));
234 return ((UDItype
) hi
<< (sizeof (SItype
) * 8)) | lo
;
237 #endif /* __powerpc64__ */