Commit 4b6113cc authored by multrus's avatar multrus
Browse files

make SVD more robust to optimizations

parent 51e2f541
Loading
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -536,14 +536,19 @@ static void biDiagonalReductionLeft(
{
    int16_t iCh, jCh;
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    float norm_x, r;
    volatile float norm_x, r;
    volatile float f;
    volatile float g_loc;
#else
    float norm_x, f, r;
#endif

    /* Setting values to 0 */
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    g_loc = 0.0f;
#else
    ( *g ) = 0.0f;
#endif

    if ( currChannel < nChannelsL ) /* i <= m */
    {
@@ -556,9 +561,15 @@ static void biDiagonalReductionLeft(

        if ( ( norm_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */
        {
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
            g_loc = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x );
            r = g_loc * singularVectors[currChannel][currChannel] - norm_x;
            singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - g_loc );
#else
            ( *g ) = -( singularVectors[currChannel][currChannel] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x );
            r = ( *g ) * singularVectors[currChannel][currChannel] - norm_x;
            singularVectors[currChannel][currChannel] = ( singularVectors[currChannel][currChannel] - ( *g ) );
#endif

            for ( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */
            {
@@ -579,6 +590,10 @@ static void biDiagonalReductionLeft(
        }
    }

#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    *g = g_loc;
#endif

    return;
}

@@ -597,10 +612,17 @@ static void biDiagonalReductionRight(
    float *g )
{
    int16_t iCh, jCh, idx;
    float norm_x, r;
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    volatile float norm_x, r;
    volatile float g_loc;
#endif

    /* Setting values to 0 */
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    g_loc = 0.0f;
#else
    ( *g ) = 0.0f;
#endif

    if ( currChannel < nChannelsL && currChannel != ( nChannelsC - 1 ) ) /* i <=m && i !=n */
    {
@@ -615,9 +637,15 @@ static void biDiagonalReductionRight(

        if ( norm_x ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */
        {
#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
            g_loc = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x );
            r = g_loc * singularVectors[currChannel][idx] - norm_x;
            singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - g_loc );
#else
            ( *g ) = -( singularVectors[currChannel][idx] >= 0 ? 1 : ( -1 ) ) * sqrtf( norm_x );
            r = ( *g ) * singularVectors[currChannel][idx] - norm_x;
            singularVectors[currChannel][idx] = ( singularVectors[currChannel][idx] - ( *g ) );
#endif

            for ( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /*  nChannelsL */
            {
@@ -635,6 +663,10 @@ static void biDiagonalReductionRight(
        }
    }

#ifdef FIX_FLOAT_1560_SVD_NO_OPT_MAX_W_SIGN
    *g = g_loc;
#endif

    return;
}