]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/s390/fixdfdi.h
host-hpux.c: Change copyright header to refer to version 3 of the GNU General Public...
[thirdparty/gcc.git] / gcc / config / s390 / fixdfdi.h
CommitLineData
f314b9b1 1/* Definitions of target machine for GNU compiler, for IBM S/390
2f83c7d6 2 Copyright (C) 1999, 2000, 2001, 2007 Free Software Foundation, Inc.
f314b9b1
UW
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 Ulrich Weigand (uweigand@de.ibm.com).
5
58add37a 6This file is part of GCC.
f314b9b1 7
58add37a
UW
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
2f83c7d6 10Software Foundation; either version 3, or (at your option) any later
58add37a 11version.
f314b9b1 12
58add37a
UW
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
f314b9b1
UW
17
18You should have received a copy of the GNU General Public License
2f83c7d6
NC
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
f314b9b1 21
f61a2c7d
AK
22#ifdef L_fixunstfdi
23
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)
36
37typedef int DItype_x __attribute__ ((mode (DI)));
38typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
39typedef int SItype_x __attribute__ ((mode (SI)));
40typedef unsigned int USItype_x __attribute__ ((mode (SI)));
41
42union 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 */
48};
49
50UDItype_x __fixunstfdi (long double a1);
51
52/* convert double to unsigned int */
53UDItype_x
54__fixunstfdi (long double a1)
55{
56 register union double_long dl1;
57 register int exp;
58 register UDItype_x l;
59
60 dl1.d = a1;
61
62 /* +/- 0, denormalized, negative */
63 if (!EXPD (dl1) || SIGND(dl1))
64 return 0;
65
66 /* The exponent - considered the binary point at the right end of
67 the mantissa. */
68 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
69
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;
75
917f1b7e 76 /* NaN: All exponent bits set and a nonzero fraction. */
f61a2c7d
AK
77 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
78 return 0x0ULL;
79
80 /* If the upper ll part of the mantissa isn't
81 zeroed out after shifting the number would be to large. */
82 if (exp >= -HIGH_LL_FRAC_BITS)
83 return 0xFFFFFFFFFFFFFFFFULL;
84
85 exp += HIGH_LL_FRAC_BITS + 1;
86
87 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
88 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
89
90 return l >> -exp;
91}
92#define __fixunstfdi ___fixunstfdi
93#endif
94#undef L_fixunstfdi
95
96#ifdef L_fixtfdi
97#define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF)
98#define EXPONENT_BIAS 16383
99#define MANTISSA_BITS 112
100#define PRECISION (MANTISSA_BITS + 1)
101#define SIGNBIT 0x80000000
102#define SIGND(fp) ((fp.l.i[0]) & SIGNBIT)
103#define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT)
104#define MANTD_LOW_LL(fp) (fp.ll[1])
105#define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK))
106#define HIGH_LL_FRAC_BITS 48
107#define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS)
108#define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1)
109
110typedef int DItype_x __attribute__ ((mode (DI)));
111typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
112typedef int SItype_x __attribute__ ((mode (SI)));
113typedef unsigned int USItype_x __attribute__ ((mode (SI)));
114
115union double_long {
116 long double d;
117 struct {
118 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */
119 } l;
120 DItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */
121};
122
123DItype_x __fixtfdi (long double a1);
124
125/* convert double to unsigned int */
126DItype_x
127__fixtfdi (long double a1)
128{
129 register union double_long dl1;
130 register int exp;
131 register UDItype_x l;
132
133 dl1.d = a1;
134
135 /* +/- 0, denormalized */
136 if (!EXPD (dl1))
137 return 0;
138
139 /* The exponent - considered the binary point at the right end of
140 the mantissa. */
141 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS;
142
143 /* number < 1: If the mantissa would need to be right-shifted more bits than
144 its size the result would be zero. */
145 if (exp <= -PRECISION)
146 return 0;
147
917f1b7e 148 /* NaN: All exponent bits set and a nonzero fraction. */
f61a2c7d
AK
149 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1))
150 return 0x8000000000000000ULL;
151
152 /* If the upper ll part of the mantissa isn't
153 zeroed out after shifting the number would be to large. */
154 if (exp >= -HIGH_LL_FRAC_BITS)
155 {
156 l = (long long)1 << 63; /* long int min */
157 return SIGND (dl1) ? l : l - 1;
158 }
159
160 /* The extra bit is needed for the sign bit. */
161 exp += HIGH_LL_FRAC_BITS + 1;
162
163 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1)
164 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1));
165
166 return SIGND (dl1) ? -(l >> -exp) : l >> -exp;
167}
168#define __fixtfdi ___fixtfdi
169#endif
170#undef L_fixtfdi
171
9db1d521
HP
172#ifdef L_fixunsdfdi
173#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
174#define EXCESSD 1022
175#define SIGNBIT 0x80000000
176#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
177#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
178#define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
f314b9b1
UW
179#define HIDDEND_LL ((UDItype_x)1 << 52)
180
181typedef int DItype_x __attribute__ ((mode (DI)));
182typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
183typedef int SItype_x __attribute__ ((mode (SI)));
184typedef unsigned int USItype_x __attribute__ ((mode (SI)));
9db1d521
HP
185
186union double_long {
187 double d;
188 struct {
f314b9b1
UW
189 SItype_x upper;
190 USItype_x lower;
9db1d521 191 } l;
f314b9b1 192 UDItype_x ll;
9db1d521
HP
193};
194
5d4d885c 195UDItype_x __fixunsdfdi (double a1);
9db1d521
HP
196
197/* convert double to unsigned int */
f314b9b1 198UDItype_x
9db1d521
HP
199__fixunsdfdi (double a1)
200{
201 register union double_long dl1;
202 register int exp;
f314b9b1 203 register UDItype_x l;
9db1d521
HP
204
205 dl1.d = a1;
206
aabcd309 207 /* +/- 0, denormalized, negative */
9db1d521
HP
208
209 if (!EXPD (dl1) || SIGND(dl1))
210 return 0;
211
212 exp = EXPD (dl1) - EXCESSD - 53;
213
214 /* number < 1 */
215
216 if (exp < -53)
217 return 0;
218
219 /* NaN */
220
221 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
222 return 0x0ULL;
223
224 /* Number big number & + inf */
225
226 if (exp >= 12) {
227 return 0xFFFFFFFFFFFFFFFFULL;
228 }
229
230 l = MANTD_LL(dl1);
231
232 /* shift down until exp < 12 or l = 0 */
233 if (exp > 0)
234 l <<= exp;
235 else
236 l >>= -exp;
237
238 return l;
239}
240#define __fixunsdfdi ___fixunsdfdi
241#endif
242#undef L_fixunsdfdi
243
244#ifdef L_fixdfdi
245#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
246#define EXCESSD 1022
247#define SIGNBIT 0x80000000
248#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
249#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
250#define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
f314b9b1
UW
251#define HIDDEND_LL ((UDItype_x)1 << 52)
252
253typedef int DItype_x __attribute__ ((mode (DI)));
254typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
255typedef int SItype_x __attribute__ ((mode (SI)));
256typedef unsigned int USItype_x __attribute__ ((mode (SI)));
9db1d521
HP
257
258union double_long {
259 double d;
260 struct {
f314b9b1
UW
261 SItype_x upper;
262 USItype_x lower;
9db1d521 263 } l;
f314b9b1 264 UDItype_x ll;
9db1d521
HP
265};
266
5d4d885c
UW
267DItype_x __fixdfdi (double a1);
268
9db1d521 269/* convert double to int */
f314b9b1 270DItype_x
9db1d521
HP
271__fixdfdi (double a1)
272{
273 register union double_long dl1;
274 register int exp;
f314b9b1 275 register DItype_x l;
9db1d521
HP
276
277 dl1.d = a1;
278
279 /* +/- 0, denormalized */
280
281 if (!EXPD (dl1))
282 return 0;
283
284 exp = EXPD (dl1) - EXCESSD - 53;
285
286 /* number < 1 */
287
288 if (exp < -53)
289 return 0;
290
291 /* NaN */
292
293 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
294 return 0x8000000000000000ULL;
295
296 /* Number big number & +/- inf */
297
298 if (exp >= 11) {
299 l = (long long)1<<63;
300 if (!SIGND(dl1))
301 l--;
302 return l;
303 }
304
305 l = MANTD_LL(dl1);
306
307 /* shift down until exp < 12 or l = 0 */
308 if (exp > 0)
309 l <<= exp;
310 else
311 l >>= -exp;
312
313 return (SIGND (dl1) ? -l : l);
314}
315#define __fixdfdi ___fixdfdi
316#endif
317#undef L_fixdfdi
318
f314b9b1
UW
319#ifdef L_fixunssfdi
320#define EXP(fp) (((fp.l) >> 23) & 0xFF)
321#define EXCESS 126
322#define SIGNBIT 0x80000000
323#define SIGN(fp) ((fp.l) & SIGNBIT)
324#define HIDDEN (1 << 23)
325#define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
326#define FRAC(fp) ((fp.l) & 0x7FFFFF)
327
328typedef int DItype_x __attribute__ ((mode (DI)));
329typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
330typedef int SItype_x __attribute__ ((mode (SI)));
331typedef unsigned int USItype_x __attribute__ ((mode (SI)));
332
333union float_long
334 {
335 float f;
336 USItype_x l;
337 };
338
5d4d885c
UW
339UDItype_x __fixunssfdi (float a1);
340
f314b9b1
UW
341/* convert float to unsigned int */
342UDItype_x
343__fixunssfdi (float a1)
344{
345 register union float_long fl1;
346 register int exp;
347 register UDItype_x l;
348
349 fl1.f = a1;
350
aabcd309 351 /* +/- 0, denormalized, negative */
f314b9b1
UW
352
353 if (!EXP (fl1) || SIGN(fl1))
354 return 0;
355
356 exp = EXP (fl1) - EXCESS - 24;
357
358 /* number < 1 */
359
360 if (exp < -24)
361 return 0;
362
363 /* NaN */
364
365 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
366 return 0x0ULL;
367
368 /* Number big number & + inf */
369
370 if (exp >= 41) {
371 return 0xFFFFFFFFFFFFFFFFULL;
372 }
373
374 l = MANT(fl1);
375
376 if (exp > 0)
377 l <<= exp;
378 else
379 l >>= -exp;
380
381 return l;
382}
383#define __fixunssfdi ___fixunssfdi
384#endif
385#undef L_fixunssfdi
386
387#ifdef L_fixsfdi
388#define EXP(fp) (((fp.l) >> 23) & 0xFF)
389#define EXCESS 126
390#define SIGNBIT 0x80000000
391#define SIGN(fp) ((fp.l) & SIGNBIT)
392#define HIDDEN (1 << 23)
393#define MANT(fp) (((fp.l) & 0x7FFFFF) | HIDDEN)
394#define FRAC(fp) ((fp.l) & 0x7FFFFF)
395
396typedef int DItype_x __attribute__ ((mode (DI)));
397typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
398typedef int SItype_x __attribute__ ((mode (SI)));
399typedef unsigned int USItype_x __attribute__ ((mode (SI)));
400
401union float_long
402 {
403 float f;
404 USItype_x l;
405 };
406
5d4d885c
UW
407DItype_x __fixsfdi (float a1);
408
f314b9b1
UW
409/* convert double to int */
410DItype_x
411__fixsfdi (float a1)
412{
413 register union float_long fl1;
414 register int exp;
415 register DItype_x l;
416
417 fl1.f = a1;
418
419 /* +/- 0, denormalized */
420
421 if (!EXP (fl1))
422 return 0;
423
424 exp = EXP (fl1) - EXCESS - 24;
425
426 /* number < 1 */
427
428 if (exp < -24)
429 return 0;
430
431 /* NaN */
432
433 if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
434 return 0x8000000000000000ULL;
435
436 /* Number big number & +/- inf */
437
438 if (exp >= 40) {
439 l = (long long)1<<63;
440 if (!SIGN(fl1))
441 l--;
442 return l;
443 }
444
445 l = MANT(fl1);
446
447 if (exp > 0)
448 l <<= exp;
449 else
450 l >>= -exp;
451
452 return (SIGN (fl1) ? -l : l);
453}
454#define __fixsfdi ___fixsfdi
455#endif
456#undef L_fixsfdi