Commit 4f42d0a9 authored by sagnowski's avatar sagnowski
Browse files

Replace overflowing basops, pt 1

parent fbd29b53
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -106,6 +106,9 @@ void E_UTIL_deemph2(Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Wo
{
    Word16 i;
    Word32 L_tmp;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    /* signal[0] = signal[0] + mu * (*mem); */
    L_tmp = L_deposit_h(*mem);
@@ -123,8 +126,13 @@ void E_UTIL_deemph2(Word16 shift, Word16 *x, const Word16 mu, const Word16 L, Wo
    {
        FOR (i = 0; i < L; i++)
        {
#ifdef BASOP_NOGLOB
            L_tmp = L_msu_o(Mpy_32_16_1(L_tmp, mu), shr_o(x[i],shift, &Overflow),-32768, &Overflow);
            x[i] = round_fx_o(L_tmp, &Overflow);
#else /* BASOP_NOGLOB */
            L_tmp = L_msu(Mpy_32_16_1(L_tmp, mu), shr(x[i],shift),-32768);
            x[i] = round_fx(L_tmp);
#endif /* BASOP_NOGLOB */
        }
    }

+29 −0
Original line number Diff line number Diff line
@@ -53,6 +53,9 @@ void fft_rel_fx(
    Word16 *x0, *x1, *x2;
    const Word16 *s, *c;
    Word16 *xi2, *xi3, *xi4, *xi1;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */


    /*-----------------------------------------------------------------*
@@ -136,9 +139,17 @@ void fft_rel_fx(
        {
            xt = *x0;
            move16();        /* xt = x[i];   */
#ifdef BASOP_NOGLOB
            *x0 =  add_o(xt,*x1, &Overflow);
#else /* BASOP_NOGLOB */
            *x0 =  add(xt,*x1);
#endif /* BASOP_NOGLOB */
            move16();        /* x[i] = xt + x[i+n2];    */
#ifdef BASOP_NOGLOB
            *x1  = sub_o(xt,*x1, &Overflow);
#else /* BASOP_NOGLOB */
            *x1  = sub(xt,*x1);
#endif /* BASOP_NOGLOB */
            move16();        /* x[i+n2] = xt - x[i+n2];      */
            *x2 = negate(*x2);
            move16();        /* x[i+n2+n4] = -x[i+n2+n4];     */
@@ -153,15 +164,33 @@ void fft_rel_fx(

            FOR (j = 1; j < n4; j++)
            {
#ifdef BASOP_NOGLOB
                t1  =  add_o(mult_r(*xi3,*c),mult_r(*xi4,*s), &Overflow);    /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind);   */
                t2 = sub_o(mult_r(*xi3,*s),mult_r(*xi4,*c), &Overflow);      /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind);     */
                *xi4 = sub_o(*xi2,t2, &Overflow);
#else /* BASOP_NOGLOB */
                t1  =  add(mult_r(*xi3,*c),mult_r(*xi4,*s));    /* t1 = *xi3**(pt_c+ind) + *xi4**(pt_s+ind);   */
                t2 = sub(mult_r(*xi3,*s),mult_r(*xi4,*c));      /* t2 = *xi3**(pt_s+ind) - *xi4**(pt_c+ind);     */
                *xi4 = sub(*xi2,t2);
#endif /* BASOP_NOGLOB */
                move16();
#ifdef BASOP_NOGLOB
                *xi3 = negate(add_o(*xi2,t2, &Overflow));
#else /* BASOP_NOGLOB */
                *xi3 = negate(add(*xi2,t2));
#endif /* BASOP_NOGLOB */
                move16();
#ifdef BASOP_NOGLOB
                *xi2 =  sub_o(*xi1,t1, &Overflow);
#else /* BASOP_NOGLOB */
                *xi2 =  sub(*xi1,t1);
#endif /* BASOP_NOGLOB */
                move16();
#ifdef BASOP_NOGLOB
                *xi1 =  add_o(*xi1,t1, &Overflow);
#else /* BASOP_NOGLOB */
                *xi1 =  add(*xi1,t1);
#endif /* BASOP_NOGLOB */
                move16();

                xi4--;
+11 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ static void filter_2nd_order(
    Word16 i;
    Word16 x2, x1;
    Word32 L_sum, L_y1, L_y2;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */


    /*
@@ -108,7 +111,11 @@ static void filter_2nd_order(
        L_y2  = L_shl(L_sum, HP20_COEFF_SCALE);
        BASOP_SATURATE_ERROR_OFF
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        signal[i*stride] = round_fx_o(L_shl_o(L_y2, prescale, &Overflow), &Overflow);
#else /* BASOP_NOGLOB */
        signal[i*stride] = round_fx(L_shl(L_y2, prescale));
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
        /* y[i+1] = b2*x[i-1] + b1*x[i-0] + b2*x[i+1] + a2*y[i-1] + a1*y[i+0];  */
        BASOP_SATURATE_ERROR_ON
@@ -122,7 +129,11 @@ static void filter_2nd_order(
        L_y1  = L_shl(L_sum, HP20_COEFF_SCALE);
        BASOP_SATURATE_ERROR_OFF
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        signal[(i+1)*stride] = round_fx_o(L_shl_o(L_y1, prescale, &Overflow), &Overflow);
#else /* BASOP_NOGLOB */
        signal[(i+1)*stride] = round_fx(L_shl(L_y1, prescale));
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
    }
    /* update static filter memory from variables */
+50 −0
Original line number Diff line number Diff line
@@ -175,6 +175,9 @@ Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo)
{
    Word16 approx /*, hi, lo, n_hi , n_lo*/;
    Word32 L_32;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    /* First approximation: 1 / L_denom = 1/denom_hi */

@@ -190,7 +193,11 @@ Word32 Div_32_opt (Word32 L_num, Word16 denom_hi, Word16 denom_lo)

    L_32 = Mpy_32_32(L_num, L_32);

#ifdef BASOP_NOGLOB
    L_32 = L_shl_o (L_32, 2, &Overflow);
#else /* BASOP_NOGLOB */
    L_32 = L_shl (L_32, 2);
#endif /* BASOP_NOGLOB */

    return (L_32);
}
@@ -232,6 +239,9 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
    Word32 t0, t1, t2;             /* temporary variables                         */
    Word16 flag;
    Word16 Ah[TCXLTP_LTP_ORDER + 1], Al[TCXLTP_LTP_ORDER + 1];   /* LPC coef. in double prec. */
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */


    BASOP_SATURATE_WARNING_OFF
@@ -292,12 +302,20 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
            t0 = Mac_32(t0, Rh[j], Rl[j], Ah[i - j], Al[i - j]);
        }

#ifdef BASOP_NOGLOB
        t0 = L_shl_o(t0, 4, &Overflow);                 /* result in Q27 -> convert to Q31 */
#else /* BASOP_NOGLOB */
        t0 = L_shl(t0, 4);                 /* result in Q27 -> convert to Q31 */
#endif /* BASOP_NOGLOB */
        /* No overflow possible            */

        /* Compose and add R[i] in Q3 */
        t0 = L_mac(t0, Rl[i], 1);
#ifdef BASOP_NOGLOB
        t0 = L_msu_o(t0, Rh[i], -32768, &Overflow);
#else /* BASOP_NOGLOB */
        t0 = L_msu(t0, Rh[i], -32768);
#endif /* BASOP_NOGLOB */

        /* K = -t0 / Alpha */
        t1 = L_abs(t0);
@@ -312,7 +330,11 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
        {
            t2 = L_negate(t2);             /* K =-t0/Alpha                    */
        }
#ifdef BASOP_NOGLOB
        t2 = L_shl_o(t2, alp_exp, &Overflow);           /* denormalize; compare to Alpha   */
#else /* BASOP_NOGLOB */
        t2 = L_shl(t2, alp_exp);           /* denormalize; compare to Alpha   */
#endif /* BASOP_NOGLOB */
        test();
        if ((mem!=NULL) && ((GT_16(abs_s(extract_h(t2)), k_max))))
        {
@@ -350,7 +372,11 @@ Word16 E_LPC_lev_dur_stab(const Word16 Rh[], const Word16 Rl[], Word16 A[],
        L_Extract(t2, &Ah[i], &Al[i]);        /* An[i] in Q27                   */

        /* Alpha = Alpha * (1-K**2) */
#ifdef BASOP_NOGLOB
        t1 = L_mult_o(Kh, Kh, &Overflow);                  /* K*K      in Q31 */
#else /* BASOP_NOGLOB */
        t1 = L_mult(Kh, Kh);                  /* K*K      in Q31 */
#endif /* BASOP_NOGLOB */
        t0 = L_mac(t1, mult(Kh, Kl), 2);
        t0 = L_abs(t0);                       /* Some case <0 !! */
        t0 = L_sub((Word32) 0x7fffffffL, t0); /* 1 - K*K  in Q31 */
@@ -767,6 +793,10 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *
    Word32 L_tmp, L_tmp1, L_tmp3;
    Word16 lpc[19];

#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */


    /* half length FFT */
    scale = add(norm_s(lpcCoeffs[0]),1)+5;
@@ -928,16 +958,26 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *
        Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i]));
        Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N/2-i]));
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im, &Overflow);
        tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.re, pwn17->v.im),  ptwiddle->v.im, pwn17->v.re, &Overflow);
#else /* BASOP_NOGLOB */
        tmpw15.v.re = mac_r(L_mult(ptwiddle->v.re, pwn17->v.re), ptwiddle->v.im, pwn17->v.im);
        tmpw15.v.im = msu_r(L_mult(ptwiddle->v.re, pwn17->v.im),  ptwiddle->v.im, pwn17->v.re);
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
        RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
        move16();
        ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
        move16();
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re, &Overflow);
        tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.re, pwn17i->v.im),  ptwiddle->v.im, pwn17i->v.re, &Overflow);
#else /* BASOP_NOGLOB */
        tmpw15.v.re = msu_r(L_mult(ptwiddle->v.im, pwn17i->v.im), ptwiddle->v.re, pwn17i->v.re);
        tmpw15.v.im = mac_r(L_mult(ptwiddle->v.re, pwn17i->v.im),  ptwiddle->v.im, pwn17i->v.re);
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
        RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re),  ReBr, pwn15i->v.im);
        move16();
@@ -958,16 +998,26 @@ void E_LPC_a_lsf_isf_conversion(Word16 *lpcCoeffs, Word16 *lsf, const Word16 *
        Word16 ImAr = extract_h(L_sub(ImagFFT[i], ImagFFT[N/2-i]));
        Word16 ImBr = extract_h(L_add(ImagFFT[i], ImagFFT[N/2-i]));
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        tmpw15.v.re = mac_ro(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im, &Overflow);
        tmpw15.v.im = msu_ro(L_mult(ptwiddle->v.im, pwn17->v.im),  ptwiddle->v.re, pwn17->v.re, &Overflow);
#else /* BASOP_NOGLOB */
        tmpw15.v.re = mac_r(L_mult(ptwiddle->v.im, pwn17->v.re), ptwiddle->v.re, pwn17->v.im);
        tmpw15.v.im = msu_r(L_mult(ptwiddle->v.im, pwn17->v.im),  ptwiddle->v.re, pwn17->v.re);
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
        RealOut[i] = mac_r(L_msu(L_msu(L_mult(ReAr, pwn17->v.re),ImAr, pwn17->v.im), ReBr, pwn15->v.im), ImBr, pwn15->v.re);
        move16();
        ImagOut[i] = mac_r(L_mac(L_mac(L_mult(ReAr, pwn17->v.im), ImAr, pwn17->v.re), ReBr, pwn15->v.re), ImBr, pwn15->v.im);
        move16();
        BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
        tmpw15.v.re = msu_ro(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re, &Overflow);
        tmpw15.v.im = mac_ro(L_mult(ptwiddle->v.im, pwn17i->v.im),  ptwiddle->v.re, pwn17i->v.re, &Overflow);
#else /* BASOP_NOGLOB */
        tmpw15.v.re = msu_r(L_mult(ptwiddle->v.re, pwn17i->v.im), ptwiddle->v.im, pwn17i->v.re);
        tmpw15.v.im = mac_r(L_mult(ptwiddle->v.im, pwn17i->v.im),  ptwiddle->v.re, pwn17i->v.re);
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON
        RealOut[N/2-i] = msu_r(L_mac(L_mac(L_mult(ReAr, pwn17i->v.re), ImAr, pwn17i->v.im), ImBr, pwn15i->v.re), ReBr, pwn15i->v.im);
        move16();
+29 −2
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift)

    Word16 cheb;
    Word32 t0, b1, b2;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    cheb = norm_s(x);
    if (cheb)
@@ -119,8 +122,13 @@ static Word16 chebyshev(Word16 x, Word32 *f, const Word16 n, const Word16 shift)


    BASOP_SATURATE_WARNING_OFF
#ifdef BASOP_NOGLOB
    t0 = L_shl_o(t0, shift, &Overflow);            /* Qx to Q30 with saturation */
    cheb = round_fx_o(t0, &Overflow);              /* Result in Q14              */
#else /* BASOP_NOGLOB */
    t0 = L_shl(t0, shift);            /* Qx to Q30 with saturation */
    cheb = round_fx(t0);              /* Result in Q14              */
#endif /* BASOP_NOGLOB */
    cheb = s_max(-32767,cheb);        /* to avoid saturation        */
    BASOP_SATURATE_WARNING_ON
    return (cheb);
@@ -333,6 +341,9 @@ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m)
    Word32 f1[NC_MAX+1], f2[NC_MAX+1]; /* Q23 */
    Word16 nc, q;
    Word32 t0, tmax, t0p, t0n;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */



@@ -413,8 +424,13 @@ void E_LPC_f_isp_a_conversion(const Word16 *isp, Word16 *a, const Word16 m)

        BASOP_SATURATE_WARNING_OFF /*overflow handling in loop expression*/
        t0 = L_shl(t0, q);
#ifdef BASOP_NOGLOB
        t0n = L_sub_o(t0 , 0x7FFFFFFF, &Overflow); /*check for positive overflow*/
        t0p = L_sub_o(t0,  0x80000000, &Overflow); /*check for negative overflow*/
#else /* BASOP_NOGLOB */
        t0n = L_sub(t0 , 0x7FFFFFFF); /*check for positive overflow*/
        t0p = L_sub(t0,  0x80000000); /*check for negative overflow*/
#endif /* BASOP_NOGLOB */
        BASOP_SATURATE_WARNING_ON

        q = sub(q,1); /*decrease q in case of overflow*/
@@ -609,7 +625,7 @@ void lsp2lpc_fx(
    Word16 giOverflow;

#ifdef BASOP_NOGLOB
    Flag Overflow;
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    FOR ( i = 0; i < order; i++ )
@@ -790,7 +806,7 @@ Word16 E_LPC_f_lsp_pol_get(const Word16 lsp[], Word32 f[], const Word16 n, cons
    Word16 m2;

#ifdef BASOP_NOGLOB
    Flag Overflow;
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    Q_out = 31-23;
@@ -1953,6 +1969,9 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/
    Word16 i, m;
    Word32 L_tmp;
    Word16 tmp, e;
#ifdef BASOP_NOGLOB
    Flag Overflow = 0;
#endif /* BASOP_NOGLOB */

    /*-------------------------------------------------------------------*
     * Check stability on lsf: distance between old lsf and current lsf
@@ -1997,10 +2016,18 @@ Word16 lsf_stab_fx( /* o : LP filter stability Q15*/
    }

    e = sub(30-21-1,e);
#ifdef BASOP_NOGLOB
    tmp = round_fx_o(L_shl_o(L_tmp, e, &Overflow), &Overflow); /*Q14*/
#else /* BASOP_NOGLOB */
    tmp = round_fx(L_shl(L_tmp, e)); /*Q14*/
#endif /* BASOP_NOGLOB */

    tmp = sub(20480, tmp);                /* 1.25 - tmp in Q14          */
#ifdef BASOP_NOGLOB
    tmp = shl_o(tmp, 1, &Overflow);                    /* Q14 -> Q15 with saturation */
#else /* BASOP_NOGLOB */
    tmp = shl(tmp, 1);                    /* Q14 -> Q15 with saturation */
#endif /* BASOP_NOGLOB */

    tmp = s_max(tmp, 0);

Loading