From b9f154fd9ea3c4cb91aed2dfb3063cf091fd8b96 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 16 Aug 2024 07:47:12 -0400 Subject: [PATCH 1/2] Fix 851, prevent precision lost during UL_div --- lib_com/options.h | 2 ++ lib_dec/ivas_range_uni_dec.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 475df11b7..a3e716f40 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -164,6 +164,8 @@ #define FIX_839_FB_CONTENT_SOMETIME_MISSING /* VA : Fix scaling error for FB TB BWE */ #define FIX_846_TILT_BWE /* VA : Proposed fix to 846, to solve saturation */ #define FIX_843_LOW_RATE_BWE /* VA : Proposed fix to 843 to solve mid band noise */ +#define FIX851_RANGE_DEC_PRECISION /* VA : 851 Proposed fix to keep precision during UL_div*/ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index f2bbc1202..0e5b5b266 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -628,17 +628,28 @@ UWord16 rc_uni_dec_read_bits( UWord32 range; /* local copy (4 to 7 uses) */ Word16 norm_range; UWord32 temp1, temp2; - +#define FIX851_RANGE_DEC_PRECISION +#ifdef FIX851_RANGE_DEC_PRECISION + Word16 exp_temp1; +#endif low = rc_st_dec->rc_low; range = rc_st_dec->rc_range; move32(); move32(); range = (UWord32) W_shr( range, bits ); +#ifdef FIX851_RANGE_DEC_PRECISION + exp_temp1 = sub( W_norm( low ), 31 + 1 ); + temp1 = (UWord32) W_shl( low, exp_temp1 ); + norm_range = sub( W_norm( range ), 31 ); + temp2 = (UWord32) W_shl( range, norm_range ); + val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( add( 32, exp_temp1 ), norm_range ) ); +#else temp1 = (UWord32) W_shr( low, 1 ); norm_range = sub( W_norm( range ), 31 ); temp2 = (UWord32) W_shl( range, norm_range ); val = (UWord32) W_shr( UL_div( temp1, temp2 ), sub( 32 - 1, norm_range ) ); +#endif /* in case of bitstream errors it is possible that val >= (1 << bits) */ IF( W_shr( val, bits ) != 0 ) /* equivalent condition */ -- GitLab From 2dd1d61849ce0317818ae5eea1abd07ee2a65999 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 16 Aug 2024 08:35:25 -0400 Subject: [PATCH 2/2] remove duplicated define --- lib_dec/ivas_range_uni_dec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_dec/ivas_range_uni_dec.c b/lib_dec/ivas_range_uni_dec.c index 0e5b5b266..94efd89e0 100644 --- a/lib_dec/ivas_range_uni_dec.c +++ b/lib_dec/ivas_range_uni_dec.c @@ -628,7 +628,6 @@ UWord16 rc_uni_dec_read_bits( UWord32 range; /* local copy (4 to 7 uses) */ Word16 norm_range; UWord32 temp1, temp2; -#define FIX851_RANGE_DEC_PRECISION #ifdef FIX851_RANGE_DEC_PRECISION Word16 exp_temp1; #endif -- GitLab