diff options
-rw-r--r-- | compat/arch.hpp | 53 | ||||
-rw-r--r-- | gui/init.cpp | 34 |
2 files changed, 64 insertions, 23 deletions
diff --git a/compat/arch.hpp b/compat/arch.hpp new file mode 100644 index 00000000..d5405f47 --- /dev/null +++ b/compat/arch.hpp @@ -0,0 +1,53 @@ +#pragma once + +// fix MSVC arch check macros + +// this file is too simple to fall under copyright, and +// can be copied, modified, and redistributed freely with +// no conditions. there's no warranty. -sh 20181226 + +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wreserved-id-macro" +# pragma clang diagnostic ignored "-Wunused-macros" +#endif + +#if defined _MSC_VER +# if defined _M_AMD64 +# undef __x86_64__ +# define __x86_64__ 1 +# elif defined _M_IX86 +# undef __i386__ +# define __i386__ 1 +# endif + +# if defined __AVX__ || defined __x86_64__ || \ + defined _M_IX86 && _M_IX86_FP >= 2 +# undef __SSE__ +# undef __SSE2__ +# undef __SSE3__ +# define __SSE__ 1 +# define __SSE2__ 1 +# define __SSE3__ 1 // assume SSE3 in the _M_IX86_FP >= 2 case +# endif +#endif + +#ifdef __clang__ +# pragma clang diagnostic pop +#endif + +#if defined __SSE3__ +# define OTR_ARCH_DENORM_DAZ +# include <pmmintrin.h> +#elif defined __SSE2__ +# define OTR_ARCH_DENORM_FTZ +# include <emmintrin.h> +#endif + +#if defined __SSE2__ +# define OTR_ARCH_FPU_MASK +# include <xmmintrin.h> +#endif + +#include <cfloat> +#include <cfenv> diff --git a/gui/init.cpp b/gui/init.cpp index d2b0c27d..b1018e39 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -11,6 +11,7 @@ #include "options/options.hpp" using namespace options; #include "compat/library-path.hpp" +#include "compat/arch.hpp" #include <memory> #include <cstdlib> @@ -30,39 +31,26 @@ using namespace options; #include <QDebug> -#if /* denormal control */ \ - /* GNU */ defined __x86_64__ || defined __SSE3__ || \ - /* MSVC */ defined _M_AMD64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) - -# if defined __GNUG__ && defined __SSE2__ && !defined __SSE3__ && !defined __x86_64__ -# undef OTR_DENORM_DAZ -# include <emmintrin.h> -# else -# define OTR_DENORM_DAZ -# include <pmmintrin.h> -# endif -# include <cfloat> - -# ifdef __APPLE__ -# include <fenv.h> -# endif - static void set_fp_mask() { -#ifdef OTR_DENORM_DAZ +#if defined OTR_ARCH_DENORM_DAZ _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); -#endif +#elif defined OTR_ARCH_DENORM_FTZ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); - //_MM_SET_ROUNDING_MODE(_MM_ROUND_NEAREST); +#endif + +#ifdef OTR_ARCH_FPU_MASK _MM_SET_EXCEPTION_MASK(_MM_MASK_MASK); +#endif #ifdef __APPLE__ fesetenv(FE_DFL_DISABLE_SSE_DENORMS_ENV); #endif -} -#else -static inline void set_fp_mask() {} + +#ifdef _WIN32 + _controlfp(_DN_FLUSH, _MCW_DN); #endif +} static void set_qt_style() { |