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 |
11 #ifndef INCLUDE_LIBYUV_CPU_ID_H_ // NOLINT | 11 #ifndef INCLUDE_LIBYUV_CPU_ID_H_ // NOLINT |
12 #define INCLUDE_LIBYUV_CPU_ID_H_ | 12 #define INCLUDE_LIBYUV_CPU_ID_H_ |
13 | 13 |
14 #include "libyuv/basic_types.h" | 14 #include "libyuv/basic_types.h" |
15 | 15 |
16 #ifdef __cplusplus | 16 #ifdef __cplusplus |
17 namespace libyuv { | 17 namespace libyuv { |
18 extern "C" { | 18 extern "C" { |
19 #endif | 19 #endif |
20 | 20 |
21 // TODO(fbarchard): Consider overlapping bits for different architectures. | |
22 // Internal flag to indicate cpuid requires initialization. | 21 // Internal flag to indicate cpuid requires initialization. |
23 #define kCpuInit 0x1 | 22 static const int kCpuInitialized = 0x1; |
24 | 23 |
25 // These flags are only valid on ARM processors. | 24 // These flags are only valid on ARM processors. |
26 static const int kCpuHasARM = 0x2; | 25 static const int kCpuHasARM = 0x2; |
27 static const int kCpuHasNEON = 0x4; | 26 static const int kCpuHasNEON = 0x4; |
28 // 0x8 reserved for future ARM flag. | 27 // 0x8 reserved for future ARM flag. |
29 | 28 |
30 // These flags are only valid on x86 processors. | 29 // These flags are only valid on x86 processors. |
31 static const int kCpuHasX86 = 0x10; | 30 static const int kCpuHasX86 = 0x10; |
32 static const int kCpuHasSSE2 = 0x20; | 31 static const int kCpuHasSSE2 = 0x20; |
33 static const int kCpuHasSSSE3 = 0x40; | 32 static const int kCpuHasSSSE3 = 0x40; |
(...skipping 17 matching lines...) Expand all Loading... |
51 | 50 |
52 // Internal function for parsing /proc/cpuinfo. | 51 // Internal function for parsing /proc/cpuinfo. |
53 LIBYUV_API | 52 LIBYUV_API |
54 int ArmCpuCaps(const char* cpuinfo_name); | 53 int ArmCpuCaps(const char* cpuinfo_name); |
55 | 54 |
56 // Detect CPU has SSE2 etc. | 55 // Detect CPU has SSE2 etc. |
57 // Test_flag parameter should be one of kCpuHas constants above. | 56 // Test_flag parameter should be one of kCpuHas constants above. |
58 // returns non-zero if instruction set is detected | 57 // returns non-zero if instruction set is detected |
59 static __inline int TestCpuFlag(int test_flag) { | 58 static __inline int TestCpuFlag(int test_flag) { |
60 LIBYUV_API extern int cpu_info_; | 59 LIBYUV_API extern int cpu_info_; |
61 return (cpu_info_ == kCpuInit ? InitCpuFlags() : cpu_info_) & test_flag; | 60 return (!cpu_info_ ? InitCpuFlags() : cpu_info_) & test_flag; |
62 } | 61 } |
63 | 62 |
64 // For testing, allow CPU flags to be disabled. | 63 // For testing, allow CPU flags to be disabled. |
65 // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. | 64 // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. |
66 // MaskCpuFlags(-1) to enable all cpu specific optimizations. | 65 // MaskCpuFlags(-1) to enable all cpu specific optimizations. |
67 // MaskCpuFlags(0) to disable all cpu specific optimizations. | 66 // MaskCpuFlags(0) to disable all cpu specific optimizations. |
68 LIBYUV_API | 67 LIBYUV_API |
69 void MaskCpuFlags(int enable_flags); | 68 void MaskCpuFlags(int enable_flags); |
70 | 69 |
71 // Low level cpuid for X86. Returns zeros on other CPUs. | 70 // Low level cpuid for X86. Returns zeros on other CPUs. |
72 // eax is the info type that you want. | 71 // eax is the info type that you want. |
73 // ecx is typically the cpu number, and should normally be zero. | 72 // ecx is typically the cpu number, and should normally be zero. |
74 LIBYUV_API | 73 LIBYUV_API |
75 void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info); | 74 void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info); |
76 | 75 |
77 #ifdef __cplusplus | 76 #ifdef __cplusplus |
78 } // extern "C" | 77 } // extern "C" |
79 } // namespace libyuv | 78 } // namespace libyuv |
80 #endif | 79 #endif |
81 | 80 |
82 #endif // INCLUDE_LIBYUV_CPU_ID_H_ NOLINT | 81 #endif // INCLUDE_LIBYUV_CPU_ID_H_ NOLINT |
OLD | NEW |