Commit eeacd4c3 authored by multrus's avatar multrus
Browse files

Merge branch '1799-replace-l_shr_o-by-overflow-free-alternatives' into 'main'

Resolve "replace L_shr_o by overflow-free alternatives"

Closes #1799

See merge request !1860
parents 0bddff96 1476d274
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1329,7 +1329,11 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead)
        {
            FOR( j = 20; j < numberBandsM; j++ )
            {
#ifdef ISSUE_1799_replace_L_shr_o
                nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow );
#else
                nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow );
#endif
            }
        }

@@ -1352,7 +1356,11 @@ void GetEnergyCldfb( Word32 *energyLookahead, /*!< o: Q(*sf_energyLookahead)
        {
            FOR( j = 20; j < numberBandsM; j++ )
            {
#ifdef ISSUE_1799_replace_L_shr_o
                nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow );
#else
                nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow );
#endif
            }
        }

+8 −0
Original line number Diff line number Diff line
@@ -1590,7 +1590,11 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e
        {
            FOR( j = 20; j < numberBandsM; j++ )
            {
#ifdef ISSUE_1799_replace_L_shr_o
                nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow );
#else
                nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow );
#endif
            }
        }

@@ -1613,7 +1617,11 @@ static void GetEnergyCldfb_ivas_fx( Word32 *energyLookahead, /*!< o: Q(*sf_e
        {
            FOR( j = 20; j < numberBandsM; j++ )
            {
#ifdef ISSUE_1799_replace_L_shr_o
                nrg = L_add_o( nrg, L_shr_sat( energyValues[k][j], s ), &Overflow );
#else
                nrg = L_add_o( nrg, L_shr_o( energyValues[k][j], s, &Overflow ), &Overflow );
#endif
            }
        }

+32 −4
Original line number Diff line number Diff line
@@ -904,7 +904,11 @@ void cng_params_upd_fx(
            tmpv = shl( *pt_exc2, scale );
            L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow );
            pt_exc2++;
#ifdef ISSUE_1799_replace_L_shr_o
            L_ener = L_add_o( L_ener, L_shr_sat( L_tmp, 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */
#else
            L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow );                                         /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */
#endif
        }
    }
    ELSE /* L_FRAME16k */
@@ -917,10 +921,18 @@ void cng_params_upd_fx(
            tmpv = shl( *pt_exc2, scale );
            L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow );
            pt_exc2++;
#ifdef ISSUE_1799_replace_L_shr_o
            L_ener = L_add_o( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */
#else
            L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */
#endif
        }
    }
#ifdef ISSUE_1799_replace_L_shr_o
    L_ener = L_shr_sat( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */
#else
    L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow );                                        /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */
#endif

    /* update the circular buffer of old energies */
    ho_ener_circ[*ho_circ_ptr] = L_ener;
@@ -1082,7 +1094,11 @@ void cng_params_upd_ivas_fx(
            tmpv = shl( *pt_exc2, scale );
            L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow );
            pt_exc2++;
#ifdef ISSUE_1799_replace_L_shr_o
            L_ener = L_add_o( L_ener, L_shr_sat( L_tmp, 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */
#else
            L_ener = L_add_o( L_ener, L_shr_o( L_tmp, 7, &Overflow ), &Overflow );                                         /* Q(2*(Q_exc+scale)+1) ,division by L_frame done here */
#endif
        }
    }
    ELSE /* L_FRAME16k */
@@ -1095,10 +1111,18 @@ void cng_params_upd_ivas_fx(
            tmpv = shl( *pt_exc2, scale );
            L_tmp = L_mac0_o( L_tmp, tmpv, tmpv, &Overflow );
            pt_exc2++;
#ifdef ISSUE_1799_replace_L_shr_o
            L_ener = L_add_o( L_ener, L_shr_sat( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7 ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */
#else
            L_ener = L_add_o( L_ener, L_shr_o( Mult_32_16( L_tmp, 26214 /* 256/320, Q15 */ ), 7, &Overflow ), &Overflow ); /* Q(2*(Q_exc+scale)+15+1-16+1) ,division by L_frame done here */
#endif
        }
    }
#ifdef ISSUE_1799_replace_L_shr_o
    L_ener = L_shr_sat( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ) ); /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */
#else
    L_ener = L_shr_o( L_ener, sub( shl( add( Q_exc, scale ), 1 ), 5 ), &Overflow );                                        /* Q6 (2*(Q_exc+scale)+1-2*(Q_exc+scale)+5) */
#endif

    /* update the circular buffer of old energies */
    ho_ener_circ[*ho_circ_ptr] = L_ener;
@@ -1137,7 +1161,11 @@ void cng_params_upd_ivas_fx(
            L_tmp = L_add_o( L_tmp, L_tmp, &Overflow );                             /* 2*Q_exc+1 */
            L_tmp = Mult_32_16( L_tmp, 128 );                                       /* 2*Q_exc+1 */
            tmp = add( add( Q_exc, Q_exc ), 1 );
#ifdef ISSUE_1799_replace_L_shr_o
            sp[i] = L_shr_sat( L_tmp, sub( tmp, 6 ) );
#else
            sp[i] = L_shr_o( L_tmp, sub( tmp, 6 ), &Overflow );
#endif
            move32(); /* Q6 */
            ptR++;
            ptI--;
+11 −3
Original line number Diff line number Diff line
@@ -504,12 +504,20 @@ void edct_16fx(

        L_tmp = L_mult( re[i], edct_table[i] );         /*Q(Qx+Q_edct+16) */
        Lacc = L_mac_o( L_tmp, im[i], *pt, &Overflow ); /*Q(Qx+Q_edct+16) */
#ifdef ISSUE_1799_replace_L_shr_o
        y[i2] = round_fx_o( L_shr_sat( Lacc, Q_edct ), &Overflow ); /* Q(Qx) */
#else
        y[i2] = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow ); /* Q(Qx) */
#endif
        move16();

        L_tmp = L_mult( re[i], edct_table[sub( shr( length, 1 ), add( 1, i ) )] ); /*Q(Qx+Q_edct+16) */
        Lacc = L_msu( L_tmp, im[i], edct_table[i] );                               /*Q(Qx+Q_edct+16) */
#ifdef ISSUE_1799_replace_L_shr_o
        *py = round_fx_o( L_shr_sat( Lacc, Q_edct ), &Overflow ); /* Q(Qx) */
#else
        *py = round_fx_o( L_shr_o( Lacc, Q_edct, &Overflow ), &Overflow );   /* Q(Qx) */
#endif
        move16();

        py -= 2;
+6 −2
Original line number Diff line number Diff line
@@ -277,7 +277,11 @@ Word16 frame_energy_fx( /* o : Frame energy in Q8

    /*add ld(2^exp1)=exp1 but check format, first*/
    tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/
#ifdef ISSUE_1799_replace_L_shr_o
    Ltmp = L_shr_sat( Ltmp, tmp16 ); /*Q25, tmp16*/
#else
    Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/
#endif
    exp2 = shr( exp1, tmp16 );                                           /*Q0 , tmp16*/
    Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/

Loading