2008-07-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / gcc / config / s390 / fixdfdi.h
blob865bf46b99fa4e68da9df7f13d6dc5296d292e95
1 /* Definitions of target machine for GNU compiler, for IBM S/390
2 Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 Ulrich Weigand (uweigand@de.ibm.com).
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
11 version.
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.
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/>. */
22 #ifdef L_fixunstfdi
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)
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)));
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 */
50 UDItype_x __fixunstfdi (long double a1);
52 /* convert double to unsigned int */
53 UDItype_x
54 __fixunstfdi (long double a1)
56 register union double_long dl1;
57 register int exp;
58 register UDItype_x l;
60 dl1.d = a1;
62 /* +/- 0, denormalized, negative */
63 if (!EXPD (dl1) || SIGND(dl1))
64 return 0;
66 /* The exponent - considered the binary point at the right end of
67 the mantissa. */
68 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
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;
76 /* NaN: All exponent bits set and a nonzero fraction. */
77 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
78 return 0x0ULL;
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;
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;
89 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
90 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
92 return l >> -exp;
94 #define __fixunstfdi ___fixunstfdi
95 #endif
96 #undef L_fixunstfdi
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)
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)));
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 */
125 DItype_x __fixtfdi (long double a1);
127 /* convert double to unsigned int */
128 DItype_x
129 __fixtfdi (long double a1)
131 register union double_long dl1;
132 register int exp;
133 register UDItype_x l;
135 dl1.d = a1;
137 /* +/- 0, denormalized */
138 if (!EXPD (dl1))
139 return 0;
141 /* The exponent - considered the binary point at the right end of
142 the mantissa. */
143 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
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;
150 /* NaN: All exponent bits set and a nonzero fraction. */
151 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
152 return 0x8000000000000000ULL;
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;
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)
165 l = 1ULL << 63; /* long long min */
166 return SIGND (dl1) ? l : l - 1;
169 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
170 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
172 return SIGND (dl1) ? -(l >> -exp) : l >> -exp;
174 #define __fixtfdi ___fixtfdi
175 #endif
176 #undef L_fixtfdi
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)
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)));
192 union double_long {
193 double d;
194 struct {
195 SItype_x upper;
196 USItype_x lower;
197 } l;
198 UDItype_x ll;
201 UDItype_x __fixunsdfdi (double a1);
203 /* convert double to unsigned int */
204 UDItype_x
205 __fixunsdfdi (double a1)
207 register union double_long dl1;
208 register int exp;
209 register UDItype_x l;
211 dl1.d = a1;
213 /* +/- 0, denormalized, negative */
215 if (!EXPD (dl1) || SIGND(dl1))
216 return 0;
218 exp = EXPD (dl1) - EXCESSD - 53;
220 /* number < 1 */
222 if (exp < -53)
223 return 0;
225 /* NaN */
227 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
228 return 0x0ULL;
230 /* Number big number & + inf */
232 if (exp >= 12) {
233 return 0xFFFFFFFFFFFFFFFFULL;
236 l = MANTD_LL(dl1);
238 /* shift down until exp < 12 or l = 0 */
239 if (exp > 0)
240 l <<= exp;
241 else
242 l >>= -exp;
244 return l;
246 #define __fixunsdfdi ___fixunsdfdi
247 #endif
248 #undef L_fixunsdfdi
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)
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)));
264 union double_long {
265 double d;
266 struct {
267 SItype_x upper;
268 USItype_x lower;
269 } l;
270 UDItype_x ll;
273 DItype_x __fixdfdi (double a1);
275 /* convert double to int */
276 DItype_x
277 __fixdfdi (double a1)
279 register union double_long dl1;
280 register int exp;
281 register DItype_x l;
283 dl1.d = a1;
285 /* +/- 0, denormalized */
287 if (!EXPD (dl1))
288 return 0;
290 exp = EXPD (dl1) - EXCESSD - 53;
292 /* number < 1 */
294 if (exp < -53)
295 return 0;
297 /* NaN */
299 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
300 return 0x8000000000000000ULL;
302 /* Number big number & +/- inf */
304 if (exp >= 11) {
305 l = (long long)1<<63;
306 if (!SIGND(dl1))
307 l--;
308 return l;
311 l = MANTD_LL(dl1);
313 /* shift down until exp < 12 or l = 0 */
314 if (exp > 0)
315 l <<= exp;
316 else
317 l >>= -exp;
319 return (SIGND (dl1) ? -l : l);
321 #define __fixdfdi ___fixdfdi
322 #endif
323 #undef L_fixdfdi
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)
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)));
339 union float_long
341 float f;
342 USItype_x l;
345 UDItype_x __fixunssfdi (float a1);
347 /* convert float to unsigned int */
348 UDItype_x
349 __fixunssfdi (float a1)
351 register union float_long fl1;
352 register int exp;
353 register UDItype_x l;
355 fl1.f = a1;
357 /* +/- 0, denormalized, negative */
359 if (!EXP (fl1) || SIGN(fl1))
360 return 0;
362 exp = EXP (fl1) - EXCESS - 24;
364 /* number < 1 */
366 if (exp < -24)
367 return 0;
369 /* NaN */
371 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
372 return 0x0ULL;
374 /* Number big number & + inf */
376 if (exp >= 41) {
377 return 0xFFFFFFFFFFFFFFFFULL;
380 l = MANT(fl1);
382 if (exp > 0)
383 l <<= exp;
384 else
385 l >>= -exp;
387 return l;
389 #define __fixunssfdi ___fixunssfdi
390 #endif
391 #undef L_fixunssfdi
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)
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)));
407 union float_long
409 float f;
410 USItype_x l;
413 DItype_x __fixsfdi (float a1);
415 /* convert double to int */
416 DItype_x
417 __fixsfdi (float a1)
419 register union float_long fl1;
420 register int exp;
421 register DItype_x l;
423 fl1.f = a1;
425 /* +/- 0, denormalized */
427 if (!EXP (fl1))
428 return 0;
430 exp = EXP (fl1) - EXCESS - 24;
432 /* number < 1 */
434 if (exp < -24)
435 return 0;
437 /* NaN */
439 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
440 return 0x8000000000000000ULL;
442 /* Number big number & +/- inf */
444 if (exp >= 40) {
445 l = (long long)1<<63;
446 if (!SIGN(fl1))
447 l--;
448 return l;
451 l = MANT(fl1);
453 if (exp > 0)
454 l <<= exp;
455 else
456 l >>= -exp;
458 return (SIGN (fl1) ? -l : l);
460 #define __fixsfdi ___fixsfdi
461 #endif
462 #undef L_fixsfdi