Skip to content
......@@ -766,8 +766,10 @@ static Word16 qlsf_Mode_Select_fx(
Word32 temp32, En = 0;
Word16 safety_net;
Word16 i, cs, cl;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/* calculate the prediction residual */
......@@ -784,7 +786,11 @@ static Word16 qlsf_Mode_Select_fx(
{
pred_pow2[i] = shl( pred1[i], cs );
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
En = L_mac_sat( En, mult( pred_pow2[i], shl_sat( w[i], 2 ) ), pred_pow2[i] ); /* 2.56*2.56 at Q-4 */
#else
En = L_mac_o( En, mult( pred_pow2[i], shl_sat( w[i], 2 ) ), pred_pow2[i], &Overflow ); /* 2.56*2.56 at Q-4 */
#endif
}
cs = shl( cs, 1 );
......@@ -1964,8 +1970,10 @@ static void first_VQstages(
Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j,
m, s, c, c2, p_max, *indices[2];
Word16 maxC = LSFMBEST;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/*float dd[16];*/
......@@ -1992,7 +2000,11 @@ static void first_VQstages(
L_tmp = L_deposit_l( 0 );
FOR( j = 0; j < N; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */
#else
L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */
#endif
L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */
L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */
}
......@@ -2154,8 +2166,10 @@ static void first_VQstages_ivas_fx(
Word16 *pTmp_short, idx_buf[2 * LSFMBEST * MAX_VQ_STAGES], parents[LSFMBEST], counter = 0, j,
m, s, c, c2, p_max, *indices[2];
Word16 maxC = LSFMBEST;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/*float dd[16];*/
......@@ -2182,7 +2196,11 @@ static void first_VQstages_ivas_fx(
L_tmp = L_deposit_l( 0 );
FOR( j = 0; j < N; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp1 = L_shl_sat( L_mult0( u[j], w[j] ), 7 ); /*x2.56 + Q8 + Q7 */
#else
L_tmp1 = L_shl_o( L_mult0( u[j], w[j] ), 7, &Overflow ); /*x2.56 + Q8 + Q7 */
#endif
L_tmp1 = Mult_32_16( L_tmp1, u[j] ); /*x2.56 + Q15 + x2.56 -Q15 */
L_tmp = L_add( L_tmp, L_tmp1 ); /*Q0 + x2.56 +x2.56 */
}
......@@ -3320,8 +3338,10 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx(
Word16 error_svq_fx[M], error_svq_q_fx[M];
Word16 cl, cs;
Word32 temp_l;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
IF( EQ_16( safety_net, 1 ) )
{
......@@ -3394,7 +3414,11 @@ Word32 qlsf_ARSN_tcvq_Enc_16k_fx(
{
yy_fx[i] = shl( yy_fx[i], cs );
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
temp_l = L_mac_sat( temp_l, mult( yy_fx[i], shl_sat( w_fx[i], 2 ) ), yy_fx[i] );
#else
temp_l = L_mac_o( temp_l, mult( yy_fx[i], shl_sat( w_fx[i], 2 ) ), yy_fx[i], &Overflow );
#endif
}
cs = shl( cs, 1 );
temp_l = L_shr( temp_l, cs );
......@@ -3413,14 +3437,20 @@ static void FFT_Mid_Interpol_16k_fx(
)
{
Word16 i;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
FOR( i = 0; i < L_FFT / 2; i++ )
{
/* Interpolation */
#ifdef ISSUE_1867_replace_overflow_libenc
Bin_Ener_mid[i] = L_shr( L_add_sat( Bin_Ener_old[i], Bin_Ener[i] ), 1 );
#else
Bin_Ener_mid[i] = L_shr( L_add_o( Bin_Ener_old[i], Bin_Ener[i], &Overflow ), 1 );
#endif
/* Memory update */
Bin_Ener_old[i] = Bin_Ener[i];
......@@ -3485,8 +3515,10 @@ static void lsf_mid_enc_fx(
Word32 L_tmp;
Word16 tmp, k1;
const Word16 *ratio = NULL;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/* convert LSPs to LSFs */
......@@ -3599,8 +3631,13 @@ static void lsf_mid_enc_fx(
/* err += wghts[j] * ftemp * ftemp; */
/* tmp is usually very small, we can have some extra precision with very rare saturation */
tmp = shl_sat( tmp, 4 );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = mult_r_sat( tmp, tmp );
err = L_mac_sat( err, tmp, shl_sat( wghts[j], 2 ) );
#else
tmp = mult_ro( tmp, tmp, &Overflow );
err = L_mac_o( err, tmp, shl_sat( wghts[j], 2 ), &Overflow );
#endif
}
/* err = L_shl(err,Wscale); */
err = Mult_32_16( err, LSF_1_OVER_256SQ );
......@@ -3662,8 +3699,10 @@ static void lsf_mid_enc_ivas_fx(
Word32 L_tmp;
Word16 tmp, k1;
const Word16 *ratio = NULL;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/* convert LSPs to LSFs */
......@@ -3785,8 +3824,13 @@ static void lsf_mid_enc_ivas_fx(
/* err += wghts[j] * ftemp * ftemp; */
/* tmp is usually very small, we can have some extra precision with very rare saturation */
tmp = shl_sat( tmp, 4 );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = mult_r_sat( tmp, tmp );
err = L_mac_sat( err, tmp, shl_sat( wghts[j], 2 ) );
#else
tmp = mult_ro( tmp, tmp, &Overflow );
err = L_mac_o( err, tmp, shl_sat( wghts[j], 2 ), &Overflow );
#endif
}
/* err = L_shl(err,Wscale); */
err = Mult_32_16( err, LSF_1_OVER_256SQ );
......
......@@ -1578,8 +1578,10 @@ void midlsf_enc_fx(
Word32 err, err_min, L_tmp;
Word16 k, k1, j, tmp, size, qlsf[M], wghts[M];
const Word16 *ratio;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
IF( EQ_16( coder_type, UNVOICED ) )
......@@ -1631,10 +1633,18 @@ void midlsf_enc_fx(
/* err += wghts[j] * ftemp * ftemp; */
/* tmp is usually very small, we can have some extra precision with very rare saturation */
tmp = shl_sat( tmp, 4 );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = mult_r_sat( tmp, tmp );
#else
tmp = mult_ro( tmp, tmp, &Overflow );
#endif
err = L_mac( err, tmp, wghts[j] );
}
#ifdef ISSUE_1867_replace_overflow_libenc
err = L_shl_sat( err, 2 );
#else
err = L_shl_o( err, 2, &Overflow );
#endif
/* err = L_shl(err,Wscale); */
err = Mult_32_16( err, LSF_1_OVER_256SQ );
......
......@@ -118,8 +118,10 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision
Word16 exp, exp1, exp2, exp3;
Word32 L_tmp, L_tmp1;
TCX_ENC_HANDLE hTcxEnc = st_fx->hTcxEnc;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
test();
{
......@@ -356,7 +358,11 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision
test();
test();
test();
#ifdef ISSUE_1867_replace_overflow_libenc
IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_sat( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) )
#else
IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_o( avrg_H1, 1, &Overflow ) ) ) || ( LT_32( Mult_32_32( L_shl_o( peak_l, exp, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( L_tmp, exp, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) || GT_32( Mult_32_32( L_shl_o( L_tmp1, exp2, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( peak_h, exp2, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) ) )
#endif
{
condition3 = 1;
move16();
......@@ -450,7 +456,11 @@ Word16 mdct_classifier_fx( /* o: MDCT A/B decision
test();
test();
test();
#ifdef ISSUE_1867_replace_overflow_libenc
IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_sat( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_sat( gain2_tmp, 1 ) ) ) ) )
#else
IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_o( gain1_tmp, 1, &Overflow ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_o( gain2_tmp, 1, &Overflow ) ) ) ) )
#endif
{
clas_final = hTcxEnc->clas_final_old;
move16();
......@@ -543,8 +553,10 @@ Word16 mdct_classifier_ivas_fx(
Word16 exp, exp1, exp2, exp3;
Word32 gain1_tmp = 0, gain2_tmp = 0;
Word32 L_tmp, L_tmp1;
#ifndef ISSUE_1867_replace_overflow_libenc
Flag Overflow = 0;
move16();
#endif
move16();
move16();
......@@ -888,7 +900,11 @@ Word16 mdct_classifier_ivas_fx(
test();
test();
test();
#ifdef ISSUE_1867_replace_overflow_libenc
IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_sat( avrg_H1, 1 ) ) ) || ( LT_32( Mult_32_32( L_shl( peak_l, exp ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( L_tmp, exp ), L_shl( avrg_l, exp1 ) ) ) || GT_32( Mult_32_32( L_shl( L_tmp1, exp2 ), L_shl( avrg_h, exp1 ) ), Mult_32_32( L_shl( peak_h, exp2 ), L_shl( avrg_l, exp1 ) ) ) ) )
#else
IF( GT_32( Mult_32_16( gain3, 27307 ), gain2 ) || ( GE_32( gain3, Mult_32_16( gain2, 26214 ) ) && GT_32( peak_H1, L_shl_o( avrg_H1, 1, &Overflow ) ) ) || ( LT_32( Mult_32_32( L_shl_o( peak_l, exp, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( L_tmp, exp, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) || GT_32( Mult_32_32( L_shl_o( L_tmp1, exp2, &Overflow ), L_shl_o( avrg_h, exp1, &Overflow ) ), Mult_32_32( L_shl_o( peak_h, exp2, &Overflow ), L_shl_o( avrg_l, exp1, &Overflow ) ) ) ) )
#endif
{
condition3 = 1;
move16();
......@@ -989,7 +1005,11 @@ Word16 mdct_classifier_ivas_fx(
test();
test();
#ifdef ISSUE_1867_replace_overflow_libenc
IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_sat( gain1_tmp, 1 ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_sat( gain2_tmp, 1 ) ) ) ) )
#else
IF( ( EQ_16( hTcxEnc->clas_final_old, HQ_CORE ) || EQ_16( hTcxEnc->clas_final_old, TCX_20_CORE ) ) && ( ( GT_32( hTcxEnc->last_gain1, L_shr( gain1_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain1, L_shl_o( gain1_tmp, 1, &Overflow ) ) ) && ( GT_32( hTcxEnc->last_gain2, L_shr( gain2_tmp, 1 ) ) && LT_32( hTcxEnc->last_gain2, L_shl_o( gain2_tmp, 1, &Overflow ) ) ) ) )
#endif
{
clas_final = hTcxEnc->clas_final_old;
move16();
......
......@@ -41,9 +41,11 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity
Word32 L_acc;
Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum;
Word16 mean_dyn;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*------------------------------------------------------------------*
......@@ -212,7 +214,11 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity
IF( EQ_16( i, ind_mins[k] ) )
{
/* include the last peak point (new minimum) to the corr. sum */
#ifdef ISSUE_1867_replace_overflow_libenc
Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] );
#else
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
#endif
/* calculation of the norm. peak correlation */
test();
......@@ -263,9 +269,15 @@ Word16 multi_harm_fx( /* o : frame multi-harmonicity
k++;
}
#ifdef ISSUE_1867_replace_overflow_libenc
Lcorx2 = L_mac_sat( Lcorx2, S[i], S[i] );
Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] );
Lcorxy = L_mac_sat( Lcorxy, S[i], old_S[i] );
#else
Lcorx2 = L_mac_o( Lcorx2, S[i], S[i], &Overflow );
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
Lcorxy = L_mac_o( Lcorxy, S[i], old_S[i], &Overflow );
#endif
}
Copy( S, old_S, ind_mins[0] );
......@@ -384,9 +396,11 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni
Word32 L_acc;
Word32 Lcorx2, Lcory2, Lcorxy, Lcor_map_LT_sum;
Word16 mean_dyn;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*------------------------------------------------------------------*
......@@ -549,7 +563,11 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni
IF( EQ_16( i, ind_mins[k] ) )
{
/* include the last peak point (new minimum) to the corr. sum */
#ifdef ISSUE_1867_replace_overflow_libenc
Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] );
#else
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
#endif
/* calculation of the norm. peak correlation */
test();
......@@ -600,9 +618,15 @@ Word16 multi_harm_ivas_fx( /* o : frame multi-harmoni
k++;
}
#ifdef ISSUE_1867_replace_overflow_libenc
Lcorx2 = L_mac_sat( Lcorx2, S[i], S[i] );
Lcory2 = L_mac_sat( Lcory2, old_S[i], old_S[i] );
Lcorxy = L_mac_sat( Lcorxy, S[i], old_S[i] );
#else
Lcorx2 = L_mac_o( Lcorx2, S[i], S[i], &Overflow );
Lcory2 = L_mac_o( Lcory2, old_S[i], old_S[i], &Overflow );
Lcorxy = L_mac_o( Lcorxy, S[i], old_S[i], &Overflow );
#endif
}
Copy( S, old_S, ind_mins[0] );
......
......@@ -354,9 +354,11 @@ void nelp_encoder_fx(
move32();
Word16 BP1_ORDER;
Word16 rf_flag;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
......@@ -422,7 +424,11 @@ void nelp_encoder_fx(
E1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
E1_fx = L_mac0_sat( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */
#else
E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */
#endif
}
qE1 = shl( qE1, 1 );
......@@ -438,7 +444,11 @@ void nelp_encoder_fx(
EL1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
EL1_fx = L_mac0_sat( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */
#else
EL1_fx = L_mac0_o( EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qIn) */
#endif
}
qEL1 = shl( qEL1, 1 );
......@@ -454,7 +464,11 @@ void nelp_encoder_fx(
EH1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
EH1_fx = L_mac0_sat( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */
#else
EH1_fx = L_mac0_o( EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qEH1) */
#endif
}
qEH1 = 2 * qEH1;
move16();
......@@ -470,7 +484,11 @@ void nelp_encoder_fx(
Ltemp = L_deposit_l( 0 );
FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */
#else
Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */
#endif
}
/*Gains[i] = (float) sqrt(Gains[i]/lag); */
......@@ -494,7 +512,11 @@ void nelp_encoder_fx(
Ltemp = L_deposit_l( 0 );
FOR( j = (Word16) ( i * lag ); j < L_FRAME; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */
#else
Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */
#endif
}
/*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */
......@@ -1099,9 +1121,11 @@ void nelp_encoder_ivas_fx(
move32();
Word16 BP1_ORDER;
Word16 rf_flag;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
SC_VBR_ENC_HANDLE hSC_VBR = st_fx->hSC_VBR;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
......@@ -1169,7 +1193,11 @@ void nelp_encoder_ivas_fx(
E1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
E1_fx = L_mac0_sat( E1_fx, in_fx[i], in_fx[i] ); /*Q(qE1+qE1) */
#else
E1_fx = L_mac0_o( E1_fx, in_fx[i], in_fx[i], &Overflow ); /*Q(qE1+qE1) */
#endif
}
qE1 = shl( qE1, 1 );
......@@ -1184,7 +1212,11 @@ void nelp_encoder_ivas_fx(
EL1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
EL1_fx = L_mac0_sat( EL1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qIn) */
#else
EL1_fx = L_mac0_o( EL1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qIn) */
#endif
}
qEL1 = shl( qEL1, 1 );
......@@ -1200,7 +1232,11 @@ void nelp_encoder_ivas_fx(
EH1_fx = L_deposit_l( 0 );
FOR( i = 0; i < L_FRAME; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
EH1_fx = L_mac0_sat( EH1_fx, filtRes_fx[i], filtRes_fx[i] ); /*Q(2*qEH1) */
#else
EH1_fx = L_mac0_o( EH1_fx, filtRes_fx[i], filtRes_fx[i], &Overflow ); /*Q(2*qEH1) */
#endif
}
qEH1 = shl( qEH1, 1 );
move16();
......@@ -1215,7 +1251,11 @@ void nelp_encoder_ivas_fx(
Ltemp = L_deposit_l( 0 );
FOR( j = (Word16) ( i * lag ); j < (Word16) ( ( i + 1 ) * lag ); j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */
#else
Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */
#endif
}
/*Gains[i] = (float) sqrt(Gains[i]/lag); */
......@@ -1239,7 +1279,11 @@ void nelp_encoder_ivas_fx(
Ltemp = L_deposit_l( 0 );
FOR( j = i_mult( i, lag ); j < L_FRAME; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Ltemp = L_mac0_sat( Ltemp, in_fx[j], in_fx[j] ); /*Q(2*qGain) */
#else
Ltemp = L_mac0_o( Ltemp, in_fx[j], in_fx[j], &Overflow ); /*Q(2*qGain) */
#endif
}
/*Gains[i] = (float) sqrt(Gains[i]/(L_FRAME-(lag*i))); */
......
......@@ -102,12 +102,16 @@ static Word16 noise_est_ln_q8_fx(
{
Word16 e_ener, f_ener;
Word32 L_tmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
L_tmp = L_add_o( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ), &Overflow ); /* +1.0f */
#else
L_tmp = L_add_sat( L_enr, L_shl( (Word32) 1L, q_new_plus_q_scale ) ); /* +1.0f */
#endif
if ( flag_add1p0 == 0 )
{
L_tmp = L_add( L_enr, 0 ); /* +0 , no offset */
......@@ -664,8 +668,10 @@ void noise_est_down_fx(
Word16 scale;
Word32 totalNoise_temp;
Word32 L_Etot, L_Etot_last, L_Etot_v_h2, L_Etot_v;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
L_Etot = L_shl( Etot, 16 ); /*Q24 for later AR1 computations*/
......@@ -681,7 +687,11 @@ void noise_est_down_fx(
totalNoise_temp = L_deposit_l( 0 );
FOR( i = min_band; i <= max_band; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
totalNoise_temp = L_add_sat( totalNoise_temp, bckr[i] ); /*Q_new+QSCALE*/
#else
totalNoise_temp = L_add_o( totalNoise_temp, bckr[i], &Overflow ); /*Q_new+QSCALE*/
#endif
}
totalNoise_temp = L_max( totalNoise_temp, L_shl( e_min, 4 ) );
......@@ -705,7 +715,11 @@ void noise_est_down_fx(
FOR( i = 0; i < NB_BANDS; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Ltmp = L_add_sat( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ) );
#else
Ltmp = L_add_o( L_shr_r( *pt1, 1 ), L_shr_r( *pt2, 1 ), &Overflow );
#endif
/*Ltmp = L_shr_r(L_add(*pt1,*pt2),1);*/
enr[i] = Ltmp;
move32(); /*Q_new+QSCALE*/
......@@ -1003,9 +1017,11 @@ void noise_est_fx(
}
GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*-----------------------------------------------------------------*
......@@ -1101,8 +1117,13 @@ void noise_est_fx(
Ltmp = L_deposit_h( corr_shift );
Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 );
#ifdef ISSUE_1867_replace_overflow_libenc
Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 );
wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 );
#else
Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow );
wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow );
#endif
tmp_pc = pc;
move16();
......@@ -1155,7 +1176,11 @@ void noise_est_fx(
FOR( i = 10; i <= st_fx->max_band; i++ )
{
Lnum = L_max( *pt1, *pt2 ); /* Don't need if anymore */
#ifdef ISSUE_1867_replace_overflow_libenc
Lsum_den = L_add_sat( Lsum_den, Lnum );
#else
Lsum_den = L_add_o( Lsum_den, Lnum, &Overflow );
#endif
Ltmpden = L_min( *pt1, *pt2 );
if ( Ltmpden == 0 )
{
......@@ -1271,7 +1296,11 @@ void noise_est_fx(
/* alpha = 0.064f * ftemp + 0.75f; */
Ltmp = Mult_32_16( (Word32) 137438953L, tmp ); /* Q31(.064)+Q8+1-16 --> Q24 */
Ltmp = L_mac( Ltmp, 256, 24576 ); /* Q8+Q15(.75)+1 --> Q24 */
#ifdef ISSUE_1867_replace_overflow_libenc
alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/
#else
alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/
#endif
/*if( alpha > 0.999f { alpha = 0.999f;} */
alpha = s_min( alpha, 32735 ); /*.999 in Q15*/
......@@ -1307,8 +1336,13 @@ void noise_est_fx(
/* tmp_enr = enr[i] + 1.0f; */
tmp_Q = add( Q_new, Q_SCALE );
Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp_enr = L_add_sat( enr[i], Ltmp ); /* enr scale dynamic */
L_tmp_ave_enr = L_add_sat( hNoiseEst->ave_enr_fx[i], Ltmp ); /* ave__enr scale dynamic */
#else
L_tmp_enr = L_add_o( enr[i], Ltmp, &Overflow ); /* enr scale dynamic */
L_tmp_ave_enr = L_add_o( hNoiseEst->ave_enr_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */
#endif
IF( LE_32( non_sta, th_sta ) ) /* Just to limit the saturation */
{
......@@ -1349,7 +1383,11 @@ void noise_est_fx(
/* ave_enr2:: calculation of another non-stationarity measure (following attacks) */
Ltmp = L_shl( (Word32) 1L, tmp_Q ); /* 1.0 added in the right dynamic domain */
/*L_tmp_enr = L_add(enr[i] , Ltmp );*/ /* enr scale dynamic , done above */
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp_ave_enr2 = L_add_sat( hNoiseEst->ave_enr2_fx[i], Ltmp ); /* ave__enr scale dynamic */
#else
L_tmp_ave_enr2 = L_add_o( hNoiseEst->ave_enr2_fx[i], Ltmp, &Overflow ); /* ave__enr scale dynamic */
#endif
IF( LE_32( Lnon_sta2, th_sta ) ) /* Just to limit the saturation */
{
Lnum = L_max( L_tmp_enr, L_tmp_ave_enr2 );
......@@ -1381,7 +1419,11 @@ void noise_est_fx(
/* log_enr = (float)ln_fx(enr[i]); */
log_enr16 = noise_est_ln_q8_fx( enr[i], 0, tmp_Q );
wtmp = abs_s( sub( log_enr16, hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] ) );
#ifdef ISSUE_1867_replace_overflow_libenc
*non_staX = add_sat( *non_staX, wtmp );
#else
*non_staX = add_o( *non_staX, wtmp, &Overflow );
#endif
move16(); /* Q8 */
hSpMusClas->past_log_enr_fx[i - START_BAND_SPMUS] = log_enr16;
move16();
......@@ -1397,7 +1439,11 @@ void noise_est_fx(
tmp_floor = LN_E_MIN_PLUS_ONE_FX;
move16(); /* non dynamic init constant in Q8 */
tmp_floor = noise_est_ln_q8_fx( hNoiseEst->bckr_fx[i], 1, tmp_Q );
#ifdef ISSUE_1867_replace_overflow_libenc
non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
#else
non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */
#endif
}
ELSE /*ini_frame < 100*/
{
......@@ -1406,7 +1452,11 @@ void noise_est_fx(
tmp_floor = LN_E_MIN_PLUS_ONE_FX;
move16(); /* non dynamic init constant in Q8 */
tmp_floor = noise_est_ln_q8_fx( E_MIN_FX, 1, tmp_Q );
#ifdef ISSUE_1867_replace_overflow_libenc
non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
#else
non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */
#endif
}
}
......@@ -1518,7 +1568,12 @@ void noise_est_fx(
Ltmp = eps_quota_fx( epsP_h[0], epsP_l[0],
epsP_h[2], epsP_l[2], 12 ); /* Word32 Q12 */
BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/
#ifdef ISSUE_1867_replace_overflow_libenc
epsP_0_2 = round_fx_sat( L_shl_sat( Ltmp, 16 ) );
/* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */
#else
epsP_0_2 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 , NB saturation in Q12 sets max value to 7,999 */
#endif
BASOP_SATURATE_WARNING_ON_EVS
epsP_0_2 = s_max( 0, epsP_0_2 ); /* min value is 0 , Q12 */
......@@ -1557,8 +1612,12 @@ void noise_est_fx(
Ltmp = eps_quota_fx( epsP_h[2], epsP_l[2],
epsP_h[16], epsP_l[16], 12 ); /* Word32 Q12 */
BASOP_SATURATE_WARNING_OFF_EVS /* may saturate*/
epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 ,
NB saturation in Q12 sets max value to 7,999 */
#ifdef ISSUE_1867_replace_overflow_libenc
epsP_2_16 = round_fx_sat( L_shl_sat( Ltmp, 16 ) ); /* Q12+16 -16 -> Q12 ,*/
#else
epsP_2_16 = round_fx_o( L_shl_o( Ltmp, 16, &Overflow ), &Overflow ); /* Q12+16 -16 -> Q12 ,*/
#endif
/*NB saturation in Q12 sets max value to 7,999 */
BASOP_SATURATE_WARNING_ON_EVS
epsP_2_16 = s_max( 0, epsP_2_16 ); /* min value is 0 , Q12 */
......@@ -1680,7 +1739,11 @@ void noise_est_fx(
*-----------------------------------------------------------------*/
Ltmp = L_mult( st_fx->voicing_fx[0], 16384 );
Ltmp = L_mac( Ltmp, st_fx->voicing_fx[1], 16384 );
#ifdef ISSUE_1867_replace_overflow_libenc
cor_tmp = mac_r_sat( Ltmp, corr_shift, MAX_16 );
#else
cor_tmp = mac_ro( Ltmp, corr_shift, MAX_16, &Overflow );
#endif
LepsP = eps_quota_fx( epsP_h[2], epsP_l[2],
epsP_h[16], epsP_l[16], 11 ); /* L_epsP in Q11 */
......@@ -2283,9 +2346,11 @@ void noise_est_ivas_fx(
Le_min_scaled = L_shl( E_MIN_FXQ31, sub( q_fr_bands, Q31 ) ); // q_fr_bands
GSC_ENC_HANDLE hGSCEnc = st_fx->hGSCEnc;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* Check if LR-VAD */
......@@ -2402,8 +2467,13 @@ void noise_est_ivas_fx(
Ltmp = L_deposit_h( corr_shift );
Ltmp = L_mac( Ltmp, st_fx->voicing_fx[0], 10923 );
#ifdef ISSUE_1867_replace_overflow_libenc
Ltmp = L_mac_sat( Ltmp, st_fx->voicing_fx[1], 10923 );
wtmp = mac_r_sat( Ltmp, st_fx->voicing_fx[2], 10923 );
#else
Ltmp = L_mac_o( Ltmp, st_fx->voicing_fx[1], 10923, &Overflow );
wtmp = mac_ro( Ltmp, st_fx->voicing_fx[2], 10923, &Overflow );
#endif
tmp_pc = pc;
move16();
......@@ -2615,7 +2685,11 @@ void noise_est_ivas_fx(
/* alpha = 0.064f * ftemp + 0.75f; */
Ltmp = Madd_32_16( 12582912 /* 0.75 in Q24*/, 137438953, tmp ); // Q24
#ifdef ISSUE_1867_replace_overflow_libenc
alpha = round_fx_sat( L_shl_sat( Ltmp, 7 ) ); /*Q24 +7 --> Q31 Q15*/
#else
alpha = round_fx_o( L_shl_o( Ltmp, 7, &Overflow ), &Overflow ); /*Q24 +7 --> Q31 Q15*/
#endif
/*if( alpha > 0.999f { alpha = 0.999f;} */
alpha = s_min( alpha, 32735 ); /*.999 in Q15*/
......@@ -2768,7 +2842,11 @@ void noise_est_ivas_fx(
IF( LT_16( ini_frame, 100 ) )
{
#ifdef ISSUE_1867_replace_overflow_libenc
non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ) ); /* Q8 */
#else
non_staB = add_o( non_staB, abs_s( sub( tmp_enr, LN_E_MIN_PLUS_ONE_FX ) ), &Overflow ); /* Q8 */
#endif
}
ELSE /*ini_frame < 100*/
{
......@@ -2790,7 +2868,11 @@ void noise_est_ivas_fx(
Ltmp1 = Mpy_32_16_1( Ltmp1, 22713 ); // Q15
tmp_floor = round_fx( L_shl( Ltmp1, 9 ) ); /* Q8 */
}
#ifdef ISSUE_1867_replace_overflow_libenc
non_staB = add_sat( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ) ); /* Q8 */
#else
non_staB = add_o( non_staB, abs_s( sub( tmp_enr, tmp_floor ) ), &Overflow ); /* Q8 */
#endif
}
}
......
......@@ -29,9 +29,11 @@ void normalizecoefs_fx(
Word16 *pcoefs16;
Word32 *pcoefs;
Word16 subvec_start, subvec_end, num_coefs;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
pcoefs = coefs;
pcoefs16 = coefs_norm;
......@@ -55,7 +57,11 @@ void normalizecoefs_fx(
*pcoefs = Mpy_32_16_1( *pcoefs, INV2POWHALF );
move32();
}
#ifdef ISSUE_1867_replace_overflow_libenc
*pcoefs16++ = round_fx_sat( L_shl_sat( *pcoefs++, 16 - k ) ); /* Q12 */
#else
*pcoefs16++ = round_fx_o( L_shl_o( *pcoefs++, 16 - k, &Overflow ), &Overflow ); /* Q12 */
#endif
move16();
}
}
......
......@@ -964,9 +964,11 @@ void norm_corr_ivas_fx(
Word16 h_e, e_max;
Word32 L_tmp;
Word64 W_tmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
k = negate( t_min );
......@@ -989,7 +991,11 @@ void norm_corr_ivas_fx(
L_tmp = L_mac( 0, xn[0], excf[0] );
FOR( i = 1; i < L_subfr; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac_sat( L_tmp, xn[i], excf[i] ); // (Q_new - 1) + (Q_new - h_e) + 1
#else
L_tmp = L_mac_o( L_tmp, xn[i], excf[i], &Overflow ); // (Q_new - 1) + (Q_new - h_e) + 1
#endif
}
exp = norm_l( L_tmp );
L_tmp = L_shl( L_tmp, exp );
......@@ -1060,9 +1066,11 @@ void norm_corr_fx(
Word16 corr, exp_corr, norm, exp_norm, exp, scale;
Word16 excf[L_FRAME16k];
Word32 L_tmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
k = negate( t_min );
......@@ -1074,10 +1082,18 @@ void norm_corr_fx(
conv_fx( &exc[k], h, excf, L_subfr );
/* Compute rounded down 1/sqrt(energy of xn[]) */
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac_sat( 1, xn[0], xn[0] );
#else
L_tmp = L_mac_o( 1, xn[0], xn[0], &Overflow );
#endif
FOR( i = 1; i < L_subfr; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac_sat( L_tmp, xn[i], xn[i] );
#else
L_tmp = L_mac_o( L_tmp, xn[i], xn[i], &Overflow );
#endif
}
exp = norm_l( L_tmp );
exp = sub( 30, exp );
......@@ -1096,7 +1112,11 @@ void norm_corr_fx(
L_tmp = L_mac( 1, xn[0], excf[0] );
FOR( i = 1; i < L_subfr; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac_sat( L_tmp, xn[i], excf[i] );
#else
L_tmp = L_mac_o( L_tmp, xn[i], excf[i], &Overflow );
#endif
}
exp = norm_l( L_tmp );
L_tmp = L_shl( L_tmp, exp );
......@@ -1107,7 +1127,11 @@ void norm_corr_fx(
L_tmp = L_mac( 1, excf[0], excf[0] );
FOR( i = 1; i < L_subfr; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac_sat( L_tmp, excf[i], excf[i] );
#else
L_tmp = L_mac_o( L_tmp, excf[i], excf[i], &Overflow );
#endif
}
exp = norm_l( L_tmp );
......
......@@ -50,9 +50,11 @@ void pitch_ol2_fx(
Word32 R1, R2;
Word16 R0, exp_R0, exp_R1, exp_R2, j;
Word16 pit_max;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* initialization */
......@@ -82,8 +84,13 @@ void pitch_ol2_fx(
pt_cor_fx = cor_fx;
FOR( t = t_min; t <= t_max; t++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
t0 = L_shl_sat( *pt_cor_32++, exp3 );
*pt_cor_fx++ = round_fx_sat( t0 );
#else
t0 = L_shl_o( *pt_cor_32++, exp3, &Overflow );
*pt_cor_fx++ = round_fx_o( t0, &Overflow );
#endif
move16();
}
......@@ -189,7 +196,11 @@ void pitch_ol2_fx(
exp_R2 = norm_l( R2 );
R2 = L_shl( R2, exp_R2 );
#ifdef ISSUE_1867_replace_overflow_libenc
R1 = L_mult_sat( round_fx_sat( R1 ), round_fx_sat( R2 ) );
#else
R1 = L_mult_o( round_fx_o( R1, &Overflow ), round_fx_o( R2, &Overflow ), &Overflow );
#endif
i = norm_l( R1 );
R1 = L_shl( R1, i );
......@@ -199,11 +210,19 @@ void pitch_ol2_fx(
R1 = Isqrt_lc( R1, &exp_R1 );
#ifdef ISSUE_1867_replace_overflow_libenc
R1 = L_mult( R0, round_fx_sat( R1 ) );
#else
R1 = L_mult( R0, round_fx_o( R1, &Overflow ) );
#endif
exp_R0 = sub( 31, exp_R0 );
exp_R0 = sub( add( exp_R0, exp_R1 ), exp3 );
#ifdef ISSUE_1867_replace_overflow_libenc
*voicing_fr_fx = round_fx_sat( L_shl_sat( R1, exp_R0 ) ); /*Q15*/
#else
*voicing_fr_fx = round_fx_o( L_shl_o( R1, exp_R0, &Overflow ), &Overflow ); /*Q15*/
#endif
move16();
}
ELSE
......@@ -243,9 +262,11 @@ void StableHighPitchDetect_fx(
Word16 tmp, tmp1, exp, diff16, cor_max16, exp1, exp2, pit_min_up;
Word32 L_tmp, L_tmp1;
Word16 Top;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/
......@@ -295,21 +316,35 @@ void StableHighPitchDetect_fx(
tmp = div_s( 16384, tmp ); /*Q(15+exp)*/
BASOP_SATURATE_WARNING_OFF_EVS
diff = L_negate( L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ) );
#ifdef ISSUE_1867_replace_overflow_libenc
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_sat( diff );
#else
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_o( diff, &Overflow );
#endif
}
ELSE
{
tmp = div_s( 16384, tmp ); /*Q(15+exp)*/
BASOP_SATURATE_WARNING_OFF_EVS
diff = L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) );
#ifdef ISSUE_1867_replace_overflow_libenc
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_sat( diff );
#else
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_o( diff, &Overflow );
#endif
}
}
ELSE
{
#ifdef ISSUE_1867_replace_overflow_libenc
diff16 = round_fx_sat( L_shl_sat( diff, 25 ) );
#else
diff16 = round_fx_o( L_shl_o( diff, 25, &Overflow ), &Overflow );
#endif
}
test();
test();
......@@ -386,7 +421,11 @@ void StableHighPitchDetect_fx(
L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp)*/
cor_max = Mult_32_32( cor_max, L_tmp1 );
exp = 31 - ( shl( Q_new, 1 ) + 1 ) - ( 31 - exp ) + 31;
#ifdef ISSUE_1867_replace_overflow_libenc
cor_max16 = round_fx_sat( L_shl_sat( cor_max, exp ) ); /*Q15*/
#else
cor_max16 = round_fx_o( L_shl_o( cor_max, exp, &Overflow ), &Overflow ); /*Q15*/
#endif
/**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/
*voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) );
move16();
......@@ -451,9 +490,11 @@ void StableHighPitchDetect_ivas_fx(
Word16 tmp, tmp1, exp, diff16, cor_max16, exp1, exp2, pit_min_up;
Word32 L_tmp, L_tmp1;
Word16 Top;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*voicing = (voicing[0] + voicing[1] + voicing[2] )/3;*/
......@@ -510,21 +551,35 @@ void StableHighPitchDetect_ivas_fx(
tmp = div_s( 16384, tmp ); /*Q(15+exp)*/
BASOP_SATURATE_WARNING_OFF_EVS
diff = L_negate( L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) ) );
#ifdef ISSUE_1867_replace_overflow_libenc
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_sat( diff );
#else
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_o( diff, &Overflow );
#endif
}
ELSE
{
tmp = div_s( 16384, tmp ); /*Q(15+exp)*/
BASOP_SATURATE_WARNING_OFF_EVS
diff = L_shr_sat( Mult_32_16( diff, tmp ), sub( exp + 7, 31 ) );
#ifdef ISSUE_1867_replace_overflow_libenc
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_sat( diff );
#else
BASOP_SATURATE_WARNING_ON_EVS
diff16 = round_fx_o( diff, &Overflow );
#endif
}
}
ELSE
{
#ifdef ISSUE_1867_replace_overflow_libenc
diff16 = round_fx_sat( L_shl_sat( diff, 25 ) );
#else
diff16 = round_fx_o( L_shl_o( diff, 25, &Overflow ), &Overflow );
#endif
}
test();
test();
......@@ -610,7 +665,11 @@ void StableHighPitchDetect_ivas_fx(
L_tmp1 = Isqrt_lc( L_tmp1, &exp ); /*Q(31-exp)*/
cor_max = Mult_32_32( cor_max, L_tmp1 );
exp = add( sub( sub( 31, add( shl( Q_new, 1 ), 1 ) ), sub( 31, exp ) ), 31 );
#ifdef ISSUE_1867_replace_overflow_libenc
cor_max16 = round_fx_sat( L_shl_sat( cor_max, exp ) ); /*Q15*/
#else
cor_max16 = round_fx_o( L_shl_o( cor_max, exp, &Overflow ), &Overflow ); /*Q15*/
#endif
/**voicing0_sm = add(mult_r(24576 ,(*voicing0_sm)) , mult_r(8192 , cor_max16));*/
*voicing0_sm = round_fx( L_mac( L_mult( 24576 /*.75f Q15*/, *voicing0_sm ), 8192 /*.25f Q15*/, cor_max16 ) );
move16();
......
......@@ -183,8 +183,10 @@ void pitch_ol_fx(
const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1;
Word16 pit_min_coding;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
/*--------------------------------------------------------------*
......@@ -737,7 +739,11 @@ void pitch_ol_fx(
enr1_exp = 0;
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
enr1 = add_sat( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1 );
#else
enr1 = add_o( extract_h( dotp_fx( pt2, pt2, len[j], &enr1_exp ) ), 1, &Overflow );
#endif
enr2 = L_mult( enr0[j], enr1 );
enr2_exp = norm_l( enr2 );
......@@ -773,7 +779,11 @@ void pitch_ol_fx(
move16(); /* selected moving vector */
enr1_exp = 0;
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
enr1 = add_sat( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1 );
#else
enr1 = add_o( extract_h( dotp_fx( pt4, pt4, len1[j], &enr1_exp ) ), 1, &Overflow );
#endif
enr2 = L_mult( enr0_1[j], enr1 );
enr2_exp = norm_l( enr2 );
......@@ -868,7 +878,11 @@ void pitch_ol_fx(
move16();
pitch_tmp[i] = pitchX[i][ind];
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
cor_tmp[i] = add_sat( corX[i][ind], corr_shift );
#else
cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow );
#endif
move16();
/* Higher is the neighbour's correlation, higher is the weighting */
......@@ -882,7 +896,11 @@ void pitch_ol_fx(
move16();
pitch_tmp[i + NHFR] = pitchX[i][ind1];
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift );
#else
cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow );
#endif
move16();
/* Higher is the neighbour's correlation, higher is the weighting */
......@@ -1103,8 +1121,10 @@ void pitch_ol_ivas_fx(
const Word16 *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1;
Word16 pit_min_coding;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
Word16 new_q;
new_q = sub( 63, shl( qwsp, 1 ) );
......@@ -1707,7 +1727,12 @@ void pitch_ol_ivas_fx(
enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr2_exp*/
Ltmp = Mpy_32_16_1( enr1, cor_buf[ind] );
#ifdef ISSUE_1867_replace_overflow_libenc
corX[i][j] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind] ) ) ); // Q15
#else
corX[i][j] = extract_h( L_shl_o( Ltmp, add( enr1_exp, cor_buf_exp[ind] ), &Overflow ) ); // Q15
#endif
move16();
Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind] );
......@@ -1750,7 +1775,11 @@ void pitch_ol_ivas_fx(
enr1 = ISqrt32( enr1, &enr1_exp ); /* 1/sqrt(energy) */ /*31-enr1_exp*/
Ltmp = Mpy_32_16_1( enr1, cor_buf[ind1 + len_x] );
#ifdef ISSUE_1867_replace_overflow_libenc
corX[i][j + NSECT] = extract_h( L_shl_sat( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ) ) ); // Q15
#else
corX[i][j + NSECT] = extract_h( L_shl_o( Ltmp, add( enr1_exp, cor_buf_exp[ind1 + len_x] ), &Overflow ) ); // Q15
#endif
move16();
Ltmp = Mpy_32_16_1( enr1, pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x] );
......@@ -1827,7 +1856,11 @@ void pitch_ol_ivas_fx(
move16();
pitch_tmp[i] = pitchX[i][ind];
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
cor_tmp[i] = add_sat( corX[i][ind], corr_shift );
#else
cor_tmp[i] = add_o( corX[i][ind], corr_shift, &Overflow );
#endif
move16();
/* Higher is the neighbour's correlation, higher is the weighting */
......@@ -1841,7 +1874,11 @@ void pitch_ol_ivas_fx(
move16();
pitch_tmp[i + NHFR] = pitchX[i][ind1];
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
cor_tmp[i + NHFR] = add_sat( corX[i][ind1], corr_shift );
#else
cor_tmp[i + NHFR] = add_o( corX[i][ind1], corr_shift, &Overflow );
#endif
move16();
/* Higher is the neighbour's correlation, higher is the weighting */
......
......@@ -622,9 +622,11 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X
Word16 n, fshift_fx, HalfLag, ab1[MAXLAG_WI], ab2[MAXLAG_WI];
Word32 corr_fx;
Word32 maxcorr_fx, wcorr_fx, diff_corr;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
IF( LT_16( X1_fx.lag_fx, X2_fx.lag_fx ) )
{
......@@ -663,9 +665,15 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X
FOR( k = 0; k <= HalfLag; k++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
corr_fx = L_mac_sat( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )] );
corr_fx = L_mac_sat( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )] );
temp = add_sat( temp, temp1 );
#else
corr_fx = L_mac_o( corr_fx, ab1[k], C_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow );
corr_fx = L_mac_o( corr_fx, ab2[k], S_fx[temp % ( 4 * X2_fx.lag_fx )], &Overflow );
temp = add_o( temp, temp1, &Overflow );
#endif
}
temp = sub( 32767, extract_l( L_shr( L_mult( 82, abs_s( n ) ), 1 ) ) ); /* Q15 */
Qcorr = norm_l( corr_fx );
......@@ -675,23 +683,40 @@ static Word16 DTFS_alignment_fine_new_fx( DTFS_STRUCTURE X1_fx, DTFS_STRUCTURE X
move16();
}
#ifdef ISSUE_1867_replace_overflow_libenc
temp1 = round_fx_sat( (Word32) L_shl_sat( corr_fx, Qcorr ) ); /* Q(Qcorr-16) */
wcorr_fx = L_mult_sat( temp1, temp ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */
#else
temp1 = round_fx_o( (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ), &Overflow ); /* Q(Qcorr-16) */
wcorr_fx = L_mult_o( temp1, temp, &Overflow ); /* Q(Qcorr-16+15+1)=Q(Qcorr) */
#endif
IF( GE_16( Qmaxcorr, Qcorr ) )
{
#ifdef ISSUE_1867_replace_overflow_libenc
diff_corr = L_sub_sat( wcorr_fx, L_shl_sat( maxcorr_fx, sub( Qcorr, Qmaxcorr ) ) ); /* Qcorr */
#else
diff_corr = L_sub_o( wcorr_fx, L_shl_o( maxcorr_fx, sub( Qcorr, Qmaxcorr ), &Overflow ), &Overflow ); /* Qcorr */
#endif
}
ELSE
{
#ifdef ISSUE_1867_replace_overflow_libenc
diff_corr = L_sub_sat( L_shl_sat( wcorr_fx, sub( Qmaxcorr, Qcorr ) ), maxcorr_fx ); /* Qmaxcorr */
#else
diff_corr = L_sub_o( L_shl_o( wcorr_fx, sub( Qmaxcorr, Qcorr ), &Overflow ), maxcorr_fx, &Overflow ); /* Qmaxcorr */
#endif
}
if ( diff_corr > 0 )
{
fshift_fx = n;
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
maxcorr_fx = (Word32) L_shl_sat( corr_fx, Qcorr ); /* Qcorr */
#else
maxcorr_fx = (Word32) L_shl_o( corr_fx, Qcorr, &Overflow ); /* Qcorr */
#endif
Qmaxcorr = Qcorr;
move16();
}
......@@ -739,9 +764,11 @@ static void LPCPowSpect_fx(
Word32 Ltemp, Lw;
Word32 Lacc;
Word16 tmp, exp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
FOR( k = 0; k < Nf; k++ )
{
......@@ -773,9 +800,15 @@ static void LPCPowSpect_fx(
t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */
Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */
#ifdef ISSUE_1867_replace_overflow_libenc
Re = L_add_sat( Re, Ltemp ); /* Re=1-sum(LPC[i]*cos(Lw)); */
Ltemp = L_add_sat( Lw, 0x6000 ); /* add 0.75, which is 3pi/2 to convert sin to cos */
Ltemp = L_shl_sat( Ltemp, 10 ); /* Q25 */
#else
Re = L_add_o( Re, Ltemp, &Overflow ); /* Re=1-sum(LPC[i]*cos(Lw)); */
Ltemp = L_add_o( Lw, 0x6000, &Overflow ); /* add 0.75, which is 3pi/2 to convert sin to cos */
Ltemp = L_shl_o( Ltemp, 10, &Overflow ); /* Q25 */
#endif
w = extract_h( Ltemp ); /* w is equivalent cos index */
dl = extract_l( Ltemp ); /* dl is 6 bit left-over for interpolation */
w = s_and( w, 511 );
......@@ -797,8 +830,13 @@ static void LPCPowSpect_fx(
t1 = add( t1, (Word16) L_shr( Ltemp, 16 ) ); /* t1 is interpolated cos(w) */
Ltemp = L_shr( L_mult( LPC[i], t1 ), 1 ); /* Ltemp in Q27 */
#ifdef ISSUE_1867_replace_overflow_libenc
Im = L_sub_sat( Im, Ltemp ); /* Im=sum(LPC[i]*sin(Lw)) */
Lw = L_add_sat( Lw, freq[k] ); /* Lw=(i+1)*freq[k] */
#else
Im = L_sub_o( Im, Ltemp, &Overflow ); /* Im=sum(LPC[i]*sin(Lw)) */
Lw = L_add_o( Lw, freq[k], &Overflow ); /* Lw=(i+1)*freq[k] */
#endif
}
/* If necessary, we can block-normalize Re and Im to improve precision */
dh = extract_h( Re );
......@@ -813,7 +851,11 @@ static void LPCPowSpect_fx(
ELSE
Lacc = L_mult0( dh, dl );
#ifdef ISSUE_1867_replace_overflow_libenc
Lacc = L_add_sat( L_shr( Lacc, 15 ), L_shr( L_mult_sat( dh, dh ), 1 ) ); /* Lacc=Re*Re */
#else
Lacc = L_add_o( L_shr( Lacc, 15 ), L_shr( L_mult_o( dh, dh, &Overflow ), 1 ), &Overflow ); /* Lacc=Re*Re */
#endif
dh = extract_h( Im );
dl = extract_l( Im );
......@@ -844,7 +886,11 @@ static void LPCPowSpect_fx(
move16();
}
Ltemp = L_deposit_h( tmp );
#ifdef ISSUE_1867_replace_overflow_libenc
out[k] = round_fx_sat( L_shl_sat( Ltemp, negate( add( exp, 8 ) ) ) );
#else
out[k] = round_fx_o( L_shl_o( Ltemp, negate( add( exp, 8 ) ), &Overflow ), &Overflow );
#endif
move16();
/* out[k] = shl(tmp,-exp-8); in Q7 */
......
......@@ -60,9 +60,11 @@ static Word16 one_pulse_search(
UWord32 UL_left_l, UL_right_l, UL_dummy;
Word32 L_tmp;
UWord16 u_sgn;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
en_tmp = en_dn_shift; /* dummy assignment to avoid compiler warning for unused parameter */
......@@ -85,8 +87,13 @@ static Word16 one_pulse_search(
FOR( i = 0; i < dim; i++ ) /* FOR 3 ops */
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp_corr = L_shl_sat( L_mac_sat( *L_xy_ptr, 1, x_abs[i] ), corr_up_shift ); /* actual in-loop target value, 2 ops */
corr_tmp = round_fx_sat( L_tmp_corr ); /* 1 op */
#else
L_tmp_corr = L_shl_o( L_mac_o( *L_xy_ptr, 1, x_abs[i], &Overflow ), corr_up_shift, &Overflow ); /* actual in-loop target value, 2 ops */
corr_tmp = round_fx_o( L_tmp_corr, &Overflow ); /* 1 op */
#endif
corr_sq_tmp = mult( corr_tmp, corr_tmp ); /* CorrSq, is a 16bit for low compelxity cross multiplication 1 op */
L_tmp_en_lc = L_mac( *L_yy_ptr, 1, y[i] ); /*Q1 result , energy may span up to ~14+1(Q1)+1(sign)=16 bits, 1 op */
......@@ -202,9 +209,11 @@ void pvq_encode_ivas_fx(
Word16 neg_gain_norm, shift_tot;
Word16 high_pulse_density_flag;
PvqEntry entry;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
L_proj_fac = 4096;
......@@ -359,8 +368,13 @@ void pvq_encode_ivas_fx(
}
Mpy_32_16_ss( L_isqrt, tmp, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) +1 */
Mpy_32_16_ss( L_tmp, neg_gain_norm, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) *Q15 +1 */
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */
xq[i] = round_fx_sat( L_tmp ); /* Q15, array move */
#else
L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */
xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */
#endif
move16();
L_xq[i] = L_tmp; /* Q31 currently unused */
move32();
......@@ -410,9 +424,11 @@ void pvq_encode_fx(
Word16 neg_gain_norm, shift_tot;
Word16 high_pulse_density_flag;
PvqEntry entry;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
L_proj_fac = 4096;
......@@ -567,8 +583,13 @@ void pvq_encode_fx(
}
Mpy_32_16_ss( L_isqrt, tmp, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) +1 */
Mpy_32_16_ss( L_tmp, neg_gain_norm, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) *Q15 +1 */
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */
xq[i] = round_fx_sat( L_tmp ); /* Q15, array move */
#else
L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */
xq[i] = round_fx_o( L_tmp, &Overflow ); /* Q15, array move */
#endif
move16();
L_xq[i] = L_tmp; /* Q31 currently unused */
move32();
......
......@@ -145,10 +145,12 @@ static Word16 gain_enc( /* o : quantization pitch index
const Word16 *p;
const Word16 *t_qua_gain;
Word32 L_tmp, dist_min, L_tmp1;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
assert( ( func_type != FUNC_GAIN_ENC_UV ) && ( func_type != FUNC_GAIN_ENC_GACELP_UV ) );
......@@ -165,7 +167,11 @@ static Word16 gain_enc( /* o : quantization pitch index
/* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */
L_tmp = calc_gain_inov( code, lcode, &L_tmp1, &exp_L_tmp1 );
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
*gain_inov = round_fx_sat( L_shl_sat( L_tmp, 15 - 3 ) ); /* gain_inov in Q12 */
#else
*gain_inov = round_fx_o( L_shl_o( L_tmp, 15 - 3, &Overflow ), &Overflow ); /* gain_inov in Q12 */
#endif
move16();
/*----------------------------------------------------------------*
* calculate the predicted gain code
......@@ -377,7 +383,11 @@ static Word16 gain_enc( /* o : quantization pitch index
/* Here, we use L_mult0 to compensate the factor 0.5 applied to coeff[1..4] before */
L_tmp = L_add( L_tmp, L_shr( L_mult0( p[2 * i + 0], p[2 * i + 0] ), shr_coeff0 ) );
L_tmp = L_sub( L_tmp, L_shr( L_mult( p[2 * i + 0], coeff1 ), shr_coeff1 ) );
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp1 = L_sub_sat( L_tmp, dist_min );
#else
L_tmp1 = L_sub_o( L_tmp, dist_min, &Overflow );
#endif
BASOP_SATURATE_WARNING_ON_EVS
if ( L_tmp1 < 0 )
{
......@@ -397,13 +407,21 @@ static Word16 gain_enc( /* o : quantization pitch index
L_tmp = L_mult( g_code, gcode0 ); /* Q11*Q15 -> Q27 */
exp_gcode0 = add( exp_gcode0, -11 );
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_shl_sat( L_tmp, exp_gcode0 ); /* Q27 -> Q16 */
#else
L_tmp = L_shl_o( L_tmp, exp_gcode0, &Overflow ); /* Q27 -> Q16 */
#endif
*gain_code = L_tmp;
move32();
/* Q16/Q12 => Q5 */
L_tmp = L_deposit_h( BASOP_Util_Divide3216_Scale( L_tmp, *gain_inov, &i ) );
#ifdef ISSUE_1867_replace_overflow_libenc
*past_gcode = L_shl_sat( L_tmp, sub( i, 15 - 12 ) );
#else
*past_gcode = L_shl_o( L_tmp, sub( i, 15 - 12 ), &Overflow );
#endif
move16();
return index;
......@@ -436,9 +454,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind
Word16 index2;
const Word16 log2_scale = 16;
move16();
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
pred_nrg_frame = 0; /* to suppress compilation warnings */
g_code2 = 0; /* to suppress compilation warnings */
......@@ -595,7 +615,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind
}
s1 = norm_l( *gain_code );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp1 = round_fx_sat( L_shl( *gain_code, s1 ) );
#else
tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow );
#endif
s1 = sub( 15, s1 );
tmp1 = mult_r( mult_r( tmp1, tmp1 ), g_coeff->y2y2 );
......@@ -608,7 +632,11 @@ Word16 gain_enc_uv_fx( /* o : quantization pitch ind
L_tmp1 = L_add( L_tmp, 0 );
s1 = norm_l( *gain_code );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp1 = round_fx_sat( L_shl( *gain_code, s1 ) );
#else
tmp1 = round_fx_o( L_shl_o( *gain_code, s1, &Overflow ), &Overflow );
#endif
s1 = sub( 15, s1 );
c_index2 = 0x7FFF;
......
......@@ -399,9 +399,11 @@ void Unified_weighting_fx(
Word16 nf_fx;
Word32 Bin_Ener_160_fx[160];
const Word32 *Freq_w_Table_fx, *Bin_Ener_fx;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*Config. weighting*/
......@@ -441,7 +443,11 @@ void Unified_weighting_fx(
L_tmp = L_deposit_l( 0 );
FOR( i = 95; i < 127; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_add_sat( L_tmp, Bin_Ener_160_fx[i] ); /* Q_ener */
#else
L_tmp = L_add_o( L_tmp, Bin_Ener_160_fx[i], &Overflow ); /* Q_ener */
#endif
}
L_tmp = L_shr( L_tmp, 5 );
......@@ -522,7 +528,11 @@ void Unified_weighting_fx(
}
ELSE
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_shl_sat( L_deposit_l( sub_sat( w_fft_fx[i], min_fx ) ), 13 ); /* Q21 */
#else
L_tmp = L_shl_o( L_deposit_l( sub_o( w_fft_fx[i], min_fx, &Overflow ) ), 13, &Overflow ); /* Q21 */
#endif
exp = norm_l( L_tmp );
frac = round_fx( L_shl( L_tmp, exp ) );
exp = sub( add( exp, 21 ), 30 );
......
......@@ -86,9 +86,11 @@ void Preemph_scaled(
Word16 mu, shift, QVal;
Word32 L_tmp, L_maxloc;
Word16 Q_min;
#if !defined( ISSUE_1867_replace_overflow_libenc )
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/*---------------------------------------------------------------*
......@@ -97,8 +99,13 @@ void Preemph_scaled(
*---------------------------------------------------------------*/
BASOP_SATURATE_WARNING_OFF_EVS
#ifdef ISSUE_1867_replace_overflow_libenc
QVal = shl_sat( 1, sub( 15, bits ) ); //?sat
#else
Overflow = 0;
QVal = shl_sat( 1, sub( 15, bits ) );
#endif
BASOP_SATURATE_WARNING_ON_EVS
mu = shr( Preemph_factor, bits ); /* Q15 --> Q(15-bits) */
......@@ -115,7 +122,11 @@ void Preemph_scaled(
/* Equivalent to tmp = max((abs(x[i] - mu*x[i-1]),tmp)
* finds the max of preemphasized signal */
L_tmp = L_mult( new_speech[i], QVal );
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_msu_sat( L_tmp, new_speech[i - 1], mu );
#else
L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow );
#endif
L_tmp = L_abs( L_tmp );
L_maxloc = L_max( L_tmp, L_maxloc );
}
......@@ -165,7 +176,11 @@ void Preemph_scaled(
FOR( i = sub( Lframe, 1 ); i > 0; i-- )
{
L_tmp = L_mult( new_speech[i], QVal );
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_msu_sat( L_tmp, new_speech[i - 1], mu );
#else
L_tmp = L_msu_o( L_tmp, new_speech[i - 1], mu, &Overflow );
#endif
L_tmp = L_shl( L_tmp, *Q_new );
new_speech[i] = round_fx_sat( L_tmp ); // Q_new
}
......@@ -198,8 +213,10 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled
{
Word16 i;
Word32 e_min_scaled;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
#endif
#endif
e_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE ) ) ), 1 ), 1 );
......@@ -229,12 +246,21 @@ Word32 Scale_mem_pre_proc( /* o : Min energy scaled
/* Do scaling and valide minimum energy value */
FOR( i = 0; i < NB_BANDS; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
enrO[i] = L_max( L_shl_sat( enrO[i], Q_exp ), e_min_scaled );
bckr[i] = L_max( L_shl_sat( bckr[i], Q_exp ), e_min_scaled );
ave_enr[i] = L_max( L_shl_sat( ave_enr[i], Q_exp ), e_min_scaled );
ave_enr2[i] = L_max( L_shl_sat( ave_enr2[i], Q_exp ), e_min_scaled );
st_fr_bands1[i] = L_max( L_shl_sat( st_fr_bands1[i], Q_exp ), e_min_scaled );
st_fr_bands2[i] = L_max( L_shl_sat( st_fr_bands2[i], Q_exp ), e_min_scaled );
#else
enrO[i] = L_max( L_shl_o( enrO[i], Q_exp, &Overflow ), e_min_scaled );
bckr[i] = L_max( L_shl_o( bckr[i], Q_exp, &Overflow ), e_min_scaled );
ave_enr[i] = L_max( L_shl_o( ave_enr[i], Q_exp, &Overflow ), e_min_scaled );
ave_enr2[i] = L_max( L_shl_o( ave_enr2[i], Q_exp, &Overflow ), e_min_scaled );
st_fr_bands1[i] = L_max( L_shl_o( st_fr_bands1[i], Q_exp, &Overflow ), e_min_scaled );
st_fr_bands2[i] = L_max( L_shl_o( st_fr_bands2[i], Q_exp, &Overflow ), e_min_scaled );
#endif
move32();
move32();
move32();
......
......@@ -65,9 +65,11 @@ void set_impulse_fx(
Word16 krit_fx, krit_max_fx, gain16;
Word32 Lrr, Ldd, Ltmp, Ltmp1;
const Word16 *pt_Glt;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
krit_max_fx = -32768;
move16();
......@@ -119,12 +121,21 @@ void set_impulse_fx(
/* nominator & DEnominator row <0> */
FOR( i = 0; i < L_SUBFR; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
Lrr = L_mac_sat( Lrr, gh_fx[i], gh_fx[i] ); // Q27
Ldd = L_mac_sat( Ldd, gh_fx[i], xn_fx[i] ); // Q27
#else
Lrr = L_mac_o( Lrr, gh_fx[i], gh_fx[i], &Overflow ); // Q27
Ldd = L_mac_o( Ldd, gh_fx[i], xn_fx[i], &Overflow ); // Q27
#endif
}
rr_fx[start1] = Lrr;
move32();
#ifdef ISSUE_1867_replace_overflow_libenc
dd_fx[start1] = round_fx_sat( Ldd ); // Q11
#else
dd_fx[start1] = round_fx_o( Ldd, &Overflow ); // Q11
#endif
rr_fx[start1] = L_max( rr_fx[start1], 1 );
FOR( i = add( start1, 1 ); i < L_IMPULSE2; i++ )
......@@ -138,14 +149,24 @@ void set_impulse_fx(
gh_fx[j] = mac_r( L_deposit_h( gh_fx[j - 1] ),
Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[j] ); // Q13
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
Lrr = L_mac_sat( Lrr, gh_fx[j], gh_fx[j] ); // Q27
Ldd = L_mac_sat( Ldd, gh_fx[j], xn_fx[j] ); // Q27
#else
Lrr = L_mac_o( Lrr, gh_fx[j], gh_fx[j], &Overflow ); // Q27
Ldd = L_mac_o( Ldd, gh_fx[j], xn_fx[j], &Overflow ); // Q27
#endif
}
gh_fx[0] = mult_r( Glottal_cdbk_fx[m * L_IMPULSE + L_IMPULSE2 - i], h_orig_fx[0] ); // Q13
move16();
#ifdef ISSUE_1867_replace_overflow_libenc
Lrr = L_mac_sat( Lrr, gh_fx[0], gh_fx[0] ); // Q27
Ldd = L_mac_sat( Ldd, gh_fx[0], xn_fx[0] ); // Q27
#else
Lrr = L_mac_o( Lrr, gh_fx[0], gh_fx[0], &Overflow ); // Q27
Ldd = L_mac_o( Ldd, gh_fx[0], xn_fx[0], &Overflow ); // Q27
#endif
dd_fx[i] = round_fx_sat( Ldd ); // Q11
rr_fx[i] = L_max( Lrr, 1 );
move32();
......@@ -179,8 +200,11 @@ void set_impulse_fx(
FOR( i = L_SUBFR - 2; i >= start2; i-- )
{
/*rr[i] = rr[i+1] + gh[L_SUBFR+L_IMPULSE2-1-i]*gh[L_SUBFR+L_IMPULSE2-1-i];*/
rr_fx[i] = L_mac_o( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i],
gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], &Overflow ); // Q27
#ifdef ISSUE_1867_replace_overflow_libenc
rr_fx[i] = L_mac_sat( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i] ); // Q27
#else
rr_fx[i] = L_mac_o( rr_fx[i + 1], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], gh_fx[L_SUBFR + L_IMPULSE2 - 1 - i], &Overflow ); // Q27
#endif
move32();
}
/* nominator rows <L_IMPULSE2,L_SUBFR-1> */
......
......@@ -662,9 +662,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
Word16 tmp1, tmp2, exp2, scale, exp3;
SP_MUS_CLAS_HANDLE hSpMusClas = st_fx->hSpMusClas;
HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
/*------------------------------------------------------------------*
......@@ -794,10 +796,18 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
sum_PS = L_deposit_l( 0 );
FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
sum_PS = L_add_sat( sum_PS, PS[i] );
#else
sum_PS = L_add_o( sum_PS, PS[i], &Overflow );
#endif
}
exp1 = norm_l( sum_PS );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp1 = round_fx_sat( L_shl( sum_PS, exp1 ) );
#else
tmp1 = round_fx_o( L_shl( sum_PS, exp1 ), &Overflow );
#endif
exp1 = sub( 30, exp1 );
FOR( i = LOWEST_FBIN; i < HIGHEST_FBIN; i++ )
......@@ -805,7 +815,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
/*PS_norm[i] = PS[i] / sum_PS;*/
/*dPS[i] = (float)fabs(PS_norm[i] - st->past_PS[i]);*/
exp2 = norm_l( PS[i] );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp2 = round_fx_sat( L_shl( PS[i], exp2 ) );
#else
tmp2 = round_fx_o( L_shl( PS[i], exp2 ), &Overflow );
#endif
exp2 = sub( 30, exp2 );
scale = shr( sub( tmp1, tmp2 ), 15 );
......@@ -866,7 +880,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
ELSE
{
exp1 = norm_l( L_add( dPS[i], 336 ) );
#ifdef ISSUE_1867_replace_overflow_libenc
tmp1 = round_fx_sat( L_shl_sat( L_add( dPS[i], 336 ), exp1 ) );
#else
tmp1 = round_fx_o( L_shl_o( L_add( dPS[i], 336 ), exp1, &Overflow ), &Overflow );
#endif
exp1 = sub( 30, exp1 );
exp2 = norm_l( mx );
......@@ -923,7 +941,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
FOR( i = 0; i < N_FEATURES; i++ )
{
/**pFV = pSF[0] * *pFV + pSF[1];*/
#ifdef ISSUE_1867_replace_overflow_libenc
*pFV = round_fx_sat( L_shl_sat( L_mac( pSF_a[i], *pFV, pSF_m[i] ), ishift[i] ) );
#else
*pFV = round_fx_o( L_shl_o( L_mac( pSF_a[i], *pFV, pSF_m[i] ), ishift[i], &Overflow ), &Overflow );
#endif
move16();
pFV++;
}
......@@ -954,7 +976,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
FOR( p = 0; p < N_FEATURES; p++ )
{
/* xm[p] = FV[p] - m_speech[k*N_FEATURES+p];*/
#ifdef ISSUE_1867_replace_overflow_libenc
xm[p] = sub_sat( FV[p], m_speech_fx[k * N_FEATURES + p] );
#else
xm[p] = sub_o( FV[p], m_speech_fx[k * N_FEATURES + p], &Overflow );
#endif
move16(); /*Q15 */
}
......@@ -970,7 +996,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
FOR( p = 0; p < N_FEATURES; p++ )
{
/*xm[p] = FV[p] - m_noise[k*N_FEATURES+p];*/
#ifdef ISSUE_1867_replace_overflow_libenc
xm[p] = sub_sat( FV[p], m_noise_fx[k * N_FEATURES + p] );
#else
xm[p] = sub_o( FV[p], m_noise_fx[k * N_FEATURES + p], &Overflow );
#endif
move16(); /*Q15 */
}
......@@ -985,7 +1015,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
FOR( p = 0; p < N_FEATURES; p++ )
{
/*xm[p] = FV[p] - m_music[k*N_FEATURES+p];*/
#ifdef ISSUE_1867_replace_overflow_libenc
xm[p] = sub_sat( FV[p], m_music_fx[k * N_FEATURES + p] );
#else
xm[p] = sub_o( FV[p], m_music_fx[k * N_FEATURES + p], &Overflow );
#endif
move16(); /*Q15 */
}
......@@ -999,7 +1033,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
/* calculate log-probability */
/*log(0.0001)-0.5f * N_FEATURES * LOG_PI2 in Q9 */
#ifdef ISSUE_1867_replace_overflow_libenc
lps = extract_h( L_shl_sat( L_sub( max_s, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */
#else
lps = extract_h( L_shl_o( L_sub( max_s, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */
#endif
lps = s_max( lps, -10832 );
lpm = extract_h( L_shl( L_sub( max_m, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */
......@@ -1007,7 +1045,11 @@ static Word16 sp_mus_classif_gmm_fx( /* o : decis
/*
lpn = (float)log(pyn) - 0.5f * N_FEATURES * (float)log(2*PI);
*/
#ifdef ISSUE_1867_replace_overflow_libenc
lpn = extract_h( L_shl_sat( L_sub( max_n, LOG_PROB_CONST ), 16 - 1 ) ); /*Q9 */
#else
lpn = extract_h( L_shl_o( L_sub( max_n, LOG_PROB_CONST ), 16 - 1, &Overflow ) ); /*Q9 */
#endif
lpn = s_max( lpn, -10832 );
*high_lpn_flag_ptr = 0;
......@@ -1459,9 +1501,11 @@ static Word16 attack_det_fx( /* o : attack flag
Word16 i, j, tmp, tmp1, attack, exp1;
Word32 L_tmp, etmp, etmp2, finc[ATT_NSEG];
Word16 att_3lsub_pos;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
att_3lsub_pos = ATT_3LSUB_POS;
......@@ -1479,7 +1523,11 @@ static Word16 attack_det_fx( /* o : attack flag
FOR( j = 1; j < ATT_SEG_LEN; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac0_sat( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j] ); /*2*Qx */
#else
L_tmp = L_mac0_o( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j], &Overflow ); /*2*Qx */
#endif
}
finc[i] = L_tmp;
......@@ -1504,7 +1552,11 @@ static Word16 attack_det_fx( /* o : attack flag
FOR( i = 1; i < att_3lsub_pos; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_add_sat( L_tmp, L_shr_sat( finc[i], Qx ) ); /*Qx */
#else
L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i], Qx ), &Overflow ); /*Qx */
#endif
}
L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */
etmp = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */
......@@ -1516,7 +1568,11 @@ static Word16 attack_det_fx( /* o : attack flag
L_tmp = L_shr_sat( finc[attack], Qx ); /*Qx */
FOR( i = 1; i < tmp1; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_add_sat( L_tmp, L_shr_sat( finc[i + attack], Qx ) ); /*Qx */
#else
L_tmp = L_add_o( L_tmp, L_shr_sat( finc[i + attack], Qx ), &Overflow ); /*Qx */
#endif
}
L_tmp = Mult_32_16( L_tmp, tmp ); /*Q(14-exp1+Qx) */
etmp2 = L_shl( L_tmp, sub( exp1, 14 ) ); /*Qx */
......@@ -2615,9 +2671,11 @@ static Word16 attack_det_ivas_fx( /* o : attack flag
Word64 W_tmp;
Word16 q_diff;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
att_3lsub_pos = ATT_3LSUB_POS;
......@@ -2635,7 +2693,11 @@ static Word16 attack_det_ivas_fx( /* o : attack flag
FOR( j = 1; j < ATT_SEG_LEN; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
L_tmp = L_mac0_sat( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j] ); /*2*Qx */
#else
L_tmp = L_mac0_o( L_tmp, inp[i * ATT_SEG_LEN + j], inp[i * ATT_SEG_LEN + j], &Overflow ); /*2*Qx */
#endif
}
finc[i] = L_tmp;
......@@ -3676,9 +3738,11 @@ static void spec_analysis_fx(
Word16 peak_idx[65];
Word16 valey_idx[65];
Word16 p2v[65];
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* find spectral peaks */
......@@ -3762,7 +3826,15 @@ static void spec_analysis_fx(
test();
IF( GT_16( peak_idx[k], valey_idx[i] ) && LT_16( peak_idx[k], valey_idx[i + 1] ) )
{
#ifdef ISSUE_1867_replace_overflow_libenc
p2v[k] = sub_sat( shl_sat( peak[k], 1 ), add_sat( valley[i], valley[i + 1] ) );
#else
#ifdef ISSUE_1796_replace_shl_o
p2v[k] = sub_o( shl_sat( peak[k], 1 ), add_o( valley[i], valley[i + 1], &Overflow ), &Overflow );
#else
p2v[k] = sub_o( shl_o( peak[k], 1, &Overflow ), add_o( valley[i], valley[i + 1], &Overflow ), &Overflow );
#endif
#endif
move16();
k = add( k, 1 );
}
......
......@@ -50,9 +50,11 @@ void stat_noise_uv_enc_fx(
Word16 noisiness = 0;
move16();
Word16 num, den, expn, expd;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
test();
test();
......@@ -65,9 +67,17 @@ void stat_noise_uv_enc_fx(
*-----------------------------------------------------------------*/
/* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
expn = sub( norm_l( LepsP[0] ), 1 );
#ifdef ISSUE_1867_replace_overflow_libenc
num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
#else
num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/
#endif
expd = norm_l( LepsP[1] );
#ifdef ISSUE_1867_replace_overflow_libenc
den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
#else
den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/
#endif
num = div_s( num, den ); /*expn-expd+15*/
num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
num = sub( num, 1024 ); /*num - 1*/
......@@ -123,9 +133,11 @@ void stat_noise_uv_enc_ivas_fx(
Word16 noisiness = 0;
move16();
Word16 num, den, expn, expd;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
test();
test();
......@@ -138,9 +150,17 @@ void stat_noise_uv_enc_ivas_fx(
*-----------------------------------------------------------------*/
/* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
expn = sub( norm_l( LepsP[0] ), 1 );
#ifdef ISSUE_1867_replace_overflow_libenc
num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
#else
num = extract_h( L_shl_o( LepsP[0], expn, &Overflow ) ); /*expn-16*/
#endif
expd = norm_l( LepsP[1] );
#ifdef ISSUE_1867_replace_overflow_libenc
den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
#else
den = extract_h( L_shl_o( LepsP[1], expd, &Overflow ) ); /*expd-16*/
#endif
num = div_s( num, den ); /*expn-expd+15*/
num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
num = sub( num, 1024 ); /*num - 1*/
......
......@@ -303,9 +303,11 @@ void swb_bwe_enc_ivas_fx(
Word16 fb_ener_adjust_fx;
Word16 ener_adjust_quan_fx = 0;
move16();
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
Word16 fb_band_begin;
Word16 q_new_input_hp;
......@@ -408,7 +410,11 @@ void swb_bwe_enc_ivas_fx(
*----------------------------------------------------------------------*/
/* tilt returned in Q24 goto to Q11 */
#ifdef ISSUE_1867_replace_overflow_libenc
tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) );
#else
tilt_nb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3, &Overflow ), &Overflow );
#endif
/*---------------------------------------------------------------------*
* SWB BWE encoding
* FB BWE encoding
......@@ -543,7 +549,11 @@ void swb_bwe_enc_ivas_fx(
L_tmp = L_shl( L_tmp, exp1 );
exp = sub( sub( 31, exp1 ), sub( 30, exp ) );
L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */
#ifdef ISSUE_1867_replace_overflow_libenc
fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */
#else
fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */
#endif
}
ELSE
{
......@@ -623,9 +633,11 @@ void swb_bwe_enc_fx(
Word16 fb_ener_adjust_fx;
Word16 ener_adjust_quan_fx = 0;
move16();
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
......@@ -683,7 +695,11 @@ void swb_bwe_enc_fx(
*----------------------------------------------------------------------*/
/* tilt returned in Q24 goto to Q11 */
#ifdef ISSUE_1867_replace_overflow_libenc
tilt_nb_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3 ) );
#else
tilt_nb_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( old_input_lp_fx, Q_slb_speech, st_fx->L_frame ), 3, &Overflow ), &Overflow );
#endif
/*---------------------------------------------------------------------*
* SWB BWE encoding
* FB BWE encoding
......@@ -806,7 +822,11 @@ void swb_bwe_enc_fx(
// exp = 31 - exp1 - ( 30 - exp );
exp = add( 31 - 30, sub( exp, exp1 ) );
L_tmp = Isqrt_lc( L_tmp, &exp ); /*31-exp */
#ifdef ISSUE_1867_replace_overflow_libenc
fb_ener_adjust_fx = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /*Q15 */
#else
fb_ener_adjust_fx = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */
#endif
}
ELSE
{
......@@ -1007,9 +1027,11 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class
Word16 sharplimit;
Word16 numsharp, num, den;
Word16 numharmonic, tmp, expn, expd, scale;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
......@@ -1046,16 +1068,28 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class
{
IF( hBWE_FD->prev_global_gain_fx == 0 )
{
#ifdef ISSUE_1867_replace_overflow_libenc
gain_tmp = round_fx_sat( L_shl_sat( fGain, 30 ) ); /*Q14 */
#else
gain_tmp = round_fx_o( L_shl_o( fGain, 30, &Overflow ), &Overflow ); /*Q14 */
#endif
}
ELSE
{
expn = norm_l( fGain );
#ifdef ISSUE_1867_replace_overflow_libenc
num = extract_h( L_shl( fGain, expn ) );
#else
num = extract_h( L_shl_o( fGain, expn, &Overflow ) );
#endif
expn = sub( sub( 30, expn ), shl( Q_shb, 1 ) );
expd = norm_l( hBWE_FD->prev_global_gain_fx );
#ifdef ISSUE_1867_replace_overflow_libenc
den = extract_h( L_shl( hBWE_FD->prev_global_gain_fx, expd ) );
#else
den = extract_h( L_shl_o( hBWE_FD->prev_global_gain_fx, expd, &Overflow ) );
#endif
expd = sub( sub( 30, expd ), shl( st_fx->prev_Q_shb, 1 ) );
scale = shr( sub( den, num ), 15 );
......@@ -1155,7 +1189,11 @@ static Word16 FD_BWE_class_fx( /* o : FD BWE class
expd = norm_s( den );
tmp = div_s( shl( 1, sub( 14, expd ) ), den ); /*Q(29-expd-Q_syn) */
L_tmp = L_mult( tmp, peak ); /*Q(30-expd) */
#ifdef ISSUE_1867_replace_overflow_libenc
sharp = round_fx_sat( L_shl_sat( L_tmp, sub( expd, 4 ) ) ); /*Q10 */
#else
sharp = round_fx_o( L_shl_o( L_tmp, sub( expd, 4 ), &Overflow ), &Overflow ); /*Q10 */
#endif
}
ELSE
{
......@@ -1351,9 +1389,11 @@ static void vqWithCand_w_fx(
const Word16 *p_E_ROM_dico;
Word16 dist, temp1;
Word32 L_dist, L_tmp;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
IF( flag )
{
......@@ -1370,14 +1410,22 @@ static void vqWithCand_w_fx(
FOR( i = 0; i < E_ROM_dico_size; i++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
dist = sub_sat( x[0], *p_E_ROM_dico++ ); /*Q8 */
#else
dist = sub_o( x[0], *p_E_ROM_dico++, &Overflow ); /*Q8 */
#endif
L_dist = L_mult( dist, w[0] ); /*Q22 */
L_dist = Mult_32_16( L_dist, dist ); /*Q15 */
L_dist = L_shr( L_dist, 10 ); /*Q5 */
FOR( j = 1; j < dim; j++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
temp1 = sub_sat( x[j], *p_E_ROM_dico++ );
#else
temp1 = sub_o( x[j], *p_E_ROM_dico++, &Overflow );
#endif
L_tmp = L_mult( temp1, w[j] ); /*Q22 */
L_tmp = Mult_32_16( L_tmp, temp1 ); /*Q15 */
L_dist = L_add( L_dist, L_shr( L_tmp, 10 ) ); /*Q5 */
......@@ -1652,9 +1700,11 @@ static void msvq_interpol_fx(
Word16 quant_select[SWB_FENV], w_env11[SWB_FENV / 2], w_env12[SWB_FENV / 2], tmp;
Word32 L_tmp, distCand[N_CAND], L_dist, L_minDist;
Word16 synth_energy[SWB_FENV];
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* Extract target vector */
......@@ -1695,13 +1745,21 @@ static void msvq_interpol_fx(
/* Extract vector for odd position */
FOR( n_band = 0; n_band < DIM11; n_band++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
quant_tmp[n_band] = add_sat( quant_tmp1[n_band], quant_tmp2[n_band] );
#else
quant_tmp[n_band] = add_o( quant_tmp1[n_band], quant_tmp2[n_band], &Overflow );
#endif
move16();
}
FOR( n_band = 0; n_band < DIM12 - 1; n_band++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] ); /*Q8 */
#else
tmp = add_o( quant_tmp[n_band], quant_tmp[n_band + 1], &Overflow ); /*Q8 */
#endif
tmp = shr( tmp, 1 );
quant_tmp2[n_band] = sub( env_temp12[n_band], tmp );
move16(); /*Q8 */
......@@ -1724,7 +1782,11 @@ static void msvq_interpol_fx(
FOR( n_band = 0; n_band < DIM12 - 1; n_band++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
tmp = add_sat( quant_tmp[n_band], quant_tmp[n_band + 1] );
#else
tmp = add_o( quant_tmp[n_band], quant_tmp[n_band + 1], &Overflow );
#endif
tmp = shr( tmp, 1 );
quant_select[( n_band << 1 ) + 1] = add( tmp, quant_tmp2[n_band] );
move16(); /*Q8 */
......@@ -1784,9 +1846,11 @@ static void msvq_interpol_2_fx(
Word16 quant_select[SWB_FENV], w_env11[SWB_FENV / 2], w_env12[SWB_FENV / 2];
Word32 L_tmp, distCand[N_CAND], L_dist, L_minDist;
Word16 synth_energy[SWB_FENV];
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* Extract target vector */
FOR( n_band = 0; n_band < DIM11 - 1; n_band++ )
......@@ -1844,9 +1908,17 @@ static void msvq_interpol_2_fx(
move16();
FOR( n_band = 1; n_band < DIM12 - 1; n_band++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
tmp_q = add_sat( quant_tmp[n_band - 1], quant_tmp[n_band] );
#else
tmp_q = add_o( quant_tmp[n_band - 1], quant_tmp[n_band], &Overflow );
#endif
tmp_q = shr( tmp_q, 1 );
#ifdef ISSUE_1867_replace_overflow_libenc
quant_tmp2[n_band] = sub_sat( env_temp12[n_band], tmp_q );
#else
quant_tmp2[n_band] = sub_o( env_temp12[n_band], tmp_q, &Overflow );
#endif
move16();
}
......@@ -1867,9 +1939,17 @@ static void msvq_interpol_2_fx(
move16(); /*Q8 */
FOR( n_band = 1; n_band < DIM12 - 1; n_band++ )
{
#ifdef ISSUE_1867_replace_overflow_libenc
tmp_q = add_sat( quant_tmp[n_band - 1], quant_tmp[n_band] );
#else
tmp_q = add_o( quant_tmp[n_band - 1], quant_tmp[n_band], &Overflow );
#endif
tmp_q = shr( tmp_q, 1 );
#ifdef ISSUE_1867_replace_overflow_libenc
quant_select[( n_band << 1 ) - 1] = add_sat( quant_tmp2[n_band], tmp_q );
#else
quant_select[( n_band << 1 ) - 1] = add_o( quant_tmp2[n_band], tmp_q, &Overflow );
#endif
}
L_dist = L_deposit_l( 0 );
......@@ -1931,9 +2011,11 @@ static void calculate_Tonality_fx(
Word16 org_spec[80], gen_spec[80];
Word32 L_log_gm_org, L_log_gm_gen;
Word16 l_shift;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* to reduce dynamic range of original spectrum */
......@@ -2039,7 +2121,11 @@ static void calculate_Tonality_fx(
L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */
L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef ISSUE_1867_replace_overflow_libenc
*SFM_org = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */
#else
*SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#endif
move16();
*SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) );
move16(); /*0.0001 and 5.993 in Q12 */
......@@ -2060,7 +2146,11 @@ static void calculate_Tonality_fx(
L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */
L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef ISSUE_1867_replace_overflow_libenc
*SFM_gen = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */
#else
*SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#endif
move16();
*SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) );
move16(); /*0.0001 and 5.993 in Q12 */
......@@ -2089,9 +2179,11 @@ static void calculate_Tonality_ivas_fx(
Word16 org_spec[80], gen_spec[80];
Word32 L_log_gm_org, L_log_gm_gen;
Word16 l_shift;
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
/* to reduce dynamic range of original spectrum */
......@@ -2197,7 +2289,11 @@ static void calculate_Tonality_ivas_fx(
L_tmp2 = Mpy_32_16_1( L_log_gm_org, inv_len ); /* Q14 */
L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef ISSUE_1867_replace_overflow_libenc
*SFM_org = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */
#else
*SFM_org = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#endif
move16();
*SFM_org = s_max( 0, s_min( *SFM_org, 24547 ) );
move16(); /*0.0001 and 5.993 in Q12 */
......@@ -2218,7 +2314,11 @@ static void calculate_Tonality_ivas_fx(
L_tmp2 = Mpy_32_16_1( L_log_gm_gen, inv_len ); /* Q14 */
L_tmp = L_sub( L_tmp1, L_tmp2 );
#ifdef ISSUE_1867_replace_overflow_libenc
*SFM_gen = round_fx_sat( L_shl_sat( L_tmp, 14 ) ); /*Q12 */
#else
*SFM_gen = round_fx_o( L_shl_o( L_tmp, 14, &Overflow ), &Overflow ); /*Q12 */
#endif
move16();
*SFM_gen = s_max( 0, s_min( *SFM_gen, 24547 ) );
move16(); /*0.0001 and 5.993 in Q12 */
......@@ -2606,9 +2706,11 @@ static Word16 SWB_BWE_encoding_fx(
Word16 SWB_tenv_tmp_fx[SWB_TENV];
Word16 max_fx;
Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV];
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
......@@ -2651,7 +2753,11 @@ static Word16 SWB_BWE_encoding_fx(
}
/* tilt returned in Q24 go to Q11 */
#ifdef ISSUE_1867_replace_overflow_libenc
tilt_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3 ) );
#else
tilt_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3, &Overflow ), &Overflow );
#endif
test();
test();
IF( EQ_16( IsTransient, 1 ) && ( GT_16( tilt_fx, 16384 ) || GT_16( st_fx->clas, 1 ) ) )
......@@ -2755,7 +2861,11 @@ static Word16 SWB_BWE_encoding_fx(
L_tmp = L_deposit_h( tmp );
L_tmp = Isqrt_lc( L_tmp, &expn ); /*31-expn */
#ifdef ISSUE_1867_replace_overflow_libenc
Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, sub( expn, 1 ) ) ); /*Q14 */
#else
Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, sub( expn, 1 ), &Overflow ), &Overflow ); /*Q14 */
#endif
}
ELSE
{
......@@ -2767,7 +2877,11 @@ static Word16 SWB_BWE_encoding_fx(
{
L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */
#ifdef ISSUE_1867_replace_overflow_libenc
Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, 2 ) ); /*Q15 */
#else
Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */
#endif
}
ELSE IF( GT_16( Rat_tenv_fx, 16384 ) )
{
......@@ -3051,9 +3165,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
Word16 SWB_tenv_tmp_fx[SWB_TENV];
Word16 max_fx;
Word16 energy_factor_fx[SWB_FENV], w_env_fx[SWB_FENV];
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move32();
#endif
#endif
Word16 inner_frame;
Word16 q_shift;
......@@ -3114,7 +3230,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
}
/* tilt returned in Q24 go to Q11 */
#ifdef ISSUE_1867_replace_overflow_libenc
tilt_fx = round_fx_sat( L_shl_sat( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3 ) );
#else
tilt_fx = round_fx_o( L_shl_o( calc_tilt_bwe_fx( insig_fx, 0, L_FRAME32k ), 3, &Overflow ), &Overflow );
#endif
test();
test();
IF( EQ_16( IsTransient, 1 ) && ( GT_16( tilt_fx, 16384 ) || GT_16( st_fx->clas, 1 ) ) )
......@@ -3219,7 +3339,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
expn = sub( sub( 30, expn ), sub( shl( Q_insig_lp, 1 ), 7 ) );
expd = norm_l( WB_tenv_syn_fx );
#ifdef ISSUE_1867_replace_overflow_libenc
den = round_fx_sat( L_shl( WB_tenv_syn_fx, expd ) );
#else
den = round_fx_o( L_shl( WB_tenv_syn_fx, expd ), &Overflow );
#endif
expd = sub( sub( 30, expd ), sub( shl( Q_insig_lp, 1 ), 7 ) );
scale = shr( sub( den, num ), 15 );
......@@ -3232,7 +3356,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
L_tmp = L_deposit_h( tmp );
L_tmp = Isqrt_lc( L_tmp, &expn ); /*31-expn */
#ifdef ISSUE_1867_replace_overflow_libenc
Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, sub( expn, 1 ) ) ); /*Q14 */
#else
Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, sub( expn, 1 ), &Overflow ), &Overflow ); /*Q14 */
#endif
}
ELSE
{
......@@ -3243,7 +3371,11 @@ static Word16 SWB_BWE_encoding_ivas_fx(
IF( LT_16( Rat_tenv_fx, 8192 ) )
{
L_tmp = L_mult( Rat_tenv_fx, 19661 ); /*Q29 */
#ifdef ISSUE_1867_replace_overflow_libenc
Rat_tenv_fx = round_fx_sat( L_shl_sat( L_tmp, 2 ) ); /*Q15 */
#else
Rat_tenv_fx = round_fx_o( L_shl_o( L_tmp, 2, &Overflow ), &Overflow ); /*Q15 */
#endif
}
ELSE IF( GT_16( Rat_tenv_fx, 16384 ) )
{
......
......@@ -117,9 +117,11 @@ void swb_bwe_enc_hr_fx(
#else
Word32 L_t_audio_tmp_fx[L_FRAME48k];
#endif
#ifndef ISSUE_1867_replace_overflow_libenc
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
Flag Overflow = 0;
move16();
#endif
#endif
FD_BWE_ENC_HANDLE hBWE_FD = st_fx->hBWE_FD;
BSTR_ENC_HANDLE hBstr = st_fx->hBstr;
......@@ -768,7 +770,11 @@ void swb_bwe_enc_hr_fx(
{
L_tmp = L_mult( temp, t_audio_fx[i] );
L_tmp = L_shr_sat( L_tmp, temp2 );
#ifdef ISSUE_1867_replace_overflow_libenc
t_audio_fx[i] = round_fx_sat( L_tmp );
#else
t_audio_fx[i] = round_fx_o( L_tmp, &Overflow );
#endif
move16();
}
......