21 #include <stdatomic.h>
30 #if HAVE_SCHED_GETAFFINITY
36 #if HAVE_GETPROCESSAFFINITYMASK || HAVE_WINRT
41 #include <sys/param.h>
43 #include <sys/types.h>
44 #include <sys/sysctl.h>
105 memory_order_relaxed);
110 #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
111 #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
112 #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
113 #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
114 #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
115 #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
116 #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
117 #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
118 #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
119 #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
120 #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
121 #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
122 #define CPUFLAG_AVXSLOW (AV_CPU_FLAG_AVXSLOW | CPUFLAG_AVX)
123 #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
124 #define CPUFLAG_FMA3 (AV_CPU_FLAG_FMA3 | CPUFLAG_AVX)
125 #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
126 #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX)
127 #define CPUFLAG_BMI2 (AV_CPU_FLAG_BMI2 | AV_CPU_FLAG_BMI1)
128 #define CPUFLAG_AESNI (AV_CPU_FLAG_AESNI | CPUFLAG_SSE42)
129 static const AVOption cpuflags_opts[] = {
175 .option = cpuflags_opts,
180 const AVClass *pclass = &
class;
185 return flags & INT_MAX;
190 static const AVOption cpuflags_opts[] = {
220 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
221 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
222 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
227 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
228 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
229 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
230 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
255 .option = cpuflags_opts,
258 const AVClass *pclass = &
class;
265 static volatile int printed;
271 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
276 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
277 nb_cpus = CPU_COUNT(&cpuset);
278 #elif HAVE_GETPROCESSAFFINITYMASK
280 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
281 nb_cpus = av_popcount64(proc_aff);
282 #elif HAVE_SYSCTL && defined(HW_NCPU)
283 int mib[2] = { CTL_HW, HW_NCPU };
284 size_t len =
sizeof(nb_cpus);
286 if (sysctl(mib, 2, &nb_cpus, &len,
NULL, 0) == -1)
288 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
289 nb_cpus = sysconf(_SC_NPROC_ONLN);
290 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
291 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
293 GetNativeSystemInfo(&sysinfo);
294 nb_cpus = sysinfo.dwNumberOfProcessors;
#define AV_CPU_FLAG_AVX
AVX functions: requires OS support even if YMM registers aren't used.
#define ATOMIC_VAR_INIT(value)
#define AV_CPU_FLAG_ALTIVEC
standard
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
#define AV_CPU_FLAG_SSE
SSE functions.
void av_set_cpu_flags_mask(int mask)
Set a mask on flags returned by av_get_cpu_flags().
#define AV_CPU_FLAG_MMX2
SSE integer functions or AMD MMX ext.
#define AV_CPU_FLAG_CMOV
supports cmov instruction
static atomic_int cpu_flags
Macro definitions for various function/variable attributes.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
size_t ff_get_cpu_max_align_x86(void)
size_t ff_get_cpu_max_align_ppc(void)
#define AV_CPU_FLAG_FMA3
Haswell FMA3 functions.
size_t ff_get_cpu_max_align_aarch64(void)
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
int ff_get_cpu_flags_ppc(void)
This function MAY rely on signal() or fork() in order to make sure AltiVec is present.
int av_parse_cpu_flags(const char *s)
Parse CPU flags from a string.
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
#define AV_CPU_FLAG_AVX2
AVX2 functions: requires OS support even if YMM registers aren't used.
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
#define AV_CPU_FLAG_XOP
Bulldozer XOP functions.
#define AV_CPU_FLAG_SSE42
Nehalem SSE4.2 functions.
#define AV_CPU_FLAG_SSSE3
Conroe SSSE3 functions.
static const uint16_t mask[17]
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_CPU_FLAG_ARMV6T2
#define AV_CPU_FLAG_VFP_VM
VFPv2 vector mode, deprecated in ARMv7-A and unavailable in various CPUs implementations.
int av_parse_cpu_caps(unsigned *flags, const char *s)
Parse CPU caps from a string and update the given AV_CPU_* flags based on that.
#define AV_CPU_FLAG_ARMV5TE
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
int ff_get_cpu_flags_x86(void)
#define atomic_load_explicit(object, order)
#define AV_CPU_FLAG_BMI2
Bit Manipulation Instruction Set 2.
#define AV_CPU_FLAG_VFPV3
#define AV_CPU_FLAG_3DNOW
AMD 3DNOW.
#define AV_CPU_FLAG_ARMV6
int ff_get_cpu_flags_aarch64(void)
#define AV_CPU_FLAG_SSE3SLOW
SSE3 supported, but usually not faster.
#define AV_CPU_FLAG_AVXSLOW
AVX supported, but slow when using YMM registers (e.g. Bulldozer)
#define AV_CPU_FLAG_BMI1
Bit Manipulation Instruction Set 1.
#define AV_CPU_FLAG_MMX
standard MMX
Describe the class of an AVClass context structure.
#define AV_CPU_FLAG_FMA4
Bulldozer FMA4 functions.
#define AV_CPU_FLAG_SSE4
Penryn SSE4.1 functions.
#define AV_CPU_FLAG_AESNI
Advanced Encryption Standard functions.
#define atomic_store_explicit(object, desired, order)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
#define AV_CPU_FLAG_3DNOWEXT
AMD 3DNowExt.
common internal and external API header
#define AV_CPU_FLAG_ARMV8
int ff_get_cpu_flags_arm(void)
#define AV_CPU_FLAG_SETEND
static int get_cpu_flags(void)
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
size_t ff_get_cpu_max_align_arm(void)
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.