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

Unified Diff: base/cpu.cc

Issue 11009011: Use the cpuid instruction to generate the CPU brand string. And (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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
Index: base/cpu.cc
===================================================================
--- base/cpu.cc (revision 159378)
+++ base/cpu.cc (working copy)
@@ -84,8 +84,9 @@
void CPU::Initialize() {
#if defined(ARCH_CPU_X86_FAMILY)
int cpu_info[4] = {-1};
- char cpu_string[0x20];
-
+ char cpu_string[32];
Mark Mentovai 2012/10/03 18:34:02 Now let’s make this stuff conform to Chromium styl
+ char cpu_brand[48];
Mark Mentovai 2012/10/03 18:34:02 You can share a buffer for cpu_string and cpu_bran
+ const int para_end = 0x80000004;
Mark Mentovai 2012/10/03 18:34:02 Don’t abbreviate. http://google-styleguide.googlec
// __cpuid with an InfoType argument of 0 returns the number of
// valid Ids in CPUInfo[0] and the CPU identification string in
// the other three array elements. The CPU identification string is
@@ -118,6 +119,21 @@
has_ssse3_ = (cpu_info[2] & 0x00000200) != 0;
has_sse41_ = (cpu_info[2] & 0x00080000) != 0;
has_sse42_ = (cpu_info[2] & 0x00100000) != 0;
+
+ // get the brand string of the cpu.
Mark Mentovai 2012/10/03 18:34:02 Comments should be written as sentences, and sente
Mark Mentovai 2012/10/03 18:34:02 I don’t think there’s any reason for this to be in
+ __cpuid(cpu_info, 0x80000000);
+
+ if (cpu_info[0] >= para_end) {
+ memset(cpu_brand, 0, sizeof(cpu_brand));
Mark Mentovai 2012/10/03 18:34:02 You don’t need this memset, because you’re going t
+ char* cpu_brand_ptr = cpu_brand;
+
+ for (int parameter = 0x80000002; parameter <= para_end; parameter++) {
+ __cpuid(cpu_info, parameter);
+ memcpy(cpu_brand_ptr, cpu_info, sizeof(cpu_info));
+ cpu_brand_ptr += sizeof(cpu_info);
+ }
+ cpu_brand_ = cpu_brand;
Mark Mentovai 2012/10/03 18:34:02 cpu_brand is not necessarily NUL-terminated as you
jar (doing other things) 2012/10/04 17:42:03 I couldn't find documentation that suggests the st
Mark Mentovai 2012/10/04 18:00:45 jar wrote:
+ }
}
#endif
}
« AUTHORS ('K') | « base/cpu.h ('k') | content/browser/gpu/gpu_blacklist.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698