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 #include <fenv.h>
7 
8 #if !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__))
9 extern int __mingw_has_sse (void);
10 #endif /* !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)) */
11 
12 /* 7.6.2.2
13    The fegetexceptflag function stores an implementation-defined
14    representation of the exception flags indicated by the argument
15    excepts in the object pointed to by the argument flagp.  */
16 
fegetexceptflag(fexcept_t * flagp,int excepts)17 int fegetexceptflag (fexcept_t * flagp, int excepts)
18 {
19 #if defined(_ARM_) || defined(__arm__)
20   fenv_t _env;
21   __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
22   *flagp = _env.__cw & excepts & FE_ALL_EXCEPT;
23 #elif defined(_ARM64_) || defined(__aarch64__)
24   unsigned __int64 fpcr;
25   __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
26   *flagp = fpcr & excepts & FE_ALL_EXCEPT;
27 #else
28   int _mxcsr;
29   unsigned short _status;
30 
31   __asm__ volatile ("fnstsw %0" : "=am" (_status));
32   _mxcsr = 0;
33   if (__mingw_has_sse ())
34     __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr));
35 
36   *flagp = (_mxcsr | _status) & excepts & FE_ALL_EXCEPT;
37 #endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
38   return 0;
39 }
40