From bcd86d167b13e5fe9213bfcadcfefd478d0590da Mon Sep 17 00:00:00 2001 From: malenov Date: Tue, 26 Nov 2024 17:04:21 +0100 Subject: [PATCH 1/5] keep track of the name of the calling function within the ELSE() statement --- lib_com/control.c | 1 + lib_com/control.h | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib_com/control.c b/lib_com/control.c index 20865de23..c5116e72c 100644 --- a/lib_com/control.c +++ b/lib_com/control.c @@ -24,6 +24,7 @@ int funcId_where_last_call_to_else_occurred; long funcid_total_wmops_at_last_call_to_else; int call_occurred = 1; +char func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH + 1] = ""; #endif #ifdef CONTROL_CODE_OPS diff --git a/lib_com/control.h b/lib_com/control.h index ad1e5ae69..4c96bca89 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -33,6 +33,7 @@ #ifndef _CONTROL_H #define _CONTROL_H +#include #include "stl.h" @@ -45,6 +46,9 @@ extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; +#define MAX_FUNCTION_NAME_LENGTH 200 /* Maximum length of the function name */ +extern char func_name_where_last_call_to_else_occurred[]; + /* Technical note : * The following 3 variables are only used for correct complexity * evaluation of the following structure : @@ -172,15 +176,15 @@ static __inline void incrWhile( void ) #define IF( a ) if ( a ) #else /* ifndef WMOPS */ -#define IF( a ) if ( incrIf(), a ) +#define IF( a ) if ( incrIf( __func__ ), a ) -static __inline void incrIf( void ) +static __inline void incrIf( const char *func_name ) { /* Technical note : * If the "IF" operator comes just after an "ELSE", its counter * must not be incremented. */ - if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) + if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) multiCounter[currCounter].If++; call_occurred = 0; @@ -205,10 +209,10 @@ static __inline void incrIf( void ) #else /* ifndef WMOPS */ #define ELSE \ - else if ( incrElse(), 0 ); \ + else if ( incrElse( __func__ ), 0 ); \ else -static __inline void incrElse( void ) +static __inline void incrElse( const char *func_name ) { multiCounter[currCounter].If++; @@ -218,6 +222,10 @@ static __inline void incrElse( void ) /* We keep track of the number of WMOPS of this funcId when the ELSE macro was called. */ funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation(); + /* We keep track of the name of the last calling function when the ELSE macro was called */ + strncpy( func_name_where_last_call_to_else_occurred, func_name, MAX_FUNCTION_NAME_LENGTH ); + func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH] = '\0'; + /* call_occurred is set to 0, in order to count the next IF (if necessary) */ call_occurred = 0; } -- GitLab From 3fd681b0604a538b420604b4eef4673c3fe61fd5 Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Tue, 26 Nov 2024 17:06:35 +0100 Subject: [PATCH 2/5] clang format --- lib_com/control.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/control.h b/lib_com/control.h index 4c96bca89..b1ad7ba76 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -208,7 +208,7 @@ static __inline void incrIf( const char *func_name ) #define ELSE else #else /* ifndef WMOPS */ -#define ELSE \ +#define ELSE \ else if ( incrElse( __func__ ), 0 ); \ else -- GitLab From 1b6555a9606ae57dda4de46dfb1095d11d16095c Mon Sep 17 00:00:00 2001 From: malenov Date: Mon, 9 Dec 2024 10:58:15 +0100 Subject: [PATCH 3/5] simplify the incrIf/incrElse functions -remove obsolete aux. variables --- lib_com/control.c | 7 +++++-- lib_com/control.h | 44 ++++++++++++++++++++++++++++++++++++-------- lib_com/count.c | 4 ++++ lib_com/options.h | 1 + lib_debug/wmc_auto.c | 2 ++ 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/lib_com/control.c b/lib_com/control.c index c5116e72c..dadb2e496 100644 --- a/lib_com/control.c +++ b/lib_com/control.c @@ -21,10 +21,13 @@ #include "stl.h" #ifdef WMOPS -int funcId_where_last_call_to_else_occurred; long funcid_total_wmops_at_last_call_to_else; -int call_occurred = 1; +#ifdef FIX_1054_IF_ELSE_CMPLX char func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH + 1] = ""; +#else +int funcId_where_last_call_to_else_occurred; +int call_occurred = 1; +#endif #endif #ifdef CONTROL_CODE_OPS diff --git a/lib_com/control.h b/lib_com/control.h index b1ad7ba76..e515ec3fb 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -36,7 +36,6 @@ #include #include "stl.h" - /***************************************************************************** * * Constants and Globals @@ -47,8 +46,11 @@ extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; #define MAX_FUNCTION_NAME_LENGTH 200 /* Maximum length of the function name */ -extern char func_name_where_last_call_to_else_occurred[]; +extern long funcid_total_wmops_at_last_call_to_else; +#ifdef FIX_1054_IF_ELSE_CMPLX +extern char func_name_where_last_call_to_else_occurred[]; +#else /* Technical note : * The following 3 variables are only used for correct complexity * evaluation of the following structure : @@ -64,9 +66,10 @@ extern char func_name_where_last_call_to_else_occurred[]; * ... * } */ -extern int funcId_where_last_call_to_else_occurred; -extern long funcid_total_wmops_at_last_call_to_else; + extern int call_occurred; +extern int funcId_where_last_call_to_else_occurred; +#endif #endif /* ifdef WMOPS */ @@ -176,19 +179,32 @@ static __inline void incrWhile( void ) #define IF( a ) if ( a ) #else /* ifndef WMOPS */ +#ifdef FIX_1054_IF_ELSE_CMPLX #define IF( a ) if ( incrIf( __func__ ), a ) +#else +#define IF( a ) if ( incrIf(), a ) +#endif +#ifdef FIX_1054_IF_ELSE_CMPLX static __inline void incrIf( const char *func_name ) +#else +static __inline void incrIf( void ) +#endif { /* Technical note : * If the "IF" operator comes just after an "ELSE", its counter * must not be incremented. */ - if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) +#ifdef FIX_1054_IF_ELSE_CMPLX + if ( ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) ) + multiCounter[currCounter].If++; +#else + if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) multiCounter[currCounter].If++; call_occurred = 0; funcId_where_last_call_to_else_occurred = MAXCOUNTERS; +#endif } #endif /* ifndef WMOPS */ @@ -208,26 +224,38 @@ static __inline void incrIf( const char *func_name ) #define ELSE else #else /* ifndef WMOPS */ +#ifdef FIX_1054_IF_ELSE_CMPLX #define ELSE \ else if ( incrElse( __func__ ), 0 ); \ else +#else +#define ELSE \ + else if ( incrElse(), 0 ); \ + else +#endif +#ifdef FIX_1054_IF_ELSE_CMPLX static __inline void incrElse( const char *func_name ) +#else +static __inline void incrElse( void ) +#endif { multiCounter[currCounter].If++; - /* We keep track of the funcId of the last function which used ELSE {...} structure. */ - funcId_where_last_call_to_else_occurred = currCounter; - /* We keep track of the number of WMOPS of this funcId when the ELSE macro was called. */ funcid_total_wmops_at_last_call_to_else = TotalWeightedOperation(); +#ifdef FIX_1054_IF_ELSE_CMPLX /* We keep track of the name of the last calling function when the ELSE macro was called */ strncpy( func_name_where_last_call_to_else_occurred, func_name, MAX_FUNCTION_NAME_LENGTH ); func_name_where_last_call_to_else_occurred[MAX_FUNCTION_NAME_LENGTH] = '\0'; +#else + /* We keep track of the funcId of the last function which used ELSE {...} structure. */ + funcId_where_last_call_to_else_occurred = currCounter; /* call_occurred is set to 0, in order to count the next IF (if necessary) */ call_occurred = 0; +#endif } #endif /* ifndef WMOPS */ diff --git a/lib_com/count.c b/lib_com/count.c index eaf6f04f4..ce38def67 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -365,7 +365,9 @@ void setCounter( int counterId ) return; } currCounter = counterId; +#ifndef FIX_1054_IF_ELSE_CMPLX call_occurred = 1; +#endif #else (void) counterId; #endif /* ifdef WMOPS */ @@ -514,9 +516,11 @@ void Init_WMOPS_counter( void ) LastWOper[currCounter] = 0; funcid[currCounter] = 0; +#ifndef FIX_1054_IF_ELSE_CMPLX /* Following line is useful for incrIf(), see control.h */ call_occurred = 1; funcId_where_last_call_to_else_occurred = MAXCOUNTERS; +#endif sum_bc[currCounter] = MAX_32; sum_wc[currCounter] = 0; diff --git a/lib_com/options.h b/lib_com/options.h index 21e924688..0d78896a5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -198,6 +198,7 @@ #define FIX_999_WRONG_ISM_EXTENDED_METADATA /* VA: fix 999: fix ISM extended metadata decoding */ #define NONBE_FIX_1205_TD_STEREO_MOD_CT /* VA: fix mismatch of coder_type (mod_ct) btw. TD stereo encoder and decoder */ #define NONBE_FIX_1204_MDCT_STEREO_NOISE_EST_SCALING /* FhG: fixes for decoder-side noise level estimation in MDCT-Stereo to prevent noise bursts in stereo switching */ +#define FIX_1054_IF_ELSE_CMPLX /* VA: Fix 1054 incorrect counting of complexity when ELSE-IF sequence is encoutered in two functions */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index e37fecf2e..7bc7bde80 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -187,9 +187,11 @@ void reset_wmops( void ) wmops_caller_stack[i] = -1; } +#ifndef FIX_1054_IF_ELSE_CMPLX /* initialize auxiliary BASOP WMOPS variables */ //call_occurred = 1; //funcId_where_last_call_to_else_occurred = INT_MAX; +#endif return; } -- GitLab From 3eebd11cb860f769bcd0a926b3d69f6c3182a3f0 Mon Sep 17 00:00:00 2001 From: malenov Date: Mon, 9 Dec 2024 13:45:14 +0100 Subject: [PATCH 4/5] reset func_name_where_last_call_to_else_occurred to empty string in each IF statement --- lib_com/control.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_com/control.h b/lib_com/control.h index e515ec3fb..64c708f3c 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -197,7 +197,12 @@ static __inline void incrIf( void ) */ #ifdef FIX_1054_IF_ELSE_CMPLX if ( ( strncmp( func_name, func_name_where_last_call_to_else_occurred, MAX_FUNCTION_NAME_LENGTH ) != 0 ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) ) + { + multiCounter[currCounter].If++; + } + + func_name_where_last_call_to_else_occurred[0] = '\0'; #else if ( ( currCounter != funcId_where_last_call_to_else_occurred ) || ( TotalWeightedOperation() != funcid_total_wmops_at_last_call_to_else ) || ( call_occurred == 1 ) ) multiCounter[currCounter].If++; -- GitLab From 5d00848b3f4f6467622b05369ec88de697d4e90f Mon Sep 17 00:00:00 2001 From: Vladimir Malenovsky Date: Tue, 10 Dec 2024 16:26:43 +0100 Subject: [PATCH 5/5] clang format --- lib_com/control.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_com/control.h b/lib_com/control.h index 64c708f3c..c788cac14 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -234,7 +234,7 @@ static __inline void incrIf( void ) else if ( incrElse( __func__ ), 0 ); \ else #else -#define ELSE \ +#define ELSE \ else if ( incrElse(), 0 ); \ else #endif -- GitLab