vlc_cpu.h 4.93 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlc_cpu.h: CPU capabilities
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 1998-2009 VLC authors and VideoLAN
5
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
6 7 8
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
9 10 11 12
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
13 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
15
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17 18
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * 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 27 28
 */

#ifndef VLC_CPU_H
# define VLC_CPU_H 1

29 30
VLC_API unsigned vlc_CPU(void);

31
# if defined (__i386__) || defined (__x86_64__)
32
#  define HAVE_FPU 1
33 34 35 36 37 38 39 40 41 42 43 44 45 46
#  define VLC_CPU_MMX    0x00000008
#  define VLC_CPU_3dNOW  0x00000010
#  define VLC_CPU_MMXEXT 0x00000020
#  define VLC_CPU_SSE    0x00000040
#  define VLC_CPU_SSE2   0x00000080
#  define VLC_CPU_SSE3   0x00000100
#  define VLC_CPU_SSSE3  0x00000200
#  define VLC_CPU_SSE4_1 0x00000400
#  define VLC_CPU_SSE4_2 0x00000800
#  define VLC_CPU_SSE4A  0x00001000
#  define VLC_CPU_AVX    0x00002000
#  define VLC_CPU_AVX2   0x00004000
#  define VLC_CPU_XOP    0x00008000
#  define VLC_CPU_FMA4   0x00010000
47 48

# if defined (__MMX__)
49
#  define vlc_CPU_MMX() (1)
50 51
#  define VLC_MMX
# else
52
#  define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
53
#  define VLC_MMX __attribute__ ((__target__ ("mmx")))
54 55 56
# endif

# if defined (__SSE__)
57 58
#  define vlc_CPU_MMXEXT() (1)
#  define vlc_CPU_SSE() (1)
59 60
#  define VLC_SSE
# else
61 62
#  define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
#  define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
63
#  define VLC_SSE __attribute__ ((__target__ ("sse")))
64 65
# endif

66 67 68 69 70 71
# ifdef __SSE2__
#  define vlc_CPU_SSE2() (1)
# else
#  define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
# endif

72 73 74 75 76 77
# ifdef __SSE3__
#  define vlc_CPU_SSE3() (1)
# else
#  define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
# endif

78 79 80 81 82 83
# ifdef __SSSE3__
#  define vlc_CPU_SSSE3() (1)
# else
#  define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
# endif

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
# ifdef __SSE4_1__
#  define vlc_CPU_SSE4_1() (1)
# else
#  define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
# endif

# ifdef __SSE4_2__
#  define vlc_CPU_SSE4_2() (1)
# else
#  define vlc_CPU_SSE4_2() ((vlc_CPU() & VLC_CPU_SSE4_2) != 0)
# endif

# ifdef __SSE4A__
#  define vlc_CPU_SSE4A() (1)
# else
#  define vlc_CPU_SSE4A() ((vlc_CPU() & VLC_CPU_SSE4A) != 0)
# endif

102 103 104 105 106 107 108 109 110 111 112 113
# ifdef __AVX__
#  define vlc_CPU_AVX() (1)
# else
#  define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
# endif

# ifdef __AVX2__
#  define vlc_CPU_AVX2() (1)
# else
#  define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
# endif

114 115 116 117 118 119
# ifdef __3dNOW__
#  define vlc_CPU_3dNOW() (1)
# else
#  define vlc_CPU_3dNOW() ((vlc_CPU() & VLC_CPU_3dNOW) != 0)
# endif

120 121 122 123 124 125 126 127 128 129 130 131
# ifdef __XOP__
#  define vlc_CPU_XOP() (1)
# else
#  define vlc_CPU_XOP() ((vlc_CPU() & VLC_CPU_XOP) != 0)
# endif

# ifdef __FMA4__
#  define vlc_CPU_FMA4() (1)
# else
#  define vlc_CPU_FMA4() ((vlc_CPU() & VLC_CPU_FMA4) != 0)
# endif

132
# elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
133
#  define HAVE_FPU 1
134 135 136 137 138 139 140
#  define VLC_CPU_ALTIVEC 2

#  ifdef ALTIVEC
#   define vlc_CPU_ALTIVEC() (1)
#  else
#   define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
#  endif
141 142

# elif defined (__arm__)
143 144 145 146 147
#  if defined (__VFP_FP__) && !defined (__SOFTFP__)
#   define HAVE_FPU 1
#  else
#   define HAVE_FPU 0
#  endif
148
#  define VLC_CPU_ARMv6    4
149 150
#  define VLC_CPU_ARM_NEON 2

151 152 153 154 155 156 157 158 159 160 161 162 163 164
#  if defined (__ARM_ARCH_7A__)
#   define VLC_CPU_ARM_ARCH 7
#  elif defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6T2__)
#   define VLC_CPU_ARM_ARCH 6
#  else
#   define VLC_CPU_ARM_ARCH 4
#  endif

#  if (VLC_CPU_ARM_ARCH >= 6)
#   define vlc_CPU_ARMv6() (1)
#  else
#   define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
#  endif

165 166 167 168 169
#  ifdef __ARM_NEON__
#   define vlc_CPU_ARM_NEON() (1)
#  else
#   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
#  endif
170

171 172
# elif defined (__aarch64__)
#  define HAVE_FPU 1
173 174
// NEON is mandatory for general purpose ARMv8-a CPUs
#  define vlc_CPU_ARM64_NEON() (1)
175

176 177 178
# elif defined (__sparc__)
#  define HAVE_FPU 1

179 180 181
# elif defined (__mips_hard_float)
#  define HAVE_FPU 1

182
# else
183 184 185 186 187
/**
 * Are single precision floating point operations "fast"?
 * If this preprocessor constant is zero, floating point should be avoided
 * (especially relevant for audio codecs).
 */
188 189 190
#  define HAVE_FPU 0

# endif
191 192

#endif /* !VLC_CPU_H */