Commit 0bddff96 authored by multrus's avatar multrus
Browse files

Merge branch '1796-replace-shl_o-by-overflow-free-alternatives' into 'main'

Resolve "Replace shl_o by overflow free alternatives"

Closes #1796

See merge request !1856
parents 648cf28d 24d34621
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -271,7 +271,11 @@ void tcx_arith_scale_envelope(

    tmp2 = BASOP_Util_Add_MantExp( negate( b ), b_e, tmp, tmp2, &scale ); /* exp(scale) */
    scale = BASOP_Util_Divide1616_Scale( scale, round_fx( a ), &tmp );
#ifdef ISSUE_1796_replace_shl_o
    scale = shl_sat( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ) ); /* Q15 */
#else
    scale = shl_o( scale, sub( sub( add( tmp, tmp2 ), a_e ), 1 ), &Overflow ); /* Q15 */
#endif

    /* iscale = 1.0f / scale; */
    iscale_e = 0;
+7 −1
Original line number Diff line number Diff line
@@ -245,9 +245,11 @@ Word16 BitAllocF_fx(
    Word16 tmp, exp1, exp2;
    Word32 Rsubband_w32_fx[NB_SFM]; /* Q15  */
    Word16 B_w16_fx;
#ifndef ISSUE_1796_replace_shl_o
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    set32_fx( Rsubband_w32_fx, 0, NB_SFM );
@@ -442,7 +444,11 @@ Word16 BitAllocF_fx(
            exp1 = sub( norm_l( L_tmp2 ), 1 );
            exp2 = norm_s( n );
            tmp = div_s( extract_h( L_shl( L_tmp2, exp1 ) ), shl( n, exp2 ) ); /*15 + 15 + exp1 - 16 - exp2*/
#ifdef ISSUE_1796_replace_shl_o
            m_fx = shl_sat( tmp, sub( exp2, exp1 ) ); /*Q14*/
#else
            m_fx = shl_o( tmp, sub( exp2, exp1 ), &Overflow ); /*Q14*/
#endif
            if ( L_tmp1 < 0 )
            {
                m_fx = negate( m_fx );
+16 −0
Original line number Diff line number Diff line
@@ -61,9 +61,11 @@ void tcxFormantEnhancement(
    Word16 i, j, k, l, n;
    Word16 fac, fac0, fac1, fac_e, d, tmp;
    Word16 xn_buf_e, xn_one, m, e;
#ifndef ISSUE_1796_replace_shl_o
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */
@@ -139,7 +141,11 @@ void tcxFormantEnhancement(
            {
                fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) );
                BASOP_SATURATE_WARNING_OFF_EVS;
#ifdef ISSUE_1796_replace_shl_o
                xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) );
#else
                xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) );
#endif
                move16();
                BASOP_SATURATE_WARNING_ON_EVS;
            }
@@ -227,9 +233,11 @@ void tcxFormantEnhancement_with_shift(
    Word16 i, j, k, l, n;
    Word16 fac, fac0, fac1, fac_e, d, tmp;
    Word16 xn_buf_e, xn_one, m, e;
#ifndef ISSUE_1796_replace_shl_o
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif

    k = shr( L_frame, 6 ); /* FDNS_NPTS = 64 */
@@ -309,7 +317,11 @@ void tcxFormantEnhancement_with_shift(
            {
                fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) );
                BASOP_SATURATE_WARNING_OFF_EVS;
#ifdef ISSUE_1796_replace_shl_o
                xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) );
#else
                xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) );
#endif
                move16();
                BASOP_SATURATE_WARNING_ON_EVS;
            }
@@ -354,7 +366,11 @@ void tcxFormantEnhancement_with_shift(
    {
        fac = add( fac0, mult( d, extract_l( L_mult0( j, inv_int[n] ) ) ) );
        BASOP_SATURATE_WARNING_OFF_EVS;
#ifdef ISSUE_1796_replace_shl_o
        xn_buf[l + j] = s_min( xn_one, shl_sat( mult( xn_buf[l + j], fac ), fac_e ) );
#else
        xn_buf[l + j] = s_min( xn_one, shl_o( mult( xn_buf[l + j], fac ), fac_e, &Overflow ) );
#endif
        move16();
        BASOP_SATURATE_WARNING_ON_EVS;
    }
+6 −0
Original line number Diff line number Diff line
@@ -2279,10 +2279,12 @@ static void getmidbands(
)
{
    Word16 j, max_psize, shift;
#ifndef ISSUE_1796_replace_shl_o
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
    move32();
#endif
#endif


    max_psize = psize[0];
@@ -2316,7 +2318,11 @@ static void getmidbands(
    move16();
    FOR( j = 0; j < npart; j++ )
    {
#ifdef ISSUE_1796_replace_shl_o
        psize_norm[j] = shl_sat( psize[j], shift ); // Q(15 - psize_norm_exp)
#else
        psize_norm[j] = shl_o( psize[j], shift, &Overflow ); // Q(15 - psize_norm_exp)
#endif
        move16();
    }
    /* minimum_statistics needs fixed exponent of 6 */
+16 −8
Original line number Diff line number Diff line
@@ -126,7 +126,11 @@ void Comp_and_apply_gain_fx(
            y_gain = extract_l( Pow2( 14, frac ) );                      /* Put 14 as exponent so that */
                                                                         /* output of Pow2() will be: */
                                                                         /* 16384 < Pow2() <= 32767 */
#ifdef ISSUE_1796_replace_shl_o
            Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) );
#else
            Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow );
#endif
            move16(); /*Q1     */
            tmp_exp = add( add( exp1, 1 ), sub( Q_exc, Qexc_diff ) );

@@ -208,7 +212,11 @@ void Comp_and_apply_gain_ivas_fx(
            y_gain = extract_l( Pow2( 14, frac ) );                          /* Put 14 as exponent so that */
                                                                             /* output of Pow2() will be: */
                                                                             /* 16384 < Pow2() <= 32767 */
#ifdef ISSUE_1796_replace_shl_o
            Ener_per_bd_yQ[i_band] = shl_sat( y_gain, sub( exp1, 13 ) ); /*Q13*/
#else
            Ener_per_bd_yQ[i_band] = shl_o( y_gain, sub( exp1, 13 ), &Overflow ); /*Q13*/
#endif
            move16(); /*Q1     */
            tmp_exp = add( add( exp1, 1 ), sub( *Q_exc, Qexc_diff ) );

Loading