25 #if HAVE_SCHED_GETAFFINITY
31 #if HAVE_GETPROCESSAFFINITYMASK
36 #include <sys/param.h>
38 #include <sys/types.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 #define CPUFLAG_AVX2 (AV_CPU_FLAG_AVX2 | CPUFLAG_AVX)
89 static const AVOption cpuflags_opts[] = {
90 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
125 .option = cpuflags_opts,
130 const AVClass *pclass = &
class;
135 return flags & INT_MAX;
140 static const AVOption cpuflags_opts[] = {
141 {
"flags" , NULL, 0,
AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit =
"flags" },
164 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
165 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
166 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
167 {
"pentium2", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2 }, .unit =
"flags" },
168 {
"pentium3", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3 }, .unit =
"flags" },
169 {
"pentium4", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4 }, .unit =
"flags" },
171 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
172 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
173 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
174 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
177 {
"athlon", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON }, .unit =
"flags" },
178 {
"athlonxp", NULL, 0,
AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP }, .unit =
"flags" },
193 .option = cpuflags_opts,
196 const AVClass *pclass = &
class;
203 static volatile int printed;
206 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
211 if (!sched_getaffinity(0,
sizeof(cpuset), &cpuset))
212 nb_cpus = CPU_COUNT(&cpuset);
213 #elif HAVE_GETPROCESSAFFINITYMASK
215 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
216 nb_cpus = av_popcount64(proc_aff);
217 #elif HAVE_SYSCTL && defined(HW_NCPU)
218 int mib[2] = { CTL_HW, HW_NCPU };
219 size_t len =
sizeof(nb_cpus);
221 if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
223 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
224 nb_cpus = sysconf(_SC_NPROC_ONLN);
225 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
226 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
241 static const struct {
282 printf(
"cpu_flags = 0x%08X\n", cpu_flags);
283 printf(
"cpu_flags =");
284 for (i = 0; cpu_flag_tab[i].flag; i++)
285 if (cpu_flags & cpu_flag_tab[i].flag)
286 printf(
" %s", cpu_flag_tab[i].
name);