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