From 198ffcfe179ab43671976b446576c218a8585043 Mon Sep 17 00:00:00 2001 From: mave2802 <59919483+mave2802@users.noreply.github.com> Date: Thu, 23 Oct 2025 12:01:32 +0200 Subject: [PATCH 1/2] initial version of optimized BASOP_Util_Add_Mant32Exp() --- lib_com/basop_util.c | 65 +++++++++++++++++++++++++++++++++++++++++++- lib_com/options.h | 2 ++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 37619f4c1..4f0407b32 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2563,7 +2563,70 @@ Word16 BASOP_Util_Cmp_Mant32Exp /*!< o: flag: result of comparison */ headroom is introduced into acc */ +#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 */ + Word16 a_e, /* i : Exponent of 1st operand a */ + Word32 b_m, /* i : Mantissa of 2nd operand b */ + Word16 b_e, /* i : Exponent of 2nd operand b */ + Word16 *ptr_e ) /* o : exponent of result */ +{ + Word16 shift; + Word32 c_m; + Word16 c_e = 0; + + /* Compare exponents: the difference is limited to +/- 30 + The Word32 mantissa of the operand with lower exponent is shifted right by the exponent difference. + Then, the unshifted mantissa of the operand with the higher exponent is added. The addition result + is normalized and the result represents the mantissa to return. The returned exponent takes into + account all shift operations. +*/ + if ( !a_m ) + { + a_e = b_e; + move16(); + } + + if ( !b_m ) + { + b_e = a_e; + move16(); + } + shift = sub( a_e, b_e ); + if ( shift >= 0 ) + { + /* exponent of a is greater or equal than exponent of b */ + c_e = add( a_e, 1 ); + shift = add( shift, 1 ); + a_m = L_shr( a_m, 1 ); + b_m = L_shr( b_m, s_min( shift,31 )); + } + if ( shift < 0 ) + { + /* exponent of b is greater or equal than exponent of a */ + c_e = add( b_e, 1 ); + shift = sub( shift, 1 ); + a_m = L_shl( a_m, s_max( shift, -31)); + b_m = L_shr( b_m, 1 ); + } + c_m = L_add( a_m, b_m ); + if ( c_m == 0 ) + { + c_e = 0; + move16(); + } + if ( c_m != 0 ) + { + shift = norm_l( c_m ); + c_m = L_shl( c_m, shift ); + c_e = sub( c_e, shift ); + } + + *ptr_e = c_e; + return( c_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 */ @@ -2622,7 +2685,7 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ return ( L_tmp ); } - +#endif static const Word16 shift_lc[] = { 9, 10 }; diff --git a/lib_com/options.h b/lib_com/options.h index 7a6d1adad..d823c363b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -82,6 +82,7 @@ #define FIX_APA_EXECS_SCALING /* VA: fix scaling of JBM APA buffer */ #define FIX_2164_ASSERT_IN_OMASA_PREPROC_FOR_EDIT /* Nokia: Issue 2164: Prevent overflow when calculating equalization coefficient for editing before clamping to safe range */ #define FIX_BASOP_ASSERT_IN_TONAL_MDCT_PLC /* FhG: fix for issue 2165 - using saturating addition in tonal MDCT PLC function */ +#define OPT_2146_BASOP_UTIL_ADD_MANT32EXP /* Dlb: optimized version of BASOP_Util_Add_Mant32Exp() */ /* ################### End FIXES switches ########################### */ @@ -121,6 +122,7 @@ #define NONBE_FIX_1197_OMASA_META_BUFFER /* Nokia: OMASA ISM_MASA_MODE_PARAM_ONE_OBJ history zero in rateswitching - port 251 */ #define FIX_1413_IGF_INIT_PRINTOUT /* FhG: use correct variable for IGF initiliazation */ + // object-editing feature porting #define TMP_FIX_SPLIT_REND // temporary fix to split-rendering (it follows the later state of the framework but it is needed now because of current test-conditions) #define TMP_FIX_OMASA_SR_BE // temporary fix to keep OMASA split-rendering BE -- GitLab From f52f2eda773aa6fb9ca4adaafa558853ee7b11cd Mon Sep 17 00:00:00 2001 From: mave2802 <59919483+mave2802@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:30:55 +0100 Subject: [PATCH 2/2] refactored code according to STL 2024 Basop rules regarding usage of IF() vs if() --- lib_com/basop_util.c | 68 ++++++++++++++++++++++---------------------- lib_com/options.h | 1 - 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 4f0407b32..a65918ada 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -2572,15 +2572,13 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ Word16 *ptr_e ) /* o : exponent of result */ { Word16 shift; - Word32 c_m; - Word16 c_e = 0; + /* Compare exponents: the difference is limited to +/- 31 + The Word32 mantissa of the operand with lower exponent is shifted right by the exponent difference. + Then, the unshifted mantissa of the operand with the higher exponent is added. The addition result + is normalized and the result represents the mantissa to return. The returned exponent takes into + account all shift operations. + */ - /* Compare exponents: the difference is limited to +/- 30 - The Word32 mantissa of the operand with lower exponent is shifted right by the exponent difference. - Then, the unshifted mantissa of the operand with the higher exponent is added. The addition result - is normalized and the result represents the mantissa to return. The returned exponent takes into - account all shift operations. -*/ if ( !a_m ) { a_e = b_e; @@ -2592,39 +2590,42 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ b_e = a_e; move16(); } + shift = sub( a_e, b_e ); + + if ( shift > 0 ) + shift = s_min( shift, 31 ); + if ( shift < 0 ) + shift = s_max( shift, -31 ); + + /* shift > 0 exponent of a is greater than exponent of b */ + if ( shift > 0 ) + b_m = L_shr( b_m, shift ); + /* shift < 0 exponent of b is greater than exponent of a */ + if ( shift < 0 ) + a_m = L_shl( a_m, shift ); + + a_m = L_add( L_shr( a_m, 1 ), L_shr( b_m, 1 ) ); + if ( shift >= 0 ) - { - /* exponent of a is greater or equal than exponent of b */ - c_e = add( a_e, 1 ); - shift = add( shift, 1 ); - a_m = L_shr( a_m, 1 ); - b_m = L_shr( b_m, s_min( shift,31 )); - } + a_e = add( a_e, 1 ); if ( shift < 0 ) - { - /* exponent of b is greater or equal than exponent of a */ - c_e = add( b_e, 1 ); - shift = sub( shift, 1 ); - a_m = L_shl( a_m, s_max( shift, -31)); - b_m = L_shr( b_m, 1 ); - } - c_m = L_add( a_m, b_m ); + a_e = add( b_e, 1 ); - if ( c_m == 0 ) + shift = norm_l( a_m ); + if ( shift ) + a_m = L_shl( a_m, shift ); + if ( !a_m ) { - c_e = 0; + a_e = 0; move16(); } - if ( c_m != 0 ) - { - shift = norm_l( c_m ); - c_m = L_shl( c_m, shift ); - c_e = sub( c_e, shift ); - } + if ( a_m ) + a_e = sub( a_e, shift ); + + *ptr_e = a_e; - *ptr_e = c_e; - return( c_m ); + return ( a_m ); } #else Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ @@ -2643,7 +2644,6 @@ Word32 BASOP_Util_Add_Mant32Exp /* o : normalized result mantissa */ is normalized and the result represents the mantissa to return. The returned exponent takes into account all shift operations. */ - if ( !a_m ) { a_e = b_e; diff --git a/lib_com/options.h b/lib_com/options.h index d823c363b..f133a531f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -72,7 +72,6 @@ #endif /* ################### Start FIXES switches ########################### */ - #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK /* Eri: Issue 1999: Range check on float values of distance attenuation, while the float values are not propagated to this function. The test is not correct, but configurable distance attenuation is not used in Characterization.*/ #define TEMP_FIX_2088_MSAN_INIT_ERROR /* Eri: Temporary fix for Issue 2088 - MSAN error. Will come with later port of JBM+Split rendering update */ -- GitLab