OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 stepping_(0), | 26 stepping_(0), |
27 ext_model_(0), | 27 ext_model_(0), |
28 ext_family_(0), | 28 ext_family_(0), |
29 has_mmx_(false), | 29 has_mmx_(false), |
30 has_sse_(false), | 30 has_sse_(false), |
31 has_sse2_(false), | 31 has_sse2_(false), |
32 has_sse3_(false), | 32 has_sse3_(false), |
33 has_ssse3_(false), | 33 has_ssse3_(false), |
34 has_sse41_(false), | 34 has_sse41_(false), |
35 has_sse42_(false), | 35 has_sse42_(false), |
36 has_avx_(false), | |
37 has_non_stop_time_stamp_counter_(false), | 36 has_non_stop_time_stamp_counter_(false), |
38 cpu_vendor_("unknown") { | 37 cpu_vendor_("unknown") { |
39 Initialize(); | 38 Initialize(); |
40 } | 39 } |
41 | 40 |
42 #if defined(ARCH_CPU_X86_FAMILY) | 41 #if defined(ARCH_CPU_X86_FAMILY) |
43 #ifndef _MSC_VER | 42 #ifndef _MSC_VER |
44 | 43 |
45 #if defined(__pic__) && defined(__i386__) | 44 #if defined(__pic__) && defined(__i386__) |
46 | 45 |
(...skipping 29 matching lines...) Expand all Loading... |
76 | 75 |
77 void __cpuidex(int cpu_info[4], int info_type, int info_index) { | 76 void __cpuidex(int cpu_info[4], int info_type, int info_index) { |
78 __asm__ volatile ( | 77 __asm__ volatile ( |
79 "cpuid \n\t" | 78 "cpuid \n\t" |
80 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) | 79 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) |
81 : "a"(info_type), "c"(info_index) | 80 : "a"(info_type), "c"(info_index) |
82 ); | 81 ); |
83 } | 82 } |
84 | 83 |
85 #endif | 84 #endif |
86 | |
87 unsigned long long _xgetbv(unsigned int xcr) { | |
88 unsigned int eax, edx; | |
89 __asm__ volatile ( | |
90 ".byte 0x0f, 0x01, 0xd0" | |
91 : "=a"(eax), "=d"(edx) | |
92 : "c" (xcr) | |
93 ); | |
94 return static_cast<unsigned long long>(eax) ^ | |
95 static_cast<unsigned long long>(edx) << 32; | |
96 } | |
97 #endif // _MSC_VER | 85 #endif // _MSC_VER |
98 #endif // ARCH_CPU_X86_FAMILY | 86 #endif // ARCH_CPU_X86_FAMILY |
99 | 87 |
100 void CPU::Initialize() { | 88 void CPU::Initialize() { |
101 #if defined(ARCH_CPU_X86_FAMILY) | 89 #if defined(ARCH_CPU_X86_FAMILY) |
102 int cpu_info[4] = {-1}; | 90 int cpu_info[4] = {-1}; |
103 char cpu_string[48]; | 91 char cpu_string[48]; |
104 | 92 |
105 // __cpuid with an InfoType argument of 0 returns the number of | 93 // __cpuid with an InfoType argument of 0 returns the number of |
106 // valid Ids in CPUInfo[0] and the CPU identification string in | 94 // valid Ids in CPUInfo[0] and the CPU identification string in |
(...skipping 18 matching lines...) Expand all Loading... |
125 type_ = (cpu_info[0] >> 12) & 0x3; | 113 type_ = (cpu_info[0] >> 12) & 0x3; |
126 ext_model_ = (cpu_info[0] >> 16) & 0xf; | 114 ext_model_ = (cpu_info[0] >> 16) & 0xf; |
127 ext_family_ = (cpu_info[0] >> 20) & 0xff; | 115 ext_family_ = (cpu_info[0] >> 20) & 0xff; |
128 has_mmx_ = (cpu_info[3] & 0x00800000) != 0; | 116 has_mmx_ = (cpu_info[3] & 0x00800000) != 0; |
129 has_sse_ = (cpu_info[3] & 0x02000000) != 0; | 117 has_sse_ = (cpu_info[3] & 0x02000000) != 0; |
130 has_sse2_ = (cpu_info[3] & 0x04000000) != 0; | 118 has_sse2_ = (cpu_info[3] & 0x04000000) != 0; |
131 has_sse3_ = (cpu_info[2] & 0x00000001) != 0; | 119 has_sse3_ = (cpu_info[2] & 0x00000001) != 0; |
132 has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; | 120 has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; |
133 has_sse41_ = (cpu_info[2] & 0x00080000) != 0; | 121 has_sse41_ = (cpu_info[2] & 0x00080000) != 0; |
134 has_sse42_ = (cpu_info[2] & 0x00100000) != 0; | 122 has_sse42_ = (cpu_info[2] & 0x00100000) != 0; |
135 has_avx_ = (cpu_info[2] & 0x10000000) != 0 && (_xgetbv(0) & 6) == 6; | 123 has_avx_ = (cpu_info[2] & 0x10000000) != 0; |
136 } | 124 } |
137 | 125 |
138 // Get the brand string of the cpu. | 126 // Get the brand string of the cpu. |
139 __cpuid(cpu_info, 0x80000000); | 127 __cpuid(cpu_info, 0x80000000); |
140 const int parameter_end = 0x80000004; | 128 const int parameter_end = 0x80000004; |
141 int max_parameter = cpu_info[0]; | 129 int max_parameter = cpu_info[0]; |
142 | 130 |
143 if (cpu_info[0] >= parameter_end) { | 131 if (cpu_info[0] >= parameter_end) { |
144 char* cpu_string_ptr = cpu_string; | 132 char* cpu_string_ptr = cpu_string; |
145 | 133 |
(...skipping 19 matching lines...) Expand all Loading... |
165 if (has_sse42()) return SSE42; | 153 if (has_sse42()) return SSE42; |
166 if (has_sse41()) return SSE41; | 154 if (has_sse41()) return SSE41; |
167 if (has_ssse3()) return SSSE3; | 155 if (has_ssse3()) return SSSE3; |
168 if (has_sse3()) return SSE3; | 156 if (has_sse3()) return SSE3; |
169 if (has_sse2()) return SSE2; | 157 if (has_sse2()) return SSE2; |
170 if (has_sse()) return SSE; | 158 if (has_sse()) return SSE; |
171 return PENTIUM; | 159 return PENTIUM; |
172 } | 160 } |
173 | 161 |
174 } // namespace base | 162 } // namespace base |
OLD | NEW |