From 4b2dc74d3f17b40a57eba3068ce498a7f30769fe Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 17 Oct 2011 05:33:10 +0000 Subject: [PATCH] Don't use inline assembly in 64-bit Visual Studio. Unfortunately, this means that cpuid leaf 7 can't be queried on versions of Visual Studio earlier than VS 2008 SP1. Fixes PR11147. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142177 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../X86/MCTargetDesc/X86MCTargetDesc.cpp | 26 +++++++------------ lib/Target/X86/X86Subtarget.cpp | 17 ++++++------ 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index 7cdd5b1b20f..37984195b09 100644 --- a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -126,22 +126,16 @@ bool X86_MC::GetCpuIDAndInfoEx(unsigned value, unsigned subleaf, unsigned *rEAX, "c" (subleaf)); return false; #elif defined(_MSC_VER) - // can't use __cpuidex because it isn't available in all supported versions - // of MSC - __asm { - mov eax,value - mov ecx,subleaf - cpuid - mov rsi,rEAX - mov dword ptr [rsi],eax - mov rsi,rEBX - mov dword ptr [rsi],ebx - mov rsi,rECX - mov dword ptr [rsi],ecx - mov rsi,rEDX - mov dword ptr [rsi],edx - } - return false; + // __cpuidex was added in MSVC++ 9.0 SP1 + #if (_MSC_VER > 1500) || (_MSC_VER == 1500 && _MSC_FULL_VER >= 150030729) + int registers[4]; + __cpuidex(registers, value, subleaf); + *rEAX = registers[0]; + *rEBX = registers[1]; + *rECX = registers[2]; + *rEDX = registers[3]; + return false; + #endif #endif #elif defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86) #if defined(__GNUC__) diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index c08dac9f999..45a8c2f1e81 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -278,14 +278,15 @@ void X86Subtarget::AutoDetectSubtargetFeatures() { } if (IsIntel && MaxLevel >= 7) { - X86_MC::GetCpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX); - if ((EBX >> 3) & 0x1) { - HasBMI = true; - ToggleFeature(X86::FeatureBMI); - } - if ((EBX >> 8) & 0x1) { - HasBMI2 = true; - ToggleFeature(X86::FeatureBMI2); + if (!X86_MC::GetCpuIDAndInfoEx(0x7, 0x0, &EAX, &EBX, &ECX, &EDX)) { + if ((EBX >> 3) & 0x1) { + HasBMI = true; + ToggleFeature(X86::FeatureBMI); + } + if ((EBX >> 8) & 0x1) { + HasBMI2 = true; + ToggleFeature(X86::FeatureBMI2); + } } } }