Line data Source code
1 : /*
2 : * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 : *
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
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #ifndef INCLUDE_LIBYUV_CPU_ID_H_
12 : #define INCLUDE_LIBYUV_CPU_ID_H_
13 :
14 : #include "libyuv/basic_types.h"
15 :
16 : #ifdef __cplusplus
17 : namespace libyuv {
18 : extern "C" {
19 : #endif
20 :
21 : // Internal flag to indicate cpuid requires initialization.
22 : static const int kCpuInitialized = 0x1;
23 :
24 : // These flags are only valid on ARM processors.
25 : static const int kCpuHasARM = 0x2;
26 : static const int kCpuHasNEON = 0x4;
27 : // 0x8 reserved for future ARM flag.
28 :
29 : // These flags are only valid on x86 processors.
30 : static const int kCpuHasX86 = 0x10;
31 : static const int kCpuHasSSE2 = 0x20;
32 : static const int kCpuHasSSSE3 = 0x40;
33 : static const int kCpuHasSSE41 = 0x80;
34 : static const int kCpuHasSSE42 = 0x100; // unused at this time.
35 : static const int kCpuHasAVX = 0x200;
36 : static const int kCpuHasAVX2 = 0x400;
37 : static const int kCpuHasERMS = 0x800;
38 : static const int kCpuHasFMA3 = 0x1000;
39 : static const int kCpuHasAVX3 = 0x2000;
40 : static const int kCpuHasF16C = 0x4000;
41 :
42 : // 0x8000 reserved for future X86 flags.
43 :
44 : // These flags are only valid on MIPS processors.
45 : static const int kCpuHasMIPS = 0x10000;
46 : static const int kCpuHasDSPR2 = 0x20000;
47 : static const int kCpuHasMSA = 0x40000;
48 :
49 : // Internal function used to auto-init.
50 : LIBYUV_API
51 : int InitCpuFlags(void);
52 :
53 : // Internal function for parsing /proc/cpuinfo.
54 : LIBYUV_API
55 : int ArmCpuCaps(const char* cpuinfo_name);
56 :
57 : // Detect CPU has SSE2 etc.
58 : // Test_flag parameter should be one of kCpuHas constants above.
59 : // returns non-zero if instruction set is detected
60 5 : static __inline int TestCpuFlag(int test_flag) {
61 : LIBYUV_API extern int cpu_info_;
62 5 : return (!cpu_info_ ? InitCpuFlags() : cpu_info_) & test_flag;
63 : }
64 :
65 : // For testing, allow CPU flags to be disabled.
66 : // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3.
67 : // MaskCpuFlags(-1) to enable all cpu specific optimizations.
68 : // MaskCpuFlags(1) to disable all cpu specific optimizations.
69 : LIBYUV_API
70 : void MaskCpuFlags(int enable_flags);
71 :
72 : // Low level cpuid for X86. Returns zeros on other CPUs.
73 : // eax is the info type that you want.
74 : // ecx is typically the cpu number, and should normally be zero.
75 : LIBYUV_API
76 : void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info);
77 :
78 : #ifdef __cplusplus
79 : } // extern "C"
80 : } // namespace libyuv
81 : #endif
82 :
83 : #endif // INCLUDE_LIBYUV_CPU_ID_H_
|