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.
29 VLC_API
unsigned vlc_CPU(void);
31 # if defined (__i386__) || defined (__x86_64__)
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
48 # if defined (__MMX__)
49 # define vlc_CPU_MMX() (1)
52 # define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
53 # define VLC_MMX __attribute__ ((__target__ ("mmx")))
56 # if defined (__SSE__)
57 # define vlc_CPU_MMXEXT() (1)
58 # define vlc_CPU_SSE() (1)
61 # define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
62 # define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
63 # define VLC_SSE __attribute__ ((__target__ ("sse")))
67 # define vlc_CPU_SSE2() (1)
69 # define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
73 # define vlc_CPU_SSE3() (1)
75 # define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
79 # define vlc_CPU_SSSE3() (1)
81 # define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
85 # define vlc_CPU_SSE4_1() (1)
87 # define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
91 # define vlc_CPU_SSE4_2() (1)
93 # define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
97 # define vlc_CPU_SSE4A() (1)
99 # define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
103 # define vlc_CPU_AVX() (1)
105 # define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
109 # define vlc_CPU_AVX2() (1)
111 # define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
115 # define vlc_CPU_3dNOW() (1)
117 # define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
121 # define vlc_CPU_XOP() (1)
123 # define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
127 # define vlc_CPU_FMA4() (1)
129 # define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
132 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
134 # define VLC_CPU_ALTIVEC 2
137 # define vlc_CPU_ALTIVEC() (1)
139 # define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
142 # elif defined (__arm__)
143 # if defined (__VFP_FP__) && !defined (__SOFTFP__)
148 # define VLC_CPU_ARMv6 4
149 # define VLC_CPU_ARM_NEON 2
151 # if defined (__ARM_ARCH_7A__)
152 # define VLC_CPU_ARM_ARCH 7
153 # elif defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6T2__)
154 # define VLC_CPU_ARM_ARCH 6
156 # define VLC_CPU_ARM_ARCH 4
159 # if (VLC_CPU_ARM_ARCH >= 6)
160 # define vlc_CPU_ARMv6() (1)
162 # define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
166 # define vlc_CPU_ARM_NEON() (1)
168 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
171 # elif defined (__aarch64__)
173 // NEON is mandatory for general purpose ARMv8-a CPUs
174 # define vlc_CPU_ARM64_NEON() (1)
176 # elif defined (__sparc__)
179 # elif defined (__mips_hard_float)
184 * Are single precision floating point operations "fast"?
185 * If this preprocessor constant is zero, floating point should be avoided
186 * (especially relevant for audio codecs).
192 #endif /* !VLC_CPU_H */