Merge from mainline
[official-gcc.git] / gcc / config / s390 / fixdfdi.h
blobfd12243a381dfd3349bf90e2a52e7394935a0304
1 /* Definitions of target machine for GNU compiler, for IBM S/390
2 Copyright (C) 1999, 2000, 2001 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 2, 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 COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #ifdef L_fixunstfdi
25 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF)
26 #define EXPONENT_BIAS 16383
27 #define MANTISSA_BITS 112
28 #define PRECISION (MANTISSA_BITS + 1)
29 #define SIGNBIT 0x80000000
30 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT)
31 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT)
32 #define MANTD_LOW_LL(fp) (fp.ll[1])
33 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK))
34 #define HIGH_LL_FRAC_BITS 48
35 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS)
36 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1)
38 typedef int DItype_x __attribute__ ((mode (DI)));
39 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
40 typedef int SItype_x __attribute__ ((mode (SI)));
41 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
43 union double_long {
44 long double d;
45 struct {
46 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */
47 } l;
48 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */
51 UDItype_x __fixunstfdi (long double a1);
53 /* convert double to unsigned int */
54 UDItype_x
55 __fixunstfdi (long double a1)
57 register union double_long dl1;
58 register int exp;
59 register UDItype_x l;
61 dl1.d = a1;
63 /* +/- 0, denormalized, negative */
64 if (!EXPD (dl1) || SIGND(dl1))
65 return 0;
67 /* The exponent - considered the binary point at the right end of
68 the mantissa. */
69 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
71 /* number < 1: If the mantissa would need to be right-shifted more bits than
72 its size (plus the implied one bit on the left) the result would be
73 zero. */
74 if (exp <= -PRECISION)
75 return 0;
77 /* NaN: All exponent bits set and a non-zero fraction. */
78 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
79 return 0x0ULL;
81 /* If the upper ll part of the mantissa isn't
82 zeroed out after shifting the number would be to large. */
83 if (exp >= -HIGH_LL_FRAC_BITS)
84 return 0xFFFFFFFFFFFFFFFFULL;
86 exp += HIGH_LL_FRAC_BITS + 1;
88 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
89 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
91 return l >> -exp;
93 #define __fixunstfdi ___fixunstfdi
94 #endif
95 #undef L_fixunstfdi
97 #ifdef L_fixtfdi
98 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF)
99 #define EXPONENT_BIAS 16383
100 #define MANTISSA_BITS 112
101 #define PRECISION (MANTISSA_BITS + 1)
102 #define SIGNBIT 0x80000000
103 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT)
104 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT)
105 #define MANTD_LOW_LL(fp) (fp.ll[1])
106 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK))
107 #define HIGH_LL_FRAC_BITS 48
108 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS)
109 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1)
111 typedef int DItype_x __attribute__ ((mode (DI)));
112 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
113 typedef int SItype_x __attribute__ ((mode (SI)));
114 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
116 union double_long {
117 long double d;
118 struct {
119 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */
120 } l;
121 DItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */
124 DItype_x __fixtfdi (long double a1);
126 /* convert double to unsigned int */
127 DItype_x
128 __fixtfdi (long double a1)
130 register union double_long dl1;
131 register int exp;
132 register UDItype_x l;
134 dl1.d = a1;
136 /* +/- 0, denormalized */
137 if (!EXPD (dl1))
138 return 0;
140 /* The exponent - considered the binary point at the right end of
141 the mantissa. */
142 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
144 /* number < 1: If the mantissa would need to be right-shifted more bits than
145 its size the result would be zero. */
146 if (exp <= -PRECISION)
147 return 0;
149 /* NaN: All exponent bits set and a non-zero fraction. */
150 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
151 return 0x8000000000000000ULL;
153 /* If the upper ll part of the mantissa isn't
154 zeroed out after shifting the number would be to large. */
155 if (exp >= -HIGH_LL_FRAC_BITS)
157 l = (long long)1 << 63; /* long int min */
158 return SIGND (dl1) ? l : l - 1;
161 /* The extra bit is needed for the sign bit. */
162 exp += HIGH_LL_FRAC_BITS + 1;
164 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
165 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
167 return SIGND (dl1) ? -(l >> -exp) : l >> -exp;
169 #define __fixtfdi ___fixtfdi
170 #endif
171 #undef L_fixtfdi
173 #ifdef L_fixunsdfdi
174 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
175 #define EXCESSD 1022
176 #define SIGNBIT 0x80000000
177 #define SIGND(fp) ((fp.l.upper) & SIGNBIT)
178 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
179 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
180 #define HIDDEND_LL ((UDItype_x)1 << 52)
182 typedef int DItype_x __attribute__ ((mode (DI)));
183 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
184 typedef int SItype_x __attribute__ ((mode (SI)));
185 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
187 union double_long {
188 double d;
189 struct {
190 SItype_x upper;
191 USItype_x lower;
192 } l;
193 UDItype_x ll;
196 UDItype_x __fixunsdfdi (double a1);
198 /* convert double to unsigned int */
199 UDItype_x
200 __fixunsdfdi (double a1)
202 register union double_long dl1;
203 register int exp;
204 register UDItype_x l;
206 dl1.d = a1;
208 /* +/- 0, denormalized, negative */
210 if (!EXPD (dl1) || SIGND(dl1))
211 return 0;
213 exp = EXPD (dl1) - EXCESSD - 53;
215 /* number < 1 */
217 if (exp < -53)
218 return 0;
220 /* NaN */
222 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
223 return 0x0ULL;
225 /* Number big number & + inf */
227 if (exp >= 12) {
228 return 0xFFFFFFFFFFFFFFFFULL;
231 l = MANTD_LL(dl1);
233 /* shift down until exp < 12 or l = 0 */
234 if (exp > 0)
235 l <<= exp;
236 else
237 l >>= -exp;
239 return l;
241 #define __fixunsdfdi ___fixunsdfdi
242 #endif
243 #undef L_fixunsdfdi
245 #ifdef L_fixdfdi
246 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
247 #define EXCESSD 1022
248 #define SIGNBIT 0x80000000
249 #define SIGND(fp) ((fp.l.upper) & SIGNBIT)
250 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
251 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
252 #define HIDDEND_LL ((UDItype_x)1 << 52)
254 typedef int DItype_x __attribute__ ((mode (DI)));
255 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
256 typedef int SItype_x __attribute__ ((mode (SI)));
257 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
259 union double_long {
260 double d;
261 struct {
262 SItype_x upper;
263 USItype_x lower;
264 } l;
265 UDItype_x ll;
268 DItype_x __fixdfdi (double a1);
270 /* convert double to int */
271 DItype_x
272 __fixdfdi (double a1)
274 register union double_long dl1;
275 register int exp;
276 register DItype_x l;
278 dl1.d = a1;
280 /* +/- 0, denormalized */
282 if (!EXPD (dl1))
283 return 0;
285 exp = EXPD (dl1) - EXCESSD - 53;
287 /* number < 1 */
289 if (exp < -53)
290 return 0;
292 /* NaN */
294 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
295 return 0x8000000000000000ULL;
297 /* Number big number & +/- inf */
299 if (exp >= 11) {
300 l = (long long)1<<63;
301 if (!SIGND(dl1))
302 l--;
303 return l;
306 l = MANTD_LL(dl1);
308 /* shift down until exp < 12 or l = 0 */
309 if (exp > 0)
310 l <<= exp;
311 else
312 l >>= -exp;
314 return (SIGND (dl1) ? -l : l);
316 #define __fixdfdi ___fixdfdi
317 #endif
318 #undef L_fixdfdi
320 #ifdef L_fixunssfdi
321 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
322 #define EXCESS 126
323 #define SIGNBIT 0x80000000
324 #define SIGN(fp) ((fp.l) & SIGNBIT)
325 #define HIDDEN (1 << 23)
326 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
327 #define FRAC(fp) ((fp.l) & 0x7FFFFF)
329 typedef int DItype_x __attribute__ ((mode (DI)));
330 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
331 typedef int SItype_x __attribute__ ((mode (SI)));
332 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
334 union float_long
336 float f;
337 USItype_x l;
340 UDItype_x __fixunssfdi (float a1);
342 /* convert float to unsigned int */
343 UDItype_x
344 __fixunssfdi (float a1)
346 register union float_long fl1;
347 register int exp;
348 register UDItype_x l;
350 fl1.f = a1;
352 /* +/- 0, denormalized, negative */
354 if (!EXP (fl1) || SIGN(fl1))
355 return 0;
357 exp = EXP (fl1) - EXCESS - 24;
359 /* number < 1 */
361 if (exp < -24)
362 return 0;
364 /* NaN */
366 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
367 return 0x0ULL;
369 /* Number big number & + inf */
371 if (exp >= 41) {
372 return 0xFFFFFFFFFFFFFFFFULL;
375 l = MANT(fl1);
377 if (exp > 0)
378 l <<= exp;
379 else
380 l >>= -exp;
382 return l;
384 #define __fixunssfdi ___fixunssfdi
385 #endif
386 #undef L_fixunssfdi
388 #ifdef L_fixsfdi
389 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
390 #define EXCESS 126
391 #define SIGNBIT 0x80000000
392 #define SIGN(fp) ((fp.l) & SIGNBIT)
393 #define HIDDEN (1 << 23)
394 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
395 #define FRAC(fp) ((fp.l) & 0x7FFFFF)
397 typedef int DItype_x __attribute__ ((mode (DI)));
398 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
399 typedef int SItype_x __attribute__ ((mode (SI)));
400 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
402 union float_long
404 float f;
405 USItype_x l;
408 DItype_x __fixsfdi (float a1);
410 /* convert double to int */
411 DItype_x
412 __fixsfdi (float a1)
414 register union float_long fl1;
415 register int exp;
416 register DItype_x l;
418 fl1.f = a1;
420 /* +/- 0, denormalized */
422 if (!EXP (fl1))
423 return 0;
425 exp = EXP (fl1) - EXCESS - 24;
427 /* number < 1 */
429 if (exp < -24)
430 return 0;
432 /* NaN */
434 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
435 return 0x8000000000000000ULL;
437 /* Number big number & +/- inf */
439 if (exp >= 40) {
440 l = (long long)1<<63;
441 if (!SIGN(fl1))
442 l--;
443 return l;
446 l = MANT(fl1);
448 if (exp > 0)
449 l <<= exp;
450 else
451 l >>= -exp;
453 return (SIGN (fl1) ? -l : l);
455 #define __fixsfdi ___fixsfdi
456 #endif
457 #undef L_fixsfdi