Index: base/cpu.cc |
diff --git a/base/cpu.cc b/base/cpu.cc |
index 0fef897ae6e1fdddff60fafdf7fad85fb85fb344..1de291e90648075fe2d839897f0e853459661cc3 100644 |
--- a/base/cpu.cc |
+++ b/base/cpu.cc |
@@ -3,8 +3,16 @@ |
// found in the LICENSE file. |
#include "base/cpu.h" |
+ |
+#if defined(ARCH_CPU_X86_FAMILY) |
+#if defined(_MSC_VER) |
#include <intrin.h> |
-#include <string> |
+#else |
+#include <cpuid.h> |
+#endif |
+#endif |
+ |
+#include <string.h> |
namespace base { |
@@ -15,11 +23,23 @@ CPU::CPU() |
stepping_(0), |
ext_model_(0), |
ext_family_(0), |
+ has_sse2_(false), |
cpu_vendor_("unknown") { |
Initialize(); |
} |
+#if defined(ARCH_CPU_X86_FAMILY) |
+static void cpuid(int info[4], int info_type) { |
+#if defined( _MSC_VER) |
+ __cpuid(info, info_type); |
+#else |
+ __cpuid(info_type, info[0], info[1], info[2], info[3]); |
fbarchard
2011/02/15 21:30:11
perfect :)
|
+#endif |
+} |
+#endif |
+ |
void CPU::Initialize() { |
+#if defined(ARCH_CPU_X86_FAMILY) |
int cpu_info[4] = {-1}; |
char cpu_string[0x20]; |
@@ -31,7 +51,7 @@ void CPU::Initialize() { |
// |
// More info can be found here: |
// http://msdn.microsoft.com/en-us/library/hskdteyh.aspx |
- __cpuid(cpu_info, 0); |
+ cpuid(cpu_info, 0); |
int num_ids = cpu_info[0]; |
memset(cpu_string, 0, sizeof(cpu_string)); |
*(reinterpret_cast<int*>(cpu_string)) = cpu_info[1]; |
@@ -40,7 +60,7 @@ void CPU::Initialize() { |
// Interpret CPU feature information. |
if (num_ids > 0) { |
- __cpuid(cpu_info, 1); |
+ cpuid(cpu_info, 1); |
stepping_ = cpu_info[0] & 0xf; |
model_ = (cpu_info[0] >> 4) & 0xf; |
family_ = (cpu_info[0] >> 8) & 0xf; |
@@ -48,7 +68,11 @@ void CPU::Initialize() { |
ext_model_ = (cpu_info[0] >> 16) & 0xf; |
ext_family_ = (cpu_info[0] >> 20) & 0xff; |
cpu_vendor_ = cpu_string; |
+ has_sse2_ = (cpu_info[3] & (1<<26)) != 0; |
} |
+#endif |
} |
+ |
+ |
} // namespace base |