Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #140 from shuffle2/master
Implement workaround for Windows versions which do not support XSAVE.
  • Loading branch information
delroth committed Mar 6, 2014
2 parents e5b250f + 932945d commit c7b8c75
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
14 changes: 0 additions & 14 deletions Source/Core/Common/Common.h
Expand Up @@ -101,20 +101,6 @@ class NonCopyable

#endif

// Architecture detection for Windows
// Architecture detection is done in cmake on all other platforms
// Windows is built on only x86/x86_64
#if _WIN32 || _WIN64
#define _M_X86 1
#if _WIN64
#define _ARCH_64 1
#define _M_X86_64 1
#else
#define _ARCH_32 1
#define _M_X86_32 1
#endif
#endif

// Windows compatibility
#ifndef _WIN32
#include <limits.h>
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/Common.vcxproj
Expand Up @@ -125,6 +125,7 @@
<ClCompile Include="x64CPUDetect.cpp" />
<ClCompile Include="x64Emitter.cpp" />
<ClCompile Include="x64FPURoundMode.cpp" />
<ClCompile Include="XSaveWorkaround.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/Common.vcxproj.filters
Expand Up @@ -103,6 +103,7 @@
<Filter>Logging</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="XSaveWorkaround.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
Expand Down
40 changes: 40 additions & 0 deletions Source/Core/Common/XSaveWorkaround.cpp
@@ -0,0 +1,40 @@
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.

#if defined(_WIN32) && defined(_ARCH_64)

#include <math.h>
#include <Windows.h>

// This puts the rest of this translation unit into a segment which is
// initialized by the CRT *before* any of the other code (including C++
// static initializers).
#pragma warning(disable : 4075)
#pragma init_seg(".CRT$XCB")

struct EnableXSaveWorkaround
{
EnableXSaveWorkaround()
{
// Some Windows environments may have hardware support for AVX/FMA,
// but the OS does not support it. The CRT math library does not support
// this scenario, so we have to manually tell it not to use FMA3
// instructions.

// The API name is somewhat misleading - we're testing for OS support
// here.
if (!IsProcessorFeaturePresent(PF_XSAVE_ENABLED))
{
_set_FMA3_enable(0);
}
}
};

static EnableXSaveWorkaround enableXSaveWorkaround;

// N.B. Any code after this will still be in the .CRT$XCB segment. Please just
// do not append any code here unless it is intended to be executed before
// static initializers.

#endif
4 changes: 3 additions & 1 deletion Source/VSProps/Base.props
Expand Up @@ -57,7 +57,9 @@
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<MinimalRebuild>false</MinimalRebuild>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>/d2Zi+ /volatile:iso /D PSAPI_VERSION=1 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions>/d2Zi+ /volatile:iso /D PSAPI_VERSION=1 /D _M_X86=1 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Platform)'=='Win32'">/D _ARCH_32=1 /D _M_X86_32=1 %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Platform)'=='x64'">/D _ARCH_64=1 /D _M_X86_64=1 %(AdditionalOptions)</AdditionalOptions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<!--
This is for GetVersionEx being marked as depreciated - which is idiotic and there's
Expand Down

0 comments on commit c7b8c75

Please sign in to comment.