annotate src/opus-1.3/silk/Inlines.h @ 169:223a55898ab9 tip default

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