From 52a297682e1b206a41940da4dcbb1b97268e5ffb Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Thu, 25 Jan 2024 14:02:13 +0100 Subject: [PATCH 1/6] FIX_976_USAN_PVQ_DEC_OMASA , corrected premature cast --- lib_com/options.h | 4 ++++ lib_dec/pvq_core_dec.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 820383e905..4d6953c941 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,6 +163,10 @@ #define FIX_956_DECODER_COMMAND_LINE_FIX /* VA: Output correct error message when the decoder command-line has too many mandatory arguments. */ #define FIX_955_FASTCONV_REND_IN_ISM /* VA: put FastConv rendering call under DEBUGGING */ + +#define FIX_976_USAN_PVQ_DEC_OMASA /* Ericsson: premature cast to unsigned detected by USAN corrected */ + + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 115d53ac57..1ef2bb0e59 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -415,11 +415,16 @@ static void densitySymbolIndexDecode( #undef WMC_TOOL_SKIP res_c = res - c; + if ( c == 0 ) { tot = res * ( res + 1 ) + 1; dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); - alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; +#ifdef FIX_976_USAN_PVQ_DEC_OMASA + alpha = (int16_t) floor_sqrt_exact( ( uint32_t )(( res + 1 ) * ( res + 1 ) - dec_freq )) + res + 1; +#else + alpha = (int16_t) floor_sqrt_exact( ( uint32_t )( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; +#endif sym_freq = 2 * ( res - alpha ) + 1; cum_freq = alpha * ( 2 * ( res + 1 ) - alpha ); } @@ -437,7 +442,12 @@ static void densitySymbolIndexDecode( dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); if ( dec_freq < tot - ( res + 1 ) - ( res - ( c + 1 ) ) * ( res - c ) * c + c + 1 ) { - alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); +#ifdef FIX_976_USAN_PVQ_DEC_OMASA + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); +#else + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); +#endif + sym_freq = 2 * alpha * res_c + 1; cum_freq = alpha * ( ( alpha - 1 ) * res_c + 1 ); } @@ -485,7 +495,7 @@ static int16_t get_pvq_splits( int16_t Np; uint32_t flag; - Np = (int16_t) ( intLimCDivPos( band_bits, 67 ) >> 2 ); + Np = ( int16_t )( intLimCDivPos( band_bits, 67 ) >> 2 ); if ( band_bits - 268 * Np != 0 || Np == 0 ) /* L_msu */ { Np++; /* ceil */ @@ -501,7 +511,7 @@ static int16_t get_pvq_splits( } } - Np = max( Np, (int16_t) ( ceil( (float) sfmsize / PVQ_MAX_BAND_SIZE ) ) ); + Np = max( Np, ( int16_t )( ceil( (float) sfmsize / PVQ_MAX_BAND_SIZE ) ) ); Np = min( MAX_SPLITS, Np ); Np = min( (int16_t) floor( (float) sfmsize / MIN_BAND_SIZE ), Np ); -- GitLab From 250353f494303b66049e99a15e1c09268667efec Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Thu, 25 Jan 2024 15:15:47 +0100 Subject: [PATCH 2/6] clang format --- lib_dec/pvq_core_dec.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 1ef2bb0e59..fd212c3d49 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -420,10 +420,10 @@ static void densitySymbolIndexDecode( { tot = res * ( res + 1 ) + 1; dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); -#ifdef FIX_976_USAN_PVQ_DEC_OMASA - alpha = (int16_t) floor_sqrt_exact( ( uint32_t )(( res + 1 ) * ( res + 1 ) - dec_freq )) + res + 1; +#ifdef FIX_976_USAN_PVQ_DEC_OMASA + alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( ( res + 1 ) * ( res + 1 ) - dec_freq ) ) + res + 1; #else - alpha = (int16_t) floor_sqrt_exact( ( uint32_t )( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; + alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; #endif sym_freq = 2 * ( res - alpha ) + 1; cum_freq = alpha * ( 2 * ( res + 1 ) - alpha ); @@ -442,11 +442,11 @@ static void densitySymbolIndexDecode( dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); if ( dec_freq < tot - ( res + 1 ) - ( res - ( c + 1 ) ) * ( res - c ) * c + c + 1 ) { -#ifdef FIX_976_USAN_PVQ_DEC_OMASA - alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); +#ifdef FIX_976_USAN_PVQ_DEC_OMASA + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); #else - alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); -#endif + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); +#endif sym_freq = 2 * alpha * res_c + 1; cum_freq = alpha * ( ( alpha - 1 ) * res_c + 1 ); @@ -495,7 +495,7 @@ static int16_t get_pvq_splits( int16_t Np; uint32_t flag; - Np = ( int16_t )( intLimCDivPos( band_bits, 67 ) >> 2 ); + Np = (int16_t) ( intLimCDivPos( band_bits, 67 ) >> 2 ); if ( band_bits - 268 * Np != 0 || Np == 0 ) /* L_msu */ { Np++; /* ceil */ @@ -511,7 +511,7 @@ static int16_t get_pvq_splits( } } - Np = max( Np, ( int16_t )( ceil( (float) sfmsize / PVQ_MAX_BAND_SIZE ) ) ); + Np = max( Np, (int16_t) ( ceil( (float) sfmsize / PVQ_MAX_BAND_SIZE ) ) ); Np = min( MAX_SPLITS, Np ); Np = min( (int16_t) floor( (float) sfmsize / MIN_BAND_SIZE ), Np ); -- GitLab From afc77096f4896d1996188b826421fb8ffd1ecd70 Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Mon, 29 Jan 2024 17:20:01 +0100 Subject: [PATCH 3/6] renamed define and aligned ivas-float negations to BASOP and ALT-BASOP --- lib_com/options.h | 2 +- lib_dec/pvq_core_dec.c | 25 +++++++++++++++++++++---- lib_enc/pvq_core_enc.c | 6 ++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8de27e096a..339c02c82e 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -163,7 +163,7 @@ #define FIX_955_FASTCONV_REND_IN_ISM /* VA: put FastConv rendering call under DEBUGGING */ -#define FIX_976_USAN_PVQ_DEC_OMASA /* Ericsson: premature cast to unsigned detected by USAN corrected */ +#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index fd212c3d49..01fd496fd0 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -98,6 +98,7 @@ static void pvq_decode_band( } set_s( g_part_s, -32768, Np ); + if ( Np > 1 ) { decode_energies( st, hPVQ, Np, dim_part, bits_part, g_part_s, band_bits_tot, bits_left, sfmsize, strict_bits ); @@ -112,11 +113,27 @@ static void pvq_decode_band( for ( j = 0; j < Np; j++ ) { - g_part[j] = -( (float) g_part_s[j] ) / 32768; - g_part_s[j] = -g_part_s[j]; + g_part[j] = -( (float) g_part_s[j] ) / 32768; +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* note: here g_part_s needs to be become exactly 1.0(float) esp. for Np==1 , thus g_part_s was initilized to (int16_t) -32768 */ +#endif + + if ( g_part_s[j] == -32768 ) + { + printf( "\n Error negative mag negative int16_t . Np=%2d in split j=%2d \n", Np, j ); + } +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* aligned to BASOP to avoid ASAN undefined negation issue with -(-32768) */ + g_part_s[j] = negate(g_part_s[j]); +#else + g_part_s[j] = -g_part_s[j]; +#endif } + srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); + + for ( j = 0; j < Np; j++ ) { js = idx_sort[Np - 1 - j]; @@ -420,7 +437,7 @@ static void densitySymbolIndexDecode( { tot = res * ( res + 1 ) + 1; dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); -#ifdef FIX_976_USAN_PVQ_DEC_OMASA +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( ( res + 1 ) * ( res + 1 ) - dec_freq ) ) + res + 1; #else alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; @@ -442,7 +459,7 @@ static void densitySymbolIndexDecode( dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); if ( dec_freq < tot - ( res + 1 ) - ( res - ( c + 1 ) ) * ( res - c ) * c + c + 1 ) { -#ifdef FIX_976_USAN_PVQ_DEC_OMASA +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); #else alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c index 5876c8b44a..7c90fb082f 100644 --- a/lib_enc/pvq_core_enc.c +++ b/lib_enc/pvq_core_enc.c @@ -124,7 +124,13 @@ static void pvq_encode_band( for ( j = 0; j < Np; j++ ) { g_part[j] = -( (float) g_part_s[j] ) / 32768; +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* aligned to BASOP to avoid ASAN undefined negation issue with -(-32768) */ + g_part_s[j] = negate( g_part_s[j] ); +#else g_part_s[j] = -g_part_s[j]; +#endif + } srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); -- GitLab From 208717bac26fefcd47e51ae3d31417174bdc37d9 Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Mon, 29 Jan 2024 17:47:10 +0100 Subject: [PATCH 4/6] format fix --- lib_dec/pvq_core_dec.c | 12 ++++++------ lib_enc/pvq_core_enc.c | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 01fd496fd0..96aa2aaf5c 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -113,10 +113,10 @@ static void pvq_decode_band( for ( j = 0; j < Np; j++ ) { - g_part[j] = -( (float) g_part_s[j] ) / 32768; + g_part[j] = -( (float) g_part_s[j] ) / 32768; #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR - /* note: here g_part_s needs to be become exactly 1.0(float) esp. for Np==1 , thus g_part_s was initilized to (int16_t) -32768 */ -#endif + /* note: here g_part_s needs to be become exactly 1.0(float) esp. for Np==1 , thus g_part_s was initilized to (int16_t) -32768 */ +#endif if ( g_part_s[j] == -32768 ) { @@ -124,10 +124,10 @@ static void pvq_decode_band( } #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* aligned to BASOP to avoid ASAN undefined negation issue with -(-32768) */ - g_part_s[j] = negate(g_part_s[j]); + g_part_s[j] = negate( g_part_s[j] ); #else - g_part_s[j] = -g_part_s[j]; -#endif + g_part_s[j] = -g_part_s[j]; +#endif } diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c index 7c90fb082f..d6671c4c97 100644 --- a/lib_enc/pvq_core_enc.c +++ b/lib_enc/pvq_core_enc.c @@ -129,8 +129,7 @@ static void pvq_encode_band( g_part_s[j] = negate( g_part_s[j] ); #else g_part_s[j] = -g_part_s[j]; -#endif - +#endif } srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); -- GitLab From 219e31f6b7859af4da5b82d538749f96a2c4c291 Mon Sep 17 00:00:00 2001 From: Jonas Sv Date: Wed, 31 Jan 2024 11:38:20 +0100 Subject: [PATCH 5/6] removed dbg printf and corrected comment on USAN --- lib_dec/pvq_core_dec.c | 9 +++------ lib_enc/pvq_core_enc.c | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 96aa2aaf5c..4176cd17df 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -115,15 +115,12 @@ static void pvq_decode_band( { g_part[j] = -( (float) g_part_s[j] ) / 32768; #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR - /* note: here g_part_s needs to be become exactly 1.0(float) esp. for Np==1 , thus g_part_s was initilized to (int16_t) -32768 */ + /* note: here g_part needs to be become exactly 1.0(float) thus in BASOP Word16 g_part_s is in the negative Q15 domain */ #endif - if ( g_part_s[j] == -32768 ) - { - printf( "\n Error negative mag negative int16_t . Np=%2d in split j=%2d \n", Np, j ); - } + #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR - /* aligned to BASOP to avoid ASAN undefined negation issue with -(-32768) */ + /* aligned to BASOP to avoid USAN undefined negation warning for -(-32768) */ g_part_s[j] = negate( g_part_s[j] ); #else g_part_s[j] = -g_part_s[j]; diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c index d6671c4c97..9f1fe46ac6 100644 --- a/lib_enc/pvq_core_enc.c +++ b/lib_enc/pvq_core_enc.c @@ -125,7 +125,7 @@ static void pvq_encode_band( { g_part[j] = -( (float) g_part_s[j] ) / 32768; #ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR - /* aligned to BASOP to avoid ASAN undefined negation issue with -(-32768) */ + /* aligned to BASOP to avoid USAN undefined negation warning with -(-32768) */ g_part_s[j] = negate( g_part_s[j] ); #else g_part_s[j] = -g_part_s[j]; -- GitLab From 499c662407caf23b63b37307715506bd3ca5a377 Mon Sep 17 00:00:00 2001 From: knj Date: Tue, 6 Feb 2024 10:11:35 +0100 Subject: [PATCH 6/6] remove fixed errors from suppression file --- scripts/ubsan.supp | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/ubsan.supp b/scripts/ubsan.supp index fc3f22e328..c1602085d2 100644 --- a/scripts/ubsan.supp +++ b/scripts/ubsan.supp @@ -30,8 +30,6 @@ implicit-signed-integer-truncation:dec_tcx.c implicit-signed-integer-truncation:hdecnrm.c implicit-signed-integer-truncation:lib_dec.c implicit-signed-integer-truncation:longarith.c -implicit-signed-integer-truncation:pvq_core_dec.c -implicit-signed-integer-truncation:pvq_core_enc.c implicit-signed-integer-truncation:tcq_position_arith.c implicit-signed-integer-truncation:tools.c shift-base:basop32.c -- GitLab