uninit.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "arith.h"
00004 
00005 #define TYSHORT 2
00006 #define TYLONG 3
00007 #define TYREAL 4
00008 #define TYDREAL 5
00009 #define TYCOMPLEX 6
00010 #define TYDCOMPLEX 7
00011 #define TYINT1 11
00012 #define TYQUAD 14
00013 #ifndef Long
00014 #define Long long
00015 #endif
00016 
00017 #ifdef __mips
00018 #define RNAN    0xffc00000
00019 #define DNAN0   0xfff80000
00020 #define DNAN1   0
00021 #endif
00022 
00023 #ifdef _PA_RISC1_1
00024 #define RNAN    0xffc00000
00025 #define DNAN0   0xfff80000
00026 #define DNAN1   0
00027 #endif
00028 
00029 #ifndef RNAN
00030 #define RNAN    0xff800001
00031 #ifdef IEEE_MC68k
00032 #define DNAN0   0xfff00000
00033 #define DNAN1   1
00034 #else
00035 #define DNAN0   1
00036 #define DNAN1   0xfff00000
00037 #endif
00038 #endif /*RNAN*/
00039 
00040 #ifdef KR_headers
00041 #define Void /*void*/
00042 #define FA7UL (unsigned Long) 0xfa7a7a7aL
00043 #else
00044 #define Void void
00045 #define FA7UL 0xfa7a7a7aUL
00046 #endif
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 static void ieee0(Void);
00053 
00054 static unsigned Long rnan = RNAN,
00055         dnan0 = DNAN0,
00056         dnan1 = DNAN1;
00057 
00058 double _0 = 0.;
00059 
00060  void
00061 #ifdef KR_headers
00062 _uninit_f2c(x, type, len) void *x; int type; long len;
00063 #else
00064 _uninit_f2c(void *x, int type, long len)
00065 #endif
00066 {
00067         static int first = 1;
00068 
00069         unsigned Long *lx, *lxe;
00070 
00071         if (first) {
00072                 first = 0;
00073                 ieee0();
00074                 }
00075         if (len == 1)
00076          switch(type) {
00077           case TYINT1:
00078                 *(char*)x = 'Z';
00079                 return;
00080           case TYSHORT:
00081                 *(short*)x = 0xfa7a;
00082                 break;
00083           case TYLONG:
00084                 *(unsigned Long*)x = FA7UL;
00085                 return;
00086           case TYQUAD:
00087           case TYCOMPLEX:
00088           case TYDCOMPLEX:
00089                 break;
00090           case TYREAL:
00091                 *(unsigned Long*)x = rnan;
00092                 return;
00093           case TYDREAL:
00094                 lx = (unsigned Long*)x;
00095                 lx[0] = dnan0;
00096                 lx[1] = dnan1;
00097                 return;
00098           default:
00099                 printf("Surprise type %d in _uninit_f2c\n", type);
00100           }
00101         switch(type) {
00102           case TYINT1:
00103                 memset(x, 'Z', len);
00104                 break;
00105           case TYSHORT:
00106                 *(short*)x = 0xfa7a;
00107                 break;
00108           case TYQUAD:
00109                 len *= 2;
00110                 /* no break */
00111           case TYLONG:
00112                 lx = (unsigned Long*)x;
00113                 lxe = lx + len;
00114                 while(lx < lxe)
00115                         *lx++ = FA7UL;
00116                 break;
00117           case TYCOMPLEX:
00118                 len *= 2;
00119                 /* no break */
00120           case TYREAL:
00121                 lx = (unsigned Long*)x;
00122                 lxe = lx + len;
00123                 while(lx < lxe)
00124                         *lx++ = rnan;
00125                 break;
00126           case TYDCOMPLEX:
00127                 len *= 2;
00128                 /* no break */
00129           case TYDREAL:
00130                 lx = (unsigned Long*)x;
00131                 for(lxe = lx + 2*len; lx < lxe; lx += 2) {
00132                         lx[0] = dnan0;
00133                         lx[1] = dnan1;
00134                         }
00135           }
00136         }
00137 #ifdef __cplusplus
00138 }
00139 #endif
00140 
00141 #ifndef MSpc
00142 #ifdef MSDOS
00143 #define MSpc
00144 #else
00145 #ifdef _WIN32
00146 #define MSpc
00147 #endif
00148 #endif
00149 #endif
00150 
00151 #ifdef MSpc
00152 #define IEEE0_done
00153 #include "float.h"
00154 #include "signal.h"
00155 
00156  static void
00157 ieee0(Void)
00158 {
00159 #ifndef __alpha
00160 #ifndef EM_DENORMAL
00161 #define EM_DENORMAL _EM_DENORMAL
00162 #endif
00163 #ifndef EM_UNDERFLOW
00164 #define EM_UNDERFLOW _EM_UNDERFLOW
00165 #endif
00166 #ifndef EM_INEXACT
00167 #define EM_INEXACT _EM_INEXACT
00168 #endif
00169 #ifndef MCW_EM
00170 #define MCW_EM _MCW_EM
00171 #endif
00172         _control87(EM_DENORMAL | EM_UNDERFLOW | EM_INEXACT, MCW_EM);
00173 #endif
00174         /* With MS VC++, compiling and linking with -Zi will permit */
00175         /* clicking to invoke the MS C++ debugger, which will show */
00176         /* the point of error -- provided SIGFPE is SIG_DFL. */
00177         signal(SIGFPE, SIG_DFL);
00178         }
00179 #endif /* MSpc */
00180 
00181 #ifdef __mips   /* must link with -lfpe */
00182 #define IEEE0_done
00183 /* code from Eric Grosse */
00184 #include <stdlib.h>
00185 #include <stdio.h>
00186 #include "/usr/include/sigfpe.h"        /* full pathname for lcc -N */
00187 #include "/usr/include/sys/fpu.h"
00188 
00189  static void
00190 #ifdef KR_headers
00191 ieeeuserhand(exception, val) unsigned exception[5]; int val[2];
00192 #else
00193 ieeeuserhand(unsigned exception[5], int val[2])
00194 #endif
00195 {
00196         fflush(stdout);
00197         fprintf(stderr,"ieee0() aborting because of ");
00198         if(exception[0]==_OVERFL) fprintf(stderr,"overflow\n");
00199         else if(exception[0]==_UNDERFL) fprintf(stderr,"underflow\n");
00200         else if(exception[0]==_DIVZERO) fprintf(stderr,"divide by 0\n");
00201         else if(exception[0]==_INVALID) fprintf(stderr,"invalid operation\n");
00202         else fprintf(stderr,"\tunknown reason\n");
00203         fflush(stderr);
00204         abort();
00205 }
00206 
00207  static void
00208 #ifdef KR_headers
00209 ieeeuserhand2(j) unsigned int **j;
00210 #else
00211 ieeeuserhand2(unsigned int **j)
00212 #endif
00213 {
00214         fprintf(stderr,"ieee0() aborting because of confusion\n");
00215         abort();
00216 }
00217 
00218  static void
00219 ieee0(Void)
00220 {
00221         int i;
00222         for(i=1; i<=4; i++){
00223                 sigfpe_[i].count = 1000;
00224                 sigfpe_[i].trace = 1;
00225                 sigfpe_[i].repls = _USER_DETERMINED;
00226                 }
00227         sigfpe_[1].repls = _ZERO;       /* underflow */
00228         handle_sigfpes( _ON,
00229                 _EN_UNDERFL|_EN_OVERFL|_EN_DIVZERO|_EN_INVALID,
00230                 ieeeuserhand,_ABORT_ON_ERROR,ieeeuserhand2);
00231         }
00232 #endif /* mips */
00233 
00234 #ifdef __linux__
00235 #define IEEE0_done
00236 #include "fpu_control.h"
00237 
00238 #ifdef __alpha__
00239 #ifndef USE_setfpucw
00240 #define __setfpucw(x) __fpu_control = (x)
00241 #endif
00242 #endif
00243 
00244 #ifndef _FPU_SETCW
00245 #undef  Can_use__setfpucw
00246 #define Can_use__setfpucw
00247 #endif
00248 
00249  static void
00250 ieee0(Void)
00251 {
00252 #if (defined(__mc68000__) || defined(__mc68020__) || defined(mc68020) || defined (__mc68k__))
00253 /* Reported 20010705 by Alan Bain <alanb@chiark.greenend.org.uk> */
00254 /* Note that IEEE 754 IOP (illegal operation) */
00255 /* = Signaling NAN (SNAN) + operation error (OPERR). */
00256 #ifdef Can_use__setfpucw
00257         __setfpucw(_FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL);
00258 #else
00259         __fpu_control = _FPU_IEEE + _FPU_DOUBLE + _FPU_MASK_OPERR + _FPU_MASK_DZ + _FPU_MASK_SNAN+_FPU_MASK_OVFL;
00260         _FPU_SETCW(__fpu_control);
00261 #endif
00262 
00263 #elif (defined(__powerpc__)||defined(_ARCH_PPC)||defined(_ARCH_PWR)) /* !__mc68k__ */
00264 /* Reported 20011109 by Alan Bain <alanb@chiark.greenend.org.uk> */
00265 
00266 #ifdef Can_use__setfpucw
00267 
00268 /* The following is NOT a mistake -- the author of the fpu_control.h
00269 for the PPC has erroneously defined IEEE mode to turn on exceptions
00270 other than Inexact! Start from default then and turn on only the ones
00271 which we want*/
00272 
00273         __setfpucw(_FPU_DEFAULT +  _FPU_MASK_IM+_FPU_MASK_OM+_FPU_MASK_UM);
00274 
00275 #else /* PPC && !Can_use__setfpucw */
00276 
00277         __fpu_control = _FPU_DEFAULT +_FPU_MASK_OM+_FPU_MASK_IM+_FPU_MASK_UM;
00278         _FPU_SETCW(__fpu_control);
00279 
00280 #endif /*Can_use__setfpucw*/
00281 
00282 #else /* !(mc68000||powerpc) */
00283 
00284 #ifdef _FPU_IEEE
00285 #ifndef _FPU_EXTENDED /* e.g., ARM processor under Linux */
00286 #define _FPU_EXTENDED 0
00287 #endif
00288 #ifndef _FPU_DOUBLE
00289 #define _FPU_DOUBLE 0
00290 #endif
00291 #ifdef Can_use__setfpucw /* pre-1997 (?) Linux */
00292         __setfpucw(_FPU_IEEE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM);
00293 #else
00294 #ifdef UNINIT_F2C_PRECISION_53 /* 20051004 */
00295         /* unmask invalid, etc., and change rounding precision to double */
00296         __fpu_control = _FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE - _FPU_MASK_IM - _FPU_MASK_ZM - _FPU_MASK_OM;
00297         _FPU_SETCW(__fpu_control);
00298 #else
00299         /* unmask invalid, etc., and keep current rounding precision */
00300         fpu_control_t cw;
00301         _FPU_GETCW(cw);
00302         cw &= ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM);
00303         _FPU_SETCW(cw);
00304 #endif
00305 #endif
00306 
00307 #else /* !_FPU_IEEE */
00308 
00309         fprintf(stderr, "\n%s\n%s\n%s\n%s\n",
00310                 "WARNING:  _uninit_f2c in libf2c does not know how",
00311                 "to enable trapping on this system, so f2c's -trapuv",
00312                 "option will not detect uninitialized variables unless",
00313                 "you can enable trapping manually.");
00314         fflush(stderr);
00315 
00316 #endif /* _FPU_IEEE */
00317 #endif /* __mc68k__ */
00318         }
00319 #endif /* __linux__ */
00320 
00321 #ifdef __alpha
00322 #ifndef IEEE0_done
00323 #define IEEE0_done
00324 #include <machine/fpu.h>
00325  static void
00326 ieee0(Void)
00327 {
00328         ieee_set_fp_control(IEEE_TRAP_ENABLE_INV);
00329         }
00330 #endif /*IEEE0_done*/
00331 #endif /*__alpha*/
00332 
00333 #ifdef __hpux
00334 #define IEEE0_done
00335 #define _INCLUDE_HPUX_SOURCE
00336 #include <math.h>
00337 
00338 #ifndef FP_X_INV
00339 #include <fenv.h>
00340 #define fpsetmask fesettrapenable
00341 #define FP_X_INV FE_INVALID
00342 #endif
00343 
00344  static void
00345 ieee0(Void)
00346 {
00347         fpsetmask(FP_X_INV);
00348         }
00349 #endif /*__hpux*/
00350 
00351 #ifdef _AIX
00352 #define IEEE0_done
00353 #include <fptrap.h>
00354 
00355  static void
00356 ieee0(Void)
00357 {
00358         fp_enable(TRP_INVALID);
00359         fp_trap(FP_TRAP_SYNC);
00360         }
00361 #endif /*_AIX*/
00362 
00363 #ifdef __sun
00364 #define IEEE0_done
00365 #include <ieeefp.h>
00366 
00367  static void
00368 ieee0(Void)
00369 {
00370         fpsetmask(FP_X_INV);
00371         }
00372 #endif /*__sparc*/
00373 
00374 #ifndef IEEE0_done
00375  static void
00376 ieee0(Void) {}
00377 #endif


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:16