static void ieee0(bool enableTrap) { TEUCHOS_TEST_FOR_EXCEPTION( enableTrap == false, std::logic_error, "Error, don't know how to turn off trap for AIX!" ); fp_enable(TRP_INVALID); fp_trap(FP_TRAP_SYNC); }
void _PM_enable_fpe(int flg, PFSignal_handler hnd) {int ret; if (flg) {ret = fp_trap(FP_TRAP_FASTMODE); if (ret == FP_TRAP_ERROR) PRINT(stdout, "FP_TRAP CALLED WITH INVALID PARAMETER - _PM_ENABLE_FPE"); else if (ret == FP_TRAP_UNIMPL) PRINT(stdout, "FP_TRAP_FASTMODE NOT SUPPORTED - _PM_ENABLE_FPE"); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW);} else {ret = fp_trap(FP_TRAP_OFF); if (ret == FP_TRAP_ERROR) PRINT(stdout, "COULD NOT TURN OFF FPE TRAPPING - _PM_ENABLE_FPE"); fp_disable_all();}; return;}
PetscErrorCode PetscSetFPTrap(PetscFPTrap on) { PetscFunctionBegin; if (on == PETSC_FP_TRAP_ON) { signal(SIGFPE,(void (*)(int))PetscDefaultFPTrap); fp_trap(FP_TRAP_SYNC); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); /* fp_enable(mask) for individual traps. Values are: TRP_INVALID TRP_DIV_BY_ZERO TRP_OVERFLOW TRP_UNDERFLOW TRP_INEXACT Can OR then together. fp_enable_all(); for all traps. */ } else { signal(SIGFPE,SIG_DFL); fp_disable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); fp_trap(FP_TRAP_OFF); } _trapmode = on; PetscFunctionReturn(0); }
static void fpe_reset(Sigfunc *handler) { /* Reset the exception handling machinery, and reset the signal * handler for SIGFPE to the given handler. */ /*-- SunOS and Solaris ----------------------------------------------------*/ #if defined(sun) /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags man pages (SunOS or Solaris) cc -c -I/usr/local/python/include fpectlmodule.c ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm */ #include <math.h> #ifndef _SUNMATH_H extern void nonstandard_arithmetic(void); extern int ieee_flags(const char*, const char*, const char*, char **); extern long ieee_handler(const char*, const char*, sigfpe_handler_type); #endif char *mode="exception", *in="all", *out; (void) nonstandard_arithmetic(); (void) ieee_flags("clearall",mode,in,&out); (void) ieee_handler("set","common",(sigfpe_handler_type)handler); PyOS_setsig(SIGFPE, handler); /*-- HPUX -----------------------------------------------------------------*/ #elif defined(__hppa) || defined(hppa) /* References: fpsetmask man page */ /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */ /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */ #include <math.h> fpsetdefaults(); PyOS_setsig(SIGFPE, handler); /*-- IBM AIX --------------------------------------------------------------*/ #elif defined(__AIX) || defined(_AIX) /* References: fp_trap, fp_enable man pages */ #include <fptrap.h> fp_trap(FP_TRAP_SYNC); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA LINUX ------------------------------------------------------*/ #elif defined(__alpha) && defined(linux) #include <asm/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- Cray Unicos ----------------------------------------------------------*/ #elif defined(cray) /* UNICOS delivers SIGFPE by default, but no matherr */ #ifdef HAS_LIBMSET libmset(-1); #endif PyOS_setsig(SIGFPE, handler); /*-- FreeBSD ----------------------------------------------------------------*/ #elif defined(__FreeBSD__) fpresetsticky(fpgetsticky()); fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL); PyOS_setsig(SIGFPE, handler); /*-- Linux ----------------------------------------------------------------*/ #elif defined(linux) #ifdef __GLIBC__ #include <fpu_control.h> #else #include <i386/fpu_control.h> #endif #ifdef _FPU_SETCW { fpu_control_t cw = 0x1372; _FPU_SETCW(cw); } #else __setfpucw(0x1372); #endif PyOS_setsig(SIGFPE, handler); /*-- Microsoft Windows, NT ------------------------------------------------*/ #elif defined(_MSC_VER) /* Reference: Visual C++ Books Online 4.2, Run-Time Library Reference, _control87, _controlfp */ #include <float.h> unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW; (void)_controlfp(0, cw); PyOS_setsig(SIGFPE, handler); /*-- Give Up --------------------------------------------------------------*/ #else fputs("Operation not implemented\n", stderr); #endif }
static void ieee0(Void) { fp_enable(TRP_INVALID); fp_trap(FP_TRAP_SYNC); }
int gsl_ieee_set_mode (int precision, int rounding, int exception_mask) { fptrap_t mode = 0 ; fprnd_t rnd = 0 ; switch (precision) { /* I'm not positive about AIX only supporting default precision rounding, * but this is the best assumption until it's proven otherwise. */ case GSL_IEEE_SINGLE_PRECISION: GSL_ERROR ("AIX only supports default precision rounding", GSL_EUNSUP) ; break ; case GSL_IEEE_DOUBLE_PRECISION: GSL_ERROR ("AIX only supports default precision rounding", GSL_EUNSUP) ; break ; case GSL_IEEE_EXTENDED_PRECISION: GSL_ERROR ("AIX only supports default precision rounding", GSL_EUNSUP) ; break ; } switch (rounding) { case GSL_IEEE_ROUND_TO_NEAREST: rnd = FP_RND_RN ; fp_swap_rnd (rnd) ; break ; case GSL_IEEE_ROUND_DOWN: rnd = FP_RND_RM ; fp_swap_rnd (rnd) ; break ; case GSL_IEEE_ROUND_UP: rnd = FP_RND_RP ; fp_swap_rnd (rnd) ; break ; case GSL_IEEE_ROUND_TO_ZERO: rnd = FP_RND_RZ ; fp_swap_rnd (rnd) ; break ; default: rnd = FP_RND_RN ; fp_swap_rnd (rnd) ; } /* Turn on all the exceptions apart from 'inexact' */ mode = TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW | TRP_UNDERFLOW ; if (exception_mask & GSL_IEEE_MASK_INVALID) mode &= ~ TRP_INVALID ; if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) { /* do nothing */ } else { GSL_ERROR ("AIX does not support the denormalized operand exception. " "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ; } if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) mode &= ~ TRP_DIV_BY_ZERO ; if (exception_mask & GSL_IEEE_MASK_OVERFLOW) mode &= ~ TRP_OVERFLOW ; if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) mode &= ~ TRP_UNDERFLOW ; if (exception_mask & GSL_IEEE_TRAP_INEXACT) { mode |= TRP_INEXACT ; } else { mode &= ~ TRP_INEXACT ; } /* AIX appears to require two steps -- first enable floating point traps * in general... */ fp_trap(FP_TRAP_SYNC); /* next, enable the traps we're interested in */ fp_enable(mode); return GSL_SUCCESS ; }
static void fpe_reset(Sigfunc *handler) { /* Reset the exception handling machinery, and reset the signal * handler for SIGFPE to the given handler. */ /*-- IRIX -----------------------------------------------------------------*/ #if defined(sgi) /* See man page on handle_sigfpes -- must link with -lfpe * My usage doesn't follow the man page exactly. Maybe somebody * else can explain handle_sigfpes to me.... * cc -c -I/usr/local/python/include fpectlmodule.c * ld -shared -o fpectlmodule.so fpectlmodule.o -lfpe */ #include <sigfpe.h> typedef void user_routine (unsigned[5], int[2]); typedef void abort_routine (unsigned long); handle_sigfpes(_OFF, 0, (user_routine *)0, _TURN_OFF_HANDLER_ON_ERROR, NULL); handle_sigfpes(_ON, _EN_OVERFL | _EN_DIVZERO | _EN_INVALID, (user_routine *)0, _ABORT_ON_ERROR, NULL); PyOS_setsig(SIGFPE, handler); /*-- SunOS and Solaris ----------------------------------------------------*/ #elif defined(sun) /* References: ieee_handler, ieee_sun, ieee_functions, and ieee_flags man pages (SunOS or Solaris) cc -c -I/usr/local/python/include fpectlmodule.c ld -G -o fpectlmodule.so -L/opt/SUNWspro/lib fpectlmodule.o -lsunmath -lm */ #include <math.h> #ifndef _SUNMATH_H extern void nonstandard_arithmetic(void); extern int ieee_flags(const char*, const char*, const char*, char **); extern long ieee_handler(const char*, const char*, sigfpe_handler_type); #endif char *mode="exception", *in="all", *out; (void) nonstandard_arithmetic(); (void) ieee_flags("clearall",mode,in,&out); (void) ieee_handler("set","common",(sigfpe_handler_type)handler); PyOS_setsig(SIGFPE, handler); /*-- HPUX -----------------------------------------------------------------*/ #elif defined(__hppa) || defined(hppa) /* References: fpsetmask man page */ /* cc -Aa +z -c -I/usr/local/python/include fpectlmodule.c */ /* ld -b -o fpectlmodule.sl fpectlmodule.o -lm */ #include <math.h> fpsetdefaults(); PyOS_setsig(SIGFPE, handler); /*-- IBM AIX --------------------------------------------------------------*/ #elif defined(__AIX) || defined(_AIX) /* References: fp_trap, fp_enable man pages */ #include <fptrap.h> fp_trap(FP_TRAP_SYNC); fp_enable(TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA OSF --------------------------------------------------------*/ #elif defined(__alpha) && defined(__osf__) /* References: exception_intro, ieee man pages */ /* cc -c -I/usr/local/python/include fpectlmodule.c */ /* ld -shared -o fpectlmodule.so fpectlmodule.o */ #include <machine/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA LINUX ------------------------------------------------------*/ #elif defined(__alpha) && defined(linux) #include <asm/fpu.h> unsigned long fp_control = IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE | IEEE_TRAP_ENABLE_OVF; ieee_set_fp_control(fp_control); PyOS_setsig(SIGFPE, handler); /*-- DEC ALPHA VMS --------------------------------------------------------*/ #elif defined(__ALPHA) && defined(__VMS) IEEE clrmsk; IEEE setmsk; clrmsk.ieee$q_flags = IEEE$M_TRAP_ENABLE_UNF | IEEE$M_TRAP_ENABLE_INE | IEEE$M_MAP_UMZ; setmsk.ieee$q_flags = IEEE$M_TRAP_ENABLE_INV | IEEE$M_TRAP_ENABLE_DZE | IEEE$M_TRAP_ENABLE_OVF; sys$ieee_set_fp_control(&clrmsk, &setmsk, 0); PyOS_setsig(SIGFPE, handler); /*-- HP IA64 VMS --------------------------------------------------------*/ #elif defined(__ia64) && defined(__VMS) PyOS_setsig(SIGFPE, handler); /*-- Cray Unicos ----------------------------------------------------------*/ #elif defined(cray) /* UNICOS delivers SIGFPE by default, but no matherr */ #ifdef HAS_LIBMSET libmset(-1); #endif PyOS_setsig(SIGFPE, handler); /*-- FreeBSD ----------------------------------------------------------------*/ #elif defined(__FreeBSD__) fpresetsticky(fpgetsticky()); fpsetmask(FP_X_INV | FP_X_DZ | FP_X_OFL); PyOS_setsig(SIGFPE, handler); /*-- Linux ----------------------------------------------------------------*/ #elif defined(linux) #ifdef __GLIBC__ #include <fpu_control.h> #else #include <i386/fpu_control.h> #endif #ifdef _FPU_SETCW { fpu_control_t cw = 0x1372; _FPU_SETCW(cw); } #else __setfpucw(0x1372); #endif PyOS_setsig(SIGFPE, handler); /*-- Microsoft Windows, NT ------------------------------------------------*/ #elif defined(_MSC_VER) /* Reference: Visual C++ Books Online 4.2, Run-Time Library Reference, _control87, _controlfp */ #include <float.h> unsigned int cw = _EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW; (void)_controlfp(0, cw); PyOS_setsig(SIGFPE, handler); /*-- Give Up --------------------------------------------------------------*/ #else fputs("Operation not implemented\n", stderr); #endif }