Commit 0a0a50ba authored by thomas dettbarn's avatar thomas dettbarn
Browse files

removed bit_estimate_fx and bit_estimate_e from the ACcontextMapping_enc_fx.c completely.

parent 19726c71
Loading
Loading
Loading
Loading
Loading
+40 −47
Original line number Diff line number Diff line
@@ -1230,43 +1230,40 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
{
    /* Common variables */
    Word16 a1, b1;
    Word16 k, pki, lev1;
    Word16 i, k, pki, lev1;
    UWord16 t;
    Word16 lastnz, lastnz2;
    Word16 rateFlag;
    Word32 bit_estimate_fx;
    Word16 bit_estimate_e;
    Word64 bit_estimate_accu;

    Word16 symbol;
    const UWord8 *lookup;
    Word32 nbits2_fx; // Q23
    Word16 nbits2_e;
    Word64 nbits2_accu; 

    /* Initialization */
    bit_estimate_fx = 2 * ONE_IN_Q29;
    bit_estimate_e = 2;
    move32();
    move16();
    bit_estimate_accu = MAKE_NUMBER_QX(2, Q23 );
    move64();

    nbits2_fx = 0;
    nbits2_e = 0;
    move32();
    move16();
    nbits2_accu = 0;
    move64();

    /* bits to encode lastnz */
    k = 1;
    move16();
    i = 2;
    move64();

    WHILE( LT_16( k, nt / 2 ) )
    {
        bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ONE_IN_Q30, 1, &bit_estimate_e );
        k = k << 1;
        bit_estimate_accu = W_add( bit_estimate_accu, MAKE_NUMBER_QX(1, Q23 ) );
        k = shl( k, 1 );
        i = add( i, 2 );
        /* check while condition */
 
    }

    nbits2_fx = bit_estimate_fx; /* exp(bit_estimate_e) */
    nbits2_e = bit_estimate_e;
    move32();
    move16();
    nbits2_accu = bit_estimate_accu;
    move64();

    IF( hm_cfg )
    {
@@ -1353,9 +1350,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            b1 = (Word16) abs( x[b1_i] );
            lev1 = -( 1 << ( NBITS_CONTEXT + NBITS_RATEQ ) );

            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */

            bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX( s_min( a1, 1 ), Q23 ) );
            bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX( s_min( b1, 1 ), Q23 ) );
            /* 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 ) );

@@ -1365,9 +1361,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            {
                pki = lookup[lev1]; /* ESC symbol */

                bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
                bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e );                           /* Add 2 LSB bits corresponding to the bit-plane        exp(bit_estimate_e) */

                bit_estimate_accu = W_add_nosat( bit_estimate_accu, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] );
                bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX(2, Q23 ) );
                a1 = shr( a1, 1 );
                b1 = shr( b1, 1 );

@@ -1379,10 +1374,10 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            pki = lookup[lev1];

            symbol = add( a1, i_mult( A_THRES, b1 ) );                                                                                                  /* Q0 */
            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
            bit_estimate_accu = W_add_nosat( bit_estimate_accu, ari_bit_estimate_s17_LC_fx[pki][symbol] );

            /* Should we truncate? */
            IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) )
            IF( GT_32( W_shr( bit_estimate_accu, Q8 ), L_shl( target, Q15 ) ) )
            {
                stop2 = 1;
                move16();
@@ -1395,10 +1390,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            ELSE
            {
                lastnz2 = add( b1_i, 1 );
                nbits2_fx = bit_estimate_fx;
                move32();
                nbits2_e = bit_estimate_e;
                move16();
                nbits2_accu = bit_estimate_accu; 
                move64();
            }

            /* Update context for next 2-tuple */
@@ -1439,11 +1432,11 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(

        } /*end of the 2-tuples loop*/

        total_output_bits = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
        total_output_bits = round_fx( W_shr(bit_estimate_accu, Q7 ) );

        IF( *stop )
        {
            total_output_bits = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) ); /* Q0 */
            total_output_bits = round_fx( W_shr( nbits2_accu, Q7 ) );
        }

        IF( stop2 )
@@ -1468,7 +1461,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
        hm_cfg->numPeakIndices = numPeakIndicesOrig; /* Q0 */
        move16();

        return round_fx( L_add( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ), ONE_IN_Q14 ) ); /* Q0 */

        return round_fx( L_add( W_shr( nbits2_accu, Q7 ), ONE_IN_Q14 ) ); /* Q0 */
    }
    ELSE /* if (!hm_cfg) */
    {
@@ -1534,8 +1528,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            move16();
            rateQ = add( rateFlag, extract_l( GT_16( k, shr( nt, 1 ) ) ) ); /* Q0 */

            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( a1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, s_min( b1, 1 ) * ONE_IN_Q30, 1, &bit_estimate_e ); /* exp(bit_estimate_e) */
            bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX( s_min( a1, 1 ), Q23 ) );
            bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX( s_min( b1, 1 ), Q23 ) );

            /* 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 + shl( rateQ, NBITS_CONTEXT )]; /* Q0 */
@@ -1547,8 +1541,8 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
                pki = lookup[( esc_nb << ( NBITS_CONTEXT + NBITS_RATEQ ) )]; /* Q0 */
                move16();

                bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
                bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, 2 * ONE_IN_Q29, 2, &bit_estimate_e );                           /* Add 2 LSB bits corresponding to the bit-plane  exp(bit_estimate_e) */
                bit_estimate_accu = W_add_nosat( bit_estimate_accu, ari_bit_estimate_s17_LC_fx[pki][VAL_ESC] );
                bit_estimate_accu = W_add_nosat( bit_estimate_accu, MAKE_VARIABLE_QX(2, Q23 ) );

                a1 = shr( a1, 1 );
                b1 = shr( b1, 1 );
@@ -1563,10 +1557,10 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            move16();

            symbol = add( a1, i_mult( A_THRES, b1 ) );                                                                                                  /* Q0 */
            bit_estimate_fx = BASOP_Util_Add_Mant32Exp( bit_estimate_fx, bit_estimate_e, ari_bit_estimate_s17_LC_fx[pki][symbol], 8, &bit_estimate_e ); /* exp(bit_estimate_e) */
            bit_estimate_accu = W_add_nosat( bit_estimate_accu, ari_bit_estimate_s17_LC_fx[pki][symbol] );

            /* Should we truncate? */
            IF( GT_32( L_shr( bit_estimate_fx, sub( Q16, bit_estimate_e ) ), L_shl( target, Q15 ) ) ) /* Overflow occured */
            IF( GT_32( W_shr( bit_estimate_accu, Q8 ), L_shl( target, Q15 ) ) )
            {
                overflow_flag = 1;
                move16();
@@ -1575,10 +1569,9 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            {
                IF( abs_s( x[k] ) || abs_s( x[k + 1] ) ) /* No overflow & non-zero tuple */
                {
                    nbits2_fx = bit_estimate_fx; /* exp(bit_estimate_e) */
                    nbits2_e = bit_estimate_e;
                    move32();
                    move16();
                    nbits2_accu = bit_estimate_accu; /* exp(bit_estimate_e) */
                    move64();

                    lastnz2 = add( k, 2 );
                }
            }
@@ -1598,7 +1591,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(

        } /*end of the 2-tuples loop*/

        tot_bits2 = round_fx( L_shr( nbits2_fx, sub( Q15, nbits2_e ) ) );
        tot_bits2 = round_fx( W_shr( nbits2_accu, Q7 ) );
        IF( LT_16( lastnz2, lastnz ) ) /* Overflow occured because unable to code all tuples */
        {
            overflow_flag = 1;
@@ -1606,7 +1599,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
        }
        IF( EQ_16( mode, -1 ) )
        {
            tot_bits2 = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
            tot_bits2 = round_fx( W_shr( bit_estimate_accu, Q7 ) );
        }
        IF( overflow_flag == 0 ) /* No overflow */
        {
@@ -1621,7 +1614,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx(
            }
            ELSE
            {
                *stop = round_fx( L_shr( bit_estimate_fx, sub( Q15, bit_estimate_e ) ) ); /* Q0 */
                *stop = round_fx( W_shr( bit_estimate_accu, Q7 ) );
                move16();
            }
        }