michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base/cpu.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace base { michael@0: michael@0: CPU::CPU() michael@0: : type_(0), michael@0: family_(0), michael@0: model_(0), michael@0: stepping_(0), michael@0: ext_model_(0), michael@0: ext_family_(0), michael@0: cpu_vendor_("unknown") { michael@0: Initialize(); michael@0: } michael@0: michael@0: void CPU::Initialize() { michael@0: int cpu_info[4] = {-1}; michael@0: char cpu_string[0x20]; michael@0: michael@0: // __cpuid with an InfoType argument of 0 returns the number of michael@0: // valid Ids in CPUInfo[0] and the CPU identification string in michael@0: // the other three array elements. The CPU identification string is michael@0: // not in linear order. The code below arranges the information michael@0: // in a human readable form. michael@0: // michael@0: // More info can be found here: michael@0: // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx michael@0: __cpuid(cpu_info, 0); michael@0: int num_ids = cpu_info[0]; michael@0: memset(cpu_string, 0, sizeof(cpu_string)); michael@0: *(reinterpret_cast(cpu_string)) = cpu_info[1]; michael@0: *(reinterpret_cast(cpu_string+4)) = cpu_info[3]; michael@0: *(reinterpret_cast(cpu_string+8)) = cpu_info[2]; michael@0: michael@0: // Interpret CPU feature information. michael@0: if (num_ids > 0) { michael@0: __cpuid(cpu_info, 1); michael@0: stepping_ = cpu_info[0] & 0xf; michael@0: model_ = (cpu_info[0] >> 4) & 0xf; michael@0: family_ = (cpu_info[0] >> 8) & 0xf; michael@0: type_ = (cpu_info[0] >> 12) & 0x3; michael@0: ext_model_ = (cpu_info[0] >> 16) & 0xf; michael@0: ext_family_ = (cpu_info[0] >> 20) & 0xff; michael@0: cpu_vendor_ = cpu_string; michael@0: } michael@0: } michael@0: michael@0: } // namespace base