]>
Commit | Line | Data |
---|---|---|
df745324 | 1 | /* Functions needed for soft-float on powerpc64-linux, copied from |
2 | libgcc2.c with macros expanded to force the use of specific types. | |
3 | ||
f1717362 | 4 | Copyright (C) 1989-2016 Free Software Foundation, Inc. |
df745324 | 5 | |
6 | This file is part of GCC. | |
7 | ||
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 | |
6bc9506f | 10 | Software Foundation; either version 3, or (at your option) any later |
df745324 | 11 | version. |
12 | ||
df745324 | 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 | |
16 | for more details. | |
17 | ||
6bc9506f | 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. | |
21 | ||
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/>. */ | |
df745324 | 26 | |
23e97733 | 27 | #if defined(__powerpc64__) || defined (__64BIT__) || defined(__ppc64__) |
baad77c2 | 28 | #define TMODES |
a23b9c51 | 29 | #include "fp-bit.h" |
df745324 | 30 | |
325ade6e | 31 | extern DItype __fixtfdi (TFtype); |
df745324 | 32 | extern DItype __fixdfdi (DFtype); |
33 | extern DItype __fixsfdi (SFtype); | |
34 | extern USItype __fixunsdfsi (DFtype); | |
35 | extern USItype __fixunssfsi (SFtype); | |
325ade6e | 36 | extern TFtype __floatditf (DItype); |
7d425655 | 37 | extern TFtype __floatunditf (UDItype); |
df745324 | 38 | extern DFtype __floatdidf (DItype); |
7d425655 | 39 | extern DFtype __floatundidf (UDItype); |
df745324 | 40 | extern SFtype __floatdisf (DItype); |
7d425655 | 41 | extern SFtype __floatundisf (UDItype); |
325ade6e | 42 | extern DItype __fixunstfdi (TFtype); |
df745324 | 43 | |
44 | static DItype local_fixunssfdi (SFtype); | |
45 | static DItype local_fixunsdfdi (DFtype); | |
46 | ||
325ade6e | 47 | DItype |
48 | __fixtfdi (TFtype a) | |
49 | { | |
50 | if (a < 0) | |
51 | return - __fixunstfdi (-a); | |
52 | return __fixunstfdi (a); | |
53 | } | |
54 | ||
df745324 | 55 | DItype |
56 | __fixdfdi (DFtype a) | |
57 | { | |
58 | if (a < 0) | |
59 | return - local_fixunsdfdi (-a); | |
60 | return local_fixunsdfdi (a); | |
61 | } | |
62 | ||
63 | DItype | |
64 | __fixsfdi (SFtype a) | |
65 | { | |
66 | if (a < 0) | |
67 | return - local_fixunssfdi (-a); | |
68 | return local_fixunssfdi (a); | |
69 | } | |
70 | ||
71 | USItype | |
72 | __fixunsdfsi (DFtype a) | |
73 | { | |
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); | |
77 | return (SItype) a; | |
78 | } | |
79 | ||
80 | USItype | |
81 | __fixunssfsi (SFtype a) | |
82 | { | |
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); | |
86 | return (SItype) a; | |
87 | } | |
88 | ||
325ade6e | 89 | TFtype |
90 | __floatditf (DItype u) | |
91 | { | |
92 | DFtype dh, dl; | |
93 | ||
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)); | |
97 | ||
98 | return (TFtype) dh + (TFtype) dl; | |
99 | } | |
100 | ||
7d425655 | 101 | TFtype |
102 | __floatunditf (UDItype u) | |
103 | { | |
104 | DFtype dh, dl; | |
105 | ||
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)); | |
109 | ||
110 | return (TFtype) dh + (TFtype) dl; | |
111 | } | |
112 | ||
df745324 | 113 | DFtype |
114 | __floatdidf (DItype u) | |
115 | { | |
116 | DFtype d; | |
117 | ||
118 | d = (SItype) (u >> (sizeof (SItype) * 8)); | |
325ade6e | 119 | d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1)); |
df745324 | 120 | d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1)); |
121 | ||
122 | return d; | |
123 | } | |
124 | ||
7d425655 | 125 | DFtype |
126 | __floatundidf (UDItype u) | |
127 | { | |
128 | DFtype d; | |
129 | ||
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)); | |
133 | ||
134 | return d; | |
135 | } | |
136 | ||
df745324 | 137 | SFtype |
138 | __floatdisf (DItype u) | |
139 | { | |
140 | DFtype f; | |
141 | ||
142 | if (53 < (sizeof (DItype) * 8) | |
143 | && 53 > ((sizeof (DItype) * 8) - 53 + 24)) | |
144 | { | |
145 | if (! (- ((DItype) 1 << 53) < u | |
146 | && u < ((DItype) 1 << 53))) | |
147 | { | |
148 | if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1)) | |
149 | { | |
150 | u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1); | |
151 | u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53)); | |
152 | } | |
153 | } | |
154 | } | |
155 | f = (SItype) (u >> (sizeof (SItype) * 8)); | |
325ade6e | 156 | f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1)); |
df745324 | 157 | f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1)); |
158 | ||
159 | return (SFtype) f; | |
160 | } | |
161 | ||
7d425655 | 162 | SFtype |
163 | __floatundisf (UDItype u) | |
164 | { | |
165 | DFtype f; | |
166 | ||
167 | if (53 < (sizeof (DItype) * 8) | |
168 | && 53 > ((sizeof (DItype) * 8) - 53 + 24)) | |
169 | { | |
170 | if (u >= ((UDItype) 1 << 53)) | |
171 | { | |
172 | if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1)) | |
173 | { | |
174 | u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1); | |
175 | u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53)); | |
176 | } | |
177 | } | |
178 | } | |
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)); | |
182 | ||
183 | return (SFtype) f; | |
184 | } | |
185 | ||
325ade6e | 186 | DItype |
187 | __fixunstfdi (TFtype a) | |
188 | { | |
189 | if (a < 0) | |
190 | return 0; | |
191 | ||
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. */ | |
199 | a -= (TFtype) v; | |
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. */ | |
203 | if (a < 0) | |
204 | v -= (USItype) (-a); | |
205 | else | |
206 | v += (USItype) a; | |
207 | return v; | |
208 | } | |
209 | ||
df745324 | 210 | /* This version is needed to prevent recursion; fixunsdfdi in libgcc |
211 | calls fixdfdi, which in turn calls calls fixunsdfdi. */ | |
212 | ||
213 | static DItype | |
214 | local_fixunsdfdi (DFtype a) | |
215 | { | |
216 | USItype hi, lo; | |
217 | ||
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; | |
221 | } | |
222 | ||
223 | /* This version is needed to prevent recursion; fixunssfdi in libgcc | |
224 | calls fixsfdi, which in turn calls calls fixunssfdi. */ | |
225 | ||
226 | static DItype | |
227 | local_fixunssfdi (SFtype original_a) | |
228 | { | |
229 | DFtype a = original_a; | |
230 | USItype hi, lo; | |
231 | ||
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; | |
235 | } | |
236 | ||
237 | #endif /* __powerpc64__ */ |