Debian Codegraph @

utils/pmx/pmx-src/libf2c/uninit.c

raw
1 #include <stdio.h>
2 #include <string.h>
3 #include "arith.h"
4
5 #define TYSHORT 2
6 #define TYLONG 3
7 #define TYREAL 4
8 #define TYDREAL 5
9 #define TYCOMPLEX 6
10 #define TYDCOMPLEX 7
11 #define TYINT1 11
12 #define TYQUAD 14
13 #ifndef Long
14 #define Long long
15 #endif
16
17 #ifdef __mips
18 #define RNAN 0xffc00000
19 #define DNAN0 0xfff80000
20 #define DNAN1 0
21 #endif
22
23 #ifdef _PA_RISC1_1
24 #define RNAN 0xffc00000
25 #define DNAN0 0xfff80000
26 #define DNAN1 0
27 #endif
28
29 #ifndef RNAN
30 #define RNAN 0xff800001
31 #ifdef IEEE_MC68k
32 #define DNAN0 0xfff00000
33 #define DNAN1 1
34 #else
35 #define DNAN0 1
36 #define DNAN1 0xfff00000
37 #endif
38 #endif /*RNAN*/
39
40 #ifdef KR_headers
41 #define Void /*void*/
42 #define FA7UL (unsigned Long) 0xfa7a7a7aL
43 #else
44 #define Void void
45 #define FA7UL 0xfa7a7a7aUL
46 #endif
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 static void ieee0(Void);
53
54 static unsigned Long rnan = RNAN,
55 dnan0 = DNAN0,
56 dnan1 = DNAN1;
57
58 double _0 = 0.;
59
60 void
61 #ifdef KR_headers
62 _uninit_f2c(x, type, len) void *x; int type; long len;
63 #else
64 _uninit_f2c(void *x, int type, long len)
65 #endif
66 {
67 static int first = 1;
68
69 unsigned Long *lx, *lxe;
70
71 if (first) {
72 first = 0;
73 ieee0();
74 }
75 if (len == 1)
76 switch(type) {
77 case TYINT1:
78 *(char*)x = 'Z';
79 return;
80 case TYSHORT:
81 *(short*)x = 0xfa7a;
82 break;
83 case TYLONG:
84 *(unsigned Long*)x = FA7UL;
85 return;
86 case TYQUAD:
87 case TYCOMPLEX:
88 case TYDCOMPLEX:
89 break;
90 case TYREAL:
91 *(unsigned Long*)x = rnan;
92 return;
93 case TYDREAL:
94 lx = (unsigned Long*)x;
95 lx[0] = dnan0;
96 lx[1] = dnan1;
97 return;
98 default:
99 printf("Surprise type %d in _uninit_f2c\n", type);
100 }
101 switch(type) {
102 case TYINT1:
103 memset(x, 'Z', len);
104 break;
105 case TYSHORT:
106 *(short*)x = 0xfa7a;
107 break;
108 case TYQUAD:
109 len *= 2;
110 /* no break */
111 case TYLONG:
112 lx = (unsigned Long*)x;
113 lxe = lx + len;
114 while(lx < lxe)
115 *lx++ = FA7UL;
116 break;
117 case TYCOMPLEX:
118 len *= 2;
119 /* no break */
120 case TYREAL:
121 lx = (unsigned Long*)x;
122 lxe = lx + len;
123 while(lx < lxe)
124 *lx++ = rnan;
125 break;
126 case TYDCOMPLEX:
127 len *= 2;
128 /* no break */
129 case TYDREAL:
130 lx = (unsigned Long*)x;
131 for(lxe = lx + 2*len; lx < lxe; lx += 2) {
132 lx[0] = dnan0;
133 lx[1] = dnan1;
134 }
135 }
136 }
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #ifndef MSpc
142 #ifdef MSDOS
143 #define MSpc
144 #else
145 #ifdef _WIN32
146 #define MSpc
147 #endif
148 #endif
149 #endif
150
151 #ifdef MSpc
152 #define IEEE0_done
153 #include "float.h"
154 #include "signal.h"
155
156 static void
157 ieee0(Void)
158 {
159 #ifndef __alpha
160 #ifndef EM_DENORMAL
161 #define EM_DENORMAL _EM_DENORMAL
162 #endif
163 #ifndef EM_UNDERFLOW
164 #define EM_UNDERFLOW _EM_UNDERFLOW
165 #endif
166 #ifndef EM_INEXACT
167 #define EM_INEXACT _EM_INEXACT
168 #endif
169 #ifndef MCW_EM
170 #define MCW_EM _MCW_EM
171 #endif
172 _control87(EM_DENORMAL | EM_UNDERFLOW | EM_INEXACT, MCW_EM);
173 #endif
174 /* With MS VC++, compiling and linking with -Zi will permit */
175 /* clicking to invoke the MS C++ debugger, which will show */
176 /* the point of error -- provided SIGFPE is SIG_DFL. */
177 signal(SIGFPE, SIG_DFL);
178 }
179 #endif /* MSpc */
180
181 #ifdef __mips /* must link with -lfpe */
182 #define IEEE0_done
183 /* code from Eric Grosse */
184 #include <stdlib.h>
185 #include <stdio.h>
186 #include "/usr/include/sigfpe.h" /* full pathname for lcc -N */
187 #include "/usr/include/sys/fpu.h"
188
189 static void
190 #ifdef KR_headers
191 ieeeuserhand(exception, val) unsigned exception[5]; int val[2];
192 #else
193 ieeeuserhand(unsigned exception[5], int val[2])
194 #endif
195 {
196 fflush(stdout);
197 fprintf(stderr,"ieee0() aborting because of ");
198 if(exception[0]==_OVERFL) fprintf(stderr,"overflow\n");
199 else if(exception[0]==_UNDERFL) fprintf(stderr,"underflow\n");
200 else if(exception[0]==_DIVZERO) fprintf(stderr,"divide by 0\n");
201 else if(exception[0]==_INVALID) fprintf(stderr,"invalid operation\n");
202 else fprintf(stderr,"\tunknown reason\n");
203 fflush(stderr);
204 abort();
205 }
206
207 static void
208 #ifdef KR_headers
209 ieeeuserhand2(j) unsigned int **j;
210 #else
211 ieeeuserhand2(unsigned int **j)
212 #endif
213 {
214 fprintf(stderr,"ieee0() aborting because of confusion\n");
215 abort();
216 }
217
218 static void
219 ieee0(Void)
220 {
221 int i;
222 for(i=1; i<=4; i++){
223 sigfpe_[i].count = 1000;
224 sigfpe_[i].trace = 1;
225 sigfpe_[i].repls = _USER_DETERMINED;
226 }
227 sigfpe_[1].repls = _ZERO; /* underflow */
228 handle_sigfpes( _ON,
229 _EN_UNDERFL|_EN_OVERFL|_EN_DIVZERO|_EN_INVALID,
230 ieeeuserhand,_ABORT_ON_ERROR,ieeeuserhand2);
231 }
232 #endif /* mips */
233
234 #ifdef __linux__
235 #define IEEE0_done
236 #include "fpu_control.h"
237
238 #ifdef __alpha__
239 #ifndef USE_setfpucw
240 #define __setfpucw(x) __fpu_control = (x)
241 #endif
242 #endif
243
244 #ifndef _FPU_SETCW
245 #undef Can_use__setfpucw
246 #define Can_use__setfpucw
247 #endif
248
249 static void
250 ieee0(Void)
251 {
252 #if (defined(__mc68000__) || defined(__mc68020__) || defined(mc68020) || defined (__mc68k__))
253 /* Reported 20010705 by Alan Bain <[email protected]> */
254 /* Note that IEEE 754 IOP (illegal operation) */
255 /* = Signaling NAN (SNAN) + operation error (OPERR). */
256 #ifdef Can_use__setfpucw /* Has __setfpucw gone missing from S.u.S.E. 6.3? */
257 __setfpucw(_FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL);
258 #else
259 __fpu_control = _FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL;
260 _FPU_SETCW(__fpu_control);
261 #endif
262
263 #elif (defined(__powerpc__)||defined(_ARCH_PPC)||defined(_ARCH_PWR)) /* !__mc68k__ */
264 /* Reported 20011109 by Alan Bain <[email protected]> */
265
266 #ifdef Can_use__setfpucw
267
268 /* The following is NOT a mistake -- the author of the fpu_control.h
269 for the PPC has erroneously defined IEEE mode to turn on exceptions
270 other than Inexact! Start from default then and turn on only the ones
271 which we want*/
272
273 __setfpucw(_FPU_DEFAULT + _FPU_MASK_IM+_FPU_MASK_OM+_FPU_MASK_UM);
274
275 #else /* PPC && !Can_use__setfpucw */
276
277 __fpu_control = _FPU_DEFAULT +_FPU_MASK_OM+_FPU_MASK_IM+_FPU_MASK_UM;
278 _FPU_SETCW(__fpu_control);
279
280 #endif /*Can_use__setfpucw*/
281
282 #else /* !(mc68000||powerpc) */
283
284 #ifdef _FPU_IEEE
285 #ifndef _FPU_EXTENDED /* e.g., ARM processor under Linux */
286 #define _FPU_EXTENDED 0
287 #endif
288 #ifndef _FPU_DOUBLE
289 #define _FPU_DOUBLE 0
290 #endif
291 #ifdef Can_use__setfpucw /* Has __setfpucw gone missing from S.u.S.E. 6.3? */
292 __setfpucw(_FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM);
293 #else
294 __fpu_control = _FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM;
295 _FPU_SETCW(__fpu_control);
296 #endif
297
298 #else /* !_FPU_IEEE */
299
300 fprintf(stderr, "\n%s\n%s\n%s\n%s\n",
301 "WARNING: _uninit_f2c in libf2c does not know how",
302 "to enable trapping on this system, so f2c's -trapuv",
303 "option will not detect uninitialized variables unless",
304 "you can enable trapping manually.");
305 fflush(stderr);
306
307 #endif /* _FPU_IEEE */
308 #endif /* __mc68k__ */
309 }
310 #endif /* __linux__ */
311
312 #ifdef __alpha
313 #ifndef IEEE0_done
314 #define IEEE0_done
315 #include <machine/fpu.h>
316 static void
317 ieee0(Void)
318 {
319 ieee_set_fp_control(IEEE_TRAP_ENABLE_INV);
320 }
321 #endif /*IEEE0_done*/
322 #endif /*__alpha*/
323
324 #ifdef __hpux
325 #define IEEE0_done
326 #define _INCLUDE_HPUX_SOURCE
327 #include <math.h>
328
329 #ifndef FP_X_INV
330 #include <fenv.h>
331 #define fpsetmask fesettrapenable
332 #define FP_X_INV FE_INVALID
333 #endif
334
335 static void
336 ieee0(Void)
337 {
338 fpsetmask(FP_X_INV);
339 }
340 #endif /*__hpux*/
341
342 #ifdef _AIX
343 #define IEEE0_done
344 #include <fptrap.h>
345
346 static void
347 ieee0(Void)
348 {
349 fp_enable(TRP_INVALID);
350 fp_trap(FP_TRAP_SYNC);
351 }
352 #endif /*_AIX*/
353
354 #ifdef __sun
355 #define IEEE0_done
356 #include <ieeefp.h>
357
358 static void
359 ieee0(Void)
360 {
361 fpsetmask(FP_X_INV);
362 }
363 #endif /*__sparc*/
364
365 #ifndef IEEE0_done
366 static void
367 ieee0(Void) {}
368 #endif