Commit bdebaafc authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Handle overflow in shr() scaling more simply

parent 1037c582
Loading
Loading
Loading
Loading
Loading
+5 −32
Original line number Diff line number Diff line
@@ -316,8 +316,12 @@ void hp20_fx_32_opt(
    prescale = s_min( prescale, diff );

    prescale = sub( 1 + HP20_FX_COEFF_SCALE, prescale );

#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC
    if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) || // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead
         LT_16( prescale_current_frame, prescale ) )                      // To avoid overflow in the subsequent shr() scaling for W_y1, W_y2, x2, and x1 calculations before the for loop.
#else
    if ( EQ_16( prescale_current_frame, 1 + HP20_FX_COEFF_SCALE - 31 ) ) // signal_fx buffer contains only zeros, so use the mem_fx scale_factor instead
#endif
    {
        prescale_current_frame = prescale;
    }
@@ -331,10 +335,8 @@ void hp20_fx_32_opt(
    move32();
    move32();
    move32();
#ifndef FIX_2086_ENABLE_HP20_OPT_FOR_ENC
    mem_fx[4] = L_deposit_l( prescale_current_frame );
    move32();
#endif

    IF( EQ_32( Fs, 8000 ) )
    {
@@ -407,36 +409,7 @@ void hp20_fx_32_opt(
    signal_fx[1] = W_round64_L( W_shl( W_y1, prescale ) );
    move32();

#ifdef FIX_2086_ENABLE_HP20_OPT_FOR_ENC
    Word16 scf_min = 63;
    move16();
    IF( GT_32( prescale, prescale_current_frame ) )
    {
        if ( NE_64( W_y1, 0 ) )
            scf_min = s_min( scf_min, W_norm( W_y1 ) );
        if ( NE_64( W_y2, 0 ) )
            scf_min = s_min( scf_min, W_norm( W_y1 ) );
        if ( NE_32( x1, 0 ) )
            scf_min = s_min( scf_min, norm_l( x1 ) );
        if ( NE_32( x2, 0 ) )
            scf_min = s_min( scf_min, norm_l( x2 ) );
        diff = sub( prescale_current_frame, prescale );
        diff = s_max( negate( scf_min ), diff );
        prescale_current_frame = add( prescale, diff );
        // prescale_current_frame = prescale;
        // diff = 0;
        // move16();
    }
    ELSE
    {
    diff = sub( prescale_current_frame, prescale );
    }
    mem_fx[4] = L_deposit_l( prescale_current_frame );
    move32();
#else
    diff = sub( prescale_current_frame, prescale );
#endif

    W_y1 = W_shr( W_y1, diff );
    W_y2 = W_shr( W_y2, diff );
    x2 = L_shr( x2, diff );