Coverage Report

Created: 2023-03-26 07:08

/src/vlc/include/vlc_cpu.h
Line
Count
Source (jump to first uncovered line)
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
/**
30
 * Retrieves CPU capability flags.
31
 */
32
VLC_API unsigned vlc_CPU(void);
33
34
/**
35
 * Computes CPU capability flags.
36
 *
37
 * Do not call this function directly.
38
 * Call vlc_CPU() instead, which caches the correct value.
39
 */
40
unsigned vlc_CPU_raw(void);
41
42
# if defined (__i386__) || defined (__x86_64__)
43
#  define HAVE_FPU 1
44
2
#  define VLC_CPU_SSE2   0x00000080
45
4
#  define VLC_CPU_SSE3   0x00000100
46
4
#  define VLC_CPU_SSSE3  0x00000200
47
4
#  define VLC_CPU_SSE4_1 0x00000400
48
2
#  define VLC_CPU_AVX    0x00002000
49
2
#  define VLC_CPU_AVX2   0x00004000
50
51
#  if defined (__SSE__)
52
#   define VLC_SSE
53
#  else
54
#   define VLC_SSE __attribute__ ((__target__ ("sse")))
55
#  endif
56
57
#  ifdef __SSE2__
58
2
#   define vlc_CPU_SSE2() (1)
59
#  else
60
#   define vlc_CPU_SSE2() ((vlc_CPU() & VLC_CPU_SSE2) != 0)
61
#  endif
62
63
#  ifdef __SSE3__
64
#   define vlc_CPU_SSE3() (1)
65
#  else
66
2
#   define vlc_CPU_SSE3() ((vlc_CPU() & VLC_CPU_SSE3) != 0)
67
#  endif
68
69
#  ifdef __SSSE3__
70
#   define vlc_CPU_SSSE3() (1)
71
#  else
72
2
#   define vlc_CPU_SSSE3() ((vlc_CPU() & VLC_CPU_SSSE3) != 0)
73
#  endif
74
75
#  ifdef __SSE4_1__
76
#   define vlc_CPU_SSE4_1() (1)
77
#  else
78
2
#   define vlc_CPU_SSE4_1() ((vlc_CPU() & VLC_CPU_SSE4_1) != 0)
79
#  endif
80
81
#  ifdef __AVX__
82
#   define vlc_CPU_AVX() (1)
83
#   define VLC_AVX
84
#  else
85
2
#   define vlc_CPU_AVX() ((vlc_CPU() & VLC_CPU_AVX) != 0)
86
#   define VLC_AVX __attribute__ ((__target__ ("avx")))
87
#  endif
88
89
#  ifdef __AVX2__
90
#   define vlc_CPU_AVX2() (1)
91
#  else
92
2
#   define vlc_CPU_AVX2() ((vlc_CPU() & VLC_CPU_AVX2) != 0)
93
#  endif
94
95
# elif defined (__ppc__) || defined (__ppc64__) || defined (__powerpc__)
96
#  define HAVE_FPU 1
97
#  define VLC_CPU_ALTIVEC 2
98
99
#  ifdef ALTIVEC
100
#   define vlc_CPU_ALTIVEC() (1)
101
#   define VLC_ALTIVEC
102
#  else
103
#   define vlc_CPU_ALTIVEC() ((vlc_CPU() & VLC_CPU_ALTIVEC) != 0)
104
#   define VLC_ALTIVEC __attribute__ ((__target__ ("altivec")))
105
#  endif
106
107
# elif defined (__arm__)
108
#  if defined (__VFP_FP__) && !defined (__SOFTFP__)
109
#   define HAVE_FPU 1
110
#  else
111
#   define HAVE_FPU 0
112
#  endif
113
#  define VLC_CPU_ARMv6    4
114
#  define VLC_CPU_ARM_NEON 2
115
116
#  if defined (__ARM_ARCH_7A__)
117
#   define VLC_CPU_ARM_ARCH 7
118
#  elif defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6T2__)
119
#   define VLC_CPU_ARM_ARCH 6
120
#  else
121
#   define VLC_CPU_ARM_ARCH 4
122
#  endif
123
124
#  if (VLC_CPU_ARM_ARCH >= 6)
125
#   define vlc_CPU_ARMv6() (1)
126
#  else
127
#   define vlc_CPU_ARMv6() ((vlc_CPU() & VLC_CPU_ARMv6) != 0)
128
#  endif
129
130
#  ifdef __ARM_NEON__
131
#   define vlc_CPU_ARM_NEON() (1)
132
#  else
133
#   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
134
#  endif
135
136
# elif defined (__aarch64__)
137
#  define HAVE_FPU 1
138
#  define VLC_CPU_ARM_NEON 0x1
139
#  define VLC_CPU_ARM_SVE  0x2
140
141
#  ifdef __ARM_NEON
142
#   define vlc_CPU_ARM_NEON() (1)
143
#  else
144
#   define vlc_CPU_ARM_NEON() ((vlc_CPU() & VLC_CPU_ARM_NEON) != 0)
145
#  endif
146
147
#  ifdef __ARM_FEATURE_SVE
148
#   define vlc_CPU_ARM_SVE()   (1)
149
#  else
150
#   define vlc_CPU_ARM_SVE()   ((vlc_CPU() & VLC_CPU_ARM_SVE) != 0)
151
#  endif
152
153
# elif defined (__sparc__)
154
#  define HAVE_FPU 1
155
156
# elif defined (__mips_hard_float)
157
#  define HAVE_FPU 1
158
159
# elif defined (__riscv)
160
#  ifdef __riscv_flen
161
#   define HAVE_FPU 1
162
#  endif
163
#  define VLC_CPU_RV_V 0x1
164
165
#  ifdef __riscv_v
166
#   define vlc_CPU_RV_V() (1)
167
#  else
168
#   define vlc_CPU_RV_V() ((vlc_CPU() & VLC_CPU_RV_V) != 0)
169
#  endif
170
171
# else
172
/**
173
 * Are single precision floating point operations "fast"?
174
 * If this preprocessor constant is zero, floating point should be avoided
175
 * (especially relevant for audio codecs).
176
 */
177
#  define HAVE_FPU 0
178
179
# endif
180
181
/**
182
 * Initialises DSP functions.
183
 *
184
 * This helper looks for accelerated Digital Signal Processing functions
185
 * identified by the supplied type name. Those functions ares typically
186
 * implemented using architecture-specific assembler code with
187
 * Single Instruction Multiple Data (SIMD) opcodes for faster processing.
188
 *
189
 * The exact purposes and semantics of the DSP functions is uniquely identified
190
 * by a nul-terminated string.
191
 *
192
 * \note This function should not be used directly. It is recommended to use
193
 * the convenience wrapper vlc_CPU_functions_init_once() instead.
194
 *
195
 * \param name nul-terminated type identifier (cannot be NULL)
196
 * \param [inout] funcs type-specific data structure to be initialised
197
 */
198
VLC_API void vlc_CPU_functions_init(const char *name, void *restrict funcs);
199
200
# ifndef __cplusplus
201
/**
202
 * Initialises DSP functions once.
203
 *
204
 * This is a convenience wrapper for vlc_CPU_functions_init().
205
 * It only initialises the functions the first time it is evaluated.
206
 */
207
static inline void vlc_CPU_functions_init_once(const char *name,
208
                                               void *restrict funcs)
209
0
{
210
0
    static vlc_once_t once = VLC_STATIC_ONCE;
211
0
212
0
    if (!vlc_once_begin(&once)) {
213
0
        vlc_CPU_functions_init(name, funcs);
214
0
        vlc_once_complete(&once);
215
0
    }
216
0
}
Unexecuted instantiation: libvlc.c:vlc_CPU_functions_init_once
Unexecuted instantiation: cpu.c:vlc_CPU_functions_init_once
Unexecuted instantiation: libvlc-module.c:vlc_CPU_functions_init_once
217
# endif
218
219
#define set_cpu_funcs(name, activate, priority) \
220
    set_callback(VLC_CHECKED_TYPE(void (*)(void *), activate)) \
221
    set_capability(name, priority)
222
223
#endif /* !VLC_CPU_H */