• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 
7 #include <fenv.h>
8 
9 #if !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__))
10 extern int __mingw_has_sse (void);
11 #endif /* !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)) */
12 
13 /* 7.6.2.5
14    The fetestexcept function determines which of a specified subset of
15    the exception flags are currently set. The excepts argument
16    specifies the exception flags to be queried.
17    The fetestexcept function returns the value of the bitwise OR of the
18    exception macros corresponding to the currently set exceptions
19    included in excepts. */
20 
fetestexcept(int excepts)21 int fetestexcept (int excepts)
22 {
23 #if defined(_ARM_) || defined(__arm__)
24   fenv_t _env;
25   __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
26   return _env.__cw & excepts & FE_ALL_EXCEPT;
27 #elif defined(_ARM64_) || defined(__aarch64__)
28   unsigned __int64 fpcr;
29   __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
30   return fpcr & excepts & FE_ALL_EXCEPT;
31 #else
32   unsigned short _sw;
33   __asm__ __volatile__ ("fnstsw %%ax" : "=a" (_sw));
34 
35   if (__mingw_has_sse ())
36     {
37       int sse_sw;
38       __asm__ __volatile__ ("stmxcsr %0;" : "=m" (sse_sw));
39       _sw |= sse_sw;
40     }
41   return _sw & excepts & FE_ALL_EXCEPT;
42 #endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
43 }
44