Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Unified Diff: base/cpu.cc

Issue 22354004: Adding check for OS support to AVX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/cpu.cc
diff --git a/base/cpu.cc b/base/cpu.cc
index 1761529e046edf2531d2d4612ca6d78c9b96289a..7ea212ef64b205d6025bc8855f784f0ba2ea4f7f 100644
--- a/base/cpu.cc
+++ b/base/cpu.cc
@@ -33,6 +33,7 @@ CPU::CPU()
has_ssse3_(false),
has_sse41_(false),
has_sse42_(false),
+ has_avx_(false),
has_non_stop_time_stamp_counter_(false),
cpu_vendor_("unknown") {
Initialize();
@@ -82,6 +83,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
@@ -120,7 +132,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;
}
// Get the brand string of the cpu.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698