Mercurial > hg > CbC > CbC_gcc
comparison libgcc/config/s390/32/_fixtfdi.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | 77e2b8dfacca |
children | 84e7813d76e9 |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
1 /* Definitions of target machine for GNU compiler, for IBM S/390 | 1 /* Definitions of target machine for GNU compiler, for IBM S/390 |
2 Copyright (C) 1999, 2000, 2001, 2007, 2008 and 2009 | 2 Copyright (C) 1999-2017 Free Software Foundation, Inc. |
3 Free Software Foundation, Inc. | |
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and | 3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and |
5 Ulrich Weigand (uweigand@de.ibm.com). | 4 Ulrich Weigand (uweigand@de.ibm.com). |
6 | 5 |
7 This file is part of GCC. | 6 This file is part of GCC. |
8 | 7 |
23 You should have received a copy of the GNU General Public License and | 22 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; | 23 a copy of the GCC Runtime Library Exception along with this program; |
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | 24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
26 <http://www.gnu.org/licenses/>. */ | 25 <http://www.gnu.org/licenses/>. */ |
27 | 26 |
27 #ifndef __s390x__ | |
28 | |
28 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) | 29 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) |
29 #define EXPONENT_BIAS 16383 | 30 #define EXPONENT_BIAS 16383 |
30 #define MANTISSA_BITS 112 | 31 #define MANTISSA_BITS 112 |
31 #define PRECISION (MANTISSA_BITS + 1) | 32 #define PRECISION (MANTISSA_BITS + 1) |
32 #define SIGNBIT 0x80000000 | 33 #define SIGNBIT 0x80000000 |
33 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT) | 34 #define SIGN(fp) ((fp.l.i[0]) & SIGNBIT) |
34 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) | 35 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) |
35 #define MANTD_LOW_LL(fp) (fp.ll[1]) | 36 #define MANTD_LOW_LL(fp) (fp.ll[1]) |
36 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) | 37 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) |
37 #define HIGH_LL_FRAC_BITS 48 | 38 #define HIGH_LL_FRAC_BITS 48 |
38 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) | 39 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) |
39 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) | 40 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) |
41 #define LLONG_MAX 9223372036854775807LL | |
42 #define LLONG_MIN (-LLONG_MAX - 1LL) | |
40 | 43 |
41 typedef int DItype_x __attribute__ ((mode (DI))); | 44 typedef int DItype_x __attribute__ ((mode (DI))); |
42 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | 45 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); |
43 typedef int SItype_x __attribute__ ((mode (SI))); | 46 typedef int SItype_x __attribute__ ((mode (SI))); |
44 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | 47 typedef unsigned int USItype_x __attribute__ ((mode (SI))); |
48 struct { | 51 struct { |
49 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ | 52 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ |
50 } l; | 53 } l; |
51 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ | 54 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ |
52 }; | 55 }; |
56 | |
57 static __inline__ void | |
58 fexceptdiv (float d, float e) | |
59 { | |
60 __asm__ __volatile__ ("debr %0,%1" : : "f" (d), "f" (e) ); | |
61 } | |
53 | 62 |
54 DItype_x __fixtfdi (long double a1); | 63 DItype_x __fixtfdi (long double a1); |
55 | 64 |
56 /* convert double to unsigned int */ | 65 /* convert double to unsigned int */ |
57 DItype_x | 66 DItype_x |
76 if (exp <= -PRECISION) | 85 if (exp <= -PRECISION) |
77 return 0; | 86 return 0; |
78 | 87 |
79 /* NaN: All exponent bits set and a nonzero fraction. */ | 88 /* NaN: All exponent bits set and a nonzero fraction. */ |
80 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) | 89 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) |
81 return 0x8000000000000000ULL; | 90 { |
91 /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ | |
92 fexceptdiv (0.0, 0.0); | |
93 return 0x8000000000000000ULL; | |
94 } | |
82 | 95 |
83 /* One extra bit is needed for the unit bit which is appended by | 96 /* One extra bit is needed for the unit bit which is appended by |
84 MANTD_HIGH_LL on the left of the matissa. */ | 97 MANTD_HIGH_LL on the left of the matissa. */ |
85 exp += HIGH_LL_FRAC_BITS + 1; | 98 exp += HIGH_LL_FRAC_BITS + 1; |
86 | 99 |
89 take care that there is still space for the sign bit to be | 102 take care that there is still space for the sign bit to be |
90 applied. So we can only go on if there is a right-shift by one | 103 applied. So we can only go on if there is a right-shift by one |
91 or more. */ | 104 or more. */ |
92 if (exp >= 0) | 105 if (exp >= 0) |
93 { | 106 { |
94 l = 1ULL << 63; /* long long min */ | 107 /* Don't throw an exception for -1p+63 */ |
95 return SIGND (dl1) ? l : l - 1; | 108 if (!SIGN (dl1) |
109 || exp > 0 | |
110 || MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) | |
111 || (dl1.ll[0] & HIGH_LL_FRAC_MASK)) | |
112 /* C99 Annex F.4 requires an "invalid" exception to be thrown. */ | |
113 fexceptdiv (0.0, 0.0); | |
114 return SIGN (dl1) ? LLONG_MIN : LLONG_MAX; | |
96 } | 115 } |
97 | 116 |
98 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) | 117 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) |
99 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); | 118 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); |
100 | 119 |
101 return SIGND (dl1) ? -(l >> -exp) : l >> -exp; | 120 return SIGN (dl1) ? -(l >> -exp) : l >> -exp; |
102 } | 121 } |
122 #endif /* !__s390x__ */ |