FFmpeg
Loading...
Searching...
No Matches
cpu.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/cpu.h"
21#include "config.h"
22
23#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
24#include <stdint.h>
25#include <sys/auxv.h>
26
27#define HWCAP_AARCH64_PMULL (1 << 4)
28#define HWCAP_AARCH64_CRC32 (1 << 7)
29#define HWCAP_AARCH64_SHA3 (1 << 17)
30#define HWCAP_AARCH64_ASIMDDP (1 << 20)
31#define HWCAP_AARCH64_SVE (1 << 22)
32#define HWCAP2_AARCH64_SVE2 (1 << 1)
33#define HWCAP2_AARCH64_I8MM (1 << 13)
34#define HWCAP2_AARCH64_SME (1 << 23)
35#define HWCAP2_AARCH64_SME_I16I64 (1 << 24)
36#define HWCAP2_AARCH64_SME2 (1ULL << 37)
37
38static int detect_flags(void)
39{
40 int flags = 0;
41
42 unsigned long hwcap = ff_getauxval(AT_HWCAP);
43 unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
44
45 if (hwcap & HWCAP_AARCH64_PMULL)
47 if (hwcap & HWCAP_AARCH64_SHA3)
49 if (hwcap & HWCAP_AARCH64_CRC32)
51 if (hwcap & HWCAP_AARCH64_ASIMDDP)
53 if (hwcap & HWCAP_AARCH64_SVE)
55 if (hwcap2 & HWCAP2_AARCH64_SVE2)
57 if (hwcap2 & HWCAP2_AARCH64_I8MM)
59 if (hwcap2 & HWCAP2_AARCH64_SME)
61 if (hwcap2 & HWCAP2_AARCH64_SME_I16I64)
63 if (hwcap2 & HWCAP2_AARCH64_SME2)
65
66 return flags;
67}
68
69#elif defined(__APPLE__) && HAVE_SYSCTLBYNAME
70#include <sys/sysctl.h>
71
72static int have_feature(const char *feature) {
73 uint32_t value = 0;
74 size_t size = sizeof(value);
75 if (!sysctlbyname(feature, &value, &size, NULL, 0))
76 return value;
77 return 0;
78}
79
80static int detect_flags(void)
81{
82 int flags = 0;
83
84 if (have_feature("hw.optional.arm.FEAT_DotProd"))
86 if (have_feature("hw.optional.arm.FEAT_I8MM"))
88 if (have_feature("hw.optional.arm.FEAT_SME"))
90 if (have_feature("hw.optional.arm.FEAT_SME_I16I64"))
92 if (have_feature("hw.optional.armv8_crc32"))
94 if (have_feature("hw.optional.arm.FEAT_PMULL"))
96 if (have_feature("hw.optional.armv8_2_sha3"))
98 if (have_feature("hw.optional.arm.FEAT_SME2"))
100
101 return flags;
102}
103
104#elif defined(__OpenBSD__)
105#include <machine/armreg.h>
106#include <machine/cpu.h>
107#include <sys/types.h>
108#include <sys/sysctl.h>
109
110static int detect_flags(void)
111{
112 int flags = 0;
113
114#ifdef CPU_ID_AA64ISAR0
115 int mib[2];
116 uint64_t isar0;
117 uint64_t isar1;
118 size_t len;
119
120 mib[0] = CTL_MACHDEP;
121 mib[1] = CPU_ID_AA64ISAR0;
122 len = sizeof(isar0);
123 if (sysctl(mib, 2, &isar0, &len, NULL, 0) != -1) {
124 if (ID_AA64ISAR0_DP(isar0) >= ID_AA64ISAR0_DP_IMPL)
126 if (ID_AA64ISAR0_CRC32(isar0) >= ID_AA64ISAR0_CRC32_BASE)
128 if (ID_AA64ISAR0_AES(isar0) >= ID_AA64ISAR0_AES_PMULL)
130 if (ID_AA64ISAR0_SHA3(isar0) >= ID_AA64ISAR0_SHA3_IMPL)
132 }
133
134 mib[0] = CTL_MACHDEP;
135 mib[1] = CPU_ID_AA64ISAR1;
136 len = sizeof(isar1);
137 if (sysctl(mib, 2, &isar1, &len, NULL, 0) != -1) {
138#ifdef ID_AA64ISAR1_I8MM_IMPL
139 if (ID_AA64ISAR1_I8MM(isar1) >= ID_AA64ISAR1_I8MM_IMPL)
141#endif
142 }
143#endif
144
145 return flags;
146}
147
148#elif defined(_WIN32)
149#include <windows.h>
150
151static int detect_flags(void)
152{
153 int flags = 0;
154#ifdef PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
155 if (IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE))
157#endif
158#ifdef PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
159 if (IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE))
161#endif
162#ifdef PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE
163 if (IsProcessorFeaturePresent(PF_ARM_SHA3_INSTRUCTIONS_AVAILABLE))
165#endif
166#ifdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
167 if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE))
169#endif
170#ifdef PF_ARM_V82_I8MM_INSTRUCTIONS_AVAILABLE
171 if (IsProcessorFeaturePresent(PF_ARM_V82_I8MM_INSTRUCTIONS_AVAILABLE))
173#endif
174#ifdef PF_ARM_SVE_INSTRUCTIONS_AVAILABLE
175 if (IsProcessorFeaturePresent(PF_ARM_SVE_INSTRUCTIONS_AVAILABLE))
177#endif
178#ifdef PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE
179 if (IsProcessorFeaturePresent(PF_ARM_SVE2_INSTRUCTIONS_AVAILABLE))
181#endif
182#ifdef PF_ARM_SME_INSTRUCTIONS_AVAILABLE
183 if (IsProcessorFeaturePresent(PF_ARM_SME_INSTRUCTIONS_AVAILABLE))
185#endif
186#ifdef PF_ARM_SME_I16I64_INSTRUCTIONS_AVAILABLE
187 if (IsProcessorFeaturePresent(PF_ARM_SME_I16I64_INSTRUCTIONS_AVAILABLE))
189#endif
190#ifdef PF_ARM_SME2_INSTRUCTIONS_AVAILABLE
191 if (IsProcessorFeaturePresent(PF_ARM_SME2_INSTRUCTIONS_AVAILABLE))
193#endif
194 return flags;
195}
196#else
197
198static int detect_flags(void)
199{
200 return 0;
201}
202
203#endif
204
206{
207 int flags = AV_CPU_FLAG_ARMV8 * HAVE_ARMV8 |
208 AV_CPU_FLAG_NEON * HAVE_NEON;
209
210#ifdef __ARM_FEATURE_DOTPROD
212#endif
213#ifdef __ARM_FEATURE_MATMUL_INT8
215#endif
216#ifdef __ARM_FEATURE_SVE
218#endif
219#ifdef __ARM_FEATURE_SVE2
221#endif
222#ifdef __ARM_FEATURE_SME
224#endif
225#ifdef __ARM_FEATURE_CRC32
227#endif
228#ifdef __ARM_FEATURE_AES
230#endif
231#ifdef __ARM_FEATURE_SHA3
233#endif
234#ifdef __ARM_FEATURE_SME_I16I64
236#endif
237#ifdef __ARM_FEATURE_SME2
239#endif
240
241 flags |= detect_flags();
242
243 return flags;
244}
245
247{
248 int flags = av_get_cpu_flags();
249
251 return 16;
252
253 return 8;
254}
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define NULL
Definition coverity.c:32
double value
Definition eval.c:102
int ff_get_cpu_flags_aarch64(void)
Definition cpu.c:205
size_t ff_get_cpu_max_align_aarch64(void)
Definition cpu.c:246
static int detect_flags(void)
Definition cpu.c:198
unsigned long ff_getauxval(unsigned long type)
Definition cpu.c:309
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition cpu.c:109
#define AV_CPU_FLAG_DOTPROD
Definition cpu.h:76
#define AV_CPU_FLAG_SVE
Definition cpu.h:78
#define AV_CPU_FLAG_NEON
Definition cpu.h:73
#define AV_CPU_FLAG_I8MM
Definition cpu.h:77
#define AV_CPU_FLAG_SVE2
Definition cpu.h:79
#define AV_CPU_FLAG_SME_I16I64
Definition cpu.h:83
#define AV_CPU_FLAG_EOR3
Definition cpu.h:86
#define AV_CPU_FLAG_SME2
Definition cpu.h:82
#define AV_CPU_FLAG_ARM_CRC
Definition cpu.h:81
#define AV_CPU_FLAG_ARMV8
Definition cpu.h:74
#define AV_CPU_FLAG_PMULL
Definition cpu.h:85
#define AV_CPU_FLAG_SME
Definition cpu.h:80
#define AT_HWCAP2
Definition cpu.c:53
#define AT_HWCAP
Definition cpu.c:50
int size
int len