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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (p && (p[6] == ' ' || p[6] == '\n')) { | 154 if (p && (p[6] == ' ' || p[6] == '\n')) { |
155 fclose(f); | 155 fclose(f); |
156 return kCpuHasNEON; | 156 return kCpuHasNEON; |
157 } | 157 } |
158 } | 158 } |
159 } | 159 } |
160 fclose(f); | 160 fclose(f); |
161 return 0; | 161 return 0; |
162 } | 162 } |
163 | 163 |
| 164 LIBYUV_API SAFEBUFFERS |
| 165 int MipsCpuCaps(const char* cpuinfo_name, const char ase[]) { |
| 166 char cpuinfo_line[512]; |
| 167 int len = strlen(ase); |
| 168 FILE* f = fopen(cpuinfo_name, "r"); |
| 169 if (!f) { |
| 170 // ase enabled if /proc/cpuinfo is unavailable. |
| 171 if(strcmp(ase, " msa") == 0) { |
| 172 return kCpuHasMSA; |
| 173 } |
| 174 if(strcmp(ase, " dspr2") == 0) { |
| 175 return kCpuHasDSPR2; |
| 176 } |
| 177 } |
| 178 while (fgets(cpuinfo_line, sizeof(cpuinfo_line) - 1, f)) { |
| 179 if (memcmp(cpuinfo_line, "ASEs implemented", 16) == 0) { |
| 180 char* p = strstr(cpuinfo_line, ase); |
| 181 if (p && (p[len] == ' ' || p[len] == '\n')) { |
| 182 fclose(f); |
| 183 if(strcmp(ase, " msa") == 0) { |
| 184 return kCpuHasMSA; |
| 185 } |
| 186 if(strcmp(ase, " dspr2") == 0) { |
| 187 return kCpuHasDSPR2; |
| 188 } |
| 189 } |
| 190 } |
| 191 } |
| 192 fclose(f); |
| 193 return 0; |
| 194 } |
| 195 |
164 // CPU detect function for SIMD instruction sets. | 196 // CPU detect function for SIMD instruction sets. |
165 LIBYUV_API | 197 LIBYUV_API |
166 int cpu_info_ = 0; // cpu_info is not initialized yet. | 198 int cpu_info_ = 0; // cpu_info is not initialized yet. |
167 | 199 |
168 // Test environment variable for disabling CPU features. Any non-zero value | 200 // Test environment variable for disabling CPU features. Any non-zero value |
169 // to disable. Zero ignored to make it easy to set the variable on/off. | 201 // to disable. Zero ignored to make it easy to set the variable on/off. |
170 #if !defined(__native_client__) && !defined(_M_ARM) | 202 #if !defined(__native_client__) && !defined(_M_ARM) |
171 | 203 |
172 static LIBYUV_BOOL TestEnv(const char* name) { | 204 static LIBYUV_BOOL TestEnv(const char* name) { |
173 const char* var = getenv(name); | 205 const char* var = getenv(name); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 cpu_info &= ~kCpuHasFMA3; | 279 cpu_info &= ~kCpuHasFMA3; |
248 } | 280 } |
249 if (TestEnv("LIBYUV_DISABLE_AVX3")) { | 281 if (TestEnv("LIBYUV_DISABLE_AVX3")) { |
250 cpu_info &= ~kCpuHasAVX3; | 282 cpu_info &= ~kCpuHasAVX3; |
251 } | 283 } |
252 #endif | 284 #endif |
253 #if defined(__mips__) && defined(__linux__) | 285 #if defined(__mips__) && defined(__linux__) |
254 #if defined(__mips_dspr2) | 286 #if defined(__mips_dspr2) |
255 cpu_info |= kCpuHasDSPR2; | 287 cpu_info |= kCpuHasDSPR2; |
256 #endif | 288 #endif |
| 289 #if defined(__mips_msa) |
| 290 cpu_info = MipsCpuCaps("/proc/cpuinfo", " msa"); |
| 291 #endif |
257 cpu_info |= kCpuHasMIPS; | 292 cpu_info |= kCpuHasMIPS; |
258 if (getenv("LIBYUV_DISABLE_DSPR2")) { | 293 if (getenv("LIBYUV_DISABLE_DSPR2")) { |
259 cpu_info &= ~kCpuHasDSPR2; | 294 cpu_info &= ~kCpuHasDSPR2; |
260 } | 295 } |
| 296 if (getenv("LIBYUV_DISABLE_MSA")) { |
| 297 cpu_info &= ~kCpuHasMSA; |
| 298 } |
261 #endif | 299 #endif |
262 #if defined(__arm__) || defined(__aarch64__) | 300 #if defined(__arm__) || defined(__aarch64__) |
263 // gcc -mfpu=neon defines __ARM_NEON__ | 301 // gcc -mfpu=neon defines __ARM_NEON__ |
264 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. | 302 // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon. |
265 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. | 303 // For Linux, /proc/cpuinfo can be tested but without that assume Neon. |
266 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) | 304 #if defined(__ARM_NEON__) || defined(__native_client__) || !defined(__linux__) |
267 cpu_info = kCpuHasNEON; | 305 cpu_info = kCpuHasNEON; |
268 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon | 306 // For aarch64(arm64), /proc/cpuinfo's feature is not complete, e.g. no neon |
269 // flag in it. | 307 // flag in it. |
270 // So for aarch64, neon enabling is hard coded here. | 308 // So for aarch64, neon enabling is hard coded here. |
(...skipping 20 matching lines...) Expand all Loading... |
291 // Note that use of this function is not thread safe. | 329 // Note that use of this function is not thread safe. |
292 LIBYUV_API | 330 LIBYUV_API |
293 void MaskCpuFlags(int enable_flags) { | 331 void MaskCpuFlags(int enable_flags) { |
294 cpu_info_ = InitCpuFlags() & enable_flags; | 332 cpu_info_ = InitCpuFlags() & enable_flags; |
295 } | 333 } |
296 | 334 |
297 #ifdef __cplusplus | 335 #ifdef __cplusplus |
298 } // extern "C" | 336 } // extern "C" |
299 } // namespace libyuv | 337 } // namespace libyuv |
300 #endif | 338 #endif |
OLD | NEW |