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

Unified Diff: base/cpu.cc

Issue 6526005: detect cpu feature for all x64 and x86 platforms (no longer windows only). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use cpuid.h Created 9 years, 10 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
« base/cpu.h ('K') | « base/cpu.h ('k') | 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 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
« base/cpu.h ('K') | « base/cpu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698