]> git.sesse.net Git - ffmpeg/blob - libavutil/cpu.c
mem: Consistently return NULL for av_malloc(0)
[ffmpeg] / libavutil / cpu.c
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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 cpuflags_mask = -1, checked;
23
24 int av_get_cpu_flags(void)
25 {
26     static int flags;
27
28     if (checked)
29         return flags;
30
31     if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
32     if (ARCH_X86) flags = ff_get_cpu_flags_x86();
33
34     flags  &= cpuflags_mask;
35     checked = 1;
36
37     return flags;
38 }
39
40 void av_set_cpu_flags_mask(int mask)
41 {
42     cpuflags_mask = mask;
43     checked       = 0;
44 }
45
46 #ifdef TEST
47
48 #undef printf
49 #include <stdio.h>
50
51 static const struct {
52     int flag;
53     const char *name;
54 } cpu_flag_tab[] = {
55 #if   ARCH_PPC
56     { AV_CPU_FLAG_ALTIVEC,   "altivec"    },
57 #elif ARCH_X86
58     { AV_CPU_FLAG_MMX,       "mmx"        },
59     { AV_CPU_FLAG_MMX2,      "mmx2"       },
60     { AV_CPU_FLAG_SSE,       "sse"        },
61     { AV_CPU_FLAG_SSE2,      "sse2"       },
62     { AV_CPU_FLAG_SSE2SLOW,  "sse2(slow)" },
63     { AV_CPU_FLAG_SSE3,      "sse3"       },
64     { AV_CPU_FLAG_SSE3SLOW,  "sse3(slow)" },
65     { AV_CPU_FLAG_SSSE3,     "ssse3"      },
66     { AV_CPU_FLAG_ATOM,      "atom"       },
67     { AV_CPU_FLAG_SSE4,      "sse4.1"     },
68     { AV_CPU_FLAG_SSE42,     "sse4.2"     },
69     { AV_CPU_FLAG_AVX,       "avx"        },
70     { AV_CPU_FLAG_XOP,       "xop"        },
71     { AV_CPU_FLAG_FMA4,      "fma4"       },
72     { AV_CPU_FLAG_3DNOW,     "3dnow"      },
73     { AV_CPU_FLAG_3DNOWEXT,  "3dnowext"   },
74 #endif
75     { 0 }
76 };
77
78 int main(void)
79 {
80     int cpu_flags = av_get_cpu_flags();
81     int i;
82
83     printf("cpu_flags = 0x%08X\n", cpu_flags);
84     printf("cpu_flags =");
85     for (i = 0; cpu_flag_tab[i].flag; i++)
86         if (cpu_flags & cpu_flag_tab[i].flag)
87             printf(" %s", cpu_flag_tab[i].name);
88     printf("\n");
89
90     return 0;
91 }
92
93 #endif