ipc/chromium/src/base/cpu.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/cpu.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "base/cpu.h"
     1.9 +#include <intrin.h>
    1.10 +#include <string>
    1.11 +
    1.12 +namespace base {
    1.13 +
    1.14 +CPU::CPU()
    1.15 +  : type_(0),
    1.16 +    family_(0),
    1.17 +    model_(0),
    1.18 +    stepping_(0),
    1.19 +    ext_model_(0),
    1.20 +    ext_family_(0),
    1.21 +    cpu_vendor_("unknown") {
    1.22 +  Initialize();
    1.23 +}
    1.24 +
    1.25 +void CPU::Initialize() {
    1.26 +  int cpu_info[4] = {-1};
    1.27 +  char cpu_string[0x20];
    1.28 +
    1.29 +  // __cpuid with an InfoType argument of 0 returns the number of
    1.30 +  // valid Ids in CPUInfo[0] and the CPU identification string in
    1.31 +  // the other three array elements. The CPU identification string is
    1.32 +  // not in linear order. The code below arranges the information
    1.33 +  // in a human readable form.
    1.34 +  //
    1.35 +  // More info can be found here:
    1.36 +  // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
    1.37 +  __cpuid(cpu_info, 0);
    1.38 +  int num_ids = cpu_info[0];
    1.39 +  memset(cpu_string, 0, sizeof(cpu_string));
    1.40 +  *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
    1.41 +  *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
    1.42 +  *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
    1.43 +
    1.44 +  // Interpret CPU feature information.
    1.45 +  if (num_ids > 0) {
    1.46 +    __cpuid(cpu_info, 1);
    1.47 +    stepping_ = cpu_info[0] & 0xf;
    1.48 +    model_ = (cpu_info[0] >> 4) & 0xf;
    1.49 +    family_ = (cpu_info[0] >> 8) & 0xf;
    1.50 +    type_ = (cpu_info[0] >> 12) & 0x3;
    1.51 +    ext_model_ = (cpu_info[0] >> 16) & 0xf;
    1.52 +    ext_family_ = (cpu_info[0] >> 20) & 0xff;
    1.53 +    cpu_vendor_ = cpu_string;
    1.54 +  }
    1.55 +}
    1.56 +
    1.57 +}  // namespace base

mercurial