diff --git a/lib_com/arith_coder_fx.c b/lib_com/arith_coder_fx.c index 7551bd41afff208bfcf26f1e5fc8787c63a736e4..55d7a3ec545c9e624da69913fcdb7cb382b42e7a 100644 --- a/lib_com/arith_coder_fx.c +++ b/lib_com/arith_coder_fx.c @@ -194,10 +194,12 @@ void tcx_arith_scale_envelope( Word16 statesi, bits; Word32 mean, a, s, L_tmp; Word16 mean_e, tmp, tmp2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif lob_bits = 0; @@ -223,8 +225,12 @@ void tcx_arith_scale_envelope( tmp = norm_l( env[k] ); tmp2 = sub( 15, tmp ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = Inv16( round_fx_sat( L_shl( env[k], tmp ) ), &tmp2 ); /* exp(tmp2) */ +#else tmp = Inv16( round_fx_o( L_shl_o( env[k], tmp, &Overflow ), &Overflow ), &tmp2 ); /* exp(tmp2) */ - ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ +#endif + ienv[k] = L_shl( L_deposit_h( tmp ), sub( tmp2, 15 ) ); /* Q16 */ move32(); mean = L_add( mean, ienv[k] ); /* Q16 */ } @@ -256,7 +262,11 @@ void tcx_arith_scale_envelope( b_e = add( b_e, mean_e ); /* scale = (-b + (float)sqrt(b*b - 4.0f*a*0.035f)) / (2.0f * a); */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = round_fx_sat( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ) ); +#else tmp = round_fx_o( BASOP_Util_Add_Mant32Exp( L_mult( b, b ), shl( b_e, 1 ), Mpy_32_16_1( a, -4588 /*-4.0f*0.035f Q15*/ ), a_e, &tmp2 ), &Overflow ); +#endif IF( tmp <= 0 ) { @@ -271,7 +281,7 @@ void tcx_arith_scale_envelope( tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); /* exp(scale) */ scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp ); -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom scale = shl_sat( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */ #else scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */ @@ -324,7 +334,11 @@ void tcx_arith_scale_envelope( L_tmp = L_add( L_tmp, L_shl( Mpy_32_16_1( env[k], mult_r( 1147 /*0.035f Q15*/, iscale ) ), iscale_e ) ); /* Q16 */ tmp = norm_l( L_tmp ); +#ifdef ISSUE_1836_replace_overflow_libcom + statesi = mult_r( statesi, round_fx_sat( L_shl( L_tmp, tmp ) ) ); +#else statesi = mult_r( statesi, round_fx_o( L_shl_o( L_tmp, tmp, &Overflow ), &Overflow ) ); +#endif bits = add( bits, sub( 15, tmp ) ); tmp = norm_s( statesi ); @@ -411,7 +425,11 @@ void tcx_arith_scale_envelope( *s_env_e = sub( add( 15, iscale_e ), tmp ); move16(); BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1836_replace_overflow_libcom + a = L_shl_sat( 1265000, sub( 15, *s_env_e ) ); +#else a = L_shl_o( 1265000, sub( 15, *s_env_e ), &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS; FOR( k = 0; k < L_frame; k++ ) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index bb92e286f399aa6f44d24ccab9abc17adb05ae18..2eaa904efa2bbc502bd92405b941b3c964ed9a2a 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -267,9 +267,11 @@ void BASOP_Util_Divide_MantExp( Word16 a_m, /*!< Mantissa of dividend a Word16 preShift, postShift; Word16 m; Word32 m32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif assert( b_m != 0 ); @@ -303,7 +305,11 @@ void BASOP_Util_Divide_MantExp( Word16 a_m, /*!< Mantissa of dividend a /* normalize result */ postShift = norm_l( m32 ); +#ifdef ISSUE_1836_replace_overflow_libcom + m = round_fx_sat( L_shl( m32, postShift ) ); +#else m = round_fx_o( L_shl( m32, postShift ), &Overflow ); +#endif /* exponent */ *ptrResult_e = sub( add( add( a_e, sub( 1, b_e ) ), preShift ), postShift ); @@ -319,7 +325,9 @@ static Word16 Sqrt16_common( Word16 m, Word16 e ) { Word16 index, frac; +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow; +#endif assert( ( m >= 0x4000 ) || ( m == 0 ) ); @@ -334,9 +342,13 @@ static Word16 Sqrt16_common( Word16 m, /* interpolate */ if ( m != 0 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + m = mac_r_sat( SqrtTable[index], SqrtDiffTable[index], frac ); +#else BASOP_SATURATE_WARNING_OFF_EVS; m = mac_ro( SqrtTable[index], SqrtDiffTable[index], frac, &Overflow ); BASOP_SATURATE_WARNING_ON_EVS; +#endif } /* handle odd exponents */ @@ -352,13 +364,19 @@ static Word32 Sqrt32_common( Word32 m, Word16 e ) { Word16 m16, index, frac; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif assert( ( m >= 0x40000000 ) || ( m == 0 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + m16 = round_fx_sat( m ); +#else m16 = round_fx_o( m, &Overflow ); +#endif /* get table index (upper 6 bits minus 32) */ /* index = (m16 >> 9) - 32; */ @@ -414,16 +432,23 @@ static Word32 ISqrt32_common( Word32 m, Word16 e ) { Word16 m16, index, frac; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif assert( m >= 0x40000000 ); +#ifdef ISSUE_1836_replace_overflow_libcom + m16 = round_fx_sat( m ); +#else #ifdef BASOP_NOGLOB_DECLARE_LOCAL m16 = round_fx_o( m, &Overflow ); #else m16 = round_fx( m ); #endif +#endif + /* get table index (upper 6 bits minus 32) */ /* index = (m16 >> 25) - 32; */ @@ -890,9 +915,11 @@ Word16 divide3232( Word32 L_num, Word32 L_denom ) { Word16 z; Word32 sign; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif sign = L_and( L_xor( L_num, L_denom ), (Word32) 0x80000000 ); @@ -906,7 +933,11 @@ Word16 divide3232( Word32 L_num, Word32 L_denom ) L_denom = L_shl( L_denom, z ); /* round_fx instead of extract_h improves spectral distortion in E_UTIL_lev_dur (schur version). */ +#ifdef ISSUE_1836_replace_overflow_libcom + z = div_l( L_num, round_fx_sat( L_denom ) ); +#else z = div_l( L_num, round_fx_o( L_denom, &Overflow ) ); +#endif if ( 0 != sign ) { z = negate( z ); @@ -2050,14 +2081,21 @@ Word32 norm_llQ31( /* o : normalized result Q31 */ Word16 i; Word32 L_tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow = 0; +#endif Flag Carry = 0; #endif /* BASOP_NOGLOB */ /* Move MSBit of L_sum into L_c */ Carry = 0; +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_add_c( L_sum, L_sum, &Carry ); /* L_tmp = L_sum << 1 */ + L_c = L_add_c( L_c, L_c, &Carry ); +#else L_tmp = L_add_co( L_sum, L_sum, &Carry, &Overflow ); /* L_tmp = L_sum << 1 */ L_c = L_add_co( L_c, L_c, &Carry, &Overflow ); +#endif L_add( 0, 0 ); test(); IF( ( L_c != (Word32) 0L ) && ( L_c != (Word32) 0xFFFFFFFFL ) ) diff --git a/lib_com/bitalloc_fx.c b/lib_com/bitalloc_fx.c index 3bb0cbd7294ce06710644dca1137a6b614730abe..2b630cf214185b387d08ef0c830e15e5b5c643db 100644 --- a/lib_com/bitalloc_fx.c +++ b/lib_com/bitalloc_fx.c @@ -23,9 +23,11 @@ void bitalloc_fx( Word16 diff, temp; Word16 fac; Word16 ii; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Word16 SFM_thr = SFM_G1G2; move16(); @@ -54,7 +56,11 @@ void bitalloc_fx( move16(); FOR( m = 1; m < im; m++ ) { - v = sub_o( temp, y[m], &Overflow ); /* Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + v = sub_sat( temp, y[m] ); /* Q0 */ +#else + v = sub_o( temp, y[m], &Overflow ); /* Q0 */ +#endif temp = s_max( temp, y[m] ); if ( v < 0 ) { @@ -245,7 +251,7 @@ Word16 BitAllocF_fx( Word16 tmp, exp1, exp2; Word32 Rsubband_w32_fx[NB_SFM]; /* Q15 */ Word16 B_w16_fx; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -444,7 +450,7 @@ Word16 BitAllocF_fx( exp1 = sub( norm_l( L_tmp2 ), 1 ); exp2 = norm_s( n ); tmp = div_s( extract_h( L_shl( L_tmp2, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/ -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom m_fx = shl_sat( tmp, sub( exp2, exp1 ) ); /*Q14*/ #else m_fx = shl_o( tmp, sub( exp2, exp1 ), &Overflow ); /*Q14*/ diff --git a/lib_com/cldfb_evs_fx.c b/lib_com/cldfb_evs_fx.c index 710ecf121251dfda9e387da641d629d451268a6d..153f95cf99aeabd50ca6eec2eaab3d0e39e30d8b 100644 --- a/lib_com/cldfb_evs_fx.c +++ b/lib_com/cldfb_evs_fx.c @@ -1240,9 +1240,11 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) Word32 energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 energyValuesSumE[CLDFB_NO_CHANNELS_MAX]; // Word16 freqTable[2] = {20, 40}; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FOR( k = 0; k < numberCols; k++ ) @@ -1329,8 +1331,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) { FOR( j = 20; j < numberBandsM; j++ ) { -#ifdef ISSUE_1799_replace_L_shr_o - nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + nrg = L_add_sat( nrg, L_shr_sat( energyValues[k][j], s ) ); #else nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); #endif @@ -1356,8 +1358,8 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead) { FOR( j = 20; j < numberBandsM; j++ ) { -#ifdef ISSUE_1799_replace_L_shr_o - nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + nrg = L_add_sat( nrg, L_shr_sat( energyValues[k][j], s ) ); #else nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); #endif diff --git a/lib_com/cldfb_fx.c b/lib_com/cldfb_fx.c index 43e94a068c21733308ee22a9fb93f83efe4ec201..00cb884d4ef1bdd41dc61acb426e1efd9cdb5a19 100644 --- a/lib_com/cldfb_fx.c +++ b/lib_com/cldfb_fx.c @@ -51,7 +51,6 @@ #define restrict #endif - /*-------------------------------------------------------------------* * Local prototypes *--------------------------------------------------------------------*/ @@ -1501,9 +1500,11 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e Word32 energyValues[CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; Word16 energyValuesSumE[CLDFB_NO_CHANNELS_MAX]; // Word16 freqTable[2] = {20, 40}; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FOR( k = 0; k < numberCols; k++ ) @@ -1590,8 +1591,8 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e { FOR( j = 20; j < numberBandsM; j++ ) { -#ifdef ISSUE_1799_replace_L_shr_o - nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + nrg = L_add_sat( nrg, L_shr_sat( energyValues[k][j], s ) ); #else nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); #endif @@ -1617,8 +1618,8 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e { FOR( j = 20; j < numberBandsM; j++ ) { -#ifdef ISSUE_1799_replace_L_shr_o - nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + nrg = L_add_sat( nrg, L_shr_sat( energyValues[k][j], s ) ); #else nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow ); #endif diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 00ce93218f4d3a5682d13d549729e3a5cb9e7445..6296b406c483787d1bfd899c90ff4ad3d9ae3d3d 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -615,9 +615,11 @@ void cng_params_postupd_fx( Word16 CNG_mode; Word16 ptr; Word32 last_active_brate; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif ptr = add( sub( ho_circ_ptr, *cng_buf_cnt ), 1 ); @@ -644,10 +646,16 @@ void cng_params_postupd_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_exc+1 */ +#else L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ @@ -725,9 +733,11 @@ void cng_params_postupd_ivas_fx( Word16 CNG_mode; Word16 ptr; Word32 last_active_brate; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif ptr = add( sub( ho_circ_ptr, *cng_buf_cnt ), 1 ); @@ -754,10 +764,16 @@ void cng_params_postupd_ivas_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_exc+1 */ +#else L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); // To do : Saturation to be re-validated. sp[i] = L_shr_sat( L_tmp, sub( tmp, 6 ) ); @@ -861,10 +877,12 @@ void cng_params_upd_fx( Word16 tmp; Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* update the pointer to circular buffer of old LSP vectors */ @@ -902,12 +920,14 @@ void cng_params_upd_fx( L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); - L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); pt_exc2++; -#ifdef ISSUE_1799_replace_L_shr_o - L_ener = L_add_o( L_ener, L_shr_sat( L_tmp, 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr_sat( L_tmp, 7 ) ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #else - L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); + pt_exc2++; + L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #endif } } @@ -919,16 +939,18 @@ void cng_params_upd_fx( L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); - L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); pt_exc2++; -#ifdef ISSUE_1799_replace_L_shr_o - L_ener = L_add_o( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #else + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); + pt_exc2++; L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #endif } } -#ifdef ISSUE_1799_replace_L_shr_o +#ifdef ISSUE_1836_replace_overflow_libcom L_ener = L_shr_sat( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #else L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ @@ -966,10 +988,16 @@ void cng_params_upd_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ - L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ - L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_exc+1 */ +#else + L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ +#endif + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr( L_tmp, sub( tmp, 6 ) ); move32(); /* Q6 */ @@ -1052,9 +1080,11 @@ void cng_params_upd_ivas_fx( move16(); Word16 temp_lo_fx, temp_hi_fx; Word16 exp_pow; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* update the pointer to circular buffer of old LSP vectors */ @@ -1092,12 +1122,14 @@ void cng_params_upd_ivas_fx( L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); - L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); pt_exc2++; -#ifdef ISSUE_1799_replace_L_shr_o - L_ener = L_add_o( L_ener, L_shr_sat( L_tmp, 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr_sat( L_tmp, 7 ) ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #else - L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); + pt_exc2++; + L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */ #endif } } @@ -1109,16 +1141,18 @@ void cng_params_upd_ivas_fx( L_tmp = L_mult0( tmpv, tmpv ); /* 2*(Q_exc+scale) */ pt_exc2++; tmpv = shl( *pt_exc2, scale ); - L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac0_sat( L_tmp, tmpv, tmpv ); pt_exc2++; -#ifdef ISSUE_1799_replace_L_shr_o - L_ener = L_add_o( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ + L_ener = L_add_sat( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ) ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #else + L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow ); + pt_exc2++; L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */ #endif } } -#ifdef ISSUE_1799_replace_L_shr_o +#ifdef ISSUE_1836_replace_overflow_libcom L_ener = L_shr_sat( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ #else L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */ @@ -1156,14 +1190,19 @@ void cng_params_upd_ivas_fx( FOR( i = 0; i < NUM_ENV_CNG; i++ ) { /* sp[i] = 2.0f*(*ptR * *ptR + *ptI * *ptI)/L_FFT; */ - L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ - L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ - L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( *ptR, *ptR ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_mult_sat( *ptI, *ptI ) ); /* 2*Q_exc+1 */ + L_tmp = L_add_sat( L_tmp, L_tmp ); /* 2*Q_exc+1 */ + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ tmp = add( add( Q_exc, Q_exc ), 1 ); -#ifdef ISSUE_1799_replace_L_shr_o sp[i] = L_shr_sat( L_tmp, sub( tmp, 6 ) ); #else + L_tmp = L_mult_o( *ptR, *ptR, &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_mult_o( *ptI, *ptI, &Overflow ), &Overflow ); /* 2*Q_exc+1 */ + L_tmp = L_add_o( L_tmp, L_tmp, &Overflow ); /* 2*Q_exc+1 */ + L_tmp = Mult_32_16( L_tmp, 128 ); /* 2*Q_exc+1 */ + tmp = add( add( Q_exc, Q_exc ), 1 ); sp[i] = L_shr_o( L_tmp, sub( tmp, 6 ), &Overflow ); #endif move32(); /* Q6 */ diff --git a/lib_com/codec_tcx_common_fx.c b/lib_com/codec_tcx_common_fx.c index 683e1e8d4ce0eac9b7dac17d6706afcda75c25bf..010590ad176ff7f53348a5bd3a763d4b0d9fc55b 100644 --- a/lib_com/codec_tcx_common_fx.c +++ b/lib_com/codec_tcx_common_fx.c @@ -61,7 +61,7 @@ void tcxFormantEnhancement( Word16 i, j, k, l, n; Word16 fac, fac0, fac1, fac_e, d, tmp; Word16 xn_buf_e, xn_one, m, e; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -141,7 +141,7 @@ void tcxFormantEnhancement( { fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); #else xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); @@ -233,7 +233,7 @@ void tcxFormantEnhancement_with_shift( Word16 i, j, k, l, n; Word16 fac, fac0, fac1, fac_e, d, tmp; Word16 xn_buf_e, xn_one, m, e; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -317,7 +317,7 @@ void tcxFormantEnhancement_with_shift( { fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); #else xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); @@ -366,7 +366,7 @@ void tcxFormantEnhancement_with_shift( { fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) ); BASOP_SATURATE_WARNING_OFF_EVS; -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) ); #else xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) ); diff --git a/lib_com/deemph_fx.c b/lib_com/deemph_fx.c index 9516202c15d3e7bf264a578ae8a48b74fe755a4c..27d823a74f888a149be610725a7bc1dcfe6d6aa3 100644 --- a/lib_com/deemph_fx.c +++ b/lib_com/deemph_fx.c @@ -39,7 +39,6 @@ #include "prot_fx.h" #include "wmc_auto.h" - void deemph_fx_32( Word32 *signal, /* i/o: signal Qx*/ const Word16 mu, /* i : deemphasis factor Q15*/ @@ -93,22 +92,34 @@ void deemph_fx( { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow; Overflow = 0; move32(); #endif - L_tmp = L_deposit_h( signal[0] ); /*Qx+16*/ L_tmp = L_mac_o( L_tmp, *mem, mu, &Overflow ); /*Qx+16*/ signal[0] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ +#else + L_tmp = L_deposit_h( signal[0] ); /*Qx+16*/ + L_tmp = L_mac_sat( L_tmp, *mem, mu ); /*Qx+16*/ + signal[0] = round_fx_sat( L_tmp ); /*Qx*/ +#endif + + move16(); FOR( i = 1; i < L; i++ ) { - L_tmp = L_deposit_h( signal[i] ); /*Qx+16*/ - L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); /*Qx+16*/ - signal[i] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ + L_tmp = L_deposit_h( signal[i] ); /*Qx+16*/ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac_sat( L_tmp, signal[i - 1], mu ); /*Qx+16*/ + signal[i] = round_fx_sat( L_tmp ); /*Qx*/ +#else + L_tmp = L_mac_o( L_tmp, signal[i - 1], mu, &Overflow ); /*Qx+16*/ + signal[i] = round_fx_o( L_tmp, &Overflow ); /*Qx*/ +#endif move16(); } @@ -131,10 +142,12 @@ void Deemph2( { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow; Overflow = 0; move32(); +#endif #endif /* saturation can occur in L_mac() */ @@ -144,8 +157,12 @@ void Deemph2( FOR( i = 1; i < L; i++ ) { - L_tmp = L_mult( x[i], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ - x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); /*Qx-1*/ + L_tmp = L_mult( x[i], 16384 /*0.5f in Q15*/ ); /*Qx+16*/ +#ifdef ISSUE_1836_replace_overflow_libcom + x[i] = mac_r_sat( L_tmp, x[i - 1], mu ); /*Qx-1*/ +#else + x[i] = mac_ro( L_tmp, x[i - 1], mu, &Overflow ); /*Qx-1*/ +#endif move16(); } @@ -175,10 +192,12 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow; Overflow = 0; move32(); +#endif #endif /* signal[0] = signal[0] + mu * (*mem); */ @@ -188,8 +207,13 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W shift = shr( -32768, shift ); /*Q15 - shift*/ FOR( i = 0; i < L; i++ ) { - L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); /*Qx-shift+16*/ - x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_msu_sat( Mpy_32_16_1( L_tmp, mu ), x[i], shift ); /*Qx-shift+16*/ + x[i] = round_fx_sat( L_tmp ); /*Qx-shift*/ +#else + L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), x[i], shift, &Overflow ); /*Qx-shift+16*/ + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#endif move16(); } } @@ -197,8 +221,13 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W { FOR( i = 0; i < L; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_msu_sat( Mpy_32_16_1( L_tmp, mu ), shr_sat( x[i], shift ), -32768 /*1.0f in Q15*/ ); /*Qx-shift+16*/ + x[i] = round_fx_sat( L_tmp ); /*Qx-shift*/ +#else L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_sat( x[i], shift ), -32768 /*1.0f in Q15*/, &Overflow ); /*Qx-shift+16*/ x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#endif move16(); } } diff --git a/lib_com/edct_fx.c b/lib_com/edct_fx.c index c30ed4a57c1bdfd74e2a6ea43449b5e8bddcd4aa..244d693819fab6a1a3d9c4e2d9087abfaa733a70 100644 --- a/lib_com/edct_fx.c +++ b/lib_com/edct_fx.c @@ -13,7 +13,6 @@ #include "math_32.h" - static Word16 get_edxt_factor( Word16 length ) /* Returns value of sqrtf(2.f/length) in Q15 */ { Word16 factor; /*Q15*/ @@ -396,10 +395,12 @@ void edct_16fx( const Word16 *px, *pt; Word16 *py; (void) element_mode; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow; Overflow = 0; move32(); +#endif #endif /*COMPLETE: some eDCT sub function are missing */ @@ -455,13 +456,22 @@ void edct_16fx( { i2 = shl( i, 1 ); - L_tmp = L_mult( x[i2], edct_table[i] ); /*Q(Qx+16) */ + L_tmp = L_mult( x[i2], edct_table[i] ); /*Q(Qx+16) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( L_tmp, *px, *pt ); /*Q(Qx+16) */ + re2[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ + move16(); + L_tmp = L_mult( *px, edct_table[i] ); /*Q(Qx+16) */ + Lacc = L_msu_sat( L_tmp, x[i2], *pt ); /*Q(Qx+16) */ + im2[i] = round_fx_sat( L_shl_sat( Lacc, Q_edct ) ); /* Q(Qx+Q_edct) */ +#else Lacc = L_mac_o( L_tmp, *px, *pt, &Overflow ); /*Q(Qx+16) */ re2[i] = round_fx_o( L_shl_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ move16(); L_tmp = L_mult( *px, edct_table[i] ); /*Q(Qx+16) */ Lacc = L_msu_o( L_tmp, x[i2], *pt, &Overflow ); /*Q(Qx+16) */ im2[i] = round_fx_o( L_shl_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx+Q_edct) */ +#endif move16(); px -= 2; pt--; @@ -486,12 +496,20 @@ void edct_16fx( fact = round_fx( L_shl( L_tmp, 2 ) ); /*Q15 */ FOR( i = 0; i < shr( length, 1 ); i++ ) { - tmp = mult_r( im2[i], fact ); /*Q(Qx+Q_edct) */ - re[i] = sub_o( re2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ + tmp = mult_r( im2[i], fact ); /*Q(Qx+Q_edct) */ +#ifdef ISSUE_1836_replace_overflow_libcom + re[i] = sub_sat( re2[i], tmp ); /*Q(Qx+Q_edct) */ +#else + re[i] = sub_o( re2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ +#endif move16(); - tmp = mult_r( re2[i], fact ); /*Q(Qx+Q_edct) */ - im[i] = add_o( im2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ + tmp = mult_r( re2[i], fact ); /*Q(Qx+Q_edct) */ +#ifdef ISSUE_1836_replace_overflow_libcom + im[i] = add_sat( im2[i], tmp ); /*Q(Qx+Q_edct) */ +#else + im[i] = add_o( im2[i], tmp, &Overflow ); /*Q(Qx+Q_edct) */ +#endif move16(); } @@ -502,21 +520,23 @@ void edct_16fx( { i2 = shl( i, 1 ); - L_tmp = L_mult( re[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ - Lacc = L_mac_o( L_tmp, im[i], *pt, &Overflow ); /*Q(Qx+Q_edct+16) */ -#ifdef ISSUE_1799_replace_L_shr_o - y[i2] = round_fx_o( L_shr_sat( Lacc, Q_edct ), &Overflow ); /* Q(Qx) */ -#else - y[i2] = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ -#endif + L_tmp = L_mult( re[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( L_tmp, im[i], *pt ); /*Q(Qx+Q_edct+16) */ + y[i2] = round_fx_sat( L_shr_sat( Lacc, Q_edct ) ); /* Q(Qx) */ move16(); L_tmp = L_mult( re[i], edct_table[sub( shr( length, 1 ), add( 1, i ) )] ); /*Q(Qx+Q_edct+16) */ Lacc = L_msu( L_tmp, im[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ -#ifdef ISSUE_1799_replace_L_shr_o - *py = round_fx_o( L_shr_sat( Lacc, Q_edct ), &Overflow ); /* Q(Qx) */ + *py = round_fx_sat( L_shr_sat( Lacc, Q_edct ) ); /* Q(Qx) */ #else - *py = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ + Lacc = L_mac_o( L_tmp, im[i], *pt, &Overflow ); /*Q(Qx+Q_edct+16) */ + y[i2] = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ + move16(); + + L_tmp = L_mult( re[i], edct_table[sub( shr( length, 1 ), add( 1, i ) )] ); /*Q(Qx+Q_edct+16) */ + Lacc = L_msu( L_tmp, im[i], edct_table[i] ); /*Q(Qx+Q_edct+16) */ + *py = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */ #endif move16(); diff --git a/lib_com/env_stab_fx.c b/lib_com/env_stab_fx.c index a3140b4e498beb79ffa011af6baa60bbeb0a2bad..50a15c5fe026e374f3ef3c825d93ea8ab560f74e 100644 --- a/lib_com/env_stab_fx.c +++ b/lib_com/env_stab_fx.c @@ -43,6 +43,7 @@ #include "rom_com.h" #include "wmc_auto.h" #include "stl.h" + /*--------------------------------------------------------------------------* * Local constants *--------------------------------------------------------------------------*/ @@ -187,9 +188,11 @@ Word16 env_stab_smo_fx( /* Q0 */ Word16 maxval, pp[NUM_ENV_STAB_PLC_STATES], pa[NUM_ENV_STAB_PLC_STATES]; Word16 i; Word16 tmp, sum, exp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* get previous state */ prev_state = maximum_fx( env_stab_state_p, NUM_ENV_STAB_PLC_STATES, &maxval ); @@ -226,7 +229,11 @@ Word16 env_stab_smo_fx( /* Q0 */ /*tmp = shl(tmp, add(exp, 1));*/ /* Q15 */ FOR( i = 0; i < NUM_ENV_STAB_PLC_STATES; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + env_stab_state_p[i] = round_fx_sat( L_shl_sat( L_mult_sat( env_stab_state_p[i], tmp ), add( exp, 1 ) ) ); /* Q15 */ +#else env_stab_state_p[i] = round_fx_o( L_shl_o( L_mult_o( env_stab_state_p[i], tmp, &Overflow ), add( exp, 1 ), &Overflow ), &Overflow ); /* Q15 */ +#endif move16(); } diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 7420a4457750209c4fca63cd8fcab712dcc819f7..6666f90914e42399d122a720c02380831add9e2c 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -21,6 +21,7 @@ #define CNG_HS 4 /* 4 bit headroom for dot product */ #define CNG_S 6 /* 1 sign bit, 6 bit integer part, 9 bit frational part for input and output data */ + /*------------------------------------------------------------------- * Local function prototypes *-------------------------------------------------------------------*/ @@ -647,11 +648,12 @@ void minimum_statistics( Word16 msAlphaCorAlpha2; Word16 msPeriodogSum16; Word16 msNoiseFloor16; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif - +#endif len2 = i_mult( MSNUMSUBFR, len ); @@ -750,7 +752,11 @@ void minimum_statistics( /* use absolute value to avoid -1.0 x -1.0 multiplications */ s2 = norm_l( scalar2 ); } +#ifdef ISSUE_1836_replace_overflow_libcom + scalar216 = round_fx_sat( L_shl( scalar2, s2 ) ); +#else scalar216 = round_fx_o( L_shl_o( scalar2, s2, &Overflow ), &Overflow ); +#endif scalar2 = L_mult( scalar216, scalar216 ); /* find common exponent */ @@ -900,7 +906,11 @@ void minimum_statistics( s2 = s_min( s2, WORD32_BITS - 1 ); /* beta: scaled by s2 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp16 = round_fx_sat( L_shl( tmp, s1 ) ); +#else tmp16 = round_fx_o( L_shl_o( tmp, s1, &Overflow ), &Overflow ); +#endif beta = mult_r( tmp16, tmp16 ); /* scalar3: scaled by s3 */ @@ -988,8 +998,13 @@ void minimum_statistics( move32(); /* exponent msCurrentMinSubWindow[j]: CNG_S */ BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1836_replace_overflow_libcom + msCurrentMinSubWindow[j] = L_shl_sat( Mpy_32_32( scalar, msBminSubWin[j] ), 5 ); + move32(); +#else msCurrentMinSubWindow[j] = L_shl_o( Mpy_32_32( scalar, msBminSubWin[j] ), 5, &Overflow ); move32(); +#endif BASOP_SATURATE_WARNING_ON_EVS; } } @@ -1246,10 +1261,12 @@ void minimum_statistics_fx( Word16 msAlphaCorAlpha2; Word16 msPeriodogSum16; Word16 msNoiseFloor16; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif len2 = i_mult( MSNUMSUBFR, len ); @@ -1349,7 +1366,11 @@ void minimum_statistics_fx( /* use absolute value to avoid -1.0 x -1.0 multiplications */ s2 = norm_l( scalar2 ); } +#ifdef ISSUE_1836_replace_overflow_libcom + scalar216 = round_fx_sat( L_shl( scalar2, s2 ) ); +#else scalar216 = round_fx_o( L_shl_o( scalar2, s2, &Overflow ), &Overflow ); +#endif scalar2 = L_mult( scalar216, scalar216 ); /* find common exponent */ @@ -1506,7 +1527,11 @@ void minimum_statistics_fx( s2 = s_min( s2, WORD32_BITS - 1 ); /* beta: scaled by s2 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp16 = round_fx_sat( L_shl( tmp, s1 ) ); +#else tmp16 = round_fx_o( L_shl_o( tmp, s1, &Overflow ), &Overflow ); +#endif beta = mult_r( tmp16, tmp16 ); /* scalar3: scaled by s3 */ @@ -1594,7 +1619,11 @@ void minimum_statistics_fx( move32(); /* exponent msCurrentMinSubWindow[j]: CNG_S */ BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1836_replace_overflow_libcom + msCurrentMinSubWindow[j] = L_shl_sat( Mpy_32_32( scalar, msBminSubWin[j] ), 5 ); +#else msCurrentMinSubWindow[j] = L_shl_o( Mpy_32_32( scalar, msBminSubWin[j] ), 5, &Overflow ); +#endif move32(); BASOP_SATURATE_WARNING_ON_EVS; } @@ -2279,7 +2308,7 @@ static void getmidbands( ) { Word16 j, max_psize, shift; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -2318,7 +2347,7 @@ static void getmidbands( move16(); FOR( j = 0; j < npart; j++ ) { -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom psize_norm[j] = shl_sat( psize[j], shift ); // Q(15 - psize_norm_exp) #else psize_norm[j] = shl_o( psize[j], shift, &Overflow ); // Q(15 - psize_norm_exp) diff --git a/lib_com/fft_fx_evs.c b/lib_com/fft_fx_evs.c index b6f2bb2acee04e556e60e2a0cd36c85d7c81763d..6572b57d7e7313a6d4986ba7175a88f30c6a25d6 100644 --- a/lib_com/fft_fx_evs.c +++ b/lib_com/fft_fx_evs.c @@ -1186,9 +1186,11 @@ static void fft5_32_16fx( Word16 T1, To, T8, Tt, T9, Ts, Te, Tp, Th, Tn, T2, T3, T4, T5, T6, T7; Word16 i0, i1, i2, i3, i4; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif i0 = Idx[0]; move16(); @@ -1216,9 +1218,15 @@ static void fft5_32_16fx( move16(); T6 = zRe[i3]; move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + T7 = add_sat( T5, T6 ); //??sat + T8 = add_sat( T4, T7 ); //??sat + Tt = sub_sat( T5, T6 ); //??sat +#else T7 = add_o( T5, T6, &Overflow ); T8 = add_o( T4, T7, &Overflow ); Tt = sub_o( T5, T6, &Overflow ); +#endif /* T9 = KP559016994 * (T4 - T7); */ L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) T9 = round_fx_sat( L_tmp ); // Qx @@ -1240,11 +1248,17 @@ static void fft5_32_16fx( L_tmp = Mult_32_16( KP559016994_16FX, sub_sat( T4, T7 ) ); // Q(16 +x) Tn = round_fx_sat( L_tmp ); // Qx - +#ifdef ISSUE_1836_replace_overflow_libcom + zRe[i0] = add_sat( T1, T8 ); //??sat + move16(); + zIm[i0] = add_sat( To, Tp ); //??sat + move32(); +#else zRe[i0] = add_o( T1, T8, &Overflow ); move16(); zIm[i0] = add_o( To, Tp, &Overflow ); move32(); +#endif /*T2 = KP951056516*Te + KP587785252*Th; */ L_tmp = Mult_32_16( KP951056516_16FX, Te ); // Q(16 +x) @@ -1261,6 +1275,16 @@ static void fft5_32_16fx( T4 = add_sat( T9, T6 ); T5 = sub_sat( T6, T9 ); +#ifdef ISSUE_1836_replace_overflow_libcom + zRe[i3] = sub_sat( T4, T2 ); //??sat + move32(); + zRe[i1] = add_sat( T5, T3 ); //??sat + move32(); + zRe[i2] = add_sat( T4, T2 ); //??sat + move32(); + zRe[i4] = sub_sat( T5, T3 ); //??sat + move32(); +#else zRe[i3] = sub_o( T4, T2, &Overflow ); move32(); zRe[i1] = add_o( T5, T3, &Overflow ); @@ -1269,6 +1293,7 @@ static void fft5_32_16fx( move32(); zRe[i4] = sub_o( T5, T3, &Overflow ); move32(); +#endif /* T2 = KP951056516 * Ts + KP587785252 * Tt; */ L_tmp = Mult_32_16( KP951056516_16FX, Ts ); // Q(16 +x) @@ -1675,9 +1700,11 @@ static void cftfsub_16fx( { Word16 j, j1, j2, j3, l; Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif l = 2; @@ -1731,6 +1758,15 @@ static void cftfsub_16fx( { FOR( j = 0; j < l; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + j1 = add_sat( j, l ); //??sat + x0r = sub_sat( a[j], a[j1] ); //??sat + x0i = sub_sat( a[j + 1], a[j1 + 1] ); //??sat + a[j] = add_sat( a[j], a[j1] ); //??sat + move16(); + a[j + 1] = add_sat( a[j + 1], a[j1 + 1] ); //??sat + move16(); +#else j1 = add_o( j, l, &Overflow ); x0r = sub_o( a[j], a[j1], &Overflow ); x0i = sub_o( a[j + 1], a[j1 + 1], &Overflow ); @@ -1738,6 +1774,7 @@ static void cftfsub_16fx( move16(); a[j + 1] = add_o( a[j + 1], a[j1 + 1], &Overflow ); move16(); +#endif a[j1] = x0r; move16(); a[j1 + 1] = x0i; @@ -1762,11 +1799,84 @@ static void cft1st_16fx( Word16 x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; Word16 tmp; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif + +#ifdef ISSUE_1836_replace_overflow_libcom + x0r = add_sat( a[0], a[2] ); //??sat + x0i = add_sat( a[1], a[3] ); //??sat + x1r = sub_sat( a[0], a[2] ); //??sat + x1i = sub_sat( a[1], a[3] ); //??sat + x2r = add_sat( a[4], a[6] ); //??sat + x2i = add_sat( a[5], a[7] ); //??sat + x3r = sub_sat( a[4], a[6] ); //??sat + x3i = sub_sat( a[5], a[7] ); //??sat + a[0] = add_sat( x0r, x2r ); //??sat + move16(); + a[1] = add_sat( x0i, x2i ); //??sat + move16(); + a[4] = sub_sat( x0r, x2r ); //??sat + move16(); + a[5] = sub_sat( x0i, x2i ); //??sat + move16(); + a[2] = sub_sat( x1r, x3i ); //??sat + move16(); + a[3] = add_sat( x1i, x3r ); //??sat + move16(); + a[6] = add_sat( x1r, x3i ); //??sat + move16(); + a[7] = sub_sat( x1i, x3r ); //??sat + wk1r = w[2]; + move32(); + x0r = add_sat( a[8], a[10] ); //??sat + x0i = add_sat( a[9], a[11] ); //??sat + x1r = sub_sat( a[8], a[10] ); //??sat + x1i = sub_sat( a[9], a[11] ); //??sat + x2r = add_sat( a[12], a[14] ); //??sat + x2i = add_sat( a[13], a[15] ); //??sat + x3r = sub_sat( a[12], a[14] ); //??sat + x3i = sub_sat( a[13], a[15] ); //??sat + a[8] = add_sat( x0r, x2r ); //??sat + move16(); + a[9] = add_sat( x0i, x2i ); //??sat + move16(); + a[12] = sub_sat( x2i, x0i ); //??sat + move16(); + a[13] = sub_sat( x0r, x2r ); //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); //??sat + x0i = add_sat( x1i, x3r ); //??sat + tmp = sub_sat( x0r, x0i ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + + a[10] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = add_sat( x0r, x0i ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ //??sat + a[11] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /* Q(Qx+Q_edct)*/ //??sat + move16(); + + x0r = add_sat( x3i, x1r ); //??sat + x0i = sub_sat( x3r, x1i ); //??sat + tmp = sub_sat( x0i, x0r ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ //??sat + a[14] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = add_sat( x0i, x0r ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[15] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + k1 = 0; + move16(); +#else x0r = add_o( a[0], a[2], &Overflow ); x0i = add_o( a[1], a[3], &Overflow ); x1r = sub_o( a[0], a[2], &Overflow ); @@ -1836,6 +1946,7 @@ static void cft1st_16fx( move16(); k1 = 0; move16(); +#endif FOR( j = 16; j < n; j += 16 ) { @@ -1856,6 +1967,118 @@ static void cft1st_16fx( L_tmp = L_shl( Mult_32_32( wk2i, wk1r ), 1 ); /*Q29 */ wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ +#ifdef ISSUE_1836_replace_overflow_libcom + x0r = add_sat( a[j], a[j + 2] ); //??sat + x0i = add_sat( a[j + 1], a[j + 3] ); //??sat + x1r = sub_sat( a[j], a[j + 2] ); //??sat + x1i = sub_sat( a[j + 1], a[j + 3] ); //??sat + x2r = add_sat( a[j + 4], a[j + 6] ); //??sat + x2i = add_sat( a[j + 5], a[j + 7] ); //??sat + x3r = sub_sat( a[j + 4], a[j + 6] ); //??sat + x3i = sub_sat( a[j + 5], a[j + 7] ); //??sat + a[j] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 1] = add_sat( x0i, x2i ); //??sat + move16(); + + x0r = sub_sat( x0r, x2r ); //??sat + x0i = sub_sat( x0i, x2i ); //??sat + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 4] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 5] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); + x0i = add_sat( x1i, x3r ); + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 2] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 3] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = add_sat( x1r, x3i ); + x0i = sub_sat( x1i, x3r ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 6] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 7] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + wk1r = w[k2 + 2]; + move32(); + wk1i = w[k2 + 3]; + move32(); + L_tmp = L_shl( Mult_32_32( wk2r, wk1i ), 1 ); /*Q29 */ + wk3r = L_sub( wk1r, L_shl( L_tmp, 1 ) ); /*Q30 */ + + L_tmp = L_shl( Mult_32_32( wk2r, wk1r ), 1 ); /*Q29 */ + wk3i = L_sub( L_shl( L_tmp, 1 ), wk1i ); /*Q30 */ + + x0r = add_sat( a[j + 8], a[j + 10] ); //??sat + x0i = add_sat( a[j + 9], a[j + 11] ); //??sat + x1r = sub_sat( a[j + 8], a[j + 10] ); //??sat + x1i = sub_sat( a[j + 9], a[j + 11] ); //??sat + x2r = add_sat( a[j + 12], a[j + 14] ); //??sat + x2i = add_sat( a[j + 13], a[j + 15] ); //??sat + x3r = sub_sat( a[j + 12], a[j + 14] ); //??sat + x3i = sub_sat( a[j + 13], a[j + 15] ); //??sat + a[j + 8] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 9] = add_sat( x0i, x2i ); //??sat + move16(); + + x0r = sub_sat( x0r, x2r ); //??sat + x0i = sub_sat( x0i, x2i ); //??sat + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 12] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 13] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); //??sat + x0i = add_sat( x1i, x3r ); //??sat + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 10] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 11] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = add_sat( x1r, x3i ); //??sat + x0i = sub_sat( x1i, x3r ); //??sat + + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j + 14] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j + 15] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); +#else x0r = add_o( a[j], a[j + 2], &Overflow ); x0i = add_o( a[j + 1], a[j + 3], &Overflow ); x1r = sub_o( a[j], a[j + 2], &Overflow ); @@ -1966,6 +2189,7 @@ static void cft1st_16fx( L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j + 15] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ move16(); +#endif } return; @@ -1988,13 +2212,44 @@ static void cftmdl_16fx( Word16 tmp, tmp2; Word32 L_tmp; Word32 L_x0r, L_x0i; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif m = shl( l, 2 ); FOR( j = 0; j < l; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + j1 = add_sat( j, l ); //??sat + j2 = add_sat( j1, l ); //??sat + j3 = add_sat( j2, l ); //??sat + x0r = add_sat( a[j], a[j1] ); //??sat + x0i = add_sat( a[j + 1], a[j1 + 1] ); //??sat + x1r = sub_sat( a[j], a[j1] ); //??sat + x1i = sub_sat( a[j + 1], a[j1 + 1] ); //??sat + x2r = add_sat( a[j2], a[j3] ); //??sat + x2i = add_sat( a[j2 + 1], a[j3 + 1] ); //??sat + x3r = sub_sat( a[j2], a[j3] ); //??sat + x3i = sub_sat( a[j2 + 1], a[j3 + 1] ); //??sat + a[j] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 1] = add_sat( x0i, x2i ); //??sat + move16(); + a[j2] = sub_sat( x0r, x2r ); //??sat + move16(); + a[j2 + 1] = sub_sat( x0i, x2i ); //??sat + move16(); + a[j1] = sub_sat( x1r, x3i ); //??sat + move16(); + a[j1 + 1] = add_sat( x1i, x3r ); //??sat + move16(); + a[j3] = add_sat( x1r, x3i ); //??sat + move16(); + a[j3 + 1] = sub_sat( x1i, x3r ); //??sat + move16(); +#else j1 = add_o( j, l, &Overflow ); j2 = add_o( j1, l, &Overflow ); j3 = add_o( j2, l, &Overflow ); @@ -2022,6 +2277,7 @@ static void cftmdl_16fx( move16(); a[j3 + 1] = sub_o( x1i, x3r, &Overflow ); move16(); +#endif } wk1r = w[2]; @@ -2029,6 +2285,51 @@ static void cftmdl_16fx( tmp2 = add( l, m ); FOR( j = m; j < tmp2; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + j1 = add_sat( j, l ); //??sat + j2 = add_sat( j1, l ); //??sat + j3 = add_sat( j2, l ); //??sat + x0r = add_sat( a[j], a[j1] ); //??sat + x0i = add_sat( a[j + 1], a[j1 + 1] ); //??sat + x1r = sub_sat( a[j], a[j1] ); //??sat + x1i = sub_sat( a[j + 1], a[j1 + 1] ); //??sat + x2r = add_sat( a[j2], a[j3] ); //??sat + x2i = add_sat( a[j2 + 1], a[j3 + 1] ); //??sat + x3r = sub_sat( a[j2], a[j3] ); //??sat + x3i = sub_sat( a[j2 + 1], a[j3 + 1] ); //??sat + a[j] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 1] = add_sat( x0i, x2i ); //??sat + move16(); + a[j2] = sub_sat( x2i, x0i ); //??sat + move16(); + a[j2 + 1] = sub_sat( x0r, x2r ); //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); //??sat + x0i = add_sat( x1i, x3r ); //??sat + tmp = sub_sat( x0r, x0i ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = add_sat( x0r, x0i ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = add_sat( x3i, x1r ); //??sat + x0i = sub_sat( x3r, x1i ); //??sat + tmp = sub_sat( x0i, x0r ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = add_sat( x0i, x0r ); //??sat + L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); +#else j1 = add_o( j, l, &Overflow ); j2 = add_o( j1, l, &Overflow ); j3 = add_o( j2, l, &Overflow ); @@ -2072,6 +2373,7 @@ static void cftmdl_16fx( L_tmp = Mult_32_16( wk1r, tmp ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ move16(); +#endif } k1 = 0; @@ -2098,6 +2400,63 @@ static void cftmdl_16fx( tmp2 = add( l, k ); FOR( j = k; j < tmp2; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + j1 = add_sat( j, l ); //??sat + j2 = add_sat( j1, l ); //??sat + j3 = add_sat( j2, l ); //??sat + x0r = add_sat( a[j], a[j1] ); //??sat + x0i = add_sat( a[j + 1], a[j1 + 1] ); //??sat + x1r = sub_sat( a[j], a[j1] ); //??sat + x1i = sub_sat( a[j + 1], a[j1 + 1] ); //??sat + x2r = add_sat( a[j2], a[j3] ); //??sat + x2i = add_sat( a[j2 + 1], a[j3 + 1] ); //??sat + x3r = sub_sat( a[j2], a[j3] ); //??sat + x3i = sub_sat( a[j2 + 1], a[j3 + 1] ); //??sat + a[j] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 1] = add_sat( x0i, x2i ); //??sat + move16(); + + x0r = sub_sat( x0r, x2r ); //??sat + x0i = sub_sat( x0i, x2i ); //??sat + + L_tmp = Mult_32_16( wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); //??sat + x0i = add_sat( x1i, x3r ); //??sat + + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_x0r = L_add( (Word32) x1r, (Word32) x3i ); + L_x0i = L_sub( (Word32) x1i, (Word32) x3r ); + x0r = extract_l( L_x0r ); + x0i = extract_l( L_x0i ); + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); +#else j1 = add_o( j, l, &Overflow ); j2 = add_o( j1, l, &Overflow ); j3 = add_o( j2, l, &Overflow ); @@ -2153,20 +2512,88 @@ static void cftmdl_16fx( L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ move16(); +#endif } wk1r = w[k2 + 2]; move32(); wk1i = w[k2 + 3]; move32(); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( Mult_32_32( wk2r, wk1i ), 1 ); /*Q29 */ //??sat + wk3r = L_sub_sat( wk1r, L_shl_sat( L_tmp, 1 ) ); /*Q30 */ //??sat + + L_tmp = L_shl_sat( Mult_32_32( wk2r, wk1r ), 1 ); /*Q29 */ //??sat + wk3i = L_sub_sat( L_shl_sat( L_tmp, 1 ), wk1i ); /*Q30 */ //??sat + tmp2 = add( l, add( k, m ) ); +#else L_tmp = L_shl_o( Mult_32_32( wk2r, wk1i ), 1, &Overflow ); /*Q29 */ wk3r = L_sub_o( wk1r, L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q30 */ L_tmp = L_shl_o( Mult_32_32( wk2r, wk1r ), 1, &Overflow ); /*Q29 */ wk3i = L_sub_o( L_shl_o( L_tmp, 1, &Overflow ), wk1i, &Overflow ); /*Q30 */ tmp2 = add( l, add( k, m ) ); +#endif FOR( j = add( k, m ); j < tmp2; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + j1 = add_sat( j, l ); //??sat + j2 = add_sat( j1, l ); //??sat + j3 = add_sat( j2, l ); //??sat + x0r = add_sat( a[j], a[j1] ); //??sat + x0i = add_sat( a[j + 1], a[j1 + 1] ); //??sat + x1r = sub_sat( a[j], a[j1] ); //??sat + x1i = sub_sat( a[j + 1], a[j1 + 1] ); //??sat + x2r = add_sat( a[j2], a[j3] ); //??sat + x2i = add_sat( a[j2 + 1], a[j3 + 1] ); //??sat + x3r = sub_sat( a[j2], a[j3] ); //??sat + x3i = sub_sat( a[j2 + 1], a[j3 + 1] ); //??sat + a[j] = add_sat( x0r, x2r ); //??sat + move16(); + a[j + 1] = add_sat( x0i, x2i ); //??sat + move16(); + + x0r = sub_sat( x0r, x2r ); //??sat + x0i = sub_sat( x0i, x2i ); //??sat + + tmp = negate( x0r ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk2r, x0i ); /*Q(15+Qx+Q_edct) */ + a[j2] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + tmp = negate( x0i ); + L_tmp = Mult_32_16( wk2i, tmp ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk2r, x0r ); /*Q(15+Qx+Q_edct) */ + a[j2 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = sub_sat( x1r, x3i ); //??sat + x0i = add_sat( x1i, x3r ); //??sat + + L_tmp = Mult_32_16( wk1r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk1i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk1r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk1i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j1 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + x0r = add_sat( x1r, x3i ); //??sat + x0i = sub_sat( x1i, x3r ); //??sat + + L_tmp = Mult_32_16( wk3r, x0r ); /*Q(15+Qx+Q_edct) */ + L_tmp = Msub_32_16( L_tmp, wk3i, x0i ); /*Q(15+Qx+Q_edct) */ + a[j3] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); + + L_tmp = Mult_32_16( wk3r, x0i ); /*Q(15+Qx+Q_edct) */ + L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ + a[j3 + 1] = round_fx_sat( L_shl_sat( L_tmp, 1 ) ); /*Q(Qx+Q_edct) */ //??sat + move16(); +#else j1 = add_o( j, l, &Overflow ); j2 = add_o( j1, l, &Overflow ); j3 = add_o( j2, l, &Overflow ); @@ -2223,6 +2650,7 @@ static void cftmdl_16fx( L_tmp = Madd_32_16( L_tmp, wk3i, x0r ); /*Q(15+Qx+Q_edct) */ a[j3 + 1] = round_fx_o( L_shl_o( L_tmp, 1, &Overflow ), &Overflow ); /*Q(Qx+Q_edct) */ move16(); +#endif } } diff --git a/lib_com/frame_ener_fx.c b/lib_com/frame_ener_fx.c index f3dbe52bda5e7738bdd04a41f8d2902e9abcc027..c641bef51336a33f12d12ba5fccdbc7131a9983f 100644 --- a/lib_com/frame_ener_fx.c +++ b/lib_com/frame_ener_fx.c @@ -40,6 +40,7 @@ #include "cnst.h" #include "prot_fx.h" #include "wmc_auto.h" + /*----------------------------------------------------------------------------------* * fer_energy() * @@ -239,14 +240,20 @@ Word16 frame_energy_fx( /* o : Frame energy in Q8 const Word16 *pt1; Word16 tmp16, exp1, exp2, tmp1, tmp2; Word16 len, enern; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ +#ifdef ISSUE_1836_replace_overflow_libcom + len = mult_r( add_sat( pitch[2], pitch[3] ), 256 ); //??sat +#else len = mult_r( add_o( pitch[2], pitch[3], &Overflow ), 256 ); +#endif if ( LT_16( len, L_SUBFR ) ) { @@ -277,19 +284,28 @@ Word16 frame_energy_fx( /* o : Frame energy in Q8 /*add ld(2^exp1)=exp1 but check format, first*/ tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ -#ifdef ISSUE_1799_replace_L_shr_o - Ltmp = L_shr_sat( Ltmp, tmp16 ); /*Q25, tmp16*/ +#ifdef ISSUE_1836_replace_overflow_libcom + Ltmp = L_shr_sat( Ltmp, tmp16 ); /*Q25, tmp16*/ //??sat +#else + Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/ +#endif + exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/ +#ifdef ISSUE_1836_replace_overflow_libcom + Ltmp = L_add_sat( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ) ); /*Q25, tmp16, normalized*/ //??sat #else - Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/ + Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/ #endif - exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/ - Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/ /*make 10*log10 out of log2*/ - Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/ + Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/ +#ifdef ISSUE_1836_replace_overflow_libcom + *frame_ener = extract_h( L_shl_sat( Ltmp, add( tmp16, 1 ) ) ); /*Q8*/ //??sat + move16(); + enern = sub_sat( *frame_ener, lp_speech ); /*Q8*/ //??sat +#else *frame_ener = extract_h( L_shl_o( Ltmp, add( tmp16, 1 ), &Overflow ) ); /*Q8*/ move16(); enern = sub_o( *frame_ener, lp_speech, &Overflow ); /*Q8*/ - +#endif return enern; } diff --git a/lib_com/get_gain_fx.c b/lib_com/get_gain_fx.c index 8ec4f5a40314afa27263cb7a4a77d8a31dd8d53c..8d10f3c4df7952b515e0a3e0e55942769f228017 100644 --- a/lib_com/get_gain_fx.c +++ b/lib_com/get_gain_fx.c @@ -53,10 +53,12 @@ Word32 get_gain( /* output: codebook gain (adaptive or fixed) { Word32 tcorr, tener, Lgain; Word16 exp_c, exp_e, exp, tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif tcorr = L_deposit_l( 0 ); @@ -70,8 +72,13 @@ Word32 get_gain( /* output: codebook gain (adaptive or fixed) tcorr = Dot_product16HQ( 0, x, y, n, &exp_c ); tener = Dot_productSq16HQ( 0, y, n, &exp_e ); +#ifdef ISSUE_1836_replace_overflow_libcom + BASOP_Util_Divide_MantExp( round_fx_sat( tcorr ), exp_c, s_max( round_fx_sat( tener ), 1 ), exp_e, &tmp, &exp ); //??sat + Lgain = L_shl_sat( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ) ) /*Q16*/; //?sat +#else BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp ); Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/; +#endif return Lgain; } @@ -84,9 +91,11 @@ Word32 get_gain2( /* output: codebook gain (adaptive or fixed) { Word32 tcorr, tener, Lgain; Word16 m_corr, m_ener, negative, Q_corr, Q_ener; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif negative = 0; @@ -130,7 +139,11 @@ Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q_corr = sub( Q_corr, Q_ener ); +#ifdef ISSUE_1836_replace_overflow_libcom + Lgain = L_shl_sat( L_deposit_l( m_corr ), add( Q_corr, 1 ) ); /* Lgain in Q16 */ //??sat +#else Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */ +#endif if ( negative != 0 ) { diff --git a/lib_com/gs_bitallocation_fx.c b/lib_com/gs_bitallocation_fx.c index 0ce59482f1f0a3de6ed59c06bf4b5065ccda3166..5e3870a7e3baf0aa154c65b802616bd75715bb3b 100644 --- a/lib_com/gs_bitallocation_fx.c +++ b/lib_com/gs_bitallocation_fx.c @@ -77,8 +77,10 @@ void bands_and_bit_alloc_fx( Word16 w_sum_bit; (void) GSC_IVAS_mode; (void) element_mode; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif nb_tot_bands = MBANDS_GN; move16(); @@ -93,8 +95,12 @@ void bands_and_bit_alloc_fx( set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* To adapt current energy band to PVQ freq band for sorting*/ +#ifdef ISSUE_1836_replace_overflow_libcom + ener_vec[0] = add_sat( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ //??sat +#else ener_vec[0] = add_o( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1], &Overflow ); /*Q12 */ - Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ +#endif + Copy( Ener_per_bd_iQ_tmp + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; move16(); IF( EQ_16( L_frame, L_FRAME16k ) ) diff --git a/lib_com/gs_bitallocation_ivas_fx.c b/lib_com/gs_bitallocation_ivas_fx.c index 9243f640e890348f577688a0dc77aff03e10a148..52e5fef7fb990f08f6af324d58b2e4ae532a2dbc 100644 --- a/lib_com/gs_bitallocation_ivas_fx.c +++ b/lib_com/gs_bitallocation_ivas_fx.c @@ -33,6 +33,7 @@ static void reajust_bits_fx( Word32 *bits_per_bands, const Word16 st_band, const #define Q31_0_02 42949673 /* 0.02 */ #define Q31_0_17 365072220 /* 0.17 */ #define Q31_0_23 493921239 /* 0.23 */ + /*-----------------------------------------------------------------* * Local functions *-----------------------------------------------------------------*/ @@ -105,8 +106,10 @@ void bands_and_bit_alloc_ivas_fx( Word32 bits_per_bands[MBANDS_GN_BITALLOC16k]; /* Q18 */ Word16 w_sum_bit; Word16 fzero_val; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif nb_tot_bands = MBANDS_GN; move16(); @@ -120,7 +123,11 @@ void bands_and_bit_alloc_ivas_fx( set16_fx( out_bits_per_bands, 0, MBANDS_GN_BITALLOC16k ); /* To adapt current energy band to PVQ freq band for sorting*/ +#ifdef ISSUE_1836_replace_overflow_libcom + ener_vec[0] = add_sat( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1] ); /*Q12 */ //??sat +#else ener_vec[0] = add_o( Ener_per_bd_iQ[0], Ener_per_bd_iQ[1], &Overflow ); /*Q12 */ +#endif move16(); Copy( Ener_per_bd_iQ + 1, ener_vec, MBANDS_GN - 1 ); /*Q12 */ ener_vec[MBANDS_GN - 1] = ener_vec[MBANDS_GN - 2]; diff --git a/lib_com/gs_gains_fx.c b/lib_com/gs_gains_fx.c index d49a786f253e10c6f3e235d8bdc712d7bb96e78d..30501ff89c7bf6091c0277a14abc4901f178d305 100644 --- a/lib_com/gs_gains_fx.c +++ b/lib_com/gs_gains_fx.c @@ -84,9 +84,11 @@ void Comp_and_apply_gain_fx( Word16 y_gain; Word16 L16, frac, exp1, tmp_exp; Word32 L32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Recreate excitation for local synthesis and decoder */ @@ -108,9 +110,15 @@ void Comp_and_apply_gain_fx( FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L32 = L_shl_sat( L_mult( exc_diffQ[i], y_gain ), tmp_exp ); /*Q_exc+16 */ //??sat + exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc */ //??sat + move16(); +#else L32 = L_shl_o( L_mult( exc_diffQ[i], y_gain ), tmp_exp, &Overflow ); /*Q_exc+16 */ exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc */ move16(); +#endif } } ELSE @@ -126,7 +134,7 @@ void Comp_and_apply_gain_fx( y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); #else Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); @@ -136,8 +144,12 @@ void Comp_and_apply_gain_fx( FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ + L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc_diffQ[i] = round_fx_sat( L_shl_sat( L32, tmp_exp ) ); /*Q_exc */ //??sat //??sat +#else exc_diffQ[i] = round_fx_o( L_shl_o( L32, tmp_exp, &Overflow ), &Overflow ); /*Q_exc */ +#endif move16(); } } @@ -161,9 +173,11 @@ void Comp_and_apply_gain_ivas_fx( Word16 L16, frac, exp1, tmp_exp; Word32 L32; Word16 Q_exc_diffQ[L_FRAME16k]; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Recreate excitation for local synthesis and decoder */ @@ -185,8 +199,12 @@ void Comp_and_apply_gain_ivas_fx( FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Q_exc+16-tmp_exp */ - exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */ + L32 = L_mult( exc_diffQ[i], y_gain ); /*Q_exc+16-tmp_exp */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ //??sat +#else + exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */ +#endif move16(); IF( exc_diffQ[i] ) { @@ -212,18 +230,22 @@ void Comp_and_apply_gain_ivas_fx( y_gain = extract_l( Pow2( 14, frac ) ); /* Put 14 as exponent so that */ /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); /*Q13*/ #else - Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/ + Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/ #endif move16(); /*Q1 */ tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) ); FOR( i = StartBin; i < NB_Qbins + StartBin; i++ ) { - L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ - exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */ + L32 = L_mult( exc_diffQ[i], y_gain ); /*Qexc_diff+15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc_diffQ[i] = round_fx_sat( L32 ); /*Q_exc-tmp_exp */ //??sat +#else + exc_diffQ[i] = round_fx_o( L32, &Overflow ); /*Q_exc-tmp_exp */ +#endif move16(); IF( exc_diffQ[i] ) { diff --git a/lib_com/gs_noisefill_fx.c b/lib_com/gs_noisefill_fx.c index 53fb676016460d2c8dac74880b4f5da6eb608564..df8813844ef021ba1da58fce59cb0dcd75a71f69 100644 --- a/lib_com/gs_noisefill_fx.c +++ b/lib_com/gs_noisefill_fx.c @@ -411,9 +411,11 @@ static void Decreas_freqPeak_fx( Word16 lsf_new_diff[M]; Word16 tmp, tmp1, exp; Word16 tmp2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif move16(); /*ptr init*/ lsf_new_diff[0] = 0; /* prevent unitialized value */ @@ -470,11 +472,15 @@ static void Decreas_freqPeak_fx( { tmp = abs_s( *src ); exp = norm_s( max_val ); - tmp1 = div_s( shl( 1, sub( 14, exp ) ), max_val ); /*Q(29 - exp - Q_exc) */ - L_tmp = L_mult( tmp, tmp1 ); /*Q(30 - exp) */ + tmp1 = div_s( shl( 1, sub( 14, exp ) ), max_val ); /*Q(29 - exp - Q_exc) */ + L_tmp = L_mult( tmp, tmp1 ); /*Q(30 - exp) */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q14 */ //??sat //??sat +#else tmp = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q14 */ - tmp = sub( 32767, tmp ); /*Q14 */ - L_tmp = L_mult( avrg, tmp ); /*Q_exc +15 */ +#endif + tmp = sub( 32767, tmp ); /*Q14 */ + L_tmp = L_mult( avrg, tmp ); /*Q_exc +15 */ tmp = round_fx( L_shl( L_tmp, 1 ) ); tmp1 = negate( tmp ); @@ -528,9 +534,11 @@ static void envelop_modify_fx( Word16 weight_fx; Word32 L_exc_diffQ_fx[L_FRAME16k], exc_diffQ_max; Word16 Q_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif start_band = i_mult( last_bin, 16 ); @@ -565,10 +573,10 @@ static void envelop_modify_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 14 ); -#ifdef ISSUE_1796_replace_shl_o - Ener1_fx = mult_ro( 13107, shl_sat( tmp, exp ), &Overflow ); /*Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ener1_fx = mult_r( 13107, shl_sat( tmp, exp ) ); /*Q0 */ //??sat #else - Ener1_fx = mult_ro( 13107, shl_o( tmp, exp, &Overflow ), &Overflow ); /*Q0 */ + Ener1_fx = mult_ro( 13107, shl_o( tmp, exp, &Overflow ), &Overflow ); /*Q0 */ #endif FOR( j = 0; j < 16; j++ ) @@ -595,10 +603,10 @@ static void envelop_modify_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 14 ); -#ifdef ISSUE_1796_replace_shl_o - Ener1_fx = mult_r( 13107, shl_sat( tmp, exp ) ); /*Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ener1_fx = mult_r( 13107, shl_sat( tmp, exp ) ); /*Q0 */ //??sat #else - Ener1_fx = mult_r( 13107, shl_o( tmp, exp, &Overflow ) ); /*Q0 */ + Ener1_fx = mult_r( 13107, shl_o( tmp, exp, &Overflow ) ); /*Q0 */ #endif src_fx = &exc_diffQ_fx[224]; @@ -698,9 +706,11 @@ void highband_exc_dct_in_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FOR( j = 10; j < MBANDS_GN; j++ ) @@ -716,13 +726,15 @@ void highband_exc_dct_in_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 14 ); -#ifdef ISSUE_1796_replace_shl_o - tmp1 = shl_sat( tmp, exp ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp1 = shl_sat( tmp, exp ); //??sat + move16(); + ener = add_sat( tmp1, ener ); /*Q0 */ //??sat #else tmp1 = shl_o( tmp, exp, &Overflow ); -#endif move16(); - ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ + ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ +#endif } test(); @@ -951,10 +963,14 @@ void highband_exc_dct_in_fx( FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) { /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ - L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ - exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ + tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ + tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ + L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */ //??sat //??sat +#else + exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ +#endif } } @@ -989,9 +1005,15 @@ void highband_exc_dct_in_fx( IF( GT_16( tmp, abs_s( *dst ) ) ) { tmp2 = *src; +#ifdef ISSUE_1836_replace_overflow_libcom + *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */ //??sat + move16(); + tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */ //??sat +#else *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */ move16(); tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */ +#endif if ( tmp2 > 0 ) { *src = tmp; @@ -1080,9 +1102,11 @@ void highband_exc_dct_in_ivas_fx( Word16 frac, exp, tmp1; Word16 tmp2; Word16 *end, Q_hb_exc; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FOR( j = 10; j < MBANDS_GN; j++ ) @@ -1098,13 +1122,15 @@ void highband_exc_dct_in_ivas_fx( /* output of Pow2() will be: */ /* 16384 < Pow2() <= 32767 */ exp = sub( exp, 14 ); -#ifdef ISSUE_1796_replace_shl_o - tmp1 = shl_sat( tmp, exp ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp1 = shl_sat( tmp, exp ); //??sat + move16(); + ener = add_sat( tmp1, ener ); /*Q0 */ //??sat #else tmp1 = shl_o( tmp, exp, &Overflow ); -#endif move16(); - ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ + ener = add_o( tmp1, ener, &Overflow ); /*Q0 */ +#endif } test(); @@ -1448,10 +1474,14 @@ void highband_exc_dct_in_ivas_fx( FOR( i = sub( L_FRAME, 16 ); i < L_FRAME; i++ ) { /*exc_dct_in[i] *= (0.067f*i-15.f); */ - tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ - tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ - L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ - exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ + tmp = mult_r( 17564, shl( i, 6 ) ); /*0.067 in Q18 and i in Q6= Q9 */ + tmp = sub( tmp, 7680 ); /*15 in Q9 = Q9 */ + L_tmp = L_mult( exc_dct_in[i], tmp ); /*Q(Q_exc+10) */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc_dct_in[i] = round_fx_sat( L_shl_sat( L_tmp, 6 ) ); /*Q_exc */ //??sat //??sat +#else + exc_dct_in[i] = round_fx_o( L_shl_o( L_tmp, 6, &Overflow ), &Overflow ); /*Q_exc */ +#endif } } @@ -1486,9 +1516,15 @@ void highband_exc_dct_in_ivas_fx( IF( GT_16( tmp, abs_s( *dst ) ) ) { tmp2 = *src; +#ifdef ISSUE_1836_replace_overflow_libcom + *src = mult_r( 16384, sub_sat( *src, abs_s( *dst ) ) ); /*Q_exc */ //??sat + move16(); + tmp = mult_r( 16384, add_sat( tmp2, abs_s( *dst ) ) ); /*Q_exc */ //??sat +#else *src = mult_r( 16384, sub_o( *src, abs_s( *dst ), &Overflow ) ); /*Q_exc */ move16(); tmp = mult_r( 16384, add_o( tmp2, abs_s( *dst ), &Overflow ) ); /*Q_exc */ +#endif IF( tmp2 > 0 ) { *src = tmp; diff --git a/lib_com/hp50_fx.c b/lib_com/hp50_fx.c index 0e412f70d6e618f6ea2154250a2a92640c7deadb..76ca278e636b416ae88fd7ddc7cca4bc22993e05 100644 --- a/lib_com/hp50_fx.c +++ b/lib_com/hp50_fx.c @@ -40,7 +40,6 @@ #include "prot_fx.h" #include "wmc_auto.h" - #define HP20_COEFF_SCALE ( 2 ) /* * hp20 @@ -86,9 +85,11 @@ static void filter_2nd_order( Word16 i; Word16 x2, x1; Word32 L_sum, L_y1, L_y2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif /* @@ -107,10 +108,18 @@ static void filter_2nd_order( L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[0], a2 ) ); /* y2*a2 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a1 ) ); /* y1*a1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_y2 = L_shl_sat( L_sum, HP20_COEFF_SCALE ); //??sat + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS + signal[0] = round_fx_sat( L_shl_sat( L_y2, prescale ) ); //??sat //??sat +#else L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS signal[0] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); +#endif + BASOP_SATURATE_WARNING_ON_EVS BASOP_SATURATE_ERROR_ON_EVS @@ -121,10 +130,17 @@ static void filter_2nd_order( L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( mem[1], a2 ) ); /* y2*a2 */ L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); /* y1*a1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_y1 = L_shl_sat( L_sum, HP20_COEFF_SCALE ); //??sat + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS + signal[stride] = round_fx_sat( L_shl_sat( L_y1, prescale ) ); //??sat +#else L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS signal[stride] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS move16(); @@ -140,10 +156,17 @@ static void filter_2nd_order( L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a2 ) ); L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a1 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_y2 = L_shl_sat( L_sum, HP20_COEFF_SCALE ); //??sat + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS + signal[i_mult( i, stride )] = round_fx_sat( L_shl_sat( L_y2, prescale ) ); //??sat +#else L_y2 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS signal[i_mult( i, stride )] = round_fx_o( L_shl_o( L_y2, prescale, &Overflow ), &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0]; */ BASOP_SATURATE_ERROR_ON_EVS @@ -154,10 +177,17 @@ static void filter_2nd_order( L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y1, a2 ) ); L_sum = L_add( L_sum, HP50_Mpy_32_32_fix( L_y2, a1 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_y1 = L_shl_sat( L_sum, HP20_COEFF_SCALE ); //??sat + BASOP_SATURATE_ERROR_OFF_EVS + BASOP_SATURATE_WARNING_OFF_EVS + signal[i_mult( add( i, 1 ), stride )] = round_fx_sat( L_shl_sat( L_y1, prescale ) ); //??sat +#else L_y1 = L_shl_o( L_sum, HP20_COEFF_SCALE, &Overflow ); BASOP_SATURATE_ERROR_OFF_EVS BASOP_SATURATE_WARNING_OFF_EVS signal[i_mult( add( i, 1 ), stride )] = round_fx_o( L_shl_o( L_y1, prescale, &Overflow ), &Overflow ); +#endif BASOP_SATURATE_WARNING_ON_EVS move16(); } @@ -190,9 +220,11 @@ void hp20( Word16 signal[], /* i/o: signal to filter any * { Word32 a1, b1, a2, b2; Word16 prescale, prescaleOld, diff; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif prescale = getScaleFactor16( signal, lg ); @@ -202,7 +234,11 @@ void hp20( Word16 signal[], /* i/o: signal to filter any * { prescale = s_min( prescale, diff ); } +#ifdef ISSUE_1836_replace_overflow_libcom + diff = norm_l( L_shl_sat( mem[3], prescaleOld ) ); //??sat +#else diff = norm_l( L_shl_o( mem[3], prescaleOld, &Overflow ) ); +#endif if ( mem[3] != 0 ) { prescale = s_min( prescale, diff ); @@ -212,27 +248,21 @@ void hp20( Word16 signal[], /* i/o: signal to filter any * IF( prescale != prescaleOld ) { diff = sub( prescale, prescaleOld ); -#ifdef ISSUE_1799_replace_L_shr_o - mem[0] = L_shr_sat( mem[0], diff ); +#ifdef ISSUE_1836_replace_overflow_libcom + mem[0] = L_shr_sat( mem[0], diff ); //??sat + move32(); + mem[1] = L_shr_sat( mem[1], diff ); //??sat + move32(); + mem[2] = L_shr_sat( mem[2], diff ); //??sat + move32(); + mem[3] = L_shr_sat( mem[3], diff ); //?sat #else mem[0] = L_shr_o( mem[0], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o - mem[1] = L_shr_sat( mem[1], diff ); -#else mem[1] = L_shr_o( mem[1], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o - mem[2] = L_shr_sat( mem[2], diff ); -#else mem[2] = L_shr_o( mem[2], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o - mem[3] = L_shr_sat( mem[3], diff ); -#else mem[3] = L_shr_o( mem[3], diff, &Overflow ); #endif move32(); @@ -319,7 +349,9 @@ void hp20_fx_32( Word32 i; Word32 a1_fx, a2_fx, b1_fx, b2_fx; Word32 diff_pos, diff_neg; +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow = 0; +#endif Word16 prescale, prescaleOld, prescale_current_frame, diff; prescale = getScaleFactor32( signal_fx, lg ); @@ -328,8 +360,14 @@ void hp20_fx_32( prescaleOld = extract_l( mem_fx[4] ); +#ifdef ISSUE_1836_replace_overflow_libcom + diff_pos = norm_l( L_shl_sat( L_max( mem_fx[2], mem_fx[3] ), prescaleOld ) ); //??sat + diff_neg = norm_l( L_shl_sat( L_min( mem_fx[2], mem_fx[3] ), prescaleOld ) ); //??sat +#else diff_pos = norm_l( L_shl_o( L_max( mem_fx[2], mem_fx[3] ), prescaleOld, &Overflow ) ); diff_neg = norm_l( L_shl_o( L_min( mem_fx[2], mem_fx[3] ), prescaleOld, &Overflow ) ); +#endif + diff = L_max( diff_pos, diff_neg ); @@ -341,27 +379,21 @@ void hp20_fx_32( prescale = s_min( 3, sub( 1 + HP20_COEFF_SCALE, prescale ) ); diff = sub( prescale, prescaleOld ); -#ifdef ISSUE_1799_replace_L_shr_o +#ifdef ISSUE_1836_replace_overflow_libcom mem_fx[0] = L_shr_sat( mem_fx[0], diff ); -#else - mem_fx[0] = L_shr_o( mem_fx[0], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o mem_fx[1] = L_shr_sat( mem_fx[1], diff ); -#else - mem_fx[1] = L_shr_o( mem_fx[1], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o mem_fx[2] = L_shr_sat( mem_fx[2], diff ); -#else - mem_fx[2] = L_shr_o( mem_fx[2], diff, &Overflow ); -#endif move32(); -#ifdef ISSUE_1799_replace_L_shr_o mem_fx[3] = L_shr_sat( mem_fx[3], diff ); #else + mem_fx[0] = L_shr_o( mem_fx[0], diff, &Overflow ); + move32(); + mem_fx[1] = L_shr_o( mem_fx[1], diff, &Overflow ); + move32(); + mem_fx[2] = L_shr_o( mem_fx[2], diff, &Overflow ); + move32(); mem_fx[3] = L_shr_o( mem_fx[3], diff, &Overflow ); #endif move32(); diff --git a/lib_com/hq2_bit_alloc_fx.c b/lib_com/hq2_bit_alloc_fx.c index 61d00ce987958b6092975f5464c0108192b6ea7b..4524813343d181ac8e0b145bf3fc644f3e4ba4af 100644 --- a/lib_com/hq2_bit_alloc_fx.c +++ b/lib_com/hq2_bit_alloc_fx.c @@ -312,9 +312,11 @@ void hq2_bit_alloc_har_fx( Word16 exp_shift; +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow; Overflow = 0; move32(); +#endif L_THR1 = L_shl( L_deposit_l( THR1 ), SWB_BWE_LR_QRk ); L_THR2 = L_shl( L_deposit_l( THR2 ), SWB_BWE_LR_QRk ); @@ -570,9 +572,13 @@ void hq2_bit_alloc_har_fx( L_temp = Mult_32_16( L_Ravg_sub[GRP_SB - 1], sub( GRP_SB, 1 ) ); /* Qbe+0+1 */ L_temp = Mult_32_16( L_temp, Inv_norm_sum_fx ); /* Qbe+1+QIpb+1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + lf_hf_ge_r_fx = round_fx_sat( L_shl_sat( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ) ) ); //??sat +#else lf_hf_ge_r_fx = round_fx_o( L_shl_o( L_temp, sub( 15 + 16, sub( add( SWB_BWE_LR_Qbe, QIns ), 30 ) ), &Overflow ), &Overflow ); Overflow = 0; /* reset BASOP Overflow */ move32(); +#endif exp_normn = norm_s( norm_sum_fx ); exp_normn = sub( exp_normn, 1 ); diff --git a/lib_com/hq2_core_com_fx.c b/lib_com/hq2_core_com_fx.c index 9017903c831ba270f320458e50d37c1056a91bd7..5c1a63f28aaeb07255c2e6b00d7351e6f33de2a6 100644 --- a/lib_com/hq2_core_com_fx.c +++ b/lib_com/hq2_core_com_fx.c @@ -88,9 +88,11 @@ void mdct_spectrum_denorm_fx( Word16 cond_fx; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); /* allow overflow happen. */ +#endif #endif exp_safe = 4; /* safe bit for overflow */ @@ -163,12 +165,12 @@ void mdct_spectrum_denorm_fx( pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_norm - exp_normd) */ Qpd = add( sub( exp_normn, exp_normd ), 15 ); -#ifdef ISSUE_1796_replace_shl_o - cond_fx = sub( shl_sat( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + cond_fx = sub( shl_sat( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); /* Q15 */ //??sat #else cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ -#endif Overflow = 0; +#endif move16(); /* allow overflow happen. */ IF( cond_fx < 0 ) { @@ -200,7 +202,11 @@ void mdct_spectrum_denorm_fx( /*gamma *= gain_tweak; */ L_tmp = L_mult( gamma_fx, gain_tweak_fx ); /* Qgamma+Qtweak+1 */ exp_norm = norm_l( L_tmp ); +#ifdef ISSUE_1836_replace_overflow_libcom + gamma_fx = round_fx_sat( L_shl( L_tmp, exp_norm ) ); //??sat +#else gamma_fx = round_fx_o( L_shl_o( L_tmp, exp_norm, &Overflow ), &Overflow ); +#endif Qgamma = sub( add( add( Qgamma, Qtweak ), exp_norm ), 15 ); /*Qgamma+Qtweak+1+exp_norm-16; */ } @@ -264,9 +270,11 @@ void mdct_spectrum_denorm_ivas_fx( Word16 cond_fx; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); /* allow overflow happen. */ +#endif #endif exp_safe = 4; /* safe bit for overflow */ @@ -339,12 +347,12 @@ void mdct_spectrum_denorm_ivas_fx( pd_fx = div_s( shl( npulses[k], exp_normn ), shl( band_width[k], exp_normd ) ); /* 15 + (exp_normn + exp_normd) */ Qpd = add( sub( exp_normn, exp_normd ), 15 ); -#ifdef ISSUE_1796_replace_shl_o - cond_fx = sub( shl_sat( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); /* Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + cond_fx = sub( shl_sat( pd_fx, sub( 15, Qpd ) ), pd_thresh_fx /*Q15*/ ); /* Q15 */ //??sat #else cond_fx = sub( shl_o( pd_fx, sub( 15, Qpd ), &Overflow ), pd_thresh_fx /*Q15*/ ); /* Q15 */ -#endif Overflow = 0; +#endif move16(); /* allow overflow happen. */ IF( cond_fx < 0 ) { @@ -376,7 +384,11 @@ void mdct_spectrum_denorm_ivas_fx( /*gamma *= gain_tweak; */ L_tmp = L_mult( gamma_fx, gain_tweak_fx ); /* Qgamma+Qtweak+1 */ exp_norm = norm_l( L_tmp ); +#ifdef ISSUE_1836_replace_overflow_libcom + gamma_fx = round_fx_sat( L_shl( L_tmp, exp_norm ) ); //??sat +#else gamma_fx = round_fx_o( L_shl_o( L_tmp, exp_norm, &Overflow ), &Overflow ); +#endif Qgamma = sub( add( add( Qgamma, Qtweak ), exp_norm ), 15 ); /*Qgamma+Qtweak+1+exp_norm-16; */ } diff --git a/lib_com/hq2_noise_inject_fx.c b/lib_com/hq2_noise_inject_fx.c index db1099809b92786326e95362ef54bbdcbc7c9341..7f61e9a91ddf249e8450f2eb8e01d9090e3c718c 100644 --- a/lib_com/hq2_noise_inject_fx.c +++ b/lib_com/hq2_noise_inject_fx.c @@ -80,9 +80,11 @@ void hq2_noise_inject_fx( Word16 i, j, k, ni_end_band, satur, count[BANDS_MAX], max_pos_pulse, pos; Word16 sb = bands; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif satur = 0; @@ -90,7 +92,11 @@ void hq2_noise_inject_fx( FOR( i = 0; i < bands; i++ ) { - Ep_fx[i] = L_shl_o( Ep_fx[i], 6, &Overflow ); /* Q-6 -> Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ep_fx[i] = L_shl_sat( Ep_fx[i], 6 ); /* Q-6 -> Q0 */ //??sat +#else + Ep_fx[i] = L_shl_o( Ep_fx[i], 6, &Overflow ); /* Q-6 -> Q0 */ +#endif move32(); } @@ -155,7 +161,11 @@ void hq2_noise_inject_fx( Q_env_fx[k] = sub( 31, exp2 ); move16(); tmp = sub( 17, Q_env_fx[k] ); +#ifdef ISSUE_1836_replace_overflow_libcom + env_fx2[k] = extract_h( L_shl_sat( env_fx[k], tmp ) ); /*Q1 */ //??sat +#else env_fx2[k] = extract_h( L_shl_o( env_fx[k], tmp, &Overflow ) ); /*Q1 */ +#endif peak_fx[k] = 0; move16(); count[k] = 0; @@ -166,7 +176,11 @@ void hq2_noise_inject_fx( FOR( i = band_start[k]; i <= band_end[k]; i++ ) { L_tmp = L_mult0( y2hat_fx[i], y2hat_fx[i] ); /* Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ep_fx[k] = L_sub_sat( Ep_fx[k], L_tmp ); //??sat +#else Ep_fx[k] = L_sub_o( Ep_fx[k], L_tmp, &Overflow ); +#endif move32(); /* Q0 */ IF( GT_16( abs_s( y2hat_fx[i] ), peak_fx[k] ) ) { @@ -386,8 +400,12 @@ void hq2_noise_inject_fx( } ELSE IF( count[k - 1] == 0 && tmp4 > 0 ) { - L_tmp = L_mult( env_fx2[k - 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ + L_tmp = L_mult( env_fx2[k - 1], tmp ); /* Q(1+Q_speech+1 = Q_speech+2) */ +#ifdef ISSUE_1836_replace_overflow_libcom + fac_fx = extract_h( L_shl_sat( L_tmp, sub( 26, Q_speech ) ) ); /*Q12 */ +#else fac_fx = extract_h( L_shl_o( L_tmp, sub( 26, Q_speech ), &Overflow ) ); /*Q12 */ +#endif } } @@ -467,8 +485,8 @@ void hq2_noise_inject_fx( } L_tmp = Mult_32_16( Ep_fx[k], fac_fx ); /*Q(Q_Ep_fx[k]+12-15 = Q_Ep_fx[k]-3) */ -#ifdef ISSUE_1799_replace_L_shr_o - ni_gain_fx[k] = L_shr_sat( L_tmp, sub( Q_Ep_fx[k], 20 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + ni_gain_fx[k] = L_shr_sat( L_tmp, sub( Q_Ep_fx[k], 20 ) ); //??sat #else ni_gain_fx[k] = L_shr_o( L_tmp, sub( Q_Ep_fx[k], 20 ), &Overflow ); #endif @@ -593,14 +611,22 @@ void hq2_noise_inject_fx( L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+28-Q_speech-15 = Q_Ep_fx[k]+13-Q_speech) */ tmp = sub( Q_Ep_fx[k], Q_speech ); tmp = sub( 15, tmp ); - tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = extract_h( L_shl_sat( L_tmp, tmp ) ); /*Q12 */ //??sat +#else + tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ +#endif } ELSE { tmp = 0x7fff; /*Q0 */ L_tmp = Mult_32_16( Ep_fx[k], tmp ); /*Q(Q_Ep_fx[k]+0-15 = Q_Ep_fx[k]-15) */ tmp = sub( 43, Q_Ep_fx[k] ); - tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = extract_h( L_shl_sat( L_tmp, tmp ) ); /*Q12 */ //??sat +#else + tmp = extract_h( L_shl_o( L_tmp, tmp, &Overflow ) ); /*Q12 */ +#endif } fac_fx = s_max( tmp, 4096 /* 1 in Q12 */ ); /*Q12 */ @@ -612,10 +638,10 @@ void hq2_noise_inject_fx( IF( band_width[k] != 0 ) { Q_speech = norm_s( band_width[k] ); -#ifdef ISSUE_1796_replace_shl_o - tmp = shl_sat( band_width[k], Q_speech ); /*Q(Q_speech) */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shl_sat( band_width[k], Q_speech ); /*Q(Q_speech) */ //??sat #else - tmp = shl_o( band_width[k], Q_speech, &Overflow ); /*Q(Q_speech) */ + tmp = shl_o( band_width[k], Q_speech, &Overflow ); /*Q(Q_speech) */ #endif tmp = div_s( 16384 /* 0.5 in Q15 */, tmp ); /*Q(15+14-Q_speech) */ } @@ -626,12 +652,16 @@ void hq2_noise_inject_fx( move16(); move16(); } - tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*Q12 */ - L_tmp = L_mult( tmp1, j ); /*Q13 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */ + tmp1 = sub( fac_fx, 4096 /* 1 in Q12 */ ); /*Q12 */ + L_tmp = L_mult( tmp1, j ); /*Q13 */ + L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(13+29-Q_speech-15 = 27-Q_speech) */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = extract_h( L_shl_sat( L_tmp, add( 1, Q_speech ) ) ); /*Q12 */ //??sat +#else tmp = extract_h( L_shl_o( L_tmp, add( 1, Q_speech ), &Overflow ) ); /*Q12 */ - tmp = sub( fac_fx, tmp ); /*Q12 */ - L_tmp = Mult_32_16( ni_gain_fx[k], tmp ); /*Q(17+12-15=14) */ +#endif + tmp = sub( fac_fx, tmp ); /*Q12 */ + L_tmp = Mult_32_16( ni_gain_fx[k], tmp ); /*Q(17+12-15=14) */ L_y2[i] = L_add( L_y2[i], L_shr( Mult_32_16( L_tmp, rand_fx ), 2 ) ); move32(); /*Q12 */ } diff --git a/lib_com/ifft_rel_fx.c b/lib_com/ifft_rel_fx.c index b372e15f3afc5251577a044e3b8fc8f532fd1dd0..dd711ed3d6282c9281b31df545fd8dc84373d1ec 100644 --- a/lib_com/ifft_rel_fx.c +++ b/lib_com/ifft_rel_fx.c @@ -39,6 +39,7 @@ #include "prot_fx.h" #include "rom_com.h" #include "wmc_auto.h" + /*-----------------------------------------------------------------* * Local constants *-----------------------------------------------------------------*/ @@ -77,10 +78,12 @@ void ifft_rel_fx( Word16 cc1, cc3, ss1, ss3; Word16 tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); #endif +#endif /*-----------------------------------------------------------------* @@ -108,30 +111,43 @@ void ifft_rel_fx( FOR( i = is; i < n; i += id ) { +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = sub_sat( *xi1, *xi3 ); /*Qx*/ //??sat + *xi1 = add_sat( *xi1, *xi3 ); /*Qx*/ //??sat + move16(); + *xi2 = shl_sat( *xi2, 1 ); /*Qx*/ //??sat + move16(); + *xi3 = sub_sat( t1, shl_sat( *xi4, 1 ) ); /*Qx*/ //??sat + move16(); + *xi4 = add_sat( t1, shl_sat( *xi4, 1 ) ); /*Qx*/ //??sat + move16(); +#else t1 = sub_o( *xi1, *xi3, &Overflow ); /*Qx*/ *xi1 = add_o( *xi1, *xi3, &Overflow ); /*Qx*/ move16(); -#ifdef ISSUE_1796_replace_shl_o - *xi2 = shl_sat( *xi2, 1 ); /*Qx*/ -#else - *xi2 = shl_o( *xi2, 1, &Overflow ); /*Qx*/ -#endif + *xi2 = shl_o( *xi2, 1, &Overflow ); /*Qx*/ move16(); -#ifdef ISSUE_1796_replace_shl_o - *xi3 = sub_o( t1, shl_sat( *xi4, 1 ), &Overflow ); /*Qx*/ -#else - *xi3 = sub_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ -#endif + *xi3 = sub_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ move16(); -#ifdef ISSUE_1796_replace_shl_o - *xi4 = add_o( t1, shl_sat( *xi4, 1 ), &Overflow ); /*Qx*/ -#else - *xi4 = add_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ -#endif + *xi4 = add_o( t1, shl_o( *xi4, 1, &Overflow ), &Overflow ); /*Qx*/ move16(); +#endif IF( NE_16( n4, 1 ) ) { +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = mult_r( sub_sat( *( xi2 + n8 ), *( xi1 + n8 ) ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ //??sat + t2 = mult_r( add_sat( *( xi4 + n8 ), *( xi3 + n8 ) ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ //??sat + + *( xi1 + n8 ) = add_sat( *( xi1 + n8 ), *( xi2 + n8 ) ); /*Qx*/ //??sat + move16(); + *( xi2 + n8 ) = sub_sat( *( xi4 + n8 ), *( xi3 + n8 ) ); /*Qx*/ //??sat + move16(); + *( xi3 + n8 ) = negate( shl_sat( add_sat( t2, t1 ), 1 ) ); /*Qx*/ //??sat + move16(); + *( xi4 + n8 ) = shl_sat( sub_sat( t1, t2 ), 1 ); /*Qx*/ //??sat + move16(); +#else t1 = mult_r( sub_o( *( xi2 + n8 ), *( xi1 + n8 ), &Overflow ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ t2 = mult_r( add_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ), INV_SQR2_FX /*Q15*/ ); /*Qx*/ @@ -139,18 +155,11 @@ void ifft_rel_fx( move16(); *( xi2 + n8 ) = sub_o( *( xi4 + n8 ), *( xi3 + n8 ), &Overflow ); /*Qx*/ move16(); -#ifdef ISSUE_1796_replace_shl_o - *( xi3 + n8 ) = negate( shl_sat( add_o( t2, t1, &Overflow ), 1 ) ); /*Qx*/ -#else *( xi3 + n8 ) = negate( shl_o( add_o( t2, t1, &Overflow ), 1, &Overflow ) ); /*Qx*/ -#endif move16(); -#ifdef ISSUE_1796_replace_shl_o - *( xi4 + n8 ) = shl_sat( sub_o( t1, t2, &Overflow ), 1 ); /*Qx*/ -#else - *( xi4 + n8 ) = shl_o( sub_o( t1, t2, &Overflow ), 1, &Overflow ); /*Qx*/ -#endif + *( xi4 + n8 ) = shl_o( sub_o( t1, t2, &Overflow ), 1, &Overflow ); /*Qx*/ move16(); +#endif } xi1 += id; xi2 += id; @@ -198,6 +207,45 @@ void ifft_rel_fx( FOR( i = is; i < n; i += id ) { +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = sub_sat( *xup1, *xdn6 ); /*Qx*/ //??sat + *xup1 = add_sat( *xup1, *xdn6 ); /*Qx*/ //??sat + move16(); + xup1 += n4; + xdn6 -= n4; + + t2 = sub_sat( *xdn6, *xup1 ); /*Qx*/ //??sat + *xdn6 = add_sat( *xup1, *xdn6 ); /*Qx*/ //??sat + move16(); + + xdn6 += n4; + t3 = add_sat( *xdn8, *xup3 ); /*Qx*/ //??sat + *xdn6 = sub_sat( *xdn8, *xup3 ); /*Qx*/ //??sat + move16(); + + xup3 += n4; + xdn8 -= n4; + + t4 = add_sat( *xup3, *xdn8 ); /*Qx*/ //??sat + *xup1 = sub_sat( *xup3, *xdn8 ); /*Qx*/ //??sat + move16(); + + t5 = sub_sat( t1, t4 ); /*Qx*/ //??sat + t1 = add_sat( t1, t4 ); /*Qx*/ //??sat + t4 = sub_sat( t2, t3 ); /*Qx*/ //??sat + t2 = add_sat( t2, t3 ); /*Qx*/ //??sat + *xup3 = sub_sat( mult_r( t1, cc3 ), mult_r( t2, ss3 ) ); /*Qx*/ //??sat + move16(); + xup3 -= n4; + *xup3 = add_sat( mult_r( t5, cc1 ), mult_r( t4, ss1 ) ); /*Qx*/ //??sat + move16(); + *xdn8 = sub_sat( mult_r( t5, ss1 ), mult_r( t4, cc1 ) ); /*Qx*/ //??sat + move16(); + + xdn8 += n4; + *xdn8 = add_sat( mult_r( t2, cc3 ), mult_r( t1, ss3 ) ); /*Qx*/ //??sat + move16(); +#else t1 = sub_o( *xup1, *xdn6, &Overflow ); /*Qx*/ *xup1 = add_o( *xup1, *xdn6, &Overflow ); /*Qx*/ move16(); @@ -235,6 +283,7 @@ void ifft_rel_fx( xdn8 += n4; *xdn8 = add_o( mult_r( t2, cc3 ), mult_r( t1, ss3 ), &Overflow ); /*Qx*/ move16(); +#endif xup1 -= n4; xup1 += id; @@ -265,10 +314,17 @@ void ifft_rel_fx( { r1 = *xi0; move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + *xi0 = add_sat( r1, *xi1 ); /*Qx*/ //??sat + move16(); + *xi1 = sub_sat( r1, *xi1 ); /*Qx*/ //??sat + move16(); +#else *xi0 = add_o( r1, *xi1, &Overflow ); /*Qx*/ move16(); *xi1 = sub_o( r1, *xi1, &Overflow ); /*Qx*/ move16(); +#endif xi0 += id; xi1 += id; } diff --git a/lib_com/interpol_fx.c b/lib_com/interpol_fx.c index abcc6092f5a0d9dfa00b03ed34d5c84235665229..7773e8d1acced30fc5e2f9005508041075447683 100644 --- a/lib_com/interpol_fx.c +++ b/lib_com/interpol_fx.c @@ -41,7 +41,6 @@ #include "rom_com.h" #include "prot_fx_enc.h" - Word32 Interpol_lc_fx( /* o : interpolated value Q15 */ const Word16 *x, /* i : input vector Q0 */ const Word16 *win, /* i : interpolation window Q14 */ @@ -83,8 +82,10 @@ Word16 Interpol_4( /* Qx o : interpolated value */ { Word16 i; Word32 L_sum; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif x = x - L_INTERPOL1 + 1; @@ -102,7 +103,13 @@ Word16 Interpol_4( /* Qx o : interpolated value */ } BASOP_SATURATE_WARNING_OFF_EVS /* Here, saturation might occur by intention */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_sum = L_shl_sat( L_sum, 1 ); /*Qx+14+2*/ + BASOP_SATURATE_WARNING_ON_EVS + return round_fx_sat( L_sum ); /*Qx*/ //??sat +#else L_sum = L_shl_o( L_sum, 1, &Overflow ); /*Qx+14+2*/ BASOP_SATURATE_WARNING_ON_EVS return round_fx_o( L_sum, &Overflow ); /*Qx*/ +#endif } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 8ffaf0bfb68f0d065cd35092b06a26f14c8c63de..8f05f18a428621c2e9188d382eb40c74490c264d 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -39,9 +39,11 @@ void ivas_fine_gain_pred_fx( Word16 tmp, exp, exp2; Word32 L_tmp; UWord16 lsb; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif FOR( band = 0; band < num_sfm; band++ ) @@ -81,7 +83,11 @@ void ivas_fine_gain_pred_fx( tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ +#ifdef ISSUE_1836_replace_overflow_libcom + gp = round_fx_sat( L_shl_sat( L_tmp, add( 1, exp ) ) ); /*27-exp+1+exp-16=12 */ //??sat //??sat +#else gp = round_fx_o( L_shl_o( L_tmp, add( 1, exp ), &Overflow ), &Overflow ); /*27-exp+1+exp-16=12 */ +#endif test(); test(); IF( EQ_16( core, HQ_CORE ) && R != NULL && LE_16( R[i_sort[band]], 256 ) ) /* 256 is 32 in Q3 */ @@ -96,8 +102,12 @@ void ivas_fine_gain_pred_fx( exp = add( exp, exp2 ); /*gp *= 1.0f - 0.05f / accuracy; */ - tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ - tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ + tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ //??sat +#else + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ +#endif tmp = sub( 32767, tmp ); tmp = s_max( 27554, tmp ); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ gp = mult_r( tmp, gp ); /*15+12+1-16=12 */ @@ -154,9 +164,11 @@ void fine_gain_pred_fx( Word16 tmp, exp, exp2; Word32 L_tmp; UWord16 lsb; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FOR( band = 0; band < num_sfm; band++ ) @@ -187,9 +199,13 @@ void fine_gain_pred_fx( exp = norm_l( xx ); L_tmp = L_shl( xx, exp ); /*2*(15-shift)+exp */ exp = sub( 31, add( exp, sub( 30, shl( shift, 1 ) ) ) ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*31 - exp */ - Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ + L_tmp = Isqrt_lc( L_tmp, &exp ); /*31 - exp */ + Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ +#ifdef ISSUE_1836_replace_overflow_libcom + gp = round_fx_sat( L_shl_sat( L_tmp, add( 1, exp ) ) ); /*27-exp+1+exp-16=12 */ //??sat //??sat +#else gp = round_fx_o( L_shl_o( L_tmp, add( 1, exp ), &Overflow ), &Overflow ); /*27-exp+1+exp-16=12 */ +#endif test(); test(); IF( EQ_16( core, HQ_CORE ) && R != NULL && LE_16( R[i_sort[band]], 256 ) ) /* 256 is 32 in Q3 */ @@ -204,8 +220,12 @@ void fine_gain_pred_fx( exp = add( exp, exp2 ); /*gp *= 1.0f - 0.05f / accuracy; */ - tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ - tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ + tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ //??sat +#else + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ +#endif tmp = sub( 32767, tmp ); tmp = s_max( 27554, tmp ); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ gp = mult_r( tmp, gp ); /*15+12+1-16=12 */ diff --git a/lib_com/lpc_tools_fx.c b/lib_com/lpc_tools_fx.c index 1035f017a5b95b59efef409b5dead1f1e95ea326..26c663135084d8792aed20ae49b169894b794242 100644 --- a/lib_com/lpc_tools_fx.c +++ b/lib_com/lpc_tools_fx.c @@ -409,8 +409,10 @@ static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word { Word16 approx /*, hi, lo, n_hi , n_lo*/; Word32 L_32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* First approximation: 1 / L_denom = 1/denom_hi */ @@ -427,7 +429,11 @@ static Word32 Div_32_opt( Word32 L_num /*Q31*/, Word16 denom_hi /*Qx -16*/, Word L_32 = Mpy_32_32( L_num, L_32 ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_32 = L_shl_sat( L_32, 2 ); //??sat +#else L_32 = L_shl_o( L_32, 2, &Overflow ); +#endif return ( L_32 ); } @@ -463,9 +469,11 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR Word32 t0, t1, t2; /* temporary variables */ Word16 flag; Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif BASOP_SATURATE_WARNING_OFF_EVS @@ -526,12 +534,21 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); } +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_shl_sat( t0, 4 ); /* result in Q27 -> convert to Q31 */ +#else t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ - /* No overflow possible */ +#endif + /* No overflow possible */ /* Compose and add R[i] in Q3 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_mac_sat( t0, Rl[i], 1 ); //??sat + t0 = L_msu_sat( t0, Rh[i], -32768 ); //??sat +#else t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#endif /* K = -t0 / Alpha */ t1 = L_abs( t0 ); @@ -546,7 +563,11 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR { t2 = L_negate( t2 ); /* K =-t0/Alpha */ } +#ifdef ISSUE_1836_replace_overflow_libcom + t2 = L_shl_sat( t2, alp_exp ); /* denormalize; compare to Alpha */ //??sat +#else t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#endif test(); if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) { @@ -585,7 +606,11 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ /* Alpha = Alpha * (1-K**2) */ - t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = L_mult_sat( Kh, Kh ); /* K*K in Q31 */ //??sat +#else + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#endif t0 = L_mac( t1, mult( Kh, Kl ), 2 ); t0 = L_abs( t0 ); /* Some case <0 !! */ t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ @@ -621,7 +646,11 @@ Word16 E_LPC_lev_dur_stab( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /*QR FOR( i = 1; i <= order; i++ ) { t0 = L_Comp( Ah[i], Al[i] ); +#ifdef ISSUE_1836_replace_overflow_libcom + A[i] = round_fx_sat( L_shl_sat( t0, k ) ); +#else A[i] = round_fx_o( L_shl_o( t0, k, &Overflow ), &Overflow ); +#endif move16(); } @@ -657,9 +686,11 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 Word32 t0, t1, t2; /* temporary variables */ Word16 flag; Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif BASOP_SATURATE_WARNING_OFF_EVS @@ -720,12 +751,21 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); } +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_shl_sat( t0, 4 ); /* result in Q27 -> convert to Q31 */ +#else t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ - /* No overflow possible */ +#endif + /* No overflow possible */ /* Compose and add R[i] in Q3 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_mac_sat( t0, Rl[i], 1 ); //??sat + t0 = L_msu_sat( t0, Rh[i], -32768 ); //??sat +#else t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#endif /* K = -t0 / Alpha */ t1 = L_abs( t0 ); @@ -740,7 +780,11 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 { t2 = L_negate( t2 ); /* K =-t0/Alpha */ } +#ifdef ISSUE_1836_replace_overflow_libcom + t2 = L_shl_sat( t2, alp_exp ); /* denormalize; compare to Alpha */ //??sat +#else t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#endif test(); if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) { @@ -779,7 +823,11 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ /* Alpha = Alpha * (1-K**2) */ - t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = L_mult_sat( Kh, Kh ); /* K*K in Q31 */ //??sat +#else + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#endif t0 = L_mac( t1, mult( Kh, Kl ), 2 ); t0 = L_abs( t0 ); /* Some case <0 !! */ t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ @@ -815,7 +863,11 @@ Word16 E_LPC_lev_dur_stab_ivas_fx( const Word16 Rh[], const Word16 Rl[], Word16 FOR( i = 1; i <= order; i++ ) { t0 = L_Comp( Ah[i], Al[i] ); +#ifdef ISSUE_1836_replace_overflow_libcom + A[i] = round_fx_sat( L_shl_sat( t0, k ) ); //??sat +#else A[i] = round_fx_o( L_shl_o( t0, k, &Overflow ), &Overflow ); +#endif move16(); } @@ -851,10 +903,12 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* Word32 t0, t1, t2; /* temporary variables */ Word16 flag; Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1]; /* LPC coef. in double prec. */ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif BASOP_SATURATE_WARNING_OFF_EVS @@ -915,12 +969,21 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* t0 = Mac_32( t0, Rh[j], Rl[j], Ah[i - j], Al[i - j] ); } +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_shl_sat( t0, 4 ); /* result in Q27 -> convert to Q31 */ //??sat +#else t0 = L_shl_o( t0, 4, &Overflow ); /* result in Q27 -> convert to Q31 */ - /* No overflow possible */ +#endif + /* No overflow possible */ /* Compose and add R[i] in Q3 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_mac_sat( t0, Rl[i], 1 ); + t0 = L_msu_sat( t0, Rh[i], -32768 ); +#else t0 = L_mac_o( t0, Rl[i], 1, &Overflow ); t0 = L_msu_o( t0, Rh[i], -32768, &Overflow ); +#endif /* K = -t0 / Alpha */ t1 = L_abs( t0 ); @@ -935,7 +998,11 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* { t2 = L_negate( t2 ); /* K =-t0/Alpha */ } +#ifdef ISSUE_1836_replace_overflow_libcom + t2 = L_shl_sat( t2, alp_exp ); /* denormalize; compare to Alpha */ //??sat +#else t2 = L_shl_o( t2, alp_exp, &Overflow ); /* denormalize; compare to Alpha */ +#endif test(); if ( ( mem != NULL ) && ( ( GT_16( abs_s( extract_h( t2 ) ), k_max ) ) ) ) { @@ -974,7 +1041,11 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* L_Extract( t2, &Ah[i], &Al[i] ); /* An[i] in Q27 */ /* Alpha = Alpha * (1-K**2) */ - t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#ifdef ISSUE_1836_replace_overflow_libcom + t1 = L_mult_sat( Kh, Kh ); /* K*K in Q31 */ //??sat +#else + t1 = L_mult_o( Kh, Kh, &Overflow ); /* K*K in Q31 */ +#endif t0 = L_mac( t1, mult( Kh, Kl ), 2 ); t0 = L_abs( t0 ); /* Some case <0 !! */ t0 = L_sub( (Word32) 0x7fffffffL, t0 ); /* 1 - K*K in Q31 */ @@ -1010,7 +1081,11 @@ Word16 E_LPC_lev_dur_stab_fx( const Word16 Rh[] /*QR -16*/, const Word16 Rl[] /* FOR( i = 1; i <= order; i++ ) { t0 = L_Comp( Ah[i], Al[i] ); +#ifdef ISSUE_1836_replace_overflow_libcom + A[i] = L_shl_sat( t0, k ); //??sat +#else A[i] = L_shl_o( t0, k, &Overflow ); +#endif move16(); } @@ -1478,9 +1553,11 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/ Word16 lpc[19]; move16(); +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* half length FFT */ @@ -1656,6 +1733,22 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/ Word16 ImAr = extract_h( L_sub( ImagFFT[i], ImagFFT[N / 2 - i] ) ); Word16 ImBr = extract_h( L_add( ImagFFT[i], ImagFFT[N / 2 - i] ) ); BASOP_SATURATE_WARNING_OFF_EVS +#ifdef ISSUE_1836_replace_overflow_libcom + tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im ); //??sat + move16(); + tmpw15.v.im = msu_r_sat( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re ); //??sat + move16(); + BASOP_SATURATE_WARNING_ON_EVS + RealOut[i] = mac_r( L_msu( L_msu( L_mult( ReAr, pwn17->v.re ), ImAr, pwn17->v.im ), ReBr, pwn15->v.im ), ImBr, pwn15->v.re ); + move16(); + ImagOut[i] = mac_r( L_mac( L_mac( L_mult( ReAr, pwn17->v.im ), ImAr, pwn17->v.re ), ReBr, pwn15->v.re ), ImBr, pwn15->v.im ); + move16(); + BASOP_SATURATE_WARNING_OFF_EVS + tmpw15.v.re = msu_r_sat( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); //??sat + move16(); + tmpw15.v.im = mac_r_sat( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); //??sat + move16(); +#else tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.re, pwn17->v.re ), ptwiddle->v.im, pwn17->v.im, &Overflow ); move16(); tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.re, pwn17->v.im ), ptwiddle->v.im, pwn17->v.re, &Overflow ); @@ -1670,6 +1763,7 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/ move16(); tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re, &Overflow ); move16(); +#endif BASOP_SATURATE_WARNING_ON_EVS RealOut[N / 2 - i] = msu_r( L_mac( L_mac( L_mult( ReAr, pwn17i->v.re ), ImAr, pwn17i->v.im ), ImBr, pwn15i->v.re ), ReBr, pwn15i->v.im ); move16(); @@ -1690,6 +1784,22 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/ Word16 ImAr = extract_h( L_sub( ImagFFT[i], ImagFFT[N / 2 - i] ) ); Word16 ImBr = extract_h( L_add( ImagFFT[i], ImagFFT[N / 2 - i] ) ); BASOP_SATURATE_WARNING_OFF_EVS +#ifdef ISSUE_1836_replace_overflow_libcom + tmpw15.v.re = mac_r_sat( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im ); //??sat + move16(); + tmpw15.v.im = msu_r_sat( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re ); //??sat + move16(); + BASOP_SATURATE_WARNING_ON_EVS + RealOut[i] = mac_r( L_msu( L_msu( L_mult( ReAr, pwn17->v.re ), ImAr, pwn17->v.im ), ReBr, pwn15->v.im ), ImBr, pwn15->v.re ); + move16(); + ImagOut[i] = mac_r( L_mac( L_mac( L_mult( ReAr, pwn17->v.im ), ImAr, pwn17->v.re ), ReBr, pwn15->v.re ), ImBr, pwn15->v.im ); + move16(); + BASOP_SATURATE_WARNING_OFF_EVS + tmpw15.v.re = msu_r_sat( L_mult( ptwiddle->v.re, pwn17i->v.im ), ptwiddle->v.im, pwn17i->v.re ); //??sat + move16(); + tmpw15.v.im = mac_r_sat( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re ); //??sat + move16(); +#else tmpw15.v.re = mac_ro( L_mult( ptwiddle->v.im, pwn17->v.re ), ptwiddle->v.re, pwn17->v.im, &Overflow ); move16(); tmpw15.v.im = msu_ro( L_mult( ptwiddle->v.im, pwn17->v.im ), ptwiddle->v.re, pwn17->v.re, &Overflow ); @@ -1704,6 +1814,7 @@ void E_LPC_a_lsf_isf_conversion( Word16 *lpcCoeffs /*Qx*/, Word16 *lsf /*15Q16*/ move16(); tmpw15.v.im = mac_ro( L_mult( ptwiddle->v.im, pwn17i->v.im ), ptwiddle->v.re, pwn17i->v.re, &Overflow ); move16(); +#endif BASOP_SATURATE_WARNING_ON_EVS RealOut[N / 2 - i] = msu_r( L_mac( L_mac( L_mult( ReAr, pwn17i->v.re ), ImAr, pwn17i->v.im ), ImBr, pwn15i->v.re ), ReBr, pwn15i->v.im ); move16(); diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index ea5e51cefa7b2eea7aef7f8fcf7f36c3ba244d26..e168cd0f800371575750217dc1f4f585ae24e2b0 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -69,8 +69,10 @@ static Word16 chebyshev( Word16 x, Word32 *f, const Word16 n, const Word16 shift Word16 cheb; Word32 t0, b1, b2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif cheb = norm_s( x ); @@ -108,16 +110,26 @@ static Word16 chebyshev( Word16 x, Word32 *f, const Word16 n, const Word16 shift b2 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ /* i = 5 */ t0 = Mpy_32_16_1( b2, x ); /* t0 = x*b1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + if ( !cheb ) + t0 = L_shl_sat( t0, 1 ); /* t0 = 2*x*b1 */ //??sat +#else if ( !cheb ) t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ - t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ - b1 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ +#endif + t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ + b1 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ /* i = 6 */ t0 = Mpy_32_16_1( b1, x ); /* t0 = x*b1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + if ( !cheb ) + t0 = L_shl_sat( t0, 1 ); /* t0 = 2*x*b1 */ //??sat +#else if ( !cheb ) t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ - t0 = L_sub( t0, b2 ); /* t0 = 2*x*b1 - b2 */ +#endif + t0 = L_sub( t0, b2 ); /* t0 = 2*x*b1 - b2 */ } /* IF (sub(n,8) == 0) */ IF( n == 8 ) @@ -125,10 +137,15 @@ static Word16 chebyshev( Word16 x, Word32 *f, const Word16 n, const Word16 shift b2 = L_add( t0, *f++ ); /* b0 = 2*x*b1 - b2 + f[i] */ /* i = 7 */ t0 = Mpy_32_16_1( b2, x ); /* t0 = x*b1 */ +#ifdef ISSUE_1836_replace_overflow_libcom + if ( !cheb ) + t0 = L_shl_sat( t0, 1 ); /* t0 = 2*x*b1 */ //??sat +#else if ( !cheb ) t0 = L_shl_o( t0, 1, &Overflow ); /* t0 = 2*x*b1 */ - t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ - /*b1 = L_add(b2,0);*/ +#endif + t0 = L_sub( t0, b1 ); /* t0 = 2*x*b1 - b2 */ + /*b1 = L_add(b2,0);*/ } ELSE { @@ -146,9 +163,14 @@ static Word16 chebyshev( Word16 x, Word32 *f, const Word16 n, const Word16 shift BASOP_SATURATE_WARNING_OFF_EVS - t0 = L_shl_o( t0, shift, &Overflow ); /* Qx to Q30 with saturation */ - cheb = round_fx_o( t0, &Overflow ); /* Result in Q14 */ - cheb = s_max( -32767, cheb ); /* to avoid saturation */ +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_shl_sat( t0, shift ); /* Qx to Q30 with saturation */ //??sat + cheb = round_fx_sat( t0 ); /* Result in Q14 */ //??sat +#else + t0 = L_shl_o( t0, shift, &Overflow ); /* Qx to Q30 with saturation */ + cheb = round_fx_o( t0, &Overflow ); /* Result in Q14 */ +#endif + cheb = s_max( -32767, cheb ); /* to avoid saturation */ BASOP_SATURATE_WARNING_ON_EVS return ( cheb ); } @@ -162,8 +184,10 @@ void E_LPC_a_isp_conversion( const Word16 a[], Word16 isp[], const Word16 old_is Word32 t0, t1; Word16 scale = 1024; move16(); +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*-------------------------------------------------------------* @@ -286,7 +310,11 @@ void E_LPC_a_isp_conversion( const Word16 a[], Word16 isp[], const Word16 old_is * xint = xlow - ylow*(xhigh-xlow)/(yhigh-ylow) *--------------------------------------------------------*/ +#ifdef ISSUE_1836_replace_overflow_libcom + y = sub_sat( yhigh, ylow ); +#else y = sub_o( yhigh, ylow, &Overflow ); +#endif IF( y != 0 ) { x = sub( xhigh, xlow ); @@ -1222,9 +1250,11 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) Word16 nc; Word32 t0; Word16 Ovf, Ovf2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif /*-----------------------------------------------------* @@ -1255,7 +1285,11 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) { f1[nc - i] = L_add( f1[nc - i], f1[nc - i - 1] ); move32(); +#ifdef ISSUE_1836_replace_overflow_libcom + f2[nc - i] = L_sub_sat( f2[nc - i], f2[nc - i - 1] ); //??sat +#else f2[nc - i] = L_sub_o( f2[nc - i], f2[nc - i - 1], &Overflow ); +#endif move32(); } @@ -1265,11 +1299,19 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) *-----------------------------------------------------*/ t0 = L_deposit_l( 0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + FOR( i = 1; i <= nc; i++ ) + { + t0 = L_max( t0, L_abs( L_add_sat( f1[i], f2[i] ) ) ); + t0 = L_max( t0, L_abs( L_sub_sat( f1[i], f2[i] ) ) ); + } +#else FOR( i = 1; i <= nc; i++ ) { t0 = L_max( t0, L_abs( L_add_o( f1[i], f2[i], &Overflow ) ) ); t0 = L_max( t0, L_abs( L_sub_o( f1[i], f2[i], &Overflow ) ) ); } +#endif k = s_min( norm_l( t0 ), 6 ); a[0] = shl( 256, k ); move16(); @@ -1283,6 +1325,16 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) FOR( i = 1; i <= nc; i++ ) { /* a[i] = 0.5*(f1[i] + f2[i]) */ +#ifdef ISSUE_1836_replace_overflow_libcom + t0 = L_add_sat( f1[i], f2[i] ); //??sat + t0 = L_shl( t0, k ); + a[i] = round_fx_sat( t0 ); /* from Q23 to Qx and * 0.5 */ //??sat + + /* a[j] = 0.5*(f1[i] - f2[i]) */ + t0 = L_sub_sat( f1[i], f2[i] ); //??sat + t0 = L_shl( t0, k ); + a[j] = round_fx_sat( t0 ); /* from Q23 to Qx and * 0.5 */ //??sat +#else t0 = L_add_o( f1[i], f2[i], &Overflow ); t0 = L_shl( t0, k ); a[i] = round_fx_o( t0, &Overflow ); /* from Q23 to Qx and * 0.5 */ @@ -1290,7 +1342,8 @@ void E_LPC_f_lsp_a_conversion( const Word16 *lsp, Word16 *a, const Word16 m ) /* a[j] = 0.5*(f1[i] - f2[i]) */ t0 = L_sub_o( f1[i], f2[i], &Overflow ); t0 = L_shl( t0, k ); - a[j] = round_fx_o( t0, &Overflow ); /* from Q23 to Qx and * 0.5 */ + a[j] = round_fx_o( t0, &Overflow ); /* from Q23 to Qx and * 0.5 */ +#endif j--; } @@ -1734,8 +1787,10 @@ void a2rc_fx( const Word16 *a, /* i: can be any Q */ Word16 m, j, n; Word16 q, q_a, q_a2, One_Qx; Word32 One_Qx2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif q = add( norm_s( a[-1] ), 1 ); q_a = sub( 15, q ); @@ -1796,32 +1851,40 @@ void a2rc_fx( const Word16 *a, /* i: can be any Q */ FOR( j = 0; j < m / 2; j++ ) { n = sub( sub( m, (Word16) 1 ), j ); - L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ + L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp1 = L_mac_sat( L_tmp1, tmp, f_fx[n] ); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ //??sat + L_tmp2 = L_mult( denom_mant, f_fx[n] ); /* denom*f[n]. Q15*Q12 = Q28 (floating with exp) */ + L_tmp2 = L_mac_sat( L_tmp2, tmp, f_fx[j] ); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ //??sat + L_tmp1 = L_shr_sat( L_tmp1, exp ); /* bringing to true Q28 */ //??sat + L_tmp2 = L_shr_sat( L_tmp2, exp ); /* bringing to true Q28 */ //??sat + f_fx[j] = round_fx_sat( L_tmp1 ); /* extracting in q_a */ //??sat + f_fx[n] = round_fx_sat( L_tmp2 ); /* extracting in q_a */ //??sat +#else L_tmp1 = L_mac_o( L_tmp1, tmp, f_fx[n], &Overflow ); /* denom*f[j]+km*denom*f[n] in Q28 (floating with exp) */ L_tmp2 = L_mult( denom_mant, f_fx[n] ); /* denom*f[n]. Q15*Q12 = Q28 (floating with exp) */ L_tmp2 = L_mac_o( L_tmp2, tmp, f_fx[j], &Overflow ); /* denom*f[n]+km*denom*f[j] in Q28 (floating with exp) */ -#ifdef ISSUE_1799_replace_L_shr_o - L_tmp1 = L_shr_sat( L_tmp1, exp ); /* bringing to true Q28 */ - L_tmp2 = L_shr_sat( L_tmp2, exp ); /* bringing to true Q28 */ -#else - L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ - L_tmp2 = L_shr_o( L_tmp2, exp, &Overflow ); /* bringing to true Q28 */ + L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ + L_tmp2 = L_shr_o( L_tmp2, exp, &Overflow ); /* bringing to true Q28 */ + f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ + f_fx[n] = round_fx_o( L_tmp2, &Overflow ); /* extracting in q_a */ #endif - f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ - f_fx[n] = round_fx_o( L_tmp2, &Overflow ); /* extracting in q_a */ } IF( m & 1 ) { - L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ - L_tmp1 = L_mac_o( L_tmp1, tmp, f_fx[j], &Overflow ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ -#ifdef ISSUE_1799_replace_L_shr_o - L_tmp1 = L_shr_sat( L_tmp1, exp ); /* bringing to true Q28 */ + L_tmp1 = L_mult( denom_mant, f_fx[j] ); /* denom*f[j]. Q15*Q12 = Q28 (floating with exp) */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp1 = L_mac_sat( L_tmp1, tmp, f_fx[j] ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ //??sat + L_tmp1 = L_shr_sat( L_tmp1, exp ); /* bringing to true Q28 */ //??sat + f_fx[j] = round_fx_sat( L_tmp1 ); /* extracting in q_a */ //??sat + move16(); #else - L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ -#endif - f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ + L_tmp1 = L_mac_o( L_tmp1, tmp, f_fx[j], &Overflow ); /* denom*f[j]+km*denom*f[j] in Q28 (floating with exp) */ + L_tmp1 = L_shr_o( L_tmp1, exp, &Overflow ); /* bringing to true Q28 */ + f_fx[j] = round_fx_o( L_tmp1, &Overflow ); /* extracting in q_a */ move16(); +#endif } } @@ -2273,8 +2336,10 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ Word16 i, m; Word32 L_tmp; Word16 tmp, e; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*-------------------------------------------------------------------* @@ -2320,13 +2385,17 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/ } e = sub( 30 - 21 - 1, e ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = round_fx_sat( L_shl_sat( L_tmp, e ) ); /*Q14*/ //??sat //??sat +#else tmp = round_fx_o( L_shl_o( L_tmp, e, &Overflow ), &Overflow ); /*Q14*/ +#endif tmp = sub( 20480, tmp ); /* 1.25 - tmp in Q14 */ -#ifdef ISSUE_1796_replace_shl_o - tmp = shl_sat( tmp, 1 ); /* Q14 -> Q15 with saturation */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shl_sat( tmp, 1 ); /* Q14 -> Q15 with saturation */ //??sat #else - tmp = shl_o( tmp, 1, &Overflow ); /* Q14 -> Q15 with saturation */ + tmp = shl_o( tmp, 1, &Overflow ); /* Q14 -> Q15 with saturation */ #endif tmp = s_max( tmp, 0 ); @@ -2364,8 +2433,10 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability Word16 i, m; Word32 L_tmp; Word16 tmp, e; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*-------------------------------------------------------------------* @@ -2417,7 +2488,11 @@ Word16 lsf_stab_ivas_fx( /* o : LP filter stability } e = sub( 30 - 21 - 1, e ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = round_fx_sat( L_shl_sat( L_tmp, e ) ); /*Q12*/ //??sat //??sat +#else tmp = round_fx_o( L_shl_o( L_tmp, e, &Overflow ), &Overflow ); /*Q12*/ +#endif // tmp = sub(20480, tmp); /* 1.25 - tmp in Q14 */ tmp = sub( 5120, tmp ); /* 1.25 - tmp in Q12 */ @@ -3776,8 +3851,10 @@ Word16 root_search_fx( Word16 low, Word32 v_high, vh; Word32 Ltemp, L_tmp1, L_tmp, Ltmp; Word16 exp1, tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif v_high = polynomial_eval_fx( high, coef, order ); /* v_high has the value at high index */ @@ -3845,9 +3922,13 @@ Word16 root_search_fx( Word16 low, L_tmp1 = L_shl( L_tmp, exp1 ); tmp = extract_h( L_tmp1 ); exp1 = sub( 30 - 25, exp1 ); - tmp = div_s( 16384, tmp ); /* 15+exp1 */ - Ltmp = Mult_32_16( *v_low, tmp ); /* 15+exp1+25-15 */ - Ltemp = L_shl_o( Ltmp, ( 6 - exp1 ), &Overflow ); /* Q31 */ + tmp = div_s( 16384, tmp ); /* 15+exp1 */ + Ltmp = Mult_32_16( *v_low, tmp ); /* 15+exp1+25-15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ltemp = L_shl_sat( Ltmp, ( 6 - exp1 ) ); /* Q31 */ //??sat +#else + Ltemp = L_shl_o( Ltmp, ( 6 - exp1 ), &Overflow ); /* Q31 */ +#endif if ( LT_32( *v_low, vh ) ) { Ltemp = L_negate( Ltemp ); diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 2e989cfbf5b9d819257cd086c85f48fc955c21d6..46fd9571a8c03d5c175d7aaa14df18de972f5b6b 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -9,7 +9,6 @@ #include "prot_fx.h" #include "wmc_auto.h" - /*-------------------------------------------------------------------* * Local constants *-------------------------------------------------------------------*/ @@ -336,8 +335,10 @@ static Word32 b_inv_sq( Word16 m_den, exp_den; Word16 div_out; Word32 Ltmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif exp_den = norm_l( in32 ); @@ -345,14 +346,17 @@ static Word32 b_inv_sq( exp_den = add( sub( 30, exp_den ), sub( 16, exp_in ) ); m_den = mult_r( m_den, m_den ); -#ifdef ISSUE_1796_replace_shl_o - exp_den = shl_sat( exp_den, 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + exp_den = shl( exp_den, 1 ); + + div_out = div_s( 8192, m_den ); + Ltmp = L_shl_sat( div_out, add( sub( 30 - 13, exp_den ), 15 ) ); /*Q15*/ //??sat #else exp_den = shl_o( exp_den, 1, &Overflow ); -#endif div_out = div_s( 8192, m_den ); Ltmp = L_shl_o( div_out, add( sub( 30 - 13, exp_den ), 15 ), &Overflow ); /*Q15*/ +#endif return Ltmp; } @@ -368,8 +372,10 @@ static Word32 inv_pow( Word32 mh; UWord16 ml; Word32 r0, s0; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif IF( re == 0 ) @@ -382,7 +388,11 @@ static Word32 inv_pow( { exp1 = norm_l( re ); tmp = extract_h( L_shl( re, exp1 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shr( L_mult_sat( tmp, tmp ), 1 ); //??sat +#else L_tmp = L_shr( L_mult_o( tmp, tmp, &Overflow ), 1 ); +#endif Mpy_32_16_ss( L_tmp, x, &mh, &ml ); r0 = L_add( L_tmp, mh ); } @@ -397,7 +407,11 @@ static Word32 inv_pow( { exp2 = norm_l( se ); tmp = extract_h( L_shl( se, exp2 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shr( L_mult_sat( tmp, tmp ), 1 ); +#else L_tmp = L_shr( L_mult_o( tmp, tmp, &Overflow ), 1 ); +#endif Mpy_32_16_ss( L_tmp, x, &mh, &ml ); s0 = L_sub( L_tmp, mh ); } @@ -427,8 +441,8 @@ static Word32 inv_pow( } tmp = div_s( (Word16) ( ( 1 << 14 ) - 1 ), tmp ); exp1 = add( exp1, exp2 ); -#ifdef ISSUE_1799_replace_L_shr_o - L_tmp = L_shr_sat( tmp, sub( 31, exp1 ) ); /* result in Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shr_sat( tmp, sub( 31, exp1 ) ); /* result in Q15 */ //??sat #else L_tmp = L_shr_o( tmp, sub( 31, exp1 ), &Overflow ); /* result in Q15 */ #endif @@ -509,8 +523,10 @@ static void spectautocorr_fx( UWord16 ml; Word32 r[M + 1]; Word16 exp0; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /*---------------------------------------------------------------------* @@ -533,7 +549,11 @@ static void spectautocorr_fx( move32(); FOR( i = 2; i < N - 1; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + r[0] = L_add_sat( r[0], G[i] ); +#else r[0] = L_add_o( r[0], G[i], &Overflow ); +#endif move32(); } @@ -567,18 +587,47 @@ static void spectautocorr_fx( move16(); /* 1.0 in Q15 */ FOR( i = 1; i < imid; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + gp = L_add_sat( G[i], G[N - i - 1] ); //??sat +#else gp = L_add_o( G[i], G[N - i - 1], &Overflow ); +#endif gn = L_sub( G[i], G[N - i - 1] ); /*r[1] = L_mac(r[1], x[i-1], gn);*/ Mpy_32_16_ss( gn, x[i - 1], &mh, &ml ); +#ifdef ISSUE_1836_replace_overflow_libcom + r[1] = L_add_sat( r[1], mh ); //??sat +#else r[1] = L_add_o( r[1], mh, &Overflow ); +#endif move32(); c[1] = x[i - 1]; move16(); FOR( j = 2; j < M; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + c[j] = mult_r( c[j - 1], x[i - 1] ); + move16(); + c[j] = add_sat( c[j], sub_sat( c[j], c[j - 2] ) ); //??sat + move16(); + + /*r[j] = L_mac(r[j], c[j], gp);*/ + Mpy_32_16_ss( gp, c[j], &mh, &ml ); + r[j] = L_add_sat( r[j], mh ); //??sat + move32(); + + c[j + 1] = mult_r( c[j], x[i - 1] ); + move16(); + c[j + 1] = add_sat( c[j + 1], sub_sat( c[j + 1], c[j - 1] ) ); //??sat //??sat + move16(); + + /*r[j+1] = L_mac(r[j+1], c[j+1], gn);*/ + Mpy_32_16_ss( gn, c[j + 1], &mh, &ml ); + r[j + 1] = L_add_sat( r[j + 1], mh ); //??sat + move32(); +#else c[j] = mult_r( c[j - 1], x[i - 1] ); move16(); c[j] = add_o( c[j], sub_o( c[j], c[j - 2], &Overflow ), &Overflow ); @@ -598,33 +647,55 @@ static void spectautocorr_fx( Mpy_32_16_ss( gn, c[j + 1], &mh, &ml ); r[j + 1] = L_add_o( r[j + 1], mh, &Overflow ); move32(); +#endif } c[j] = mult_r( c[j - 1], x[i - 1] ); move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + c[j] = add_sat( c[j], sub_sat( c[j], c[j - 2] ) ); //??sat + move16(); + + Mpy_32_16_ss( gp, c[j], &mh, &ml ); + r[j] = L_add_sat( r[j], mh ); //??sat + move32(); +#else c[j] = add_o( c[j], sub_o( c[j], c[j - 2], &Overflow ), &Overflow ); move16(); Mpy_32_16_ss( gp, c[j], &mh, &ml ); r[j] = L_add_o( r[j], mh, &Overflow ); move32(); +#endif } /*---------------------------------------------------------------------* * Add the endpoints x = cos(0) = 1 and x = cos(pi) = -1 as * well as the lower half of the unit circle. *---------------------------------------------------------------------*/ +#ifdef ISSUE_1836_replace_overflow_libcom + gp = L_shr( L_add_sat( G[0], G[N - 1] ), 1 ); //??sat + gn = L_shr( L_sub( G[0], G[N - 1] ), 1 ); + + r[0] = L_add_sat( r[0], gp ); //??sat +#else gp = L_shr( L_add_o( G[0], G[N - 1], &Overflow ), 1 ); gn = L_shr( L_sub( G[0], G[N - 1] ), 1 ); r[0] = L_add_o( r[0], gp, &Overflow ); +#endif move32(); exp0 = norm_l( r[0] ); L_Extract( L_shl( r[0], exp0 ), &rh[0], &rl[0] ); FOR( j = 1; j < M; j += 2 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_Extract( L_shl( L_add_sat( r[j], gn ), exp0 ), &rh[j], &rl[j] ); //??sat + L_Extract( L_shl( L_add_sat( r[j + 1], gp ), exp0 ), &rh[j + 1], &rl[j + 1] ); //??sat +#else L_Extract( L_shl( L_add_o( r[j], gn, &Overflow ), exp0 ), &rh[j], &rl[j] ); L_Extract( L_shl( L_add_o( r[j + 1], gp, &Overflow ), exp0 ), &rh[j + 1], &rl[j + 1] ); +#endif } return; diff --git a/lib_com/math_op.c b/lib_com/math_op.c index 74143b8ed40d03dd8eff19bf7ca2c39cff1b3d54..24eb8827883c86110a6449a3f8173c74a08cc530 100644 --- a/lib_com/math_op.c +++ b/lib_com/math_op.c @@ -228,20 +228,30 @@ Word32 Energy_scale( /* (o) : Q31: normalized result (1 < val { Word16 i, sft, tmp; Word32 L_sum; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif L_sum = 0; /* just to avoid superflous compiler warning about uninitialized use of L_sum */ IF( expi == 0 ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_sum = L_mac_sat( 1, x[0], x[0] ); //??sat + FOR( i = 1; i < lg; i++ ) + { + L_sum = L_mac_sat( L_sum, x[i], x[i] ); //??sat + } +#else L_sum = L_mac_o( 1, x[0], x[0], &Overflow ); FOR( i = 1; i < lg; i++ ) { L_sum = L_mac_o( L_sum, x[i], x[i], &Overflow ); } +#endif } IF( expi < 0 ) { @@ -251,26 +261,32 @@ Word32 Energy_scale( /* (o) : Q31: normalized result (1 < val FOR( i = 1; i < lg; i++ ) { tmp = mult_r( x[i], sft ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_sum = L_mac_sat( L_sum, tmp, tmp ); //??sat +#else L_sum = L_mac_o( L_sum, tmp, tmp, &Overflow ); +#endif } } IF( expi > 0 ) { -#ifdef ISSUE_1796_replace_shl_o - tmp = shl_sat( x[0], expi ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shl_sat( x[0], expi ); //??sat + L_sum = L_mac_sat( 1, tmp, tmp ); //??sat + FOR( i = 1; i < lg; i++ ) + { + tmp = shl_sat( x[i], expi ); //??sat + L_sum = L_mac_sat( L_sum, tmp, tmp ); //??sat + } #else tmp = shl_o( x[0], expi, &Overflow ); -#endif L_sum = L_mac_o( 1, tmp, tmp, &Overflow ); FOR( i = 1; i < lg; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - tmp = shl_sat( x[i], expi ); -#else tmp = shl_o( x[i], expi, &Overflow ); -#endif L_sum = L_mac_o( L_sum, tmp, tmp, &Overflow ); } +#endif } /* Normalize acc in Q31 */ diff --git a/lib_com/modif_fs_fx.c b/lib_com/modif_fs_fx.c index fae2a43c2f5c1330d63dc06c1e3e21886d58fb7d..1ad07ff66437c24cebcdd76d71dd200cfdf4280c 100644 --- a/lib_com/modif_fs_fx.c +++ b/lib_com/modif_fs_fx.c @@ -75,7 +75,7 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q Word16 flag_low_order = 0; move16(); Word16 filt_len_tmp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -279,8 +279,8 @@ Word16 modify_Fs_ivas_fx( /* o : length of output Q test(); IF( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { -#ifdef ISSUE_1796_replace_shl_o - num_den = shl_sat( num_den, 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + num_den = shl_sat( num_den, 1 ); //??sat #else num_den = shl_o( num_den, 1, &Overflow ); #endif @@ -364,7 +364,7 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ Word16 flag_low_order = 0; move16(); Word16 filt_len_tmp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -565,8 +565,8 @@ Word16 modify_Fs_fx( /* o : length of output Q0 */ if ( GT_32( fin, 16000 ) && ( EQ_16( lg_out, L_FRAME ) || EQ_16( lg_out, L_FRAME16k ) || EQ_16( lg_out, 512 ) ) ) { #ifdef BASOP_NOGLOB_DECLARE_LOCAL -#ifdef ISSUE_1796_replace_shl_o - num_den = shl_sat( num_den, 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + num_den = shl_sat( num_den, 1 ); //??sat #else num_den = shl_o( num_den, 1, &Overflow ); #endif @@ -941,9 +941,11 @@ void Decimate_allpass_steep_fx( Word32 Lacc, Lacc1; Word16 temp1, temp2; Word16 sum = 0; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); @@ -953,60 +955,103 @@ void Decimate_allpass_steep_fx( FOR( k = 0; k < N / 2; k++ ) { - Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP1_STEEP_FX[0], in_fx[2 * k] ); /* Q(16+x) */ //??sat + Lacc1 = L_deposit_h( in_fx[2 * k] ); /* Q16+Qx */ + temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_msu_sat( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q16+Qx */ //??sat +#else Lacc = L_mac_o( Lacc, AP1_STEEP_FX[0], in_fx[2 * k], &Overflow ); /* Q(16+x) */ Lacc1 = L_deposit_h( in_fx[2 * k] ); /* Q16+Qx */ temp1 = extract_h( Lacc ); /* Qx */ Lacc1 = L_msu_o( Lacc1, AP1_STEEP_FX[0], temp1, &Overflow ); /* Q16+Qx */ - mem[0] = extract_h( Lacc1 ); /* Qx */ +#endif + mem[0] = extract_h( Lacc1 ); /* Qx */ temp[0] = temp1; move16(); move16(); - Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */ - Lacc1 = ( L_mac_o( Lacc1, AP1_STEEP_FX[1], temp1, &Overflow ) ); /* Q16+Qx */ + Lacc1 = L_deposit_h( mem[1] ); /* Q16+Qx */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc1 = ( L_mac_sat( Lacc1, AP1_STEEP_FX[1], temp1 ) ); /* Q16+Qx */ //??sat - temp2 = extract_h( Lacc1 ); /* Qx */ - Lacc = L_msu_o( Lacc, AP1_STEEP_FX[1], temp2, &Overflow ); /* Q16+Qx */ - mem[1] = extract_h( Lacc ); /* Qx */ + temp2 = extract_h( Lacc1 ); /* Qx */ + Lacc = L_msu_sat( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q16+Qx */ //??sat +#else + Lacc1 = ( L_mac_o( Lacc1, AP1_STEEP_FX[1], temp1, &Overflow ) ); /* Q16+Qx */ + + temp2 = extract_h( Lacc1 ); /* Qx */ + Lacc = L_msu_o( Lacc, AP1_STEEP_FX[1], temp2, &Overflow ); /* Q16+Qx */ +#endif + mem[1] = extract_h( Lacc ); /* Qx */ temp[1] = temp2; move16(); move16(); - Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + out_fx[k] = extract_h( L_mac_sat( Lacc, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ) ); /* Qx format */ //??sat + move16(); + mem[ALLPASSSECTIONS_STEEP - 1] = extract_h( L_msu_sat( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k] ) ); /* Qx */ //??sat + move16(); +#else out_fx[k] = extract_h( L_mac_o( Lacc, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2, &Overflow ) ); /* Qx format */ move16(); mem[ALLPASSSECTIONS_STEEP - 1] = extract_h( L_msu_o( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[k], &Overflow ) ); /* Qx */ move16(); +#endif } /* lower allpass filter chain */ - Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP2_STEEP_FX[0], mem[2 * ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ //??sat + Lacc1 = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ + temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_msu_sat( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ //??sat +#else Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], mem[2 * ALLPASSSECTIONS_STEEP], &Overflow ); /*Q(16+x) */ Lacc1 = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ temp1 = extract_h( Lacc ); /* Qx */ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ +#endif mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); temp[0] = temp1; move16(); - Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ - Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ - temp2 = extract_h( Lacc1 ); /* Qx */ + Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc1 = L_mac_sat( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ //??sat + temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); - Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ - mem[ALLPASSSECTIONS_STEEP + 1] = extract_h( Lacc ); /* Qx */ + Lacc = L_msu_sat( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ //??sat +#else + Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ + temp2 = extract_h( Lacc1 ); /* Qx */ + temp[1] = temp2; + move16(); + Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ +#endif + mem[ALLPASSSECTIONS_STEEP + 1] = extract_h( Lacc ); /* Qx */ move16(); - Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ //??sat + temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ + move16(); + Lacc1 = L_msu_sat( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2] ); /* Q(16+x) */ //??sat +#else Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2, &Overflow ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ temp[2] = extract_h( Lacc ); /* temp[2] in Qx */ move16(); Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2], &Overflow ); /* Q(16+x) */ - mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ +#endif + mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ move16(); sum = mult_r( out_fx[0], 16384 ); /* Qx */ out_fx[0] = add_sat( sum, mult_r( temp[ALLPASSSECTIONS_STEEP - 1], 16384 ) ); /* Qx */ @@ -1017,11 +1062,18 @@ void Decimate_allpass_steep_fx( { - Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ - Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], in_fx[2 * k - 1], &Overflow ); /* Q(16+x):temp[0] */ - Lacc1 = L_deposit_h( in_fx[2 * k - 1] ); /* Q(16+x) */ - temp1 = extract_h( Lacc ); /* Qx */ - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP2_STEEP_FX[0], in_fx[2 * k - 1] ); /* Q(16+x):temp[0] */ //??sat + Lacc1 = L_deposit_h( in_fx[2 * k - 1] ); /* Q(16+x) */ + temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_msu_sat( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ //??sat +#else + Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], in_fx[2 * k - 1], &Overflow ); /* Q(16+x):temp[0] */ + Lacc1 = L_deposit_h( in_fx[2 * k - 1] ); /* Q(16+x) */ + temp1 = extract_h( Lacc ); /* Qx */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ +#endif mem[ALLPASSSECTIONS_STEEP] = extract_h( Lacc1 ); /* Qx */ move16(); @@ -1029,9 +1081,23 @@ void Decimate_allpass_steep_fx( move16(); - Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ - Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ - temp2 = extract_h( Lacc1 ); /* Qx */ + Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc1 = L_mac_sat( Lacc1, AP2_STEEP_FX[1], temp1 ); /* Q(16+x) */ //??sat + temp2 = extract_h( Lacc1 ); /* Qx */ + temp[1] = temp2; + move16(); + Lacc = L_msu_sat( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ //??sat + mem[ALLPASSSECTIONS_STEEP + 1] = extract_h( Lacc ); /* Qx */ + + + Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ + Lacc = L_mac_sat( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[1] ); //??sat /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ + temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ + Lacc1 = L_msu_sat( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2] ); //??sat /* Q(16+x) */ +#else + Lacc1 = L_mac_o( Lacc1, AP2_STEEP_FX[1], temp1, &Overflow ); /* Q(16+x) */ + temp2 = extract_h( Lacc1 ); /* Qx */ temp[1] = temp2; move16(); Lacc = L_msu_o( Lacc, AP2_STEEP_FX[1], temp2, &Overflow ); /* Q(16+x) */ @@ -1042,7 +1108,8 @@ void Decimate_allpass_steep_fx( Lacc = L_mac_o( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[1], &Overflow ); /* Q(16+x) temp[ALLPASSSECTIONS_STEEP-1] */ temp[2] = extract_h( Lacc ); /*temp[2] in Qx */ Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp[2], &Overflow ); /* Q(16+x) */ - mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ +#endif + mem[2 * ALLPASSSECTIONS_STEEP - 1] = extract_h( Lacc1 ); /* Qx */ sum = mult_r( out_fx[k], 16384 ); /* Qx */ @@ -1158,9 +1225,11 @@ void Interpolate_allpass_steep_fx( Word16 k; Word32 Lacc = 0, Lacc1 = 0; Word16 temp1, temp2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*** State in Q0,in_fx Q0, AP1_STEEP in Q15 AP2_STEEP in Q15 OP in Q0 ************/ /*upper allpass filter chain */ @@ -1168,11 +1237,34 @@ void Interpolate_allpass_steep_fx( FOR( k = 0; k < N; k++ ) { - Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ - Lacc = L_mac_o( Lacc, AP2_STEEP_FX[0], in_fx[k], &Overflow ); /* Q(16+x):temp[0] */ - Lacc1 = L_deposit_h( in_fx[k] ); /* Q(16+x) */ - temp1 = round_fx_o( Lacc, &Overflow ); /* Qx */ - Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[0] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP2_STEEP_FX[0], in_fx[k] ); /* Q(16+x):temp[0] */ //??sat + Lacc1 = L_deposit_h( in_fx[k] ); /* Q(16+x) */ + temp1 = round_fx_sat( Lacc ); /* Qx */ //??sat + Lacc1 = L_msu_sat( Lacc1, AP2_STEEP_FX[0], temp1 ); /* Q(16+x) */ //??sat + + mem[0] = round_fx_sat( Lacc1 ); //??sat + move16(); + Lacc1 = L_deposit_h( mem[1] ); /* Q(16+x) */ //??sat + Lacc1 = ( L_mac_sat( Lacc1, AP2_STEEP_FX[1], temp1 ) ); /* Q(16+x):temp[1] */ //??sat + Lacc = L_deposit_h( temp1 ); + + temp2 = round_fx_sat( Lacc1 ); /* Qx */ //??sat + Lacc = L_msu_sat( Lacc, AP2_STEEP_FX[1], temp2 ); /* Q(16+x) */ //??sat + mem[1] = round_fx_sat( Lacc ); /* Qx */ //??sat + move16(); + + Lacc1 = L_deposit_h( temp2 ); + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ //??sat + out_fx[2 * k + 1] = round_fx_sat( L_mac_sat( Lacc, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ) ); /* Qx format */ //??sat + move16(); + mem[ALLPASSSECTIONS_STEEP - 1] = round_fx_sat( L_msu_sat( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[2 * k + 1] ) ); /* Qx */ //??sat //??sat + move16(); +#else + Lacc1 = L_deposit_h( in_fx[k] ); /* Q(16+x) */ + temp1 = round_fx_o( Lacc, &Overflow ); /* Qx */ + Lacc1 = L_msu_o( Lacc1, AP2_STEEP_FX[0], temp1, &Overflow ); /* Q(16+x) */ mem[0] = round_fx_o( Lacc1, &Overflow ); move16(); @@ -1191,13 +1283,36 @@ void Interpolate_allpass_steep_fx( move16(); mem[ALLPASSSECTIONS_STEEP - 1] = round_fx_o( L_msu_o( Lacc1, AP2_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[2 * k + 1], &Overflow ), &Overflow ); /* Qx */ move16(); +#endif } /* lower allpass filter chain */ FOR( k = 0; k < N; k++ ) { - Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ + Lacc = L_deposit_h( mem[ALLPASSSECTIONS_STEEP] ); /* Q(16+x) */ +#ifdef ISSUE_1836_replace_overflow_libcom + Lacc = L_mac_sat( Lacc, AP1_STEEP_FX[0], in_fx[k] ); /* Q(16+x):temp[0] */ //??sat + Lacc1 = L_deposit_h( in_fx[k] ); /* Q(16+x) */ + temp1 = round_fx_sat( Lacc ); /* Qx */ //??sat + Lacc1 = L_msu_sat( Lacc1, AP1_STEEP_FX[0], temp1 ); /* Q(16+x) */ //??sat + + mem[ALLPASSSECTIONS_STEEP] = round_fx_sat( Lacc1 ); //??sat + Lacc1 = L_deposit_h( mem[ALLPASSSECTIONS_STEEP + 1] ); /* Q(16+x) */ + Lacc1 = L_mac_sat( Lacc1, AP1_STEEP_FX[1], temp1 ); /* Q(16+x):temp[1] */ //??sat + + temp2 = round_fx_sat( Lacc1 ); /* Qx */ //??sat + Lacc = L_deposit_h( temp1 ); + Lacc = L_msu_sat( Lacc, AP1_STEEP_FX[1], temp2 ); /* Q(16+x) */ //??sat + mem[ALLPASSSECTIONS_STEEP + 1] = round_fx_sat( Lacc ); /* Qx */ //??sat + + Lacc = L_deposit_h( mem[2 * ALLPASSSECTIONS_STEEP - 1] ); /* Q(16+x) */ + Lacc1 = L_deposit_h( temp2 ); + out_fx[2 * k] = round_fx_sat( L_mac_sat( Lacc, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], temp2 ) ); /* Qx format */ //??sat //??sat + move16(); + mem[2 * ALLPASSSECTIONS_STEEP - 1] = round_fx_sat( L_msu_sat( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[2 * k] ) ); /* Qx */ //??sat //??sat + move16(); +#else Lacc = L_mac_o( Lacc, AP1_STEEP_FX[0], in_fx[k], &Overflow ); /* Q(16+x):temp[0] */ Lacc1 = L_deposit_h( in_fx[k] ); /* Q(16+x) */ temp1 = round_fx_o( Lacc, &Overflow ); /* Qx */ @@ -1218,6 +1333,7 @@ void Interpolate_allpass_steep_fx( move16(); mem[2 * ALLPASSSECTIONS_STEEP - 1] = round_fx_o( L_msu_o( Lacc1, AP1_STEEP_FX[ALLPASSSECTIONS_STEEP - 1], out_fx[2 * k], &Overflow ), &Overflow ); /* Qx */ move16(); +#endif } return; diff --git a/lib_com/oper_32b.c b/lib_com/oper_32b.c index be34a12481f96713597bce743c203af7811e3719..de733005eadaaf293fad806fc26b65a2b18dcd0b 100644 --- a/lib_com/oper_32b.c +++ b/lib_com/oper_32b.c @@ -124,13 +124,20 @@ Word32 L_Comp( Word16 hi, Word16 lo ) Word32 Mpy_32( Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) { Word32 L_32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif L_32 = L_mult( hi1, hi2 ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_32 = L_mac_sat( L_32, mult( hi1, lo2 ), 1 ); //??sat + L_32 = L_mac_sat( L_32, mult( lo1, hi2 ), 1 ); //??sat +#else L_32 = L_mac_o( L_32, mult( hi1, lo2 ), 1, &Overflow ); L_32 = L_mac_o( L_32, mult( lo1, hi2 ), 1, &Overflow ); +#endif return ( L_32 ); } @@ -159,13 +166,21 @@ Word32 Mpy_32( Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) Word32 Mac_32( Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) { Word32 L_32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif +#ifdef ISSUE_1836_replace_overflow_libcom + L_32 = L_mac_sat( L_num, hi1, hi2 ); //??sat + L_32 = L_mac_sat( L_32, mult( hi1, lo2 ), 1 ); //??sat + L_32 = L_mac_sat( L_32, mult( lo1, hi2 ), 1 ); //??sat +#else L_32 = L_mac_o( L_num, hi1, hi2, &Overflow ); L_32 = L_mac_o( L_32, mult( hi1, lo2 ), 1, &Overflow ); L_32 = L_mac_o( L_32, mult( lo1, hi2 ), 1, &Overflow ); +#endif return ( L_32 ); } @@ -193,12 +208,19 @@ Word32 Mac_32( Word32 L_num, Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2 ) Word32 Sqr_32( Word16 hi, Word16 lo ) { Word32 L_32; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif +#ifdef ISSUE_1836_replace_overflow_libcom + L_32 = L_mult_sat( hi, hi ); //??sat + L_32 = L_mac_sat( L_32, mult( hi, lo ), 2 ); //??sat +#else L_32 = L_mult_o( hi, hi, &Overflow ); L_32 = L_mac_o( L_32, mult( hi, lo ), 2, &Overflow ); +#endif return ( L_32 ); } diff --git a/lib_com/options.h b/lib_com/options.h index e2543337aa061e9ea20e66049a42f81efd36c405..84ce4e93ff69e26b1e8404106b049a3d16c67afd 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,6 +84,8 @@ #define FIX_1762_COMPILER_ISSUE_NEW /* FhG: fix compiler issues with W_mac_32_32() + ONE_IN_Q30 */ #define ISSUE_1796_replace_shl_o /* FhG: replace shl_ro by overflow-free alternatives - BE*/ #define ISSUE_1799_replace_L_shr_o /* FhG: replace by non-overflow-alternative - BE */ +#define ISSUE_1836_replace_overflow_libcom /* FhG: replace overflow operators by non-overflow-alternatives - BE */ +#define ISSUE_1866_replace_overflow_libdec /* FhG: BE - Replace BASOPoverflow operators all over the lib_dec module if Overflow result is not used */ #define NONBE_FIX_TCX5_INTERLEAVING_FOR_FS_IN_UNEQUAL_FS_OUT /* FhG: apply correct TCX5 grouping/interleaving when input_fs != output_fs */ @@ -117,9 +119,6 @@ #define NONBE_FIX_ISM_XOVER_BR /* FhG: issue 1072: select OSBA coding method depending on number of object and bitrate */ #define FIX_1053_REVERB_RECONFIGURATION /* Philips: issue 1053: fix for dynamic switching of acoustic environment */ #define CONF_DISTATT /* Eri: Make distance attenuation configurable */ - -#define ISSUE_1866_replace_overflow_libdec /* FhG: BE - Replace BASOPoverflow operators all over the lib_dec module if Overflow result is not used*/ - #define FIX_1068_ASAN_IN_MC_2_BINAURAL_ROOM_IR /* issue 1068 : Memory leak in MC to BINAURAL_ROOM decoding with bitrate switching*/ #define NONBE_FIX_1052_SBA_EXT /* Dlb: SBA external output support */ #define NONBE_FIX_MC_LFE_LPF /* Dlb: Adding the LFE LPF filter back for MC content. */ diff --git a/lib_com/phase_dispersion_fx.c b/lib_com/phase_dispersion_fx.c index 3103723becabab50ac704ec5634594e73531e5b3..b937d0fcf749bdc36494c2f70640988d5057988f 100644 --- a/lib_com/phase_dispersion_fx.c +++ b/lib_com/phase_dispersion_fx.c @@ -8,6 +8,7 @@ #include "basop_util.h" #include "rom_com.h" + /*-----------------------------------------------------------------------* * phase_dispersion: * @@ -30,9 +31,11 @@ void phase_dispersion( Word32 x32[2 * L_SUBFR]; Word16 *code_real, *code_imag; const Word16 *h_real, *h_imag; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif move16(); @@ -57,7 +60,11 @@ void phase_dispersion( move16(); prev_gain_pit[0] = gain_pit; +#ifdef ISSUE_1836_replace_overflow_libcom + IF( GT_32( gain_code, L_add_sat( *prev_gain_code, L_shl_sat( *prev_gain_code, 1 ) ) ) ) //??sat +#else IF( GT_32( gain_code, L_add_o( *prev_gain_code, L_shl_o( *prev_gain_code, 1, &Overflow ), &Overflow ) ) ) +#endif { IF( LT_16( state, 2 ) ) { @@ -165,7 +172,11 @@ void phase_dispersion( scale2 = getScaleFactor32( x32, L_subfr ); FOR( i = 0; i < L_subfr; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + code[i] = round_fx_sat( L_shl_sat( x32[i], scale2 ) ); +#else code[i] = round_fx_o( L_shl_o( x32[i], scale2, &Overflow ), &Overflow ); +#endif move16(); } j = sub( j, scale2 ); diff --git a/lib_com/ppp_fx.c b/lib_com/ppp_fx.c index cc6b59bdba01a0428f477f792a6a8809e5594d80..56cde545636bd8818918335a5c3d8006d3221bde 100644 --- a/lib_com/ppp_fx.c +++ b/lib_com/ppp_fx.c @@ -97,9 +97,11 @@ void deemph_lpc_fx( Word16 k, temp; Word16 b_fx[M + 2]; /* Q12 */ Word16 a_fx[2] = { -22282, 32767 }; /* Q15 {-PREEMPH_FAC,1.0} */ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif b_fx[0] = 4096; move16(); /* 1 in Q12 */ @@ -115,7 +117,11 @@ void deemph_lpc_fx( { /* LPC_de_curr[k] = a[0]*b[k] + a[1]*b[k+1]; */ temp = mult( a_fx[0], b_fx[k] ); /* Q12 */ +#ifdef ISSUE_1836_replace_overflow_libcom + LPC_de_curr_fx[k] = add_sat( temp, b_fx[k + 1] ); //??sat +#else LPC_de_curr_fx[k] = add_o( temp, b_fx[k + 1], &Overflow ); +#endif move16(); /* Q12 */ } @@ -137,7 +143,11 @@ void deemph_lpc_fx( { /* LPC_de_old[k] = a[0]*b[k] + a[1]*b[k+1]; */ temp = mult( a_fx[0], b_fx[k] ); /* Q12 */ +#ifdef ISSUE_1836_replace_overflow_libcom + LPC_de_old_fx[k] = add_sat( temp, b_fx[k + 1] ); //??sat +#else LPC_de_old_fx[k] = add_o( temp, b_fx[k + 1], &Overflow ); +#endif move16(); /* Q12 */ } } diff --git a/lib_com/pred_lt4_fx.c b/lib_com/pred_lt4_fx.c index 465138bde1fd083c8ed2a0beade5da3fa290ea2f..f457e676f414ad10dc3c78dba7bbe7c52654d1cd 100644 --- a/lib_com/pred_lt4_fx.c +++ b/lib_com/pred_lt4_fx.c @@ -8,7 +8,6 @@ #include "rom_com.h" /* Static table prototypes */ #include "prot_fx.h" /* Function prototypes */ - /*-------------------------------------------------------------------* * Function pred_lt4: * * ~~~~~~~~~ * @@ -35,9 +34,11 @@ void pred_lt4_ivas_fx( Word32 s; const Word16 *x0, *x1, *x2; const Word32 *c1, *c2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif x0 = &excI[-T0]; @@ -71,7 +72,11 @@ void pred_lt4_ivas_fx( s = W_sat_l( W_shr( s64, 16 ) ); /* Q_exc + Q16 */ } - excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */ +#ifdef ISSUE_1836_replace_overflow_libcom + excO[j] = round_fx_sat( s ); /* Q_exc */ //??sat +#else + excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */ +#endif move16(); } return; @@ -91,9 +96,11 @@ void pred_lt4( Word16 i, j; Word32 s; const Word16 *x0, *x1, *x2, *c1, *c2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif x0 = &excI[-T0]; @@ -127,12 +134,21 @@ void pred_lt4( } s = W_sat_l( s64 ); /* Q_exc + Q14 */ } +#ifdef ISSUE_1836_replace_overflow_libcom +#if ( INTERP_EXP != -1 ) + s = L_shl_sat( s, INTERP_EXP + 1 ); /* Q_exc + Q15 */ //??sat +#endif + + excO[j] = round_fx_sat( s ); /* Q_exc */ //??sat + move16(); +#else #if ( INTERP_EXP != -1 ) s = L_shl_o( s, INTERP_EXP + 1, &Overflow ); /* Q_exc + Q15 */ #endif excO[j] = round_fx_o( s, &Overflow ); /* Q_exc */ move16(); +#endif } return; } @@ -177,9 +193,11 @@ void pred_lt4_tc_fx( Word16 excO[L_SUBFR + 1]; Word32 L_sum; Word16 excI[2 * L_SUBFR]; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Copy( exc + sub( i_subfr, L_SUBFR ), excI, L_SUBFR * 2 ); /* Q0 */ @@ -212,15 +230,25 @@ void pred_lt4_tc_fx( k += UP_SAMP; L_sum = L_mac( L_sum, x0[i], win[k] ); /* Q15 */ } - L_sum = L_shl_o( L_sum, 1, &Overflow ); /* Q16 */ - excO[j] = round_fx_o( L_sum, &Overflow ); /* Q0 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_sum = L_shl_sat( L_sum, 1 ); /* Q16 */ //??sat + excO[j] = round_fx_sat( L_sum ); /* Q0 */ //??sat +#else + L_sum = L_shl_o( L_sum, 1, &Overflow ); /* Q16 */ + excO[j] = round_fx_o( L_sum, &Overflow ); /* Q0 */ +#endif + move16(); x0++; } FOR( i = T0; i < L_SUBFR; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + exc[i + i_subfr] = add_sat( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ) ); /* Q0 */ //??sat +#else exc[i + i_subfr] = add_o( exc[i + i_subfr], mult_r( PIT_SHARP_fx, excO[i] ), &Overflow ); /* Q0 */ +#endif move16(); } } diff --git a/lib_com/preemph_fx.c b/lib_com/preemph_fx.c index b7886cb65324d5bfb77d84fe104b24ff7abb7e33..b24aa94671f1ba2daab58de3855da93f37b8212b 100644 --- a/lib_com/preemph_fx.c +++ b/lib_com/preemph_fx.c @@ -22,12 +22,23 @@ void preemph_copy_fx( ) { Word16 i, temp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif temp = x[lg - 1]; /* Qx */ move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + FOR( i = lg - 1; i > 0; i-- ) + { + y[i] = msu_r_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx */ + move16(); + } + y[0] = msu_r_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx */ //??sat + move16(); +#else FOR( i = lg - 1; i > 0; i-- ) { y[i] = msu_ro( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx */ @@ -35,6 +46,8 @@ void preemph_copy_fx( } y[0] = msu_ro( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx */ move16(); +#endif + *mem = temp; /* Qx */ move16(); @@ -49,12 +62,23 @@ void preemph_copy_32fx( ) { Word16 i, temp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif temp = x[lg - 1]; /* Qx */ move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + FOR( i = lg - 1; i > 0; i-- ) + { + y[i] = L_msu_sat( L_deposit_h( x[i] ), x[i - 1], mu ); /* Qx+16 */ //??sat + move16(); + } + y[0] = L_msu_sat( L_deposit_h( x[0] ), *mem, mu ); /* Qx+16 */ //??sat + move16(); +#else FOR( i = lg - 1; i > 0; i-- ) { y[i] = L_msu_o( L_deposit_h( x[i] ), x[i - 1], mu, &Overflow ); /* Qx+16 */ @@ -62,6 +86,7 @@ void preemph_copy_32fx( } y[0] = L_msu_o( L_deposit_h( x[0] ), *mem, mu, &Overflow ); /* Qx+16 */ move16(); +#endif *mem = temp; /* Qx */ move16(); @@ -125,13 +150,31 @@ void E_UTIL_f_preemph2( { Word16 i, temp; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif temp = signal[lg - 1]; /* Qx */ move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + FOR( i = lg - 1; i > 0; i-- ) + { + L_tmp = L_mult( signal[i], 16384 ); /* Qx + 15 */ + L_tmp = L_msu0_sat( L_tmp, signal[i - 1], mu ); /* Qx + 15 */ //??sat + L_tmp = L_shl_sat( L_tmp, add( shift, 1 ) ); /* Qx + shift + 16 */ + signal[i] = round_fx_sat( L_tmp ); /* Qx + shift */ //??sat + move16(); + } + + L_tmp = L_mult( signal[0], 16384 ); /* Qx + 15 */ + L_tmp = L_msu0_sat( L_tmp, *mem, mu ); /* Qx + 15 */ //??sat + L_tmp = L_shl_sat( L_tmp, add( shift, 1 ) ); /* Qx + shift + 16 */ + signal[0] = round_fx_sat( L_tmp ); /* Qx + shift */ //??sat + move16(); +#else FOR( i = lg - 1; i > 0; i-- ) { L_tmp = L_mult( signal[i], 16384 ); /* Qx + 15 */ @@ -146,6 +189,7 @@ void E_UTIL_f_preemph2( L_tmp = L_shl_o( L_tmp, add( shift, 1 ), &Overflow ); /* Qx + shift + 16 */ signal[0] = round_fx_o( L_tmp, &Overflow ); /* Qx + shift */ move16(); +#endif *mem = temp; /* Qx */ move16(); diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 1adcdb7ae6074f3f2b89dbd4883a144f48883b55..d53004f03cf43d9382df31c4109ec6c856e8f3aa 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -427,9 +427,11 @@ void NearOppSplitAdjustment_fx( Word16 qac, qboth, qskew, qavg, qmin, Midx; Word32 L_QIb, L_qnum; Word16 QIb, QIa; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif rangeCoderFinalizationFBits_fx( Qac, INTac, &qac ); @@ -456,7 +458,11 @@ void NearOppSplitAdjustment_fx( } *qnear = qboth; /* Q3 */ move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + QIb = extract_h( L_shl_sat( L_QIb, 16 ) ); /* may saturate Q0*/ //??sat +#else QIb = extract_h( L_shl_o( L_QIb, 16, &Overflow ) ); /* may saturate Q0*/ +#endif if ( LE_16( QIb, qboth ) ) { *qnear = QIb; /* Q0 */ @@ -527,9 +533,11 @@ void fine_gain_quant_fx( Word16 tmp1, tmp2, exp1, exp2; Word32 L_tmp; UWord16 lsb; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif FOR( band = 0; band < num_sfm; band++ ) @@ -552,7 +560,11 @@ void fine_gain_quant_fx( tmp1 = sub( tmp1, exp1 ); L_tmp = L_Comp( tmp1, exp2 ); Mpy_32_16_ss( L_tmp, 24660, &L_tmp, &lsb ); /* 24660 = 20*log10(2) in Q12 */ /*16+12-15=13 */ +#ifdef ISSUE_1836_replace_overflow_libcom + gain_db = round_fx_sat( L_shl_sat( L_tmp, 17 ) ); //??sat +#else gain_db = round_fx_sat( L_shl_o( L_tmp, 17, &Overflow ) ); +#endif idx = squant_fx( gain_db, &gain_dbq, finegain_fx[gbits - 1], gain_cb_size[gbits - 1] ); push_indice( hBstr, IND_PVQ_FINE_GAIN, idx, gbits ); diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 0ed9c9ac844e12d16ec61679379fbf4fd3577b95..1de4fac6cc751d4ae8029f4d5199d8b21df7d19a 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -62,9 +62,11 @@ void Residu3_lc_fx( Word16 i, j; Word32 s; Word16 q; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif q = add( norm_s( a[0] ), 1 ); @@ -72,11 +74,37 @@ void Residu3_lc_fx( { q = add( q, shift ); } -#ifdef ISSUE_1796_replace_shl_o - *y++ = shl_sat( x[0], shift ); +#ifdef ISSUE_1836_replace_overflow_libcom + *y++ = shl_sat( x[0], shift ); //??sat + move16(); + + FOR( i = 1; i < m; i++ ) + { + s = L_mult_sat( x[i], a[0] ); //??sat + /* Stop at i to Avoid Mults with Zeros */ + FOR( j = 1; j <= i; j++ ) + { + s = L_mac_sat( s, x[i - j], a[j] ); //??sat + } + + s = L_shl_sat( s, q ); //??sat + *y++ = round_fx_sat( s ); //??sat + } + + FOR( ; i < lg; i++ ) + { + s = L_mult_sat( x[i], a[0] ); //??sat + FOR( j = 1; j <= m; j++ ) + { + s = L_mac_sat( s, x[i - j], a[j] ); //??sat + } + + s = L_shl_sat( s, q ); //??sat + *y++ = round_fx_sat( s ); //??sat + } + #else *y++ = shl_o( x[0], shift, &Overflow ); -#endif move16(); FOR( i = 1; i < m; i++ ) @@ -103,6 +131,8 @@ void Residu3_lc_fx( s = L_shl_o( s, q, &Overflow ); *y++ = round_fx_o( s, &Overflow ); } + +#endif } /*--------------------------------------------------------------------* @@ -155,9 +185,11 @@ void Residu3_fx( Word64 s64; Word32 s32; Word16 q; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif q = add( norm_s( a[0] ), 1 ); if ( shift != 0 ) @@ -174,7 +206,11 @@ void Residu3_fx( } s64 = W_mac_16_16( s64, x[i - 16], a[16] ); s32 = W_shl_sat_l( s64, q ); +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = round_fx_sat( s32 ); //??sat +#else y[i] = round_fx_o( s32, &Overflow ); +#endif move16(); } } diff --git a/lib_com/stat_noise_uv_mod_fx.c b/lib_com/stat_noise_uv_mod_fx.c index 8d1236b534091f8569a9a047f2a207a7573456d0..7624375d3218556dca2dc89eb4766cee0ef63115 100644 --- a/lib_com/stat_noise_uv_mod_fx.c +++ b/lib_com/stat_noise_uv_mod_fx.c @@ -74,9 +74,11 @@ void stat_noise_uv_mod_fx( Word16 En_shift, Tmp; Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*---------------------------------------------------------* @@ -109,7 +111,11 @@ void stat_noise_uv_mod_fx( move16(); tmp_res = div_l( L_tmp_res, tmp_den ); move16(); +#ifdef ISSUE_1836_replace_overflow_libcom + min_alpha = add_sat( tmp_res, 16384 ); //??sat +#else min_alpha = add_o( tmp_res, 16384, &Overflow ); +#endif move16(); /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ @@ -161,8 +167,8 @@ void stat_noise_uv_mod_fx( FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ -#ifdef ISSUE_1796_replace_shl_o - exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ //??Sat #else exctilt = mult( shl_o( sub( TILT_COMP_LIM_FX, min_alpha ), 2, &Overflow ), exctilt ); /*Q15 */ #endif @@ -190,8 +196,8 @@ void stat_noise_uv_mod_fx( tmp_shift = norm_s( tmp_den ); tmp_den = shl( tmp_den, tmp_shift ); tmp_res = div_s( tmp_nom, tmp_den ); -#ifdef ISSUE_1796_replace_shl_o - tmp_res = shl_sat( tmp_res, tmp_shift ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp_res = shl_sat( tmp_res, tmp_shift ); //??Sat #else tmp_res = shl_o( tmp_res, tmp_shift, &Overflow ); #endif @@ -258,7 +264,11 @@ void stat_noise_uv_mod_fx( L_tmp_res = Mult_32_16( *ge_sm, tmp_res ); /* Q_stat_noise_ge+45-Q_local-Q_ge-tmp_shift-15 */ L_tmp_res = Mult_32_16( L_tmp_res, sub( 32767, beta ) ); /*30-Q_local-tmp_shift+15-15 */ L_tmp_res = L_add_sat( L_shl_sat( L_tmp_res, sub( add( Q_local, tmp_shift ), 15 ) ), beta ); /* Q15 */ - tmp_res = extract_h( L_shl_o( L_tmp_res, 15, &Overflow ) ); /* 15+15-16=14 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp_res = extract_h( L_shl_sat( L_tmp_res, 15 ) ); /* 15+15-16=14 */ //??sat +#else + tmp_res = extract_h( L_shl_o( L_tmp_res, 15, &Overflow ) ); /* 15+15-16=14 */ +#endif Noimix_fract = extract_l( Mult_32_16( L_tmp_res, Noimix_fract ) ); /*15+15-15 */ @@ -392,9 +402,11 @@ void stat_noise_uv_mod_ivas_fx( Word16 En_shift, Tmp; Word16 Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ Word32 L_Exc2_local[L_FRAME]; /* local_copy in scaled Q_local*/ +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /*---------------------------------------------------------* @@ -424,7 +436,11 @@ void stat_noise_uv_mod_ivas_fx( L_tmp_res = L_shl( L_tmp_res, sub( tmp_shift, 1 ) ); tmp_den = shl( tmp_den, tmp_shift ); tmp_res = div_l( L_tmp_res, tmp_den ); +#ifdef ISSUE_1836_replace_overflow_libcom + min_alpha = add_sat( tmp_res, 16384 ); //??sat +#else min_alpha = add_o( tmp_res, 16384, &Overflow ); +#endif /**st_min_alpha = sub(*st_min_alpha, 1638); move16();*/ min_alpha = s_max( min_alpha, sub( *st_min_alpha, 1638 ) ); @@ -475,8 +491,8 @@ void stat_noise_uv_mod_ivas_fx( FOR( i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR ) { exctilt = calc_tilt_fx( &Exc2_local[i_subfr], En_shift, L_SUBFR ); /*Q15 */ -#ifdef ISSUE_1796_replace_shl_o - exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + exctilt = mult( shl_sat( sub( TILT_COMP_LIM_FX, min_alpha ), 2 ), exctilt ); /*Q15 */ //??sat #else exctilt = mult( shl_o( sub( TILT_COMP_LIM_FX, min_alpha ), 2, &Overflow ), exctilt ); /*Q15 */ #endif @@ -504,8 +520,8 @@ void stat_noise_uv_mod_ivas_fx( tmp_shift = norm_s( tmp_den ); tmp_den = shl( tmp_den, tmp_shift ); tmp_res = div_s( tmp_nom, tmp_den ); -#ifdef ISSUE_1796_replace_shl_o - tmp_res = shl_sat( tmp_res, tmp_shift ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp_res = shl_sat( tmp_res, tmp_shift ); //??sat #else tmp_res = shl_o( tmp_res, tmp_shift, &Overflow ); #endif diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index beaef461407840ade891b3580064e51b4709f5db..67310a7c7a9d607ae5001364c572f9ca0f31ccfe 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -996,11 +996,10 @@ static void filt_mu_fx( Word16 mu, ga, temp; const Word16 *ptrs; Word16 tmp, exp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow = 0; -#endif move32(); - +#endif IF( EQ_16( SubFrameLength, L_SUBFR ) ) { @@ -1040,8 +1039,8 @@ static void filt_mu_fx( { temp = mult_r( mu, ( *ptrs++ ) ); temp = add_sat( temp, *ptrs ); /*Q12 */ -#ifdef ISSUE_1796_replace_shl_o - sig_out[n] = shl_sat( mult_r( ga, temp ), 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + sig_out[n] = shl_sat( mult_r( ga, temp ), 1 ); //??sat #else sig_out[n] = shl_o( mult_r( ga, temp ), 1, &Overflow ); #endif @@ -1451,9 +1450,11 @@ void GenShapedWBExcitation_ivas_fx( Word32 LepsP[LPC_WHTN_ORDER_WB + 1]; Word16 tmp_vfac; Word16 avg_voice_fac; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move16(); +#endif #endif /*0.25f*sum_f(voice_factors, NB_SUBFR)*/ @@ -1543,8 +1544,8 @@ void GenShapedWBExcitation_ivas_fx( n1 = norm_s( max_val ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - excTmp2_frac[i] = shl_sat( excTmp2[i], n1 ); // Q_bwe_exc + n1 +#ifdef ISSUE_1836_replace_overflow_libcom + excTmp2_frac[i] = shl( excTmp2[i], n1 ); // Q_bwe_exc + n1 // saturation not possible #else excTmp2_frac[i] = shl_o( excTmp2[i], n1, &Overflow ); // Q_bwe_exc + n1 #endif @@ -1553,16 +1554,28 @@ void GenShapedWBExcitation_ivas_fx( n1 = sub( sub( 14, n1 ), Q_bwe_exc ); pow1 = 1; move32(); +#ifdef ISSUE_1836_replace_overflow_libcom + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ // saturation not possible: excTmp2_frac[i] < MIN_16 + pow1 = L_add_sat( pow1, L_shr( L_tmp, 10 ) ); /* Q22 */ + } +#else FOR( i = 0; i < L_FRAME16k / 4; i++ ) { L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow ); /* Q29 */ pow1 = L_add_o( pow1, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */ } +#endif } FOR( i = 0; i < L_FRAME16k / 4; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + excNoisyEnv[i] = L_add_sat( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) ); // L_mult: sat not poosible, excTmp2 > 0 //??sat +#else excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow ); +#endif move32(); /* Q_bwe_exc+16 */ *mem_csfilt = Mult_32_16( excNoisyEnv[i], neg_csfilt_den2[1] ); move32(); /* Q_bwe_exc+16 */ @@ -1592,7 +1605,11 @@ void GenShapedWBExcitation_ivas_fx( n2 = norm_l( Lmax ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */ +#ifdef ISSUE_1836_replace_overflow_libcom + exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ +#else + exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */ +#endif move16(); } n2 = 30 - n2 - ( Q_bwe_exc + 6 ); @@ -1600,8 +1617,13 @@ void GenShapedWBExcitation_ivas_fx( move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */ - pow22 = L_add_o( pow22, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ //??sat + pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ +#else + L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */ + pow22 = L_add_o( pow22, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */ +#endif } } @@ -1610,11 +1632,19 @@ void GenShapedWBExcitation_ivas_fx( IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /* 0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); - scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ //??sat //??sat +#else + scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ +#endif sc = sub( add( n2, Q_bwe_exc ), 14 ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + exc4kWhtnd[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ //??sat //??sat //??sat +#else exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow ), sc, &Overflow ), &Overflow ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ +#endif move16(); } } @@ -1630,8 +1660,8 @@ void GenShapedWBExcitation_ivas_fx( { /*tmp_vfac = 2*voice_factors[i]; tmp_vfac = min(1, tmp_vfac);*/ -#ifdef ISSUE_1796_replace_shl_o - tmp_vfac = shl_sat( voice_factors[i], 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp_vfac = shl_sat( voice_factors[i], 1 ); //??sat #else tmp_vfac = shl_o( voice_factors[i], 1, &Overflow ); #endif @@ -1643,6 +1673,20 @@ void GenShapedWBExcitation_ivas_fx( } Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp ); +#ifdef ISSUE_1836_replace_overflow_libcom + temp1 = round_fx_sat( L_shl_sat( Ltemp1, exp ) ); /* Q15 */ //??sat //??sat + L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ + Ltemp2 = root_a_over_b_fx( L_tmp, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); + temp2 = round_fx_sat( L_shl_sat( Ltemp2, exp ) ); /* Q15 */ //??sat //??sat + FOR( j = 0; j < L_FRAME16k / 16; j++ ) + { + L_tmp = L_mult( temp1, exc4kWhtnd[k] ); /* Q(16+Q_bwe_exc) */ + L_tmp = L_add_sat( L_tmp, L_shl_sat( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ //??sat //??sat + exc4kWhtnd[k] = round_fx_sat( L_tmp ); /* Q_bwe_exc */ //??sat + move16(); + k++; + } +#else temp1 = round_fx_o( L_shl_o( Ltemp1, exp, &Overflow ), &Overflow ); /* Q15 */ L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ Ltemp2 = root_a_over_b_fx( L_tmp, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp ); @@ -1655,6 +1699,7 @@ void GenShapedWBExcitation_ivas_fx( move16(); k++; } +#endif } } } @@ -1709,9 +1754,11 @@ void GenShapedWBExcitation_fx( Word32 LepsP[LPC_WHTN_ORDER_WB + 1]; Word16 tmp_vfac; Word16 avg_voice_fac; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); move16(); @@ -1803,8 +1850,8 @@ void GenShapedWBExcitation_fx( n1 = norm_s( max_val ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - excTmp2_frac[i] = shl_sat( excTmp2[i], n1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + excTmp2_frac[i] = shl( excTmp2[i], n1 ); #else excTmp2_frac[i] = shl_o( excTmp2[i], n1, &Overflow ); #endif @@ -1815,14 +1862,23 @@ void GenShapedWBExcitation_fx( move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */ //??sat + pow1 = L_add_sat( pow1, L_shr( L_tmp, 7 ) ); /* Q22 */ //??sat +#else L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow ); /* Q29 */ pow1 = L_add_o( pow1, L_shr( L_tmp, 7 ), &Overflow ); /* Q22 */ +#endif } } FOR( i = 0; i < L_FRAME16k / 4; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + excNoisyEnv[i] = L_add_sat( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) ); //??sat +#else excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow ); +#endif move32(); /* Q_bwe_exc+16 */ *mem_csfilt = Mpy_32_16_1( excNoisyEnv[i], neg_csfilt_den2[1] ); move32(); /* Q_bwe_exc+16 */ @@ -1853,7 +1909,11 @@ void GenShapedWBExcitation_fx( n2 = norm_l( Lmax ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) ); /* Q(14-n2) */ +#else exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */ +#endif move16(); } n2 = sub( sub( 30, n2 ), add( Q_bwe_exc, 6 ) ); @@ -1861,8 +1921,13 @@ void GenShapedWBExcitation_fx( move32(); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { - L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */ - pow22 = L_add_o( pow22, L_shr( L_tmp, 7 ), &Overflow ); /* Q22 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult_sat( exc4k_frac[i], exc4k_frac[i] ); /* Q29 */ //??sat + pow22 = L_add( pow22, L_shr( L_tmp, 7 ) ); /* Q22 */ +#else + L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */ + pow22 = L_add_o( pow22, L_shr( L_tmp, 7 ), &Overflow ); /* Q22 */ +#endif } } @@ -1871,13 +1936,23 @@ void GenShapedWBExcitation_fx( IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 /*0.2 in Q15 */ ) ) ) { L_tmp = root_a_over_b_fx( pow1, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); - scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */ //??sat //??sat + sc = sub( add( n2, Q_bwe_exc ), 14 ); + FOR( i = 0; i < L_FRAME16k / 4; i++ ) + { + exc4kWhtnd[i] = round_fx_sat( L_shl_sat( L_mult_sat( exc4k_frac[i], scale ), sc ) ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ //??sat //??sat //??sat + move16(); + } +#else + scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */ sc = sub( add( n2, Q_bwe_exc ), 14 ); FOR( i = 0; i < L_FRAME16k / 4; i++ ) { exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow ), sc, &Overflow ), &Overflow ); /* Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */ move16(); } +#endif } ELSE { @@ -1892,8 +1967,8 @@ void GenShapedWBExcitation_fx( { /*tmp_vfac = 2*voice_factors[i]; tmp_vfac = min(1, tmp_vfac);*/ -#ifdef ISSUE_1796_replace_shl_o - tmp_vfac = shl_sat( voice_factors[i], 1 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp_vfac = shl_sat( voice_factors[i], 1 ); //??sat #else tmp_vfac = shl_o( voice_factors[i], 1, &Overflow ); #endif @@ -1905,6 +1980,20 @@ void GenShapedWBExcitation_fx( } Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp ); +#ifdef ISSUE_1836_replace_overflow_libcom + temp1 = round_fx_sat( L_shl_sat( Ltemp1, exp ) ); /* Q15 */ //??sat //??sat + L_tmp = Mpy_32_16_1( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ + Ltemp2 = root_a_over_b_fx( L_tmp, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); + temp2 = round_fx_sat( L_shl_sat( Ltemp2, exp ) ); /* Q15 */ //??sat //??sat + FOR( j = 0; j < L_FRAME16k / 16; j++ ) + { + L_tmp = L_mult( temp1, exc4kWhtnd[k] ); /* Q(16+Q_bwe_exc) */ + L_tmp = L_add_sat( L_tmp, L_shl_sat( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */ //??sat //??sat + exc4kWhtnd[k] = round_fx_sat( L_tmp ); /* Q_bwe_exc */ //??sat + move16(); + k = add( k, 1 ); + } +#else temp1 = round_fx_o( L_shl_o( Ltemp1, exp, &Overflow ), &Overflow ); /* Q15 */ L_tmp = Mpy_32_16_1( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/ Ltemp2 = root_a_over_b_fx( L_tmp, sub( 22, shl( n1, 1 ) ), pow22, sub( 22, shl( n2, 1 ) ), &exp ); @@ -1917,6 +2006,7 @@ void GenShapedWBExcitation_fx( move16(); k = add( k, 1 ); } +#endif } } } @@ -5691,10 +5781,12 @@ void non_linearity_fx( Word16 nframes; Word32 prev_scale; Word16 length_half; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif IF( EQ_16( L_frame, L_FRAME16k ) ) @@ -5793,15 +5885,19 @@ void non_linearity_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), j ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ //??sat +#else + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ tmp = extract_l( Pow2( 14, frac ) ); -#ifdef ISSUE_1796_replace_shl_o - scale_step = shl_sat( tmp, exp ); /* Q14 */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale_step = shl_sat( tmp, exp ); /* Q14 */ //??sat #else - scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ + scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ #endif } } @@ -5825,8 +5921,12 @@ void non_linearity_fx( IF( GT_16( max_val, shl( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale = L_shl_sat( L_mult( 21955 /* 0.67 in Q15 */, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ //??sat +#else scale = L_shl_o( L_mult( 21955 /* 0.67 in Q15 */, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ +#endif } ELSE { @@ -5875,15 +5975,19 @@ void non_linearity_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ //??sat +#else + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ tmp = extract_l( Pow2( 14, frac ) ); -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom scale_step = shl_sat( tmp, exp ); /*Q14 */ #else - scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ + scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ #endif } } @@ -5951,10 +6055,12 @@ void non_linearity_ivas_fx( Word16 nframes; Word32 prev_scale; Word16 length_half; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif IF( EQ_16( L_frame, L_FRAME16k ) ) @@ -6053,15 +6159,19 @@ void non_linearity_ivas_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), j ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ //??sat +#else + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /* Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ tmp = extract_l( Pow2( 14, frac ) ); -#ifdef ISSUE_1796_replace_shl_o - scale_step = shl_sat( tmp, exp ); /* Q14 */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale_step = shl_sat( tmp, exp ); /* Q14 */ //??sat #else - scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ + scale_step = shl_o( tmp, exp, &Overflow ); /* Q14 */ #endif } } @@ -6085,8 +6195,12 @@ void non_linearity_ivas_fx( IF( GT_16( max_val, shl_sat( 1, Q_inp ) ) ) { exp = norm_s( max_val ); - tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ - scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ + tmp = div_s( shl( 1, sub( 14, exp ) ), max_val ); /* Q(29-exp-Q_inp) */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale = L_shl_sat( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ) ); /* Q31 */ //??sat +#else + scale = L_shl_o( L_mult( 21955, tmp ), add( exp, sub( Q_inp, 14 ) ), &Overflow ); /* Q31 */ +#endif } ELSE { @@ -6135,15 +6249,19 @@ void non_linearity_ivas_fx( tmp = div_s( shl( 1, sub( 14, exp ) ), tmp ); /* Q(29-exp) */ /* (log2(scale / prev_scale))/length */ - L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ) ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ //??sat +#else + L_tmp = L_shl_o( Mult_32_16( L_tmp, tmp ), sub( exp, 14 ), &Overflow ); /*Q(16+29-exp+1-16+exp-14)->Q16 */ +#endif frac = L_Extract_lc( L_tmp, &exp ); /* Extract exponent of L_tmp */ tmp = extract_l( Pow2( 14, frac ) ); -#ifdef ISSUE_1796_replace_shl_o - scale_step = shl_sat( tmp, exp ); /*Q14 */ +#ifdef ISSUE_1836_replace_overflow_libcom + scale_step = shl_sat( tmp, exp ); /*Q14 */ //??sat #else - scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ + scale_step = shl_o( tmp, exp, &Overflow ); /*Q14 */ #endif } } @@ -6857,6 +6975,9 @@ void synthesise_fb_high_band_fx( * * * Estimate mix factors for SHB excitation generation * *-------------------------------------------------------------------*/ +#ifdef ISSUE_1836_replace_overflow_libcom +#undef ISSUE_1836_replace_overflow_libcom +#endif void Estimate_mix_factors_fx( const Word16 *shb_res, /* i : SHB LP residual in Q = Q_shb */ const Word16 Q_shb, @@ -6879,9 +7000,11 @@ void Estimate_mix_factors_fx( Word16 exp1, exp2, expa, expb, fraca, fracb, scale, num_flag, den_flag; Word16 tmp, tmp1, sc1, sc2; Word32 L_tmp1, L_tmp2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Copy( shb_res, shb_res_local, L_FRAME16k ); @@ -6940,7 +7063,11 @@ void Estimate_mix_factors_fx( expa = sub( 30, expa ); expb = norm_l( temp_p1_p2 ); +#ifdef ISSUE_1836_replace_overflow_libcom + fracb = round_fx_sat( L_shl( temp_p1_p2, expb ) ); //??sat +#else fracb = round_fx_o( L_shl_o( temp_p1_p2, expb, &Overflow ), &Overflow ); +#endif expb = sub( 30, expb ); num_flag = 0; @@ -7064,9 +7191,11 @@ void prep_tbe_exc_fx( Word32 L_tmp, Ltemp1, Ltemp2; Word32 tempQ31; Word16 tempQ15; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /**voice_factors = VF_0th_PARAM + VF_1st_PARAM * voice_fac + VF_2nd_PARAM * voice_fac * voice_fac; @@ -7081,10 +7210,10 @@ void prep_tbe_exc_fx( tmp = MAX_16; move16(); -#ifdef ISSUE_1796_replace_shl_o - pitch = shl_sat( add( shl_sat( T0, 2 ), T0_frac ), 5 ); /* Q7 */ +#ifdef ISSUE_1836_replace_overflow_libcom + pitch = shl_sat( add( shl_sat( T0, 2 ), T0_frac ), 5 ); /* Q7 */ //??sat //??sat #else - pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ + pitch = shl_o( add( shl_o( T0, 2, &Overflow ), T0_frac ), 5, &Overflow ); /* Q7 */ #endif test(); @@ -7114,7 +7243,19 @@ void prep_tbe_exc_fx( IF( EQ_16( L_frame_fx, L_FRAME ) ) { - interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ + interp_code_5over2_fx( code_fx, tmp_code_fx, L_subfr ); /* code: Q9, tmp_code: Q9 */ +#ifdef ISSUE_1836_replace_overflow_libcom + gain_code16 = round_fx_sat( L_shl_sat( gain_code_fx, Q_exc ) ); /*Q_exc */ //??sat //??sat + FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) + { + L_tmp = L_mult( gain_code16, tmp_code_fx[i] ); /* Q9 + Q_exc + 1*/ + L_tmp = L_shl_sat( L_tmp, 5 ); /* Q9 + Q_exc + Q6*/ //??sat + L_tmp = L_mac_sat( L_tmp, gain_pit_fx, bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] ); /*Q15+Q_exc */ //??sat + L_tmp = L_shl_sat( L_tmp, 1 ); /*16+Q_exc */ /* saturation can occur here */ + bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_sat( L_tmp ); /*Q_exc */ //??sat + move16(); + } +#else gain_code16 = round_fx_o( L_shl_o( gain_code_fx, Q_exc, &Overflow ), &Overflow ); /*Q_exc */ FOR( i = 0; i < L_subfr * HIBND_ACB_L_FAC; i++ ) { @@ -7125,6 +7266,7 @@ void prep_tbe_exc_fx( bwe_exc_fx[i + i_subfr_fx * HIBND_ACB_L_FAC] = round_fx_o( L_tmp, &Overflow ); /*Q_exc */ move16(); } +#endif } ELSE { @@ -7138,10 +7280,17 @@ void prep_tbe_exc_fx( Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ Ltemp2 = L_mult( gain_preQ_fx, code_preQ_fx[i] ); /*Q2 * Q10 -> Q12 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ltemp1 = L_shl_sat( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/ ); /*Q_exc+16 */ //??sat + Ltemp2 = L_shl_sat( Ltemp2, add( Q_exc, shift ) /*Q_exc+ 2 + 6 (or) 10 - 13*/ ); /*Q_exc+16 */ //??sat + + tmp_code_preInt_fx[i] = round_fx_sat( L_add_sat( Ltemp1, Ltemp2 ) ); /* Q_exc */ //??sat //??sat +#else Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ Ltemp2 = L_shl_o( Ltemp2, add( Q_exc, shift ) /*Q_exc+ 2 + 6 (or) 10 - 13*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ + tmp_code_preInt_fx[i] = round_fx_o( L_add_o( Ltemp1, Ltemp2, &Overflow ), &Overflow ); /* Q_exc */ +#endif move16(); } } @@ -7150,9 +7299,14 @@ void prep_tbe_exc_fx( FOR( i = 0; i < L_subfr; i++ ) { /*code in the encoder is Q9 and there is no <<1 with Mult_32_16 Q16 * Q9 -> Q9 */ - Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ - Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ - tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ + Ltemp1 = Mult_32_16( gain_code_fx, code_fx[i] ); /* Q16 + Q9 + 1 - 16 = Q10 */ +#ifdef ISSUE_1836_replace_overflow_libcom + Ltemp1 = L_shl_sat( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/ ); /*Q_exc+16 */ //??sat + tmp_code_preInt_fx[i] = round_fx_sat( Ltemp1 ); /* Q_exc */ //??sat +#else + Ltemp1 = L_shl_o( Ltemp1, add( Q_exc, 6 ) /*Q_exc+16-19*/, &Overflow ); /*Q_exc+16 */ + tmp_code_preInt_fx[i] = round_fx_o( Ltemp1, &Overflow ); /* Q_exc */ +#endif move16(); } } @@ -7160,9 +7314,15 @@ void prep_tbe_exc_fx( interp_code_4over2_fx( tmp_code_preInt_fx, tmp_code_fx, L_subfr ); /* o: tmp_code in Q_exc */ FOR( i = 0; i < shl( L_subfr, 1 ); i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + ( i_subfr_fx << 1 )] ); /*Q14+Q_exc+1 */ + tmp = round_fx_sat( L_shl_sat( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/ ) ); /* tmp in Q_exc */ //??sat //??sat + bwe_exc_fx[i + ( i_subfr_fx << 1 )] = add_sat( tmp, tmp_code_fx[i] ); /*Q_exc */ //??sat +#else L_tmp = L_mult( gain_pit_fx, bwe_exc_fx[i + shl( i_subfr_fx, 1 )] ); /*Q14+Q_exc+1 */ tmp = round_fx_o( L_shl_o( L_tmp, 1 /* (Q_exc+16)-(14+Q_exc+1)*/, &Overflow ), &Overflow ); /* tmp in Q_exc */ bwe_exc_fx[i + shl( i_subfr_fx, 1 )] = add_o( tmp, tmp_code_fx[i], &Overflow ); /*Q_exc */ +#endif move16(); } } @@ -7198,7 +7358,7 @@ Word16 swb_formant_fac_fx( { Word16 formant_fac; Word16 tmp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif @@ -7229,8 +7389,8 @@ Word16 swb_formant_fac_fx( /* formant_fac = 1.0f - 0.5f*formant_fac */ tmp = mult_r( 16384, formant_fac ); /* 0.5 in Q15 */ -#ifdef ISSUE_1796_replace_shl_o - formant_fac = shl_sat( sub( 4096 /* 1 in Q12 */, tmp ), 3 ); +#ifdef ISSUE_1836_replace_overflow_libcom + formant_fac = shl_sat( sub( 4096 /* 1 in Q12 */, tmp ), 3 ); //??sat #else formant_fac = shl_o( sub( 4096 /* 1 in Q12 */, tmp ), 3, &Overflow ); #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index e0315bbcb1c0c0a733b4f84404beaab10fab1bd3..6f4eb87630391dc469a9f516c3f54fc8920adf4c 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -11,11 +11,16 @@ static Word32 syn_kern_2( Word32 L_tmp, const Word16 a[], const Word16 y[] ) { +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif L_tmp = L_msu_o( L_tmp, y[-1], a[1], &Overflow ); return L_msu_o( L_tmp, y[-2], a[2], &Overflow ); +#else + L_tmp = L_msu_sat( L_tmp, y[-1], a[1] ); //??sat + return L_msu_sat( L_tmp, y[-2], a[2] ); //??sat +#endif } static Word32 syn_kern_4( Word32 L_tmp, const Word16 a[], const Word16 y[] ) @@ -341,9 +346,11 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W Word32 L_tmp; Word16 q; Word32 ( *syn_kern )( Word32 L_tmp, const Word16 a[], const Word16 y[] ) = NULL; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif if ( EQ_16( m, 6 ) ) @@ -377,8 +384,13 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W *-----------------------------------------------------------------------*/ /* Filtering Only from Input + Memory */ L_tmp = syn_kern( L_mult( a0, *x++ ), a, mem ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); //??sat + *y++ = round_fx_sat( L_tmp ); //??sat +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = round_fx_o( L_tmp, &Overflow ); +#endif move16(); /* Filtering from Input + Mix of Memory & Output Signal Past */ @@ -388,15 +400,24 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W /* Process Output Signal Past */ FOR( j = 1; j <= i; j++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_msu_sat( L_tmp, a[j], y[-j] ); //??sat +#else L_tmp = L_msu_o( L_tmp, a[j], y[-j], &Overflow ); +#endif } /* Process Memory */ FOR( ; j <= m; j++ ) { L_tmp = L_msu_sat( L_tmp, a[j], mem[i - j] ); } +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); //??sat + *y++ = round_fx_sat( L_tmp ); //??sat +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = round_fx_o( L_tmp, &Overflow ); +#endif move16(); } @@ -404,8 +425,13 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W FOR( ; i < lg; i++ ) { L_tmp = syn_kern( L_mult( a0, *x++ ), a, y ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); + *y++ = round_fx_sat( L_tmp ); +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); *y++ = round_fx_o( L_tmp, &Overflow ); +#endif move16(); } @@ -452,8 +478,10 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] Word32 L_tmp; Word16 q; Word32 ( *syn_kern )( Word32 L_tmp, const Word32 a[], const Word32 y[] ) = NULL; +#ifndef ISSUE_1836_replace_overflow_libcom Flag Overflow = 0; move32(); +#endif if ( EQ_16( m, 6 ) ) { @@ -480,8 +508,8 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] *-----------------------------------------------------------------------*/ mem += m; /*move32();*/ -#ifdef ISSUE_1799_replace_L_shr_o - a0 = L_shr_sat( a[0], shift ); /* input / 2^shift */ +#ifdef ISSUE_1836_replace_overflow_libcom + a0 = L_shr_sat( a[0], shift ); /* input / 2^shift */ //??sat #else a0 = L_shr_o( a[0], shift, &Overflow ); /* input / 2^shift */ #endif @@ -491,7 +519,11 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] *-----------------------------------------------------------------------*/ /* Filtering Only from Input + Memory */ L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, mem ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); //??sat +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); +#endif *y++ = L_tmp; move32(); @@ -509,7 +541,11 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] { L_tmp = Msub_32_32_r( L_tmp, a[j], mem[i - j] ); } +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); //??sat +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); +#endif *y++ = L_tmp; move32(); } @@ -518,7 +554,11 @@ void E_UTIL_synthesis_fx( const Word16 shift, const Word32 a[], const Word32 x[] FOR( ; i < lg; i++ ) { L_tmp = syn_kern( Mpy_32_32( a0, *x++ ), a, y ); +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( L_tmp, q ); //??sat +#else L_tmp = L_shl_o( L_tmp, q, &Overflow ); +#endif *y++ = L_tmp; move32(); } diff --git a/lib_com/tcx_ltp_fx.c b/lib_com/tcx_ltp_fx.c index 322549a6f0841e9d147075092d263ad85526b9da..b3fe52dd6cf7b324d83420f691cd5dc459927ab9 100644 --- a/lib_com/tcx_ltp_fx.c +++ b/lib_com/tcx_ltp_fx.c @@ -389,9 +389,11 @@ void predict_signal( Word16 j; Word32 s; const Word16 *x0, *win; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif x0 = &excI[-T0 - 1]; frac = negate( frac ); @@ -408,10 +410,17 @@ void predict_signal( FOR( j = 0; j < L_subfr; j++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + s = L_mult_sat( win[0], x0[0] ); /* Qx + 16 */ //??sat + s = L_mac_sat( s, win[1], x0[1] ); /* Qx + 16 */ //??sat + s = L_mac_sat( s, win[2], x0[2] ); /* Qx + 16 */ //??sat + excO[j] = mac_r_sat( s, win[3], x0[3] ); /* Qx + 16 */ //??sat +#else s = L_mult_o( win[0], x0[0], &Overflow ); /* Qx + 16 */ s = L_mac_o( s, win[1], x0[1], &Overflow ); /* Qx + 16 */ s = L_mac_o( s, win[2], x0[2], &Overflow ); /* Qx + 16 */ excO[j] = mac_ro( s, win[3], x0[3], &Overflow ); /* Qx + 16 */ +#endif move16(); x0++; diff --git a/lib_com/tcx_mdct_fx.c b/lib_com/tcx_mdct_fx.c index b2cee32e67e81bb3cd4b8af746959d3d014edd81..135e54af826cd92d22e07cf7cc008c5983b9ab03 100644 --- a/lib_com/tcx_mdct_fx.c +++ b/lib_com/tcx_mdct_fx.c @@ -107,9 +107,11 @@ void TCX_MDCT( Word16 factor, neg_factor; Word16 factor_e; (void) element_mode; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); *y_e = add( *y_e, factor_e ); @@ -126,7 +128,11 @@ void TCX_MDCT( } FOR( i = 0; i < l / 2; i++ ) { - y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#ifdef ISSUE_1836_replace_overflow_libcom + y[m / 2 + r / 2 + m / 2 + i] = L_msu_sat( L_mult( x[i], factor ), x[l - 1 - i], factor ); /* exp(y_e) */ //??sat +#else + y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#endif move32(); } FOR( i = 0; i < m / 2; i++ ) @@ -136,7 +142,11 @@ void TCX_MDCT( } FOR( i = 0; i < r / 2; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_sat( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor ); /* exp(y_e) */ +#else y[m / 2 + r / 2 - 1 - m / 2 - i] = L_mac_o( L_mult( x[l + m + i], neg_factor ), x[l + m + r - 1 - i], neg_factor, &Overflow ); /* exp(y_e) */ +#endif move32(); } @@ -163,9 +173,11 @@ void TCX_MDST( Word16 factor, neg_factor; Word16 factor_e; (void) element_mode; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif factor = TCX_MDCT_GetScaleFactor( add( add( shr( l, 1 ), m ), shr( r, 1 ) ), &factor_e ); /* exp(factor_e) */ *y_e = add( *y_e, factor_e ); @@ -182,7 +194,11 @@ void TCX_MDST( } FOR( i = 0; i < l / 2; i++ ) { - y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], neg_factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#ifdef ISSUE_1836_replace_overflow_libcom + y[m / 2 + r / 2 + m / 2 + i] = L_msu_sat( L_mult( x[i], neg_factor ), x[l - 1 - i], factor ); /* exp(y_e) */ //??sat +#else + y[m / 2 + r / 2 + m / 2 + i] = L_msu_o( L_mult( x[i], neg_factor ), x[l - 1 - i], factor, &Overflow ); /* exp(y_e) */ +#endif move32(); } FOR( i = 0; i < m / 2; i++ ) diff --git a/lib_com/tcx_utils_fx.c b/lib_com/tcx_utils_fx.c index c5ff95e04e68c7904a93ddc7444440333131cded..fa0f7a9dfd6435395904b7f68dc310ee2fa6fb36 100644 --- a/lib_com/tcx_utils_fx.c +++ b/lib_com/tcx_utils_fx.c @@ -991,8 +991,10 @@ void mdct_shaping( Word32 *px = x; /*Qx*/ Word16 const *pgains = gains; Word16 const *pgainsexp = gains_exp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif /* FDNS_NPTS = 64 */ @@ -1044,7 +1046,11 @@ void mdct_shaping( FOR( l = 0; l < k; l++ ) { - *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ +#ifdef ISSUE_1836_replace_overflow_libcom + *x = L_shl_sat( Mpy_32_16_r( *x, *gains ), *gains_exp ); /*Qx*/ +#else + *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ +#endif move32(); x++; } @@ -1063,7 +1069,11 @@ void mdct_shaping( gains_exp = pgainsexp; FOR( i = 0; i < FDNS_NPTS; i++ ) { - *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ +#ifdef ISSUE_1836_replace_overflow_libcom + *x = L_shl_sat( Mpy_32_16_r( *x, *gains ), *gains_exp ); /*Qx*/ +#else + *x = L_shl_o( Mpy_32_16_r( *x, *gains ), *gains_exp, &Overflow ); /*Qx*/ +#endif move32(); x += k; gains++; @@ -1389,9 +1399,11 @@ void PsychAdaptLowFreqDeemph( Word16 i; Word16 max_val, max_e, fac, min, min_e, tmp, tmp_e; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; #endif +#endif assert( lpcGains[0] >= 0x4000 ); @@ -1438,8 +1450,12 @@ void PsychAdaptLowFreqDeemph( L_tmp = BASOP_Util_Log2( L_tmp ); /* Q25 */ L_tmp = L_shr( L_tmp, 7 ); /* 0.0078125f = 1.f/(1<<7) */ L_tmp = BASOP_Util_InvLog2( L_tmp ); /* Q31 */ - tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ - fac = tmp; /* Q15 */ +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = round_fx_sat( L_tmp ); /* Q15 */ +#else + tmp = round_fx_o( L_tmp, &Overflow ); /* Q15 */ +#endif + fac = tmp; /* Q15 */ move16(); /* gradual lowering of lowest 32 bins; DC is lowered by (max_val/tmp)^1/4 */ @@ -2081,8 +2097,10 @@ void tcx_get_gain( Word32 corr, ener; Word16 sx, sy, corr_e, ener_e; Word16 i, tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif maxX = L_deposit_l( 1 ); @@ -2129,7 +2147,11 @@ void tcx_get_gain( ener = L_shl( ener, tmp ); /*Q31 - ener_e + tmp*/ ener_e = sub( ener_e, tmp ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = div_s( abs_s( round_fx_sat( corr ) ), round_fx_sat( ener ) ); /*Q15 - (corr_e - ener_e)*/ +#else tmp = div_s( abs_s( round_fx_o( corr, &Overflow ) ), round_fx_o( ener, &Overflow ) ); /*Q15 - (corr_e - ener_e)*/ +#endif if ( corr < 0 ) tmp = negate( tmp ); diff --git a/lib_com/tns_base.c b/lib_com/tns_base.c index aaf262786f2b56f03539e26998c112ae20795f6d..ab5b41038471801befc0891d290a1b6eda80b629 100644 --- a/lib_com/tns_base.c +++ b/lib_com/tns_base.c @@ -21,7 +21,6 @@ #define HLM_MIN_NRG_FX 32768 /*Q0*/ #define MAX_SUBDIVISIONS 3 - /*---------------------------------------------------------------------------- * Local prototypes *---------------------------------------------------------------------------*/ @@ -439,9 +438,11 @@ Word16 ITF_Detect_fx( Word32 L_tmp, tmp32; Word16 tmpbuf[325]; Word16 n, i; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif move16(); @@ -475,7 +476,11 @@ Word16 ITF_Detect_fx( /* Check threshold HLM_MIN_NRG */ BASOP_SATURATE_WARNING_OFF_EVS; +#ifdef ISSUE_1836_replace_overflow_libcom + tmp32 = L_sub( L_shl_sat( L_tmp, sub( shift, sub( 24, Q ) ) ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#else tmp32 = L_sub( L_shl_o( L_tmp, sub( shift, sub( 24, Q ) ), &Overflow ), 4194304l /*HLM_MIN_NRG Q7*/ ); /*Q7*/ +#endif BASOP_SATURATE_WARNING_ON_EVS; /* get pre-shift for autocorrelation */ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 5e116a286b3e84a2a49b9d36f51595cffa065ff5..cae17e24d424f26e0b353a9bd2cdd0d42e833f58 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -308,18 +308,21 @@ Word16 usquant_fx( /* o: index of the winning codeword */ Word16 idx; Word16 tmp, exp; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* idx = (short)( (x - qlow)/delta + 0.5f); */ exp = norm_s( delta ); - tmp = div_s( shl( 1, sub( 14, exp ) ), delta ); /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */ - L_tmp = L_mult( sub_o( x, qlow, &Overflow ), tmp ); /*Q(31-exp) */ -#ifdef ISSUE_1796_replace_shl_o - idx = extract_l( L_shr_r( L_add( L_tmp, shl_sat( 1, sub( 30, exp ) ) ), sub( 31, exp ) ) ); /*Q0 */ + tmp = div_s( shl( 1, sub( 14, exp ) ), delta ); /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mult( sub_sat( x, qlow ), tmp ); /*Q(31-exp) */ //??sat + idx = extract_l( L_shr_r( L_add( L_tmp, shl_sat( 1, sub( 30, exp ) ) ), sub( 31, exp ) ) ); /*Q0 */ //??sat #else + L_tmp = L_mult( sub_o( x, qlow, &Overflow ), tmp ); /*Q(31-exp) */ idx = extract_l( L_shr_r( L_add( L_tmp, shl_o( 1, sub( 30, exp ), &Overflow ) ), sub( 31, exp ) ) ); /*Q0 */ #endif @@ -327,9 +330,13 @@ Word16 usquant_fx( /* o: index of the winning codeword */ idx = s_max( idx, 0 ); /* *xq = idx*delta + qlow; */ - L_tmp = L_deposit_l( qlow ); /*Qx */ - L_tmp = L_mac( L_tmp, idx, delta ); /*Qx */ - *xq = round_fx_o( L_shl_o( L_tmp, 16, &Overflow ), &Overflow ); /*Qx */ + L_tmp = L_deposit_l( qlow ); /*Qx */ + L_tmp = L_mac( L_tmp, idx, delta ); /*Qx */ +#ifdef ISSUE_1836_replace_overflow_libcom + *xq = round_fx_sat( L_shl_sat( L_tmp, 16 ) ); /*Qx */ +#else + *xq = round_fx_o( L_shl_o( L_tmp, 16, &Overflow ), &Overflow ); /*Qx */ +#endif return idx; } /*-------------------------------------------------------------------* @@ -395,14 +402,20 @@ Word32 sum2_fx( /* o : sum of all squared vector elements { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < lvec; i++ ) { - L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q(2x+1) */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_mac_sat( L_tmp, vec[i], vec[i] ); /*Q(2x+1) */ +#else + L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q(2x+1) */ +#endif } return L_tmp; @@ -456,15 +469,21 @@ Word32 sum2_fx_mod( /* o : sum of all squared vector element { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif L_tmp = L_deposit_l( 0 ); FOR( i = 0; i < lvec; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_add_sat( L_tmp, L_shr( L_mult_sat( vec[i], vec[i] ), 9 ) ); +#else L_tmp = L_add_o( L_tmp, L_shr( L_mult_o( vec[i], vec[i], &Overflow ), 9 ), &Overflow ); +#endif } return L_tmp; @@ -684,7 +703,7 @@ void Copy_Scale_sig( { Word16 i; Word16 tmp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -711,8 +730,8 @@ void Copy_Scale_sig( } FOR( i = 0; i < lg; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - y[i] = shl_sat( x[i], exp0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = shl_sat( x[i], exp0 ); //??sat #else y[i] = shl_o( x[i], exp0, &Overflow ); #endif @@ -733,7 +752,7 @@ void Copy_Scale_sig_16_32_DEPREC( { Word16 i; Word16 tmp; -#ifndef ISSUE_1796_replace_shl_o +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); @@ -755,8 +774,8 @@ void Copy_Scale_sig_16_32_DEPREC( /*Should not happen */ FOR( i = 0; i < lg; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - y[i] = L_deposit_l( shl_sat( x[i], exp0 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = L_deposit_l( shl_sat( x[i], exp0 ) ); //??sat #else y[i] = L_deposit_l( shl_o( x[i], exp0, &Overflow ) ); #endif @@ -772,8 +791,8 @@ void Copy_Scale_sig_16_32_DEPREC( #else assert( exp0 < 16 ); #endif -#ifdef ISSUE_1796_replace_shl_o - tmp = shl_sat( 1, exp0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = shl_sat( 1, exp0 ); //??sat #else tmp = shl_o( 1, exp0, &Overflow ); #endif @@ -793,10 +812,12 @@ void Copy_Scale_sig_16_32_no_sat( { Word16 i; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif IF( exp0 == 0 ) @@ -813,8 +834,8 @@ void Copy_Scale_sig_16_32_no_sat( /*Should not happen */ FOR( i = 0; i < lg; i++ ) { -#ifdef ISSUE_1796_replace_shl_o - y[i] = L_deposit_l( shl_sat( x[i], exp0 ) ); +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = L_deposit_l( shl_sat( x[i], exp0 ) ); //??sat #else y[i] = L_deposit_l( shl_o( x[i], exp0, &Overflow ) ); #endif @@ -822,7 +843,11 @@ void Copy_Scale_sig_16_32_no_sat( } return; } +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( 1, exp0 - 1 ); //??sat +#else L_tmp = L_shl_o( 1, exp0 - 1, &Overflow ); +#endif IF( L_tmp >= 0x7FFF ) { @@ -854,9 +879,11 @@ void Copy_Scale_sig_32_16( { Word16 i; Word16 tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif tmp = add( 16, exp0 ); @@ -864,7 +891,11 @@ void Copy_Scale_sig_32_16( { FOR( i = 0; i < lg; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = round_fx_sat( L_shl_sat( x[i], tmp ) ); +#else y[i] = round_fx_o( L_shl_o( x[i], tmp, &Overflow ), &Overflow ); +#endif move16(); } } @@ -872,7 +903,11 @@ void Copy_Scale_sig_32_16( { FOR( i = 0; i < lg; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = round_fx_sat( x[i] ); //??sat +#else y[i] = round_fx_o( x[i], &Overflow ); +#endif move16(); } } @@ -890,9 +925,11 @@ void Scale_sig32( ) { Word16 i; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif IF( 0 == exp0 ) { @@ -901,7 +938,11 @@ void Scale_sig32( FOR( i = 0; i < lg; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + x[i] = L_shl_sat( x[i], exp0 ); +#else x[i] = L_shl_o( x[i], exp0, &Overflow ); +#endif move32(); /* saturation can occur here */ } } @@ -1896,10 +1937,12 @@ Word16 w_vquant_fx( Word16 tmp; Word16 c, idx, j; Word32 dist, minDist; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif +#endif idx = 0; @@ -1916,6 +1959,28 @@ Word16 w_vquant_fx( { dist = L_deposit_l( 0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = sub_sat( x[3], shr( cb[j++], Qx ) ); //??sat + if ( weights[3] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[2], shr( cb[j++], Qx ) ); //??sat + if ( weights[2] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[1], shr( cb[j++], Qx ) ); //??sat + if ( weights[1] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[0], shr( cb[j++], Qx ) ); //??sat + if ( weights[0] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } +#else tmp = sub_o( x[3], shr( cb[j++], Qx ), &Overflow ); if ( weights[3] != 0 ) { @@ -1936,6 +2001,7 @@ Word16 w_vquant_fx( { dist = L_mac0_o( dist, tmp, tmp, &Overflow ); } +#endif if ( LT_32( dist, minDist ) ) { idx = c; @@ -1965,6 +2031,28 @@ Word16 w_vquant_fx( { dist = L_deposit_l( 0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = sub_sat( x[0], shr( cb[j++], Qx ) ); //??sat + if ( weights[0] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[1], shr( cb[j++], Qx ) ); //??sat + if ( weights[1] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[2], shr( cb[j++], Qx ) ); //??sat + if ( weights[2] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } + tmp = sub_sat( x[3], shr( cb[j++], Qx ) ); //??sat + if ( weights[3] != 0 ) + { + dist = L_mac0_sat( dist, tmp, tmp ); //??sat + } +#else tmp = sub_o( x[0], shr( cb[j++], Qx ), &Overflow ); if ( weights[0] != 0 ) { @@ -1985,6 +2073,7 @@ Word16 w_vquant_fx( { dist = L_mac0_o( dist, tmp, tmp, &Overflow ); } +#endif if ( LT_32( dist, minDist ) ) { idx = c; @@ -2451,9 +2540,11 @@ Word32 root_a_over_b_fx( Word16 tmp, num, den, scale; Word16 exp, exp_num, exp_den; Word32 L_tmp; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif test(); IF( ( a <= 0 ) || ( b <= 0 ) ) @@ -2464,15 +2555,23 @@ Word32 root_a_over_b_fx( } exp_num = norm_l( b ); +#ifdef ISSUE_1836_replace_overflow_libcom + num = round_fx_sat( L_shl_sat( b, exp_num ) ); //??sat +#else num = round_fx_o( L_shl_o( b, exp_num, &Overflow ), &Overflow ); +#endif exp_num = sub( sub( 30, exp_num ), Q_b ); exp_den = norm_l( a ); +#ifdef ISSUE_1836_replace_overflow_libcom + den = round_fx_sat( L_shl_sat( a, exp_den ) ); //??sat +#else den = round_fx_o( L_shl_o( a, exp_den, &Overflow ), &Overflow ); +#endif exp_den = sub( sub( 30, exp_den ), Q_a ); scale = shr( sub( den, num ), 15 ); -#ifdef ISSUE_1796_replace_shl_o +#ifdef ISSUE_1836_replace_overflow_libcom //??sat num = shl_sat( num, scale ); #else num = shl_o( num, scale, &Overflow ); @@ -2632,9 +2731,11 @@ void fir_fx( const Word16 x[], /* i : input vector Word16 buf_in[L_FRAME32k + L_FILT_MAX]; Word16 i, j; Word32 s; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* prepare the input buffer (copy and update memory) */ Copy( mem, buf_in, K ); @@ -2647,14 +2748,27 @@ void fir_fx( const Word16 x[], /* i : input vector /* do the filtering */ FOR( i = 0; i < L; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + s = L_mult_sat( buf_in[K + i], h[0] ); //??sat +#else s = L_mult_o( buf_in[K + i], h[0], &Overflow ); +#endif FOR( j = 1; j <= K; j++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + s = L_mac_sat( s, h[j], buf_in[K + i - j] ); //??sat +#else s = L_mac_o( s, h[j], buf_in[K + i - j], &Overflow ); +#endif } +#ifdef ISSUE_1836_replace_overflow_libcom + s = L_shl_sat( s, shift ); //??sat + y[i] = round_fx_sat( s ); /*Qx */ //??sat +#else s = L_shl_o( s, shift, &Overflow ); y[i] = round_fx_o( s, &Overflow ); /*Qx */ +#endif move16(); } } @@ -2790,8 +2904,10 @@ Word16 squant_fx( /* o: index of the winning codeword */ Word16 tmp; Word16 c, idx; Word32 L_mindist, L_dist; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#endif #endif idx = 0; @@ -2802,10 +2918,18 @@ Word16 squant_fx( /* o: index of the winning codeword */ FOR( c = 0; c < cbsize; c++ ) { L_dist = L_deposit_l( 0 ); +#ifdef ISSUE_1836_replace_overflow_libcom + tmp = sub_sat( x, cb[c] ); +#else tmp = sub_o( x, cb[c], &Overflow ); +#endif /*dist += tmp*tmp; */ +#ifdef ISSUE_1836_replace_overflow_libcom + L_dist = L_mac_sat( L_dist, tmp, tmp ); //??sat +#else L_dist = L_mac_o( L_dist, tmp, tmp, &Overflow ); +#endif if ( LT_32( L_dist, L_mindist ) ) { @@ -2943,9 +3067,11 @@ void Copy_Scale_sig32( Word16 i; Word32 L_tmp; Word16 tmp = exp0; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif IF( exp0 == 0 ) { @@ -2960,12 +3086,20 @@ void Copy_Scale_sig32( { FOR( i = 0; i < lg; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = L_shl_sat( x[i], tmp ); //??sat +#else y[i] = L_shl_o( x[i], tmp, &Overflow ); +#endif move16(); } return; } +#ifdef ISSUE_1836_replace_overflow_libcom + L_tmp = L_shl_sat( 1, exp0 - 1 ); //??sat +#else L_tmp = L_shl_o( 1, exp0 - 1, &Overflow ); +#endif FOR( i = 0; i < lg; i++ ) { y[i] = W_extract_l( W_mult_32_32( L_tmp, x[i] ) ); @@ -3142,9 +3276,11 @@ void add_vec_fx( ) { Word16 i, Qyx1, Qyx2; +#ifndef ISSUE_1836_replace_overflow_libcom #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif Qyx1 = sub( Qx1, Qy ); Qyx2 = sub( Qx2, Qy ); @@ -3152,7 +3288,11 @@ void add_vec_fx( { FOR( i = 0; i < N; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = add_sat( x1[i], shr_r_sat( x2[i], Qyx2 ) ); //??sat //??sat +#else y[i] = add_o( x1[i], shr_r_sat( x2[i], Qyx2 ), &Overflow ); +#endif move16(); } } @@ -3160,7 +3300,11 @@ void add_vec_fx( { FOR( i = 0; i < N; i++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + y[i] = add_sat( shr_r_sat( x1[i], Qyx1 ), shr_r_sat( x2[i], Qyx2 ) ); //??sat //!!sat //!!sat +#else y[i] = add_o( shr_r_sat( x1[i], Qyx1 ), shr_r_sat( x2[i], Qyx2 ), &Overflow ); +#endif move16(); } } @@ -3287,7 +3431,11 @@ Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) FOR( i = 0; i < j; i++ ) { /* divide by 2 so energy will be divided by 4 */ +#ifdef ISSUE_1836_replace_overflow_libcom + temp = mult_r( *signal++, 16384 ); +#else temp = mult_ro( *signal++, 16384, &Overflow ); +#endif L_Energy = L_mac0_o( L_Energy, temp, temp, &Overflow ); } FOR( i = j; i < len; i += 8 ) /* Process 8 Samples at a time */ @@ -3297,7 +3445,11 @@ Word32 Calc_Energy_Autoscaled( /* o: Result (Energy) L_temp = L_mult0( temp, temp ); FOR( j = 1; j < 8; j++ ) { +#ifdef ISSUE_1836_replace_overflow_libcom + temp = mult_r( *signal++, 16384 ); +#else temp = mult_ro( *signal++, 16384, &Overflow ); +#endif L_temp = L_mac0_o( L_temp, temp, temp, &Overflow ); } #ifdef ISSUE_1799_replace_L_shr_o