Debian Codegraph @

debian/external_deps/fetk/punc/src/vf2c/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 #if defined (__mips) && !defined (__linux__) /* 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 #if defined(__riscv) && defined(__riscv_xlen) && __riscv_xlen == 64
239 /* Masks for riscv64 interrupts. */
240 #define _FPU_MASK_V 0x0800 /* Invalid operation */
241 #define _FPU_MASK_Z 0x0400 /* Division by zero */
242 #define _FPU_MASK_O 0x0200 /* Overflow */
243 #define _FPU_MASK_U 0x0100 /* Underflow */
244 #define _FPU_MASK_I 0x0080 /* Inexact operation */
245 #endif
246
247 #ifdef __alpha__
248 #ifndef USE_setfpucw
249 #define __setfpucw(x) __fpu_control = (x)
250 #endif
251 #endif
252
253 #ifndef _FPU_SETCW
254 #undef Can_use__setfpucw
255 #define Can_use__setfpucw
256 #endif
257
258 static void
259 ieee0(Void)
260 {
261 #if (defined(__mc68000__) || defined(__mc68020__) || defined(mc68020) || defined (__mc68k__))
262 /* Reported 20010705 by Alan Bain <[email protected]> */
263 /* Note that IEEE 754 IOP (illegal operation) */
264 /* = Signaling NAN (SNAN) + operation error (OPERR). */
265 #ifdef Can_use__setfpucw
266 __setfpucw(_FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL);
267 #else
268 __fpu_control = _FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL;
269 _FPU_SETCW(__fpu_control);
270 #endif
271
272 #elif (defined(__powerpc__)||defined(_ARCH_PPC)||defined(_ARCH_PWR)) /* !__mc68k__ */
273 /* Reported 20011109 by Alan Bain <[email protected]> */
274
275 #ifdef Can_use__setfpucw
276
277 /* The following is NOT a mistake -- the author of the fpu_control.h
278 for the PPC has erroneously defined IEEE mode to turn on exceptions
279 other than Inexact! Start from default then and turn on only the ones
280 which we want*/
281
282 __setfpucw(_FPU_DEFAULT + _FPU_MASK_IM+_FPU_MASK_OM+_FPU_MASK_UM);
283
284 #else /* PPC && !Can_use__setfpucw */
285
286 __fpu_control = _FPU_DEFAULT +_FPU_MASK_OM+_FPU_MASK_IM+_FPU_MASK_UM;
287 _FPU_SETCW(__fpu_control);
288
289 #endif /*Can_use__setfpucw*/
290
291 #else /* !(mc68000||powerpc) */
292
293 #ifdef _FPU_IEEE
294 #ifndef _FPU_EXTENDED /* e.g., ARM processor under Linux */
295 #define _FPU_EXTENDED 0
296 #endif
297 #ifndef _FPU_DOUBLE
298 #define _FPU_DOUBLE 0
299 #endif
300 #ifdef Can_use__setfpucw /* pre-1997 (?) Linux */
301 __setfpucw(_FPU_IEEE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM);
302 #else
303 #ifdef UNINIT_F2C_PRECISION_53 /* 20051004 */
304 /* unmask invalid, etc., and change rounding precision to double */
305 __fpu_control = _FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM;
306 _FPU_SETCW(__fpu_control);
307 #else
308 /* unmask invalid, etc., and keep current rounding precision */
309 fpu_control_t cw;
310 _FPU_GETCW(cw);
311 #ifdef _FPU_MASK_IM
312 cw &= ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM);
313 #else
314 cw &= ~(_FPU_MASK_I | _FPU_MASK_Z | _FPU_MASK_O);
315 #endif
316 _FPU_SETCW(cw);
317 #endif
318 #endif
319
320 #else /* !_FPU_IEEE */
321
322 fprintf(stderr, "\n%s\n%s\n%s\n%s\n",
323 "WARNING: _uninit_f2c in libf2c does not know how",
324 "to enable trapping on this system, so f2c's -trapuv",
325 "option will not detect uninitialized variables unless",
326 "you can enable trapping manually.");
327 fflush(stderr);
328
329 #endif /* _FPU_IEEE */
330 #endif /* __mc68k__ */
331 }
332 #endif /* __linux__ */
333
334 #ifdef __alpha
335 #ifndef IEEE0_done
336 #define IEEE0_done
337 #include <machine/fpu.h>
338 static void
339 ieee0(Void)
340 {
341 ieee_set_fp_control(IEEE_TRAP_ENABLE_INV);
342 }
343 #endif /*IEEE0_done*/
344 #endif /*__alpha*/
345
346 #ifdef __hpux
347 #define IEEE0_done
348 #define _INCLUDE_HPUX_SOURCE
349 #include <math.h>
350
351 #ifndef FP_X_INV
352 #include <fenv.h>
353 #define fpsetmask fesettrapenable
354 #define FP_X_INV FE_INVALID
355 #endif
356
357 static void
358 ieee0(Void)
359 {
360 fpsetmask(FP_X_INV);
361 }
362 #endif /*__hpux*/
363
364 #ifdef _AIX
365 #define IEEE0_done
366 #include <fptrap.h>
367
368 static void
369 ieee0(Void)
370 {
371 fp_enable(TRP_INVALID);
372 fp_trap(FP_TRAP_SYNC);
373 }
374 #endif /*_AIX*/
375
376 #ifdef __sun
377 #define IEEE0_done
378 #include <ieeefp.h>
379
380 static void
381 ieee0(Void)
382 {
383 fpsetmask(FP_X_INV);
384 }
385 #endif /*__sparc*/
386
387 #ifndef IEEE0_done
388 static void
389 ieee0(Void) {}
390 #endif