24 #if HAVE_SCHED_GETAFFINITY
30 #if HAVE_GETPROCESSAFFINITYMASK
35 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/sysctl.h>
74 #define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
75 #define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
76 #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
77 #define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
78 #define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
79 #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
80 #define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
81 #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
82 #define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
83 #define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
84 #define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
85 #define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
86 #define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
87 #define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
88 static const AVOption cpuflags_opts[] = {
89 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
123 .option = cpuflags_opts,
128 const AVClass *pclass = &
class;
133 return flags & INT_MAX;
138 static const AVOption cpuflags_opts[] = {
139 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
162 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
163 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
164 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
165 {
"pentium2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit =
"flags" },
166 {
"pentium3", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit =
"flags" },
167 {
"pentium4", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit =
"flags" },
169 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
170 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
171 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
172 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
175 {
"athlon", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit =
"flags" },
176 {
"athlonxp", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit =
"flags" },
191 .option = cpuflags_opts,
194 const AVClass *pclass = &
class;
201 static volatile int printed;
204 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
209 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
210 nb_cpus = CPU_COUNT(&cpuset);
211 #elif HAVE_GETPROCESSAFFINITYMASK
213 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
214 nb_cpus = av_popcount64(proc_aff);
215 #elif HAVE_SYSCTL && defined(HW_NCPU)
216 int mib[2] = { CTL_HW, HW_NCPU };
217 size_t len =
sizeof(nb_cpus);
219 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
221 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
222 nb_cpus = sysconf(_SC_NPROC_ONLN);
223 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
224 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
239 static const struct {
279 printf(
"cpu_flags = 0x%08X\n", cpu_flags);
280 printf(
"cpu_flags =");
281 for (i = 0; cpu_flag_tab[i].flag; i++)
282 if (cpu_flags & cpu_flag_tab[i].flag)
283 printf(
" %s", cpu_flag_tab[i].
name);