]> git.sesse.net Git - vlc/blob - include/vlc_cpu.h
direct3d11: support more pixel formats
[vlc] / include / vlc_cpu.h
1 /*****************************************************************************
2  * vlc_cpu.h: CPU capabilities
3  *****************************************************************************
4  * Copyright (C) 1998-2009 VLC authors and VideoLAN
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 /**
22  * \file
23  * This file provides CPU features detection.
24  */
25
26 #ifndef VLC_CPU_H
27 # define VLC_CPU_H 1
28
29 VLC_API unsigned vlc_CPU(void);
30
31 # if defined (__i386__) || defined (__x86_64__)
32 #  define HAVE_FPU 1
33 #  define VLC_CPU_MMX    0x00000008
34 #  define VLC_CPU_3dNOW  0x00000010
35 #  define VLC_CPU_MMXEXT 0x00000020
36 #  define VLC_CPU_SSE    0x00000040
37 #  define VLC_CPU_SSE2   0x00000080
38 #  define VLC_CPU_SSE3   0x00000100
39 #  define VLC_CPU_SSSE3  0x00000200
40 #  define VLC_CPU_SSE4_1 0x00000400
41 #  define VLC_CPU_SSE4_2 0x00000800
42 #  define VLC_CPU_SSE4A  0x00001000
43 #  define VLC_CPU_AVX    0x00002000
44 #  define VLC_CPU_AVX2   0x00004000
45 #  define VLC_CPU_XOP    0x00008000
46 #  define VLC_CPU_FMA4   0x00010000
47
48 # if defined (__MMX__)
49 #  define vlc_CPU_MMX() (1)
50 #  define VLC_MMX
51 # else
52 #  define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
53 #  if VLC_GCC_VERSION(4, 4) || defined(__clang__)
54 #   define VLC_MMX __attribute__ ((__target__ ("mmx")))
55 #  else
56 #   define VLC_MMX VLC_MMX_is_not_implemented_on_this_compiler
57 #  endif
58 # endif
59
60 # if defined (__SSE__)
61 #  define vlc_CPU_MMXEXT() (1)
62 #  define vlc_CPU_SSE() (1)
63 #  define VLC_SSE
64 # else
65 #  define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
66 #  define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
67 #  if VLC_GCC_VERSION(4, 4) || defined(__clang__)
68 #   define VLC_SSE __attribute__ ((__target__ ("sse")))
69 #  else
70 #   define VLC_SSE VLC_SSE_is_not_implemented_on_this_compiler
71 #  endif
72 # endif
73
74 # ifdef __SSE2__
75 #  define vlc_CPU_SSE2() (1)
76 # else
77 #  define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
78 # endif
79
80 # ifdef __SSE3__
81 #  define vlc_CPU_SSE3() (1)
82 # else
83 #  define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
84 # endif
85
86 # ifdef __SSSE3__
87 #  define vlc_CPU_SSSE3() (1)
88 # else
89 #  define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
90 # endif
91
92 # ifdef __SSE4_1__
93 #  define vlc_CPU_SSE4_1() (1)
94 # else
95 #  define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
96 # endif
97
98 # ifdef __SSE4_2__
99 #  define vlc_CPU_SSE4_2() (1)
100 # else
101 #  define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
102 # endif
103
104 # ifdef __SSE4A__
105 #  define vlc_CPU_SSE4A() (1)
106 # else
107 #  define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
108 # endif
109
110 # ifdef __AVX__
111 #  define vlc_CPU_AVX() (1)
112 # else
113 #  define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
114 # endif
115
116 # ifdef __AVX2__
117 #  define vlc_CPU_AVX2() (1)
118 # else
119 #  define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
120 # endif
121
122 # ifdef __3dNOW__
123 #  define vlc_CPU_3dNOW() (1)
124 # else
125 #  define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
126 # endif
127
128 # ifdef __XOP__
129 #  define vlc_CPU_XOP() (1)
130 # else
131 #  define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
132 # endif
133
134 # ifdef __FMA4__
135 #  define vlc_CPU_FMA4() (1)
136 # else
137 #  define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
138 # endif
139
140 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
141 #  define HAVE_FPU 1
142 #  define VLC_CPU_ALTIVEC 2
143
144 #  ifdef ALTIVEC
145 #   define vlc_CPU_ALTIVEC() (1)
146 #  else
147 #   define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
148 #  endif
149
150 # elif defined (__arm__)
151 #  if defined (__VFP_FP__) && !defined (__SOFTFP__)
152 #   define HAVE_FPU 1
153 #  else
154 #   define HAVE_FPU 0
155 #  endif
156 #  define VLC_CPU_ARMv6    4
157 #  define VLC_CPU_ARM_NEON 2
158
159 #  if defined (__ARM_ARCH_7A__)
160 #   define VLC_CPU_ARM_ARCH 7
161 #  elif defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6T2__)
162 #   define VLC_CPU_ARM_ARCH 6
163 #  else
164 #   define VLC_CPU_ARM_ARCH 4
165 #  endif
166
167 #  if (VLC_CPU_ARM_ARCH >= 6)
168 #   define vlc_CPU_ARMv6() (1)
169 #  else
170 #   define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
171 #  endif
172
173 #  ifdef __ARM_NEON__
174 #   define vlc_CPU_ARM_NEON() (1)
175 #  else
176 #   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
177 #  endif
178
179 # elif defined (__aarch64__)
180 #  define HAVE_FPU 1
181
182 # elif defined (__sparc__)
183 #  define HAVE_FPU 1
184
185 # elif defined (__mips_hard_float)
186 #  define HAVE_FPU 1
187
188 # else
189 /**
190  * Are single precision floating point operations "fast"?
191  * If this preprocessor constant is zero, floating point should be avoided
192  * (especially relevant for audio codecs).
193  */
194 #  define HAVE_FPU 0
195
196 # endif
197
198 #endif /* !VLC_CPU_H */