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

Unified Diff: base/cpu.cc

Issue 12511002: Adding check for OS support to AVX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: using windows_verion and mac_util Created 7 years, 9 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 d6976bab33b316aed50e3a133edf1a7e8a060a97..8e47f0df21bf830ee2915731d6fc87e0397478cf 100644
--- a/base/cpu.cc
+++ b/base/cpu.cc
@@ -11,6 +11,20 @@
#include "build/build_config.h"
#if defined(ARCH_CPU_X86_FAMILY)
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
+#if defined(OS_LINUX)
+#include "base/file_util.h"
+#endif
+
+#if defined(OS_MACOSX)
+#include "base/mac/mac_util.h"
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
#if defined(_MSC_VER)
#include <intrin.h>
#endif
@@ -32,6 +46,7 @@ CPU::CPU()
has_ssse3_(false),
has_sse41_(false),
has_sse42_(false),
+ has_avx_(false),
cpu_vendor_("unknown") {
Initialize();
}
@@ -81,6 +96,44 @@ void __cpuidex(int cpu_info[4], int info_type, int info_index) {
#endif
#endif // _MSC_VER
+
+#if defined(OS_WIN)
+
+bool OSHasAVXSupport() {
+ base::win::OSInfo* info = base::win::OSInfo::GetInstance();
+
+ // Windows 7 SP1 added support for AVX.
+ return info->version() > base::win::VERSION_VISTA ||
apatrick_chromium 2013/03/07 21:22:47 This is checking for Windows 7 all versions or Vis
+ info->version() == base::win::VERSION_VISTA &&
+ info->service_pack().major >= 1;
+}
+
+#elif defined(OS_LINUX)
+
+bool OSHasAVXSupport() {
+ std::string buffer;
+ if (!file_util::ReadFileToString(base::FilePath("/proc/cpuinfo"), &buffer))
DaleCurtis 2013/03/07 21:12:11 As mentioned earlier, I'm pretty sure this will ca
whunt 2013/03/07 21:17:08 With this patch, Chrome *appears* to run correctly
DaleCurtis 2013/03/07 21:33:36 Ah looks like it doesn't crash but instead just fa
whunt 2013/03/07 21:49:03 I am neither very knowledgeable about linux or the
DaleCurtis 2013/03/07 21:57:43 Looks like you can use the xgetbv intrinsic once t
whunt 2013/03/07 23:28:54 awesome suggestion, done
+ return false;
+
+ // Scan through /proc/cpuinfo to see if the kernel supports AVX.
+ return buffer.find("avx") != std::string::npos;
+}
+
+#elif defined(OS_MACOSX)
+
+bool OSHasAVXSupport() {
+ // AVX support was added in 10.6.8
+ // This check is conservative due to the fact that IsOS... doesn't
+ // have minor versions
+ return base::mac::IsOSLionOrLater();
+}
+
+#else
+bool OSHasAVXSupport() {
+ return false;
+}
+
+#endif
#endif // ARCH_CPU_X86_FAMILY
void CPU::Initialize() {
@@ -117,7 +170,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 && OSHasAVXSupport();
}
// 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