No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gcc4 / gcc / config / s390 / fixdfdi.h
blob95a5eef0173790b9b5fc6c335e0876ecf3291a8f
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 /* One extra bit is needed for the unit bit which is appended by
82 MANTD_HIGH_LL on the left of the matissa. */
83 exp += HIGH_LL_FRAC_BITS + 1;
85 /* If the result would still need a left shift it will be to large
86 to be represented. */
87 if (exp > 0)
88 return 0xFFFFFFFFFFFFFFFFULL;
90 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
91 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
93 return l >> -exp;
95 #define __fixunstfdi ___fixunstfdi
96 #endif
97 #undef L_fixunstfdi
99 #ifdef L_fixtfdi
100 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF)
101 #define EXPONENT_BIAS 16383
102 #define MANTISSA_BITS 112
103 #define PRECISION (MANTISSA_BITS + 1)
104 #define SIGNBIT 0x80000000
105 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT)
106 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT)
107 #define MANTD_LOW_LL(fp) (fp.ll[1])
108 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK))
109 #define HIGH_LL_FRAC_BITS 48
110 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS)
111 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1)
113 typedef int DItype_x __attribute__ ((mode (DI)));
114 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
115 typedef int SItype_x __attribute__ ((mode (SI)));
116 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
118 union double_long {
119 long double d;
120 struct {
121 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */
122 } l;
123 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */
126 DItype_x __fixtfdi (long double a1);
128 /* convert double to unsigned int */
129 DItype_x
130 __fixtfdi (long double a1)
132 register union double_long dl1;
133 register int exp;
134 register UDItype_x l;
136 dl1.d = a1;
138 /* +/- 0, denormalized */
139 if (!EXPD (dl1))
140 return 0;
142 /* The exponent - considered the binary point at the right end of
143 the mantissa. */
144 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
146 /* number < 1: If the mantissa would need to be right-shifted more bits than
147 its size the result would be zero. */
148 if (exp <= -PRECISION)
149 return 0;
151 /* NaN: All exponent bits set and a non-zero fraction. */
152 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
153 return 0x8000000000000000ULL;
155 /* One extra bit is needed for the unit bit which is appended by
156 MANTD_HIGH_LL on the left of the matissa. */
157 exp += HIGH_LL_FRAC_BITS + 1;
159 /* If the result would still need a left shift it will be to large
160 to be represented. Compared to the unsigned variant we have to
161 take care that there is still space for the sign bit to be
162 applied. So we can only go on if there is a right-shift by one
163 or more. */
164 if (exp >= 0)
166 l = (long long)1 << 63; /* long long int min */
167 return SIGND (dl1) ? l : l - 1;
170 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
171 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
173 return SIGND (dl1) ? -(l >> -exp) : l >> -exp;
175 #define __fixtfdi ___fixtfdi
176 #endif
177 #undef L_fixtfdi
179 #ifdef L_fixunsdfdi
180 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
181 #define EXCESSD 1022
182 #define SIGNBIT 0x80000000
183 #define SIGND(fp) ((fp.l.upper) & SIGNBIT)
184 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
185 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
186 #define HIDDEND_LL ((UDItype_x)1 << 52)
188 typedef int DItype_x __attribute__ ((mode (DI)));
189 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
190 typedef int SItype_x __attribute__ ((mode (SI)));
191 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
193 union double_long {
194 double d;
195 struct {
196 SItype_x upper;
197 USItype_x lower;
198 } l;
199 UDItype_x ll;
202 UDItype_x __fixunsdfdi (double a1);
204 /* convert double to unsigned int */
205 UDItype_x
206 __fixunsdfdi (double a1)
208 register union double_long dl1;
209 register int exp;
210 register UDItype_x l;
212 dl1.d = a1;
214 /* +/- 0, denormalized, negative */
216 if (!EXPD (dl1) || SIGND(dl1))
217 return 0;
219 exp = EXPD (dl1) - EXCESSD - 53;
221 /* number < 1 */
223 if (exp < -53)
224 return 0;
226 /* NaN */
228 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
229 return 0x0ULL;
231 /* Number big number & + inf */
233 if (exp >= 12) {
234 return 0xFFFFFFFFFFFFFFFFULL;
237 l = MANTD_LL(dl1);
239 /* shift down until exp < 12 or l = 0 */
240 if (exp > 0)
241 l <<= exp;
242 else
243 l >>= -exp;
245 return l;
247 #define __fixunsdfdi ___fixunsdfdi
248 #endif
249 #undef L_fixunsdfdi
251 #ifdef L_fixdfdi
252 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
253 #define EXCESSD 1022
254 #define SIGNBIT 0x80000000
255 #define SIGND(fp) ((fp.l.upper) & SIGNBIT)
256 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
257 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
258 #define HIDDEND_LL ((UDItype_x)1 << 52)
260 typedef int DItype_x __attribute__ ((mode (DI)));
261 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
262 typedef int SItype_x __attribute__ ((mode (SI)));
263 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
265 union double_long {
266 double d;
267 struct {
268 SItype_x upper;
269 USItype_x lower;
270 } l;
271 UDItype_x ll;
274 DItype_x __fixdfdi (double a1);
276 /* convert double to int */
277 DItype_x
278 __fixdfdi (double a1)
280 register union double_long dl1;
281 register int exp;
282 register DItype_x l;
284 dl1.d = a1;
286 /* +/- 0, denormalized */
288 if (!EXPD (dl1))
289 return 0;
291 exp = EXPD (dl1) - EXCESSD - 53;
293 /* number < 1 */
295 if (exp < -53)
296 return 0;
298 /* NaN */
300 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
301 return 0x8000000000000000ULL;
303 /* Number big number & +/- inf */
305 if (exp >= 11) {
306 l = (long long)1<<63;
307 if (!SIGND(dl1))
308 l--;
309 return l;
312 l = MANTD_LL(dl1);
314 /* shift down until exp < 12 or l = 0 */
315 if (exp > 0)
316 l <<= exp;
317 else
318 l >>= -exp;
320 return (SIGND (dl1) ? -l : l);
322 #define __fixdfdi ___fixdfdi
323 #endif
324 #undef L_fixdfdi
326 #ifdef L_fixunssfdi
327 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
328 #define EXCESS 126
329 #define SIGNBIT 0x80000000
330 #define SIGN(fp) ((fp.l) & SIGNBIT)
331 #define HIDDEN (1 << 23)
332 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
333 #define FRAC(fp) ((fp.l) & 0x7FFFFF)
335 typedef int DItype_x __attribute__ ((mode (DI)));
336 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
337 typedef int SItype_x __attribute__ ((mode (SI)));
338 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
340 union float_long
342 float f;
343 USItype_x l;
346 UDItype_x __fixunssfdi (float a1);
348 /* convert float to unsigned int */
349 UDItype_x
350 __fixunssfdi (float a1)
352 register union float_long fl1;
353 register int exp;
354 register UDItype_x l;
356 fl1.f = a1;
358 /* +/- 0, denormalized, negative */
360 if (!EXP (fl1) || SIGN(fl1))
361 return 0;
363 exp = EXP (fl1) - EXCESS - 24;
365 /* number < 1 */
367 if (exp < -24)
368 return 0;
370 /* NaN */
372 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
373 return 0x0ULL;
375 /* Number big number & + inf */
377 if (exp >= 41) {
378 return 0xFFFFFFFFFFFFFFFFULL;
381 l = MANT(fl1);
383 if (exp > 0)
384 l <<= exp;
385 else
386 l >>= -exp;
388 return l;
390 #define __fixunssfdi ___fixunssfdi
391 #endif
392 #undef L_fixunssfdi
394 #ifdef L_fixsfdi
395 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
396 #define EXCESS 126
397 #define SIGNBIT 0x80000000
398 #define SIGN(fp) ((fp.l) & SIGNBIT)
399 #define HIDDEN (1 << 23)
400 #define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
401 #define FRAC(fp) ((fp.l) & 0x7FFFFF)
403 typedef int DItype_x __attribute__ ((mode (DI)));
404 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
405 typedef int SItype_x __attribute__ ((mode (SI)));
406 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
408 union float_long
410 float f;
411 USItype_x l;
414 DItype_x __fixsfdi (float a1);
416 /* convert double to int */
417 DItype_x
418 __fixsfdi (float a1)
420 register union float_long fl1;
421 register int exp;
422 register DItype_x l;
424 fl1.f = a1;
426 /* +/- 0, denormalized */
428 if (!EXP (fl1))
429 return 0;
431 exp = EXP (fl1) - EXCESS - 24;
433 /* number < 1 */
435 if (exp < -24)
436 return 0;
438 /* NaN */
440 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
441 return 0x8000000000000000ULL;
443 /* Number big number & +/- inf */
445 if (exp >= 40) {
446 l = (long long)1<<63;
447 if (!SIGN(fl1))
448 l--;
449 return l;
452 l = MANT(fl1);
454 if (exp > 0)
455 l <<= exp;
456 else
457 l >>= -exp;
459 return (SIGN (fl1) ? -l : l);
461 #define __fixsfdi ___fixsfdi
462 #endif
463 #undef L_fixsfdi