Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: base/cpu.cc

Issue 22354004: Adding check for OS support to AVX (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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),
36 has_non_stop_time_stamp_counter_(false), 37 has_non_stop_time_stamp_counter_(false),
37 cpu_vendor_("unknown") { 38 cpu_vendor_("unknown") {
38 Initialize(); 39 Initialize();
39 } 40 }
40 41
41 #if defined(ARCH_CPU_X86_FAMILY) 42 #if defined(ARCH_CPU_X86_FAMILY)
42 #ifndef _MSC_VER 43 #ifndef _MSC_VER
43 44
44 #if defined(__pic__) && defined(__i386__) 45 #if defined(__pic__) && defined(__i386__)
45 46
(...skipping 29 matching lines...) Expand all
75 76
76 void __cpuidex(int cpu_info[4], int info_type, int info_index) { 77 void __cpuidex(int cpu_info[4], int info_type, int info_index) {
77 __asm__ volatile ( 78 __asm__ volatile (
78 "cpuid \n\t" 79 "cpuid \n\t"
79 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3]) 80 : "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
80 : "a"(info_type), "c"(info_index) 81 : "a"(info_type), "c"(info_index)
81 ); 82 );
82 } 83 }
83 84
84 #endif 85 #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 }
85 #endif // _MSC_VER 97 #endif // _MSC_VER
86 #endif // ARCH_CPU_X86_FAMILY 98 #endif // ARCH_CPU_X86_FAMILY
87 99
88 void CPU::Initialize() { 100 void CPU::Initialize() {
89 #if defined(ARCH_CPU_X86_FAMILY) 101 #if defined(ARCH_CPU_X86_FAMILY)
90 int cpu_info[4] = {-1}; 102 int cpu_info[4] = {-1};
91 char cpu_string[48]; 103 char cpu_string[48];
92 104
93 // __cpuid with an InfoType argument of 0 returns the number of 105 // __cpuid with an InfoType argument of 0 returns the number of
94 // valid Ids in CPUInfo[0] and the CPU identification string in 106 // valid Ids in CPUInfo[0] and the CPU identification string in
(...skipping 18 matching lines...) Expand all
113 type_ = (cpu_info[0] >> 12) & 0x3; 125 type_ = (cpu_info[0] >> 12) & 0x3;
114 ext_model_ = (cpu_info[0] >> 16) & 0xf; 126 ext_model_ = (cpu_info[0] >> 16) & 0xf;
115 ext_family_ = (cpu_info[0] >> 20) & 0xff; 127 ext_family_ = (cpu_info[0] >> 20) & 0xff;
116 has_mmx_ = (cpu_info[3] & 0x00800000) != 0; 128 has_mmx_ = (cpu_info[3] & 0x00800000) != 0;
117 has_sse_ = (cpu_info[3] & 0x02000000) != 0; 129 has_sse_ = (cpu_info[3] & 0x02000000) != 0;
118 has_sse2_ = (cpu_info[3] & 0x04000000) != 0; 130 has_sse2_ = (cpu_info[3] & 0x04000000) != 0;
119 has_sse3_ = (cpu_info[2] & 0x00000001) != 0; 131 has_sse3_ = (cpu_info[2] & 0x00000001) != 0;
120 has_ssse3_ = (cpu_info[2] & 0x00000200) != 0; 132 has_ssse3_ = (cpu_info[2] & 0x00000200) != 0;
121 has_sse41_ = (cpu_info[2] & 0x00080000) != 0; 133 has_sse41_ = (cpu_info[2] & 0x00080000) != 0;
122 has_sse42_ = (cpu_info[2] & 0x00100000) != 0; 134 has_sse42_ = (cpu_info[2] & 0x00100000) != 0;
123 has_avx_ = (cpu_info[2] & 0x10000000) != 0; 135 has_avx_ = (cpu_info[2] & 0x10000000) != 0 && (_xgetbv(0) & 6) == 6;
124 } 136 }
125 137
126 // Get the brand string of the cpu. 138 // Get the brand string of the cpu.
127 __cpuid(cpu_info, 0x80000000); 139 __cpuid(cpu_info, 0x80000000);
128 const int parameter_end = 0x80000004; 140 const int parameter_end = 0x80000004;
129 int max_parameter = cpu_info[0]; 141 int max_parameter = cpu_info[0];
130 142
131 if (cpu_info[0] >= parameter_end) { 143 if (cpu_info[0] >= parameter_end) {
132 char* cpu_string_ptr = cpu_string; 144 char* cpu_string_ptr = cpu_string;
133 145
(...skipping 19 matching lines...) Expand all
153 if (has_sse42()) return SSE42; 165 if (has_sse42()) return SSE42;
154 if (has_sse41()) return SSE41; 166 if (has_sse41()) return SSE41;
155 if (has_ssse3()) return SSSE3; 167 if (has_ssse3()) return SSSE3;
156 if (has_sse3()) return SSE3; 168 if (has_sse3()) return SSE3;
157 if (has_sse2()) return SSE2; 169 if (has_sse2()) return SSE2;
158 if (has_sse()) return SSE; 170 if (has_sse()) return SSE;
159 return PENTIUM; 171 return PENTIUM;
160 } 172 }
161 173
162 } // namespace base 174 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698