From b0e6eba1a93578273bc5e8ed7c398fdec5bf469c Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Sun, 8 Sep 2019 00:31:51 -0700
Subject: [PATCH] Adapt fegetexcept etc. workarounds to work when debugging
 turned on.

---
 src/microcode/floenv.c | 43 ++++++++++++++++++++++++++++++++++++++++
 src/microcode/floenv.h | 45 ++++--------------------------------------
 2 files changed, 47 insertions(+), 41 deletions(-)

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)))
 
-- 
2.25.1