From: Chris Hanson Date: Thu, 15 Nov 2018 05:19:09 +0000 (-0800) Subject: Add patch from internet to enable/disable FP traps on macOS. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~95 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=a93bf340f584ee721423aed7e8e755e660710ccb;p=mit-scheme.git Add patch from internet to enable/disable FP traps on macOS. --- diff --git a/src/microcode/floenv.h b/src/microcode/floenv.h index 4d0ad90eb..15f424d77 100644 --- a/src/microcode/floenv.h +++ b/src/microcode/floenv.h @@ -42,6 +42,43 @@ USA. # endif # ifdef __APPLE__ # undef HAVE_FEGETEXCEPT +# define HAVE_FEENABLEEXCEPT +# define HAVE_FEDISABLEEXCEPT + +// From http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c + +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; +} + # endif #elif ((!defined (CMPINTMD_EMULATES_FENV)) && (defined (HAVE_IEEEFP_H)))