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
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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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
)));
45 SItype_x i
[4]; /* 32 bit parts: 0 upper ... 3 lowest */
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 */
54 __fixunstfdi (long double a1
)
56 register union double_long dl1
;
62 /* +/- 0, denormalized, negative */
63 if (!EXPD (dl1
) || SIGND(dl1
))
66 /* The exponent - considered the binary point at the right end of
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
73 if (exp
<= -PRECISION
)
76 /* NaN: All exponent bits set and a nonzero fraction. */
77 if ((EXPD(dl1
) == 0x7fff) && !FRACD_ZERO_P (dl1
))
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
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));
94 #define __fixunstfdi ___fixunstfdi
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
)));
120 SItype_x i
[4]; /* 32 bit parts: 0 upper ... 3 lowest */
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 */
129 __fixtfdi (long double a1
)
131 register union double_long dl1
;
133 register UDItype_x l
;
137 /* +/- 0, denormalized */
141 /* The exponent - considered the binary point at the right end of
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
)
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
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
179 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
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
)));
201 UDItype_x
__fixunsdfdi (double a1
);
203 /* convert double to unsigned int */
205 __fixunsdfdi (double a1
)
207 register union double_long dl1
;
209 register UDItype_x l
;
213 /* +/- 0, denormalized, negative */
215 if (!EXPD (dl1
) || SIGND(dl1
))
218 exp
= EXPD (dl1
) - EXCESSD
- 53;
227 if ((EXPD(dl1
) == 0x7ff) && (FRACD_LL(dl1
) != 0)) /* NaN */
230 /* Number big number & + inf */
233 return 0xFFFFFFFFFFFFFFFFULL
;
238 /* shift down until exp < 12 or l = 0 */
246 #define __fixunsdfdi ___fixunsdfdi
251 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
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
)));
273 DItype_x
__fixdfdi (double a1
);
275 /* convert double to int */
277 __fixdfdi (double a1
)
279 register union double_long dl1
;
285 /* +/- 0, denormalized */
290 exp
= EXPD (dl1
) - EXCESSD
- 53;
299 if ((EXPD(dl1
) == 0x7ff) && (FRACD_LL(dl1
) != 0)) /* NaN */
300 return 0x8000000000000000ULL
;
302 /* Number big number & +/- inf */
305 l
= (long long)1<<63;
313 /* shift down until exp < 12 or l = 0 */
319 return (SIGND (dl1
) ? -l
: l
);
321 #define __fixdfdi ___fixdfdi
326 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
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
)));
345 UDItype_x
__fixunssfdi (float a1
);
347 /* convert float to unsigned int */
349 __fixunssfdi (float a1
)
351 register union float_long fl1
;
353 register UDItype_x l
;
357 /* +/- 0, denormalized, negative */
359 if (!EXP (fl1
) || SIGN(fl1
))
362 exp
= EXP (fl1
) - EXCESS
- 24;
371 if ((EXP(fl1
) == 0xff) && (FRAC(fl1
) != 0)) /* NaN */
374 /* Number big number & + inf */
377 return 0xFFFFFFFFFFFFFFFFULL
;
389 #define __fixunssfdi ___fixunssfdi
394 #define EXP(fp) (((fp.l) >> 23) & 0xFF)
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
)));
413 DItype_x
__fixsfdi (float a1
);
415 /* convert double to int */
419 register union float_long fl1
;
425 /* +/- 0, denormalized */
430 exp
= EXP (fl1
) - EXCESS
- 24;
439 if ((EXP(fl1
) == 0xff) && (FRAC(fl1
) != 0)) /* NaN */
440 return 0x8000000000000000ULL
;
442 /* Number big number & +/- inf */
445 l
= (long long)1<<63;
458 return (SIGN (fl1
) ? -l
: l
);
460 #define __fixsfdi ___fixsfdi