michael@0: /*********************************************************************** michael@0: Copyright (c) 2006-2011, Skype Limited. All rights reserved. michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions michael@0: are met: michael@0: - Redistributions of source code must retain the above copyright notice, michael@0: this list of conditions and the following disclaimer. michael@0: - Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: - Neither the name of Internet Society, IETF or IETF Trust, nor the michael@0: names of specific contributors, may be used to endorse or promote michael@0: products derived from this software without specific prior written michael@0: permission. michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" michael@0: AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE michael@0: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE michael@0: POSSIBILITY OF SUCH DAMAGE. michael@0: ***********************************************************************/ michael@0: michael@0: #ifndef SIGPROCFIX_API_MACROCOUNT_H michael@0: #define SIGPROCFIX_API_MACROCOUNT_H michael@0: #include michael@0: michael@0: #ifdef silk_MACRO_COUNT michael@0: #define varDefine opus_int64 ops_count = 0; michael@0: michael@0: extern opus_int64 ops_count; michael@0: michael@0: static OPUS_INLINE opus_int64 silk_SaveCount(){ michael@0: return(ops_count); michael@0: } michael@0: michael@0: static OPUS_INLINE opus_int64 silk_SaveResetCount(){ michael@0: opus_int64 ret; michael@0: michael@0: ret = ops_count; michael@0: ops_count = 0; michael@0: return(ret); michael@0: } michael@0: michael@0: static OPUS_INLINE silk_PrintCount(){ michael@0: printf("ops_count = %d \n ", (opus_int32)ops_count); michael@0: } michael@0: michael@0: #undef silk_MUL michael@0: static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: ops_count += 4; michael@0: ret = a32 * b32; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_MUL_uint michael@0: static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){ michael@0: opus_uint32 ret; michael@0: ops_count += 4; michael@0: ret = a32 * b32; michael@0: return ret; michael@0: } michael@0: #undef silk_MLA michael@0: static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 4; michael@0: ret = a32 + b32 * c32; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_MLA_uint michael@0: static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){ michael@0: opus_uint32 ret; michael@0: ops_count += 4; michael@0: ret = a32 + b32 * c32; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMULWB michael@0: static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: ops_count += 5; michael@0: ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16); michael@0: return ret; michael@0: } michael@0: #undef silk_SMLAWB michael@0: static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 5; michael@0: ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16))); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMULWT michael@0: static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: ops_count += 4; michael@0: ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16); michael@0: return ret; michael@0: } michael@0: #undef silk_SMLAWT michael@0: static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 4; michael@0: ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16)); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMULBB michael@0: static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32); michael@0: return ret; michael@0: } michael@0: #undef silk_SMLABB michael@0: static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMULBT michael@0: static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){ michael@0: opus_int32 ret; michael@0: ops_count += 4; michael@0: ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMLABT michael@0: static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMULTT michael@0: static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = (a32 >> 16) * (b32 >> 16); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMLATT michael@0: static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a32 + (b32 >> 16) * (c32 >> 16); michael@0: return ret; michael@0: } michael@0: michael@0: michael@0: /* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/ michael@0: #undef silk_MLA_ovflw michael@0: #define silk_MLA_ovflw silk_MLA michael@0: michael@0: #undef silk_SMLABB_ovflw michael@0: #define silk_SMLABB_ovflw silk_SMLABB michael@0: michael@0: #undef silk_SMLABT_ovflw michael@0: #define silk_SMLABT_ovflw silk_SMLABT michael@0: michael@0: #undef silk_SMLATT_ovflw michael@0: #define silk_SMLATT_ovflw silk_SMLATT michael@0: michael@0: #undef silk_SMLAWB_ovflw michael@0: #define silk_SMLAWB_ovflw silk_SMLAWB michael@0: michael@0: #undef silk_SMLAWT_ovflw michael@0: #define silk_SMLAWT_ovflw silk_SMLAWT michael@0: michael@0: #undef silk_SMULL michael@0: static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){ michael@0: opus_int64 ret; michael@0: ops_count += 8; michael@0: ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32)); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMLAL michael@0: static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){ michael@0: opus_int64 ret; michael@0: ops_count += 8; michael@0: ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32)); michael@0: return ret; michael@0: } michael@0: #undef silk_SMLALBB michael@0: static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){ michael@0: opus_int64 ret; michael@0: ops_count += 4; michael@0: ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16)); michael@0: return ret; michael@0: } michael@0: michael@0: #undef SigProcFIX_CLZ16 michael@0: static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16) michael@0: { michael@0: opus_int32 out32 = 0; michael@0: ops_count += 10; michael@0: if( in16 == 0 ) { michael@0: return 16; michael@0: } michael@0: /* test nibbles */ michael@0: if( in16 & 0xFF00 ) { michael@0: if( in16 & 0xF000 ) { michael@0: in16 >>= 12; michael@0: } else { michael@0: out32 += 4; michael@0: in16 >>= 8; michael@0: } michael@0: } else { michael@0: if( in16 & 0xFFF0 ) { michael@0: out32 += 8; michael@0: in16 >>= 4; michael@0: } else { michael@0: out32 += 12; michael@0: } michael@0: } michael@0: /* test bits and return */ michael@0: if( in16 & 0xC ) { michael@0: if( in16 & 0x8 ) michael@0: return out32 + 0; michael@0: else michael@0: return out32 + 1; michael@0: } else { michael@0: if( in16 & 0xE ) michael@0: return out32 + 2; michael@0: else michael@0: return out32 + 3; michael@0: } michael@0: } michael@0: michael@0: #undef SigProcFIX_CLZ32 michael@0: static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32) michael@0: { michael@0: /* test highest 16 bits and convert to opus_int16 */ michael@0: ops_count += 2; michael@0: if( in32 & 0xFFFF0000 ) { michael@0: return SigProcFIX_CLZ16((opus_int16)(in32 >> 16)); michael@0: } else { michael@0: return SigProcFIX_CLZ16((opus_int16)in32) + 16; michael@0: } michael@0: } michael@0: michael@0: #undef silk_DIV32 michael@0: static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){ michael@0: ops_count += 64; michael@0: return a32 / b32; michael@0: } michael@0: michael@0: #undef silk_DIV32_16 michael@0: static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){ michael@0: ops_count += 32; michael@0: return a32 / b32; michael@0: } michael@0: michael@0: #undef silk_SAT8 michael@0: static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){ michael@0: opus_int8 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \ michael@0: ((a) < silk_int8_MIN ? silk_int8_MIN : (a))); michael@0: return(tmp); michael@0: } michael@0: michael@0: #undef silk_SAT16 michael@0: static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){ michael@0: opus_int16 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \ michael@0: ((a) < silk_int16_MIN ? silk_int16_MIN : (a))); michael@0: return(tmp); michael@0: } michael@0: #undef silk_SAT32 michael@0: static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){ michael@0: opus_int32 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \ michael@0: ((a) < silk_int32_MIN ? silk_int32_MIN : (a))); michael@0: return(tmp); michael@0: } michael@0: #undef silk_POS_SAT32 michael@0: static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){ michael@0: opus_int32 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a)); michael@0: return(tmp); michael@0: } michael@0: michael@0: #undef silk_ADD_POS_SAT8 michael@0: static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){ michael@0: opus_int8 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b))); michael@0: return(tmp); michael@0: } michael@0: #undef silk_ADD_POS_SAT16 michael@0: static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){ michael@0: opus_int16 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b))); michael@0: return(tmp); michael@0: } michael@0: michael@0: #undef silk_ADD_POS_SAT32 michael@0: static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){ michael@0: opus_int32 tmp; michael@0: ops_count += 1; michael@0: tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b))); michael@0: return(tmp); michael@0: } michael@0: michael@0: #undef silk_ADD_POS_SAT64 michael@0: static OPUS_INLINE opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){ michael@0: opus_int64 tmp; michael@0: ops_count += 1; michael@0: tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b))); michael@0: return(tmp); michael@0: } michael@0: michael@0: #undef silk_LSHIFT8 michael@0: static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){ michael@0: opus_int8 ret; michael@0: ops_count += 1; michael@0: ret = a << shift; michael@0: return ret; michael@0: } michael@0: #undef silk_LSHIFT16 michael@0: static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){ michael@0: opus_int16 ret; michael@0: ops_count += 1; michael@0: ret = a << shift; michael@0: return ret; michael@0: } michael@0: #undef silk_LSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a << shift; michael@0: return ret; michael@0: } michael@0: #undef silk_LSHIFT64 michael@0: static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){ michael@0: ops_count += 1; michael@0: return a << shift; michael@0: } michael@0: michael@0: #undef silk_LSHIFT_ovflw michael@0: static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){ michael@0: ops_count += 1; michael@0: return a << shift; michael@0: } michael@0: michael@0: #undef silk_LSHIFT_uint michael@0: static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){ michael@0: opus_uint32 ret; michael@0: ops_count += 1; michael@0: ret = a << shift; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_RSHIFT8 michael@0: static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){ michael@0: ops_count += 1; michael@0: return a >> shift; michael@0: } michael@0: #undef silk_RSHIFT16 michael@0: static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){ michael@0: ops_count += 1; michael@0: return a >> shift; michael@0: } michael@0: #undef silk_RSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){ michael@0: ops_count += 1; michael@0: return a >> shift; michael@0: } michael@0: #undef silk_RSHIFT64 michael@0: static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){ michael@0: ops_count += 1; michael@0: return a >> shift; michael@0: } michael@0: michael@0: #undef silk_RSHIFT_uint michael@0: static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){ michael@0: ops_count += 1; michael@0: return a >> shift; michael@0: } michael@0: michael@0: #undef silk_ADD_LSHIFT michael@0: static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b << shift); michael@0: return ret; /* shift >= 0*/ michael@0: } michael@0: #undef silk_ADD_LSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b << shift); michael@0: return ret; /* shift >= 0*/ michael@0: } michael@0: #undef silk_ADD_LSHIFT_uint michael@0: static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ michael@0: opus_uint32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b << shift); michael@0: return ret; /* shift >= 0*/ michael@0: } michael@0: #undef silk_ADD_RSHIFT michael@0: static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b >> shift); michael@0: return ret; /* shift > 0*/ michael@0: } michael@0: #undef silk_ADD_RSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b >> shift); michael@0: return ret; /* shift > 0*/ michael@0: } michael@0: #undef silk_ADD_RSHIFT_uint michael@0: static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){ michael@0: opus_uint32 ret; michael@0: ops_count += 1; michael@0: ret = a + (b >> shift); michael@0: return ret; /* shift > 0*/ michael@0: } michael@0: #undef silk_SUB_LSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a - (b << shift); michael@0: return ret; /* shift >= 0*/ michael@0: } michael@0: #undef silk_SUB_RSHIFT32 michael@0: static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a - (b >> shift); michael@0: return ret; /* shift > 0*/ michael@0: } michael@0: michael@0: #undef silk_RSHIFT_ROUND michael@0: static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){ michael@0: opus_int32 ret; michael@0: ops_count += 3; michael@0: ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_RSHIFT_ROUND64 michael@0: static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){ michael@0: opus_int64 ret; michael@0: ops_count += 6; michael@0: ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_abs_int64 michael@0: static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){ michael@0: ops_count += 1; michael@0: return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/ michael@0: } michael@0: michael@0: #undef silk_abs_int32 michael@0: static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){ michael@0: ops_count += 1; michael@0: return silk_abs(a); michael@0: } michael@0: michael@0: michael@0: #undef silk_min michael@0: static silk_min(a, b){ michael@0: ops_count += 1; michael@0: return (((a) < (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_max michael@0: static silk_max(a, b){ michael@0: ops_count += 1; michael@0: return (((a) > (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_sign michael@0: static silk_sign(a){ michael@0: ops_count += 1; michael@0: return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 )); michael@0: } michael@0: michael@0: #undef silk_ADD16 michael@0: static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){ michael@0: opus_int16 ret; michael@0: ops_count += 1; michael@0: ret = a + b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_ADD32 michael@0: static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a + b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_ADD64 michael@0: static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){ michael@0: opus_int64 ret; michael@0: ops_count += 2; michael@0: ret = a + b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SUB16 michael@0: static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){ michael@0: opus_int16 ret; michael@0: ops_count += 1; michael@0: ret = a - b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SUB32 michael@0: static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){ michael@0: opus_int32 ret; michael@0: ops_count += 1; michael@0: ret = a - b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SUB64 michael@0: static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){ michael@0: opus_int64 ret; michael@0: ops_count += 2; michael@0: ret = a - b; michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_ADD_SAT16 michael@0: static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) { michael@0: opus_int16 res; michael@0: /* Nb will be counted in AKP_add32 and silk_SAT16*/ michael@0: res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) ); michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_ADD_SAT32 michael@0: static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 res; michael@0: ops_count += 1; michael@0: res = ((((a32) + (b32)) & 0x80000000) == 0 ? \ michael@0: ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \ michael@0: ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) ); michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_ADD_SAT64 michael@0: static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) { michael@0: opus_int64 res; michael@0: ops_count += 1; michael@0: res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \ michael@0: ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \ michael@0: ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) ); michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_SUB_SAT16 michael@0: static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) { michael@0: opus_int16 res; michael@0: silk_assert(0); michael@0: /* Nb will be counted in sub-macros*/ michael@0: res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) ); michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_SUB_SAT32 michael@0: static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) { michael@0: opus_int32 res; michael@0: ops_count += 1; michael@0: res = ((((a32)-(b32)) & 0x80000000) == 0 ? \ michael@0: (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \ michael@0: ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) ); michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_SUB_SAT64 michael@0: static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) { michael@0: opus_int64 res; michael@0: ops_count += 1; michael@0: res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \ michael@0: (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \ michael@0: ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) ); michael@0: michael@0: return res; michael@0: } michael@0: michael@0: #undef silk_SMULWW michael@0: static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){ michael@0: opus_int32 ret; michael@0: /* Nb will be counted in sub-macros*/ michael@0: ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16)); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_SMLAWW michael@0: static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){ michael@0: opus_int32 ret; michael@0: /* Nb will be counted in sub-macros*/ michael@0: ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16)); michael@0: return ret; michael@0: } michael@0: michael@0: #undef silk_min_int michael@0: static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) < (b)) ? (a) : (b)); michael@0: } michael@0: michael@0: #undef silk_min_16 michael@0: static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) < (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_min_32 michael@0: static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) < (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_min_64 michael@0: static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) < (b)) ? (a) : (b)); michael@0: } michael@0: michael@0: /* silk_min() versions with typecast in the function call */ michael@0: #undef silk_max_int michael@0: static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) > (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_max_16 michael@0: static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) > (b)) ? (a) : (b)); michael@0: } michael@0: #undef silk_max_32 michael@0: static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) > (b)) ? (a) : (b)); michael@0: } michael@0: michael@0: #undef silk_max_64 michael@0: static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b) michael@0: { michael@0: ops_count += 1; michael@0: return (((a) > (b)) ? (a) : (b)); michael@0: } michael@0: michael@0: michael@0: #undef silk_LIMIT_int michael@0: static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2) michael@0: { michael@0: opus_int ret; michael@0: ops_count += 6; michael@0: michael@0: ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ michael@0: : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); michael@0: michael@0: return(ret); michael@0: } michael@0: michael@0: #undef silk_LIMIT_16 michael@0: static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2) michael@0: { michael@0: opus_int16 ret; michael@0: ops_count += 6; michael@0: michael@0: ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ michael@0: : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); michael@0: michael@0: return(ret); michael@0: } michael@0: michael@0: michael@0: #undef silk_LIMIT_32 michael@0: static OPUS_INLINE opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2) michael@0: { michael@0: opus_int32 ret; michael@0: ops_count += 6; michael@0: michael@0: ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \ michael@0: : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a)))); michael@0: return(ret); michael@0: } michael@0: michael@0: #else michael@0: #define varDefine michael@0: #define silk_SaveCount() michael@0: michael@0: #endif michael@0: #endif michael@0: