Commit 1cae4d03 authored by Fabian Bauer's avatar Fabian Bauer
Browse files

lib_com/tools_fx.c

lib_com/weight_a_fx.c
lib_com/wi_fx.c
lib_com/window_fx.c : completed overflow op replacement
parent 742a5b64
Loading
Loading
Loading
Loading
Loading
+167 −14
Original line number Diff line number Diff line
@@ -308,28 +308,36 @@ Word16 usquant_fx( /* o: index of the winning codeword */
    Word16 idx;
    Word16 tmp, exp;
    Word32 L_tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    /*    idx = (short)( (x - qlow)/delta + 0.5f); */
    exp = norm_s( delta );
    tmp = div_s( shl( 1, sub( 14, exp ) ), delta );     /*Q(29-exp-(Qx-1))->Q(30-exp-Qx) */
    L_tmp = L_mult( sub_o( x, qlow, &Overflow ), tmp ); /*Q(31-exp) */
#ifdef ISSUE_1796_replace_shl_o
    idx = extract_l( L_shr_r( L_add( L_tmp, shl_sat( 1, sub( 30, exp ) ) ), sub( 31, exp ) ) ); /*Q0 */
#ifdef ISSUE_1836_replace_overflow_libcom
    L_tmp = L_mult( sub_sat( x, qlow ), tmp ); /*Q(31-exp) */   //??sat
    idx = extract_l( L_shr_r( L_add( L_tmp, shl_sat( 1, sub( 30, exp ) ) ), sub( 31, exp ) ) ); /*Q0 */ //??sat
#else
    L_tmp = L_mult( sub_o( x, qlow, &Overflow ), tmp ); /*Q(31-exp) */
    idx = extract_l( L_shr_r( L_add( L_tmp, shl_o( 1, sub( 30, exp ), &Overflow ) ), sub( 31, exp ) ) ); /*Q0 */
#endif


    idx = s_min( idx, sub( cbsize, 1 ) );
    idx = s_max( idx, 0 );

    /*    *xq = idx*delta + qlow; */
    L_tmp = L_deposit_l( qlow );                                    /*Qx */
    L_tmp = L_mac( L_tmp, idx, delta );                             /*Qx */
#ifdef ISSUE_1836_replace_overflow_libcom
    *xq = round_fx_sat( L_shl_sat( L_tmp, 16 ) );                   /*Qx */
#else
    *xq = round_fx_o( L_shl_o( L_tmp, 16, &Overflow ), &Overflow ); /*Qx */
#endif
    return idx;
}
/*-------------------------------------------------------------------*
@@ -395,14 +403,20 @@ Word32 sum2_fx( /* o : sum of all squared vector elements
{
    Word16 i;
    Word32 L_tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    L_tmp = L_deposit_l( 0 );
    FOR( i = 0; i < lvec; i++ )
    {
#ifdef ISSUE_1836_replace_overflow_libcom
        L_tmp = L_mac_sat( L_tmp, vec[i], vec[i] ); /*Q(2x+1) */
#else
        L_tmp = L_mac_o( L_tmp, vec[i], vec[i], &Overflow ); /*Q(2x+1) */
#endif
    }

    return L_tmp;
@@ -456,15 +470,21 @@ Word32 sum2_fx_mod( /* o : sum of all squared vector element
{
    Word16 i;
    Word32 L_tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    L_tmp = L_deposit_l( 0 );
    FOR( i = 0; i < lvec; i++ )
    {
#ifdef ISSUE_1836_replace_overflow_libcom
        L_tmp = L_add_sat( L_tmp, L_shr( L_mult_sat( vec[i], vec[i] ), 9 ) );
#else
        L_tmp = L_add_o( L_tmp, L_shr( L_mult_o( vec[i], vec[i], &Overflow ), 9 ), &Overflow );
#endif
    }

    return L_tmp;
@@ -684,7 +704,7 @@ void Copy_Scale_sig(
{
    Word16 i;
    Word16 tmp;
#ifndef ISSUE_1796_replace_shl_o
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
@@ -711,8 +731,8 @@ void Copy_Scale_sig(
    }
    FOR( i = 0; i < lg; i++ )
    {
#ifdef ISSUE_1796_replace_shl_o
        y[i] = shl_sat( x[i], exp0 );
#ifdef ISSUE_1836_replace_overflow_libcom
        y[i] = shl_sat( x[i], exp0 );   //??sat
#else
        y[i] = shl_o( x[i], exp0, &Overflow );
#endif
@@ -733,7 +753,7 @@ void Copy_Scale_sig_16_32_DEPREC(
{
    Word16 i;
    Word16 tmp;
#ifndef ISSUE_1796_replace_shl_o
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
@@ -755,8 +775,8 @@ void Copy_Scale_sig_16_32_DEPREC(
        /*Should not happen */
        FOR( i = 0; i < lg; i++ )
        {
#ifdef ISSUE_1796_replace_shl_o
            y[i] = L_deposit_l( shl_sat( x[i], exp0 ) );
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = L_deposit_l( shl_sat( x[i], exp0 ) );  //??sat
#else
            y[i] = L_deposit_l( shl_o( x[i], exp0, &Overflow ) );
#endif
@@ -772,8 +792,8 @@ void Copy_Scale_sig_16_32_DEPREC(
#else
    assert( exp0 < 16 );
#endif
#ifdef ISSUE_1796_replace_shl_o
    tmp = shl_sat( 1, exp0 );
#ifdef ISSUE_1836_replace_overflow_libcom
    tmp = shl_sat( 1, exp0 );   //??sat
#else
    tmp = shl_o( 1, exp0, &Overflow );
#endif
@@ -793,10 +813,12 @@ void Copy_Scale_sig_16_32_no_sat(
{
    Word16 i;
    Word32 L_tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif


    IF( exp0 == 0 )
@@ -813,8 +835,8 @@ void Copy_Scale_sig_16_32_no_sat(
        /*Should not happen */
        FOR( i = 0; i < lg; i++ )
        {
#ifdef ISSUE_1796_replace_shl_o
            y[i] = L_deposit_l( shl_sat( x[i], exp0 ) );
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = L_deposit_l( shl_sat( x[i], exp0 ) );  //??sat
#else
            y[i] = L_deposit_l( shl_o( x[i], exp0, &Overflow ) );
#endif
@@ -822,7 +844,11 @@ void Copy_Scale_sig_16_32_no_sat(
        }
        return;
    }
#ifdef ISSUE_1836_replace_overflow_libcom
    L_tmp = L_shl_sat( 1, exp0 - 1 ); //??sat
#else
    L_tmp = L_shl_o( 1, exp0 - 1, &Overflow );
#endif

    IF( L_tmp >= 0x7FFF )
    {
@@ -854,9 +880,11 @@ void Copy_Scale_sig_32_16(
{
    Word16 i;
    Word16 tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    tmp = add( 16, exp0 );
@@ -864,7 +892,11 @@ void Copy_Scale_sig_32_16(
    {
        FOR( i = 0; i < lg; i++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = round_fx_sat( L_shl_sat( x[i], tmp ) );
#else
            y[i] = round_fx_o( L_shl_o( x[i], tmp, &Overflow ), &Overflow );
#endif
            move16();
        }
    }
@@ -872,7 +904,11 @@ void Copy_Scale_sig_32_16(
    {
        FOR( i = 0; i < lg; i++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = round_fx_sat( x[i] );  //??sat
#else
            y[i] = round_fx_o( x[i], &Overflow );
#endif
            move16();
        }
    }
@@ -890,9 +926,11 @@ void Scale_sig32(
)
{
    Word16 i;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    IF( 0 == exp0 )
    {
@@ -901,7 +939,11 @@ void Scale_sig32(

    FOR( i = 0; i < lg; i++ )
    {
#ifdef ISSUE_1836_replace_overflow_libcom
        x[i] = L_shl_sat( x[i], exp0 );
#else
        x[i] = L_shl_o( x[i], exp0, &Overflow );
#endif
        move32(); /* saturation can occur here */
    }
}
@@ -1896,10 +1938,12 @@ Word16 w_vquant_fx(
    Word16 tmp;
    Word16 c, idx, j;
    Word32 dist, minDist;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif


    idx = 0;
@@ -1916,6 +1960,28 @@ Word16 w_vquant_fx(
        {
            dist = L_deposit_l( 0 );

#ifdef ISSUE_1836_replace_overflow_libcom
            tmp = sub_sat( x[3], shr( cb[j++], Qx ) );  //??sat
            if ( weights[3] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );    //??sat
            }
            tmp = sub_sat( x[2], shr( cb[j++], Qx ) );  //??sat
            if ( weights[2] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );    //??sat
            }
            tmp = sub_sat( x[1], shr( cb[j++], Qx ) );  //??sat
            if ( weights[1] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );    //??sat
            }
            tmp = sub_sat( x[0], shr( cb[j++], Qx ) );  //??sat
            if ( weights[0] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );    //??sat
            }
#else
            tmp = sub_o( x[3], shr( cb[j++], Qx ), &Overflow );
            if ( weights[3] != 0 )
            {
@@ -1936,6 +2002,7 @@ Word16 w_vquant_fx(
            {
                dist = L_mac0_o( dist, tmp, tmp, &Overflow );
            }
#endif
            if ( LT_32( dist, minDist ) )
            {
                idx = c;
@@ -1965,6 +2032,28 @@ Word16 w_vquant_fx(
        {
            dist = L_deposit_l( 0 );

#ifdef ISSUE_1836_replace_overflow_libcom
            tmp = sub_sat( x[0], shr( cb[j++], Qx ) );    //??sat
            if ( weights[0] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );      //??sat
            }
            tmp = sub_sat( x[1], shr( cb[j++], Qx ) );    //??sat
            if ( weights[1] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );      //??sat
            }
            tmp = sub_sat( x[2], shr( cb[j++], Qx ) );    //??sat
            if ( weights[2] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );      //??sat
            }
            tmp = sub_sat( x[3], shr( cb[j++], Qx ) );    //??sat
            if ( weights[3] != 0 )
            {
                dist = L_mac0_sat( dist, tmp, tmp );      //??sat
            }
#else
            tmp = sub_o( x[0], shr( cb[j++], Qx ), &Overflow );
            if ( weights[0] != 0 )
            {
@@ -1985,6 +2074,7 @@ Word16 w_vquant_fx(
            {
                dist = L_mac0_o( dist, tmp, tmp, &Overflow );
            }
#endif
            if ( LT_32( dist, minDist ) )
            {
                idx = c;
@@ -2451,9 +2541,11 @@ Word32 root_a_over_b_fx(
    Word16 tmp, num, den, scale;
    Word16 exp, exp_num, exp_den;
    Word32 L_tmp;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    test();
    IF( ( a <= 0 ) || ( b <= 0 ) )
@@ -2464,15 +2556,23 @@ Word32 root_a_over_b_fx(
    }

    exp_num = norm_l( b );
#ifdef ISSUE_1836_replace_overflow_libcom
    num = round_fx_sat( L_shl_sat( b, exp_num ) );  //??sat
#else
    num = round_fx_o( L_shl_o( b, exp_num, &Overflow ), &Overflow );
#endif
    exp_num = sub( sub( 30, exp_num ), Q_b );

    exp_den = norm_l( a );
#ifdef ISSUE_1836_replace_overflow_libcom
    den = round_fx_sat( L_shl_sat( a, exp_den ) );  //??sat
#else
    den = round_fx_o( L_shl_o( a, exp_den, &Overflow ), &Overflow );
#endif
    exp_den = sub( sub( 30, exp_den ), Q_a );

    scale = shr( sub( den, num ), 15 );
#ifdef ISSUE_1796_replace_shl_o
#ifdef ISSUE_1836_replace_overflow_libcom     //??sat
    num = shl_sat( num, scale );
#else
    num = shl_o( num, scale, &Overflow );
@@ -2632,9 +2732,11 @@ void fir_fx( const Word16 x[], /* i : input vector
    Word16 buf_in[L_FRAME32k + L_FILT_MAX];
    Word16 i, j;
    Word32 s;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    /* prepare the input buffer (copy and update memory) */
    Copy( mem, buf_in, K );
@@ -2647,14 +2749,27 @@ void fir_fx( const Word16 x[], /* i : input vector
    /* do the filtering */
    FOR( i = 0; i < L; i++ )
    {
#ifdef ISSUE_1836_replace_overflow_libcom
        s = L_mult_sat( buf_in[K + i], h[0] );   //??sat
#else
        s = L_mult_o( buf_in[K + i], h[0], &Overflow );
#endif

        FOR( j = 1; j <= K; j++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            s = L_mac_sat( s, h[j], buf_in[K + i - j] );  //??sat
#else
            s = L_mac_o( s, h[j], buf_in[K + i - j], &Overflow );
#endif
        }
#ifdef ISSUE_1836_replace_overflow_libcom
        s = L_shl_sat( s, shift );          //??sat
        y[i] = round_fx_sat( s ); /*Qx */   //??sat
#else
        s = L_shl_o( s, shift, &Overflow );
        y[i] = round_fx_o( s, &Overflow ); /*Qx */
#endif
        move16();
    }
}
@@ -2790,8 +2905,10 @@ Word16 squant_fx( /* o: index of the winning codeword */
    Word16 tmp;
    Word16 c, idx;
    Word32 L_mindist, L_dist;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
#endif
#endif

    idx = 0;
@@ -2802,10 +2919,18 @@ Word16 squant_fx( /* o: index of the winning codeword */
    FOR( c = 0; c < cbsize; c++ )
    {
        L_dist = L_deposit_l( 0 );
#ifdef ISSUE_1836_replace_overflow_libcom
        tmp = sub_sat( x, cb[c] );
#else
        tmp = sub_o( x, cb[c], &Overflow );
#endif

        /*dist += tmp*tmp; */
#ifdef ISSUE_1836_replace_overflow_libcom
        L_dist = L_mac_sat( L_dist, tmp, tmp );   //??sat
#else
        L_dist = L_mac_o( L_dist, tmp, tmp, &Overflow );
#endif

        if ( LT_32( L_dist, L_mindist ) )
        {
@@ -2943,9 +3068,11 @@ void Copy_Scale_sig32(
    Word16 i;
    Word32 L_tmp;
    Word16 tmp = exp0;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    IF( exp0 == 0 )
    {
@@ -2960,12 +3087,20 @@ void Copy_Scale_sig32(
    {
        FOR( i = 0; i < lg; i++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = L_shl_sat( x[i], tmp );  //??sat
#else
            y[i] = L_shl_o( x[i], tmp, &Overflow );
#endif
            move16();
        }
        return;
    }
#ifdef ISSUE_1836_replace_overflow_libcom
    L_tmp = L_shl_sat( 1, exp0 - 1 );   //??sat
#else
    L_tmp = L_shl_o( 1, exp0 - 1, &Overflow );
#endif
    FOR( i = 0; i < lg; i++ )
    {
        y[i] = W_extract_l( W_mult_32_32( L_tmp, x[i] ) );
@@ -3142,9 +3277,11 @@ void add_vec_fx(
)
{
    Word16 i, Qyx1, Qyx2;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif
    Qyx1 = sub( Qx1, Qy );
    Qyx2 = sub( Qx2, Qy );
@@ -3152,7 +3289,11 @@ void add_vec_fx(
    {
        FOR( i = 0; i < N; i++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = add_sat( x1[i], shr_r_sat( x2[i], Qyx2 ) );  //??sat //??sat
#else
            y[i] = add_o( x1[i], shr_r_sat( x2[i], Qyx2 ), &Overflow );
#endif
            move16();
        }
    }
@@ -3160,7 +3301,11 @@ void add_vec_fx(
    {
        FOR( i = 0; i < N; i++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            y[i] = add_sat( shr_r_sat( x1[i], Qyx1 ), shr_r_sat( x2[i], Qyx2 ) );   //??sat //!!sat //!!sat
#else
            y[i] = add_o( shr_r_sat( x1[i], Qyx1 ), shr_r_sat( x2[i], Qyx2 ), &Overflow );
#endif
            move16();
        }
    }
@@ -3287,7 +3432,11 @@ Word32 Calc_Energy_Autoscaled( /* o: Result (Energy)
    FOR( i = 0; i < j; i++ )
    {
        /* divide by 2 so energy will be divided by 4 */
#ifdef ISSUE_1836_replace_overflow_libcom
        temp = mult_r( *signal++, 16384 );
#else
        temp = mult_ro( *signal++, 16384, &Overflow );
#endif
        L_Energy = L_mac0_o( L_Energy, temp, temp, &Overflow );
    }
    FOR( i = j; i < len; i += 8 ) /* Process 8 Samples at a time */
@@ -3297,7 +3446,11 @@ Word32 Calc_Energy_Autoscaled( /* o: Result (Energy)
        L_temp = L_mult0( temp, temp );
        FOR( j = 1; j < 8; j++ )
        {
#ifdef ISSUE_1836_replace_overflow_libcom
            temp = mult_r( *signal++, 16384 );
#else
            temp = mult_ro( *signal++, 16384, &Overflow );
#endif
            L_temp = L_mac0_o( L_temp, temp, temp, &Overflow );
        }
#ifdef ISSUE_1799_replace_L_shr_o
+6 −0
Original line number Diff line number Diff line
@@ -100,10 +100,12 @@ void weight_a_fx(
    Word16 i, fac;
    Word32 Amax;
    Word16 shift;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow;
    Overflow = 0;
    move32();
#endif
#endif

    fac = gamma; /* Q15 */
@@ -122,7 +124,11 @@ void weight_a_fx(
    move16();
    FOR( i = 1; i < m; i++ )
    {
#ifdef ISSUE_1836_replace_overflow_libcom
        ap[i] = round_fx_sat( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q11 + shift */   //??sat
#else
        ap[i] = round_fx_o( L_shl( L_mult0( a[i], fac ), shift ), &Overflow ); /* Q11 + shift */
#endif
        move16();
        fac = mult_r( fac, gamma ); /* Q15 */
    }
+361 −23

File changed.

Preview size limit exceeded, changes collapsed.

+8 −2
Original line number Diff line number Diff line
@@ -29,10 +29,12 @@ void ham_cos_window(
{
    Word16 i;
    Word32 cte, cc;
#ifndef ISSUE_1836_replace_overflow_libcom
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move16();
#endif
#endif


    assert( n1 >= 102 ); /* if n1 is too low -> overflow in div_l */
@@ -46,7 +48,11 @@ void ham_cos_window(
    {
        /* fh_f[i] = 0.54f - 0.46f * (Float32)cos(cc);	*/
        BASOP_SATURATE_WARNING_OFF_EVS
#ifdef ISSUE_1836_replace_overflow_libcom
        fh[i] = sub_sat( P54_0Q15, mult_r( getCosWord16( round_fx_sat( L_shl_sat( cc, 9 ) ) ), P92_0Q15 ) ); /*0Q15*/   //??sat //??sat //??sat
#else
        fh[i] = sub_o( P54_0Q15, mult_r( getCosWord16( round_fx_o( L_shl_o( cc, 9, &Overflow ), &Overflow ) ), P92_0Q15 ), &Overflow ); /*0Q15*/
#endif
        move16();
        BASOP_SATURATE_WARNING_ON_EVS
        cc = L_add( cc, cte ); /*0Q15*/
@@ -63,8 +69,8 @@ void ham_cos_window(
    FOR( i = n1; i < n1 + n2; i++ )
    {
        /* fh_f[i] = (Float32)cos(cc);		*/
#ifdef ISSUE_1796_replace_shl_o
        fh[i] = shl_sat( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1 ); /*0Q15*/
#ifdef ISSUE_1836_replace_overflow_libcom
        fh[i] = shl_sat( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1 ); /*0Q15*/     //??sat
#else
        fh[i] = shl_o( getCosWord16( round_fx( L_shl( cc, 10 ) ) ), 1, &Overflow ); /*0Q15*/
#endif