/src/libavif/ext/libyuv/include/libyuv/cpu_id.h
Line | Count | Source |
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 = 0x100; |
27 | | static const int kCpuHasNeonDotProd = 0x200; |
28 | | static const int kCpuHasNeonI8MM = 0x400; |
29 | | static const int kCpuHasSVE = 0x800; |
30 | | static const int kCpuHasSVE2 = 0x1000; |
31 | | static const int kCpuHasSME = 0x2000; |
32 | | static const int kCpuHasSME2 = 0x4000; |
33 | | static const int kCpuHasSVEF32MM = 0x8000; |
34 | | |
35 | | // These flags are only valid on RISCV processors. |
36 | | static const int kCpuHasRISCV = 0x4; |
37 | | static const int kCpuHasRVV = 0x100; |
38 | | static const int kCpuHasRVVZVFH = 0x200; |
39 | | |
40 | | // These flags are only valid on x86 processors. |
41 | | static const int kCpuHasX86 = 0x8; |
42 | | static const int kCpuHasSSE2 = 0x100; |
43 | | static const int kCpuHasSSSE3 = 0x200; |
44 | | static const int kCpuHasSSE41 = 0x400; |
45 | | static const int kCpuHasSSE42 = 0x800; |
46 | | static const int kCpuHasAVX = 0x1000; |
47 | | static const int kCpuHasAVX2 = 0x2000; |
48 | | static const int kCpuHasERMS = 0x4000; |
49 | | static const int kCpuHasFSMR = 0x8000; |
50 | | static const int kCpuHasFMA3 = 0x10000; |
51 | | static const int kCpuHasF16C = 0x20000; |
52 | | static const int kCpuHasAVX512BW = 0x40000; |
53 | | static const int kCpuHasAVX512VL = 0x80000; |
54 | | static const int kCpuHasAVX512VNNI = 0x100000; |
55 | | static const int kCpuHasAVX512VBMI = 0x200000; |
56 | | static const int kCpuHasAVX512VBMI2 = 0x400000; |
57 | | static const int kCpuHasAVX512VBITALG = 0x800000; |
58 | | static const int kCpuHasAVX10 = 0x1000000; |
59 | | static const int kCpuHasAVX10_2 = 0x2000000; |
60 | | static const int kCpuHasAVXVNNI = 0x4000000; |
61 | | static const int kCpuHasAVXVNNIINT8 = 0x8000000; |
62 | | static const int kCpuHasAMXINT8 = 0x10000000; |
63 | | |
64 | | // These flags are only valid on LOONGARCH processors. |
65 | | static const int kCpuHasLOONGARCH = 0x20; |
66 | | static const int kCpuHasLSX = 0x100; |
67 | | static const int kCpuHasLASX = 0x200; |
68 | | |
69 | | // Optional init function. TestCpuFlag does an auto-init. |
70 | | // Returns cpu_info flags. |
71 | | LIBYUV_API |
72 | | int InitCpuFlags(void); |
73 | | |
74 | | // Detect CPU has SSE2 etc. |
75 | | // Test_flag parameter should be one of kCpuHas constants above. |
76 | | // Returns non-zero if instruction set is detected |
77 | 57.7k | static __inline int TestCpuFlag(int test_flag) { |
78 | 57.7k | LIBYUV_API extern int cpu_info_; |
79 | 57.7k | #ifdef __ATOMIC_RELAXED |
80 | 57.7k | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); |
81 | | #else |
82 | | int cpu_info = cpu_info_; |
83 | | #endif |
84 | 57.7k | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag; |
85 | 57.7k | } convert_argb.cc:libyuv::TestCpuFlag(int) Line | Count | Source | 77 | 13.2k | static __inline int TestCpuFlag(int test_flag) { | 78 | 13.2k | LIBYUV_API extern int cpu_info_; | 79 | 13.2k | #ifdef __ATOMIC_RELAXED | 80 | 13.2k | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); | 81 | | #else | 82 | | int cpu_info = cpu_info_; | 83 | | #endif | 84 | 13.2k | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag; | 85 | 13.2k | } |
Unexecuted instantiation: convert.cc:libyuv::TestCpuFlag(int) Unexecuted instantiation: convert_from_argb.cc:libyuv::TestCpuFlag(int) Unexecuted instantiation: cpu_id.cc:libyuv::TestCpuFlag(int) planar_functions.cc:libyuv::TestCpuFlag(int) Line | Count | Source | 77 | 6.02k | static __inline int TestCpuFlag(int test_flag) { | 78 | 6.02k | LIBYUV_API extern int cpu_info_; | 79 | 6.02k | #ifdef __ATOMIC_RELAXED | 80 | 6.02k | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); | 81 | | #else | 82 | | int cpu_info = cpu_info_; | 83 | | #endif | 84 | 6.02k | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag; | 85 | 6.02k | } |
Unexecuted instantiation: rotate.cc:libyuv::TestCpuFlag(int) scale.cc:libyuv::TestCpuFlag(int) Line | Count | Source | 77 | 33.5k | static __inline int TestCpuFlag(int test_flag) { | 78 | 33.5k | LIBYUV_API extern int cpu_info_; | 79 | 33.5k | #ifdef __ATOMIC_RELAXED | 80 | 33.5k | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); | 81 | | #else | 82 | | int cpu_info = cpu_info_; | 83 | | #endif | 84 | 33.5k | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag; | 85 | 33.5k | } |
scale_common.cc:libyuv::TestCpuFlag(int) Line | Count | Source | 77 | 4.96k | static __inline int TestCpuFlag(int test_flag) { | 78 | 4.96k | LIBYUV_API extern int cpu_info_; | 79 | 4.96k | #ifdef __ATOMIC_RELAXED | 80 | 4.96k | int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); | 81 | | #else | 82 | | int cpu_info = cpu_info_; | 83 | | #endif | 84 | 4.96k | return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag; | 85 | 4.96k | } |
Unexecuted instantiation: scale_uv.cc:libyuv::TestCpuFlag(int) |
86 | | |
87 | | // Internal function for parsing /proc/cpuinfo. |
88 | | LIBYUV_API |
89 | | int ArmCpuCaps(const char* cpuinfo_name); |
90 | | LIBYUV_API |
91 | | int RiscvCpuCaps(const char* cpuinfo_name); |
92 | | |
93 | | #ifdef __linux__ |
94 | | // On Linux, parse AArch64 features from getauxval(AT_HWCAP{,2}). |
95 | | LIBYUV_API |
96 | | int AArch64CpuCaps(unsigned long hwcap, unsigned long hwcap2); |
97 | | #else |
98 | | LIBYUV_API |
99 | | int AArch64CpuCaps(); |
100 | | #endif |
101 | | |
102 | | // For testing, allow CPU flags to be disabled. |
103 | | // ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3. |
104 | | // MaskCpuFlags(-1) to enable all cpu specific optimizations. |
105 | | // MaskCpuFlags(1) to disable all cpu specific optimizations. |
106 | | // MaskCpuFlags(0) to reset state so next call will auto init. |
107 | | // Returns cpu_info flags. |
108 | | LIBYUV_API |
109 | | int MaskCpuFlags(int enable_flags); |
110 | | |
111 | | // Sets the CPU flags to |cpu_flags|, bypassing the detection code. |cpu_flags| |
112 | | // should be a valid combination of the kCpuHas constants above and include |
113 | | // kCpuInitialized. Use this method when running in a sandboxed process where |
114 | | // the detection code might fail (as it might access /proc/cpuinfo). In such |
115 | | // cases the cpu_info can be obtained from a non sandboxed process by calling |
116 | | // InitCpuFlags() and passed to the sandboxed process (via command line |
117 | | // parameters, IPC...) which can then call this method to initialize the CPU |
118 | | // flags. |
119 | | // Notes: |
120 | | // - when specifying 0 for |cpu_flags|, the auto initialization is enabled |
121 | | // again. |
122 | | // - enabling CPU features that are not supported by the CPU will result in |
123 | | // undefined behavior. |
124 | | // TODO(fbarchard): consider writing a helper function that translates from |
125 | | // other library CPU info to libyuv CPU info and add a .md doc that explains |
126 | | // CPU detection. |
127 | 3 | static __inline void SetCpuFlags(int cpu_flags) { |
128 | 3 | LIBYUV_API extern int cpu_info_; |
129 | 3 | #ifdef __ATOMIC_RELAXED |
130 | 3 | __atomic_store_n(&cpu_info_, cpu_flags, __ATOMIC_RELAXED); |
131 | | #else |
132 | | cpu_info_ = cpu_flags; |
133 | | #endif |
134 | 3 | } Unexecuted instantiation: convert_argb.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: convert.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: convert_from_argb.cc:libyuv::SetCpuFlags(int) cpu_id.cc:libyuv::SetCpuFlags(int) Line | Count | Source | 127 | 3 | static __inline void SetCpuFlags(int cpu_flags) { | 128 | 3 | LIBYUV_API extern int cpu_info_; | 129 | 3 | #ifdef __ATOMIC_RELAXED | 130 | 3 | __atomic_store_n(&cpu_info_, cpu_flags, __ATOMIC_RELAXED); | 131 | | #else | 132 | | cpu_info_ = cpu_flags; | 133 | | #endif | 134 | 3 | } |
Unexecuted instantiation: planar_functions.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: rotate.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: scale.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: scale_common.cc:libyuv::SetCpuFlags(int) Unexecuted instantiation: scale_uv.cc:libyuv::SetCpuFlags(int) |
135 | | |
136 | | // Low level cpuid for X86. Returns zeros on other CPUs. |
137 | | // eax is the info type that you want. |
138 | | // ecx is typically the cpu number, and should normally be zero. |
139 | | LIBYUV_API |
140 | | void CpuId(int info_eax, int info_ecx, int* cpu_info); |
141 | | |
142 | | #ifdef __cplusplus |
143 | | } // extern "C" |
144 | | } // namespace libyuv |
145 | | #endif |
146 | | |
147 | | #endif // INCLUDE_LIBYUV_CPU_ID_H_ |