diff --git a/lib_com/deemph_fx.c b/lib_com/deemph_fx.c index 9bc20cb6f6892b86fe023ff163fa8272ec9cc7bb..523061b9808f6bf61038b4c909884fa39f64f9a5 100644 --- a/lib_com/deemph_fx.c +++ b/lib_com/deemph_fx.c @@ -197,8 +197,12 @@ void E_UTIL_deemph2( Word16 shift, Word16 *x, const Word16 mu, const Word16 L, W { FOR( i = 0; i < L; i++ ) { +#ifdef ISSUE_1772_replace_shr_o + 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*/ +#else L_tmp = L_msu_o( Mpy_32_16_1( L_tmp, mu ), shr_o( x[i], shift, &Overflow ), -32768 /*1.0f in Q15*/, &Overflow ); /*Qx-shift+16*/ - x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ +#endif + x[i] = round_fx_o( L_tmp, &Overflow ); /*Qx-shift*/ move16(); } } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index e51d2807b10162a20e29b17dca29ab55a8e7c13a..1860744457d8d605bd2422dc59753c169e00758b 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -96,8 +96,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 = div_s( 13107, accuracy ); /* 0.05 in Q18 */ +#ifdef ISSUE_1772_replace_shr_o + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ +#else tmp = shr_o( tmp, sub( 34, exp ), &Overflow ); /*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 */ @@ -204,8 +208,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 = div_s( 13107, accuracy ); /* 0.05 in Q18 */ +#ifdef ISSUE_1772_replace_shr_o + tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ +#else tmp = shr_o( tmp, sub( 34, exp ), &Overflow ); /*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/options.h b/lib_com/options.h index dd32167b9169ff4864904770b674463b566e938b..25579d5b0749371393bba402523e04201bc4ffa8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -103,5 +103,6 @@ #define FIX_1762_COMPILER_ISSUE /* FhG: fix compiler issues with W_mac_32_32() + ONE_IN_Q30 */ #define ISSUE_1751_replace_shl_ro /*FhG: replace shl_ro by overflow-free alternatives*/ #define ISSUE_1770_replace_shr_ro /* FhG: replace by non-overflow-alternative - BE */ +#define ISSUE_1772_replace_shr_o /* FhG: replace by non-overflow-alternative - BE */ #endif diff --git a/lib_com/syn_filt_fx.c b/lib_com/syn_filt_fx.c index ada0d243ea88b7c08fdb6ac8bd5d8720f9eb7f8f..1216c4533f0955530ca6612e47f70007bf0d6dd4 100644 --- a/lib_com/syn_filt_fx.c +++ b/lib_com/syn_filt_fx.c @@ -188,14 +188,20 @@ void syn_filt_fx( Word16 *yy; Word32 s; Word16 q; +#ifndef ISSUE_1772_replace_shr_o Flag Overflow = 0; move16(); +#endif Word16 a0; yy = &buf[0]; q = add( norm_s( a[0] ), 1 ); +#ifdef ISSUE_1772_replace_shr_o + a0 = shr_sat( a[0], shift ); /* input / 2^shift */ +#else a0 = shr_o( a[0], shift, &Overflow ); /* input / 2^shift */ +#endif /*------------------------------------------------------------------* * copy initial filter states into synthesis buffer and do synthesis @@ -373,7 +379,11 @@ void E_UTIL_synthesis( const Word16 shift, const Word16 a[], const Word16 x[], W *-----------------------------------------------------------------------*/ mem += m; /*move16();*/ +#ifdef ISSUE_1772_replace_shr_o + a0 = shr_sat( a[0], shift ); /* input / 2^shift */ +#else a0 = shr_o( a[0], shift, &Overflow ); /* input / 2^shift */ +#endif /*-----------------------------------------------------------------------* * Do the filtering *-----------------------------------------------------------------------*/ diff --git a/lib_dec/FEC_HQ_core_fx.c b/lib_dec/FEC_HQ_core_fx.c index cc03dcf525f424e500118ee9f8d2362c74ebedd3..40e26df9c1d6c2348031ad11bbb9133df9cda173 100644 --- a/lib_dec/FEC_HQ_core_fx.c +++ b/lib_dec/FEC_HQ_core_fx.c @@ -638,7 +638,11 @@ void ivas_HQ_FEC_Mem_update_fx( exp2 = norm_l( hHQ_nbfec->ynrm_values_fx[i][0] ); tmp_fx = div_s( extract_h( L_shl( en_high_fx[i], exp1 ) ), extract_h( L_shl( hHQ_nbfec->ynrm_values_fx[i][0], exp2 ) ) ); exp = add( 15, sub( exp1, exp2 ) ); +#ifdef ISSUE_1772_replace_shr_o + *mean_en_high_fx = add_o( *mean_en_high_fx, shr_sat( tmp_fx, sub( exp, 5 ) ), &Overflow ); +#else *mean_en_high_fx = add_o( *mean_en_high_fx, shr_o( tmp_fx, sub( exp, 5 ), &Overflow ), &Overflow ); +#endif move16(); } *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[sub( num_Sb, k )] ); @@ -924,7 +928,11 @@ void HQ_FEC_Mem_update_fx( exp2 = norm_l( hHQ_nbfec->ynrm_values_fx[i][0] ); tmp_fx = div_s( extract_h( L_shl( en_high_fx[i], exp1 ) ), extract_h( L_shl( hHQ_nbfec->ynrm_values_fx[i][0], exp2 ) ) ); exp = add( 15, sub( exp1, exp2 ) ); +#ifdef ISSUE_1772_replace_shr_o + *mean_en_high_fx = add_o( *mean_en_high_fx, shr_sat( tmp_fx, sub( exp, 5 ) ), &Overflow ); +#else *mean_en_high_fx = add_o( *mean_en_high_fx, shr_o( tmp_fx, sub( exp, 5 ), &Overflow ), &Overflow ); +#endif move16(); } *mean_en_high_fx = mult( *mean_en_high_fx, inv_tbl_fx[sub( num_Sb, k )] ); diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index ad2f8607311a94fdc8a81ec9955dd2e16e97bb04..7c4c91936631f0f6c4fd64ecb9bd4ae7e44bbd8a 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -1164,9 +1164,11 @@ static Word16 imax_fx( /* o: The location, relative to the Word16 y1, y2, y3, man, expo, edge; const Word16 *pY; Word32 numer, denom, sign, acc, y3_y1; +#ifndef ISSUE_1772_replace_shr_o #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); +#endif #endif /* Seek the extremum of the parabola P(x) defined by 3 consecutive points so that P([-1 0 1]) = [y1 y2 y3] */ @@ -1200,9 +1202,13 @@ static Word16 imax_fx( /* o: The location, relative to the } /* Although the output of ratio() is in Q14, adding the missing factor of 2 (See above) * in the denominator, the output is now considered to be in Q15. */ - man = ratio( numer, denom, &expo ); /* The mantissa is considered in Q15 */ + man = ratio( numer, denom, &expo ); /* The mantissa is considered in Q15 */ +#ifdef ISSUE_1772_replace_shr_o + posi = shr_sat( man, expo ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ +#else posi = shr_o( man, expo, &Overflow ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ - if ( sign < 0 ) /* Restore the sign. */ +#endif + if ( sign < 0 ) /* Restore the sign. */ { posi = negate( posi ); } diff --git a/lib_enc/ari_hm_enc_fx.c b/lib_enc/ari_hm_enc_fx.c index 343f1890fd01b79e821a02184d77e8383bc8d3fd..1172bd890a4f8a96883f9fec9b5f10041047b02a 100644 --- a/lib_enc/ari_hm_enc_fx.c +++ b/lib_enc/ari_hm_enc_fx.c @@ -458,7 +458,11 @@ Word16 SearchPeriodicityIndex_fx( tmp = sub( norm_l( tmp32 ), 1 ); tmp2 = norm_l( AbsTotal ); tmp3 = div_s( round_fx_o( L_shl_o( tmp32, tmp, &Overflow ), &Overflow ), round_fx_o( L_shl_o( AbsTotal, tmp2, &Overflow ), &Overflow ) ); +#ifdef ISSUE_1772_replace_shr_o + *RelativeScore = shr_sat( tmp3, add( sub( tmp, tmp2 ), 2 ) ); /* -> 2Q13 */ +#else *RelativeScore = shr_o( tmp3, add( sub( tmp, tmp2 ), 2 ), &Overflow ); /* -> 2Q13 */ +#endif move16(); } ELSE diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 27f3d2aa6697f9d88264ca14b3a8452595d9de08..c8fab11a91ed6679f9e42728d3131b390a6b1285 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -2604,7 +2604,11 @@ void QuantizeSpectrum_fx( /* scale output */ FOR( i = 0; i < L_frame; i++ ) { +#ifdef ISSUE_1772_replace_shr_o + xn_buf16[i] = shr_sat( xn_buf16[i], Q ); +#else xn_buf16[i] = shr_o( xn_buf16[i], Q, &Overflow ); +#endif move16(); } @@ -4523,7 +4527,11 @@ void InternalTCXDecoder_fx( /* scale output */ FOR( i = 0; i < L_frame; i++ ) { +#ifdef ISSUE_1772_replace_shr_o + xn_buf16[i] = shr_sat( xn_buf16[i], Q ); +#else xn_buf16[i] = shr_o( xn_buf16[i], Q, &Overflow ); +#endif move16(); } diff --git a/lib_enc/enc_gen_voic_rf_fx.c b/lib_enc/enc_gen_voic_rf_fx.c index e9c9d87f74bfa057d719079170b1496c85b61887..8d9e1e1a13a1b817dcfb88714741bdd2ca1b59fc 100644 --- a/lib_enc/enc_gen_voic_rf_fx.c +++ b/lib_enc/enc_gen_voic_rf_fx.c @@ -449,7 +449,11 @@ void coder_acelp_rf_fx( Ltmp = L_add_o( Ltmp, Ltmp2, &Overflow ); /* Q15 + Q_xn */ hRF->rf_mem_w0 = sub_o( xn[L_SUBFR - 1], round_fx_o( L_shl_o( Ltmp, 1, &Overflow ), &Overflow ), &Overflow ); /* Q_xn */ move16(); +#ifdef ISSUE_1772_replace_shr_o + hRF->rf_mem_w0 = shr_sat( hRF->rf_mem_w0, shift ); /*Qnew-1*/ +#else hRF->rf_mem_w0 = shr_o( hRF->rf_mem_w0, shift, &Overflow ); /*Qnew-1*/ +#endif /*-------------------------------------------------------* diff --git a/lib_enc/gaus_enc_fx.c b/lib_enc/gaus_enc_fx.c index 2aa9a5dfff887f9e1fd502971505046bb588201e..1efe1f656cf3ad523a83224221c81bc8cae05718 100644 --- a/lib_enc/gaus_enc_fx.c +++ b/lib_enc/gaus_enc_fx.c @@ -362,8 +362,12 @@ void gauss2v_fx( exp_den = norm_l( Lden ); Den = extract_h( L_shl( Lden, exp_den ) ); +#ifdef ISSUE_1772_replace_shr_o + delta = shr_sat( div_s( Num, Den ), sub( exp_num, exp_den ) ); /* Q15 */ +#else delta = shr_o( div_s( Num, Den ), sub( exp_num, exp_den ), &Overflow ); /* Q15 */ - delta = i_mult2( delta, m_sign ); /* Apply sign Q0*/ +#endif + delta = i_mult2( delta, m_sign ); /* Apply sign Q0*/ /* index_delta = (short)(FAC_DELTA * fdelta) */ index_delta = shr( delta, SFAC_DELTA ); @@ -823,8 +827,12 @@ void gauss2v_ivas_fx( exp_den = norm_l( Lden ); Den = extract_h( L_shl( Lden, exp_den ) ); +#ifdef ISSUE_1772_replace_shr_o + delta = shr_sat( div_s( Num, Den ), sub( exp_num, exp_den ) ); /* Q15 */ +#else delta = shr_o( div_s( Num, Den ), sub( exp_num, exp_den ), &Overflow ); /* Q15 */ - delta = i_mult2( delta, m_sign ); /* Apply sign */ +#endif + delta = i_mult2( delta, m_sign ); /* Apply sign */ /* index_delta = (short)(FAC_DELTA * fdelta) */ index_delta = shr( delta, SFAC_DELTA ); diff --git a/lib_enc/multi_harm_fx.c b/lib_enc/multi_harm_fx.c index 1bae597b6892428a06b6c83e1b0de38121329432..c49c405b51a26ea49489b63b4ecceef0ea2d2e61 100644 --- a/lib_enc/multi_harm_fx.c +++ b/lib_enc/multi_harm_fx.c @@ -238,7 +238,11 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity corxy = shl( corxy, cor ); /* cor = corxy * corxy / (corx2 * cory2) */ corxy = div_s( corxy, corx2 ); +#ifdef ISSUE_1772_replace_shr_o + cor = shr_sat( corxy, sub( shl( tmp16, 1 ), Expx2 ) ); /* Q15 */ +#else cor = shr_o( corxy, sub( shl( tmp16, 1 ), Expx2 ), &Overflow ); /* Q15 */ +#endif } ELSE { @@ -575,7 +579,11 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni corxy = shl( corxy, cor ); /* cor = corxy * corxy / (corx2 * cory2) */ corxy = div_s( corxy, corx2 ); +#ifdef ISSUE_1772_replace_shr_o + cor = shr_sat( corxy, sub( shl( tmp16, 1 ), Expx2 ) ); /* Q15 */ +#else cor = shr_o( corxy, sub( shl( tmp16, 1 ), Expx2 ), &Overflow ); /* Q15 */ +#endif } ELSE { diff --git a/lib_enc/set_impulse_fx.c b/lib_enc/set_impulse_fx.c index d4dd73abe8ea2be7536ea15ce15c6270737b279f..364d78f97d57c3cf7a6243b1243a59e44c6a7797 100644 --- a/lib_enc/set_impulse_fx.c +++ b/lib_enc/set_impulse_fx.c @@ -201,7 +201,11 @@ void set_impulse_fx( den = extract_h( L_shl( rr_fx[i], exp_den ) ); num = div_s( num, den ); +#ifdef ISSUE_1772_replace_shr_o + krit_fx = shr_sat( num, sub( sub( shl_o( exp_num, 1, &Overflow ), exp_den ), 2 ) ); /* Q18 */ +#else krit_fx = shr_o( num, sub( sub( shl_o( exp_num, 1, &Overflow ), exp_den ), 2 ), &Overflow ); /* Q18 */ +#endif IF( GT_16( krit_fx, krit_max_fx ) ) { diff --git a/lib_enc/stat_noise_uv_enc_fx.c b/lib_enc/stat_noise_uv_enc_fx.c index 24932542ce178bea11bb597e42f06d43d7575017..8dfb407383675c291905f6b0d04841b2f294b1d4 100644 --- a/lib_enc/stat_noise_uv_enc_fx.c +++ b/lib_enc/stat_noise_uv_enc_fx.c @@ -67,10 +67,14 @@ void stat_noise_uv_enc_fx( expn = sub( norm_l( LepsP[0] ), 1 ); num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/ expd = norm_l( LepsP[1] ); - den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ - num = div_s( num, den ); /*expn-expd+15*/ + den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ + num = div_s( num, den ); /*expn-expd+15*/ +#ifdef ISSUE_1772_replace_shr_o + num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ +#else num = shr_o( num, add( sub( expn, expd ), 5 ), &Overflow ); /*Q10*/ - num = sub( num, 1024 ); /*num - 1*/ +#endif + num = sub( num, 1024 ); /*num - 1*/ test(); IF( NE_16( st_fx->bwidth, NB ) ) @@ -140,10 +144,14 @@ void stat_noise_uv_enc_ivas_fx( expn = sub( norm_l( LepsP[0] ), 1 ); num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/ expd = norm_l( LepsP[1] ); - den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ - num = div_s( num, den ); /*expn-expd+15*/ + den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/ + num = div_s( num, den ); /*expn-expd+15*/ +#ifdef ISSUE_1772_replace_shr_o + num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/ +#else num = shr_o( num, add( sub( expn, expd ), 5 ), &Overflow ); /*Q10*/ - num = sub( num, 1024 ); /*num - 1*/ +#endif + num = sub( num, 1024 ); /*num - 1*/ test(); IF( NE_16( st_fx->bwidth, NB ) )