OSDN Git Service

Adjust repository version following WSL-5.2.2 release.
[mingw/mingw-org-wsl.git] / mingwrt / mingwex / feholdexcept.c
1 #include <fenv.h>
2 #include "cpu_features.h"
3
4 /* 7.6.4.2
5    The feholdexcept function saves the current floating-point
6    environment in the object pointed to by envp, clears the exception
7    flags, and then installs a non-stop (continue on exceptions) mode,
8    if available, for all exceptions.  */
9
10 int feholdexcept (fenv_t * envp)
11 {
12   __asm__ ("fnstenv %0;" : "=m" (* envp)); /* save current into envp */
13  /* fnstenv sets control word to non-stop for all exceptions, so all we
14     need to do is clear the exception flags.  */
15   __asm__ ("fnclex");
16
17   if (__HAS_SSE)
18     {
19        unsigned int _csr;
20        /* Save the SSE MXCSR register.  */
21        __asm__ ("stmxcsr %0" :  "=m" (envp->__mxcsr));
22        /* Clear the exception flags. */
23        _csr = envp->__mxcsr & ~FE_ALL_EXCEPT;
24        /* Set exception mask to non-stop  */
25        _csr |= (FE_ALL_EXCEPT << __MXCSR_EXCEPT_MASK_SHIFT) /*= 0x1f80 */;
26        __asm__ volatile ("ldmxcsr %0" : : "m" (_csr));
27     }
28
29   return 0;
30 }