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
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
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
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
)));
46 SItype_x i
[4]; /* 32 bit parts: 0 upper ... 3 lowest */
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 */
55 __fixunstfdi (long double a1
)
57 register union double_long dl1
;
63 /* +/- 0, denormalized, negative */
64 if (!EXPD (dl1
) || SIGND(dl1
))
67 /* The exponent - considered the binary point at the right end of
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
74 if (exp
<= -PRECISION
)
77 /* NaN: All exponent bits set and a non-zero fraction. */
78 if ((EXPD(dl1
) == 0x7fff) && !FRACD_ZERO_P (dl1
))
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
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));
95 #define __fixunstfdi ___fixunstfdi
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
)));
121 SItype_x i
[4]; /* 32 bit parts: 0 upper ... 3 lowest */
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 */
130 __fixtfdi (long double a1
)
132 register union double_long dl1
;
134 register UDItype_x l
;
138 /* +/- 0, denormalized */
142 /* The exponent - considered the binary point at the right end of
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
)
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
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
180 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
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
)));
202 UDItype_x
__fixunsdfdi (double a1
);
204 /* convert double to unsigned int */
206 __fixunsdfdi (double a1
)
208 register union double_long dl1
;
210 register UDItype_x l
;
214 /* +/- 0, denormalized, negative */
216 if (!EXPD (dl1
) || SIGND(dl1
))
219 exp
= EXPD (dl1
) - EXCESSD
- 53;
228 if ((EXPD(dl1
) == 0x7ff) && (FRACD_LL(dl1
) != 0)) /* NaN */
231 /* Number big number & + inf */
234 return 0xFFFFFFFFFFFFFFFFULL
;
239 /* shift down until exp < 12 or l = 0 */
247 #define __fixunsdfdi ___fixunsdfdi
252 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
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
)));
274 DItype_x
__fixdfdi (double a1
);
276 /* convert double to int */
278 __fixdfdi (double a1
)
280 register union double_long dl1
;
286 /* +/- 0, denormalized */
291 exp
= EXPD (dl1
) - EXCESSD
- 53;
300 if ((EXPD(dl1
) == 0x7ff) && (FRACD_LL(dl1
) != 0)) /* NaN */
301 return 0x8000000000000000ULL
;
303 /* Number big number & +/- inf */
306 l
= (long long)1<<63;
314 /* shift down until exp < 12 or l = 0 */
320 return (SIGND (dl1
) ? -l
: l
);
322 #define __fixdfdi ___fixdfdi
327 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
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
)));
346 UDItype_x
__fixunssfdi (float a1
);
348 /* convert float to unsigned int */
350 __fixunssfdi (float a1
)
352 register union float_long fl1
;
354 register UDItype_x l
;
358 /* +/- 0, denormalized, negative */
360 if (!EXP (fl1
) || SIGN(fl1
))
363 exp
= EXP (fl1
) - EXCESS
- 24;
372 if ((EXP(fl1
) == 0xff) && (FRAC(fl1
) != 0)) /* NaN */
375 /* Number big number & + inf */
378 return 0xFFFFFFFFFFFFFFFFULL
;
390 #define __fixunssfdi ___fixunssfdi
395 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
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
)));
414 DItype_x
__fixsfdi (float a1
);
416 /* convert double to int */
420 register union float_long fl1
;
426 /* +/- 0, denormalized */
431 exp
= EXP (fl1
) - EXCESS
- 24;
440 if ((EXP(fl1
) == 0xff) && (FRAC(fl1
) != 0)) /* NaN */
441 return 0x8000000000000000ULL
;
443 /* Number big number & +/- inf */
446 l
= (long long)1<<63;
459 return (SIGN (fl1
) ? -l
: l
);
461 #define __fixsfdi ___fixsfdi