OSDN Git Service

* arc.c (output_shift): Use stdio instead of asm_fprintf.
[pf3gnuchains/gcc-fork.git] / gcc / config / s390 / fixdfdi.h
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).
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */ 
22
23 #ifdef L_fixunsdfdi
24 #define EXPD(fp)        (((fp.l.upper) >> 20) & 0x7FF)
25 #define EXCESSD         1022
26 #define SIGNBIT         0x80000000
27 #define SIGND(fp)       ((fp.l.upper) & SIGNBIT)
28 #define MANTD_LL(fp)    ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
29 #define FRACD_LL(fp)    (fp.ll & (HIDDEND_LL-1))
30 #define HIDDEND_LL      ((UDItype_x)1 << 52)
31
32 typedef int DItype_x __attribute__ ((mode (DI)));
33 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
34 typedef int SItype_x __attribute__ ((mode (SI)));
35 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
36
37 union double_long {
38     double d;
39     struct {
40       SItype_x upper;
41       USItype_x lower;
42     } l;
43     UDItype_x ll;
44 };
45
46
47 /* convert double to unsigned int */
48 UDItype_x
49 __fixunsdfdi (double a1)
50 {
51     register union double_long dl1;
52     register int exp;
53     register UDItype_x l;
54
55     dl1.d = a1;
56
57     /* +/- 0, denormalized, negativ */
58
59     if (!EXPD (dl1) || SIGND(dl1))
60       return 0;
61
62     exp = EXPD (dl1) - EXCESSD - 53;
63
64     /* number < 1 */
65
66     if (exp < -53)
67       return 0;
68
69     /* NaN */
70
71     if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
72       return 0x0ULL;
73
74     /* Number big number & + inf */
75
76     if (exp >= 12) {
77       return 0xFFFFFFFFFFFFFFFFULL;
78     }
79
80     l = MANTD_LL(dl1);
81
82     /* shift down until exp < 12 or l = 0 */
83     if (exp > 0)
84       l <<= exp;
85     else 
86       l >>= -exp;
87
88     return l;
89 }
90 #define __fixunsdfdi ___fixunsdfdi
91 #endif
92 #undef L_fixunsdfdi
93
94 #ifdef L_fixdfdi
95 #define EXPD(fp)        (((fp.l.upper) >> 20) & 0x7FF)
96 #define EXCESSD         1022
97 #define SIGNBIT         0x80000000
98 #define SIGND(fp)       ((fp.l.upper) & SIGNBIT)
99 #define MANTD_LL(fp)    ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
100 #define FRACD_LL(fp)    (fp.ll & (HIDDEND_LL-1))
101 #define HIDDEND_LL      ((UDItype_x)1 << 52)
102
103 typedef int DItype_x __attribute__ ((mode (DI)));
104 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
105 typedef int SItype_x __attribute__ ((mode (SI)));
106 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
107
108 union double_long {
109     double d;
110     struct {
111       SItype_x upper;
112       USItype_x lower;
113     } l;
114     UDItype_x ll;
115 };
116
117 /* convert double to int */
118 DItype_x
119 __fixdfdi (double a1)
120 {
121     register union double_long dl1;
122     register int exp;
123     register DItype_x l;
124
125     dl1.d = a1;
126
127     /* +/- 0, denormalized */
128
129     if (!EXPD (dl1))
130       return 0;
131
132     exp = EXPD (dl1) - EXCESSD - 53;
133
134     /* number < 1 */
135
136     if (exp < -53)
137       return 0;
138
139     /* NaN */
140
141     if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
142       return 0x8000000000000000ULL;
143
144     /* Number big number & +/- inf */
145
146     if (exp >= 11) {
147         l = (long long)1<<63;
148         if (!SIGND(dl1))
149             l--;
150         return l;
151     }
152
153     l = MANTD_LL(dl1);
154
155     /* shift down until exp < 12 or l = 0 */
156     if (exp > 0)
157       l <<= exp;
158     else 
159       l >>= -exp;
160
161     return (SIGND (dl1) ? -l : l);
162 }
163 #define __fixdfdi ___fixdfdi
164 #endif
165 #undef L_fixdfdi
166
167 #ifdef L_fixunssfdi
168 #define EXP(fp)         (((fp.l) >> 23) & 0xFF)
169 #define EXCESS          126
170 #define SIGNBIT         0x80000000
171 #define SIGN(fp)        ((fp.l) & SIGNBIT)
172 #define HIDDEN          (1 << 23)
173 #define MANT(fp)        (((fp.l) & 0x7FFFFF) | HIDDEN)
174 #define FRAC(fp)        ((fp.l) & 0x7FFFFF)
175
176 typedef int DItype_x __attribute__ ((mode (DI)));
177 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
178 typedef int SItype_x __attribute__ ((mode (SI)));
179 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
180
181 union float_long
182   {
183     float f;
184     USItype_x l;
185   };
186
187 /* convert float to unsigned int */
188 UDItype_x
189 __fixunssfdi (float a1)
190 {
191     register union float_long fl1;
192     register int exp;
193     register UDItype_x l;
194
195     fl1.f = a1;
196
197     /* +/- 0, denormalized, negativ */
198
199     if (!EXP (fl1) || SIGN(fl1))
200       return 0;
201
202     exp = EXP (fl1) - EXCESS - 24;
203
204     /* number < 1 */
205
206     if (exp < -24)
207       return 0;
208
209     /* NaN */
210
211     if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
212       return 0x0ULL;
213
214     /* Number big number & + inf */
215
216     if (exp >= 41) {
217       return 0xFFFFFFFFFFFFFFFFULL;
218     }
219
220     l = MANT(fl1);
221
222     if (exp > 0)
223       l <<= exp;
224     else 
225       l >>= -exp;
226
227     return l;
228 }
229 #define __fixunssfdi ___fixunssfdi
230 #endif
231 #undef L_fixunssfdi
232
233 #ifdef L_fixsfdi
234 #define EXP(fp)         (((fp.l) >> 23) & 0xFF)
235 #define EXCESS          126
236 #define SIGNBIT         0x80000000
237 #define SIGN(fp)        ((fp.l) & SIGNBIT)
238 #define HIDDEN          (1 << 23)
239 #define MANT(fp)        (((fp.l) & 0x7FFFFF) | HIDDEN)
240 #define FRAC(fp)        ((fp.l) & 0x7FFFFF)
241
242 typedef int DItype_x __attribute__ ((mode (DI)));
243 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
244 typedef int SItype_x __attribute__ ((mode (SI)));
245 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
246
247 union float_long
248   {
249     float f;
250     USItype_x l;
251   };
252
253 /* convert double to int */
254 DItype_x
255 __fixsfdi (float a1)
256 {
257     register union float_long fl1;
258     register int exp;
259     register DItype_x l;
260
261     fl1.f = a1;
262
263     /* +/- 0, denormalized */
264
265     if (!EXP (fl1))
266       return 0;
267
268     exp = EXP (fl1) - EXCESS - 24;
269
270     /* number < 1 */
271
272     if (exp < -24)
273       return 0;
274
275     /* NaN */
276
277     if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
278       return 0x8000000000000000ULL;
279
280     /* Number big number & +/- inf */
281
282     if (exp >= 40) {
283         l = (long long)1<<63;
284         if (!SIGN(fl1))
285             l--;
286         return l;
287     }
288
289     l = MANT(fl1);
290
291     if (exp > 0)
292       l <<= exp;
293     else 
294       l >>= -exp;
295
296     return (SIGN (fl1) ? -l : l);
297 }
298 #define __fixsfdi ___fixsfdi
299 #endif
300 #undef L_fixsfdi
301