• 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 #include <fenv.h>
7 
8 #if !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__))
9 int __mingw_has_sse (void);
10 
__mingw_has_sse(void)11 int __mingw_has_sse(void)
12 {
13   int cpuInfo[4],infoType = 1;
14 
15 #ifndef _WIN64
16   int o_flag, n_flag;
17 
18   __asm__ volatile ("pushfl\n\tpopl %0" : "=mr" (o_flag));
19   n_flag = o_flag ^ 0x200000;
20   __asm__ volatile ("pushl %0\n\tpopfl" : : "g" (n_flag));
21   __asm__ volatile ("pushfl\n\tpopl %0" : "=mr" (n_flag));
22   if (n_flag == o_flag)
23     return 0;
24 #endif
25 
26   __asm__ __volatile__ (
27     "cpuid"
28     : "=a" (cpuInfo[0]), "=b" (cpuInfo[1]), "=c" (cpuInfo[2]),
29     "=d" (cpuInfo[3])
30     : "a" (infoType));
31   if (cpuInfo[3] & 0x2000000)
32     return 1;
33   return 0;
34 }
35 #endif /* !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)) */
36 
37 /* 7.6.2.1
38    The feclearexcept function clears the supported exceptions
39    represented by its argument.  */
40 
feclearexcept(int excepts)41 int feclearexcept (int excepts)
42 {
43   fenv_t _env;
44 #if defined(_ARM_) || defined(__arm__)
45   __asm__ volatile ("fmrx %0, FPSCR" : "=r" (_env));
46   _env.__cw &= ~(excepts & FE_ALL_EXCEPT);
47   __asm__ volatile ("fmxr FPSCR, %0" : : "r" (_env));
48 #elif defined(_ARM64_) || defined(__aarch64__)
49   unsigned __int64 fpcr;
50   (void) _env;
51   __asm__ volatile ("mrs %0, fpcr" : "=r" (fpcr));
52   fpcr &= ~(excepts & FE_ALL_EXCEPT);
53   __asm__ volatile ("msr fpcr, %0" : : "r" (fpcr));
54 #else
55   int _mxcsr;
56   if (excepts == FE_ALL_EXCEPT)
57     {
58       __asm__ volatile ("fnclex");
59     }
60   else
61     {
62       __asm__ volatile ("fnstenv %0" : "=m" (_env));
63       _env.__status_word &= ~(excepts & FE_ALL_EXCEPT);
64       __asm__ volatile ("fldenv %0" : : "m" (_env));
65     }
66   if (__mingw_has_sse ())
67     {
68       __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr));
69       _mxcsr &= ~(((excepts & FE_ALL_EXCEPT)));
70       __asm__ volatile ("ldmxcsr %0" : : "m" (_mxcsr));
71     }
72 #endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
73   return (0);
74 }
75