From: Chris Hanson Date: Sun, 8 Sep 2019 07:31:51 +0000 (-0700) Subject: Adapt fegetexcept etc. workarounds to work when debugging turned on. X-Git-Tag: mit-scheme-pucked-10.1.20~11^2~52 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=b0e6eba1a93578273bc5e8ed7c398fdec5bf469c;p=mit-scheme.git Adapt fegetexcept etc. workarounds to work when debugging turned on. --- diff --git a/src/microcode/floenv.c b/src/microcode/floenv.c index 59e619823..a8e6c1d73 100644 --- a/src/microcode/floenv.c +++ b/src/microcode/floenv.c @@ -33,6 +33,49 @@ USA. #include "floenv.h" +#ifdef NEED_FEEXCEPT_WORKAROUND + +// From http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c + +int fegetexcept(void) +{ + fenv_t fenv; + return (fegetenv (&fenv)) ? -1 : (fenv.__control & FE_ALL_EXCEPT); +} + +int feenableexcept(unsigned int excepts) +{ + fenv_t fenv; + if (fegetenv (&fenv)) + return -1; + + unsigned int new_excepts = excepts & FE_ALL_EXCEPT; + unsigned int old_excepts = fenv.__control & FE_ALL_EXCEPT; + + // unmask + fenv.__control &= ~new_excepts; + fenv.__mxcsr &= ~(new_excepts << 7); + + return (fesetenv (&fenv)) ? -1 : old_excepts; +} + +int fedisableexcept(unsigned int excepts) +{ + fenv_t fenv; + if (fegetenv (&fenv)) + return -1; + + unsigned int new_excepts = excepts & FE_ALL_EXCEPT; + unsigned int old_excepts = fenv.__control & FE_ALL_EXCEPT; + + // mask + fenv.__control |= new_excepts; + fenv.__mxcsr |= new_excepts << 7; + + return (fesetenv (&fenv)) ? -1 : old_excepts; +} +#endif // NEED_FEEXCEPT_WORKAROUND + #ifndef __GNUC__ # pragma STDC FENV_ACCESS ON #endif diff --git a/src/microcode/floenv.h b/src/microcode/floenv.h index 3d0189c28..331347781 100644 --- a/src/microcode/floenv.h +++ b/src/microcode/floenv.h @@ -46,47 +46,10 @@ USA. # endif # define HAVE_FEENABLEEXCEPT # define HAVE_FEDISABLEEXCEPT - -// From http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c - -inline int fegetexcept(void) -{ - fenv_t fenv; - return (fegetenv (&fenv)) ? -1 : (fenv.__control & FE_ALL_EXCEPT); -} - -inline int feenableexcept(unsigned int excepts) -{ - fenv_t fenv; - if (fegetenv (&fenv)) - return -1; - - unsigned int new_excepts = excepts & FE_ALL_EXCEPT; - unsigned int old_excepts = fenv.__control & FE_ALL_EXCEPT; - - // unmask - fenv.__control &= ~new_excepts; - fenv.__mxcsr &= ~(new_excepts << 7); - - return (fesetenv (&fenv)) ? -1 : old_excepts; -} - -inline int fedisableexcept(unsigned int excepts) -{ - fenv_t fenv; - if (fegetenv (&fenv)) - return -1; - - unsigned int new_excepts = excepts & FE_ALL_EXCEPT; - unsigned int old_excepts = fenv.__control & FE_ALL_EXCEPT; - - // mask - fenv.__control |= new_excepts; - fenv.__mxcsr |= new_excepts << 7; - - return (fesetenv (&fenv)) ? -1 : old_excepts; -} - +# define NEED_FEEXCEPT_WORKAROUND + extern int fegetexcept(void); + extern int feenableexcept(unsigned int); + extern int fedisableexcept(unsigned int); # endif #elif ((!defined (CMPINTMD_EMULATES_FENV)) && (defined (HAVE_IEEEFP_H)))