]> Savannah Git Hosting - gnulib.git/commitdiff
fenv-exceptions-tracking-c99: Fix feraiseexcept (FE_OVERFLOW) on MSVC.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Oct 2023 22:29:46 +0000 (00:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Oct 2023 22:37:43 +0000 (00:37 +0200)
* lib/fenv-except-tracking-raise.c (feraiseexcept): Use the generic
approach for all exceptions.

ChangeLog
lib/fenv-except-tracking-raise.c

index a527f14ae8f88577e78e4456c839a7f66dbbaa04..928ddf72b85d9c9d859d99f5dc84f6b68ae19b8d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-10-28  Bruno Haible  <bruno@clisp.org>
+
+       fenv-exceptions-tracking-c99: Fix feraiseexcept (FE_OVERFLOW) on MSVC.
+       * lib/fenv-except-tracking-raise.c (feraiseexcept): Use the generic
+       approach for all exceptions.
+
 2023-10-28  Bruno Haible  <bruno@clisp.org>
 
        fpe-trapping: Always clear the FE_INVALID exception flag first.
index a9f8b04963e86f820e86c5c7a242c52f7b66285d..8699662ef554477174b05fec420fd36b7a81537a 100644 (file)
@@ -71,6 +71,14 @@ generic_feraiseexcept (int exceptions)
 int
 feraiseexcept (int exceptions)
 {
+#  if defined _MSC_VER
+
+  /* Setting the exception flags only in the SSE unit (i.e. in the mxcsr
+     register) would not cause the hardware to trap on the exception.  */
+  generic_feraiseexcept (exceptions);
+
+#  else
+
   exceptions &= FE_ALL_EXCEPT;
 
   if ((exceptions & ~(FE_INVALID | FE_DIVBYZERO)) == 0)
@@ -95,18 +103,6 @@ feraiseexcept (int exceptions)
   else
     {
       /* The general case.  */
-#  if defined _MSC_VER
-
-      exceptions = exceptions_to_x86hardware (exceptions);
-
-      /* Set the bits only in the SSE unit.  */
-      unsigned int mxcsr, orig_mxcsr;
-      _FPU_GETSSECW (orig_mxcsr);
-      mxcsr = orig_mxcsr | exceptions;
-      if (mxcsr != orig_mxcsr)
-        _FPU_SETSSECW (mxcsr);
-
-#  else
 
       /* Set the bits in the 387 unit.  */
       x86_387_fenv_t env;
@@ -122,8 +118,9 @@ feraiseexcept (int exceptions)
           __asm__ __volatile__ ("fwait");
         }
 
-#  endif
     }
+
+#  endif
   return 0;
 }
 
@@ -168,6 +165,8 @@ feraiseexcept (int exceptions)
      the overflow/underflow exception follows the inexact exception.  After
      each exception we read from the fpscr, to force the exception to be
      raised immediately.  */
+  /* XXX Probably this should do actual floating-point operations, like in
+     generic_feraiseexcept, not just setting flag bits in the fpscr.  */
   unsigned int fpscr, orig_fpscr;
   /* First: invalid exception.  */
   if (exceptions & FE_INVALID)