Commit bd4bcf9f authored by multrus's avatar multrus
Browse files

[cleanup] accept NONBE_SVD_OPTIMIZATION

parent 974539c9
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -75,7 +75,6 @@

#define ISSUE_1836_replace_overflow_libcom                   /* FhG: replace overflow operators by non-overflow-alternatives in lib_com - BE */

#define	NONBE_SVD_OPTIMIZATION                               /* FhG: reduce WMOPS of HouseHolderReduction() in ivas_svd_dec.c() by removing redundant mathematics and using 64 bit additions */
#define FIX_1766_TCX2ACELP_BWE_ISSUE                         /* VA : Fix rare BWE issue when switching from TCX to ACELP */
#define FIX_1781_SPECTRAL_GAPS                               /* FhG: Change internal calculation of tcx_noise_factor_ivas_fx() to 32-bit*/
#define FIX_ISSUE_1811_EXCEEDING_W_SHIFTS                    /* FhG: limit exceeding 64bit shifts */
+0 −5
Original line number Diff line number Diff line
@@ -1799,7 +1799,6 @@ void ivas_param_mc_dec_digest_tc_fx(
        test();
        IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) )
        {
#ifdef NONBE_SVD_OPTIMIZATION
            Word16 len = imult1616( nchan_transport, nchan_transport );
            Word16 sc = s_min( getScaleFactor32( cx_fx, len ), getScaleFactor32( cx_next_band_fx, len ) );
            IF( EQ_16( sc, 0 ) )
@@ -1811,10 +1810,6 @@ void ivas_param_mc_dec_digest_tc_fx(
            }
            v_add_fx( cx_fx, cx_next_band_fx, cx_fx, len );
            Copy32( cx_fx, cx_next_band_fx, len );
#else
            v_add_fx( cx_fx, cx_next_band_fx, cx_fx, imult1616( nchan_transport, nchan_transport ) );
            Copy32( cx_fx, cx_next_band_fx, imult1616( nchan_transport, nchan_transport ) );
#endif
        }

        FOR( is_next_band = 0; is_next_band < 2; is_next_band++ )
+0 −355
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ static void HouseholderReduction_fx(
    const Word16 nChannelsC, /* Q0 */
    Word32 *eps_x_fx,        /* exp(eps_x_fx_e) */
    Word16 *eps_x_fx_e );
#ifdef NONBE_SVD_OPTIMIZATION

static void biDiagonalReductionLeft_fx(
    Word32 singularVectors[][MAX_OUTPUT_CHANNELS],  /* exp(singularVectors_e) */
@@ -83,35 +82,6 @@ static void biDiagonalReductionRight_fx(
    const Word16 currChannel, /* Q0 */
    Word32 *g,
    Word16 *g_e );
#else
static void biDiagonalReductionLeft_fx(
    Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */
    Word32 singularValues[MAX_OUTPUT_CHANNELS],    /* exp(singularValues_e) */
    Word32 secDiag[MAX_OUTPUT_CHANNELS],           /* exp(secDiag_e) */
    Word16 singularVectors2_e[][MAX_OUTPUT_CHANNELS],
    Word16 singularValues_e[MAX_OUTPUT_CHANNELS],
    Word16 *secDiag_e,
    const Word16 nChannelsL,  /* Q0 */
    const Word16 nChannelsC,  /* Q0 */
    const Word16 currChannel, /* Q0 */
    Word32 *sig_x,            /* exp(sig_x_e) */
    Word16 *sig_x_e,
    Word32 *g /* Q31 */
);

static void biDiagonalReductionRight_fx(
    Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */
    Word32 secDiag[MAX_OUTPUT_CHANNELS],           /* exp(secDiag_e) */
    Word16 singularVectors2_e[][MAX_OUTPUT_CHANNELS],
    Word16 *secDiag_e,
    const Word16 nChannelsL,  /* Q0 */
    const Word16 nChannelsC,  /* Q0 */
    const Word16 currChannel, /* Q0 */
    Word32 *sig_x,            /* exp(sig_x_e) */
    Word16 *sig_x_e,
    Word32 *g /* Q31 */
);            // Q31
#endif

static void singularVectorsAccumulationLeft_fx(
    Word32 singularVectors_Left[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) as Input, Q31 as output */
@@ -841,7 +811,6 @@ static void HouseholderReduction_fx(
    Word16 *eps_x_fx_e )
{
    Word16 nCh;
#ifdef NONBE_SVD_OPTIMIZATION

    Word32 g_left_fx = 0;
    Word16 g_left_e = 0;
@@ -852,20 +821,10 @@ static void HouseholderReduction_fx(
    move32();
    move16();

#else

    // float g = 0.0f, sig_x = 0.0f;// to be removed
    Word32 g_fx = 0, sig_x_fx = 0;
    move32();
    move32();
    Word16 sig_x_fx_e = 0;
    move16();
#endif

    Word16 iCh, jCh;
    Word16 singularVectors_Left_fx_e[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS];

#ifdef NONBE_SVD_OPTIMIZATION
    Word16 sc = 0;
    move16();
    sc = getScaleFactor32( singularVectors_Left_fx[0], nChannelsC );
@@ -922,34 +881,6 @@ static void HouseholderReduction_fx(
        }
    }

#else

    FOR( jCh = 0; jCh < nChannelsL; jCh++ )
    {
        FOR( iCh = 0; iCh < nChannelsC; iCh++ )
        {
            singularVectors_Left_fx_e[jCh][iCh] = singularVectors_Left_e;
            move16();
        }
    }

    /* Bidiagonal Reduction for every channel */
    FOR( nCh = 0; nCh < nChannelsC; nCh++ ) /* nChannelsC */
    {
        biDiagonalReductionLeft_fx( singularVectors_Left_fx, singularValues_fx, secDiag_fx, singularVectors_Left_fx_e, singularValues_fx_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx );
        biDiagonalReductionRight_fx( singularVectors_Left_fx, secDiag_fx, singularVectors_Left_fx_e, secDiag_fx_e, nChannelsL, nChannelsC, nCh, &sig_x_fx, &sig_x_fx_e, &g_fx );

        Word16 L_temp_e;
        Word32 L_temp = BASOP_Util_Add_Mant32Exp( L_abs( singularValues_fx[nCh] ), singularValues_fx_e[nCh], L_abs( secDiag_fx[nCh] ), secDiag_fx_e[nCh], &L_temp_e ); /* exp(L_temp_e) */
        IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( L_temp, L_temp_e, *eps_x_fx, *eps_x_fx_e ), 1 ) )
        {
            *eps_x_fx = L_temp; /* exp(L_temp_e) */
            move32();
            *eps_x_fx_e = L_temp_e;
            move32();
        }
    }
#endif

    /* SingularVecotr Accumulation */
    singularVectorsAccumulationRight_fx( singularVectors_Left_fx, singularVectors_Right_fx, secDiag_fx, singularVectors_Left_fx_e, secDiag_fx_e, nChannelsC );
@@ -960,7 +891,6 @@ static void HouseholderReduction_fx(
    return;
}

#ifdef NONBE_SVD_OPTIMIZATION
/*-------------------------------------------------------------------------
 * biDiagonalReductionLeft()
 *
@@ -1157,291 +1087,6 @@ static void biDiagonalReductionRight_fx(

    return;
}
#else
/*-------------------------------------------------------------------------
 * biDiagonalReductionLeft()
 *
 *
 *-------------------------------------------------------------------------*/

static void biDiagonalReductionLeft_fx(
    Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */
    Word32 singularValues[MAX_OUTPUT_CHANNELS],    /* exp(singularValues_e) */
    Word32 secDiag[MAX_OUTPUT_CHANNELS],           /* exp(secDiag_e) */
    Word16 singularVectors2_e[][MAX_OUTPUT_CHANNELS],
    Word16 singularValues_e[MAX_OUTPUT_CHANNELS],
    Word16 *secDiag_e,
    const Word16 nChannelsL,  /* Q0 */
    const Word16 nChannelsC,  /* Q0 */
    const Word16 currChannel, /* Q0 */
    Word32 *sig_x,            /* exp(sig_x_e) */
    Word16 *sig_x_e,
    Word32 *g /* Q31 */
)
{
    Word16 iCh, jCh, idx;
    Word32 norm_x, f, r;
    Word16 norm_x_e, f_e, r_e;
    Word32 L_temp;
    Word16 L_temp_e;

    secDiag[currChannel] = Mpy_32_32( *sig_x, *g ); /* exp(sig_x_e) */
    move32();
    secDiag_e[currChannel] = *sig_x_e;
    move16();

    /* Setting values to 0 */
    ( *sig_x ) = 0;
    move32();
    ( *g ) = 0;
    move32();

    IF( LT_16( currChannel, nChannelsL ) ) /* i <= m */
    {
        idx = currChannel;
        move16();

        FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
        {
            ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[jCh][currChannel] ), singularVectors2_e[jCh][currChannel], sig_x_e ); /* exp(sig_x_e) */
        }

        IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */
        {
            Word16 invVal_e;
            Word32 invVal;
            invVal = BASOP_Util_Divide3232_Scale_newton( MAXVAL_WORD32, maxWithSign_fx( *sig_x ), &invVal_e );
            Word64 temp = 0;
            move64();
            Word16 max_e = MIN_16;
            move16();
            FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
            {
                Word16 temp_e = norm_l( singularVectors[jCh][currChannel] );
                singularVectors[jCh][currChannel] = Mpy_32_32( L_shl( singularVectors[jCh][currChannel], temp_e ), invVal ); /* exp(sing_exp + (singularVectors_e - sig_x_e) */
                move32();
                singularVectors2_e[jCh][currChannel] = sub( add( invVal_e, sub( singularVectors2_e[jCh][currChannel], *sig_x_e ) ), temp_e );
                move16();
                max_e = s_max( max_e, singularVectors2_e[jCh][currChannel] );
            }

            FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
            {
                temp = W_add( temp, L_shr( Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][currChannel] ), shl( sub( max_e, singularVectors2_e[jCh][currChannel] ), 1 ) ) );
            }

            Word16 nrm = W_norm( temp );
            nrm = sub( nrm, 32 );
            norm_x = W_shl_sat_l( temp, nrm );
            norm_x_e = sub( add( max_e, max_e ), nrm );

            IF( GT_16( norm_x_e, 0 ) )
            {
                norm_x = MAX_32;
                move32();
                norm_x_e = 0;
                move16();
            }
            L_temp_e = norm_x_e;
            move16();
            L_temp = Sqrt32( norm_x, &L_temp_e );
            L_temp = L_shl_r( L_temp, L_temp_e ); // Q31
                                                  //( *g ) = L_negate( GE_32( singularVectors[currChannel][idx], 0 ) ? L_temp : L_negate( L_temp ) );
            if ( singularVectors[currChannel][idx] >= 0 )
            {
                L_temp = L_negate( L_temp );
            }
            ( *g ) = L_temp;
            move32();

            r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), singularVectors2_e[currChannel][idx], -norm_x, norm_x_e, &r_e );                                      /* exp(r_e) */
            singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], singularVectors2_e[currChannel][idx], -( *g ), 0, &singularVectors2_e[currChannel][idx] ); /* sing_exp */
            move32();

            invVal = BASOP_Util_Divide3232_Scale_newton( MAXVAL_WORD32, maxWithSign_fx( r ), &invVal_e );

            FOR( iCh = currChannel + 1; iCh < nChannelsC; iCh++ ) /* nChannelsC */
            {
                Word16 max2_e = MIN_16;
                max_e = MIN_16;
                move16();
                move16();
                temp = 0;
                move64();

                FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
                {
                    max_e = s_max( max_e, singularVectors2_e[jCh][currChannel] ); /* exp(norm_x_e) */
                    max2_e = s_max( max2_e, singularVectors2_e[jCh][iCh] );       /* exp(norm_x_e) */
                }
                max_e = add( max_e, max2_e );

                FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
                {
                    temp = W_add( temp, L_shr( Mpy_32_32( singularVectors[jCh][currChannel], singularVectors[jCh][iCh] ), sub( max_e, add( singularVectors2_e[jCh][currChannel], singularVectors2_e[jCh][iCh] ) ) ) );
                }
                nrm = W_norm( temp );
                nrm = sub( nrm, 32 );
                norm_x = W_shl_sat_l( temp, nrm );
                norm_x_e = sub( max_e, nrm );

                f = Mpy_32_32( norm_x, invVal ); /* invVal_e + (norm_x_e - r_e) */
                f_e = add( invVal_e, sub( norm_x_e, r_e ) );

                FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
                {
                    singularVectors[jCh][iCh] = BASOP_Util_Add_Mant32Exp( singularVectors[jCh][iCh], singularVectors2_e[jCh][iCh], Mpy_32_32( f, singularVectors[jCh][currChannel] ), add( f_e, singularVectors2_e[jCh][currChannel] ), &singularVectors2_e[jCh][iCh] );
                    move32();
                }
            }


            FOR( jCh = idx; jCh < nChannelsL; jCh++ ) /* nChannelsL */
            {
                singularVectors[jCh][currChannel] = Mpy_32_32( singularVectors[jCh][currChannel], ( *sig_x ) ); /* sing_exp + sig_x_e */
                move32();
                singularVectors2_e[jCh][currChannel] = add( singularVectors2_e[jCh][currChannel], *sig_x_e );
                move16();
            }
        }

        // rescaling block
        singularValues[currChannel] = Mpy_32_32( ( *sig_x ), ( *g ) ); /* sig_x_e */
        move32();
        singularValues_e[currChannel] = *sig_x_e;
        move16();
    }

    return;
}

/*-------------------------------------------------------------------------
 * biDiagonalReductionRight()
 *
 *
 *-------------------------------------------------------------------------*/

static void biDiagonalReductionRight_fx(
    Word32 singularVectors[][MAX_OUTPUT_CHANNELS], /* exp(singularVectors_e) */
    Word32 secDiag[MAX_OUTPUT_CHANNELS],           /* exp(secDiag_exp[]) */
    Word16 singularVectors2_e[][MAX_OUTPUT_CHANNELS],
    Word16 *secDiag_exp,
    const Word16 nChannelsL,  /* Q0 */
    const Word16 nChannelsC,  /* Q0 */
    const Word16 currChannel, /* Q0 */
    Word32 *sig_x,            /* exp(sig_x_e) */
    Word16 *sig_x_e,
    Word32 *g /* Q31 */
)
{
    Word16 iCh, jCh, idx;
    Word32 norm_x, r;
    Word16 norm_x_e, r_e;
    Word32 L_temp;
    Word16 L_temp_e;

    /* Setting values to 0 */
    ( *sig_x ) = 0;
    move32();
    ( *g ) = 0;
    move32();

    IF( LT_16( currChannel, nChannelsL ) && NE_16( currChannel, sub( nChannelsC, 1 ) ) ) /* i <=m && i !=n */
    {
        idx = add( currChannel, 1 ); /* Q0 */

        FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */
        {
            ( *sig_x ) = BASOP_Util_Add_Mant32Exp( *sig_x, *sig_x_e, L_abs( singularVectors[currChannel][jCh] ), singularVectors2_e[currChannel][jCh], sig_x_e ); /* exp(sig_x_e) */
        }

        IF( ( *sig_x ) ) /*(fabsf(*sig_x) > EPSILON * fabsf(*sig_x)) { */
        {
            norm_x = 0;
            move32();
            norm_x_e = 0;
            move16();

            Word16 invVal_e, temp_e;
            Word32 invVal;
            invVal = BASOP_Util_Divide3232_Scale_newton( MAXVAL_WORD32, maxWithSign_fx( *sig_x ), &invVal_e );
            FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*nChannelsC */
            {
                temp_e = norm_l( singularVectors[currChannel][jCh] );
                singularVectors[currChannel][jCh] = Mpy_32_32( L_shl( singularVectors[currChannel][jCh], temp_e ), invVal ); /* exp(sing_exp + (singularVectors_e - sig_x_e) */
                move32();
                singularVectors2_e[currChannel][jCh] = add( sub( invVal_e, temp_e ), sub( singularVectors2_e[currChannel][jCh], *sig_x_e ) );
                move16();
                norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[currChannel][jCh], singularVectors[currChannel][jCh] ), shl( singularVectors2_e[currChannel][jCh], 1 ), &norm_x_e ); /* exp(norm_x_e) */
            }
            IF( GT_16( norm_x_e, 0 ) )
            {
                norm_x = MAX_32;
                move32();
                norm_x_e = 0;
                move16();
            }
            L_temp_e = norm_x_e;
            move16();
            L_temp = Sqrt32( norm_x, &L_temp_e );
            L_temp = L_shl_r( L_temp, L_temp_e ); // Q31
            IF( singularVectors[currChannel][idx] >= 0 )
            {
                ( *g ) = L_negate( L_temp ); /* exp(L_temp_e) */
                move32();
            }
            ELSE
            {
                ( *g ) = L_negate( L_negate( L_temp ) ); /* exp(L_temp_e) */
                move32();
            }

            r = BASOP_Util_Add_Mant32Exp( Mpy_32_32( ( *g ), singularVectors[currChannel][idx] ), singularVectors2_e[currChannel][idx], -norm_x, norm_x_e, &r_e );                                      /* exp(r_e) */
            singularVectors[currChannel][idx] = BASOP_Util_Add_Mant32Exp( singularVectors[currChannel][idx], singularVectors2_e[currChannel][idx], -( *g ), 0, &singularVectors2_e[currChannel][idx] ); /* exp(sing_exp) */
            move32();

            invVal = BASOP_Util_Divide3232_Scale_newton( MAXVAL_WORD32, maxWithSign_fx( r ), &invVal_e );

            FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */
            {
                temp_e = norm_l( singularVectors[currChannel][jCh] );
                secDiag[jCh] = Mpy_32_32( L_shl( singularVectors[currChannel][jCh], temp_e ), invVal ); /* exp(sing_exp + (singularVectors_e - sig_x_e) */
                move32();
                secDiag_exp[jCh] = add( sub( invVal_e, temp_e ), sub( singularVectors2_e[currChannel][jCh], r_e ) );
                move16();
            }

            FOR( iCh = currChannel + 1; iCh < nChannelsL; iCh++ ) /*  nChannelsL */
            {
                norm_x = 0;
                move32();
                norm_x_e = 0;
                move16();
                FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /* nChannelsC */
                {
                    norm_x = BASOP_Util_Add_Mant32Exp( norm_x, norm_x_e, Mpy_32_32( singularVectors[iCh][jCh], singularVectors[currChannel][jCh] ), add( singularVectors2_e[iCh][jCh], singularVectors2_e[currChannel][jCh] ), &norm_x_e ); /* exp(norm_x_e) */
                }

                FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*  nChannelsC */
                {
                    singularVectors[iCh][jCh] = BASOP_Util_Add_Mant32Exp( singularVectors[iCh][jCh], singularVectors2_e[iCh][jCh], Mpy_32_32( norm_x, secDiag[jCh] ), add( norm_x_e, secDiag_exp[jCh] ), &singularVectors2_e[iCh][jCh] ); /* exp(sing_exp2) */
                    move32();
                }
            }

            FOR( jCh = idx; jCh < nChannelsC; jCh++ ) /*  nChannelsC */
            {
                singularVectors[currChannel][jCh] = Mpy_32_32( singularVectors[currChannel][jCh], ( *sig_x ) ); /* exp(sing_exp + sig_x_e) */
                move32();
                singularVectors2_e[currChannel][jCh] = add( singularVectors2_e[currChannel][jCh], *sig_x_e );
                move16();
            }
        }
    }

    return;
}
#endif

/*-------------------------------------------------------------------------
 * singularVectorsAccumulationLeft()