Index: base/cpu.cc |
diff --git a/base/cpu.cc b/base/cpu.cc |
index 0fef897ae6e1fdddff60fafdf7fad85fb85fb344..7cda16aeab810c03240932758a71a738bbd3da4c 100644 |
--- a/base/cpu.cc |
+++ b/base/cpu.cc |
@@ -3,8 +3,14 @@ |
// found in the LICENSE file. |
#include "base/cpu.h" |
+ |
+#if defined(ARCH_CPU_X86_FAMILY) |
+#if defined(_MSC_VER) |
#include <intrin.h> |
-#include <string> |
+#endif |
+#endif |
+ |
+#include <string.h> |
namespace base { |
@@ -15,11 +21,28 @@ 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 |
+ asm volatile ( |
+ "cpuid \n\t" |
+ "movl %%ebx, %1 \n\t" |
+ : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) |
+ : "a"(info_type) |
+ ); |
+#endif |
+} |
+#endif |
fbarchard
2011/02/15 01:42:56
Your ebx usage seems -m32 -fpic unsafe?
I tried it
|
+ |
void CPU::Initialize() { |
+#if defined(ARCH_CPU_X86_FAMILY) |
int cpu_info[4] = {-1}; |
char cpu_string[0x20]; |
@@ -31,7 +54,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 +63,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 +71,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; |
fbarchard
2011/02/15 01:42:56
add has_ssse3_ while you're at it? Or a todo
|
} |
+#endif |
} |
+ |
+ |
} // namespace base |