From ec6f32c77f19dec09957e81c6d0d817713687c93 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 26 Nov 2025 16:25:41 +0100 Subject: [PATCH 01/12] first approach --- lib_com/basop_util.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 3a0a72bc3..6be43a701 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2565,6 +2565,47 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ headroom is introduced into acc */ +#if 1 +Word32 BASOP_Util_Add_Mant32Exp( + Word32 Mant1, + Word16 exp1, + Word32 Mant2, + Word16 exp2, + Word16 *exp_res ) +{ + + Word32 tmp1, tmp2, tmp_res; + Word16 scale_tmp, scale_tmp2; + + + if ( Mant1 == 0 ) + { + exp1 = exp2; + move16(); + } + + if ( Mant2 == 0 ) + { + exp2 = exp1; + move16(); + } + + scale_tmp = sub( s_max( exp2, exp1 ), 1 ); + tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); + + tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp_res = L_add( tmp1, tmp2 ); + + scale_tmp2 = norm_l( tmp_res ); + tmp_res = L_shl( tmp_res, scale_tmp2 ); + + + *exp_res = sub( scale_tmp, scale_tmp2 ); + move16(); + + return tmp_res; +} +#else #ifdef OPT_2146_BASOP_UTIL_ADD_MANT32EXP Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ ( Word32 a_m, /* i : Mantissa of 1st operand a */ @@ -2630,6 +2671,7 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ return ( a_m ); } #else + Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ ( Word32 a_m, /* i : Mantissa of 1st operand a */ Word16 a_e, /* i : Exponent of 1st operand a */ @@ -2688,6 +2730,7 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ return ( L_tmp ); } #endif +#endif static const Word16 shift_lc[] = { 9, 10 }; -- GitLab From 4e6736578e4fd3a1c82d7d51d91e01a0e2a9afce Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 07:00:21 +0100 Subject: [PATCH 02/12] fix error --- lib_com/basop_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 6be43a701..1edad3a1f 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2590,7 +2590,7 @@ Word32 BASOP_Util_Add_Mant32Exp( move16(); } - scale_tmp = sub( s_max( exp2, exp1 ), 1 ); + scale_tmp = add( s_max( exp2, exp1 ), 1 ); tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); -- GitLab From aac60a598071bd504585c2a593036b928256e299 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 07:19:15 +0100 Subject: [PATCH 03/12] trigger more tests --- lib_com/basop_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 1edad3a1f..8e246c08f 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2592,8 +2592,8 @@ Word32 BASOP_Util_Add_Mant32Exp( scale_tmp = add( s_max( exp2, exp1 ), 1 ); tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp_res = L_add( tmp1, tmp2 ); scale_tmp2 = norm_l( tmp_res ); -- GitLab From db742001aaafa8ac3e31ce16adf2c9e432fa77eb Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 09:38:55 +0100 Subject: [PATCH 04/12] fix diffs --- lib_com/basop_util.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 8e246c08f..16e9ad99f 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2575,7 +2575,7 @@ Word32 BASOP_Util_Add_Mant32Exp( { Word32 tmp1, tmp2, tmp_res; - Word16 scale_tmp, scale_tmp2; + Word16 scale_tmp, scale_tmp2, scale_tmp3; if ( Mant1 == 0 ) @@ -2592,15 +2592,22 @@ Word32 BASOP_Util_Add_Mant32Exp( scale_tmp = add( s_max( exp2, exp1 ), 1 ); tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); tmp_res = L_add( tmp1, tmp2 ); scale_tmp2 = norm_l( tmp_res ); tmp_res = L_shl( tmp_res, scale_tmp2 ); + scale_tmp3 = 0; + move16(); + + if ( tmp_res != 0 ) + { + scale_tmp3 = sub( scale_tmp, scale_tmp2 ); + } - *exp_res = sub( scale_tmp, scale_tmp2 ); + *exp_res = scale_tmp3; move16(); return tmp_res; -- GitLab From 48c88257da7d3356dd9bed52a8c964b0de532108 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 11:38:43 +0100 Subject: [PATCH 05/12] faster --- lib_com/basop_util.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 16e9ad99f..805f82f59 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2577,24 +2577,22 @@ Word32 BASOP_Util_Add_Mant32Exp( Word32 tmp1, tmp2, tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; + scale_tmp = add( s_max( exp2, exp1 ), 1 ); + scale_tmp3 = sub( exp1, scale_tmp ); - if ( Mant1 == 0 ) + if ( Mant1 != 0 ) { - exp1 = exp2; - move16(); + Mant1 = L_shl( Mant1, scale_tmp3 ); } - if ( Mant2 == 0 ) + scale_tmp3 = sub( exp2, scale_tmp ); + if ( Mant2 != 0 ) { - exp2 = exp1; - move16(); + Mant2 = L_shl( Mant2, scale_tmp3 ); } - scale_tmp = add( s_max( exp2, exp1 ), 1 ); - tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); - tmp_res = L_add( tmp1, tmp2 ); + tmp_res = L_add( Mant1, Mant2 ); scale_tmp2 = norm_l( tmp_res ); tmp_res = L_shl( tmp_res, scale_tmp2 ); -- GitLab From ae15866626619597fb873d46355fe17155029ec6 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 12:04:53 +0100 Subject: [PATCH 06/12] fix warnings --- lib_com/basop_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 805f82f59..728132d6e 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2574,7 +2574,7 @@ Word32 BASOP_Util_Add_Mant32Exp( Word16 *exp_res ) { - Word32 tmp1, tmp2, tmp_res; + Word32 tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; scale_tmp = add( s_max( exp2, exp1 ), 1 ); -- GitLab From 692cdb8621965035b00dd9b9b60de15a2fb82bc0 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 12:26:32 +0100 Subject: [PATCH 07/12] Revert "fix warnings" This reverts commit ae15866626619597fb873d46355fe17155029ec6. --- lib_com/basop_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 728132d6e..805f82f59 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2574,7 +2574,7 @@ Word32 BASOP_Util_Add_Mant32Exp( Word16 *exp_res ) { - Word32 tmp_res; + Word32 tmp1, tmp2, tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; scale_tmp = add( s_max( exp2, exp1 ), 1 ); -- GitLab From aa5533d0cec74bb4492e369da7c52d3d7f6903cc Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 27 Nov 2025 12:26:50 +0100 Subject: [PATCH 08/12] Revert "faster" This reverts commit 48c88257da7d3356dd9bed52a8c964b0de532108. --- lib_com/basop_util.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 805f82f59..16e9ad99f 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2577,22 +2577,24 @@ Word32 BASOP_Util_Add_Mant32Exp( Word32 tmp1, tmp2, tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; - scale_tmp = add( s_max( exp2, exp1 ), 1 ); - scale_tmp3 = sub( exp1, scale_tmp ); - if ( Mant1 != 0 ) + if ( Mant1 == 0 ) { - Mant1 = L_shl( Mant1, scale_tmp3 ); + exp1 = exp2; + move16(); } - scale_tmp3 = sub( exp2, scale_tmp ); - if ( Mant2 != 0 ) + if ( Mant2 == 0 ) { - Mant2 = L_shl( Mant2, scale_tmp3 ); + exp2 = exp1; + move16(); } + scale_tmp = add( s_max( exp2, exp1 ), 1 ); + tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - tmp_res = L_add( Mant1, Mant2 ); + tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp_res = L_add( tmp1, tmp2 ); scale_tmp2 = norm_l( tmp_res ); tmp_res = L_shl( tmp_res, scale_tmp2 ); -- GitLab From 05020caa92c3c556e82a9fe556243c26b4e0a4ac Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 2 Dec 2025 12:40:41 +0100 Subject: [PATCH 09/12] mux only version --- lib_com/basop_util.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 16e9ad99f..218a30ca6 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2566,6 +2566,11 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ */ #if 1 +static Word32 mux32( int decision, Word32 Lv1, Word32 Lv2 ) +{ + return Q6_R_mux_pRR( decision, Lv1, Lv2 ); +} + Word32 BASOP_Util_Add_Mant32Exp( Word32 Mant1, Word16 exp1, @@ -2577,35 +2582,26 @@ Word32 BASOP_Util_Add_Mant32Exp( Word32 tmp1, tmp2, tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; + int M1_iszero = EQ_32( Mant1, 0 ); + int M2_iszero = EQ_32( Mant2, 0 ); + exp2 = mux32( M2_iszero, exp1, exp2 ); + exp1 = mux32( M1_iszero, exp2, exp1 ); - if ( Mant1 == 0 ) - { - exp1 = exp2; - move16(); - } + Word16 e1e2max = s_max( exp2, exp1 ); + Word32 M1_M2 = L_shl( Mant1, sub( exp1, e1e2max ) ); + Word32 M2_M1 = L_shl( Mant2, sub( exp2, e1e2max ) ); - if ( Mant2 == 0 ) - { - exp2 = exp1; - move16(); - } + Mant1 = L_shr( mux32( M2_iszero, Mant1, M1_M2 ), 1 ); + Mant2 = L_shr( mux32( M1_iszero, Mant2, M2_M1 ), 1 ); - scale_tmp = add( s_max( exp2, exp1 ), 1 ); - tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); + tmp_res = L_add( Mant1, Mant2 ); - tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); - tmp_res = L_add( tmp1, tmp2 ); + scale_tmp = add( e1e2max, 1 ); scale_tmp2 = norm_l( tmp_res ); tmp_res = L_shl( tmp_res, scale_tmp2 ); - scale_tmp3 = 0; - move16(); - - if ( tmp_res != 0 ) - { - scale_tmp3 = sub( scale_tmp, scale_tmp2 ); - } + scale_tmp3 = mux32( EQ_32( tmp_res, 0 ), 0, sub( scale_tmp, scale_tmp2 ) ); *exp_res = scale_tmp3; move16(); -- GitLab From 17914e213d1dac10a26ae4670d72b8ad75d108bd Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Tue, 2 Dec 2025 14:43:08 +0100 Subject: [PATCH 10/12] Revert "mux only version" This reverts commit 05020caa92c3c556e82a9fe556243c26b4e0a4ac. --- lib_com/basop_util.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 845e3b139..78e00861a 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2513,11 +2513,6 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ */ #if 1 -static Word32 mux32(int decision, Word32 Lv1, Word32 Lv2) -{ - return Q6_R_mux_pRR(decision, Lv1, Lv2); -} - Word32 BASOP_Util_Add_Mant32Exp( Word32 Mant1, Word16 exp1, @@ -2529,26 +2524,35 @@ Word32 BASOP_Util_Add_Mant32Exp( Word32 tmp1, tmp2, tmp_res; Word16 scale_tmp, scale_tmp2, scale_tmp3; - int M1_iszero = EQ_32(Mant1, 0); - int M2_iszero = EQ_32(Mant2, 0); - exp2 = mux32(M2_iszero, exp1, exp2); - exp1 = mux32(M1_iszero, exp2, exp1); - Word16 e1e2max = s_max(exp2, exp1); - Word32 M1_M2 = L_shl(Mant1, sub(exp1, e1e2max)); - Word32 M2_M1 = L_shl(Mant2, sub(exp2, e1e2max)); + if ( Mant1 == 0 ) + { + exp1 = exp2; + move16(); + } - Mant1 = L_shr(mux32(M2_iszero, Mant1, M1_M2), 1); - Mant2 = L_shr(mux32(M1_iszero, Mant2, M2_M1), 1); + if ( Mant2 == 0 ) + { + exp2 = exp1; + move16(); + } - tmp_res = L_add(Mant1, Mant2); + scale_tmp = add( s_max( exp2, exp1 ), 1 ); + tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - scale_tmp = add(e1e2max, 1); + tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp_res = L_add( tmp1, tmp2 ); scale_tmp2 = norm_l(tmp_res); tmp_res = L_shl(tmp_res, scale_tmp2); - scale_tmp3 = mux32(EQ_32(tmp_res, 0), 0, sub(scale_tmp, scale_tmp2)); + scale_tmp3 = 0; + move16(); + + if ( tmp_res != 0 ) + { + scale_tmp3 = sub( scale_tmp, scale_tmp2 ); + } *exp_res = scale_tmp3; move16(); -- GitLab From aa83b914775ab502602b896d45df8cd6ba54f08b Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 4 Dec 2025 14:44:59 +0100 Subject: [PATCH 11/12] options --- lib_com/options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_com/options.h b/lib_com/options.h index 355f7dc1b..1072e2ae7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -85,6 +85,7 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define FIX_1435_MOVE_STEREO_PANNING /* VA: issue 1435: do the EVS stereo panning in the renderer */ +#define ISSUE_2247_Accelerate_AddMant32Exp /* FhG: inline and acelerate Heavily used BASOP_Util_AddMant32Exp */ /* #################### End BE switches ################################## */ -- GitLab From d3c8861d5ba935df55cace9ad4a164659ed11d13 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Thu, 4 Dec 2025 15:24:35 +0100 Subject: [PATCH 12/12] set new addmant32exp as inline --- lib_com/basop_util.c | 49 +------------------------------------------ lib_com/basop_util.h | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 78e00861a..b6ef548d1 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2512,54 +2512,7 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ headroom is introduced into acc */ -#if 1 -Word32 BASOP_Util_Add_Mant32Exp( - Word32 Mant1, - Word16 exp1, - Word32 Mant2, - Word16 exp2, - Word16* exp_res) -{ - - Word32 tmp1, tmp2, tmp_res; - Word16 scale_tmp, scale_tmp2, scale_tmp3; - - - if ( Mant1 == 0 ) - { - exp1 = exp2; - move16(); - } - - if ( Mant2 == 0 ) - { - exp2 = exp1; - move16(); - } - - scale_tmp = add( s_max( exp2, exp1 ), 1 ); - tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); - - tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); - tmp_res = L_add( tmp1, tmp2 ); - - scale_tmp2 = norm_l(tmp_res); - tmp_res = L_shl(tmp_res, scale_tmp2); - - scale_tmp3 = 0; - move16(); - - if ( tmp_res != 0 ) - { - scale_tmp3 = sub( scale_tmp, scale_tmp2 ); - } - - *exp_res = scale_tmp3; - move16(); - - return tmp_res; -} -#else +#ifndef ISSUE_2247_Accelerate_AddMant32Exp Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ ( Word32 a_m, /* i : Mantissa of 1st operand a */ Word16 a_e, /* i : Exponent of 1st operand a */ diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index c0f6df8cd..b437e78e4 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -59,6 +59,56 @@ #define CHEAP_NORM_SIZE 161 #endif +#ifdef ISSUE_2247_Accelerate_AddMant32Exp +static __inline Word32 BASOP_Util_Add_Mant32Exp( + Word32 Mant1, + Word16 exp1, + Word32 Mant2, + Word16 exp2, + Word16 *exp_res ) +{ + + Word32 tmp1, tmp2, tmp_res; + Word16 scale_tmp, scale_tmp2, scale_tmp3; + + + if ( Mant1 == 0 ) + { + exp1 = exp2; + move16(); + } + + if ( Mant2 == 0 ) + { + exp2 = exp1; + move16(); + } + + scale_tmp = add( s_max( exp2, exp1 ), 1 ); + tmp1 = L_shl( Mant1, sub( exp1, scale_tmp ) ); + + tmp2 = L_shl( Mant2, sub( exp2, scale_tmp ) ); + tmp_res = L_add( tmp1, tmp2 ); + + scale_tmp2 = norm_l( tmp_res ); + tmp_res = L_shl( tmp_res, scale_tmp2 ); + + scale_tmp3 = 0; + move16(); + + if ( tmp_res != 0 ) + { + scale_tmp3 = sub( scale_tmp, scale_tmp2 ); + } + + *exp_res = scale_tmp3; + move16(); + + return tmp_res; +} + +#endif + static __inline Word16 limitScale16( Word16 s ) { /* It is assumed, that s is calculated just before, therefore we can switch upon sign */ -- GitLab