From 4e41d8e1319d341278c61a9488c756d689f38a0c Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Fri, 11 Jul 2025 15:07:03 +0530 Subject: [PATCH] Multi channel bit-exact optimizations - 3 Residu3_fx, dotp_fixed_32, SQ_gain_estimate_stereo_fx, dotp_fixed_o, IGF_getCrest_new_fx updated. Around 4 WMOPs reduction observed --- lib_com/options.h | 1 + lib_com/residu_fx.c | 2 +- lib_com/tools.c | 8 ++++++++ lib_enc/igf_enc.c | 2 +- lib_enc/ivas_stereo_mdct_stereo_enc_fx.c | 22 ++++++++++++++++++++-- 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0cf958d03..23d8ca6d1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -79,6 +79,7 @@ /* Note: each compile switch (FIX_1101_...) is independent from the other ones */ +#define OPT_MCT_ENC_V2_BE #define OPT_MCH_DEC_V1_NBE #define OPT_MCT_ENC_48KB_NBE #define OPT_MCH_DEC_V1_BE diff --git a/lib_com/residu_fx.c b/lib_com/residu_fx.c index 32d18d1fe..91d0ee30a 100644 --- a/lib_com/residu_fx.c +++ b/lib_com/residu_fx.c @@ -156,7 +156,7 @@ void Residu3_fx( move16(); #endif q = add( norm_s( a[0] ), 1 ); - IF( shift != 0 ) + if ( shift != 0 ) { q = add( q, shift ); } diff --git a/lib_com/tools.c b/lib_com/tools.c index 3cf11ea92..0087920cd 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -688,7 +688,11 @@ Word32 dotp_fixed_o( move16(); test(); test(); +#ifdef OPT_MCT_ENC_V2_BE + FOR( ; ( suma > MAX_32 ) || ( suma < MIN_32 ) || ( *res_q > 31 ); ) +#else WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) ) +#endif { suma = W_shr( suma, 1 ); *res_q = sub( *res_q, 1 ); @@ -718,7 +722,11 @@ Word32 dotp_fixed_32( move16(); test(); test(); +#ifdef OPT_MCT_ENC_V2_BE + FOR( ; ( suma > MAX_32 ) || ( suma < MIN_32 ) || ( *res_q > 31 ); ) +#else WHILE( GT_64( suma, MAX_32 ) || LT_64( suma, MIN_32 ) || GT_16( *res_q, 31 ) ) +#endif { suma = W_shr( suma, 1 ); *res_q = sub( *res_q, 1 ); diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index fe1ba10c1..7da9fa6cf 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -137,7 +137,7 @@ static Word16 IGF_getCrest_new_fx( move16(); x_eff = L_add( x_eff, L_mult0( x, x ) ); - IF( GT_16( x, x_max ) ) + if ( GT_16( x, x_max ) ) { x_max = x; move16(); diff --git a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c index 2f1b7d6c8..f7735e8df 100644 --- a/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c +++ b/lib_enc/ivas_stereo_mdct_stereo_enc_fx.c @@ -882,7 +882,7 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res move32(); en_fx[q] = Mpy_32_16_1( L_add( L_shl( e_ener, Q25 ), en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) move32(); - i = add( i, 4 ); + i += 4; } i = 0; move16(); @@ -901,7 +901,7 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res move32(); en_fx[q] = Mpy_32_16_1( L_add( L_shl( e_ener, Q25 ), en_fx[q] ), 9864 /* log10(2) in Q15 */ ); // Q(25) move32(); - i = add( i, 4 ); + i += 4; } /* SQ scale: 4 bits / 6 dB per quadruple */ @@ -911,6 +911,9 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res offset_fx = fac_fx; /* Q25 */ move32(); +#ifdef OPT_MCT_ENC_V2_BE + Word64 target_64_fx = W_shl( target_fx, 7 ); // Q25 +#endif /* find offset (0 to 128 dB with step of 0.125dB) */ FOR( iter = 0; iter < 10; iter++ ) { @@ -923,6 +926,20 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res { tmp_32 = L_sub( en_fx[i], offset_fx ); /* Q25 */ +#ifdef OPT_MCT_ENC_V2_BE + /* avoid SV with 1 bin of amp < 0.5f */ + if ( GT_32( tmp_32, 10066329 /*0.3 Q25*/ ) ) + { + W_tmp = W_add( W_tmp, tmp_32 ); /* Q25 */ + } + /* if ener is above target -> break and increase offset */ + IF( GT_64( W_tmp, target_64_fx ) ) + { + offset_fx = L_add( offset_fx, fac_fx ); /* Q25 */ + BREAK; + } +#else + /* avoid SV with 1 bin of amp < 0.5f */ IF( GT_32( tmp_32, 10066329 /*0.3 Q25*/ ) ) { @@ -935,6 +952,7 @@ static Word32 SQ_gain_estimate_stereo_fx( // e_res BREAK; } } +#endif } } -- GitLab