Coverage Report

Created: 2024-09-06 07:53

/src/opus/celt/arch.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2003-2008 Jean-Marc Valin
2
   Copyright (c) 2007-2008 CSIRO
3
   Copyright (c) 2007-2009 Xiph.Org Foundation
4
   Written by Jean-Marc Valin */
5
/**
6
   @file arch.h
7
   @brief Various architecture definitions for CELT
8
*/
9
/*
10
   Redistribution and use in source and binary forms, with or without
11
   modification, are permitted provided that the following conditions
12
   are met:
13
14
   - Redistributions of source code must retain the above copyright
15
   notice, this list of conditions and the following disclaimer.
16
17
   - Redistributions in binary form must reproduce the above copyright
18
   notice, this list of conditions and the following disclaimer in the
19
   documentation and/or other materials provided with the distribution.
20
21
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25
   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
*/
33
34
#ifndef ARCH_H
35
#define ARCH_H
36
37
#include "opus_types.h"
38
#include "opus_defines.h"
39
40
# if !defined(__GNUC_PREREQ)
41
#  if defined(__GNUC__)&&defined(__GNUC_MINOR__)
42
#   define __GNUC_PREREQ(_maj,_min) \
43
 ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min))
44
#  else
45
#   define __GNUC_PREREQ(_maj,_min) 0
46
#  endif
47
# endif
48
49
#if OPUS_GNUC_PREREQ(3, 0)
50
0
#define opus_likely(x)       (__builtin_expect(!!(x), 1))
51
0
#define opus_unlikely(x)     (__builtin_expect(!!(x), 0))
52
#else
53
#define opus_likely(x)       (!!(x))
54
#define opus_unlikely(x)     (!!(x))
55
#endif
56
57
0
#define CELT_SIG_SCALE 32768.f
58
59
0
#define CELT_FATAL(str) celt_fatal(str, __FILE__, __LINE__);
60
61
#if defined(ENABLE_ASSERTIONS) || defined(ENABLE_HARDENING)
62
#ifdef __GNUC__
63
__attribute__((noreturn))
64
#endif
65
void celt_fatal(const char *str, const char *file, int line);
66
67
#if defined(CELT_C) && !defined(OVERRIDE_celt_fatal)
68
#include <stdio.h>
69
#include <stdlib.h>
70
#ifdef __GNUC__
71
__attribute__((noreturn))
72
#endif
73
void celt_fatal(const char *str, const char *file, int line)
74
0
{
75
0
   fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
76
#if defined(_MSC_VER)
77
   _set_abort_behavior( 0, _WRITE_ABORT_MSG);
78
#endif
79
0
   abort();
80
0
}
81
#endif
82
83
0
#define celt_assert(cond) {if (!(cond)) {CELT_FATAL("assertion failed: " #cond);}}
84
0
#define celt_assert2(cond, message) {if (!(cond)) {CELT_FATAL("assertion failed: " #cond "\n" message);}}
85
0
#define MUST_SUCCEED(call) celt_assert((call) == OPUS_OK)
86
#else
87
#define celt_assert(cond)
88
#define celt_assert2(cond, message)
89
#define MUST_SUCCEED(call) do {if((call) != OPUS_OK) {RESTORE_STACK; return OPUS_INTERNAL_ERROR;} } while (0)
90
#endif
91
92
#if defined(ENABLE_ASSERTIONS)
93
#define celt_sig_assert(cond) {if (!(cond)) {CELT_FATAL("signal assertion failed: " #cond);}}
94
#else
95
#define celt_sig_assert(cond)
96
#endif
97
98
0
#define IMUL32(a,b) ((a)*(b))
99
100
0
#define MIN16(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum 16-bit value.   */
101
0
#define MAX16(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 16-bit value.   */
102
0
#define MIN32(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum 32-bit value.   */
103
0
#define MAX32(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum 32-bit value.   */
104
0
#define IMIN(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum int value.   */
105
0
#define IMAX(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum int value.   */
106
#define UADD32(a,b) ((a)+(b))
107
#define USUB32(a,b) ((a)-(b))
108
109
/* Set this if opus_int64 is a native type of the CPU. */
110
/* Assume that all LP64 architectures have fast 64-bit types; also x86_64
111
   (which can be ILP32 for x32) and Win64 (which is LLP64). */
112
#if defined(__x86_64__) || defined(__LP64__) || defined(_WIN64)
113
#define OPUS_FAST_INT64 1
114
#else
115
#define OPUS_FAST_INT64 0
116
#endif
117
118
#define PRINT_MIPS(file)
119
120
#ifdef FIXED_POINT
121
122
typedef opus_int16 opus_val16;
123
typedef opus_int32 opus_val32;
124
typedef opus_int64 opus_val64;
125
126
typedef opus_val32 celt_sig;
127
typedef opus_val16 celt_norm;
128
typedef opus_val32 celt_ener;
129
130
#define celt_isnan(x) 0
131
132
#define Q15ONE 32767
133
134
#define SIG_SHIFT 12
135
/* Safe saturation value for 32-bit signals. Should be less than
136
   2^31*(1-0.85) to avoid blowing up on DC at deemphasis.*/
137
#define SIG_SAT (300000000)
138
139
#define NORM_SCALING 16384
140
141
#define DB_SHIFT 10
142
143
#define EPSILON 1
144
#define VERY_SMALL 0
145
#define VERY_LARGE16 ((opus_val16)32767)
146
#define Q15_ONE ((opus_val16)32767)
147
148
#define SCALEIN(a)      (a)
149
#define SCALEOUT(a)     (a)
150
151
#define ABS16(x) ((x) < 0 ? (-(x)) : (x))
152
#define ABS32(x) ((x) < 0 ? (-(x)) : (x))
153
154
static OPUS_INLINE opus_int16 SAT16(opus_int32 x) {
155
   return x > 32767 ? 32767 : x < -32768 ? -32768 : (opus_int16)x;
156
}
157
158
#ifdef FIXED_DEBUG
159
#include "fixed_debug.h"
160
#else
161
162
#include "fixed_generic.h"
163
164
#ifdef OPUS_ARM_PRESUME_AARCH64_NEON_INTR
165
#include "arm/fixed_arm64.h"
166
#elif defined (OPUS_ARM_INLINE_EDSP)
167
#include "arm/fixed_armv5e.h"
168
#elif defined (OPUS_ARM_INLINE_ASM)
169
#include "arm/fixed_armv4.h"
170
#elif defined (BFIN_ASM)
171
#include "fixed_bfin.h"
172
#elif defined (TI_C5X_ASM)
173
#include "fixed_c5x.h"
174
#elif defined (TI_C6X_ASM)
175
#include "fixed_c6x.h"
176
#endif
177
178
#endif
179
180
#else /* FIXED_POINT */
181
182
typedef float opus_val16;
183
typedef float opus_val32;
184
typedef float opus_val64;
185
186
typedef float celt_sig;
187
typedef float celt_norm;
188
typedef float celt_ener;
189
190
#ifdef FLOAT_APPROX
191
/* This code should reliably detect NaN/inf even when -ffast-math is used.
192
   Assumes IEEE 754 format. */
193
static OPUS_INLINE int celt_isnan(float x)
194
0
{
195
0
   union {float f; opus_uint32 i;} in;
196
0
   in.f = x;
197
0
   return ((in.i>>23)&0xFF)==0xFF && (in.i&0x007FFFFF)!=0;
198
0
}
Unexecuted instantiation: celt.c:celt_isnan
Unexecuted instantiation: pitch_sse.c:celt_isnan
Unexecuted instantiation: opus_multistream_encoder.c:celt_isnan
Unexecuted instantiation: repacketizer.c:celt_isnan
Unexecuted instantiation: bands.c:celt_isnan
Unexecuted instantiation: celt_encoder.c:celt_isnan
Unexecuted instantiation: entcode.c:celt_isnan
Unexecuted instantiation: entdec.c:celt_isnan
Unexecuted instantiation: entenc.c:celt_isnan
Unexecuted instantiation: mathops.c:celt_isnan
Unexecuted instantiation: mdct.c:celt_isnan
Unexecuted instantiation: modes.c:celt_isnan
Unexecuted instantiation: pitch.c:celt_isnan
Unexecuted instantiation: celt_lpc.c:celt_isnan
Unexecuted instantiation: quant_bands.c:celt_isnan
Unexecuted instantiation: rate.c:celt_isnan
Unexecuted instantiation: vq.c:celt_isnan
Unexecuted instantiation: x86cpu.c:celt_isnan
Unexecuted instantiation: x86_celt_map.c:celt_isnan
Unexecuted instantiation: vq_sse2.c:celt_isnan
Unexecuted instantiation: pitch_avx.c:celt_isnan
Unexecuted instantiation: opus.c:celt_isnan
Unexecuted instantiation: opus_decoder.c:celt_isnan
Unexecuted instantiation: opus_encoder.c:celt_isnan
Unexecuted instantiation: extensions.c:celt_isnan
Unexecuted instantiation: opus_multistream.c:celt_isnan
Unexecuted instantiation: analysis.c:celt_isnan
Unexecuted instantiation: mlp.c:celt_isnan
Unexecuted instantiation: celt_decoder.c:celt_isnan
Unexecuted instantiation: cwrs.c:celt_isnan
Unexecuted instantiation: kiss_fft.c:celt_isnan
Unexecuted instantiation: laplace.c:celt_isnan
Unexecuted instantiation: dec_API.c:celt_isnan
Unexecuted instantiation: enc_API.c:celt_isnan
Unexecuted instantiation: encode_indices.c:celt_isnan
Unexecuted instantiation: encode_pulses.c:celt_isnan
Unexecuted instantiation: shell_coder.c:celt_isnan
Unexecuted instantiation: tables_gain.c:celt_isnan
Unexecuted instantiation: tables_LTP.c:celt_isnan
Unexecuted instantiation: tables_other.c:celt_isnan
Unexecuted instantiation: tables_pitch_lag.c:celt_isnan
Unexecuted instantiation: tables_pulses_per_block.c:celt_isnan
Unexecuted instantiation: HP_variable_cutoff.c:celt_isnan
Unexecuted instantiation: NLSF_unpack.c:celt_isnan
Unexecuted instantiation: stereo_LR_to_MS.c:celt_isnan
Unexecuted instantiation: stereo_MS_to_LR.c:celt_isnan
Unexecuted instantiation: check_control_input.c:celt_isnan
Unexecuted instantiation: control_SNR.c:celt_isnan
Unexecuted instantiation: init_encoder.c:celt_isnan
Unexecuted instantiation: control_codec.c:celt_isnan
Unexecuted instantiation: lin2log.c:celt_isnan
Unexecuted instantiation: log2lin.c:celt_isnan
Unexecuted instantiation: resampler.c:celt_isnan
Unexecuted instantiation: resampler_private_down_FIR.c:celt_isnan
Unexecuted instantiation: resampler_private_IIR_FIR.c:celt_isnan
Unexecuted instantiation: resampler_private_up2_HQ.c:celt_isnan
Unexecuted instantiation: resampler_rom.c:celt_isnan
Unexecuted instantiation: stereo_decode_pred.c:celt_isnan
Unexecuted instantiation: stereo_encode_pred.c:celt_isnan
Unexecuted instantiation: stereo_find_predictor.c:celt_isnan
Unexecuted instantiation: stereo_quant_pred.c:celt_isnan
Unexecuted instantiation: encode_frame_FLP.c:celt_isnan
Unexecuted instantiation: find_pitch_lags_FLP.c:celt_isnan
Unexecuted instantiation: find_pred_coefs_FLP.c:celt_isnan
Unexecuted instantiation: LPC_analysis_filter_FLP.c:celt_isnan
Unexecuted instantiation: LTP_analysis_filter_FLP.c:celt_isnan
Unexecuted instantiation: LTP_scale_ctrl_FLP.c:celt_isnan
Unexecuted instantiation: noise_shape_analysis_FLP.c:celt_isnan
Unexecuted instantiation: process_gains_FLP.c:celt_isnan
Unexecuted instantiation: residual_energy_FLP.c:celt_isnan
Unexecuted instantiation: warped_autocorrelation_FLP.c:celt_isnan
Unexecuted instantiation: wrappers_FLP.c:celt_isnan
Unexecuted instantiation: autocorrelation_FLP.c:celt_isnan
Unexecuted instantiation: bwexpander_FLP.c:celt_isnan
Unexecuted instantiation: energy_FLP.c:celt_isnan
Unexecuted instantiation: k2a_FLP.c:celt_isnan
Unexecuted instantiation: pitch_analysis_core_FLP.c:celt_isnan
Unexecuted instantiation: scale_copy_vector_FLP.c:celt_isnan
Unexecuted instantiation: schur_FLP.c:celt_isnan
Unexecuted instantiation: sort_FLP.c:celt_isnan
Unexecuted instantiation: x86_silk_map.c:celt_isnan
Unexecuted instantiation: NSQ_del_dec_avx2.c:celt_isnan
Unexecuted instantiation: code_signs.c:celt_isnan
Unexecuted instantiation: init_decoder.c:celt_isnan
Unexecuted instantiation: decode_frame.c:celt_isnan
Unexecuted instantiation: decode_parameters.c:celt_isnan
Unexecuted instantiation: decode_indices.c:celt_isnan
Unexecuted instantiation: decode_pulses.c:celt_isnan
Unexecuted instantiation: decoder_set_fs.c:celt_isnan
Unexecuted instantiation: gain_quant.c:celt_isnan
Unexecuted instantiation: LP_variable_cutoff.c:celt_isnan
Unexecuted instantiation: NLSF_decode.c:celt_isnan
Unexecuted instantiation: NSQ.c:celt_isnan
Unexecuted instantiation: NSQ_del_dec.c:celt_isnan
Unexecuted instantiation: PLC.c:celt_isnan
Unexecuted instantiation: tables_NLSF_CB_NB_MB.c:celt_isnan
Unexecuted instantiation: tables_NLSF_CB_WB.c:celt_isnan
Unexecuted instantiation: VAD.c:celt_isnan
Unexecuted instantiation: control_audio_bandwidth.c:celt_isnan
Unexecuted instantiation: quant_LTP_gains.c:celt_isnan
Unexecuted instantiation: VQ_WMat_EC.c:celt_isnan
Unexecuted instantiation: process_NLSFs.c:celt_isnan
Unexecuted instantiation: A2NLSF.c:celt_isnan
Unexecuted instantiation: ana_filt_bank_1.c:celt_isnan
Unexecuted instantiation: biquad_alt.c:celt_isnan
Unexecuted instantiation: bwexpander_32.c:celt_isnan
Unexecuted instantiation: bwexpander.c:celt_isnan
Unexecuted instantiation: decode_pitch.c:celt_isnan
Unexecuted instantiation: inner_prod_aligned.c:celt_isnan
Unexecuted instantiation: LPC_analysis_filter.c:celt_isnan
Unexecuted instantiation: LPC_inv_pred_gain.c:celt_isnan
Unexecuted instantiation: table_LSF_cos.c:celt_isnan
Unexecuted instantiation: NLSF2A.c:celt_isnan
Unexecuted instantiation: NLSF_stabilize.c:celt_isnan
Unexecuted instantiation: NLSF_VQ_weights_laroia.c:celt_isnan
Unexecuted instantiation: pitch_est_tables.c:celt_isnan
Unexecuted instantiation: resampler_down2_3.c:celt_isnan
Unexecuted instantiation: resampler_down2.c:celt_isnan
Unexecuted instantiation: resampler_private_AR2.c:celt_isnan
Unexecuted instantiation: sigm_Q15.c:celt_isnan
Unexecuted instantiation: sort.c:celt_isnan
Unexecuted instantiation: sum_sqr_shift.c:celt_isnan
Unexecuted instantiation: LPC_fit.c:celt_isnan
Unexecuted instantiation: apply_sine_window_FLP.c:celt_isnan
Unexecuted instantiation: find_LPC_FLP.c:celt_isnan
Unexecuted instantiation: find_LTP_FLP.c:celt_isnan
Unexecuted instantiation: burg_modified_FLP.c:celt_isnan
Unexecuted instantiation: inner_product_FLP.c:celt_isnan
Unexecuted instantiation: scale_vector_FLP.c:celt_isnan
Unexecuted instantiation: NSQ_sse4_1.c:celt_isnan
Unexecuted instantiation: NSQ_del_dec_sse4_1.c:celt_isnan
Unexecuted instantiation: VAD_sse4_1.c:celt_isnan
Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:celt_isnan
Unexecuted instantiation: inner_product_FLP_avx2.c:celt_isnan
Unexecuted instantiation: CNG.c:celt_isnan
Unexecuted instantiation: decode_core.c:celt_isnan
Unexecuted instantiation: interpolate.c:celt_isnan
Unexecuted instantiation: NLSF_encode.c:celt_isnan
Unexecuted instantiation: NLSF_VQ.c:celt_isnan
Unexecuted instantiation: NLSF_del_dec_quant.c:celt_isnan
Unexecuted instantiation: corrMatrix_FLP.c:celt_isnan
199
#else
200
#ifdef __FAST_MATH__
201
#error Cannot build libopus with -ffast-math unless FLOAT_APPROX is defined. This could result in crashes on extreme (e.g. NaN) input
202
#endif
203
#define celt_isnan(x) ((x)!=(x))
204
#endif
205
206
0
#define Q15ONE 1.0f
207
208
0
#define NORM_SCALING 1.f
209
210
0
#define EPSILON 1e-15f
211
0
#define VERY_SMALL 1e-30f
212
#define VERY_LARGE16 1e15f
213
#define Q15_ONE ((opus_val16)1.f)
214
215
/* This appears to be the same speed as C99's fabsf() but it's more portable. */
216
0
#define ABS16(x) ((float)fabs(x))
217
0
#define ABS32(x) ((float)fabs(x))
218
219
0
#define QCONST16(x,bits) (x)
220
0
#define QCONST32(x,bits) (x)
221
222
0
#define NEG16(x) (-(x))
223
#define NEG32(x) (-(x))
224
0
#define NEG32_ovflw(x) (-(x))
225
0
#define EXTRACT16(x) (x)
226
0
#define EXTEND32(x) (x)
227
0
#define SHR16(a,shift) (a)
228
0
#define SHL16(a,shift) (a)
229
0
#define SHR32(a,shift) (a)
230
0
#define SHL32(a,shift) (a)
231
0
#define PSHR32(a,shift) (a)
232
0
#define VSHR32(a,shift) (a)
233
234
#define PSHR(a,shift)   (a)
235
#define SHR(a,shift)    (a)
236
#define SHL(a,shift)    (a)
237
0
#define SATURATE(x,a)   (x)
238
0
#define SATURATE16(x)   (x)
239
240
0
#define ROUND16(a,shift)  (a)
241
0
#define SROUND16(a,shift) (a)
242
0
#define HALF16(x)       (.5f*(x))
243
0
#define HALF32(x)       (.5f*(x))
244
245
0
#define ADD16(a,b) ((a)+(b))
246
0
#define SUB16(a,b) ((a)-(b))
247
0
#define ADD32(a,b) ((a)+(b))
248
0
#define SUB32(a,b) ((a)-(b))
249
0
#define ADD32_ovflw(a,b) ((a)+(b))
250
0
#define SUB32_ovflw(a,b) ((a)-(b))
251
#define MULT16_16_16(a,b)     ((a)*(b))
252
0
#define MULT16_16(a,b)     ((opus_val32)(a)*(opus_val32)(b))
253
0
#define MAC16_16(c,a,b)     ((c)+(opus_val32)(a)*(opus_val32)(b))
254
255
0
#define MULT16_32_Q15(a,b)     ((a)*(b))
256
#define MULT16_32_Q16(a,b)     ((a)*(b))
257
258
0
#define MULT32_32_Q31(a,b)     ((a)*(b))
259
260
0
#define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))
261
#define MAC16_32_Q16(c,a,b)     ((c)+(a)*(b))
262
263
#define MULT16_16_Q11_32(a,b)     ((a)*(b))
264
#define MULT16_16_Q11(a,b)     ((a)*(b))
265
#define MULT16_16_Q13(a,b)     ((a)*(b))
266
0
#define MULT16_16_Q14(a,b)     ((a)*(b))
267
0
#define MULT16_16_Q15(a,b)     ((a)*(b))
268
0
#define MULT16_16_P15(a,b)     ((a)*(b))
269
#define MULT16_16_P13(a,b)     ((a)*(b))
270
#define MULT16_16_P14(a,b)     ((a)*(b))
271
0
#define MULT16_32_P16(a,b)     ((a)*(b))
272
273
0
#define DIV32_16(a,b)     (((opus_val32)(a))/(opus_val16)(b))
274
0
#define DIV32(a,b)     (((opus_val32)(a))/(opus_val32)(b))
275
276
0
#define SCALEIN(a)      ((a)*CELT_SIG_SCALE)
277
0
#define SCALEOUT(a)     ((a)*(1/CELT_SIG_SCALE))
278
279
#define SIG2WORD16(x) (x)
280
281
#endif /* !FIXED_POINT */
282
283
#ifndef GLOBAL_STACK_SIZE
284
#ifdef FIXED_POINT
285
#define GLOBAL_STACK_SIZE 120000
286
#else
287
#define GLOBAL_STACK_SIZE 120000
288
#endif
289
#endif
290
291
#endif /* ARCH_H */