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 # if VLC_GCC_VERSION(4, 4) || defined(__clang__)
54 # define VLC_MMX __attribute__ ((__target__ ("mmx")))
56 # define VLC_MMX VLC_MMX_is_not_implemented_on_this_compiler
60 # if defined (__SSE__)
61 # define vlc_CPU_MMXEXT() (1)
62 # define vlc_CPU_SSE() (1)
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")))
70 # define VLC_SSE VLC_SSE_is_not_implemented_on_this_compiler
75 # define vlc_CPU_SSE2() (1)
77 # define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
81 # define vlc_CPU_SSE3() (1)
83 # define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
87 # define vlc_CPU_SSSE3() (1)
89 # define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
93 # define vlc_CPU_SSE4_1() (1)
95 # define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
99 # define vlc_CPU_SSE4_2() (1)
101 # define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
105 # define vlc_CPU_SSE4A() (1)
107 # define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
111 # define vlc_CPU_AVX() (1)
113 # define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
117 # define vlc_CPU_AVX2() (1)
119 # define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
123 # define vlc_CPU_3dNOW() (1)
125 # define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
129 # define vlc_CPU_XOP() (1)
131 # define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
135 # define vlc_CPU_FMA4() (1)
137 # define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
140 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
142 # define VLC_CPU_ALTIVEC 2
145 # define vlc_CPU_ALTIVEC() (1)
147 # define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
150 # elif defined (__arm__)
151 # if defined (__VFP_FP__) && !defined (__SOFTFP__)
156 # define VLC_CPU_ARMv6 4
157 # define VLC_CPU_ARM_NEON 2
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
164 # define VLC_CPU_ARM_ARCH 4
167 # if (VLC_CPU_ARM_ARCH >= 6)
168 # define vlc_CPU_ARMv6() (1)
170 # define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
174 # define vlc_CPU_ARM_NEON() (1)
176 # define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
179 # elif defined (__aarch64__)
182 # elif defined (__sparc__)
185 # elif defined (__mips_hard_float)
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).
198 #endif /* !VLC_CPU_H */