audiotrack: avoid cast, use proper type
[vlc.git] / include / vlc_cpu.h
blob80dfd9656d43d19c6d38c9f930b05560b63253be
1 /*****************************************************************************
2 * vlc_cpu.h: CPU capabilities
3 *****************************************************************************
4 * Copyright (C) 1998-2009 VLC authors and VideoLAN
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.
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.
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 *****************************************************************************/
21 /**
22 * \file
23 * This file provides CPU features detection.
26 #ifndef VLC_CPU_H
27 # define VLC_CPU_H 1
29 /**
30 * Retrieves CPU capability flags.
32 VLC_API unsigned vlc_CPU(void);
34 /**
35 * Computes CPU capability flags.
37 * Do not call this function directly.
38 * Call vlc_CPU() instead, which caches the correct value.
40 unsigned vlc_CPU_raw(void);
42 # if defined (__i386__) || defined (__x86_64__)
43 # define HAVE_FPU 1
44 # define VLC_CPU_MMX 0x00000008
45 # define VLC_CPU_3dNOW 0x00000010
46 # define VLC_CPU_MMXEXT 0x00000020
47 # define VLC_CPU_SSE 0x00000040
48 # define VLC_CPU_SSE2 0x00000080
49 # define VLC_CPU_SSE3 0x00000100
50 # define VLC_CPU_SSSE3 0x00000200
51 # define VLC_CPU_SSE4_1 0x00000400
52 # define VLC_CPU_SSE4_2 0x00000800
53 # define VLC_CPU_SSE4A 0x00001000
54 # define VLC_CPU_AVX 0x00002000
55 # define VLC_CPU_AVX2 0x00004000
56 # define VLC_CPU_XOP 0x00008000
57 # define VLC_CPU_FMA4 0x00010000
59 # if defined (__MMX__)
60 # define vlc_CPU_MMX() (1)
61 # define VLC_MMX
62 # else
63 # define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
64 # define VLC_MMX __attribute__ ((__target__ ("mmx")))
65 # endif
67 # if defined (__SSE__)
68 # define vlc_CPU_MMXEXT() (1)
69 # define vlc_CPU_SSE() (1)
70 # define VLC_SSE
71 # else
72 # define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
73 # define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
74 # define VLC_SSE __attribute__ ((__target__ ("sse")))
75 # endif
77 # ifdef __SSE2__
78 # define vlc_CPU_SSE2() (1)
79 # else
80 # define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
81 # endif
83 # ifdef __SSE3__
84 # define vlc_CPU_SSE3() (1)
85 # else
86 # define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
87 # endif
89 # ifdef __SSSE3__
90 # define vlc_CPU_SSSE3() (1)
91 # else
92 # define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
93 # endif
95 # ifdef __SSE4_1__
96 # define vlc_CPU_SSE4_1() (1)
97 # else
98 # define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
99 # endif
101 # ifdef __SSE4_2__
102 # define vlc_CPU_SSE4_2() (1)
103 # else
104 # define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
105 # endif
107 # ifdef __SSE4A__
108 # define vlc_CPU_SSE4A() (1)
109 # else
110 # define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
111 # endif
113 # ifdef __AVX__
114 # define vlc_CPU_AVX() (1)
115 # else
116 # define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
117 # endif
119 # ifdef __AVX2__
120 # define vlc_CPU_AVX2() (1)
121 # else
122 # define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
123 # endif
125 # ifdef __3dNOW__
126 # define vlc_CPU_3dNOW() (1)
127 # else
128 # define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
129 # endif
131 # ifdef __XOP__
132 # define vlc_CPU_XOP() (1)
133 # else
134 # define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
135 # endif
137 # ifdef __FMA4__
138 # define vlc_CPU_FMA4() (1)
139 # else
140 # define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
141 # endif
143 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
144 # define HAVE_FPU 1
145 # define VLC_CPU_ALTIVEC 2
147 # ifdef ALTIVEC
148 # define vlc_CPU_ALTIVEC() (1)
149 # else
150 # define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
151 # endif
153 # elif defined (__arm__)
154 # if defined (__VFP_FP__) && !defined (__SOFTFP__)
155 # define HAVE_FPU 1
156 # else
157 # define HAVE_FPU 0
158 # endif
159 # define VLC_CPU_ARMv6 4
160 # define VLC_CPU_ARM_NEON 2
162 # if defined (__ARM_ARCH_7A__)
163 # define VLC_CPU_ARM_ARCH 7
164 # elif defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6T2__)
165 # define VLC_CPU_ARM_ARCH 6
166 # else
167 # define VLC_CPU_ARM_ARCH 4
168 # endif
170 # if (VLC_CPU_ARM_ARCH >= 6)
171 # define vlc_CPU_ARMv6() (1)
172 # else
173 # define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
174 # endif
176 # ifdef __ARM_NEON__
177 # define vlc_CPU_ARM_NEON() (1)
178 # else
179 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
180 # endif
182 # elif defined (__aarch64__)
183 # define HAVE_FPU 1
184 # define VLC_CPU_ARM_NEON 0x1
185 # define VLC_CPU_ARM_SVE 0x2
187 # ifdef __ARM_NEON
188 # define vlc_CPU_ARM_NEON() (1)
189 # else
190 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
191 # endif
193 # ifdef __ARM_FEATURE_SVE
194 # define vlc_CPU_ARM_SVE() (1)
195 # else
196 # define vlc_CPU_ARM_SVE() ((vlc_CPU() & VLC_CPU_ARM_SVE) != 0)
197 # endif
199 # elif defined (__sparc__)
200 # define HAVE_FPU 1
202 # elif defined (__mips_hard_float)
203 # define HAVE_FPU 1
205 # else
207 * Are single precision floating point operations "fast"?
208 * If this preprocessor constant is zero, floating point should be avoided
209 * (especially relevant for audio codecs).
211 # define HAVE_FPU 0
213 # endif
215 #endif /* !VLC_CPU_H */