diff options
| author | shuffle2 <godisgovernment@gmail.com> | 2014-08-11 12:47:39 -0700 |
|---|---|---|
| committer | shuffle2 <godisgovernment@gmail.com> | 2014-08-11 12:47:39 -0700 |
| commit | edf660f21fcb01b52d9588d8e66367e1b6fefb5f (patch) | |
| tree | 0a0b5176c3b3196f509f367ec7cc8ecc21155d19 /Source/Core/Common/XSaveWorkaround.cpp | |
| parent | 5928eacbe2eacaffeff991066470e1c03b2afe44 (diff) | |
| parent | d0c3e46c800ec30492127589e3a55ac912b28e90 (diff) | |
Merge pull request #776 from shuffle2/improve-xsaveworkaround
Windows: Improve XSaveWorkaround to behave correctly when XSAVE processor feature is enabled, but AVX support isn't available for whatever reason.
Diffstat (limited to 'Source/Core/Common/XSaveWorkaround.cpp')
| -rw-r--r-- | Source/Core/Common/XSaveWorkaround.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Source/Core/Common/XSaveWorkaround.cpp b/Source/Core/Common/XSaveWorkaround.cpp index 78f92b9bcf..d73b4a6ee0 100644 --- a/Source/Core/Common/XSaveWorkaround.cpp +++ b/Source/Core/Common/XSaveWorkaround.cpp @@ -7,6 +7,8 @@ #include <math.h> #include <Windows.h> +typedef decltype(&GetEnabledXStateFeatures) GetEnabledXStateFeatures_t; + int __cdecl EnableXSaveWorkaround() { // Some Windows environments may have hardware support for AVX/FMA, @@ -19,6 +21,24 @@ int __cdecl EnableXSaveWorkaround() if (!IsProcessorFeaturePresent(PF_XSAVE_ENABLED)) { _set_FMA3_enable(0); + return 0; + } + + // Even if XSAVE feature is enabled, we have to see if + // GetEnabledXStateFeatures function is present, and see what it says about + // AVX state. + auto kernel32Handle = GetModuleHandle(TEXT("kernel32.dll")); + if (kernel32Handle == nullptr) + { + std::abort(); + } + + auto pGetEnabledXStateFeatures = (GetEnabledXStateFeatures_t)GetProcAddress( + kernel32Handle, "GetEnabledXStateFeatures"); + if (pGetEnabledXStateFeatures == nullptr || + (pGetEnabledXStateFeatures() & XSTATE_MASK_AVX) == 0) + { + _set_FMA3_enable(0); } return 0; |
