From 8e5a2afdae4d71b2a2b2f52d3423aba6e38c3977 Mon Sep 17 00:00:00 2001 From: gerstack Date: Wed, 23 Jul 2025 14:32:47 +0200 Subject: [PATCH 01/14] ISSUE 1817, MR less ~/tmp/out_print --- lib_dec/dec_tcx_fx.c | 25 ++++++++++ lib_dec/fd_cng_dec_fx.c | 101 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 8009c69e0..7319ef6ac 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1859,6 +1859,7 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) +#if 0 { Word16 i; Word32 L_sum, L_c; @@ -1895,6 +1896,30 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul L_sum = norm_llQ31( L_c, L_sum, exp ); return L_sum; } +#else +{ + Word16 i; + Word32 L_sum; + Word64 L_sum64; + Word16 sh; + + L_sum64 = W_deposit32_l( L_off ); + + FOR( i = 0; i < lg; i+=2 ) + { + L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); + } +#if 0 + L_sum = w_norm_llQ31( L_sum64, exp ); +#else + sh = W_norm( L_sum64 ); + L_sum = W_extract_h( W_shl(L_sum64, sh) ); + *exp = (L_sum == 0) ? -32 : 32 - sh; +#endif /* 0/1 use of w_norm_llQ31() */ + return L_sum; +} +#endif /* 0/1 legacy */ + void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 501276dfc..2416fb68e 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -555,6 +555,16 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ +static inline Word32 w_norm_llQ31_inl( Word64 L64_var1, Word16 *S_var2 ) /*Q31 - L_tmp_exp*/ +{ + Word32 L_result; + Word16 sh = W_norm( L64_var1 ); + L_result = W_extract_h( W_shl(L64_var1, sh) ); + *S_var2 = (L_result == 0) ? -32 : 32 - sh; + return L_result; +} + + Word16 ApplyFdCng_fx( Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, @@ -576,13 +586,17 @@ Word16 ApplyFdCng_fx( Word16 facTab[NPART]; Word16 facTabExp[NPART]; Word16 tmp_loop; +#if 0 Word32 L_c; +#endif Word16 lsp_cng[M]; HANDLE_FD_CNG_DEC hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; +#if 0 Flag Carry = 0; +#endif move16(); move16(); #endif @@ -794,6 +808,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -826,6 +841,27 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); +#else + { + Word64 W_tmp = 0; + FOR( j = 0; j < tmp_loop; j++ ) + { + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j )); /*Q31*/ + + } + L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + } + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp*/ + + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); + L_tmp_exp = add( L_tmp_exp, 1 ); +#endif st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } @@ -833,6 +869,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -863,12 +900,32 @@ Word16 ApplyFdCng_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ +#else + { + Word64 W_tmp = 0; + FOR( j = 0; j < tmp_loop; j++ ) + { + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j )); /*Q31 - L_tmp_exp*/ + } + L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + } + L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16 )); /*->Q31, L_tmp_exp*/ + + + st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ +#endif move16(); st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -900,6 +957,30 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); +#else + { + Word64 W_tmp = 0; + FOR( j = 0; j < tmp_loop; j++ ) + { + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ + } +#if 0 + L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ +#else + L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ +#endif + } + L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shr( L_mac( -28000, st->L_frame, 95 ), 15 - 1)] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp */ + + st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); + +#endif st->cngTDLevel_e = L_tmp_exp; move16(); } @@ -1018,6 +1099,7 @@ Word16 ApplyFdCng_fx( /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -1049,6 +1131,25 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); +#else + { + Word64 W_tmp = 0; + FOR( j = 0; j < tmp_loop; j++ ) + { + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ + } + L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + } + L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); + + L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ + + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp*/ + + st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ + move16(); +#endif st->cngTDLevel_e = L_tmp_exp; move16(); BREAK; -- GitLab From 653045804dc140fad830fee2fe1934887afc4bdd Mon Sep 17 00:00:00 2001 From: gerstack Date: Wed, 23 Jul 2025 14:42:13 +0200 Subject: [PATCH 02/14] ISSUE 1817, MR less 1931, clang-format --- lib_dec/dec_tcx_fx.c | 15 +++++++-------- lib_dec/fd_cng_dec_fx.c | 37 ++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 7319ef6ac..4e43998f4 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1858,8 +1858,8 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul const Word16 x[], /* i : x vector Qn */ const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ -) -#if 0 + ) +#if 0 { Word16 i; Word32 L_sum, L_c; @@ -1905,24 +1905,23 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul L_sum64 = W_deposit32_l( L_off ); - FOR( i = 0; i < lg; i+=2 ) + FOR( i = 0; i < lg; i += 2 ) { L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); } -#if 0 +#if 0 L_sum = w_norm_llQ31( L_sum64, exp ); #else sh = W_norm( L_sum64 ); - L_sum = W_extract_h( W_shl(L_sum64, sh) ); - *exp = (L_sum == 0) ? -32 : 32 - sh; + L_sum = W_extract_h( W_shl( L_sum64, sh ) ); + *exp = ( L_sum == 0 ) ? -32 : 32 - sh; #endif /* 0/1 use of w_norm_llQ31() */ return L_sum; } #endif /* 0/1 legacy */ - -void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) + void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) { const TCX_CONFIG_HANDLE tcx_cfg = st->hTcxCfg; Word16 tmp_offset; diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 2416fb68e..01db0750c 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -559,8 +559,8 @@ static inline Word32 w_norm_llQ31_inl( Word64 L64_var1, Word16 *S_var2 ) /*Q31 - { Word32 L_result; Word16 sh = W_norm( L64_var1 ); - L_result = W_extract_h( W_shl(L64_var1, sh) ); - *S_var2 = (L_result == 0) ? -32 : 32 - sh; + L_result = W_extract_h( W_shl( L64_var1, sh ) ); + *S_var2 = ( L_result == 0 ) ? -32 : 32 - sh; return L_result; } @@ -586,7 +586,7 @@ Word16 ApplyFdCng_fx( Word16 facTab[NPART]; Word16 facTabExp[NPART]; Word16 tmp_loop; -#if 0 +#if 0 Word32 L_c; #endif Word16 lsp_cng[M]; @@ -594,7 +594,7 @@ Word16 ApplyFdCng_fx( HANDLE_FD_CNG_COM hFdCngCom; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#if 0 +#if 0 Flag Carry = 0; #endif move16(); @@ -808,7 +808,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -846,8 +846,7 @@ Word16 ApplyFdCng_fx( Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { - W_tmp = W_add( W_tmp, *( cngNoiseLevel + j )); /*Q31*/ - + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31*/ } L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ } @@ -856,7 +855,7 @@ Word16 ApplyFdCng_fx( L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); @@ -869,7 +868,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -905,7 +904,7 @@ Word16 ApplyFdCng_fx( Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { - W_tmp = W_add( W_tmp, *( cngNoiseLevel + j )); /*Q31 - L_tmp_exp*/ + W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ } @@ -914,7 +913,7 @@ Word16 ApplyFdCng_fx( L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16 )); /*->Q31, L_tmp_exp*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ @@ -925,7 +924,7 @@ Word16 ApplyFdCng_fx( } tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -959,23 +958,23 @@ Word16 ApplyFdCng_fx( move16(); #else { - Word64 W_tmp = 0; + Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } -#if 0 +#if 0 L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ #else L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ #endif } - L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1); + L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ - L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shr( L_mac( -28000, st->L_frame, 95 ), 15 - 1)] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp */ + L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shr( L_mac( -28000, st->L_frame, 95 ), 15 - 1 )] ); /*Q16,exp -7*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp */ st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); @@ -1099,7 +1098,7 @@ Word16 ApplyFdCng_fx( /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#if 0 L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -1145,7 +1144,7 @@ Word16 ApplyFdCng_fx( L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, T_DIV_L_Frame[L_shl( L_mac( -28000, st->L_frame, 95 ), 1 - 15 )] ); /*Q16,exp -7*/ - L_tmp_exp = add( L_tmp_exp, -7 + (31 - 16) ); /*->Q31, L_tmp_exp*/ + L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -- GitLab From aeae329f121cd581c6ab4d017232db6f4dd5a4b0 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 17:47:18 +0200 Subject: [PATCH 03/14] ISSUE 1817, MR less 1931, basop_watch in basop32.c:1661 --- apps/renderer.c | 1 + lib_com/basop32.c | 5 +++++ lib_com/basop32.h | 6 ++++++ lib_dec/fd_cng_dec_fx.c | 36 +++++++++++++++++++----------------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/apps/renderer.c b/apps/renderer.c index 317713c05..18d446066 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -47,6 +47,7 @@ #include "rotation_file_reader.h" #include "vector3_pair_file_reader.h" #include "wmc_auto.h" +#include "basop32.h" #define WMC_TOOL_SKIP diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 6a34cff43..14083dd41 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -1647,7 +1647,11 @@ Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ) return ( L_var_out ); } +#ifdef BASOP_WATCH_L_add +Word32 L_add_watch( Word32 L_var1, Word32 L_var2 , const char *fname, int linenumber) +#else Word32 L_add( Word32 L_var1, Word32 L_var2 ) +#endif /* BASOP_WATCH_L_add */ { Word32 L_var_out; @@ -1658,6 +1662,7 @@ Word32 L_add( Word32 L_var1, Word32 L_var2 ) if ( ( L_var_out ^ L_var1 ) & MIN_32 ) { L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32; +fprintf(stderr,"BASOP_WATCH L_add(0x%08X,0x%08X), %s:%d\n", L_var1, L_var2, fname, linenumber); assert( 0 ); } } diff --git a/lib_com/basop32.h b/lib_com/basop32.h index 9bbf24f1c..f7a50d621 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -143,7 +143,13 @@ Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ); /* Long sub with c, 2 */ Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Msu without sat, 1 */ +#define BASOP_WATCH_L_add +#ifdef BASOP_WATCH_L_add +#define L_add(a,b) L_add_watch(a,b, __FILE__, __LINE__) +Word32 L_add_watch( Word32 L_var1, Word32 L_var2 , const char *fname, int linenumber); /* Long add, 1 */ +#else Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ +#endif /* BASOP_WATCH_L_add */ Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 01db0750c..be08be852 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -19,6 +19,8 @@ #include "debug.h" #endif +#define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW + #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ #define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */ @@ -586,17 +588,17 @@ Word16 ApplyFdCng_fx( Word16 facTab[NPART]; Word16 facTabExp[NPART]; Word16 tmp_loop; -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW Word32 L_c; -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ Word16 lsp_cng[M]; HANDLE_FD_CNG_DEC hFdCngDec; HANDLE_FD_CNG_COM hFdCngCom; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW Flag Carry = 0; -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ move16(); move16(); #endif @@ -808,7 +810,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -841,7 +843,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); -#else +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) @@ -860,7 +862,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } @@ -868,7 +870,7 @@ Word16 ApplyFdCng_fx( { tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -899,7 +901,7 @@ Word16 ApplyFdCng_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#else +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) @@ -917,14 +919,14 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ move16(); st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -956,14 +958,14 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#else +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ #else L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ @@ -979,7 +981,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ st->cngTDLevel_e = L_tmp_exp; move16(); } @@ -1098,7 +1100,7 @@ Word16 ApplyFdCng_fx( /*st->cngTDLevel = (float)sqrt( (sumFLOAT(cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand) / 2 * hFdCngCom->fftlen) / st->Mode2_L_frame);*/ tmp_loop = sub( hFdCngCom->stopFFTbin, hFdCngCom->startBand ); -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = L_deposit_h( 0 ); L_c = L_deposit_h( 0 ); FOR( j = 0; j < tmp_loop; j++ ) @@ -1130,7 +1132,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); -#else +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) @@ -1148,7 +1150,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#endif +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ st->cngTDLevel_e = L_tmp_exp; move16(); BREAK; -- GitLab From 24fc296cdcc940caa967a938d1bae8f0f90ad552 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 18:04:08 +0200 Subject: [PATCH 04/14] ISSUE 1817, MR less 1931, basop_watch in basop32.c:1661 --- lib_com/basop32.c | 4 ++-- lib_com/basop32.h | 26 +++++++++++++------------- lib_dec/fd_cng_dec_fx.c | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 14083dd41..29ce99445 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -1648,7 +1648,7 @@ Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ) } #ifdef BASOP_WATCH_L_add -Word32 L_add_watch( Word32 L_var1, Word32 L_var2 , const char *fname, int linenumber) +Word32 L_add_watch( Word32 L_var1, Word32 L_var2, const char *fname, int linenumber ) #else Word32 L_add( Word32 L_var1, Word32 L_var2 ) #endif /* BASOP_WATCH_L_add */ @@ -1662,7 +1662,7 @@ Word32 L_add( Word32 L_var1, Word32 L_var2 ) if ( ( L_var_out ^ L_var1 ) & MIN_32 ) { L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32; -fprintf(stderr,"BASOP_WATCH L_add(0x%08X,0x%08X), %s:%d\n", L_var1, L_var2, fname, linenumber); + fprintf( stderr, "BASOP_WATCH L_add(0x%08X,0x%08X), %s:%d\n", L_var1, L_var2, fname, linenumber ); assert( 0 ); } } diff --git a/lib_com/basop32.h b/lib_com/basop32.h index f7a50d621..c5bf0ffae 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -145,20 +145,20 @@ Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* sat, 1 */ #define BASOP_WATCH_L_add #ifdef BASOP_WATCH_L_add -#define L_add(a,b) L_add_watch(a,b, __FILE__, __LINE__) -Word32 L_add_watch( Word32 L_var1, Word32 L_var2 , const char *fname, int linenumber); /* Long add, 1 */ +#define L_add( a, b ) L_add_watch( a, b, __FILE__, __LINE__ ) +Word32 L_add_watch( Word32 L_var1, Word32 L_var2, const char *fname, int linenumber ); /* Long add, 1 */ #else -Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ -#endif /* BASOP_WATCH_L_add */ -Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ -Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ -Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ -Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */ -Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */ -Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */ -Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */ -Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with - round, 2 */ +Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ +#endif /* BASOP_WATCH_L_add */ +Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ +Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ +Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ +Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */ +Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */ +Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */ +Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */ +Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with + round, 2 */ Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac with rounding, 1 */ diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index be08be852..7ea3771f9 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -843,7 +843,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) @@ -901,7 +901,7 @@ Word16 ApplyFdCng_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) @@ -919,7 +919,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ move16(); st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); @@ -1132,7 +1132,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) -- GitLab From b501254fb089c9768d37bca17ac1053831bb28a8 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 20:12:00 +0200 Subject: [PATCH 05/14] ISSUE 1817, MR less 1931, moved inline function w_norm_llQ31() to basop_util.h --- lib_com/basop_util.c | 3 +++ lib_com/basop_util.h | 17 +++++++++++++++ lib_com/options.h | 2 ++ lib_dec/dec_tcx_fx.c | 16 ++++---------- lib_dec/fd_cng_dec_fx.c | 46 ++++++++++++++--------------------------- 5 files changed, 41 insertions(+), 43 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 4c7ebea26..e893565d0 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2089,6 +2089,8 @@ Word32 norm_llQ31( /* o : normalized result Q31 */ return L_sum; } +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW +/* note: now available in basop_util.h */ Word32 w_norm_llQ31( Word64 L_sum, Word16 *exp ); Word32 w_norm_llQ31( /* o : normalized result Q31 */ Word64 L_sum, /* i : upper and lower bits of accu, unsigned Q31 */ @@ -2115,6 +2117,7 @@ Word32 w_norm_llQ31( /* o : normalized result Q31 */ L_tmp = W_extract_h( L64_inp64 ); return L_tmp; } +#endif Word32 Dot_product16HQ( /* o : normalized result Q31 */ const Word32 L_off, /* i : initial sum value Qn */ diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index c95bf8100..a320212ad 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -627,6 +627,23 @@ Word32 norm_llQ31( /* o : normalized result Q31 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ); +#ifdef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW +/*------------------------------------------------------------------* + * w_norm_llQ31: + * + * \brief Compute normalized Q31 Values out of overflowed Q31 value + * using 64-bit operators + *------------------------------------------------------------------*/ +static inline Word32 w_norm_llQ31( Word64 L64_var1, Word16 *S_var2 ) /*Q31 - L_tmp_exp*/ +{ + Word32 L_result; + Word16 sh = W_norm( L64_var1 ); + L_result = W_extract_h( W_shl( L64_var1, sh ) ); + *S_var2 = ( L_result == 0 ) ? -32 : 32 - sh; + return L_result; +} +#endif + /** * \brief Compute dot product of 1 32 bit vectors with itself * \param x input vector 1 diff --git a/lib_com/options.h b/lib_com/options.h index 14b1c5eb8..264a4b5fc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -148,4 +148,6 @@ #define FIX_1824 #define FIX_1822 +#define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW /* FhG: bit-exact, replace carry and overflow operations by 64-bit operations, MR 1931 */ + #endif diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 4e43998f4..54d2ede81 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -6,9 +6,9 @@ #include #include #include "prot_fx.h" +#include "options.h" #include "basop_util.h" #include "stl.h" -#include "options.h" #include "math.h" #include "ivas_prot_fx.h" #include "rom_com.h" @@ -1859,7 +1859,7 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) -#if 0 +#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW { Word16 i; Word32 L_sum, L_c; @@ -1901,7 +1901,6 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul Word16 i; Word32 L_sum; Word64 L_sum64; - Word16 sh; L_sum64 = W_deposit32_l( L_off ); @@ -1909,17 +1908,10 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul { L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); } -#if 0 - L_sum = w_norm_llQ31( L_sum64, exp ); -#else - sh = W_norm( L_sum64 ); - L_sum = W_extract_h( W_shl( L_sum64, sh ) ); - *exp = ( L_sum == 0 ) ? -32 : 32 - sh; -#endif /* 0/1 use of w_norm_llQ31() */ + L_sum = w_norm_llQ31( L_sum64, exp ); /*Q31 - *exp */ return L_sum; } -#endif /* 0/1 legacy */ - +#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) { diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 7ea3771f9..b8042d2e8 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -19,8 +19,6 @@ #include "debug.h" #endif -#define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW - #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */ #define ST_PERIODOG_FACT_Q15 29491 /* 0.9 in Q15, short-term filter factor for periodogram */ @@ -557,16 +555,6 @@ void deleteFdCngDec_fx( HANDLE_FD_CNG_DEC *hFdCngDec ) error */ -static inline Word32 w_norm_llQ31_inl( Word64 L64_var1, Word16 *S_var2 ) /*Q31 - L_tmp_exp*/ -{ - Word32 L_result; - Word16 sh = W_norm( L64_var1 ); - L_result = W_extract_h( W_shl( L64_var1, sh ) ); - *S_var2 = ( L_result == 0 ) ? -32 : 32 - sh; - return L_result; -} - - Word16 ApplyFdCng_fx( Word16 *timeDomainInput, /* i : pointer to time domain input Q*/ Word16 Q, @@ -843,18 +831,18 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31*/ } - L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ } L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = Mpy_32_16_1( L_tmp, 1 ); /*Q16 - L_tmp_exp*/ + L_tmp = L_shr( L_tmp, 15); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ @@ -862,7 +850,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); L_tmp_exp = add( L_tmp_exp, 1 ); -#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#endif st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); } @@ -901,16 +889,16 @@ Word16 ApplyFdCng_fx( L_tmp_exp = add( L_tmp_exp, 31 - 16 ); /*->Q31, L_tmp_exp*/ st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } - L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ } - L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -919,7 +907,7 @@ Word16 ApplyFdCng_fx( st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ -#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#endif move16(); st->hTcxDec->conCngLevelBackgroundTrace_e = L_tmp_exp; move16(); @@ -958,20 +946,16 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } -#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ -#else - L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ -#endif } - L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -981,7 +965,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#endif st->cngTDLevel_e = L_tmp_exp; move16(); } @@ -1132,16 +1116,16 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); -#else /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#else { Word64 W_tmp = 0; FOR( j = 0; j < tmp_loop; j++ ) { W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ } - L_tmp = w_norm_llQ31_inl( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ + L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ } - L_tmp_exp = add( L_tmp_exp, *cngNoiseLevel_exp - 1 ); + L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -1150,7 +1134,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); -#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ +#endif st->cngTDLevel_e = L_tmp_exp; move16(); BREAK; -- GitLab From 5efd6626fba1e348c8dfd90b09765bb5c6c94029 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 20:13:52 +0200 Subject: [PATCH 06/14] replaced L_add() with L_add_sat() in operator round_fx() --- lib_com/basop32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 29ce99445..4b219916b 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -1268,7 +1268,7 @@ Word16 round_fx( Word32 L_var1 ) Word32 L_rounded; BASOP_SATURATE_WARNING_OFF - L_rounded = L_add( L_var1, (Word32) 0x00008000L ); + L_rounded = L_add_sat( L_var1, (Word32) 0x00008000L ); BASOP_SATURATE_WARNING_ON var_out = extract_h( L_rounded ); -- GitLab From b7fa0830c352b790e0e0a5268717fa60d1085613 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 20:19:17 +0200 Subject: [PATCH 07/14] ISSUE 1817, MR less 1931, clang-format --- lib_dec/dec_tcx_fx.c | 6 +++--- lib_dec/fd_cng_dec_fx.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 54d2ede81..3f2077557 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1858,7 +1858,7 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul const Word16 x[], /* i : x vector Qn */ const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ Word16 *exp /* o : exponent of result in [-32,31] Q0 */ - ) +) #ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW { Word16 i; @@ -1908,12 +1908,12 @@ static Word32 CalculateAbsEnergy_fx( /* o : normalized resul { L_sum64 = W_mac_16_16( L_sum64, x[i], x[i] ); } - L_sum = w_norm_llQ31( L_sum64, exp ); /*Q31 - *exp */ + L_sum = w_norm_llQ31( L_sum64, exp ); /*Q31 - *exp */ return L_sum; } #endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */ - void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) +void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_TDAC, Word16 *xn_buf, const Word16 *tcx_aldo_window_1, const PWord16 *tcx_aldo_window_1_trunc, const PWord16 *tcx_aldo_window_2, const PWord16 *tcx_mdct_window_half, const PWord16 *tcx_mdct_window_minimum, const PWord16 *tcx_mdct_window_trans, Word16 tcx_mdct_window_half_length, Word16 tcx_mdct_window_min_length, Word16 index, Word16 left_rect, Word16 tcx_offset, Word16 overlap, Word16 L_frame, Word16 L_frameTCX, Word16 L_spec_TCX5, Word16 L_frame_glob, Word16 frame_cnt, Word16 bfi, Word16 *old_out, Word16 *Q_old_wtda, Decoder_State *st, Word16 fullbandScale, Word16 *acelp_zir ) { const TCX_CONFIG_HANDLE tcx_cfg = st->hTcxCfg; Word16 tmp_offset; diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index b8042d2e8..faf0a5b81 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -842,7 +842,7 @@ Word16 ApplyFdCng_fx( } L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); - L_tmp = L_shr( L_tmp, 15); /*Q16 - L_tmp_exp*/ + L_tmp = L_shr( L_tmp, 15 ); /*Q16 - L_tmp_exp*/ L_tmp = Mpy_32_16_1( L_tmp, shr( T_DIV_L_Frame[L_shl( L_mac( -28000, NORM_MDCT_FACTOR, 95 ), 1 - 15 )], 1 ) ); /*Q16,exp -7*/ L_tmp_exp = add( L_tmp_exp, -7 + ( 31 - 16 ) ); /*->Q31, L_tmp_exp*/ -- GitLab From 5959a3a840bef0af8b0c5989a82ce811e0e37dc9 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 20:57:43 +0200 Subject: [PATCH 08/14] removed BASOP_WATCH --- lib_com/basop32.c | 5 ----- lib_com/basop32.h | 8 +------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/lib_com/basop32.c b/lib_com/basop32.c index 4b219916b..eebc16849 100644 --- a/lib_com/basop32.c +++ b/lib_com/basop32.c @@ -1647,11 +1647,7 @@ Word32 L_add_o( Word32 L_var1, Word32 L_var2, Flag *Overflow ) return ( L_var_out ); } -#ifdef BASOP_WATCH_L_add -Word32 L_add_watch( Word32 L_var1, Word32 L_var2, const char *fname, int linenumber ) -#else Word32 L_add( Word32 L_var1, Word32 L_var2 ) -#endif /* BASOP_WATCH_L_add */ { Word32 L_var_out; @@ -1662,7 +1658,6 @@ Word32 L_add( Word32 L_var1, Word32 L_var2 ) if ( ( L_var_out ^ L_var1 ) & MIN_32 ) { L_var_out = ( L_var1 < 0 ) ? MIN_32 : MAX_32; - fprintf( stderr, "BASOP_WATCH L_add(0x%08X,0x%08X), %s:%d\n", L_var1, L_var2, fname, linenumber ); assert( 0 ); } } diff --git a/lib_com/basop32.h b/lib_com/basop32.h index c5bf0ffae..07ec614f2 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -143,13 +143,7 @@ Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ); /* Long sub with c, 2 */ Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Msu without sat, 1 */ -#define BASOP_WATCH_L_add -#ifdef BASOP_WATCH_L_add -#define L_add( a, b ) L_add_watch( a, b, __FILE__, __LINE__ ) -Word32 L_add_watch( Word32 L_var1, Word32 L_var2, const char *fname, int linenumber ); /* Long add, 1 */ -#else -Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ -#endif /* BASOP_WATCH_L_add */ +Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ -- GitLab From 7b2ff3d1e6db5404e5fc9627b36c5d47f6674288 Mon Sep 17 00:00:00 2001 From: gerstack Date: Thu, 24 Jul 2025 21:03:49 +0200 Subject: [PATCH 09/14] ISSUE 1817, MR less 1931, clang-format --- lib_com/basop32.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib_com/basop32.h b/lib_com/basop32.h index 07ec614f2..9bbf24f1c 100644 --- a/lib_com/basop32.h +++ b/lib_com/basop32.h @@ -143,16 +143,16 @@ Word32 L_sub_c( Word32 L_var1, Word32 L_var2 ); /* Long sub with c, 2 */ Word32 DEPR_L_msuNs( Word32 L_var3, Word16 var1, Word16 var2, Flag *Carry ); /* Msu without sat, 1 */ -Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ -Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ -Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ -Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ -Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */ -Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */ -Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */ -Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */ -Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with - round, 2 */ +Word32 L_add( Word32 L_var1, Word32 L_var2 ); /* Long add, 1 */ +Word32 L_sub( Word32 L_var1, Word32 L_var2 ); /* Long sub, 1 */ +Word32 L_add_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long add with c, 2 */ +Word32 DEPR_L_sub_c( Word32 L_var1, Word32 L_var2, Flag *Carry ); /* Long sub with c, 2 */ +Word32 L_negate( Word32 L_var1 ); /* Long negate, 1 */ +Word16 mult_r( Word16 var1, Word16 var2 ); /* Mult with round, 1 */ +Word32 L_shl( Word32 L_var1, Word16 var2 ); /* Long shift left, 1 */ +Word32 L_shr( Word32 L_var1, Word16 var2 ); /* Long shift right, 1 */ +Word16 shr_r( Word16 var1, Word16 var2 ); /* Shift right with + round, 2 */ Word16 mac_r( Word32 L_var3, Word16 var1, Word16 var2 ); /* Mac with rounding, 1 */ -- GitLab From 0ee5f9688769b07c71539aec38a03fb8a0b653a9 Mon Sep 17 00:00:00 2001 From: gerstack Date: Fri, 25 Jul 2025 10:44:29 +0200 Subject: [PATCH 10/14] ISSUE 1817, MR less 1931, introduced function sum_array_norm() to cover 4 identical loops --- lib_com/basop_util.c | 19 +++++++++++++++++++ lib_com/basop_util.h | 14 ++++++++++++++ lib_dec/fd_cng_dec_fx.c | 40 ++++++---------------------------------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index e893565d0..704eb7f6e 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2142,6 +2142,25 @@ Word32 Dot_product16HQ( /* o : normalized result return L_sum; } +Word32 sum_array_norm( /* o : normalized result Q31 */ + const Word32 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ +) +{ + Word16 i; + Word64 W_tmp = 0; + Word32 L_tmp; + FOR( i = 0; i < lg; i++ ) + { + W_tmp = W_add( W_tmp, x[i] ); /*Q31*/ + } + L_tmp = w_norm_llQ31( W_tmp, exp ); /*Q31 - *exp*/ + return L_tmp; +} + + + Word32 Norm32Norm( const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e ) { Word32 L_tmp, L_tmp2; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index a320212ad..5cc3accd3 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -612,6 +612,20 @@ Word32 Dot_product16HQ( /*hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else - { - Word64 W_tmp = 0; - FOR( j = 0; j < tmp_loop; j++ ) - { - W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ - } - L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - } + L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -947,14 +933,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); #else - { - Word64 W_tmp = 0; - FOR( j = 0; j < tmp_loop; j++ ) - { - W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ - } - L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - } + L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -1117,14 +1096,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); #else - { - Word64 W_tmp = 0; - FOR( j = 0; j < tmp_loop; j++ ) - { - W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/ - } - L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ - } + L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ -- GitLab From d50fceaf3090cf2c165313788b017405fd014e23 Mon Sep 17 00:00:00 2001 From: gerstack Date: Fri, 25 Jul 2025 10:49:55 +0200 Subject: [PATCH 11/14] ISSUE 1817, MR less 1931, clang-format --- lib_com/basop_util.c | 9 ++++----- lib_com/basop_util.h | 8 ++++---- lib_dec/fd_cng_dec_fx.c | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 704eb7f6e..695ead35d 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2142,10 +2142,10 @@ Word32 Dot_product16HQ( /* o : normalized result return L_sum; } -Word32 sum_array_norm( /* o : normalized result Q31 */ - const Word32 x[], /* i : x vector Qn */ - const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ - Word16 *exp /* o : exponent of result in [-32,31] Q0 */ +Word32 sum_array_norm( /* o : normalized result Q31 */ + const Word32 x[], /* i : x vector Qn */ + const Word16 lg, /* i : vector length, range [0..7FFF] Q0 */ + Word16 *exp /* o : exponent of result in [-32,31] Q0 */ ) { Word16 i; @@ -2160,7 +2160,6 @@ Word32 sum_array_norm( /* o : normalized result } - Word32 Norm32Norm( const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e ) { Word32 L_tmp, L_tmp2; diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 5cc3accd3..0a82d112d 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -620,10 +620,10 @@ Word32 Dot_product16HQ( /*hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ #else - L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -933,7 +933,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/ move16(); #else - L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/ + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ @@ -1096,7 +1096,7 @@ Word16 ApplyFdCng_fx( st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/ move16(); #else - L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/ + L_tmp = sum_array_norm( cngNoiseLevel, tmp_loop, &L_tmp_exp ); /*Q31 - L_tmp_exp*/ L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 ); L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/ -- GitLab From 625364d8547f42df82d9bb3c29abf685034087e8 Mon Sep 17 00:00:00 2001 From: gerstack Date: Mon, 4 Aug 2025 17:42:48 +0200 Subject: [PATCH 12/14] ISSUE_1811_EXCEEDING_W_SHIFTS, W_shl() shift limited to 63 --- lib_rend/ivas_objectRenderer_sfx_fx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib_rend/ivas_objectRenderer_sfx_fx.c b/lib_rend/ivas_objectRenderer_sfx_fx.c index 8967b89a2..a1b8da354 100644 --- a/lib_rend/ivas_objectRenderer_sfx_fx.c +++ b/lib_rend/ivas_objectRenderer_sfx_fx.c @@ -229,7 +229,11 @@ static void sincResample_fx( /* Calculate the sinc-index for the center value of the sinc */ Word16 center_val_e; Word64 center_val; +#ifndef FIX_ISSUE_1811_EXCEEDING_W_SHIFTS center_val = W_sub( t_frac_plus_eps, W_shl( t, sub( 31, t_frac_plus_eps_e ) ) ); // exp(center_val_e) +#else + center_val = W_sub( t_frac_plus_eps, W_shl( t, s_min( sub( 31, t_frac_plus_eps_e ), 63 ) ) ); // exp(center_val_e) +#endif center_val_e = add( t_frac_plus_eps_e, 6 ); Word16 com_e = s_max( 0, center_val_e ); center_val = W_add( W_shr( center_val, sub( com_e, center_val_e ) ), W_shl( 1, sub( 30, com_e ) ) ); // exp(center_val_e) -- GitLab From 559a76877053fd98d3e7d272610c91d44c952c7e Mon Sep 17 00:00:00 2001 From: gerstack Date: Mon, 4 Aug 2025 17:47:10 +0200 Subject: [PATCH 13/14] ISSUE_1811_EXCEEDING_W_SHIFTS, W_shl() shift limited to 63 --- lib_com/options.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 1f4ed0856..69b9ab295 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -89,6 +89,8 @@ #define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW /* FhG: bit-exact, replace carry and overflow operations by 64-bit operations, MR 1931 */ +#define FIX_ISSUE_1811_EXCEEDING_W_SHIFTS + /* #################### Start BASOP porting switches ############################ */ #define FIX_1372_ISAR_POST_REND -- GitLab From 4890db2aa3a06d8f0bd4a7a685ea2d450de1f5ea Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Mon, 4 Aug 2025 21:35:01 +0200 Subject: [PATCH 14/14] remove code in FIX_ISSUE_1811_EXCEEDING_W_SHIFTS, since this is part of MR1928 --- lib_com/options.h | 1 - lib_rend/ivas_objectRenderer_sfx_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 14b9da20b..f25ef28f2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -88,7 +88,6 @@ #define FIX_1822 #define FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW /* FhG: bit-exact, replace carry and overflow operations by 64-bit operations, MR 1931 */ -#define FIX_ISSUE_1811_EXCEEDING_W_SHIFTS #define FIX_1844_MISSING_FREE /* FhG: add missing free in ivas_binRenderer_convModuleClose_fx() */ /* #################### Start BASOP porting switches ############################ */ diff --git a/lib_rend/ivas_objectRenderer_sfx_fx.c b/lib_rend/ivas_objectRenderer_sfx_fx.c index a1b8da354..8967b89a2 100644 --- a/lib_rend/ivas_objectRenderer_sfx_fx.c +++ b/lib_rend/ivas_objectRenderer_sfx_fx.c @@ -229,11 +229,7 @@ static void sincResample_fx( /* Calculate the sinc-index for the center value of the sinc */ Word16 center_val_e; Word64 center_val; -#ifndef FIX_ISSUE_1811_EXCEEDING_W_SHIFTS center_val = W_sub( t_frac_plus_eps, W_shl( t, sub( 31, t_frac_plus_eps_e ) ) ); // exp(center_val_e) -#else - center_val = W_sub( t_frac_plus_eps, W_shl( t, s_min( sub( 31, t_frac_plus_eps_e ), 63 ) ) ); // exp(center_val_e) -#endif center_val_e = add( t_frac_plus_eps_e, 6 ); Word16 com_e = s_max( 0, center_val_e ); center_val = W_add( W_shr( center_val, sub( com_e, center_val_e ) ), W_shl( 1, sub( 30, com_e ) ) ); // exp(center_val_e) -- GitLab