Commit d8081a4d authored by thomas dettbarn's avatar thomas dettbarn
Browse files

code cleanup. using Q20 instead of Q23 for the accu_variables gives a little bit more headroom.

parent 0fd8a97f
Loading
Loading
Loading
Loading
Loading
+54 −69
Original line number Diff line number Diff line
@@ -1745,19 +1745,17 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
    const UWord8 *lookup;
    Word16 idx;
    Word16 tmp;
    Word16 accu_variables; /* Q0 */
    Word32 accu_lut;       /* Q8 */
    Word16 loop_end;
    Word32 accu_lut;
    Word16 accu_variables;

    accu_variables = 0;
    accu_lut = 0;
    move16();
    move32();
    accu_variables = 0;
    move16();

    /* Main Loop through the 2-tuples */
    /*hContextMem->nt_half = end_line >> 1;*/

    loop_end = min( hContextMem->lastnz, end_line );
    FOR( k = start_line; k < loop_end; k += 2 )
    FOR( k = start_line; k < min( hContextMem->lastnz, end_line ); k += 2 )
    {
        a1_i = k; /* Q0 */
        move16();
@@ -1786,12 +1784,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
        lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) ); /* Q0 */

        /* Signs Bits */
        //        hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( a1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
        //        hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, imult3216( ONE_IN_Q30, s_min( b1, 1 ) ), Q1, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
        accu_variables = L_add( accu_variables, s_min( a1, 1 ) );
        accu_variables = L_add( accu_variables, s_min( b1, 1 ) );
        move32();
        move32();
        accu_variables = add( accu_variables, s_min( a1, 1 ) );
        accu_variables = add( accu_variables, s_min( b1, 1 ) );

        /* pre-compute address of ari_pk_s17_LC_ext[0][Val_esc] to avoid doing it multiple times inside the loop */
        lookup = &ari_lookup_s17_LC[t] + ( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );
@@ -1803,15 +1797,8 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
            pki = lookup[lev1]; /* Q0 */
            move16();

            //            hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], Q8, &hContextMem->bit_estimate_e ); /* exp(hContextMem->bit_estimate_e) */
            //            hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, 2 * ONE_IN_Q29, Q2, &hContextMem->bit_estimate_e );                           /* Add the 2 LSB bits that were shifted out	exp(hContextMem->bit_estimate_e) */
            accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] );
            accu_variables = L_add( accu_variables, 2 );
            move32();
            move32();

            // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][VAL_ESC];
            // hContextMem->bit_estimate += 2; /* Add the 2 LSB bits that were shifted out */
            accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC]>>3 );
            accu_variables = add( accu_variables, 2 );

            a1 = shr( a1, 1 );
            b1 = shr( b1, 1 );
@@ -1823,10 +1810,7 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
        pki = lookup[lev1]; /* Q0 */
        move16();
        symbol = add( a1, i_mult( A_THRES, b1 ) );                                                                                                                                                       /* MSB symbol    Q0*/
                                                   //        hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], Q8, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */
        accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol] );
        move32();
        // hContextMem->bit_estimate = hContextMem->bit_estimate + ari_bit_estimate_s17_LC[pki][symbol];
        accu_lut = L_add( accu_lut, ari_bit_estimate_s17_LC_fx[pki][symbol]>>3 );

        /* Update context */
        lev1 = shr( lev1, NBITS_CONTEXT + NBITS_RATEQ );
@@ -1844,8 +1828,9 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx(
        move16();

    }                                                                                                               /*end of the 2-tuples loop*/
    accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q23, accu_variables ) ); // bring both accus into the same representation (Q8)
    hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q8, &hContextMem->bit_estimate_e );
    accu_lut = L_add( accu_lut, imult3216( ONE_IN_Q20, accu_variables ) );        // bring the accu_variables into Q20
    hContextMem->bit_estimate_fx = BASOP_Util_Add_Mant32Exp( hContextMem->bit_estimate_fx, hContextMem->bit_estimate_e, accu_lut, Q11, &hContextMem->bit_estimate_e ); /* exp(bit_estimate_e) */
    move32();
    total_output_bits = round_fx( L_shr( hContextMem->bit_estimate_fx, sub( Q15, hContextMem->bit_estimate_e ) ) ); /* Q0 */
    // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f );