ipc/chromium/src/base/cpu.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 #include "base/cpu.h"
     6 #include <intrin.h>
     7 #include <string>
     9 namespace base {
    11 CPU::CPU()
    12   : type_(0),
    13     family_(0),
    14     model_(0),
    15     stepping_(0),
    16     ext_model_(0),
    17     ext_family_(0),
    18     cpu_vendor_("unknown") {
    19   Initialize();
    20 }
    22 void CPU::Initialize() {
    23   int cpu_info[4] = {-1};
    24   char cpu_string[0x20];
    26   // __cpuid with an InfoType argument of 0 returns the number of
    27   // valid Ids in CPUInfo[0] and the CPU identification string in
    28   // the other three array elements. The CPU identification string is
    29   // not in linear order. The code below arranges the information
    30   // in a human readable form.
    31   //
    32   // More info can be found here:
    33   // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
    34   __cpuid(cpu_info, 0);
    35   int num_ids = cpu_info[0];
    36   memset(cpu_string, 0, sizeof(cpu_string));
    37   *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1];
    38   *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3];
    39   *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2];
    41   // Interpret CPU feature information.
    42   if (num_ids > 0) {
    43     __cpuid(cpu_info, 1);
    44     stepping_ = cpu_info[0] & 0xf;
    45     model_ = (cpu_info[0] >> 4) & 0xf;
    46     family_ = (cpu_info[0] >> 8) & 0xf;
    47     type_ = (cpu_info[0] >> 12) & 0x3;
    48     ext_model_ = (cpu_info[0] >> 16) & 0xf;
    49     ext_family_ = (cpu_info[0] >> 20) & 0xff;
    50     cpu_vendor_ = cpu_string;
    51   }
    52 }
    54 }  // namespace base

mercurial