cpu.c
Go to the documentation of this file.
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 
23 {
24  static int flags, checked;
25 
26  if (checked)
27  return flags;
28 
29  if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
30  if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
31  if (ARCH_X86) flags = ff_get_cpu_flags_x86();
32 
33  checked = 1;
34  return flags;
35 }
36 
37 #ifdef TEST
38 
39 #undef printf
40 #include <stdio.h>
41 
42 static const struct {
43  int flag;
44  const char *name;
45 } cpu_flag_tab[] = {
46 #if ARCH_ARM
47  { AV_CPU_FLAG_IWMMXT, "iwmmxt" },
48 #elif ARCH_PPC
49  { AV_CPU_FLAG_ALTIVEC, "altivec" },
50 #elif ARCH_X86
51  { AV_CPU_FLAG_MMX, "mmx" },
52  { AV_CPU_FLAG_MMX2, "mmx2" },
53  { AV_CPU_FLAG_SSE, "sse" },
54  { AV_CPU_FLAG_SSE2, "sse2" },
55  { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
56  { AV_CPU_FLAG_SSE3, "sse3" },
57  { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
58  { AV_CPU_FLAG_SSSE3, "ssse3" },
59  { AV_CPU_FLAG_ATOM, "atom" },
60  { AV_CPU_FLAG_SSE4, "sse4.1" },
61  { AV_CPU_FLAG_SSE42, "sse4.2" },
62  { AV_CPU_FLAG_AVX, "avx" },
63  { AV_CPU_FLAG_XOP, "xop" },
64  { AV_CPU_FLAG_FMA4, "fma4" },
65  { AV_CPU_FLAG_3DNOW, "3dnow" },
66  { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
67  { AV_CPU_FLAG_CMOV, "cmov" },
68 #endif
69  { 0 }
70 };
71 
72 int main(void)
73 {
75  int i;
76 
77  printf("cpu_flags = 0x%08X\n", cpu_flags);
78  printf("cpu_flags =");
79  for (i = 0; cpu_flag_tab[i].flag; i++)
80  if (cpu_flags & cpu_flag_tab[i].flag)
81  printf(" %s", cpu_flag_tab[i].name);
82  printf("\n");
83 
84  return 0;
85 }
86 
87 #endif
#define AV_CPU_FLAG_AVX
AVX functions: requires OS support even if YMM registers aren't used.
Definition: cpu.h:40
#define AV_CPU_FLAG_ALTIVEC
standard
Definition: cpu.h:45
#define AV_CPU_FLAG_SSE
SSE functions.
Definition: cpu.h:30
#define AV_CPU_FLAG_MMX2
SSE integer functions or AMD MMX ext.
Definition: cpu.h:28
#define AV_CPU_FLAG_CMOV
i686 cmov
Definition: cpu.h:44
#define ARCH_PPC
Definition: config.h:24
#define ARCH_X86
Definition: config.h:31
int ff_get_cpu_flags_ppc(void)
This function MAY rely on signal() or fork() in order to make sure AltiVec is present.
Definition: cpu.c:38
#define AV_CPU_FLAG_ATOM
Atom processor, some SSSE3 instructions are slower.
Definition: cpu.h:37
static int flags
Definition: log.c:34
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
Definition: cpu.h:32
#define AV_CPU_FLAG_XOP
Bulldozer XOP functions.
Definition: cpu.h:41
#define ARCH_ARM
Definition: config.h:14
#define AV_CPU_FLAG_SSE42
Nehalem SSE4.2 functions.
Definition: cpu.h:39
#define AV_CPU_FLAG_SSSE3
Conroe SSSE3 functions.
Definition: cpu.h:36
int main(int argc, char **argv)
Definition: avconv.c:4508
#define AV_CPU_FLAG_SSE3
Prescott SSE3 functions.
Definition: cpu.h:34
int ff_get_cpu_flags_x86(void)
Definition: cpu.c:42
static int cpu_flags
Definition: dct-test.c:85
#define AV_CPU_FLAG_3DNOW
AMD 3DNOW.
Definition: cpu.h:29
#define AV_CPU_FLAG_IWMMXT
XScale IWMMXT.
Definition: cpu.h:43
#define AV_CPU_FLAG_SSE3SLOW
SSE3 supported, but usually not faster.
Definition: cpu.h:35
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:27
#define AV_CPU_FLAG_FMA4
Bulldozer FMA4 functions.
Definition: cpu.h:42
#define printf
Definition: internal.h:151
#define AV_CPU_FLAG_SSE4
Penryn SSE4.1 functions.
Definition: cpu.h:38
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:22
#define AV_CPU_FLAG_3DNOWEXT
AMD 3DNowExt.
Definition: cpu.h:33
const char * name
Definition: audioconvert.c:61
int ff_get_cpu_flags_arm(void)
Definition: cpu.c:22
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
Definition: cpu.h:31