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 *****************************************************************************/
23 * This file provides CPU features detection.
30 * Retrieves CPU capability flags.
32 VLC_API
unsigned vlc_CPU(void);
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__)
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)
63 # define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
64 # define VLC_MMX __attribute__ ((__target__ ("mmx")))
67 # if defined (__SSE__)
68 # define vlc_CPU_MMXEXT() (1)
69 # define vlc_CPU_SSE() (1)
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")))
78 # define vlc_CPU_SSE2() (1)
80 # define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
84 # define vlc_CPU_SSE3() (1)
86 # define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
90 # define vlc_CPU_SSSE3() (1)
92 # define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
96 # define vlc_CPU_SSE4_1() (1)
98 # define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
102 # define vlc_CPU_SSE4_2() (1)
104 # define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
108 # define vlc_CPU_SSE4A() (1)
110 # define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
114 # define vlc_CPU_AVX() (1)
116 # define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
120 # define vlc_CPU_AVX2() (1)
122 # define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
126 # define vlc_CPU_3dNOW() (1)
128 # define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
132 # define vlc_CPU_XOP() (1)
134 # define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
138 # define vlc_CPU_FMA4() (1)
140 # define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
143 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
145 # define VLC_CPU_ALTIVEC 2
148 # define vlc_CPU_ALTIVEC() (1)
150 # define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
153 # elif defined (__arm__)
154 # if defined (__VFP_FP__) && !defined (__SOFTFP__)
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
167 # define VLC_CPU_ARM_ARCH 4
170 # if (VLC_CPU_ARM_ARCH >= 6)
171 # define vlc_CPU_ARMv6() (1)
173 # define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
177 # define vlc_CPU_ARM_NEON() (1)
179 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
182 # elif defined (__aarch64__)
184 # define VLC_CPU_ARM_NEON 0x1
185 # define VLC_CPU_ARM_SVE 0x2
188 # define vlc_CPU_ARM_NEON() (1)
190 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
193 # ifdef __ARM_FEATURE_SVE
194 # define vlc_CPU_ARM_SVE() (1)
196 # define vlc_CPU_ARM_SVE() ((vlc_CPU() & VLC_CPU_ARM_SVE) != 0)
199 # elif defined (__sparc__)
202 # elif defined (__mips_hard_float)
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).
215 #endif /* !VLC_CPU_H */