From 267ec305aca39037677145fe1d314a8c7533266f Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 3 Nov 2025 14:57:23 +0000 Subject: [PATCH 1/8] Implement W_negate function. --- lib_basop/enh64.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib_basop/enh64.h | 1 + lib_debug/wmc_auto.c | 2 +- lib_debug/wmc_auto.h | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib_basop/enh64.c b/lib_basop/enh64.c index 8bffb620c..08534c8dc 100644 --- a/lib_basop/enh64.c +++ b/lib_basop/enh64.c @@ -128,6 +128,49 @@ Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) } +/*__________________________________________________________________________________ + | | + | Function Name : W_negate | + | | + | Purpose : | + | | + | Negate the 64 bit variable L64_var1 with saturation; saturate in the case | + | where input is 0x8000 0000 0000 0000. | + | | + | Complexity weight : 1 | + | | + | Inputs : | + | | + | L64_var1 64 bit long signed integer (Word64) whose value falls in the range: | + | 0x8000 0000 0000 0000 <= L64_var1 <= 0x7fff ffff ffff ffff. | + | | + | Outputs : | + | | + | none | + | | + | Return Value : | + | | + | L64_var_out | + | 64 bit long signed integer (Word64) whose value falls in the range: | + | 0x8000 0000 0000 0000 <= L_var_out <= 0x7fff ffff ffff ffff. | + |_________________________________________________________________________________| +*/ +Word64 W_negate( Word64 L64_var1 ) +{ + Word64 L64_var_out; + + L64_var_out = ( L64_var1 == MIN_64 ) ? MAX_64 : -L64_var1; + +#ifdef WMOPS + multiCounter[currCounter].W_negate++; +#endif + + BASOP_CHECK(); + + return ( L64_var_out ); +} + + /*___________________________________________________________________________ | | | Function Name : W_shl | diff --git a/lib_basop/enh64.h b/lib_basop/enh64.h index c3896bb0d..7358fc56b 100644 --- a/lib_basop/enh64.h +++ b/lib_basop/enh64.h @@ -23,6 +23,7 @@ #ifdef ENH_64_BIT_OPERATOR Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ); Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_negate( Word64 L64_var1 ); Word64 W_shl( Word64 L64_var1, Word16 var2 ); Word64 W_shr( Word64 L64_var1, Word16 var2 ); Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ); diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index 5afd9de16..e7cc88031 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -133,7 +133,7 @@ static BASIC_OP op_weight = { #ifdef ENH_64_BIT_OPERATOR /* Weights of new 64 bit basops */ , - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 64e2c751a..a1465df58 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -879,6 +879,7 @@ typedef struct unsigned int move64; /* Complexity Weight of 1 */ unsigned int W_add_nosat; /* Complexity Weight of 1 */ unsigned int W_sub_nosat; /* Complexity Weight of 1 */ + unsigned int W_negate; /* Complexity Weight of 1 */ unsigned int W_shl; /* Complexity Weight of 1 */ unsigned int W_shr; /* Complexity Weight of 1 */ unsigned int W_shl_nosat; /* Complexity Weight of 1 */ -- GitLab From 297ef63119fb51b2509b20bd884deeacf31885d2 Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 3 Nov 2025 14:57:23 +0000 Subject: [PATCH 2/8] Optimize matrixTransp1Mul_fx. --- lib_com/options.h | 6 +++ .../ivas_dirac_dec_binaural_functions_fx.c | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index c967fd233..729e366af 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -138,4 +138,10 @@ /* #################### End BASOP porting switches ############################ */ +/* #################### Start BASOP optimization switches ############################ */ + +#define OPT_2181_MATRIX_TRANSP_1_MUL /* Dolby: Issue 2181, optimize matrixTransp1Mul_fx. */ + +/* #################### End BASOP optimization switches ############################ */ + #endif diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 60bbce7a9..10085a477 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -3997,6 +3997,44 @@ static void matrixTransp1Mul_fx( Word64 tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; Word64 tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; +#ifdef OPT_2181_MATRIX_TRANSP_1_MUL + Word64 tmp64; + Word16 common_lsh; + common_lsh = 63; + move16(); + + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + tmp64 = W_mult_32_32( Are_fx[0][chA], Bre_fx[0][chB] ); + tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bre_fx[1][chB] ); + tmp64 = W_mac_32_32( tmp64, Aim_fx[0][chA], Bim_fx[0][chB] ); + tmp_outRe_fx[chA][chB] = tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bim_fx[1][chB] ); + move64(); + common_lsh = s_min( common_lsh, W_norm( tmp64 ) ); + + tmp64 = W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ); + tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bre_fx[1][chB] ); + tmp64 = W_mac_32_32( W_negate( tmp64 ), Are_fx[0][chA], Bim_fx[0][chB] ); + tmp_outIm_fx[chA][chB] = tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bim_fx[1][chB] ); + move64(); + common_lsh = s_min( common_lsh, W_norm( tmp64 ) ); + } + } + FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) + { + FOR( chB = 0; chB < BINAURAL_CHANNELS; chB++ ) + { + outRe_fx[chA][chB] = W_extract_h( W_shl( tmp_outRe_fx[chA][chB], common_lsh ) ); + move32(); + outIm_fx[chA][chB] = W_extract_h( W_shl( tmp_outIm_fx[chA][chB], common_lsh ) ); + move32(); + } + } + *q_out = add( add( add( q_A, q_B ), 1 ), common_lsh ); + move16(); +#else Word16 q_tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; Word16 q_tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; Word64 tmp64_1, tmp64_2; @@ -4043,6 +4081,7 @@ static void matrixTransp1Mul_fx( } *q_out = sub( q_common, 32 ); move16(); +#endif if ( L_and( is_zero_arr( outRe_fx[0], size ), is_zero_arr( outIm_fx[0], size ) ) ) { *q_out = Q31; -- GitLab From a8316e76a9c61199420ebf403e19d10ebaeb2b02 Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 3 Nov 2025 16:01:44 +0000 Subject: [PATCH 3/8] Fix q_out. --- lib_rend/ivas_dirac_dec_binaural_functions_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 10085a477..93b9778a6 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -4032,7 +4032,7 @@ static void matrixTransp1Mul_fx( move32(); } } - *q_out = add( add( add( q_A, q_B ), 1 ), common_lsh ); + *q_out = sub( add( add( add( q_A, q_B ), 1 ), common_lsh ), 32 ); move16(); #else Word16 q_tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; -- GitLab From d1225c4dfa009961d7dda2b164e47f5b5af62b2f Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 3 Nov 2025 17:11:09 +0000 Subject: [PATCH 4/8] Fix common left shift initial value. --- lib_rend/ivas_dirac_dec_binaural_functions_fx.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 93b9778a6..fda10d47c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -3999,8 +3999,9 @@ static void matrixTransp1Mul_fx( Word64 tmp_outIm_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; #ifdef OPT_2181_MATRIX_TRANSP_1_MUL Word64 tmp64; - Word16 common_lsh; - common_lsh = 63; + Word16 common_lsh, q; + q = add( add( q_A, q_B ), 1 ); + common_lsh = sub( 63, q ); move16(); FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) @@ -4032,7 +4033,7 @@ static void matrixTransp1Mul_fx( move32(); } } - *q_out = sub( add( add( add( q_A, q_B ), 1 ), common_lsh ), 32 ); + *q_out = sub( add( q, common_lsh ), 32 ); move16(); #else Word16 q_tmp_outRe_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS]; -- GitLab From 24c1c3724a1a46256b537595b0f2e8c9b14e877f Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Wed, 5 Nov 2025 13:59:43 +0000 Subject: [PATCH 5/8] Use W_neg instead of W_negate. --- lib_basop/enh64.c | 43 ------------------- lib_basop/enh64.h | 1 - lib_debug/wmc_auto.c | 2 +- lib_debug/wmc_auto.h | 1 - .../ivas_dirac_dec_binaural_functions_fx.c | 2 +- 5 files changed, 2 insertions(+), 47 deletions(-) diff --git a/lib_basop/enh64.c b/lib_basop/enh64.c index 08534c8dc..8bffb620c 100644 --- a/lib_basop/enh64.c +++ b/lib_basop/enh64.c @@ -128,49 +128,6 @@ Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) } -/*__________________________________________________________________________________ - | | - | Function Name : W_negate | - | | - | Purpose : | - | | - | Negate the 64 bit variable L64_var1 with saturation; saturate in the case | - | where input is 0x8000 0000 0000 0000. | - | | - | Complexity weight : 1 | - | | - | Inputs : | - | | - | L64_var1 64 bit long signed integer (Word64) whose value falls in the range: | - | 0x8000 0000 0000 0000 <= L64_var1 <= 0x7fff ffff ffff ffff. | - | | - | Outputs : | - | | - | none | - | | - | Return Value : | - | | - | L64_var_out | - | 64 bit long signed integer (Word64) whose value falls in the range: | - | 0x8000 0000 0000 0000 <= L_var_out <= 0x7fff ffff ffff ffff. | - |_________________________________________________________________________________| -*/ -Word64 W_negate( Word64 L64_var1 ) -{ - Word64 L64_var_out; - - L64_var_out = ( L64_var1 == MIN_64 ) ? MAX_64 : -L64_var1; - -#ifdef WMOPS - multiCounter[currCounter].W_negate++; -#endif - - BASOP_CHECK(); - - return ( L64_var_out ); -} - - /*___________________________________________________________________________ | | | Function Name : W_shl | diff --git a/lib_basop/enh64.h b/lib_basop/enh64.h index 7358fc56b..c3896bb0d 100644 --- a/lib_basop/enh64.h +++ b/lib_basop/enh64.h @@ -23,7 +23,6 @@ #ifdef ENH_64_BIT_OPERATOR Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ); Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ); -Word64 W_negate( Word64 L64_var1 ); Word64 W_shl( Word64 L64_var1, Word16 var2 ); Word64 W_shr( Word64 L64_var1, Word16 var2 ); Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ); diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index e7cc88031..5afd9de16 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -133,7 +133,7 @@ static BASIC_OP op_weight = { #ifdef ENH_64_BIT_OPERATOR /* Weights of new 64 bit basops */ , - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index a1465df58..64e2c751a 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -879,7 +879,6 @@ typedef struct unsigned int move64; /* Complexity Weight of 1 */ unsigned int W_add_nosat; /* Complexity Weight of 1 */ unsigned int W_sub_nosat; /* Complexity Weight of 1 */ - unsigned int W_negate; /* Complexity Weight of 1 */ unsigned int W_shl; /* Complexity Weight of 1 */ unsigned int W_shr; /* Complexity Weight of 1 */ unsigned int W_shl_nosat; /* Complexity Weight of 1 */ diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 154e75762..416a8a71c 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -4041,7 +4041,7 @@ static void matrixTransp1Mul_fx( tmp64 = W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ); tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bre_fx[1][chB] ); - tmp64 = W_mac_32_32( W_negate( tmp64 ), Are_fx[0][chA], Bim_fx[0][chB] ); + tmp64 = W_mac_32_32( W_neg( tmp64 ), Are_fx[0][chA], Bim_fx[0][chB] ); tmp_outIm_fx[chA][chB] = tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bim_fx[1][chB] ); move64(); common_lsh = s_min( common_lsh, W_norm( tmp64 ) ); -- GitLab From b916c938510d273a1bc04f45666f44ddcac6852e Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Wed, 5 Nov 2025 14:03:17 +0000 Subject: [PATCH 6/8] Fix build failure. --- lib_dec/ivas_ism_metadata_dec_fx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_ism_metadata_dec_fx.c b/lib_dec/ivas_ism_metadata_dec_fx.c index 54cc5da15..4d3c06b9c 100644 --- a/lib_dec/ivas_ism_metadata_dec_fx.c +++ b/lib_dec/ivas_ism_metadata_dec_fx.c @@ -30,7 +30,6 @@ *******************************************************************************************************/ -#include "move.h" #include #include "options.h" #include "ivas_cnst.h" @@ -40,6 +39,7 @@ #include "ivas_stat_enc.h" #include #include "wmc_auto.h" +#include "move.h" #include "ivas_prot_fx.h" -- GitLab From c551423d14fc113e75e55bcb92f4c6289747a480 Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 10 Nov 2025 10:42:08 +0000 Subject: [PATCH 7/8] Address Thomas Dettbarn's comments. --- lib_rend/ivas_dirac_dec_binaural_functions_fx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c index 416a8a71c..351f59453 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions_fx.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions_fx.c @@ -4035,16 +4035,16 @@ static void matrixTransp1Mul_fx( tmp64 = W_mult_32_32( Are_fx[0][chA], Bre_fx[0][chB] ); tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bre_fx[1][chB] ); tmp64 = W_mac_32_32( tmp64, Aim_fx[0][chA], Bim_fx[0][chB] ); - tmp_outRe_fx[chA][chB] = tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bim_fx[1][chB] ); + tmp_outRe_fx[chA][chB] = W_mac_32_32( tmp64, Aim_fx[1][chA], Bim_fx[1][chB] ); move64(); - common_lsh = s_min( common_lsh, W_norm( tmp64 ) ); + common_lsh = s_min( common_lsh, W_norm( tmp_outRe_fx[chA][chB] ) ); tmp64 = W_mult_32_32( Aim_fx[0][chA], Bre_fx[0][chB] ); tmp64 = W_mac_32_32( tmp64, Aim_fx[1][chA], Bre_fx[1][chB] ); tmp64 = W_mac_32_32( W_neg( tmp64 ), Are_fx[0][chA], Bim_fx[0][chB] ); - tmp_outIm_fx[chA][chB] = tmp64 = W_mac_32_32( tmp64, Are_fx[1][chA], Bim_fx[1][chB] ); + tmp_outIm_fx[chA][chB] = W_mac_32_32( tmp64, Are_fx[1][chA], Bim_fx[1][chB] ); move64(); - common_lsh = s_min( common_lsh, W_norm( tmp64 ) ); + common_lsh = s_min( common_lsh, W_norm( tmp_outIm_fx[chA][chB] ) ); } } FOR( chA = 0; chA < BINAURAL_CHANNELS; chA++ ) -- GitLab From 417d9326159b17c68fa77976059edb4354a48a67 Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Tue, 2 Dec 2025 13:58:14 +0000 Subject: [PATCH 8/8] Apply clang format. --- lib_com/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index b79c649f2..17347d0d9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -106,7 +106,7 @@ /* #################### Start BASOP optimization switches ############################ */ -#define OPT_2181_MATRIX_TRANSP_1_MUL /* Dolby: Issue 2181, optimize matrixTransp1Mul_fx. */ +#define OPT_2181_MATRIX_TRANSP_1_MUL /* Dolby: Issue 2181, optimize matrixTransp1Mul_fx. */ /* #################### End BASOP optimization switches ############################ */ -- GitLab