Mercurial > hg > CbC > CbC_gcc
comparison gcc/config/s390/fixdfdi.h @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children | 855418dad1a3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
1 /* Definitions of target machine for GNU compiler, for IBM S/390 | |
2 Copyright (C) 1999, 2000, 2001, 2007, 2008 Free Software Foundation, Inc. | |
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and | |
4 Ulrich Weigand (uweigand@de.ibm.com). | |
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 | |
10 Software Foundation; either version 3, or (at your option) any later | |
11 version. | |
12 | |
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 | |
18 You should have received a copy of the GNU General Public License | |
19 along with GCC; see the file COPYING3. If not see | |
20 <http://www.gnu.org/licenses/>. */ | |
21 | |
22 #ifdef L_fixunstfdi | |
23 | |
24 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) | |
25 #define EXPONENT_BIAS 16383 | |
26 #define MANTISSA_BITS 112 | |
27 #define PRECISION (MANTISSA_BITS + 1) | |
28 #define SIGNBIT 0x80000000 | |
29 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT) | |
30 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) | |
31 #define MANTD_LOW_LL(fp) (fp.ll[1]) | |
32 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) | |
33 #define HIGH_LL_FRAC_BITS 48 | |
34 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) | |
35 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) | |
36 | |
37 typedef int DItype_x __attribute__ ((mode (DI))); | |
38 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
39 typedef int SItype_x __attribute__ ((mode (SI))); | |
40 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
41 | |
42 union double_long { | |
43 long double d; | |
44 struct { | |
45 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ | |
46 } l; | |
47 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ | |
48 }; | |
49 | |
50 UDItype_x __fixunstfdi (long double a1); | |
51 | |
52 /* convert double to unsigned int */ | |
53 UDItype_x | |
54 __fixunstfdi (long double a1) | |
55 { | |
56 register union double_long dl1; | |
57 register int exp; | |
58 register UDItype_x l; | |
59 | |
60 dl1.d = a1; | |
61 | |
62 /* +/- 0, denormalized, negative */ | |
63 if (!EXPD (dl1) || SIGND(dl1)) | |
64 return 0; | |
65 | |
66 /* The exponent - considered the binary point at the right end of | |
67 the mantissa. */ | |
68 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; | |
69 | |
70 /* number < 1: If the mantissa would need to be right-shifted more bits than | |
71 its size (plus the implied one bit on the left) the result would be | |
72 zero. */ | |
73 if (exp <= -PRECISION) | |
74 return 0; | |
75 | |
76 /* NaN: All exponent bits set and a nonzero fraction. */ | |
77 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) | |
78 return 0x0ULL; | |
79 | |
80 /* One extra bit is needed for the unit bit which is appended by | |
81 MANTD_HIGH_LL on the left of the matissa. */ | |
82 exp += HIGH_LL_FRAC_BITS + 1; | |
83 | |
84 /* If the result would still need a left shift it will be too large | |
85 to be represented. */ | |
86 if (exp > 0) | |
87 return 0xFFFFFFFFFFFFFFFFULL; | |
88 | |
89 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) | |
90 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); | |
91 | |
92 return l >> -exp; | |
93 } | |
94 #define __fixunstfdi ___fixunstfdi | |
95 #endif | |
96 #undef L_fixunstfdi | |
97 | |
98 #ifdef L_fixtfdi | |
99 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) | |
100 #define EXPONENT_BIAS 16383 | |
101 #define MANTISSA_BITS 112 | |
102 #define PRECISION (MANTISSA_BITS + 1) | |
103 #define SIGNBIT 0x80000000 | |
104 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT) | |
105 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) | |
106 #define MANTD_LOW_LL(fp) (fp.ll[1]) | |
107 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) | |
108 #define HIGH_LL_FRAC_BITS 48 | |
109 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) | |
110 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) | |
111 | |
112 typedef int DItype_x __attribute__ ((mode (DI))); | |
113 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
114 typedef int SItype_x __attribute__ ((mode (SI))); | |
115 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
116 | |
117 union double_long { | |
118 long double d; | |
119 struct { | |
120 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ | |
121 } l; | |
122 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ | |
123 }; | |
124 | |
125 DItype_x __fixtfdi (long double a1); | |
126 | |
127 /* convert double to unsigned int */ | |
128 DItype_x | |
129 __fixtfdi (long double a1) | |
130 { | |
131 register union double_long dl1; | |
132 register int exp; | |
133 register UDItype_x l; | |
134 | |
135 dl1.d = a1; | |
136 | |
137 /* +/- 0, denormalized */ | |
138 if (!EXPD (dl1)) | |
139 return 0; | |
140 | |
141 /* The exponent - considered the binary point at the right end of | |
142 the mantissa. */ | |
143 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; | |
144 | |
145 /* number < 1: If the mantissa would need to be right-shifted more bits than | |
146 its size the result would be zero. */ | |
147 if (exp <= -PRECISION) | |
148 return 0; | |
149 | |
150 /* NaN: All exponent bits set and a nonzero fraction. */ | |
151 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) | |
152 return 0x8000000000000000ULL; | |
153 | |
154 /* One extra bit is needed for the unit bit which is appended by | |
155 MANTD_HIGH_LL on the left of the matissa. */ | |
156 exp += HIGH_LL_FRAC_BITS + 1; | |
157 | |
158 /* If the result would still need a left shift it will be too large | |
159 to be represented. Compared to the unsigned variant we have to | |
160 take care that there is still space for the sign bit to be | |
161 applied. So we can only go on if there is a right-shift by one | |
162 or more. */ | |
163 if (exp >= 0) | |
164 { | |
165 l = 1ULL << 63; /* long long min */ | |
166 return SIGND (dl1) ? l : l - 1; | |
167 } | |
168 | |
169 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) | |
170 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); | |
171 | |
172 return SIGND (dl1) ? -(l >> -exp) : l >> -exp; | |
173 } | |
174 #define __fixtfdi ___fixtfdi | |
175 #endif | |
176 #undef L_fixtfdi | |
177 | |
178 #ifdef L_fixunsdfdi | |
179 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) | |
180 #define EXCESSD 1022 | |
181 #define SIGNBIT 0x80000000 | |
182 #define SIGND(fp) ((fp.l.upper) & SIGNBIT) | |
183 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) | |
184 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1)) | |
185 #define HIDDEND_LL ((UDItype_x)1 << 52) | |
186 | |
187 typedef int DItype_x __attribute__ ((mode (DI))); | |
188 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
189 typedef int SItype_x __attribute__ ((mode (SI))); | |
190 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
191 | |
192 union double_long { | |
193 double d; | |
194 struct { | |
195 SItype_x upper; | |
196 USItype_x lower; | |
197 } l; | |
198 UDItype_x ll; | |
199 }; | |
200 | |
201 UDItype_x __fixunsdfdi (double a1); | |
202 | |
203 /* convert double to unsigned int */ | |
204 UDItype_x | |
205 __fixunsdfdi (double a1) | |
206 { | |
207 register union double_long dl1; | |
208 register int exp; | |
209 register UDItype_x l; | |
210 | |
211 dl1.d = a1; | |
212 | |
213 /* +/- 0, denormalized, negative */ | |
214 | |
215 if (!EXPD (dl1) || SIGND(dl1)) | |
216 return 0; | |
217 | |
218 exp = EXPD (dl1) - EXCESSD - 53; | |
219 | |
220 /* number < 1 */ | |
221 | |
222 if (exp < -53) | |
223 return 0; | |
224 | |
225 /* NaN */ | |
226 | |
227 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */ | |
228 return 0x0ULL; | |
229 | |
230 /* Number big number & + inf */ | |
231 | |
232 if (exp >= 12) { | |
233 return 0xFFFFFFFFFFFFFFFFULL; | |
234 } | |
235 | |
236 l = MANTD_LL(dl1); | |
237 | |
238 /* shift down until exp < 12 or l = 0 */ | |
239 if (exp > 0) | |
240 l <<= exp; | |
241 else | |
242 l >>= -exp; | |
243 | |
244 return l; | |
245 } | |
246 #define __fixunsdfdi ___fixunsdfdi | |
247 #endif | |
248 #undef L_fixunsdfdi | |
249 | |
250 #ifdef L_fixdfdi | |
251 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) | |
252 #define EXCESSD 1022 | |
253 #define SIGNBIT 0x80000000 | |
254 #define SIGND(fp) ((fp.l.upper) & SIGNBIT) | |
255 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) | |
256 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1)) | |
257 #define HIDDEND_LL ((UDItype_x)1 << 52) | |
258 | |
259 typedef int DItype_x __attribute__ ((mode (DI))); | |
260 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
261 typedef int SItype_x __attribute__ ((mode (SI))); | |
262 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
263 | |
264 union double_long { | |
265 double d; | |
266 struct { | |
267 SItype_x upper; | |
268 USItype_x lower; | |
269 } l; | |
270 UDItype_x ll; | |
271 }; | |
272 | |
273 DItype_x __fixdfdi (double a1); | |
274 | |
275 /* convert double to int */ | |
276 DItype_x | |
277 __fixdfdi (double a1) | |
278 { | |
279 register union double_long dl1; | |
280 register int exp; | |
281 register DItype_x l; | |
282 | |
283 dl1.d = a1; | |
284 | |
285 /* +/- 0, denormalized */ | |
286 | |
287 if (!EXPD (dl1)) | |
288 return 0; | |
289 | |
290 exp = EXPD (dl1) - EXCESSD - 53; | |
291 | |
292 /* number < 1 */ | |
293 | |
294 if (exp < -53) | |
295 return 0; | |
296 | |
297 /* NaN */ | |
298 | |
299 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */ | |
300 return 0x8000000000000000ULL; | |
301 | |
302 /* Number big number & +/- inf */ | |
303 | |
304 if (exp >= 11) { | |
305 l = (long long)1<<63; | |
306 if (!SIGND(dl1)) | |
307 l--; | |
308 return l; | |
309 } | |
310 | |
311 l = MANTD_LL(dl1); | |
312 | |
313 /* shift down until exp < 12 or l = 0 */ | |
314 if (exp > 0) | |
315 l <<= exp; | |
316 else | |
317 l >>= -exp; | |
318 | |
319 return (SIGND (dl1) ? -l : l); | |
320 } | |
321 #define __fixdfdi ___fixdfdi | |
322 #endif | |
323 #undef L_fixdfdi | |
324 | |
325 #ifdef L_fixunssfdi | |
326 #define EXP(fp) (((fp.l) >> 23) & 0xFF) | |
327 #define EXCESS 126 | |
328 #define SIGNBIT 0x80000000 | |
329 #define SIGN(fp) ((fp.l) & SIGNBIT) | |
330 #define HIDDEN (1 << 23) | |
331 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN) | |
332 #define FRAC(fp) ((fp.l) & 0x7FFFFF) | |
333 | |
334 typedef int DItype_x __attribute__ ((mode (DI))); | |
335 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
336 typedef int SItype_x __attribute__ ((mode (SI))); | |
337 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
338 | |
339 union float_long | |
340 { | |
341 float f; | |
342 USItype_x l; | |
343 }; | |
344 | |
345 UDItype_x __fixunssfdi (float a1); | |
346 | |
347 /* convert float to unsigned int */ | |
348 UDItype_x | |
349 __fixunssfdi (float a1) | |
350 { | |
351 register union float_long fl1; | |
352 register int exp; | |
353 register UDItype_x l; | |
354 | |
355 fl1.f = a1; | |
356 | |
357 /* +/- 0, denormalized, negative */ | |
358 | |
359 if (!EXP (fl1) || SIGN(fl1)) | |
360 return 0; | |
361 | |
362 exp = EXP (fl1) - EXCESS - 24; | |
363 | |
364 /* number < 1 */ | |
365 | |
366 if (exp < -24) | |
367 return 0; | |
368 | |
369 /* NaN */ | |
370 | |
371 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */ | |
372 return 0x0ULL; | |
373 | |
374 /* Number big number & + inf */ | |
375 | |
376 if (exp >= 41) { | |
377 return 0xFFFFFFFFFFFFFFFFULL; | |
378 } | |
379 | |
380 l = MANT(fl1); | |
381 | |
382 if (exp > 0) | |
383 l <<= exp; | |
384 else | |
385 l >>= -exp; | |
386 | |
387 return l; | |
388 } | |
389 #define __fixunssfdi ___fixunssfdi | |
390 #endif | |
391 #undef L_fixunssfdi | |
392 | |
393 #ifdef L_fixsfdi | |
394 #define EXP(fp) (((fp.l) >> 23) & 0xFF) | |
395 #define EXCESS 126 | |
396 #define SIGNBIT 0x80000000 | |
397 #define SIGN(fp) ((fp.l) & SIGNBIT) | |
398 #define HIDDEN (1 << 23) | |
399 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN) | |
400 #define FRAC(fp) ((fp.l) & 0x7FFFFF) | |
401 | |
402 typedef int DItype_x __attribute__ ((mode (DI))); | |
403 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
404 typedef int SItype_x __attribute__ ((mode (SI))); | |
405 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
406 | |
407 union float_long | |
408 { | |
409 float f; | |
410 USItype_x l; | |
411 }; | |
412 | |
413 DItype_x __fixsfdi (float a1); | |
414 | |
415 /* convert double to int */ | |
416 DItype_x | |
417 __fixsfdi (float a1) | |
418 { | |
419 register union float_long fl1; | |
420 register int exp; | |
421 register DItype_x l; | |
422 | |
423 fl1.f = a1; | |
424 | |
425 /* +/- 0, denormalized */ | |
426 | |
427 if (!EXP (fl1)) | |
428 return 0; | |
429 | |
430 exp = EXP (fl1) - EXCESS - 24; | |
431 | |
432 /* number < 1 */ | |
433 | |
434 if (exp < -24) | |
435 return 0; | |
436 | |
437 /* NaN */ | |
438 | |
439 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */ | |
440 return 0x8000000000000000ULL; | |
441 | |
442 /* Number big number & +/- inf */ | |
443 | |
444 if (exp >= 40) { | |
445 l = (long long)1<<63; | |
446 if (!SIGN(fl1)) | |
447 l--; | |
448 return l; | |
449 } | |
450 | |
451 l = MANT(fl1); | |
452 | |
453 if (exp > 0) | |
454 l <<= exp; | |
455 else | |
456 l >>= -exp; | |
457 | |
458 return (SIGN (fl1) ? -l : l); | |
459 } | |
460 #define __fixsfdi ___fixsfdi | |
461 #endif | |
462 #undef L_fixsfdi |