svq1enc: Set picture_structure correctly
[libav.git] / libavutil / cpu.c
CommitLineData
c6c98d08 1/*
2912e87a 2 * This file is part of Libav.
c6c98d08 3 *
2912e87a 4 * Libav is free software; you can redistribute it and/or
c6c98d08
SS
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
2912e87a 9 * Libav is distributed in the hope that it will be useful,
c6c98d08
SS
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
2912e87a 15 * License along with Libav; if not, write to the Free Software
c6c98d08
SS
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "cpu.h"
20#include "config.h"
3527a739 21#include "opt.h"
c6c98d08 22
a9c5b6f6 23static int cpuflags_mask = -1, checked;
4d851f8d 24
c6c98d08
SS
25int av_get_cpu_flags(void)
26{
4d851f8d 27 static int flags;
a3f0d2b9
MR
28
29 if (checked)
30 return flags;
31
d526c533 32 if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
a3f0d2b9
MR
33 if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
34 if (ARCH_X86) flags = ff_get_cpu_flags_x86();
35
4d851f8d 36 flags &= cpuflags_mask;
a3f0d2b9 37 checked = 1;
4d851f8d 38
a3f0d2b9 39 return flags;
c6c98d08 40}
c6c98d08 41
4d851f8d
AK
42void av_set_cpu_flags_mask(int mask)
43{
44 cpuflags_mask = mask;
45 checked = 0;
46}
47
3527a739
MR
48int av_parse_cpu_flags(const char *s)
49{
239fdf1b 50#define CPUFLAG_MMXEXT (AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
3527a739
MR
51#define CPUFLAG_3DNOW (AV_CPU_FLAG_3DNOW | AV_CPU_FLAG_MMX)
52#define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
239fdf1b 53#define CPUFLAG_SSE (AV_CPU_FLAG_SSE | CPUFLAG_MMXEXT)
3527a739
MR
54#define CPUFLAG_SSE2 (AV_CPU_FLAG_SSE2 | CPUFLAG_SSE)
55#define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
56#define CPUFLAG_SSE3 (AV_CPU_FLAG_SSE3 | CPUFLAG_SSE2)
57#define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
58#define CPUFLAG_SSSE3 (AV_CPU_FLAG_SSSE3 | CPUFLAG_SSE3)
59#define CPUFLAG_SSE4 (AV_CPU_FLAG_SSE4 | CPUFLAG_SSSE3)
60#define CPUFLAG_SSE42 (AV_CPU_FLAG_SSE42 | CPUFLAG_SSE4)
61#define CPUFLAG_AVX (AV_CPU_FLAG_AVX | CPUFLAG_SSE42)
62#define CPUFLAG_XOP (AV_CPU_FLAG_XOP | CPUFLAG_AVX)
63#define CPUFLAG_FMA4 (AV_CPU_FLAG_FMA4 | CPUFLAG_AVX)
64 static const AVOption cpuflags_opts[] = {
65 { "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
6eca84ba 66#if ARCH_PPC
3527a739 67 { "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ALTIVEC }, .unit = "flags" },
6eca84ba 68#elif ARCH_X86
3527a739 69 { "mmx" , NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_MMX }, .unit = "flags" },
239fdf1b 70 { "mmxext" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_MMXEXT }, .unit = "flags" },
3527a739
MR
71 { "sse" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE }, .unit = "flags" },
72 { "sse2" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE2 }, .unit = "flags" },
73 { "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE2SLOW }, .unit = "flags" },
74 { "sse3" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE3 }, .unit = "flags" },
75 { "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE3SLOW }, .unit = "flags" },
76 { "ssse3" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSSE3 }, .unit = "flags" },
77 { "atom" , NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ATOM }, .unit = "flags" },
78 { "sse4.1" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE4 }, .unit = "flags" },
79 { "sse4.2" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_SSE42 }, .unit = "flags" },
80 { "avx" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_AVX }, .unit = "flags" },
81 { "xop" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_XOP }, .unit = "flags" },
82 { "fma4" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_FMA4 }, .unit = "flags" },
83 { "3dnow" , NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_3DNOW }, .unit = "flags" },
84 { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { CPUFLAG_3DNOWEXT }, .unit = "flags" },
65345a5a 85 { "cmov", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_CMOV }, .unit = "flags" },
6eca84ba 86#elif ARCH_ARM
3527a739
MR
87 { "armv5te", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV5TE }, .unit = "flags" },
88 { "armv6", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV6 }, .unit = "flags" },
89 { "armv6t2", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_ARMV6T2 }, .unit = "flags" },
90 { "vfp", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_VFP }, .unit = "flags" },
91 { "vfpv3", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_VFPV3 }, .unit = "flags" },
92 { "neon", NULL, 0, AV_OPT_TYPE_CONST, { AV_CPU_FLAG_NEON }, .unit = "flags" },
6eca84ba 93#endif
3527a739
MR
94 { NULL },
95 };
96 static const AVClass class = {
97 .class_name = "cpuflags",
98 .item_name = av_default_item_name,
99 .option = cpuflags_opts,
100 .version = LIBAVUTIL_VERSION_INT,
101 };
102
103 int flags = 0, ret;
104 const AVClass *pclass = &class;
105
106 if ((ret = av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, &flags)) < 0)
107 return ret;
108
109 return flags & INT_MAX;
110}
111
c6c98d08
SS
112#ifdef TEST
113
114#undef printf
ec5f5719 115#include <stdio.h>
c6c98d08 116
c31bc537
MR
117static const struct {
118 int flag;
119 const char *name;
120} cpu_flag_tab[] = {
d526c533
MR
121#if ARCH_ARM
122 { AV_CPU_FLAG_ARMV5TE, "armv5te" },
123 { AV_CPU_FLAG_ARMV6, "armv6" },
124 { AV_CPU_FLAG_ARMV6T2, "armv6t2" },
125 { AV_CPU_FLAG_VFP, "vfp" },
126 { AV_CPU_FLAG_VFPV3, "vfpv3" },
127 { AV_CPU_FLAG_NEON, "neon" },
128#elif ARCH_PPC
c31bc537
MR
129 { AV_CPU_FLAG_ALTIVEC, "altivec" },
130#elif ARCH_X86
131 { AV_CPU_FLAG_MMX, "mmx" },
239fdf1b 132 { AV_CPU_FLAG_MMXEXT, "mmxext" },
c31bc537
MR
133 { AV_CPU_FLAG_SSE, "sse" },
134 { AV_CPU_FLAG_SSE2, "sse2" },
135 { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
136 { AV_CPU_FLAG_SSE3, "sse3" },
137 { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
138 { AV_CPU_FLAG_SSSE3, "ssse3" },
139 { AV_CPU_FLAG_ATOM, "atom" },
140 { AV_CPU_FLAG_SSE4, "sse4.1" },
141 { AV_CPU_FLAG_SSE42, "sse4.2" },
142 { AV_CPU_FLAG_AVX, "avx" },
96a59cf3
JGG
143 { AV_CPU_FLAG_XOP, "xop" },
144 { AV_CPU_FLAG_FMA4, "fma4" },
c31bc537
MR
145 { AV_CPU_FLAG_3DNOW, "3dnow" },
146 { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
65345a5a 147 { AV_CPU_FLAG_CMOV, "cmov" },
c31bc537
MR
148#endif
149 { 0 }
150};
151
c6c98d08
SS
152int main(void)
153{
154 int cpu_flags = av_get_cpu_flags();
c31bc537 155 int i;
c6c98d08
SS
156
157 printf("cpu_flags = 0x%08X\n", cpu_flags);
c31bc537
MR
158 printf("cpu_flags =");
159 for (i = 0; cpu_flag_tab[i].flag; i++)
160 if (cpu_flags & cpu_flag_tab[i].flag)
161 printf(" %s", cpu_flag_tab[i].name);
162 printf("\n");
163
c6c98d08
SS
164 return 0;
165}
166
167#endif