From 7fde3b1cce9e23e276580cb61b123834a4c76937 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 15 Dec 2024 21:04:18 +0100 Subject: [PATCH 1/4] add BASOP_Util_Divide3232_Scale_FhG --- lib_com/basop_util.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ lib_com/basop_util.h | 8 ++++ lib_com/options.h | 1 + 3 files changed, 96 insertions(+) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index fb4cf1517..fc555aa94 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1037,8 +1037,94 @@ Word32 div_w( Word32 L_num, Word32 L_den ) } } +#ifdef BASOP_DIVIDE3232_FHG +// replace depreacted L_add_c() by L_add_co(); currently disabled, because of missing counting in L_add_co(); +//#define REPLACE_DEPR_L_ADD_C +Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bits ) +{ + Word32 z; + Word16 sx; + Word16 sy; + Word32 sign; + Word16 iteration; + Flag Carry; +#ifdef REPLACE_DEPR_L_ADD_C + Flag Overflow; +#endif + Word16 s_val; + + unset_carry( &Carry ); +#ifdef REPLACE_DEPR_L_ADD_C + unset_overflow( &Overflow ); +#endif + + /* assert (x >= (Word32)0); */ + assert( y != (Word32) 0 ); + + IF( x == (Word32) 0 ) + { + *s = -31; + move16(); + return ( (Word32) 0 ); + } + + sign = L_shr( L_xor( x, y ), 31 ); + + sx = norm_l( x ); + x = L_shl( x, sx ); + x = L_shr( x, 1 ); + s_val = sub( 1, sx ); + if ( x < 0 ) + { + x = L_negate( x ); + } + + sy = norm_l( y ); + y = L_shl( y, sy ); + y = L_shr( y, 1 ); + s_val = add( s_val, sy ); + if ( y >= 0 ) + { + y = L_negate( y ); + } + + *s = s_val; + move16(); + + z = L_sub( x, x ); // z = 0 + + FOR( iteration = (Word16) 0; iteration < (Word16) bits; iteration++ ) + { + if ( L_add( x, y ) >= 0 ) + { +#ifdef REPLACE_DEPR_L_ADD_C + x = L_add_co( x, y, &Carry, &Overflow ); // sets always carry=1 +#else + x = DEPR_L_add_c( x, y, &Carry ); // sets always carry=1 +#endif + } +#ifdef REPLACE_DEPR_L_ADD_C + z = L_add_co( z, z, &Carry, &Overflow ); // sets always carry=0 +#else + z = DEPR_L_add_c( z, z, &Carry ); // sets always carry=0 +#endif + x = L_add( x, x ); + } + + if ( sign != 0 ) + { + z = L_negate( z ); + } + + return L_shl( z, sub( 31, bits ) ); +} +#endif + Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) { +#ifdef BASOP_DIVIDE3232_FHG + return BASOP_Util_Divide3232_Scale_FhG( x, y, s, 24 ); +#else Word32 z; Word16 sx; Word16 sy; @@ -1087,6 +1173,7 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) } return z; +#endif } Word16 BASOP_Util_Divide3232_Scale( Word32 x, Word32 y, Word16 *s ) diff --git a/lib_com/basop_util.h b/lib_com/basop_util.h index 92994542e..01ff60fa3 100644 --- a/lib_com/basop_util.h +++ b/lib_com/basop_util.h @@ -328,6 +328,14 @@ Word16 BASOP_Util_Divide3232_Scale( Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s ); /*!< o : Additional scalefactor difference*/ + +#ifdef BASOP_DIVIDE3232_FHG +Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, /*!< i : Numerator*/ + Word32 y, /*!< i : Denominator*/ + Word16 *s, /*!< o : Additional scalefactor difference*/ + Word16 bits ); /*!< i : number of mantissa bits of result*/ +#endif + Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, /*!< i : Numerator*/ Word32 y, /*!< i : Denominator*/ Word16 *s ); /*!< o : Additional scalefactor difference*/ diff --git a/lib_com/options.h b/lib_com/options.h index 2954fb8a4..4feafb5d4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -91,4 +91,5 @@ #define FIX_1054_IF_ELSE_CMPLX /* VA: Fix 1054 incorrect counting of complexity when ELSE-IF sequence is encoutered in two functions */ #define FIX_1052_COPY_CMPLX_DISCREPANCY /* VA: modify IF-ELSE statements used in Copy*() functions to avoid dependency on x[] and y[] in RAM */ #define FIX_1049_SHR_RO_COMPLEXITY /* VA: fix for issue 1049: incorrect counting of complexity in the shr_ro() function */ +#define BASOP_DIVIDE3232_FHG /* FhG: scalable 32 by 32 division, use with 24 bit precision */ #endif -- GitLab From 5c289327637889b71edee06e151247679155e0ad Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 15 Dec 2024 21:39:15 +0100 Subject: [PATCH 2/4] clang format --- lib_com/basop_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index fc555aa94..9b2085c4b 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1106,7 +1106,7 @@ Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bi #ifdef REPLACE_DEPR_L_ADD_C z = L_add_co( z, z, &Carry, &Overflow ); // sets always carry=0 #else - z = DEPR_L_add_c( z, z, &Carry ); // sets always carry=0 + z = DEPR_L_add_c( z, z, &Carry ); // sets always carry=0 #endif x = L_add( x, x ); } -- GitLab From 5bce62fadac0211b4d1f42e957742bc48c9ad48f Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Tue, 17 Dec 2024 12:34:09 +0100 Subject: [PATCH 3/4] remove impact on BASOP_Util_Divide3232_Scale_cadence() for now --- lib_com/basop_util.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 9b2085c4b..61dd133f4 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1122,9 +1122,6 @@ Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bi Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) { -#ifdef BASOP_DIVIDE3232_FHG - return BASOP_Util_Divide3232_Scale_FhG( x, y, s, 24 ); -#else Word32 z; Word16 sx; Word16 sy; @@ -1173,7 +1170,6 @@ Word32 BASOP_Util_Divide3232_Scale_cadence( Word32 x, Word32 y, Word16 *s ) } return z; -#endif } Word16 BASOP_Util_Divide3232_Scale( Word32 x, Word32 y, Word16 *s ) -- GitLab From 610221e29cead060b577924bba61b918b117d858 Mon Sep 17 00:00:00 2001 From: Stefan Doehla Date: Mon, 27 Jan 2025 09:08:24 +0100 Subject: [PATCH 4/4] remove unnecessary path with L_add_co --- lib_com/basop_util.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/lib_com/basop_util.c b/lib_com/basop_util.c index 5f23ff286..1a5d0615f 100644 --- a/lib_com/basop_util.c +++ b/lib_com/basop_util.c @@ -1007,8 +1007,6 @@ Word32 div_w( Word32 L_num, Word32 L_den ) } #ifdef BASOP_DIVIDE3232_FHG -// replace depreacted L_add_c() by L_add_co(); currently disabled, because of missing counting in L_add_co(); -//#define REPLACE_DEPR_L_ADD_C Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bits ) { Word32 z; @@ -1017,15 +1015,9 @@ Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bi Word32 sign; Word16 iteration; Flag Carry; -#ifdef REPLACE_DEPR_L_ADD_C - Flag Overflow; -#endif Word16 s_val; unset_carry( &Carry ); -#ifdef REPLACE_DEPR_L_ADD_C - unset_overflow( &Overflow ); -#endif /* assert (x >= (Word32)0); */ assert( y != (Word32) 0 ); @@ -1066,17 +1058,9 @@ Word32 BASOP_Util_Divide3232_Scale_FhG( Word32 x, Word32 y, Word16 *s, Word16 bi { if ( L_add( x, y ) >= 0 ) { -#ifdef REPLACE_DEPR_L_ADD_C - x = L_add_co( x, y, &Carry, &Overflow ); // sets always carry=1 -#else - x = DEPR_L_add_c( x, y, &Carry ); // sets always carry=1 -#endif + x = L_add_c( x, y, &Carry ); // sets always carry=1 } -#ifdef REPLACE_DEPR_L_ADD_C - z = L_add_co( z, z, &Carry, &Overflow ); // sets always carry=0 -#else - z = DEPR_L_add_c( z, z, &Carry ); // sets always carry=0 -#endif + z = L_add_c( z, z, &Carry ); // sets always carry=0 x = L_add( x, x ); } -- GitLab