From ec6f32c77f19dec09957e81c6d0d817713687c93 Mon Sep 17 00:00:00 2001 From: Fabian Bauer Date: Wed, 26 Nov 2025 16:25:41 +0100 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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