OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/cpu.h" | 5 #include "base/cpu.h" |
6 #include <intrin.h> | 6 #include <intrin.h> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 // More info can be found here: | 32 // More info can be found here: |
33 // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx | 33 // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx |
34 __cpuid(cpu_info, 0); | 34 __cpuid(cpu_info, 0); |
35 int num_ids = cpu_info[0]; | 35 int num_ids = cpu_info[0]; |
36 memset(cpu_string, 0, sizeof(cpu_string)); | 36 memset(cpu_string, 0, sizeof(cpu_string)); |
37 *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1]; | 37 *(reinterpret_cast<int*>(cpu_string)) = cpu_info[1]; |
38 *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3]; | 38 *(reinterpret_cast<int*>(cpu_string+4)) = cpu_info[3]; |
39 *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2]; | 39 *(reinterpret_cast<int*>(cpu_string+8)) = cpu_info[2]; |
40 | 40 |
41 // Interpret CPU feature information. | 41 // Interpret CPU feature information. |
42 __cpuid(cpu_info, 1); | 42 if (num_ids > 0) { |
43 stepping_ = cpu_info[0] & 0xf; | 43 __cpuid(cpu_info, 1); |
44 model_ = (cpu_info[0] >> 4) & 0xf; | 44 stepping_ = cpu_info[0] & 0xf; |
45 family_ = (cpu_info[0] >> 8) & 0xf; | 45 model_ = (cpu_info[0] >> 4) & 0xf; |
46 type_ = (cpu_info[0] >> 12) & 0x3; | 46 family_ = (cpu_info[0] >> 8) & 0xf; |
47 ext_model_ = (cpu_info[0] >> 16) & 0xf; | 47 type_ = (cpu_info[0] >> 12) & 0x3; |
48 ext_family_ = (cpu_info[0] >> 20) & 0xff; | 48 ext_model_ = (cpu_info[0] >> 16) & 0xf; |
49 cpu_vendor_ = cpu_string; | 49 ext_family_ = (cpu_info[0] >> 20) & 0xff; |
| 50 cpu_vendor_ = cpu_string; |
| 51 } |
50 } | 52 } |
51 | 53 |
52 } // namespace base | 54 } // namespace base |
OLD | NEW |