1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef SCOPED_FPU_SETTINGS
4 #define SCOPED_FPU_SETTINGS
5 
6 // dedicated is compiled w/o streflop!
7 #if defined(__SUPPORT_SNAN__) && !defined(DEDICATED) && !defined(UNITSYNC)
8 
9 #include "lib/streflop/streflop_cond.h"
10 
11 class ScopedDisableFpuExceptions {
12 public:
ScopedDisableFpuExceptions()13 	ScopedDisableFpuExceptions() {
14 		streflop::fegetenv(&fenv);
15 		streflop::feclearexcept(streflop::FPU_Exceptions(streflop::FE_INVALID | streflop::FE_DIVBYZERO | streflop::FE_OVERFLOW));
16 	}
~ScopedDisableFpuExceptions()17 	~ScopedDisableFpuExceptions() {
18 		streflop::fesetenv(&fenv);
19 	}
20 private:
21 	streflop::fpenv_t fenv;
22 };
23 
24 #else
25 
26 #include <stddef.h> //NULL
27 class ScopedDisableFpuExceptions {
28 public:
ScopedDisableFpuExceptions()29 	ScopedDisableFpuExceptions() {
30 		if (false) *(int *)NULL = 0; // just something here to avoid MSVC "unreferenced local variable"
31 	}
32 };
33 
34 #endif
35 
36 #endif // SCOPED_FPU_SETTINGS
37