Index: base/cpu.cc |
diff --git a/base/cpu.cc b/base/cpu.cc |
index d6976bab33b316aed50e3a133edf1a7e8a060a97..74513739f121ebc348e48a3b8f4cd0ed0cfefcf3 100644 |
--- a/base/cpu.cc |
+++ b/base/cpu.cc |
@@ -32,6 +32,7 @@ CPU::CPU() |
has_ssse3_(false), |
has_sse41_(false), |
has_sse42_(false), |
+ has_avx_(false), |
cpu_vendor_("unknown") { |
Initialize(); |
} |
@@ -80,6 +81,17 @@ void __cpuidex(int cpu_info[4], int info_type, int info_index) { |
} |
#endif |
+ |
+unsigned long long _xgetbv(unsigned int xcr) { |
+ unsigned int eax, edx; |
+ __asm__ volatile ( |
+ ".byte 0x0f, 0x01, 0xd0" |
+ : "=a"(eax), "=d"(edx) |
+ : "c" (xcr) |
+ ); |
+ return static_cast<unsigned long long>(eax) ^ |
+ static_cast<unsigned long long>(edx) << 32; |
+} |
#endif // _MSC_VER |
#endif // ARCH_CPU_X86_FAMILY |
@@ -117,7 +129,7 @@ void CPU::Initialize() { |
has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; |
has_sse41_ = (cpu_info[2] & 0x00080000) != 0; |
has_sse42_ = (cpu_info[2] & 0x00100000) != 0; |
- has_avx_ = (cpu_info[2] & 0x10000000) != 0; |
+ has_avx_ = (cpu_info[2] & 0x10000000) != 0 && (_xgetbv(0) & 6) == 6; |
DaleCurtis
2013/03/07 23:37:15
I think this needs #include <immintrin.h> on Windo
apatrick_chromium
2013/03/08 00:39:41
This says that it need Visual Studio 2010 SP1, whi
whunt
2013/03/08 18:30:32
XSAVE/XRSTOR are required for SSE to work at all a
whunt
2013/03/08 18:30:32
<intrin.h> should include <immintrin.h>
I've only
|
} |
// Get the brand string of the cpu. |