Coverage Report

Created: 2023-09-25 08:12

/src/opus/celt/fixed_generic.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2007-2009 Xiph.Org Foundation
2
   Copyright (C) 2003-2008 Jean-Marc Valin
3
   Copyright (C) 2007-2008 CSIRO */
4
/**
5
   @file fixed_generic.h
6
   @brief Generic fixed-point operations
7
*/
8
/*
9
   Redistribution and use in source and binary forms, with or without
10
   modification, are permitted provided that the following conditions
11
   are met:
12
13
   - Redistributions of source code must retain the above copyright
14
   notice, this list of conditions and the following disclaimer.
15
16
   - Redistributions in binary form must reproduce the above copyright
17
   notice, this list of conditions and the following disclaimer in the
18
   documentation and/or other materials provided with the distribution.
19
20
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
24
   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
#ifndef FIXED_GENERIC_H
34
#define FIXED_GENERIC_H
35
36
/** Multiply a 16-bit signed value by a 16-bit unsigned value. The result is a 32-bit signed value */
37
#define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(b))
38
39
/** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */
40
#if OPUS_FAST_INT64
41
#define MULT16_32_Q16(a,b) ((opus_val32)SHR((opus_int64)((opus_val16)(a))*(b),16))
42
#else
43
#define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR((b),16)), SHR(MULT16_16SU((a),((b)&0x0000ffff)),16))
44
#endif
45
46
/** 16x32 multiplication, followed by a 16-bit shift right (round-to-nearest). Results fits in 32 bits */
47
#if OPUS_FAST_INT64
48
0
#define MULT16_32_P16(a,b) ((opus_val32)PSHR((opus_int64)((opus_val16)(a))*(b),16))
49
#else
50
#define MULT16_32_P16(a,b) ADD32(MULT16_16((a),SHR((b),16)), PSHR(MULT16_16SU((a),((b)&0x0000ffff)),16))
51
#endif
52
53
/** 16x32 multiplication, followed by a 15-bit shift right. Results fits in 32 bits */
54
#if OPUS_FAST_INT64
55
117G
#define MULT16_32_Q15(a,b) ((opus_val32)SHR((opus_int64)((opus_val16)(a))*(b),15))
56
#else
57
#define MULT16_32_Q15(a,b) ADD32(SHL(MULT16_16((a),SHR((b),16)),1), SHR(MULT16_16SU((a),((b)&0x0000ffff)),15))
58
#endif
59
60
/** 32x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */
61
#if OPUS_FAST_INT64
62
0
#define MULT32_32_Q16(a,b) ((opus_val32)SHR((opus_int64)(a)*(opus_int64)(b),16))
63
#else
64
#define MULT32_32_Q16(a,b) (ADD32(ADD32(ADD32((opus_val32)(SHR32(((opus_uint32)((a)&0x0000ffff)*(opus_uint32)((b)&0x0000ffff)),16)), MULT16_16SU(SHR32(a,16),((b)&0x0000ffff))), MULT16_16SU(SHR32(b,16),((a)&0x0000ffff))), SHL32(MULT16_16(SHR32(a,16),SHR32(b,16)),16)))
65
#endif
66
67
/** 32x32 multiplication, followed by a 31-bit shift right. Results fits in 32 bits */
68
#if OPUS_FAST_INT64
69
319M
#define MULT32_32_Q31(a,b) ((opus_val32)SHR((opus_int64)(a)*(opus_int64)(b),31))
70
#else
71
#define MULT32_32_Q31(a,b) ADD32(ADD32(SHL(MULT16_16(SHR((a),16),SHR((b),16)),1), SHR(MULT16_16SU(SHR((a),16),((b)&0x0000ffff)),15)), SHR(MULT16_16SU(SHR((b),16),((a)&0x0000ffff)),15))
72
#endif
73
74
/** Compile-time conversion of float constant to 16-bit value */
75
7.34G
#define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits))))
76
77
/** Compile-time conversion of float constant to 32-bit value */
78
1.28G
#define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits))))
79
80
/** Negate a 16-bit value */
81
42.8M
#define NEG16(x) (-(x))
82
/** Negate a 32-bit value */
83
#define NEG32(x) (-(x))
84
85
/** Change a 32-bit value into a 16-bit value. The value is assumed to fit in 16-bit, otherwise the result is undefined */
86
148G
#define EXTRACT16(x) ((opus_val16)(x))
87
/** Change a 16-bit value into a 32-bit value */
88
13.1G
#define EXTEND32(x) ((opus_val32)(x))
89
90
/** Arithmetic shift-right of a 16-bit value */
91
1.84G
#define SHR16(a,shift) ((a) >> (shift))
92
/** Arithmetic shift-left of a 16-bit value */
93
29.3G
#define SHL16(a,shift) ((opus_int16)((opus_uint16)(a)<<(shift)))
94
/** Arithmetic shift-right of a 32-bit value */
95
193G
#define SHR32(a,shift) ((a) >> (shift))
96
/** Arithmetic shift-left of a 32-bit value */
97
67.4G
#define SHL32(a,shift) ((opus_int32)((opus_uint32)(a)<<(shift)))
98
99
/** 32-bit arithmetic shift right with rounding-to-nearest instead of rounding down */
100
74.5G
#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
101
/** 32-bit arithmetic shift right where the argument can be negative */
102
7.78G
#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
103
104
/** "RAW" macros, should not be used outside of this header file */
105
133G
#define SHR(a,shift) ((a) >> (shift))
106
#define SHL(a,shift) SHL32(a,shift)
107
0
#define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift))
108
338M
#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
109
110
2.09M
#define SATURATE16(x) (EXTRACT16((x)>32767 ? 32767 : (x)<-32768 ? -32768 : (x)))
111
112
/** Shift by a and round-to-nearest 32-bit value. Result is a 16-bit value */
113
1.01G
#define ROUND16(x,a) (EXTRACT16(PSHR32((x),(a))))
114
/** Shift by a and round-to-nearest 32-bit value. Result is a saturated 16-bit value */
115
24.6G
#define SROUND16(x,a) EXTRACT16(SATURATE(PSHR32(x,a), 32767));
116
117
/** Divide by two */
118
154M
#define HALF16(x)  (SHR16(x,1))
119
1.69G
#define HALF32(x)  (SHR32(x,1))
120
121
/** Add two 16-bit values */
122
9.82G
#define ADD16(a,b) ((opus_val16)((opus_val16)(a)+(opus_val16)(b)))
123
/** Subtract two 16-bit values */
124
5.73G
#define SUB16(a,b) ((opus_val16)(a)-(opus_val16)(b))
125
/** Add two 32-bit values */
126
316G
#define ADD32(a,b) ((opus_val32)(a)+(opus_val32)(b))
127
/** Subtract two 32-bit values */
128
5.68G
#define SUB32(a,b) ((opus_val32)(a)-(opus_val32)(b))
129
130
/** Add two 32-bit values, ignore any overflows */
131
110G
#define ADD32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)+(opus_uint32)(b)))
132
/** Subtract two 32-bit values, ignore any overflows */
133
100G
#define SUB32_ovflw(a,b) ((opus_val32)((opus_uint32)(a)-(opus_uint32)(b)))
134
/* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */
135
/** Negate 32-bit value, ignore any overflows */
136
2.09G
#define NEG32_ovflw(a) ((opus_val32)(0-(opus_uint32)(a)))
137
138
/** 16x16 multiplication where the result fits in 16 bits */
139
#define MULT16_16_16(a,b)     ((((opus_val16)(a))*((opus_val16)(b))))
140
141
/** 32x32 multiplication where the result fits in 32 bits */
142
#define MULT32_32_32(a,b)     ((((opus_val32)(a))*((opus_val32)(b))))
143
144
/* (opus_val32)(opus_val16) gives TI compiler a hint that it's 16x16->32 multiply */
145
/** 16x16 multiplication where the result fits in 32 bits */
146
10.4G
#define MULT16_16(a,b)     (((opus_val32)(opus_val16)(a))*((opus_val32)(opus_val16)(b)))
147
148
/** 16x16 multiply-add where the result fits in 32 bits */
149
273G
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
150
/** 16x32 multiply, followed by a 15-bit shift right and 32-bit add.
151
    b must fit in 31 bits.
152
    Result fits in 32 bits. */
153
485M
#define MAC16_32_Q15(c,a,b) ADD32((c),ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
154
155
/** 16x32 multiplication, followed by a 16-bit shift right and 32-bit add.
156
    Results fits in 32 bits */
157
#define MAC16_32_Q16(c,a,b) ADD32((c),ADD32(MULT16_16((a),SHR((b),16)), SHR(MULT16_16SU((a),((b)&0x0000ffff)),16)))
158
159
#define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11))
160
#define MULT16_16_Q11(a,b) (SHR(MULT16_16((a),(b)),11))
161
#define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
162
10.7M
#define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
163
14.1G
#define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
164
165
#define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
166
#define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))
167
1.46G
#define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15))
168
169
/** Divide a 32-bit value by a 16-bit value. Result fits in 16 bits */
170
410M
#define DIV32_16(a,b) ((opus_val16)(((opus_val32)(a))/((opus_val16)(b))))
171
172
/** Divide a 32-bit value by a 32-bit value. Result fits in 32 bits */
173
2.04M
#define DIV32(a,b) (((opus_val32)(a))/((opus_val32)(b)))
174
175
#if defined(MIPSr1_ASM)
176
#include "mips/fixed_generic_mipsr1.h"
177
#endif
178
179
static OPUS_INLINE opus_val16 SIG2WORD16_generic(celt_sig x)
180
28.6M
{
181
28.6M
   x = PSHR32(x, SIG_SHIFT);
182
28.6M
   x = MAX32(x, -32768);
183
28.6M
   x = MIN32(x, 32767);
184
28.6M
   return EXTRACT16(x);
185
28.6M
}
Unexecuted instantiation: opus_multistream_decoder.c:SIG2WORD16_generic
Unexecuted instantiation: celt.c:SIG2WORD16_generic
Unexecuted instantiation: opus.c:SIG2WORD16_generic
Unexecuted instantiation: opus_decoder.c:SIG2WORD16_generic
Unexecuted instantiation: opus_multistream.c:SIG2WORD16_generic
celt_decoder.c:SIG2WORD16_generic
Line
Count
Source
180
28.6M
{
181
28.6M
   x = PSHR32(x, SIG_SHIFT);
182
28.6M
   x = MAX32(x, -32768);
183
28.6M
   x = MIN32(x, 32767);
184
28.6M
   return EXTRACT16(x);
185
28.6M
}
Unexecuted instantiation: entcode.c:SIG2WORD16_generic
Unexecuted instantiation: entdec.c:SIG2WORD16_generic
Unexecuted instantiation: mathops.c:SIG2WORD16_generic
Unexecuted instantiation: mdct.c:SIG2WORD16_generic
Unexecuted instantiation: modes.c:SIG2WORD16_generic
Unexecuted instantiation: pitch.c:SIG2WORD16_generic
Unexecuted instantiation: celt_lpc.c:SIG2WORD16_generic
Unexecuted instantiation: quant_bands.c:SIG2WORD16_generic
Unexecuted instantiation: rate.c:SIG2WORD16_generic
Unexecuted instantiation: vq.c:SIG2WORD16_generic
Unexecuted instantiation: x86cpu.c:SIG2WORD16_generic
Unexecuted instantiation: x86_celt_map.c:SIG2WORD16_generic
Unexecuted instantiation: pitch_sse2.c:SIG2WORD16_generic
Unexecuted instantiation: celt_lpc_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: pitch_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: dec_API.c:SIG2WORD16_generic
Unexecuted instantiation: tables_other.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_MS_to_LR.c:SIG2WORD16_generic
Unexecuted instantiation: resampler.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_private_down_FIR.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_private_IIR_FIR.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_private_up2_HQ.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_rom.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_decode_pred.c:SIG2WORD16_generic
Unexecuted instantiation: bands.c:SIG2WORD16_generic
Unexecuted instantiation: cwrs.c:SIG2WORD16_generic
Unexecuted instantiation: entenc.c:SIG2WORD16_generic
Unexecuted instantiation: kiss_fft.c:SIG2WORD16_generic
Unexecuted instantiation: laplace.c:SIG2WORD16_generic
Unexecuted instantiation: init_decoder.c:SIG2WORD16_generic
Unexecuted instantiation: decode_frame.c:SIG2WORD16_generic
Unexecuted instantiation: decode_parameters.c:SIG2WORD16_generic
Unexecuted instantiation: decode_indices.c:SIG2WORD16_generic
Unexecuted instantiation: decode_pulses.c:SIG2WORD16_generic
Unexecuted instantiation: decoder_set_fs.c:SIG2WORD16_generic
Unexecuted instantiation: gain_quant.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_decode.c:SIG2WORD16_generic
Unexecuted instantiation: PLC.c:SIG2WORD16_generic
Unexecuted instantiation: shell_coder.c:SIG2WORD16_generic
Unexecuted instantiation: tables_gain.c:SIG2WORD16_generic
Unexecuted instantiation: tables_LTP.c:SIG2WORD16_generic
Unexecuted instantiation: tables_NLSF_CB_NB_MB.c:SIG2WORD16_generic
Unexecuted instantiation: tables_NLSF_CB_WB.c:SIG2WORD16_generic
Unexecuted instantiation: tables_pitch_lag.c:SIG2WORD16_generic
Unexecuted instantiation: tables_pulses_per_block.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_unpack.c:SIG2WORD16_generic
Unexecuted instantiation: bwexpander.c:SIG2WORD16_generic
Unexecuted instantiation: decode_pitch.c:SIG2WORD16_generic
Unexecuted instantiation: lin2log.c:SIG2WORD16_generic
Unexecuted instantiation: log2lin.c:SIG2WORD16_generic
Unexecuted instantiation: LPC_analysis_filter.c:SIG2WORD16_generic
Unexecuted instantiation: LPC_inv_pred_gain.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF2A.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_stabilize.c:SIG2WORD16_generic
Unexecuted instantiation: pitch_est_tables.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_private_AR2.c:SIG2WORD16_generic
Unexecuted instantiation: sort.c:SIG2WORD16_generic
Unexecuted instantiation: sum_sqr_shift.c:SIG2WORD16_generic
Unexecuted instantiation: LPC_fit.c:SIG2WORD16_generic
Unexecuted instantiation: CNG.c:SIG2WORD16_generic
Unexecuted instantiation: code_signs.c:SIG2WORD16_generic
Unexecuted instantiation: decode_core.c:SIG2WORD16_generic
Unexecuted instantiation: bwexpander_32.c:SIG2WORD16_generic
Unexecuted instantiation: table_LSF_cos.c:SIG2WORD16_generic
Unexecuted instantiation: opus_multistream_encoder.c:SIG2WORD16_generic
Unexecuted instantiation: repacketizer.c:SIG2WORD16_generic
Unexecuted instantiation: celt_encoder.c:SIG2WORD16_generic
Unexecuted instantiation: opus_encoder.c:SIG2WORD16_generic
Unexecuted instantiation: analysis.c:SIG2WORD16_generic
Unexecuted instantiation: mlp.c:SIG2WORD16_generic
Unexecuted instantiation: enc_API.c:SIG2WORD16_generic
Unexecuted instantiation: encode_indices.c:SIG2WORD16_generic
Unexecuted instantiation: encode_pulses.c:SIG2WORD16_generic
Unexecuted instantiation: HP_variable_cutoff.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_LR_to_MS.c:SIG2WORD16_generic
Unexecuted instantiation: check_control_input.c:SIG2WORD16_generic
Unexecuted instantiation: control_SNR.c:SIG2WORD16_generic
Unexecuted instantiation: init_encoder.c:SIG2WORD16_generic
Unexecuted instantiation: control_codec.c:SIG2WORD16_generic
Unexecuted instantiation: biquad_alt.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_encode_pred.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_find_predictor.c:SIG2WORD16_generic
Unexecuted instantiation: stereo_quant_pred.c:SIG2WORD16_generic
Unexecuted instantiation: encode_frame_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: find_pitch_lags_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: find_pred_coefs_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: noise_shape_analysis_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: process_gains_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: residual_energy_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: warped_autocorrelation_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: apply_sine_window_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: autocorr_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: k2a_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: k2a_Q16_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: pitch_analysis_core_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: vector_ops_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: schur64_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: schur_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: x86_silk_map.c:SIG2WORD16_generic
Unexecuted instantiation: LP_variable_cutoff.c:SIG2WORD16_generic
Unexecuted instantiation: NSQ.c:SIG2WORD16_generic
Unexecuted instantiation: NSQ_del_dec.c:SIG2WORD16_generic
Unexecuted instantiation: VAD.c:SIG2WORD16_generic
Unexecuted instantiation: control_audio_bandwidth.c:SIG2WORD16_generic
Unexecuted instantiation: quant_LTP_gains.c:SIG2WORD16_generic
Unexecuted instantiation: VQ_WMat_EC.c:SIG2WORD16_generic
Unexecuted instantiation: process_NLSFs.c:SIG2WORD16_generic
Unexecuted instantiation: ana_filt_bank_1.c:SIG2WORD16_generic
Unexecuted instantiation: inner_prod_aligned.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_VQ_weights_laroia.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_down2_3.c:SIG2WORD16_generic
Unexecuted instantiation: resampler_down2.c:SIG2WORD16_generic
Unexecuted instantiation: sigm_Q15.c:SIG2WORD16_generic
Unexecuted instantiation: LTP_analysis_filter_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: LTP_scale_ctrl_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: find_LPC_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: find_LTP_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: burg_modified_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: NSQ_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: NSQ_del_dec_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: VAD_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: vector_ops_FIX_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: burg_modified_FIX_sse4_1.c:SIG2WORD16_generic
Unexecuted instantiation: interpolate.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_encode.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_VQ.c:SIG2WORD16_generic
Unexecuted instantiation: NLSF_del_dec_quant.c:SIG2WORD16_generic
Unexecuted instantiation: A2NLSF.c:SIG2WORD16_generic
Unexecuted instantiation: corrMatrix_FIX.c:SIG2WORD16_generic
Unexecuted instantiation: opus_projection_decoder.c:SIG2WORD16_generic
Unexecuted instantiation: mapping_matrix.c:SIG2WORD16_generic
Unexecuted instantiation: opus_projection_encoder.c:SIG2WORD16_generic
186
#define SIG2WORD16(x) (SIG2WORD16_generic(x))
187
188
#endif