From 57d7caa25928e1643093afec19b242603c082b93 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 26 Aug 2024 11:09:36 -0400 Subject: [PATCH 1/3] fix possible saturations when shl reach max values, changes under FIX_860_FER_CRASH --- lib_com/options.h | 3 +++ lib_com/tools_fx.c | 12 +++++++++++- lib_dec/ivas_stereo_dft_dec_fx.c | 12 ++++++++++++ lib_dec/ivas_stereo_icbwe_dec.c | 8 ++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 7079776b0..d19e9d6b8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -171,6 +171,9 @@ #define FIX_854_HILBERT_SCALING /* VA: reduce lost of precision due to unnecessary scaling, reduce a lot the 2 kHz tone */ #define FIX_856_EXTRACT_L /* VA: Fix undesirable wrap-around */ #define FIX_835_PARAMMC_BUFFER_VALUES /* FhG: issue 835: wide range of buffer values for cx in ParamMC */ + +#define FIX_860_FER_CRASH /* VA: fix crash issues caused by saturation within shl */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index d0b3dd0dd..2ac0d4866 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -4474,12 +4474,22 @@ void v_add_fixed_me( Word16 x1_shift = sub( s_max( x1_e, x2_e ), x1_e ); Word16 x2_shift = sub( s_max( x1_e, x2_e ), x2_e ); +#if 1//def IMPRO_PRECISION + Word32 hdrm_x1_shift = L_shl_sat( 1, add( hdrm, sub( 31, x1_shift ) ) ); + Word32 hdrm_x2_shift = L_shl_sat( 1, add( hdrm, sub( 31, x2_shift ) ) ); FOR( i = 0; i < N; i++ ) { - y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); + y[i] = W_round64_L( W_mac_32_32( W_mult_32_32( x1[i], hdrm_x1_shift ), x2[i], hdrm_x2_shift ) ); move32(); } +#else + FOR( i = 0; i < N; i++ ) + { + y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); + move32(); + } +#endif *y_e = add( s_max( x1_e, x2_e ), hdrm ); move16(); diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index c4988417f..a03d520f9 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -3676,7 +3676,11 @@ void stereo_dft_dec_read_BS_fx( { hStereoDft->side_gain_index_previous[b] = ind1[b]; move16(); +#ifdef FIX_860_FER_CRASH + hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl_sat( ind1[b], 26 ); +#else hStereoDft->res_gains_ind_fx[0][b + STEREO_DFT_BAND_MAX] = L_shl( ind1[b], 26 ); +#endif move32(); } @@ -3866,7 +3870,11 @@ void stereo_dft_dec_read_BS_fx( stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); hStereoDft->res_pred_index_previous[b] = I; move16(); +#ifdef FIX_860_FER_CRASH + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); +#else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); +#endif move32(); } @@ -3891,7 +3899,11 @@ void stereo_dft_dec_read_BS_fx( stereo_dft_dequantize_res_gains_fx( ind1 + b, &I, hStereoDft->side_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), hStereoDft->res_pred_gain_fx + add( i_mult( add( k, k_offset ), STEREO_DFT_BAND_MAX ), b ), 1 ); hStereoDft->res_pred_index_previous[b] = I; move16(); +#ifdef FIX_860_FER_CRASH + hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl_sat( I, 26 ); +#else hStereoDft->res_gains_ind_fx[1][b + STEREO_DFT_BAND_MAX] = L_shl( I, 26 ); +#endif move32(); } } diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index 5476af31c..f48df2559 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -1209,7 +1209,11 @@ void stereo_icBWE_dec_fx( tmp = shl( tmp, 2 ); icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, ratio_L_fx, &temp2_fx ); +#ifdef FIX_860_FER_CRASH + icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 +#else icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 +#endif } ELSE { @@ -1238,7 +1242,11 @@ void stereo_icBWE_dec_fx( tmp = shl( tmp, 2 ); icbweM2Ref_fx = Sqrt16( sub( 16384, tmp ), &temp1_fx ); icbweM2Ref_fx = BASOP_Util_Divide1616_Scale( icbweM2Ref_fx, sub( 32767, ratio_L_fx ), &temp2_fx ); +#ifdef FIX_860_FER_CRASH + icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 +#else icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 +#endif } ELSE { -- GitLab From 7ff8508a7b560ac95555cf8fc9212420ac9d735f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 26 Aug 2024 11:11:51 -0400 Subject: [PATCH 2/3] remove un-desired code modification --- lib_com/tools_fx.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index 2ac0d4866..d0b3dd0dd 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -4474,22 +4474,12 @@ void v_add_fixed_me( Word16 x1_shift = sub( s_max( x1_e, x2_e ), x1_e ); Word16 x2_shift = sub( s_max( x1_e, x2_e ), x2_e ); -#if 1//def IMPRO_PRECISION - Word32 hdrm_x1_shift = L_shl_sat( 1, add( hdrm, sub( 31, x1_shift ) ) ); - Word32 hdrm_x2_shift = L_shl_sat( 1, add( hdrm, sub( 31, x2_shift ) ) ); - FOR( i = 0; i < N; i++ ) - { - y[i] = W_round64_L( W_mac_32_32( W_mult_32_32( x1[i], hdrm_x1_shift ), x2[i], hdrm_x2_shift ) ); - move32(); - } -#else - FOR( i = 0; i < N; i++ ) { y[i] = L_add( L_shr( x1[i], hdrm + x1_shift ), L_shr( x2[i], hdrm + x2_shift ) ); move32(); } -#endif + *y_e = add( s_max( x1_e, x2_e ), hdrm ); move16(); -- GitLab From 3dfdddb5ffe219867f09536daf801a50fb3104e4 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 26 Aug 2024 11:14:04 -0400 Subject: [PATCH 3/3] correct clang-format --- lib_dec/ivas_stereo_icbwe_dec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index f48df2559..76ebdf310 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -1212,7 +1212,7 @@ void stereo_icBWE_dec_fx( #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 #else - icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 + icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 #endif } ELSE @@ -1245,7 +1245,7 @@ void stereo_icBWE_dec_fx( #ifdef FIX_860_FER_CRASH icbweM2Ref_fx = shl_sat( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 #else - icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 + icbweM2Ref_fx = shl( icbweM2Ref_fx, add( temp2_fx, sub( temp1_fx, 1 ) ) ); // Q14 #endif } ELSE -- GitLab