From dfb8459c925db4dbbbba512536774db3e4c903e3 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 3 Feb 2025 13:59:22 +0100 Subject: [PATCH 1/4] improved the WMOPS performance of RcontextMapping_encode2_estimate_bandWise_fx() by 11.293. --- lib_enc/ACcontextMapping_enc_fx.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 08baa4f3d..1e9ea59ed 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1745,9 +1745,16 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( const UWord8 *lookup; Word16 idx; Word16 tmp; + Word16 accu_variables; /* Q0 */ + Word32 accu_lut; /* Q8 */ + accu_variables = 0; + accu_lut = 0; + move16(); + move32(); /* Main Loop through the 2-tuples */ /*hContextMem->nt_half = end_line >> 1;*/ + FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 ) { a1_i = k; /* Q0 */ @@ -1777,8 +1784,10 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */ /* Signs Bits */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ +// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ +// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ + accu_variables = L_add(accu_variables, s_min( a1, 1 ) ); + accu_variables = L_add(accu_variables, s_min( b1, 1 ) ); move32(); move32(); @@ -1792,8 +1801,10 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ +// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ +// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ + accu_lut = L_add(accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] ); + accu_variables = L_add(accu_variables, 2 ); move32(); move32(); @@ -1810,7 +1821,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ +// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ + accu_lut = L_add(accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol] ); move32(); // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; @@ -1830,6 +1842,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( move16(); } /*end of the 2-tuples loop*/ + accu_lut = L_add(accu_lut, imult3216( ONE_IN_Q23, accu_variables ) ); // bring both accus into the same representation (Q8) + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut , Q8, &hContextMem->bit_estimate_e); total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); -- GitLab From 470073d2046bd690ae06be8e6a8e6a9b30b662b0 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 3 Feb 2025 14:06:59 +0100 Subject: [PATCH 2/4] applied the formatting patch. --- lib_enc/ACcontextMapping_enc_fx.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 1e9ea59ed..75cc8ca99 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1784,10 +1784,10 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */ /* Signs Bits */ -// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ -// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - accu_variables = L_add(accu_variables, s_min( a1, 1 ) ); - accu_variables = L_add(accu_variables, s_min( b1, 1 ) ); + // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ + // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ + accu_variables = L_add( accu_variables, s_min( a1, 1 ) ); + accu_variables = L_add( accu_variables, s_min( b1, 1 ) ); move32(); move32(); @@ -1801,10 +1801,10 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); -// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ -// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ - accu_lut = L_add(accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] ); - accu_variables = L_add(accu_variables, 2 ); + // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ + // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] ); + accu_variables = L_add( accu_variables, 2 ); move32(); move32(); @@ -1820,9 +1820,9 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ -// hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ - accu_lut = L_add(accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol] ); + symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ + // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol] ); move32(); // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; @@ -1841,9 +1841,9 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */ move16(); - } /*end of the 2-tuples loop*/ - accu_lut = L_add(accu_lut, imult3216( ONE_IN_Q23, accu_variables ) ); // bring both accus into the same representation (Q8) - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut , Q8, &hContextMem->bit_estimate_e); + } /*end of the 2-tuples loop*/ + accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q23, accu_variables ) ); // bring both accus into the same representation (Q8) + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q8, &hContextMem->bit_estimate_e ); total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); -- GitLab From 0fd8a97f30804eea6b76e764f28814d720f3084e Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 3 Feb 2025 14:17:40 +0100 Subject: [PATCH 3/4] moved one unnecessary function out of the for loop. --- lib_enc/ACcontextMapping_enc_fx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index 75cc8ca99..e9e18099c 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1747,6 +1747,7 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( Word16 tmp; Word16 accu_variables; /* Q0 */ Word32 accu_lut; /* Q8 */ + Word16 loop_end; accu_variables = 0; accu_lut = 0; @@ -1755,7 +1756,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( /* Main Loop through the 2-tuples */ /*hContextMem->nt_half = end_line >> 1;*/ - FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 ) + loop_end = min( hContextMem->lastnz, end_line ); + FOR( k = start_line; k < loop_end; k += 2 ) { a1_i = k; /* Q0 */ move16(); -- GitLab From d8081a4ddb664d030b4dc4e7bb5a8dc6642c0a66 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Thu, 6 Feb 2025 11:45:58 +0100 Subject: [PATCH 4/4] code cleanup. using Q20 instead of Q23 for the accu_variables gives a little bit more headroom. --- lib_enc/ACcontextMapping_enc_fx.c | 123 +++++++++++++----------------- 1 file changed, 54 insertions(+), 69 deletions(-) diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index e9e18099c..9607ffd0f 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1106,8 +1106,8 @@ void RCcontextMapping_encode2_no_mem_s17_LCS_fx( } /* Finish range encoder */ - rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ - bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ + rc_tot_bits = rc_uni_enc_finish_fx( &rc_st_enc ); /* No. of bits consumed by range coder Q0*/ + bp = add( rc_tot_bits, nbbits_ntuples ); /* Update bitstream pointer Q0*/ /* Cross-check that there is no overflow */ @@ -1215,15 +1215,15 @@ static Word16 find_last_nz_pair_fx( *-------------------------------------------------------------------*/ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( - Word16 *x, /* Spectral coefficients Q0*/ - const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ - Word16 *lastnz_out, /* Q0 */ - Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/ - const Word16 target, /* Target bits Q0*/ - Word16 *stop, /* Q0 */ - Word16 mode, /* Q0 */ - CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ -) + Word16 *x, /* Spectral coefficients Q0*/ + const Word16 nt, /* L - size of spectrum (no. of spectral coefficients) Q0*/ + Word16 *lastnz_out, /* Q0 */ + Word16 *nEncoded, /* No. of spectral coefficients that can be coded without an overflow occuring Q0*/ + const Word16 target, /* Target bits Q0*/ + Word16 *stop, /* Q0 */ + Word16 mode, /* Q0 */ + CONTEXT_HM_CONFIG *hm_cfg /* context-based harmonic model configuration */ + ) { /* Common variables */ Word16 a1, b1; @@ -1363,7 +1363,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( pki = lookup[lev1]; /* ESC symbol */ bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */ - bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */ + bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e ); /* Add 2 LSB bits corresponding to the bit-plane exp(bit_estimate_e) */ a1 = shr( a1, 1 ); b1 = shr( b1, 1 ); @@ -1451,7 +1451,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( *nEncoded = lastnz2; /* Q0 */ move16(); - *stop = stop2; /* If zero, it means no overflow occured during bit-estimation Q0*/ + *stop = stop2; /* If zero, it means no overflow occured during bit-estimation Q0*/ move16(); *lastnz_out = lastnz; /* Q0 */ move16(); @@ -1512,7 +1512,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( lastnz = add( lastnz, 2 ); /* Q0 */ IF( LT_16( lastnz, 2 ) ) { - lastnz = 2; /* At least one tuple is coded Q0*/ + lastnz = 2; /* At least one tuple is coded Q0*/ move16(); } @@ -1611,37 +1611,37 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( move16(); } ELSE /* Overflow */ + { + IF( *stop ){ + *stop = tot_bits2; /* Q0 */ + move16(); + } + ELSE { - IF( *stop ){ - *stop = tot_bits2; /* Q0 */ + *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */ + move16(); + } + } + + *lastnz_out = lastnz; /* Q0 */ move16(); - } - ELSE - { - *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */ + *nEncoded = lastnz2; /* Q0 */ move16(); - } -} + /* Safety mechanism to avoid overflow */ + test(); + IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) + { + FOR( k = 0; k < lastnz2; k++ ) + { + x[k] = 0; + move16(); + } + } -*lastnz_out = lastnz; /* Q0 */ -move16(); -*nEncoded = lastnz2; /* Q0 */ -move16(); -/* Safety mechanism to avoid overflow */ -test(); -IF( EQ_16( lastnz2, 2 ) && EQ_16( overflow_flag, 1 ) ) -{ - FOR( k = 0; k < lastnz2; k++ ) - { - x[k] = 0; - move16(); + return tot_bits2; } } -return tot_bits2; -} -} - /*-------------------------------------------------------------------* * RCcontextMapping_encode2_estimate_bandWise_start_fx() @@ -1745,19 +1745,17 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( const UWord8 *lookup; Word16 idx; Word16 tmp; - Word16 accu_variables; /* Q0 */ - Word32 accu_lut; /* Q8 */ - Word16 loop_end; + Word32 accu_lut; + Word16 accu_variables; - accu_variables = 0; accu_lut = 0; - move16(); move32(); + accu_variables = 0; + move16(); + /* Main Loop through the 2-tuples */ /*hContextMem->nt_half = end_line >> 1;*/ - - loop_end = min( hContextMem->lastnz, end_line ); - FOR( k = start_line; k < loop_end; k += 2 ) + FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 ) { a1_i = k; /* Q0 */ move16(); @@ -1786,12 +1784,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */ /* Signs Bits */ - // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - accu_variables = L_add( accu_variables, s_min( a1, 1 ) ); - accu_variables = L_add( accu_variables, s_min( b1, 1 ) ); - move32(); - move32(); + accu_variables = add( accu_variables, s_min( a1, 1 ) ); + accu_variables = add( accu_variables, s_min( b1, 1 ) ); /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */ lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); @@ -1803,15 +1797,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */ - // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e ); /* Add the 2 LSB bits that were shifted out exp(hContextMem->bit_estimate_e) */ - accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] ); - accu_variables = L_add( accu_variables, 2 ); - move32(); - move32(); - - // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC]; - // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC]>>3 ); + accu_variables = add( accu_variables, 2 ); a1 = shr( a1, 1 ); b1 = shr( b1, 1 ); @@ -1822,11 +1809,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( pki = lookup[lev1]; /* Q0 */ move16(); - symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ - // hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ - accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol] ); - move32(); - // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol]; + symbol = add( a1, i_mult( A_THRES, b1 ) ); /* MSB symbol Q0*/ + accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol]>>3 ); /* Update context */ lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ ); @@ -1843,9 +1827,10 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */ move16(); - } /*end of the 2-tuples loop*/ - accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q23, accu_variables ) ); // bring both accus into the same representation (Q8) - hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q8, &hContextMem->bit_estimate_e ); + } /*end of the 2-tuples loop*/ + accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q20, accu_variables ) ); // bring the accu_variables into Q20 + hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q11, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */ + move32(); total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); -- GitLab