| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if (p && (p[6] == ' ' || p[6] == '\n')) { | 144 if (p && (p[6] == ' ' || p[6] == '\n')) { |
| 145 fclose(f); | 145 fclose(f); |
| 146 return kCpuHasNEON; | 146 return kCpuHasNEON; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 fclose(f); | 150 fclose(f); |
| 151 return 0; | 151 return 0; |
| 152 } | 152 } |
| 153 | 153 |
| 154 #if defined(__mips__) && defined(__linux__) | |
| 155 static int MipsCpuCaps(const char* search_string) { | |
| 156 char cpuinfo_line[512]; | |
| 157 const char* file_name = "/proc/cpuinfo"; | |
| 158 FILE* f = fopen(file_name, "r"); | |
| 159 if (!f) { | |
| 160 // Assume DSP if /proc/cpuinfo is unavailable. | |
| 161 // This will occur for Chrome sandbox for Pepper or Render process. | |
| 162 return kCpuHasMIPS_DSP; | |
| 163 } | |
| 164 while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f) != NULL) { | |
| 165 if (strstr(cpuinfo_line, search_string) != NULL) { | |
| 166 fclose(f); | |
| 167 return kCpuHasMIPS_DSP; | |
| 168 } | |
| 169 } | |
| 170 fclose(f); | |
| 171 return 0; | |
| 172 } | |
| 173 #endif | |
| 174 | |
| 175 // CPU detect function for SIMD instruction sets. | 154 // CPU detect function for SIMD instruction sets. |
| 176 LIBYUV_API | 155 LIBYUV_API |
| 177 int cpu_info_ = 0; // cpu_info is not initialized yet. | 156 int cpu_info_ = 0; // cpu_info is not initialized yet. |
| 178 | 157 |
| 179 // Test environment variable for disabling CPU features. Any non-zero value | 158 // Test environment variable for disabling CPU features. Any non-zero value |
| 180 // to disable. Zero ignored to make it easy to set the variable on/off. | 159 // to disable. Zero ignored to make it easy to set the variable on/off. |
| 181 #if !defined(__native_client__) && !defined(_M_ARM) | 160 #if !defined(__native_client__) && !defined(_M_ARM) |
| 182 | 161 |
| 183 static LIBYUV_BOOL TestEnv(const char* name) { | 162 static LIBYUV_BOOL TestEnv(const char* name) { |
| 184 const char* var = getenv(name); | 163 const char* var = getenv(name); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 cpu_info &= ~kCpuHasERMS; | 234 cpu_info &= ~kCpuHasERMS; |
| 256 } | 235 } |
| 257 if (TestEnv("LIBYUV_DISABLE_FMA3")) { | 236 if (TestEnv("LIBYUV_DISABLE_FMA3")) { |
| 258 cpu_info &= ~kCpuHasFMA3; | 237 cpu_info &= ~kCpuHasFMA3; |
| 259 } | 238 } |
| 260 if (TestEnv("LIBYUV_DISABLE_AVX3")) { | 239 if (TestEnv("LIBYUV_DISABLE_AVX3")) { |
| 261 cpu_info &= ~kCpuHasAVX3; | 240 cpu_info &= ~kCpuHasAVX3; |
| 262 } | 241 } |
| 263 #endif | 242 #endif |
| 264 #if defined(__mips__) && defined(__linux__) | 243 #if defined(__mips__) && defined(__linux__) |
| 265 // Linux mips parse text file for dsp detect. | |
| 266 cpu_info = MipsCpuCaps("dsp"); // set kCpuHasMIPS_DSP. | |
| 267 #if defined(__mips_dspr2) | 244 #if defined(__mips_dspr2) |
| 268 cpu_info |= kCpuHasMIPS_DSPR2; | 245 cpu_info |= kCpuHasMIPS_DSPR2; |
| 269 #endif | 246 #endif |
| 270 cpu_info |= kCpuHasMIPS; | 247 cpu_info |= kCpuHasMIPS; |
| 271 | 248 |
| 272 if (getenv("LIBYUV_DISABLE_MIPS")) { | 249 if (getenv("LIBYUV_DISABLE_MIPS")) { |
| 273 cpu_info &= ~kCpuHasMIPS; | 250 cpu_info &= ~kCpuHasMIPS; |
| 274 } | 251 } |
| 275 if (getenv("LIBYUV_DISABLE_MIPS_DSP")) { | |
| 276 cpu_info &= ~kCpuHasMIPS_DSP; | |
| 277 } | |
| 278 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) { | 252 if (getenv("LIBYUV_DISABLE_MIPS_DSPR2")) { |
| 279 cpu_info &= ~kCpuHasMIPS_DSPR2; | 253 cpu_info &= ~kCpuHasMIPS_DSPR2; |
| 280 } | 254 } |
| 281 #endif | 255 #endif |
| 282 #if defined(__arm__) || defined(__aarch64__) | 256 #if defined(__arm__) || defined(__aarch64__) |
| 283 // gcc -mfpu=neon defines __ARM_NEON__ | 257 // gcc -mfpu=neon defines __ARM_NEON__ |
| 284 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. | 258 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. |
| 285 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. | 259 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. |
| 286 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) | 260 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) |
| 287 cpu_info = kCpuHasNEON; | 261 cpu_info = kCpuHasNEON; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 311 // Note that use of this function is not thread safe. | 285 // Note that use of this function is not thread safe. |
| 312 LIBYUV_API | 286 LIBYUV_API |
| 313 void MaskCpuFlags(int enable_flags) { | 287 void MaskCpuFlags(int enable_flags) { |
| 314 cpu_info_ = InitCpuFlags() & enable_flags; | 288 cpu_info_ = InitCpuFlags() & enable_flags; |
| 315 } | 289 } |
| 316 | 290 |
| 317 #ifdef __cplusplus | 291 #ifdef __cplusplus |
| 318 } // extern "C" | 292 } // extern "C" |
| 319 } // namespace libyuv | 293 } // namespace libyuv |
| 320 #endif | 294 #endif |
| OLD | NEW |