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

Side by Side Diff: source/libvpx/third_party/libyuv/source/cpu_id.cc

Issue 996503002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // Low level cpuid for X86. Returns zeros on other CPUs. 46 // Low level cpuid for X86. Returns zeros on other CPUs.
47 #if !defined(__pnacl__) && !defined(__CLR_VER) && \ 47 #if !defined(__pnacl__) && !defined(__CLR_VER) && \
48 (defined(_M_IX86) || defined(_M_X64) || \ 48 (defined(_M_IX86) || defined(_M_X64) || \
49 defined(__i386__) || defined(__x86_64__)) 49 defined(__i386__) || defined(__x86_64__))
50 LIBYUV_API 50 LIBYUV_API
51 void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { 51 void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) {
52 #if defined(_MSC_VER) && !defined(__clang__) 52 #if defined(_MSC_VER) && !defined(__clang__)
53 #if (_MSC_FULL_VER >= 160040219) 53 #if (_MSC_FULL_VER >= 160040219)
54 __cpuidex((int*)(cpu_info), info_eax, info_ecx); 54 __cpuidex((int*)(cpu_info), info_eax, info_ecx);
55 #elif defined(_M_IX86) 55 #endif
56 #if defined(_M_IX86)
56 __asm { 57 __asm {
57 mov eax, info_eax 58 mov eax, info_eax
58 mov ecx, info_ecx 59 mov ecx, info_ecx
59 mov edi, cpu_info 60 mov edi, cpu_info
60 cpuid 61 cpuid
61 mov [edi], eax 62 mov [edi], eax
62 mov [edi + 4], ebx 63 mov [edi + 4], ebx
63 mov [edi + 8], ecx 64 mov [edi + 8], ecx
64 mov [edi + 12], edx 65 mov [edi + 12], edx
65 } 66 }
(...skipping 25 matching lines...) Expand all
91 #endif // defined(_MSC_VER) 92 #endif // defined(_MSC_VER)
92 } 93 }
93 94
94 #if !defined(__native_client__) 95 #if !defined(__native_client__)
95 #define HAS_XGETBV 96 #define HAS_XGETBV
96 // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. 97 // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers.
97 int TestOsSaveYmm() { 98 int TestOsSaveYmm() {
98 uint32 xcr0 = 0u; 99 uint32 xcr0 = 0u;
99 #if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219) 100 #if defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219)
100 xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. 101 xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required.
101 #elif defined(_M_IX86) && defined(_MSC_VER) 102 #endif
103 #if defined(_M_IX86) && defined(_MSC_VER)
102 __asm { 104 __asm {
103 xor ecx, ecx // xcr 0 105 xor ecx, ecx // xcr 0
104 _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier. 106 _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier.
105 mov xcr0, eax 107 mov xcr0, eax
106 } 108 }
107 #elif defined(__i386__) || defined(__x86_64__) 109 #endif
110 #if defined(__i386__) || defined(__x86_64__)
108 asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcr0) : "c" (0) : "%edx"); 111 asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcr0) : "c" (0) : "%edx");
109 #endif // defined(_MSC_VER) 112 #endif // defined(_MSC_VER)
110 return((xcr0 & 6) == 6); // Is ymm saved? 113 return((xcr0 & 6) == 6); // Is ymm saved?
111 } 114 }
112 #endif // !defined(__native_client__) 115 #endif // !defined(__native_client__)
113 #else 116 #else
114 LIBYUV_API 117 LIBYUV_API
115 void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) { 118 void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) {
116 cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0; 119 cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0;
117 } 120 }
(...skipping 10 matching lines...) Expand all
128 // This will occur for Chrome sandbox for Pepper or Render process. 131 // This will occur for Chrome sandbox for Pepper or Render process.
129 return kCpuHasNEON; 132 return kCpuHasNEON;
130 } 133 }
131 while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) { 134 while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) {
132 if (memcmp(cpuinfo_line, "Features", 8) == 0) { 135 if (memcmp(cpuinfo_line, "Features", 8) == 0) {
133 char* p = strstr(cpuinfo_line, " neon"); 136 char* p = strstr(cpuinfo_line, " neon");
134 if (p && (p[5] == ' ' || p[5] == '\n')) { 137 if (p && (p[5] == ' ' || p[5] == '\n')) {
135 fclose(f); 138 fclose(f);
136 return kCpuHasNEON; 139 return kCpuHasNEON;
137 } 140 }
141 // aarch64 uses asimd for Neon.
142 p = strstr(cpuinfo_line, " asimd");
143 if (p && (p[6] == ' ' || p[6] == '\n')) {
144 fclose(f);
145 return kCpuHasNEON;
146 }
138 } 147 }
139 } 148 }
140 fclose(f); 149 fclose(f);
141 return 0; 150 return 0;
142 } 151 }
143 152
144 #if defined(__mips__) && defined(__linux__) 153 #if defined(__mips__) && defined(__linux__)
145 static int MipsCpuCaps(const char* search_string) { 154 static int MipsCpuCaps(const char* search_string) {
146 char cpuinfo_line[512]; 155 char cpuinfo_line[512];
147 const char* file_name = "/proc/cpuinfo"; 156 const char* file_name = "/proc/cpuinfo";
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 242 }
234 if (TestEnv("LIBYUV_DISABLE_AVX2")) { 243 if (TestEnv("LIBYUV_DISABLE_AVX2")) {
235 cpu_info_ &= ~kCpuHasAVX2; 244 cpu_info_ &= ~kCpuHasAVX2;
236 } 245 }
237 if (TestEnv("LIBYUV_DISABLE_ERMS")) { 246 if (TestEnv("LIBYUV_DISABLE_ERMS")) {
238 cpu_info_ &= ~kCpuHasERMS; 247 cpu_info_ &= ~kCpuHasERMS;
239 } 248 }
240 if (TestEnv("LIBYUV_DISABLE_FMA3")) { 249 if (TestEnv("LIBYUV_DISABLE_FMA3")) {
241 cpu_info_ &= ~kCpuHasFMA3; 250 cpu_info_ &= ~kCpuHasFMA3;
242 } 251 }
243 #elif defined(__mips__) && defined(__linux__) 252 #endif
253 #if defined(__mips__) && defined(__linux__)
244 // Linux mips parse text file for dsp detect. 254 // Linux mips parse text file for dsp detect.
245 cpu_info_ = MipsCpuCaps("dsp"); // set kCpuHasMIPS_DSP. 255 cpu_info_ = MipsCpuCaps("dsp"); // set kCpuHasMIPS_DSP.
246 #if defined(__mips_dspr2) 256 #if defined(__mips_dspr2)
247 cpu_info_ |= kCpuHasMIPS_DSPR2; 257 cpu_info_ |= kCpuHasMIPS_DSPR2;
248 #endif 258 #endif
249 cpu_info_ |= kCpuHasMIPS; 259 cpu_info_ |= kCpuHasMIPS;
250 260
251 if (getenv("LIBYUV_DISABLE_MIPS")) { 261 if (getenv("LIBYUV_DISABLE_MIPS")) {
252 cpu_info_ &= ~kCpuHasMIPS; 262 cpu_info_ &= ~kCpuHasMIPS;
253 } 263 }
254 if (getenv("LIBYUV_DISABLE_MIPS_DSP")) { 264 if (getenv("LIBYUV_DISABLE_MIPS_DSP")) {
255 cpu_info_ &= ~kCpuHasMIPS_DSP; 265 cpu_info_ &= ~kCpuHasMIPS_DSP;
256 } 266 }
257 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) { 267 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) {
258 cpu_info_ &= ~kCpuHasMIPS_DSPR2; 268 cpu_info_ &= ~kCpuHasMIPS_DSPR2;
259 } 269 }
260 #elif defined(__arm__) || defined(__aarch64__) 270 #endif
271 #if defined(__arm__) || defined(__aarch64__)
261 // gcc -mfpu=neon defines __ARM_NEON__ 272 // gcc -mfpu=neon defines __ARM_NEON__
262 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. 273 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon.
263 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. 274 // For Linux, /proc/cpuinfo can be tested but without that assume Neon.
264 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) 275 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__)
265 cpu_info_ = kCpuHasNEON; 276 cpu_info_ = kCpuHasNEON;
266 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon 277 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon
267 // flag in it. 278 // flag in it.
268 // So for aarch64, neon enabling is hard coded here. 279 // So for aarch64, neon enabling is hard coded here.
269 #elif defined(__aarch64__) 280 #endif
281 #if defined(__aarch64__)
270 cpu_info_ = kCpuHasNEON; 282 cpu_info_ = kCpuHasNEON;
271 #else 283 #else
272 // Linux arm parse text file for neon detect. 284 // Linux arm parse text file for neon detect.
273 cpu_info_ = ArmCpuCaps("/proc/cpuinfo"); 285 cpu_info_ = ArmCpuCaps("/proc/cpuinfo");
274 #endif 286 #endif
275 cpu_info_ |= kCpuHasARM; 287 cpu_info_ |= kCpuHasARM;
276 if (TestEnv("LIBYUV_DISABLE_NEON")) { 288 if (TestEnv("LIBYUV_DISABLE_NEON")) {
277 cpu_info_ &= ~kCpuHasNEON; 289 cpu_info_ &= ~kCpuHasNEON;
278 } 290 }
279 #endif // __arm__ 291 #endif // __arm__
280 if (TestEnv("LIBYUV_DISABLE_ASM")) { 292 if (TestEnv("LIBYUV_DISABLE_ASM")) {
281 cpu_info_ = 0; 293 cpu_info_ = 0;
282 } 294 }
283 return cpu_info_; 295 return cpu_info_;
284 } 296 }
285 297
286 LIBYUV_API 298 LIBYUV_API
287 void MaskCpuFlags(int enable_flags) { 299 void MaskCpuFlags(int enable_flags) {
288 cpu_info_ = InitCpuFlags() & enable_flags; 300 cpu_info_ = InitCpuFlags() & enable_flags;
289 } 301 }
290 302
291 #ifdef __cplusplus 303 #ifdef __cplusplus
292 } // extern "C" 304 } // extern "C"
293 } // namespace libyuv 305 } // namespace libyuv
294 #endif 306 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698