| OLD | NEW |
| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 191 } |
| 192 #else // nacl does not support getenv(). | 192 #else // nacl does not support getenv(). |
| 193 static LIBYUV_BOOL TestEnv(const char*) { | 193 static LIBYUV_BOOL TestEnv(const char*) { |
| 194 return LIBYUV_FALSE; | 194 return LIBYUV_FALSE; |
| 195 } | 195 } |
| 196 #endif | 196 #endif |
| 197 | 197 |
| 198 LIBYUV_API SAFEBUFFERS | 198 LIBYUV_API SAFEBUFFERS |
| 199 int InitCpuFlags(void) { | 199 int InitCpuFlags(void) { |
| 200 #if !defined(__pnacl__) && !defined(__CLR_VER) && defined(CPU_X86) | 200 #if !defined(__pnacl__) && !defined(__CLR_VER) && defined(CPU_X86) |
| 201 | 201 int cpu_info; |
| 202 uint32 cpu_info0[4] = { 0, 0, 0, 0 }; | 202 uint32 cpu_info0[4] = { 0, 0, 0, 0 }; |
| 203 uint32 cpu_info1[4] = { 0, 0, 0, 0 }; | 203 uint32 cpu_info1[4] = { 0, 0, 0, 0 }; |
| 204 uint32 cpu_info7[4] = { 0, 0, 0, 0 }; | 204 uint32 cpu_info7[4] = { 0, 0, 0, 0 }; |
| 205 CpuId(0, 0, cpu_info0); | 205 CpuId(0, 0, cpu_info0); |
| 206 CpuId(1, 0, cpu_info1); | 206 CpuId(1, 0, cpu_info1); |
| 207 if (cpu_info0[0] >= 7) { | 207 if (cpu_info0[0] >= 7) { |
| 208 CpuId(7, 0, cpu_info7); | 208 CpuId(7, 0, cpu_info7); |
| 209 } | 209 } |
| 210 cpu_info_ = ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) | | 210 cpu_info = ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) | |
| 211 ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) | | 211 ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) | |
| 212 ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) | | 212 ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) | |
| 213 ((cpu_info1[2] & 0x00100000) ? kCpuHasSSE42 : 0) | | 213 ((cpu_info1[2] & 0x00100000) ? kCpuHasSSE42 : 0) | |
| 214 ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0) | | 214 ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0) | |
| 215 ((cpu_info1[2] & 0x00001000) ? kCpuHasFMA3 : 0) | | 215 ((cpu_info1[2] & 0x00001000) ? kCpuHasFMA3 : 0) | |
| 216 kCpuHasX86; | 216 kCpuHasX86; |
| 217 | 217 |
| 218 #ifdef HAS_XGETBV | 218 #ifdef HAS_XGETBV |
| 219 // AVX requires CPU has AVX, XSAVE and OSXSave for xgetbv | 219 // AVX requires CPU has AVX, XSAVE and OSXSave for xgetbv |
| 220 if ((cpu_info1[2] & 0x1c000000) == 0x1c000000 && // AVX and OSXSave | 220 if ((cpu_info1[2] & 0x1c000000) == 0x1c000000 && // AVX and OSXSave |
| 221 !TestEnv("LIBYUV_DISABLE_AVX") && TestOsSaveYmm()) { // Saves YMM. | 221 !TestEnv("LIBYUV_DISABLE_AVX") && TestOsSaveYmm()) { // Saves YMM. |
| 222 cpu_info_ |= ((cpu_info7[1] & 0x00000020) ? kCpuHasAVX2 : 0) | | 222 cpu_info |= ((cpu_info7[1] & 0x00000020) ? kCpuHasAVX2 : 0) | kCpuHasAVX; |
| 223 kCpuHasAVX; | |
| 224 } | 223 } |
| 225 #endif | 224 #endif |
| 226 // Environment variable overrides for testing. | 225 // Environment variable overrides for testing. |
| 227 if (TestEnv("LIBYUV_DISABLE_X86")) { | 226 if (TestEnv("LIBYUV_DISABLE_X86")) { |
| 228 cpu_info_ &= ~kCpuHasX86; | 227 cpu_info &= ~kCpuHasX86; |
| 229 } | 228 } |
| 230 if (TestEnv("LIBYUV_DISABLE_SSE2")) { | 229 if (TestEnv("LIBYUV_DISABLE_SSE2")) { |
| 231 cpu_info_ &= ~kCpuHasSSE2; | 230 cpu_info &= ~kCpuHasSSE2; |
| 232 } | 231 } |
| 233 if (TestEnv("LIBYUV_DISABLE_SSSE3")) { | 232 if (TestEnv("LIBYUV_DISABLE_SSSE3")) { |
| 234 cpu_info_ &= ~kCpuHasSSSE3; | 233 cpu_info &= ~kCpuHasSSSE3; |
| 235 } | 234 } |
| 236 if (TestEnv("LIBYUV_DISABLE_SSE41")) { | 235 if (TestEnv("LIBYUV_DISABLE_SSE41")) { |
| 237 cpu_info_ &= ~kCpuHasSSE41; | 236 cpu_info &= ~kCpuHasSSE41; |
| 238 } | 237 } |
| 239 if (TestEnv("LIBYUV_DISABLE_SSE42")) { | 238 if (TestEnv("LIBYUV_DISABLE_SSE42")) { |
| 240 cpu_info_ &= ~kCpuHasSSE42; | 239 cpu_info &= ~kCpuHasSSE42; |
| 241 } | 240 } |
| 242 if (TestEnv("LIBYUV_DISABLE_AVX2")) { | 241 if (TestEnv("LIBYUV_DISABLE_AVX2")) { |
| 243 cpu_info_ &= ~kCpuHasAVX2; | 242 cpu_info &= ~kCpuHasAVX2; |
| 244 } | 243 } |
| 245 if (TestEnv("LIBYUV_DISABLE_ERMS")) { | 244 if (TestEnv("LIBYUV_DISABLE_ERMS")) { |
| 246 cpu_info_ &= ~kCpuHasERMS; | 245 cpu_info &= ~kCpuHasERMS; |
| 247 } | 246 } |
| 248 if (TestEnv("LIBYUV_DISABLE_FMA3")) { | 247 if (TestEnv("LIBYUV_DISABLE_FMA3")) { |
| 249 cpu_info_ &= ~kCpuHasFMA3; | 248 cpu_info &= ~kCpuHasFMA3; |
| 250 } | 249 } |
| 251 #endif | 250 #endif |
| 252 #if defined(__mips__) && defined(__linux__) | 251 #if defined(__mips__) && defined(__linux__) |
| 253 // Linux mips parse text file for dsp detect. | 252 // Linux mips parse text file for dsp detect. |
| 254 cpu_info_ = MipsCpuCaps("dsp"); // set kCpuHasMIPS_DSP. | 253 cpu_info = MipsCpuCaps("dsp"); // set kCpuHasMIPS_DSP. |
| 255 #if defined(__mips_dspr2) | 254 #if defined(__mips_dspr2) |
| 256 cpu_info_ |= kCpuHasMIPS_DSPR2; | 255 cpu_info |= kCpuHasMIPS_DSPR2; |
| 257 #endif | 256 #endif |
| 258 cpu_info_ |= kCpuHasMIPS; | 257 cpu_info |= kCpuHasMIPS; |
| 259 | 258 |
| 260 if (getenv("LIBYUV_DISABLE_MIPS")) { | 259 if (getenv("LIBYUV_DISABLE_MIPS")) { |
| 261 cpu_info_ &= ~kCpuHasMIPS; | 260 cpu_info &= ~kCpuHasMIPS; |
| 262 } | 261 } |
| 263 if (getenv("LIBYUV_DISABLE_MIPS_DSP")) { | 262 if (getenv("LIBYUV_DISABLE_MIPS_DSP")) { |
| 264 cpu_info_ &= ~kCpuHasMIPS_DSP; | 263 cpu_info &= ~kCpuHasMIPS_DSP; |
| 265 } | 264 } |
| 266 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) { | 265 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) { |
| 267 cpu_info_ &= ~kCpuHasMIPS_DSPR2; | 266 cpu_info &= ~kCpuHasMIPS_DSPR2; |
| 268 } | 267 } |
| 269 #endif | 268 #endif |
| 270 #if defined(__arm__) || defined(__aarch64__) | 269 #if defined(__arm__) || defined(__aarch64__) |
| 271 // gcc -mfpu=neon defines __ARM_NEON__ | 270 // gcc -mfpu=neon defines __ARM_NEON__ |
| 272 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. | 271 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. |
| 273 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. | 272 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. |
| 274 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) | 273 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) |
| 275 cpu_info_ = kCpuHasNEON; | 274 cpu_info = kCpuHasNEON; |
| 276 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon | 275 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon |
| 277 // flag in it. | 276 // flag in it. |
| 278 // So for aarch64, neon enabling is hard coded here. | 277 // So for aarch64, neon enabling is hard coded here. |
| 279 #endif | 278 #endif |
| 280 #if defined(__aarch64__) | 279 #if defined(__aarch64__) |
| 281 cpu_info_ = kCpuHasNEON; | 280 cpu_info = kCpuHasNEON; |
| 282 #else | 281 #else |
| 283 // Linux arm parse text file for neon detect. | 282 // Linux arm parse text file for neon detect. |
| 284 cpu_info_ = ArmCpuCaps("/proc/cpuinfo"); | 283 cpu_info = ArmCpuCaps("/proc/cpuinfo"); |
| 285 #endif | 284 #endif |
| 286 cpu_info_ |= kCpuHasARM; | 285 cpu_info |= kCpuHasARM; |
| 287 if (TestEnv("LIBYUV_DISABLE_NEON")) { | 286 if (TestEnv("LIBYUV_DISABLE_NEON")) { |
| 288 cpu_info_ &= ~kCpuHasNEON; | 287 cpu_info &= ~kCpuHasNEON; |
| 289 } | 288 } |
| 290 #endif // __arm__ | 289 #endif // __arm__ |
| 291 if (TestEnv("LIBYUV_DISABLE_ASM")) { | 290 if (TestEnv("LIBYUV_DISABLE_ASM")) { |
| 292 cpu_info_ = 0; | 291 cpu_info = 0; |
| 293 } | 292 } |
| 293 cpu_info_ = cpu_info; |
| 294 return cpu_info_; | 294 return cpu_info_; |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Note that use of this function is not thread safe. |
| 297 LIBYUV_API | 298 LIBYUV_API |
| 298 void MaskCpuFlags(int enable_flags) { | 299 void MaskCpuFlags(int enable_flags) { |
| 299 cpu_info_ = InitCpuFlags() & enable_flags; | 300 cpu_info_ = InitCpuFlags() & enable_flags; |
| 300 } | 301 } |
| 301 | 302 |
| 302 #ifdef __cplusplus | 303 #ifdef __cplusplus |
| 303 } // extern "C" | 304 } // extern "C" |
| 304 } // namespace libyuv | 305 } // namespace libyuv |
| 305 #endif | 306 #endif |
| OLD | NEW |