/src/mozilla-central/media/libopus/silk/Inlines.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*********************************************************************** |
2 | | Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 | | Redistribution and use in source and binary forms, with or without |
4 | | modification, are permitted provided that the following conditions |
5 | | are met: |
6 | | - Redistributions of source code must retain the above copyright notice, |
7 | | this list of conditions and the following disclaimer. |
8 | | - Redistributions in binary form must reproduce the above copyright |
9 | | notice, this list of conditions and the following disclaimer in the |
10 | | documentation and/or other materials provided with the distribution. |
11 | | - Neither the name of Internet Society, IETF or IETF Trust, nor the |
12 | | names of specific contributors, may be used to endorse or promote |
13 | | products derived from this software without specific prior written |
14 | | permission. |
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | | POSSIBILITY OF SUCH DAMAGE. |
26 | | ***********************************************************************/ |
27 | | |
28 | | /*! \file silk_Inlines.h |
29 | | * \brief silk_Inlines.h defines OPUS_INLINE signal processing functions. |
30 | | */ |
31 | | |
32 | | #ifndef SILK_FIX_INLINES_H |
33 | | #define SILK_FIX_INLINES_H |
34 | | |
35 | | #ifdef __cplusplus |
36 | | extern "C" |
37 | | { |
38 | | #endif |
39 | | |
40 | | /* count leading zeros of opus_int64 */ |
41 | | static OPUS_INLINE opus_int32 silk_CLZ64( opus_int64 in ) |
42 | 0 | { |
43 | 0 | opus_int32 in_upper; |
44 | 0 |
|
45 | 0 | in_upper = (opus_int32)silk_RSHIFT64(in, 32); |
46 | 0 | if (in_upper == 0) { |
47 | 0 | /* Search in the lower 32 bits */ |
48 | 0 | return 32 + silk_CLZ32( (opus_int32) in ); |
49 | 0 | } else { |
50 | 0 | /* Search in the upper 32 bits */ |
51 | 0 | return silk_CLZ32( in_upper ); |
52 | 0 | } |
53 | 0 | } Unexecuted instantiation: x86cpu.c:silk_CLZ64 Unexecuted instantiation: LPC_inv_pred_gain.c:silk_CLZ64 Unexecuted instantiation: NLSF2A.c:silk_CLZ64 Unexecuted instantiation: NSQ_del_dec_sse4_1.c:silk_CLZ64 Unexecuted instantiation: NSQ_sse4_1.c:silk_CLZ64 Unexecuted instantiation: VAD_sse4_1.c:silk_CLZ64 Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus0.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus1.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus2.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus3.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus4.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus5.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus6.c:silk_CLZ64 Unexecuted instantiation: Unified_c_media_libopus7.c:silk_CLZ64 |
54 | | |
55 | | /* get number of leading zeros and fractional part (the bits right after the leading one */ |
56 | | static OPUS_INLINE void silk_CLZ_FRAC( |
57 | | opus_int32 in, /* I input */ |
58 | | opus_int32 *lz, /* O number of leading zeros */ |
59 | | opus_int32 *frac_Q7 /* O the 7 bits right after the leading one */ |
60 | | ) |
61 | 0 | { |
62 | 0 | opus_int32 lzeros = silk_CLZ32(in); |
63 | 0 |
|
64 | 0 | * lz = lzeros; |
65 | 0 | * frac_Q7 = silk_ROR32(in, 24 - lzeros) & 0x7f; |
66 | 0 | } Unexecuted instantiation: x86cpu.c:silk_CLZ_FRAC Unexecuted instantiation: LPC_inv_pred_gain.c:silk_CLZ_FRAC Unexecuted instantiation: NLSF2A.c:silk_CLZ_FRAC Unexecuted instantiation: NSQ_del_dec_sse4_1.c:silk_CLZ_FRAC Unexecuted instantiation: NSQ_sse4_1.c:silk_CLZ_FRAC Unexecuted instantiation: VAD_sse4_1.c:silk_CLZ_FRAC Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus0.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus1.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus2.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus3.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus4.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus5.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus6.c:silk_CLZ_FRAC Unexecuted instantiation: Unified_c_media_libopus7.c:silk_CLZ_FRAC |
67 | | |
68 | | /* Approximation of square root */ |
69 | | /* Accuracy: < +/- 10% for output values > 15 */ |
70 | | /* < +/- 2.5% for output values > 120 */ |
71 | | static OPUS_INLINE opus_int32 silk_SQRT_APPROX( opus_int32 x ) |
72 | 0 | { |
73 | 0 | opus_int32 y, lz, frac_Q7; |
74 | 0 |
|
75 | 0 | if( x <= 0 ) { |
76 | 0 | return 0; |
77 | 0 | } |
78 | 0 | |
79 | 0 | silk_CLZ_FRAC(x, &lz, &frac_Q7); |
80 | 0 |
|
81 | 0 | if( lz & 1 ) { |
82 | 0 | y = 32768; |
83 | 0 | } else { |
84 | 0 | y = 46214; /* 46214 = sqrt(2) * 32768 */ |
85 | 0 | } |
86 | 0 |
|
87 | 0 | /* get scaling right */ |
88 | 0 | y >>= silk_RSHIFT(lz, 1); |
89 | 0 |
|
90 | 0 | /* increment using fractional part of input */ |
91 | 0 | y = silk_SMLAWB(y, y, silk_SMULBB(213, frac_Q7)); |
92 | 0 |
|
93 | 0 | return y; |
94 | 0 | } Unexecuted instantiation: x86cpu.c:silk_SQRT_APPROX Unexecuted instantiation: LPC_inv_pred_gain.c:silk_SQRT_APPROX Unexecuted instantiation: NLSF2A.c:silk_SQRT_APPROX Unexecuted instantiation: NSQ_del_dec_sse4_1.c:silk_SQRT_APPROX Unexecuted instantiation: NSQ_sse4_1.c:silk_SQRT_APPROX Unexecuted instantiation: VAD_sse4_1.c:silk_SQRT_APPROX Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus0.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus1.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus2.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus3.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus4.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus5.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus6.c:silk_SQRT_APPROX Unexecuted instantiation: Unified_c_media_libopus7.c:silk_SQRT_APPROX |
95 | | |
96 | | /* Divide two int32 values and return result as int32 in a given Q-domain */ |
97 | | static OPUS_INLINE opus_int32 silk_DIV32_varQ( /* O returns a good approximation of "(a32 << Qres) / b32" */ |
98 | | const opus_int32 a32, /* I numerator (Q0) */ |
99 | | const opus_int32 b32, /* I denominator (Q0) */ |
100 | | const opus_int Qres /* I Q-domain of result (>= 0) */ |
101 | | ) |
102 | 0 | { |
103 | 0 | opus_int a_headrm, b_headrm, lshift; |
104 | 0 | opus_int32 b32_inv, a32_nrm, b32_nrm, result; |
105 | 0 |
|
106 | 0 | silk_assert( b32 != 0 ); |
107 | 0 | silk_assert( Qres >= 0 ); |
108 | 0 |
|
109 | 0 | /* Compute number of bits head room and normalize inputs */ |
110 | 0 | a_headrm = silk_CLZ32( silk_abs(a32) ) - 1; |
111 | 0 | a32_nrm = silk_LSHIFT(a32, a_headrm); /* Q: a_headrm */ |
112 | 0 | b_headrm = silk_CLZ32( silk_abs(b32) ) - 1; |
113 | 0 | b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */ |
114 | 0 |
|
115 | 0 | /* Inverse of b32, with 14 bits of precision */ |
116 | 0 | b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */ |
117 | 0 |
|
118 | 0 | /* First approximation */ |
119 | 0 | result = silk_SMULWB(a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */ |
120 | 0 |
|
121 | 0 | /* Compute residual by subtracting product of denominator and first approximation */ |
122 | 0 | /* It's OK to overflow because the final value of a32_nrm should always be small */ |
123 | 0 | a32_nrm = silk_SUB32_ovflw(a32_nrm, silk_LSHIFT_ovflw( silk_SMMUL(b32_nrm, result), 3 )); /* Q: a_headrm */ |
124 | 0 |
|
125 | 0 | /* Refinement */ |
126 | 0 | result = silk_SMLAWB(result, a32_nrm, b32_inv); /* Q: 29 + a_headrm - b_headrm */ |
127 | 0 |
|
128 | 0 | /* Convert to Qres domain */ |
129 | 0 | lshift = 29 + a_headrm - b_headrm - Qres; |
130 | 0 | if( lshift < 0 ) { |
131 | 0 | return silk_LSHIFT_SAT32(result, -lshift); |
132 | 0 | } else { |
133 | 0 | if( lshift < 32){ |
134 | 0 | return silk_RSHIFT(result, lshift); |
135 | 0 | } else { |
136 | 0 | /* Avoid undefined result */ |
137 | 0 | return 0; |
138 | 0 | } |
139 | 0 | } |
140 | 0 | } Unexecuted instantiation: x86cpu.c:silk_DIV32_varQ Unexecuted instantiation: LPC_inv_pred_gain.c:silk_DIV32_varQ Unexecuted instantiation: NLSF2A.c:silk_DIV32_varQ Unexecuted instantiation: NSQ_del_dec_sse4_1.c:silk_DIV32_varQ Unexecuted instantiation: NSQ_sse4_1.c:silk_DIV32_varQ Unexecuted instantiation: VAD_sse4_1.c:silk_DIV32_varQ Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus0.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus1.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus2.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus3.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus4.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus5.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus6.c:silk_DIV32_varQ Unexecuted instantiation: Unified_c_media_libopus7.c:silk_DIV32_varQ |
141 | | |
142 | | /* Invert int32 value and return result as int32 in a given Q-domain */ |
143 | | static OPUS_INLINE opus_int32 silk_INVERSE32_varQ( /* O returns a good approximation of "(1 << Qres) / b32" */ |
144 | | const opus_int32 b32, /* I denominator (Q0) */ |
145 | | const opus_int Qres /* I Q-domain of result (> 0) */ |
146 | | ) |
147 | 0 | { |
148 | 0 | opus_int b_headrm, lshift; |
149 | 0 | opus_int32 b32_inv, b32_nrm, err_Q32, result; |
150 | 0 |
|
151 | 0 | silk_assert( b32 != 0 ); |
152 | 0 | silk_assert( Qres > 0 ); |
153 | 0 |
|
154 | 0 | /* Compute number of bits head room and normalize input */ |
155 | 0 | b_headrm = silk_CLZ32( silk_abs(b32) ) - 1; |
156 | 0 | b32_nrm = silk_LSHIFT(b32, b_headrm); /* Q: b_headrm */ |
157 | 0 |
|
158 | 0 | /* Inverse of b32, with 14 bits of precision */ |
159 | 0 | b32_inv = silk_DIV32_16( silk_int32_MAX >> 2, silk_RSHIFT(b32_nrm, 16) ); /* Q: 29 + 16 - b_headrm */ |
160 | 0 |
|
161 | 0 | /* First approximation */ |
162 | 0 | result = silk_LSHIFT(b32_inv, 16); /* Q: 61 - b_headrm */ |
163 | 0 |
|
164 | 0 | /* Compute residual by subtracting product of denominator and first approximation from one */ |
165 | 0 | err_Q32 = silk_LSHIFT( ((opus_int32)1<<29) - silk_SMULWB(b32_nrm, b32_inv), 3 ); /* Q32 */ |
166 | 0 |
|
167 | 0 | /* Refinement */ |
168 | 0 | result = silk_SMLAWW(result, err_Q32, b32_inv); /* Q: 61 - b_headrm */ |
169 | 0 |
|
170 | 0 | /* Convert to Qres domain */ |
171 | 0 | lshift = 61 - b_headrm - Qres; |
172 | 0 | if( lshift <= 0 ) { |
173 | 0 | return silk_LSHIFT_SAT32(result, -lshift); |
174 | 0 | } else { |
175 | 0 | if( lshift < 32){ |
176 | 0 | return silk_RSHIFT(result, lshift); |
177 | 0 | }else{ |
178 | 0 | /* Avoid undefined result */ |
179 | 0 | return 0; |
180 | 0 | } |
181 | 0 | } |
182 | 0 | } Unexecuted instantiation: x86cpu.c:silk_INVERSE32_varQ Unexecuted instantiation: LPC_inv_pred_gain.c:silk_INVERSE32_varQ Unexecuted instantiation: NLSF2A.c:silk_INVERSE32_varQ Unexecuted instantiation: NSQ_del_dec_sse4_1.c:silk_INVERSE32_varQ Unexecuted instantiation: NSQ_sse4_1.c:silk_INVERSE32_varQ Unexecuted instantiation: VAD_sse4_1.c:silk_INVERSE32_varQ Unexecuted instantiation: VQ_WMat_EC_sse4_1.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus0.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus1.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus2.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus3.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus4.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus5.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus6.c:silk_INVERSE32_varQ Unexecuted instantiation: Unified_c_media_libopus7.c:silk_INVERSE32_varQ |
183 | | |
184 | | #ifdef __cplusplus |
185 | | } |
186 | | #endif |
187 | | |
188 | | #endif /* SILK_FIX_INLINES_H */ |