NSQ_mips.h (5280B)
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 #ifndef NSQ_MIPS_H__ 29 #define NSQ_MIPS_H__ 30 31 #ifdef HAVE_CONFIG_H 32 #include "config.h" 33 #endif 34 35 #include "main.h" 36 #include "macros.h" 37 38 #if defined (__mips_dsp) && __mips == 32 39 40 #define MIPS_MULT __builtin_mips_mult 41 #define MIPS_MADD __builtin_mips_madd 42 #define MIPS_EXTR_R __builtin_mips_extr_r_w 43 44 #define OVERRIDE_silk_noise_shape_quantizer_short_prediction 45 /* suddenly performance is worse */ 46 #define dont_OVERRIDE_silk_NSQ_noise_shape_feedback_loop 47 48 /* gets worst performance result */ 49 #elif defined(__mips_isa_rev) && __mips == 32 50 51 static inline long long MIPS_MULT(int a, int b) { 52 return (long long)a * b; 53 } 54 55 static inline long long MIPS_MADD(long long acc, int a, int b) { 56 return acc + (long long)a * b; 57 } 58 59 static inline opus_val32 MIPS_EXTR_R(long long acc, int shift) { 60 return (opus_val32)((acc + (1 << shift) / 2) >> shift); 61 } 62 63 #define OVERRIDE_silk_noise_shape_quantizer_short_prediction 64 #define OVERRIDE_silk_NSQ_noise_shape_feedback_loop 65 66 #endif 67 68 #if defined(OVERRIDE_silk_noise_shape_quantizer_short_prediction) 69 70 static OPUS_INLINE opus_int32 silk_noise_shape_quantizer_short_prediction_mips(const opus_int32 *buf32, const opus_int16 *coef16, opus_int order) 71 { 72 opus_int64 out; 73 silk_assert( order == 10 || order == 16 ); 74 75 out = MIPS_MULT( buf32[ 0 ], coef16[ 0 ] ); 76 out = MIPS_MADD( out, buf32[ -1 ], coef16[ 1 ] ); 77 out = MIPS_MADD( out, buf32[ -2 ], coef16[ 2 ] ); 78 out = MIPS_MADD( out, buf32[ -3 ], coef16[ 3 ] ); 79 out = MIPS_MADD( out, buf32[ -4 ], coef16[ 4 ] ); 80 out = MIPS_MADD( out, buf32[ -5 ], coef16[ 5 ] ); 81 out = MIPS_MADD( out, buf32[ -6 ], coef16[ 6 ] ); 82 out = MIPS_MADD( out, buf32[ -7 ], coef16[ 7 ] ); 83 out = MIPS_MADD( out, buf32[ -8 ], coef16[ 8 ] ); 84 out = MIPS_MADD( out, buf32[ -9 ], coef16[ 9 ] ); 85 86 if( order == 16 ) 87 { 88 out = MIPS_MADD( out, buf32[ -10 ], coef16[ 10 ] ); 89 out = MIPS_MADD( out, buf32[ -11 ], coef16[ 11 ] ); 90 out = MIPS_MADD( out, buf32[ -12 ], coef16[ 12 ] ); 91 out = MIPS_MADD( out, buf32[ -13 ], coef16[ 13 ] ); 92 out = MIPS_MADD( out, buf32[ -14 ], coef16[ 14 ] ); 93 out = MIPS_MADD( out, buf32[ -15 ], coef16[ 15 ] ); 94 } 95 return MIPS_EXTR_R(out, 16); 96 } 97 98 #undef silk_noise_shape_quantizer_short_prediction 99 #define silk_noise_shape_quantizer_short_prediction(in, coef, coefRev, order, arch) ((void)arch,silk_noise_shape_quantizer_short_prediction_mips(in, coef, order)) 100 101 #endif /* OVERRIDE_silk_noise_shape_quantizer_short_prediction */ 102 103 104 #if defined(OVERRIDE_silk_NSQ_noise_shape_feedback_loop) 105 106 static OPUS_INLINE opus_int32 silk_NSQ_noise_shape_feedback_loop_mips(const opus_int32 *data0, opus_int32 *data1, const opus_int16 *coef, opus_int order) 107 { 108 opus_int32 out; 109 opus_int32 tmp1, tmp2; 110 opus_int j; 111 112 tmp2 = data0[0]; 113 tmp1 = data1[0]; 114 data1[0] = tmp2; 115 116 out = MIPS_MULT(tmp2, coef[0]); 117 118 for (j = 2; j < order; j += 2) { 119 tmp2 = data1[j - 1]; 120 data1[j - 1] = tmp1; 121 out = MIPS_MADD(out, tmp1, coef[j - 1]); 122 tmp1 = data1[j + 0]; 123 data1[j + 0] = tmp2; 124 out = MIPS_MADD(out, tmp2, coef[j]); 125 } 126 data1[order - 1] = tmp1; 127 out = MIPS_MADD(out, tmp1, coef[order - 1]); 128 /* silk_SMLAWB: shift right by 16 && Q11 -> Q12: shift left by 1 */ 129 return MIPS_EXTR_R( out, (16 - 1) ); 130 } 131 132 #undef silk_NSQ_noise_shape_feedback_loop 133 #define silk_NSQ_noise_shape_feedback_loop(data0, data1, coef, order, arch) ((void)arch,silk_NSQ_noise_shape_feedback_loop_mips(data0, data1, coef, order)) 134 135 #endif /* OVERRIDE_silk_NSQ_noise_shape_feedback_loop */ 136 137 #endif /* NSQ_DEL_DEC_MIPSR1_H__ */