27 #if HAVE_SCHED_GETAFFINITY
33 #if HAVE_GETPROCESSAFFINITYMASK
38 #include <sys/param.h>
40 #include <sys/types.h>
41 #include <sys/sysctl.h>
81 #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
82 #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
83 #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
84 #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
85 #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
86 #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
87 #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
88 #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
89 #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
90 #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
91 #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
92 #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
93 #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
94 #define CPUFLAG_FMA3 (AV_CPU_FLAG_FMA3 | CPUFLAG_AVX)
95 #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
96 #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX)
97 #define CPUFLAG_BMI1 (AV_CPU_FLAG_BMI1)
98 #define CPUFLAG_BMI2 (AV_CPU_FLAG_BMI2 | CPUFLAG_BMI1)
99 static const AVOption cpuflags_opts[] = {
100 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
141 .option = cpuflags_opts,
146 const AVClass *pclass = &
class;
151 return flags & INT_MAX;
156 static const AVOption cpuflags_opts[] = {
157 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
184 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
185 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
186 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
187 {
"pentium2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit =
"flags" },
188 {
"pentium3", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit =
"flags" },
189 {
"pentium4", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit =
"flags" },
191 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
192 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
193 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
194 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
197 {
"athlon", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit =
"flags" },
198 {
"athlonxp", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit =
"flags" },
213 .option = cpuflags_opts,
216 const AVClass *pclass = &
class;
223 static volatile int printed;
226 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
231 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
232 nb_cpus = CPU_COUNT(&cpuset);
233 #elif HAVE_GETPROCESSAFFINITYMASK
235 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
236 nb_cpus = av_popcount64(proc_aff);
237 #elif HAVE_SYSCTL && defined(HW_NCPU)
238 int mib[2] = { CTL_HW, HW_NCPU };
239 size_t len =
sizeof(nb_cpus);
241 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
243 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
244 nb_cpus = sysconf(_SC_NPROC_ONLN);
245 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
246 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
261 static const struct {
308 printf(
"cpu_flags = 0x%08X\n", cpu_flags);
309 printf(
"cpu_flags =");
310 for (i = 0; cpu_flag_tab[i].flag; i++)
311 if (cpu_flags & cpu_flag_tab[i].flag)
312 printf(
" %s", cpu_flag_tab[i].
name);