Commit 0ee5f968 authored by JÜRGEN Gerstacker's avatar JÜRGEN Gerstacker
Browse files

ISSUE 1817, MR less 1931, introduced function sum_array_norm() to cover 4 identical loops

parent 7b2ff3d1
Loading
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -2142,6 +2142,25 @@ Word32 Dot_product16HQ( /* o : normalized result
    return L_sum;
}

Word32 sum_array_norm(                    /* o : normalized result              Q31 */
                      const Word32 x[],   /* i : x vector                        Qn */
                      const Word16 lg,    /* i : vector length, range [0..7FFF]  Q0 */
                      Word16 *exp         /* o : exponent of result in [-32,31]  Q0 */
)
{
    Word16 i;
    Word64 W_tmp = 0;
    Word32 L_tmp;
    FOR( i = 0; i < lg; i++ )
    {
        W_tmp = W_add( W_tmp, x[i] ); /*Q31*/
    }
    L_tmp = w_norm_llQ31( W_tmp, exp ); /*Q31 - *exp*/
    return L_tmp;
}



Word32 Norm32Norm( const Word32 *x, const Word16 headroom, const Word16 length, Word16 *result_e )
{
    Word32 L_tmp, L_tmp2;
+14 −0
Original line number Diff line number Diff line
@@ -612,6 +612,20 @@ Word32 Dot_product16HQ( /*<! o : normalized result
                        Word16 *exp         /*<! o : exponent of result in [-32,31]  Q0 */
);

/*------------------------------------------------------------------*
 * sum_array_norm:
 *
 * \brief Compute array summation of x[] using 64-bit accumulator.
 *
 * Performs normalization of the result, returns the exponent
 * Note: no headroom is required for data in x[]
 *------------------------------------------------------------------*/
Word32 sum_array_norm(                    /* o : normalized result              Q31 */
                      const Word32 x[],   /* i : x vector                        Qn */
                      const Word16 lg,    /* i : vector length, range [0..7FFF]  Q0 */
                      Word16 *exp         /* o : exponent of result in [-32,31]  Q0 */
);

/*------------------------------------------------------------------*
 * norm_llQ31:
 *
+6 −34
Original line number Diff line number Diff line
@@ -578,7 +578,7 @@ Word16 ApplyFdCng_fx(
    Word16 tmp_loop;
#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW
    Word32 L_c;
#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */
#endif
    Word16 lsp_cng[M];
    HANDLE_FD_CNG_DEC hFdCngDec;
    HANDLE_FD_CNG_COM hFdCngCom;
@@ -586,7 +586,7 @@ Word16 ApplyFdCng_fx(
    Flag Overflow = 0;
#ifndef FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW
    Flag Carry = 0;
#endif /* FIX_ISSUE_1817_REPLACE_CARRY_OVERFLOW */
#endif
    move16();
    move16();
#endif
@@ -832,14 +832,7 @@ Word16 ApplyFdCng_fx(
                    move16();
                    L_tmp_exp = add( L_tmp_exp, 1 );
#else
                    {
                        Word64 W_tmp = 0;
                        FOR( j = 0; j < tmp_loop; j++ )
                        {
                            W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31*/
                        }
                        L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/
                    }
                    L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/
                    L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 );

                    L_tmp = L_shr( L_tmp, 15 ); /*Q16 - L_tmp_exp*/
@@ -890,14 +883,7 @@ Word16 ApplyFdCng_fx(

                    st->hTcxDec->conCngLevelBackgroundTrace = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/
#else
                    {
                        Word64 W_tmp = 0;
                        FOR( j = 0; j < tmp_loop; j++ )
                        {
                            W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/
                        }
                        L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/
                    }
                    L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp);
                    L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 );

                    L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/
@@ -947,14 +933,7 @@ Word16 ApplyFdCng_fx(
                st->cngTDLevel = round_fx_sat( Sqrt32( L_tmp, &L_tmp_exp ) ); /*Q15 - L_tmp_exp*/
                move16();
#else
                {
                    Word64 W_tmp = 0;
                    FOR( j = 0; j < tmp_loop; j++ )
                    {
                        W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/
                    }
                    L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/
                }
                L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/
                L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 );

                L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/
@@ -1117,14 +1096,7 @@ Word16 ApplyFdCng_fx(
                st->cngTDLevel = round_fx_o( Sqrt32( L_tmp, &L_tmp_exp ), &Overflow ); /*Q15 - L_tmp_exp*/
                move16();
#else
                {
                    Word64 W_tmp = 0;
                    FOR( j = 0; j < tmp_loop; j++ )
                    {
                        W_tmp = W_add( W_tmp, *( cngNoiseLevel + j ) ); /*Q31 - L_tmp_exp*/
                    }
                    L_tmp = w_norm_llQ31( W_tmp, &L_tmp_exp ); /*Q31 - L_tmp_exp*/
                }
                L_tmp = sum_array_norm(cngNoiseLevel, tmp_loop, &L_tmp_exp); /*Q31 - L_tmp_exp*/
                L_tmp_exp = sub( add( L_tmp_exp, *cngNoiseLevel_exp ), 1 );

                L_tmp = Mpy_32_16_1( L_tmp, hFdCngCom->fftlen ); /*Q16 - L_tmp_exp*/