int test_settings(void) { int failures = 0; fp_except mask_orig; printf("Testing settings on the chip... "); fflush(stdout); fpsetround(FP_RM); if(fpgetround() != FP_RM) FAIL_TEST; fpsetround(FP_RP); if(fpgetround() != FP_RP) FAIL_TEST; fpsetround(FP_RZ); if(fpgetround() != FP_RZ) FAIL_TEST; fpsetround(FP_RN); if(fpgetround() != FP_RN) FAIL_TEST; fpsetsticky(FP_X_INV | FP_X_DZ | FP_X_IMP); if(fpgetsticky() != (FP_X_INV | FP_X_DZ | FP_X_IMP)) FAIL_TEST; fpsetsticky(FP_X_OFL | FP_X_IMP); if(fpgetsticky() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST; fpsetsticky(FP_X_UFL | FP_X_DZ); if(fpgetsticky() != (FP_X_UFL | FP_X_DZ)) FAIL_TEST; fpsetsticky(0); if(fpgetsticky() != 0) FAIL_TEST; mask_orig = fpsetmask(FP_X_INV | FP_X_DZ); if(fpgetmask() != (FP_X_INV | FP_X_DZ)) FAIL_TEST; fpsetmask(FP_X_OFL | FP_X_IMP); if(fpgetmask() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST; fpsetmask(FP_X_UFL | FP_X_DZ | FP_X_INV); if(fpgetmask() != (FP_X_UFL | FP_X_DZ | FP_X_INV)) FAIL_TEST; fpsetmask(mask_orig); if(fpgetmask() != mask_orig) FAIL_TEST; #ifdef __CYGWIN__ fpsetprecision(FP_PC_SGL); if(fpgetprecision() != FP_PC_SGL) FAIL_TEST; fpsetprecision(FP_PC_DBL); if(fpgetprecision() != FP_PC_DBL) FAIL_TEST; fpsetprecision(FP_PC_EXT); if(fpgetprecision() != FP_PC_EXT) FAIL_TEST; #endif if(failures == 0) { printf(" PASSED\n"); return 0; } else { printf(" %d failures\n", failures); return 1; } }
void fpe_init(void) { TURN_ON_FPE_TRAPS; #ifdef HAVE_SIGACTION_SA_SIGACTION { struct sigaction x; memset(&x, 0, sizeof(x)); x.sa_sigaction = fpe_catch; x.sa_flags = SA_SIGINFO; sigaction(SIGFPE, &x, (struct sigaction *) 0); } #else signal(SIGFPE, fpe_catch); #endif #ifdef HAVE_STRTOD_OVF_BUG /* we've already turned the traps on */ working_mask = fpgetmask(); entry_mask = working_mask & ~FP_X_DZ & ~FP_X_OFL; #endif }
int nacl_main(int argc, char **argv) { if (nacl_startup_untar(argv[0], DATA_FILE, "/")) return -1; wchar_t **argv_copy; /* We need a second copy, as Python might modify the first one. */ wchar_t **argv_copy2; int i, res; char *oldloc; #ifdef __FreeBSD__ fp_except_t m; #endif argv_copy = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); argv_copy2 = (wchar_t **)PyMem_RawMalloc(sizeof(wchar_t*) * (argc+1)); if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); if (!oldloc) { fprintf(stderr, "out of memory\n"); return 1; } setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy[i] = _Py_char2wchar(argv[i], NULL); if (!argv_copy[i]) { PyMem_RawFree(oldloc); fprintf(stderr, "Fatal Python error: " "unable to decode the command line argument #%i\n", i + 1); return 1; } argv_copy2[i] = argv_copy[i]; } argv_copy2[argc] = argv_copy[argc] = NULL; setlocale(LC_ALL, oldloc); PyMem_RawFree(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_RawFree(argv_copy2[i]); } PyMem_RawFree(argv_copy); PyMem_RawFree(argv_copy2); return res; }
int fegetexcept(void) { #ifdef __SOFTFP__ return fpgetmask(); #else return __SHIFTOUT(armreg_fpscr_read(), VFP_FPSCR_ESUM); #endif }
static void check_strtod_ovf(void) { #ifdef USE_IEEEFP_H fpsetmask(fpgetmask() | FP_X_OFL | FP_X_DZ); #endif checking_for_strtod_ovf_bug = 1; strtod(longstr, (char **) 0); exit(0); }
/* * The fegetenv() function shall attempt to store the current floating-point * environment in the object pointed to by envp. */ int fegetenv(fenv_t *envp) { #ifdef __SOFTFP__ *envp = __SHIFTIN(fpgetround(), VFP_FPSCR_RMODE) | __SHIFTIN(fpgetmask(), VFP_FPSCR_ESUM) | __SHIFTIN(fpgetsticky(), VFP_FPSCR_CSUM); #else *envp = armreg_fpscr_read(); #endif return 0; }
/* * The feholdexcept() function shall save the current floating-point * environment in the object pointed to by envp, clear the floating-point * status flags, and then install a non-stop (continue on floating-point * exceptions) mode, if available, for all floating-point exceptions. */ int feholdexcept(fenv_t *envp) { #ifdef __SOFTFP__ *envp = __SHIFTIN(fpgetround(), VFP_FPSCR_RMODE) | __SHIFTIN(fpgetmask(), VFP_FPSCR_ESUM) | __SHIFTIN(fpgetsticky(), VFP_FPSCR_CSUM); fpsetmask(0); fpsetsticky(0); #else *envp = armreg_fpscr_read(); armreg_fpscr_write((*envp) & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM)); #endif return 0; }
int fedisableexcept(int excepts) { #ifndef lint _DIAGASSERT((except & ~FE_ALL_EXCEPT) == 0); #endif #ifdef __SOFTFP__ int old = fpgetmask(); fpsetmask(old & ~excepts); return old; #else int fpscr = armreg_fpscr_read(); armreg_fpscr_write(fpscr & ~__SHIFTIN((excepts), VFP_FPSCR_ESUM)); return __SHIFTOUT(fpscr, VFP_FPSCR_ESUM) & FE_ALL_EXCEPT; #endif }
/* * The feupdateenv() function shall attempt to save the currently raised * floating-point exceptions in its automatic storage, attempt to install the * floating-point environment represented by the object pointed to by envp, * and then attempt to raise the saved floating-point exceptions. */ int feupdateenv(const fenv_t *envp) { #ifndef lint _DIAGASSERT(envp != NULL); #endif #ifdef __SOFTFP__ (void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE)); (void)fpsetmask(fpgetmask() | __SHIFTOUT(*envp, VFP_FPSCR_ESUM)); (void)fpsetsticky(fpgetsticky() | __SHIFTOUT(*envp, VFP_FPSCR_CSUM)); #else int fpscr = armreg_fpscr_read() & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM); fpscr |= *envp; armreg_fpscr_write(fpscr); #endif /* Success */ return 0; }
int main(int argc, char **argv) { wchar_t **argv_copy = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); /* We need a second copies, as Python might modify the first one. */ wchar_t **argv_copy2 = (wchar_t **)PyMem_Malloc(sizeof(wchar_t*)*argc); int i, res; char *oldloc; /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP * exceptions by default. Here we disable them. */ #ifdef __FreeBSD__ fp_except_t m; m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif if (!argv_copy || !argv_copy2) { fprintf(stderr, "out of memory\n"); return 1; } oldloc = strdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { argv_copy2[i] = argv_copy[i] = char2wchar(argv[i]); if (!argv_copy[i]) return 1; } setlocale(LC_ALL, oldloc); free(oldloc); res = Py_Main(argc, argv_copy); for (i = 0; i < argc; i++) { PyMem_Free(argv_copy2[i]); } PyMem_Free(argv_copy); PyMem_Free(argv_copy2); return res; }
FPEnvironmentImpl::FPEnvironmentImpl() { _rnd = fpgetround(); _exc = fpgetmask(); }
/* initialize mp3 encoder */ void lame_init(lame_global_flags *gfp) { /* * Disable floating point exepctions */ #ifdef __FreeBSD__ # include <floatingpoint.h> { /* seet floating point mask to the Linux default */ fp_except_t mask; mask=fpgetmask(); /* if bit is set, we get SIGFPE on that error! */ fpsetmask(mask & ~(FP_X_INV|FP_X_DZ)); /* fprintf(stderr,"FreeBSD mask is 0x%x\n",mask); */ } #endif #if defined(__riscos__) && !defined(ABORTFP) /* Disable FPE's under RISC OS */ /* if bit is set, we disable trapping that error! */ /* _FPE_IVO : invalid operation */ /* _FPE_DVZ : divide by zero */ /* _FPE_OFL : overflow */ /* _FPE_UFL : underflow */ /* _FPE_INX : inexact */ DisableFPETraps( _FPE_IVO | _FPE_DVZ | _FPE_OFL ); #endif /* * Debugging stuff * The default is to ignore FPE's, unless compiled with -DABORTFP * so add code below to ENABLE FPE's. */ #if defined(ABORTFP) && !defined(__riscos__) #if defined(_MSC_VER) { #include <float.h> unsigned int mask; mask=_controlfp( 0, 0 ); mask&=~(_EM_OVERFLOW|_EM_UNDERFLOW|_EM_ZERODIVIDE|_EM_INVALID); mask=_controlfp( mask, _MCW_EM ); } #elif defined(__CYGWIN__) # define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) # define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) # define _EM_INEXACT 0x00000001 /* inexact (precision) */ # define _EM_UNDERFLOW 0x00000002 /* underflow */ # define _EM_OVERFLOW 0x00000004 /* overflow */ # define _EM_ZERODIVIDE 0x00000008 /* zero divide */ # define _EM_INVALID 0x00000010 /* invalid */ { unsigned int mask; _FPU_GETCW(mask); /* Set the FPU control word to abort on most FPEs */ mask &= ~(_EM_UNDERFLOW | _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID); _FPU_SETCW(mask); } # else { # include <fpu_control.h> #ifndef _FPU_GETCW #define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) #endif #ifndef _FPU_SETCW #define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) #endif unsigned int mask; _FPU_GETCW(mask); /* Set the Linux mask to abort on most FPE's */ /* if bit is set, we _mask_ SIGFPE on that error! */ /* mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM );*/ mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM ); _FPU_SETCW(mask); } #endif #endif /* ABORTFP && !__riscos__ */ /* Global flags. set defaults here */ gfp->allow_diff_short=0; gfp->ATHonly=0; gfp->noATH=0; gfp->bWriteVbrTag=1; gfp->cwlimit=0; gfp->disable_reservoir=0; gfp->experimentalX = 0; gfp->experimentalY = 0; gfp->experimentalZ = 0; gfp->frameNum=0; gfp->gtkflag=0; gfp->quality=5; gfp->input_format=sf_unknown; gfp->filter_type=0; gfp->lowpassfreq=0; gfp->highpassfreq=0; gfp->lowpasswidth=-1; gfp->highpasswidth=-1; gfp->lowpass1=0; gfp->lowpass2=0; gfp->highpass1=0; gfp->highpass2=0; gfp->lowpass_band=32; gfp->highpass_band=-1; gfp->no_short_blocks=0; gfp->resample_ratio=1; gfp->padding_type=2; gfp->padding=0; gfp->swapbytes=0; gfp->silent=0; gfp->totalframes=0; gfp->VBR=0; gfp->VBR_q=4; gfp->VBR_min_bitrate_kbps=0; gfp->VBR_max_bitrate_kbps=0; gfp->VBR_min_bitrate=1; gfp->VBR_max_bitrate=13; gfp->version = 1; /* =1 Default: MPEG-1 */ gfp->mode = MPG_MD_JOINT_STEREO; gfp->mode_fixed=0; gfp->force_ms=0; gfp->brate=0; gfp->copyright=0; gfp->original=1; gfp->extension=0; gfp->error_protection=0; gfp->emphasis=0; gfp->in_samplerate=1000*44.1; gfp->out_samplerate=0; gfp->num_channels=2; gfp->num_samples=MAX_U_32_NUM; gfp->inPath=NULL; gfp->outPath=NULL; id3tag.used=0; }
int main(int argc, char *argv[]) { struct sigaction sa; volatile double x; if (argc != 2) { fprintf(stderr, "usage: %s condition\n", argv[0]); exit(1); } /* * check to make sure that all exceptions are masked and * that the accumulated exception status is clear. */ assert(fpgetmask() == 0); assert(fpgetsticky() == 0); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = sigfpe; sa.sa_flags = SA_SIGINFO; sigaction(SIGFPE, &sa, NULL); signal_status = 1; if (strcmp(argv[1], "fltdiv") == 0) { /* trip divide by zero */ x = one / zero; assert(fpgetsticky() & FP_X_DZ); fpsetsticky(0); /* and now unmask to get a signal */ signal_status = 0; fpsetmask(FP_X_DZ); x = one / zero; } else if (strcmp(argv[1], "fltinv") == 0) { /* trip invalid operation */ x = zero / zero; assert(fpgetsticky() & FP_X_INV); fpsetsticky(0); /* and now unmask to get a signal */ signal_status = 0; fpsetmask(FP_X_INV); x = zero / zero; } else if (strcmp(argv[1], "fltovf") == 0) { /* trip overflow */ x = huge * huge; assert(fpgetsticky() & FP_X_OFL); fpsetsticky(0); /* and now unmask to get a signal */ signal_status = 0; fpsetmask(FP_X_OFL); x = huge * huge; } else if (strcmp(argv[1], "fltund") == 0) { /* trip underflow */ x = tiny * tiny; assert(fpgetsticky() & FP_X_UFL); fpsetsticky(0); /* and now unmask to get a signal */ signal_status = 0; fpsetmask(FP_X_UFL); x = tiny * tiny; } else { errx(1, "unrecognized condition %s", argv[1]); } /* * attempt to trigger the exception on machines where * floating-point exceptions are deferred. */ x = one * one; errx(1, "signal wasn't caught"); }