summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gypi1
-rw-r--r--base/cpu.cc77
-rw-r--r--base/cpu.h18
3 files changed, 91 insertions, 5 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 7a5da2e..79ba5f4 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -515,7 +515,6 @@
'third_party/purify/pure_api.c',
'base_drag_source.cc',
'base_drop_target.cc',
- 'cpu.cc',
'crypto/capi_util.h',
'crypto/capi_util.cc',
'event_recorder.cc',
diff --git a/base/cpu.cc b/base/cpu.cc
index 0fef897..3232f15 100644
--- a/base/cpu.cc
+++ b/base/cpu.cc
@@ -1,10 +1,16 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// 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,66 @@ CPU::CPU()
stepping_(0),
ext_model_(0),
ext_family_(0),
+ has_mmx_(false),
+ has_sse_(false),
+ has_sse2_(false),
+ has_sse3_(false),
+ has_ssse3_(false),
+ has_sse41_(false),
+ has_sse42_(false),
cpu_vendor_("unknown") {
Initialize();
}
+#if defined(ARCH_CPU_X86_FAMILY)
+#ifndef _MSC_VER
+
+#if defined(__pic__) && defined(__i386__)
+
+void __cpuid(int cpu_info[4], int info_type) {
+ __asm__ volatile (
+ "mov %%ebx, %%edi\n"
+ "cpuid\n"
+ "xchg %%edi, %%ebx\n"
+ : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type)
+ );
+}
+
+void __cpuidex(int cpu_info[4], int info_type, int info_index) {
+ __asm__ volatile (
+ "mov %%ebx, %%edi\n"
+ "cpuid\n"
+ "xchg %%edi, %%ebx\n"
+ : "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type), "c"(info_index)
+ );
+}
+
+#else
+
+void __cpuid(int cpu_info[4], int info_type) {
+ __asm__ volatile (
+ "cpuid \n\t"
+ : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type)
+ );
+}
+
+void __cpuidex(int cpu_info[4], int info_type, int info_index) {
+ __asm__ volatile (
+ "cpuid \n\t"
+ : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
+ : "a"(info_type), "c"(info_index)
+ );
+}
+
+#endif
+#endif // _MSC_VER
+#endif // ARCH_CPU_X86_FAMILY
+
void CPU::Initialize() {
+#if defined(ARCH_CPU_X86_FAMILY)
int cpu_info[4] = {-1};
char cpu_string[0x20];
@@ -42,13 +103,23 @@ void CPU::Initialize() {
if (num_ids > 0) {
__cpuid(cpu_info, 1);
stepping_ = cpu_info[0] & 0xf;
- model_ = (cpu_info[0] >> 4) & 0xf;
+ model_ = ((cpu_info[0] >> 4) & 0xf) + ((cpu_info[0] >> 12) & 0xf0);
family_ = (cpu_info[0] >> 8) & 0xf;
type_ = (cpu_info[0] >> 12) & 0x3;
ext_model_ = (cpu_info[0] >> 16) & 0xf;
ext_family_ = (cpu_info[0] >> 20) & 0xff;
cpu_vendor_ = cpu_string;
+ has_mmx_ = (cpu_info[3] & 0x00800000) != 0;
+ has_sse_ = (cpu_info[3] & 0x02000000) != 0;
+ has_sse2_ = (cpu_info[3] & 0x04000000) != 0;
+ has_sse3_ = (cpu_info[2] & 0x00000001) != 0;
+ has_ssse3_ = (cpu_info[2] & 0x00000200) != 0;
+ has_sse41_ = (cpu_info[2] & 0x00080000) != 0;
+ has_sse42_ = (cpu_info[2] & 0x00100000) != 0;
}
+#endif
}
+
+
} // namespace base
diff --git a/base/cpu.h b/base/cpu.h
index 963da1a7..1634bf9 100644
--- a/base/cpu.h
+++ b/base/cpu.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,8 @@
#define BASE_CPU_H_
#pragma once
+#include "build/build_config.h"
+
#include <string>
namespace base {
@@ -24,6 +26,13 @@ class CPU {
int type() const { return type_; }
int extended_model() const { return ext_model_; }
int extended_family() const { return ext_family_; }
+ int has_mmx() const { return has_mmx_; }
+ int has_sse() const { return has_sse_; }
+ int has_sse2() const { return has_sse2_; }
+ int has_sse3() const { return has_sse3_; }
+ int has_ssse3() const { return has_ssse3_; }
+ int has_sse41() const { return has_sse41_; }
+ int has_sse42() const { return has_sse42_; }
private:
// Query the processor for CPUID information.
@@ -35,6 +44,13 @@ class CPU {
int stepping_; // processor revision number
int ext_model_;
int ext_family_;
+ bool has_mmx_;
+ bool has_sse_;
+ bool has_sse2_;
+ bool has_sse3_;
+ bool has_ssse3_;
+ bool has_sse41_;
+ bool has_sse42_;
std::string cpu_vendor_;
};