]> git.sesse.net Git - ffmpeg/blob - libavutil/cpu.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavutil / cpu.c
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
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  *
9  * FFmpeg is distributed in the hope that it will be useful,
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
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #include "cpu.h"
20 #include "config.h"
21
22 static int flags, checked;
23
24 void av_force_cpu_flags(int arg){
25     flags   = arg;
26     checked = arg != -1;
27 }
28
29 int av_get_cpu_flags(void)
30 {
31     if (checked)
32         return flags;
33
34     if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
35     if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
36     if (ARCH_X86) flags = ff_get_cpu_flags_x86();
37
38     checked = 1;
39     return flags;
40 }
41
42 void av_set_cpu_flags_mask(int mask)
43 {
44     checked       = 0;
45     flags         = av_get_cpu_flags() & mask;
46     checked       = 1;
47 }
48
49 #ifdef TEST
50
51 #undef printf
52 #include <stdio.h>
53
54 static const struct {
55     int flag;
56     const char *name;
57 } cpu_flag_tab[] = {
58 #if   ARCH_ARM
59     { AV_CPU_FLAG_IWMMXT,    "iwmmxt"     },
60 #elif ARCH_PPC
61     { AV_CPU_FLAG_ALTIVEC,   "altivec"    },
62 #elif ARCH_X86
63     { AV_CPU_FLAG_MMX,       "mmx"        },
64     { AV_CPU_FLAG_MMX2,      "mmx2"       },
65     { AV_CPU_FLAG_SSE,       "sse"        },
66     { AV_CPU_FLAG_SSE2,      "sse2"       },
67     { AV_CPU_FLAG_SSE2SLOW,  "sse2(slow)" },
68     { AV_CPU_FLAG_SSE3,      "sse3"       },
69     { AV_CPU_FLAG_SSE3SLOW,  "sse3(slow)" },
70     { AV_CPU_FLAG_SSSE3,     "ssse3"      },
71     { AV_CPU_FLAG_ATOM,      "atom"       },
72     { AV_CPU_FLAG_SSE4,      "sse4.1"     },
73     { AV_CPU_FLAG_SSE42,     "sse4.2"     },
74     { AV_CPU_FLAG_AVX,       "avx"        },
75     { AV_CPU_FLAG_XOP,       "xop"        },
76     { AV_CPU_FLAG_FMA4,      "fma4"       },
77     { AV_CPU_FLAG_3DNOW,     "3dnow"      },
78     { AV_CPU_FLAG_3DNOWEXT,  "3dnowext"   },
79 #endif
80     { 0 }
81 };
82
83 int main(void)
84 {
85     int cpu_flags = av_get_cpu_flags();
86     int i;
87
88     printf("cpu_flags = 0x%08X\n", cpu_flags);
89     printf("cpu_flags =");
90     for (i = 0; cpu_flag_tab[i].flag; i++)
91         if (cpu_flags & cpu_flag_tab[i].flag)
92             printf(" %s", cpu_flag_tab[i].name);
93     printf("\n");
94
95     return 0;
96 }
97
98 #endif