vlc_cpu.h 3.46 KB
Newer Older
1 2 3
/*****************************************************************************
 * vlc_cpu.h: CPU capabilities
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 1998-2009 VLC authors and VideoLAN
5
 *
Jean-Baptiste Kempf's avatar
LGPL  
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
LGPL  
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
LGPL  
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
#  define VLC_CPU_MMX    8
34
#  define CPU_CAPABILITY_3DNOW   (1<<4)
35 36
#  define VLC_CPU_MMXEXT 32
#  define VLC_CPU_SSE    64
37
#  define VLC_CPU_SSE2   128
38
#  define VLC_CPU_SSE3   256
39
#  define VLC_CPU_SSSE3  512
40 41 42
#  define CPU_CAPABILITY_SSE4_1  (1<<10)
#  define CPU_CAPABILITY_SSE4_2  (1<<11)
#  define CPU_CAPABILITY_SSE4A   (1<<12)
43 44

# if defined (__MMX__)
45
#  define vlc_CPU_MMX() (1)
46 47
#  define VLC_MMX
# else
48 49 50 51 52 53
#  define vlc_CPU_MMX() ((vlc_CPU() & VLC_CPU_MMX) != 0)
#  if VLC_GCC_VERSION(4, 4)
#   define VLC_MMX __attribute__ ((__target__ ("mmx")))
#  else
#   define VLC_MMX VLC_MMX_is_not_implemented_on_this_compiler
#  endif
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 63 64 65 66 67
#  define vlc_CPU_MMXEXT() ((vlc_CPU() & VLC_CPU_MMXEXT) != 0)
#  define vlc_CPU_SSE() ((vlc_CPU() & VLC_CPU_SSE) != 0)
#  if VLC_GCC_VERSION(4, 4)
#   define VLC_SSE __attribute__ ((__target__ ("sse")))
#  else
#   define VLC_SSE VLC_SSE_is_not_implemented_on_this_compiler
#  endif
68 69
# endif

70 71 72 73 74 75
# ifdef __SSE2__
#  define vlc_CPU_SSE2() (1)
# else
#  define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
# endif

76 77 78 79 80 81
# ifdef __SSE3__
#  define vlc_CPU_SSE3() (1)
# else
#  define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
# endif

82 83 84 85 86 87
# ifdef __SSSE3__
#  define vlc_CPU_SSSE3() (1)
# else
#  define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
# endif

88
# elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
89
#  define HAVE_FPU 1
90 91 92 93 94 95 96
#  define VLC_CPU_ALTIVEC 2

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

# elif defined (__arm__)
99 100 101 102 103
#  if defined (__VFP_FP__) && !defined (__SOFTFP__)
#   define HAVE_FPU 1
#  else
#   define HAVE_FPU 0
#  endif
104 105 106 107 108 109 110
#  define VLC_CPU_ARM_NEON 2

#  ifdef __ARM_NEON__
#   define vlc_CPU_ARM_NEON() (1)
#  else
#   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
#  endif
111 112 113 114 115

# elif defined (__sparc__)
#  define HAVE_FPU 1

# else
116 117 118 119 120
/**
 * Are single precision floating point operations "fast"?
 * If this preprocessor constant is zero, floating point should be avoided
 * (especially relevant for audio codecs).
 */
121 122 123
#  define HAVE_FPU 0

# endif
124 125

#endif /* !VLC_CPU_H */