From 8d095e08e97db5268b80fab66d81c12b97213129 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 4 Jun 2025 10:34:26 +0200 Subject: [PATCH 01/13] first draft of the optimized householder reduction. --- lib_dec/ivas_svd_dec.c | 148 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 145 insertions(+), 3 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index d4ac7d139..fa06e3010 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -29,6 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ +//#define MYCHANGES #include #include "options.h" @@ -58,8 +59,11 @@ *-----------------------------------------------------------------------*/ static float GivensRotation( const float x, const float z ); - +#ifdef MYCHANGES +static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float sig_x, float g ); +#else static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); +#endif static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); @@ -493,7 +497,11 @@ static void HouseholderReduction( /* Bidiagonal Reduction for every channel */ for ( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { +#ifdef MYCHANGES + biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, sig_x, g ); +#else biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); +#endif biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); *eps_x = max( *eps_x, ( fabsf( singularValues[nCh] ) + fabsf( secDiag[nCh] ) ) ); } @@ -512,6 +520,71 @@ static void HouseholderReduction( * *-------------------------------------------------------------------------*/ +#ifdef MYCHANGES +static void biDiagonalReductionLeft( + float singularVectors[][MAX_OUTPUT_CHANNELS], + float singularValues[MAX_OUTPUT_CHANNELS], + float secDiag[MAX_OUTPUT_CHANNELS], + const int16_t nChannelsL, + const int16_t nChannelsC, + const int16_t currChannel, + float sig_x, + float g ) +{ + int16_t iCh, jCh; + float norm_x, f, r; + + secDiag[currChannel] = ( sig_x ) * ( g ); + + /* Setting values to 0 */ + sig_x = 0.0f; + g = 0.0f; + + if ( currChannel < nChannelsL ) /* i <= m */ + { + for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + { + sig_x += fabsf( singularVectors[jCh][currChannel] ); + } + if ( ( sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + { + norm_x = 0.0f; + + + for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + { + norm_x += ( singularVectors[jCh][currChannel] * singularVectors[jCh][currChannel] ); + } + g = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); + r = g * singularVectors[currChannel][currChannel] - norm_x; + singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - g ); + + for ( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ + { + norm_x = 0.0f; + for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + { + norm_x += ( singularVectors[jCh][currChannel] * singularVectors[jCh][iCh] ); + } + + f = norm_x / maxWithSign( r ); + + + for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ + { + singularVectors[jCh][iCh] += ( f * singularVectors[jCh][currChannel] ); + } + } + } + + singularValues[currChannel] = g; + } + + return; +} + +#else + static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], @@ -582,14 +655,83 @@ static void biDiagonalReductionLeft( return; } - +#endif /*------------------------------------------------------------------------- * biDiagonalReductionRight() * * *-------------------------------------------------------------------------*/ +#ifdef MYCHANGES +static void biDiagonalReductionRight( + float singularVectors[][MAX_OUTPUT_CHANNELS], + float secDiag[MAX_OUTPUT_CHANNELS], + const int16_t nChannelsL, + const int16_t nChannelsC, + const int16_t currChannel, + float *sig_x, + float *g ) +{ + int16_t iCh, jCh, idx; + float norm_x, r; + + /* Setting values to 0 */ + ( *sig_x ) = 0.0f; + ( *g ) = 0.0f; + + if ( currChannel < nChannelsL && currChannel != ( nChannelsC - 1 ) ) /* i <=m && i !=n */ + { + idx = currChannel + 1; + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + ( *sig_x ) += fabsf( singularVectors[currChannel][jCh] ); + } + + if ( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + { + norm_x = 0.0f; + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ + { + norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); + } + ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); + r = ( *g ) * singularVectors[currChannel][idx] - norm_x; + singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + secDiag[jCh] = singularVectors[currChannel][jCh] / maxWithSign( r ); + } + + for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ + { + norm_x = 0.0f; + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); + } + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + singularVectors[iCh][jCh] += ( norm_x * secDiag[jCh] ); + } + } + ( *g ) = ( *g ) / maxWithSign( *sig_x ); + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + singularVectors[currChannel][jCh] = ( singularVectors[currChannel][jCh] * ( *sig_x ) ); + } + } + } + + return; +} + + +#else static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], @@ -657,7 +799,7 @@ static void biDiagonalReductionRight( return; } - +#endif /*------------------------------------------------------------------------- * singularVectorsAccumulationLeft() * -- GitLab From fb373c802ac9c2e4cc8e860079720d7d94ae2536 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 4 Jun 2025 11:06:53 +0200 Subject: [PATCH 02/13] optimizations in biDiagonalReductionLeft() and biDiagonalReductionRight() reduced the WMOPS. --- lib_dec/ivas_svd_dec.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index fa06e3010..1e57dd694 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -29,7 +29,7 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ -//#define MYCHANGES +#define MYCHANGES #include #include "options.h" @@ -719,11 +719,6 @@ static void biDiagonalReductionRight( } } ( *g ) = ( *g ) / maxWithSign( *sig_x ); - - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ - { - singularVectors[currChannel][jCh] = ( singularVectors[currChannel][jCh] * ( *sig_x ) ); - } } } -- GitLab From ae31c412dfd5e25c9246fe1f96eecf4f8e01df8b Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 4 Jun 2025 11:20:13 +0200 Subject: [PATCH 03/13] added a new define NONBE_SVD_OPTIMIZATION to encapsulate changes in ivas_svd_dec.c --- lib_com/options.h | 4 ++- lib_dec/ivas_svd_dec.c | 61 +++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 16880c701..706b8c347 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -143,9 +143,11 @@ /* ################### Start FIXES switches ########################### */ - /* #################### End FIXES switches ############################ */ +/* ################### Start NONBE switches ########################### */ +#define NONBE_SVD_OPTIMIZATION +/* #################### End NONBE switches ############################ */ /* clang-format on */ diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 1e57dd694..6021dd375 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -29,7 +29,6 @@ the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ -#define MYCHANGES #include #include "options.h" @@ -59,13 +58,14 @@ *-----------------------------------------------------------------------*/ static float GivensRotation( const float x, const float z ); -#ifdef MYCHANGES -static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float sig_x, float g ); +#ifdef NONBE_SVD_OPTIMIZATION +static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float g ); +static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *g ); #else static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); +static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); #endif -static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); static void singularVectorsAccumulationLeft( float singularVectors_Left[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC ); @@ -492,17 +492,23 @@ static void HouseholderReduction( float *eps_x ) { int16_t nCh; - float g = 0.0f, sig_x = 0.0f; + float g = 0.0f; +#ifdef NONBE_SVD_OPTIMIZATION + +#else + float sig_x = 0.0f; +#endif /* Bidiagonal Reduction for every channel */ for ( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { -#ifdef MYCHANGES - biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, sig_x, g ); +#ifdef NONBE_SVD_OPTIMIZATION + biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, g ); + biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &g ); #else biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); -#endif biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); +#endif *eps_x = max( *eps_x, ( fabsf( singularValues[nCh] ) + fabsf( secDiag[nCh] ) ) ); } @@ -520,7 +526,7 @@ static void HouseholderReduction( * *-------------------------------------------------------------------------*/ -#ifdef MYCHANGES +#ifdef NONBE_SVD_OPTIMIZATION static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], @@ -528,33 +534,27 @@ static void biDiagonalReductionLeft( const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, - float sig_x, float g ) { int16_t iCh, jCh; float norm_x, f, r; - secDiag[currChannel] = ( sig_x ) * ( g ); + secDiag[currChannel] = g; /* Setting values to 0 */ - sig_x = 0.0f; g = 0.0f; if ( currChannel < nChannelsL ) /* i <= m */ { + norm_x = 0.0f; + + for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ { - sig_x += fabsf( singularVectors[jCh][currChannel] ); + norm_x += ( singularVectors[jCh][currChannel] * singularVectors[jCh][currChannel] ); } - if ( ( sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + if ( ( norm_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { - norm_x = 0.0f; - - - for ( jCh = currChannel; jCh < nChannelsL; jCh++ ) /* nChannelsL */ - { - norm_x += ( singularVectors[jCh][currChannel] * singularVectors[jCh][currChannel] ); - } g = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); r = g * singularVectors[currChannel][currChannel] - norm_x; singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - g ); @@ -662,40 +662,34 @@ static void biDiagonalReductionLeft( * * *-------------------------------------------------------------------------*/ -#ifdef MYCHANGES +#ifdef NONBE_SVD_OPTIMIZATION static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, - float *sig_x, float *g ) { int16_t iCh, jCh, idx; float norm_x, r; /* Setting values to 0 */ - ( *sig_x ) = 0.0f; ( *g ) = 0.0f; if ( currChannel < nChannelsL && currChannel != ( nChannelsC - 1 ) ) /* i <=m && i !=n */ { idx = currChannel + 1; - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + norm_x = 0.0f; + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { - ( *sig_x ) += fabsf( singularVectors[currChannel][jCh] ); + norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); } - if ( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + if ( norm_x ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { - norm_x = 0.0f; - - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ - { - norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); - } ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); r = ( *g ) * singularVectors[currChannel][idx] - norm_x; singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); @@ -718,7 +712,6 @@ static void biDiagonalReductionRight( singularVectors[iCh][jCh] += ( norm_x * secDiag[jCh] ); } } - ( *g ) = ( *g ) / maxWithSign( *sig_x ); } } -- GitLab From 1503ea89937f16648133983c3f14debfa6b38cc7 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Wed, 4 Jun 2025 11:35:25 +0200 Subject: [PATCH 04/13] applied the clang patch. --- lib_dec/ivas_svd_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 6021dd375..e9af487ef 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -493,7 +493,7 @@ static void HouseholderReduction( { int16_t nCh; float g = 0.0f; -#ifdef NONBE_SVD_OPTIMIZATION +#ifdef NONBE_SVD_OPTIMIZATION #else float sig_x = 0.0f; @@ -502,7 +502,7 @@ static void HouseholderReduction( /* Bidiagonal Reduction for every channel */ for ( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { -#ifdef NONBE_SVD_OPTIMIZATION +#ifdef NONBE_SVD_OPTIMIZATION biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, g ); biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &g ); #else @@ -526,7 +526,7 @@ static void HouseholderReduction( * *-------------------------------------------------------------------------*/ -#ifdef NONBE_SVD_OPTIMIZATION +#ifdef NONBE_SVD_OPTIMIZATION static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], @@ -662,7 +662,7 @@ static void biDiagonalReductionLeft( * * *-------------------------------------------------------------------------*/ -#ifdef NONBE_SVD_OPTIMIZATION +#ifdef NONBE_SVD_OPTIMIZATION static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], -- GitLab From f23ca0983144d7db2525bf44fbc163e040c16ca3 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 10 Jun 2025 13:55:49 +0200 Subject: [PATCH 05/13] biDiagonalReductionRight() was not calculating the secDiag Vector correctly. --- lib_dec/ivas_svd_dec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index e9af487ef..eeb91dff1 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -42,7 +42,6 @@ #endif #include "wmc_auto.h" - /*-----------------------------------------------------------------------* * Local constants *-----------------------------------------------------------------------*/ @@ -512,6 +511,7 @@ static void HouseholderReduction( *eps_x = max( *eps_x, ( fabsf( singularValues[nCh] ) + fabsf( secDiag[nCh] ) ) ); } + /* SingularVecotr Accumulation */ singularVectorsAccumulationRight( singularVectors_Left, singularVectors_Right, secDiag, nChannelsC ); singularVectorsAccumulationLeft( singularVectors_Left, singularValues, nChannelsL, nChannelsC ); @@ -673,6 +673,7 @@ static void biDiagonalReductionRight( { int16_t iCh, jCh, idx; float norm_x, r; + float abs_x; /* Setting values to 0 */ ( *g ) = 0.0f; @@ -682,10 +683,12 @@ static void biDiagonalReductionRight( idx = currChannel + 1; norm_x = 0.0f; + abs_x = 0.0f; for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ { norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); + abs_x += fabs( singularVectors[currChannel][jCh] ); } if ( norm_x ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ @@ -693,10 +696,9 @@ static void biDiagonalReductionRight( ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); r = ( *g ) * singularVectors[currChannel][idx] - norm_x; singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - secDiag[jCh] = singularVectors[currChannel][jCh] / maxWithSign( r ); + secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x )/ maxWithSign( r ); } for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ @@ -706,7 +708,7 @@ static void biDiagonalReductionRight( { norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); } - + norm_x /= abs_x; for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { singularVectors[iCh][jCh] += ( norm_x * secDiag[jCh] ); @@ -762,7 +764,6 @@ static void biDiagonalReductionRight( { secDiag[jCh] = singularVectors[currChannel][jCh] / maxWithSign( r ); } - for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { norm_x = 0.0f; -- GitLab From 4181ddda3d8ec3222cfd8c620b2d81018db71f0f Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 10 Jun 2025 14:18:33 +0200 Subject: [PATCH 06/13] applied the clang patch. --- lib_dec/ivas_svd_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index eeb91dff1..22e780efb 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -698,7 +698,7 @@ static void biDiagonalReductionRight( singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x )/ maxWithSign( r ); + secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x ) / maxWithSign( r ); } for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ -- GitLab From d1e053b3d7f4f151715a484914bf8539af6cd9f9 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 13 Jun 2025 09:57:26 +0200 Subject: [PATCH 07/13] in ivas_svd_dec.c, changed an awkward ifdef (empty) else ... endif construct into ifndef ... endif. --- lib_dec/ivas_svd_dec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 22e780efb..7d4141358 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -492,9 +492,7 @@ static void HouseholderReduction( { int16_t nCh; float g = 0.0f; -#ifdef NONBE_SVD_OPTIMIZATION - -#else +#ifndef NONBE_SVD_OPTIMIZATION float sig_x = 0.0f; #endif -- GitLab From 23dc9ec2f7e4f374a3163e7cd037e9d69243cf88 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 17 Jun 2025 11:04:09 +0200 Subject: [PATCH 08/13] moved local variables from biDiagonalReductionLeft() to biDiagonalReductionRight() for clarification. --- lib_dec/ivas_svd_dec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 7d4141358..47f88759f 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -58,7 +58,7 @@ static float GivensRotation( const float x, const float z ); #ifdef NONBE_SVD_OPTIMIZATION -static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float g ); +static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel ); static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *g ); #else static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); @@ -500,7 +500,7 @@ static void HouseholderReduction( for ( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { #ifdef NONBE_SVD_OPTIMIZATION - biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, g ); + biDiagonalReductionLeft( singularVectors_Left, singularValues, nChannelsL, nChannelsC, nCh ); biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &g ); #else biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); @@ -528,16 +528,12 @@ static void HouseholderReduction( static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], - float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, - const int16_t currChannel, - float g ) + const int16_t currChannel ) { int16_t iCh, jCh; - float norm_x, f, r; - - secDiag[currChannel] = g; + float norm_x, f, r, g; /* Setting values to 0 */ g = 0.0f; @@ -673,6 +669,8 @@ static void biDiagonalReductionRight( float norm_x, r; float abs_x; + secDiag[currChannel] = *g; + /* Setting values to 0 */ ( *g ) = 0.0f; -- GitLab From f4acb2d589bdf6c1313c68a3bb18d32c0fc91a2f Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 17 Jun 2025 11:43:24 +0200 Subject: [PATCH 09/13] reduced the role of abs_x in biDiagonalReductionRight() --- lib_dec/ivas_svd_dec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 47f88759f..548c3cf5e 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -692,10 +692,6 @@ static void biDiagonalReductionRight( ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); r = ( *g ) * singularVectors[currChannel][idx] - norm_x; singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ - { - secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x ) / maxWithSign( r ); - } for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ { @@ -704,12 +700,16 @@ static void biDiagonalReductionRight( { norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); } - norm_x /= abs_x; + norm_x /= r ; for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { - singularVectors[iCh][jCh] += ( norm_x * secDiag[jCh] ); + singularVectors[iCh][jCh] += ( norm_x * singularVectors[currChannel][jCh] ); } } + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x ) / maxWithSign( r ); + } } } -- GitLab From ffbb5a15ddb0d312f75929a458557d0c80d17f7e Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Tue, 17 Jun 2025 12:02:00 +0200 Subject: [PATCH 10/13] clang patch applied. --- lib_dec/ivas_svd_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 548c3cf5e..ada828d04 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -700,7 +700,7 @@ static void biDiagonalReductionRight( { norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); } - norm_x /= r ; + norm_x /= r; for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ { singularVectors[iCh][jCh] += ( norm_x * singularVectors[currChannel][jCh] ); -- GitLab From 3d6a0b86dfdd08a3656a112d42afee8c0215cb3a Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 18 Jul 2025 11:32:40 +0200 Subject: [PATCH 11/13] Code cleanup in the HouseholderReduction(), biDiagonalReduction_Left() and biDiagonalReduction_Right() functions. Removed one more redundant mathematical operation. --- lib_dec/ivas_svd_dec.c | 152 +++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 75 deletions(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index ada828d04..97ab43b00 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -58,8 +58,8 @@ static float GivensRotation( const float x, const float z ); #ifdef NONBE_SVD_OPTIMIZATION -static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel ); -static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *g ); +static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *g ); +static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *g ); #else static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); static void biDiagonalReductionRight( float singularVectors[][MAX_OUTPUT_CHANNELS], float secDiag[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, const int16_t currChannel, float *sig_x, float *g ); @@ -491,17 +491,22 @@ static void HouseholderReduction( float *eps_x ) { int16_t nCh; - float g = 0.0f; -#ifndef NONBE_SVD_OPTIMIZATION +#ifdef NONBE_SVD_OPTIMIZATION + float g_left = 0.0f; + float g_right = 0.0f; +#else float sig_x = 0.0f; + float g = 0.0f; #endif /* Bidiagonal Reduction for every channel */ for ( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */ { #ifdef NONBE_SVD_OPTIMIZATION - biDiagonalReductionLeft( singularVectors_Left, singularValues, nChannelsL, nChannelsC, nCh ); - biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &g ); + secDiag[nCh] = g_right; /* from the previous channel */ + biDiagonalReductionLeft( singularVectors_Left, nChannelsL, nChannelsC, nCh, &g_left ); + singularValues[nCh] = g_left; + biDiagonalReductionRight( singularVectors_Left, nChannelsL, nChannelsC, nCh, &g_right ); #else biDiagonalReductionLeft( singularVectors_Left, singularValues, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); biDiagonalReductionRight( singularVectors_Left, secDiag, nChannelsL, nChannelsC, nCh, &sig_x, &g ); @@ -518,25 +523,24 @@ static void HouseholderReduction( } +#ifdef NONBE_SVD_OPTIMIZATION /*------------------------------------------------------------------------- * biDiagonalReductionLeft() * * *-------------------------------------------------------------------------*/ - -#ifdef NONBE_SVD_OPTIMIZATION static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], - float singularValues[MAX_OUTPUT_CHANNELS], const int16_t nChannelsL, const int16_t nChannelsC, - const int16_t currChannel ) + const int16_t currChannel, + float *g ) { int16_t iCh, jCh; - float norm_x, f, r, g; + float norm_x, f, r; /* Setting values to 0 */ - g = 0.0f; + ( *g ) = 0.0f; if ( currChannel < nChannelsL ) /* i <= m */ { @@ -549,9 +553,9 @@ static void biDiagonalReductionLeft( } if ( ( norm_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ { - g = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); - r = g * singularVectors[currChannel][currChannel] - norm_x; - singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - g ); + ( *g ) = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); + r = ( *g ) * singularVectors[currChannel][currChannel] - norm_x; + singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - ( *g ) ); for ( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */ { @@ -570,8 +574,60 @@ static void biDiagonalReductionLeft( } } } + } + + return; +} + +/*------------------------------------------------------------------------- + * biDiagonalReductionRight() + * + * + *-------------------------------------------------------------------------*/ +static void biDiagonalReductionRight( + float singularVectors[][MAX_OUTPUT_CHANNELS], + const int16_t nChannelsL, + const int16_t nChannelsC, + const int16_t currChannel, + float *g ) +{ + int16_t iCh, jCh, idx; + float norm_x, r; + + /* Setting values to 0 */ + ( *g ) = 0.0f; + + if ( currChannel < nChannelsL && currChannel != ( nChannelsC - 1 ) ) /* i <=m && i !=n */ + { + idx = currChannel + 1; + + norm_x = 0.0f; + + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ + { + norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); + } - singularValues[currChannel] = g; + if ( norm_x ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ + { + ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); + r = ( *g ) * singularVectors[currChannel][idx] - norm_x; + singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); + + for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ + { + norm_x = 0.0f; + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); + } + norm_x /= r; + for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ + { + singularVectors[iCh][jCh] += ( norm_x * singularVectors[currChannel][jCh] ); + } + } + } } return; @@ -579,6 +635,11 @@ static void biDiagonalReductionLeft( #else +/*------------------------------------------------------------------------- + * biDiagonalReductionLeft() + * + * + *-------------------------------------------------------------------------*/ static void biDiagonalReductionLeft( float singularVectors[][MAX_OUTPUT_CHANNELS], float singularValues[MAX_OUTPUT_CHANNELS], @@ -657,65 +718,6 @@ static void biDiagonalReductionLeft( * *-------------------------------------------------------------------------*/ #ifdef NONBE_SVD_OPTIMIZATION -static void biDiagonalReductionRight( - float singularVectors[][MAX_OUTPUT_CHANNELS], - float secDiag[MAX_OUTPUT_CHANNELS], - const int16_t nChannelsL, - const int16_t nChannelsC, - const int16_t currChannel, - float *g ) -{ - int16_t iCh, jCh, idx; - float norm_x, r; - float abs_x; - - secDiag[currChannel] = *g; - - /* Setting values to 0 */ - ( *g ) = 0.0f; - - if ( currChannel < nChannelsL && currChannel != ( nChannelsC - 1 ) ) /* i <=m && i !=n */ - { - idx = currChannel + 1; - - norm_x = 0.0f; - abs_x = 0.0f; - - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */ - { - norm_x += ( singularVectors[currChannel][jCh] * singularVectors[currChannel][jCh] ); - abs_x += fabs( singularVectors[currChannel][jCh] ); - } - - if ( norm_x ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */ - { - ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x ); - r = ( *g ) * singularVectors[currChannel][idx] - norm_x; - singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) ); - - for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /* nChannelsL */ - { - norm_x = 0.0f; - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ - { - norm_x += ( singularVectors[iCh][jCh] * singularVectors[currChannel][jCh] ); - } - norm_x /= r; - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ - { - singularVectors[iCh][jCh] += ( norm_x * singularVectors[currChannel][jCh] ); - } - } - for ( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */ - { - secDiag[jCh] = ( singularVectors[currChannel][jCh] * abs_x ) / maxWithSign( r ); - } - } - } - - return; -} - #else static void biDiagonalReductionRight( -- GitLab From a2ec6747a7633ab26c2cab1e56fa0b4cd196d51a Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 18 Jul 2025 11:43:05 +0200 Subject: [PATCH 12/13] clang patch applied. --- lib_dec/ivas_svd_dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_dec/ivas_svd_dec.c b/lib_dec/ivas_svd_dec.c index 97ab43b00..0f9c7523b 100644 --- a/lib_dec/ivas_svd_dec.c +++ b/lib_dec/ivas_svd_dec.c @@ -494,7 +494,7 @@ static void HouseholderReduction( #ifdef NONBE_SVD_OPTIMIZATION float g_left = 0.0f; float g_right = 0.0f; -#else +#else float sig_x = 0.0f; float g = 0.0f; #endif -- GitLab From dc35c6913ab6be0de724e03af2364f7a5fa8319c Mon Sep 17 00:00:00 2001 From: Dominik Weckbecker Date: Fri, 15 Aug 2025 11:08:39 +0200 Subject: [PATCH 13/13] fix merge error in options.h --- lib_com/options.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 848cf4bd7..ae63ea2b7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -174,9 +174,6 @@ /* #################### End FIXES switches ############################ */ -/* ################### Start NONBE switches ########################### */ -#define NONBE_SVD_OPTIMIZATION -/* #################### End NONBE switches ############################ */ #define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ /* #################### Start BASOP porting switches ############################ */ -- GitLab