]> git.sesse.net Git - vlc/blob - include/vlc_cpu.h
Check for SSSE3 at build time if possible
[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    8
34 #  define CPU_CAPABILITY_3DNOW   (1<<4)
35 #  define VLC_CPU_MMXEXT 32
36 #  define VLC_CPU_SSE    64
37 #  define VLC_CPU_SSE2   128
38 #  define VLC_CPU_SSE3   256
39 #  define VLC_CPU_SSSE3  512
40 #  define CPU_CAPABILITY_SSE4_1  (1<<10)
41 #  define CPU_CAPABILITY_SSE4_2  (1<<11)
42 #  define CPU_CAPABILITY_SSE4A   (1<<12)
43
44 # if defined (__MMX__)
45 #  define vlc_CPU_MMX() (1)
46 #  define VLC_MMX
47 # else
48 #  define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
49 #  if VLC_GCC_VERSION(4, 4)
50 #   define VLC_MMX __attribute__ ((__target__ ("mmx")))
51 #  else
52 #   define VLC_MMX VLC_MMX_is_not_implemented_on_this_compiler
53 #  endif
54 # endif
55
56 # if defined (__SSE__)
57 #  define vlc_CPU_MMXEXT() (1)
58 #  define vlc_CPU_SSE() (1)
59 #  define VLC_SSE
60 # else
61 #  define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
62 #  define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
63 #  if VLC_GCC_VERSION(4, 4)
64 #   define VLC_SSE __attribute__ ((__target__ ("sse")))
65 #  else
66 #   define VLC_SSE VLC_SSE_is_not_implemented_on_this_compiler
67 #  endif
68 # endif
69
70 # ifdef __SSE2__
71 #  define vlc_CPU_SSE2() (1)
72 # else
73 #  define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
74 # endif
75
76 # ifdef __SSE3__
77 #  define vlc_CPU_SSE3() (1)
78 # else
79 #  define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
80 # endif
81
82 # ifdef __SSSE3__
83 #  define vlc_CPU_SSSE3() (1)
84 # else
85 #  define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
86 # endif
87
88 # elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
89 #  define HAVE_FPU 1
90 #  define VLC_CPU_ALTIVEC 2
91
92 #  ifdef ALTIVEC
93 #   define vlc_CPU_ALTIVEC() (1)
94 #  else
95 #   define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
96 #  endif
97
98 # elif defined (__arm__)
99 #  if defined (__VFP_FP__) && !defined (__SOFTFP__)
100 #   define HAVE_FPU 1
101 #  else
102 #   define HAVE_FPU 0
103 #  endif
104 #  define VLC_CPU_ARM_NEON 2
105
106 #  ifdef __ARM_NEON__
107 #   define vlc_CPU_ARM_NEON() (1)
108 #  else
109 #   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
110 #  endif
111
112 # elif defined (__sparc__)
113 #  define HAVE_FPU 1
114
115 # else
116 /**
117  * Are single precision floating point operations "fast"?
118  * If this preprocessor constant is zero, floating point should be avoided
119  * (especially relevant for audio codecs).
120  */
121 #  define HAVE_FPU 0
122
123 # endif
124
125 #endif /* !VLC_CPU_H */