Chromium Code Reviews| 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. |