27 #if HAVE_SCHED_GETAFFINITY
33 #if HAVE_GETPROCESSAFFINITYMASK
38 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/sysctl.h>
101 #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
102 #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
103 #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
104 #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
105 #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
106 #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
107 #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
108 #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
109 #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
110 #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
111 #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
112 #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
113 #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
114 #define CPUFLAG_FMA3 (AV_CPU_FLAG_FMA3 | CPUFLAG_AVX)
115 #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
116 #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX)
117 #define CPUFLAG_BMI1 (AV_CPU_FLAG_BMI1)
118 #define CPUFLAG_BMI2 (AV_CPU_FLAG_BMI2 | CPUFLAG_BMI1)
119 static const AVOption cpuflags_opts[] = {
120 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
162 .option = cpuflags_opts,
167 const AVClass *pclass = &
class;
172 return flags & INT_MAX;
177 static const AVOption cpuflags_opts[] = {
178 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
205 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
206 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
207 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
208 {
"pentium2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit =
"flags" },
209 {
"pentium3", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit =
"flags" },
210 {
"pentium4", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit =
"flags" },
212 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
213 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
214 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
215 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
218 {
"athlon", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit =
"flags" },
219 {
"athlonxp", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit =
"flags" },
234 .option = cpuflags_opts,
237 const AVClass *pclass = &
class;
244 static volatile int printed;
247 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
252 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
253 nb_cpus = CPU_COUNT(&cpuset);
254 #elif HAVE_GETPROCESSAFFINITYMASK
256 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
257 nb_cpus = av_popcount64(proc_aff);
258 #elif HAVE_SYSCTL && defined(HW_NCPU)
259 int mib[2] = { CTL_HW, HW_NCPU };
260 size_t len =
sizeof(nb_cpus);
262 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
264 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
265 nb_cpus = sysconf(_SC_NPROC_ONLN);
266 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
267 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
282 static const struct {
330 printf(
"cpu_flags = 0x%08X\n", cpu_flags);
331 printf(
"cpu_flags =");
332 for (i = 0; cpu_flag_tab[i].flag; i++)
333 if (cpu_flags & cpu_flag_tab[i].flag)
334 printf(
" %s", cpu_flag_tab[i].
name);