diff --git a/lib_com/control.c b/lib_com/control.c index 20865de23788f218d0022257b64fe0a2d8c35ad6..dadb2e4967166a786333097c5102c3745397d491 100644 --- a/lib_com/control.c +++ b/lib_com/control.c @@ -21,10 +21,14 @@ #include "stl.h" #ifdef WMOPS -int funcId_where_last_call_to_else_occurred; long funcid_total_wmops_at_last_call_to_else; +#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 ad1e5ae6929c43918f6b9438232418ee31e1082b..c788cac140d174f56799e577ec66d7355dfe4f91 100644 --- a/lib_com/control.h +++ b/lib_com/control.h @@ -33,9 +33,9 @@ #ifndef _CONTROL_H #define _CONTROL_H +#include #include "stl.h" - /***************************************************************************** * * Constants and Globals @@ -45,6 +45,12 @@ extern BASIC_OP multiCounter[MAXCOUNTERS]; extern int currCounter; +#define MAX_FUNCTION_NAME_LENGTH 200 /* Maximum length of the function name */ + +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 : @@ -60,9 +66,10 @@ extern int currCounter; * ... * } */ -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 */ @@ -172,19 +179,37 @@ 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. */ +#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++; call_occurred = 0; funcId_where_last_call_to_else_occurred = MAXCOUNTERS; +#endif } #endif /* ifndef WMOPS */ @@ -204,22 +229,38 @@ static __inline void incrIf( void ) #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 eaf6f04f422786a7f67642b6e3bfca292eb2afde..ce38def6716e73c2ccb0ce7f15913873d698f0dd 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 c74d7af3467b351490a440d76adbb4aae681e0a0..0ae5cf8ca1470da7221c88047349f832dc5d334c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,4 +83,5 @@ #define NONE_BE_FIX_BASOP_1044_OSBA_PRERENDER_MIX_GAINS /* DLB: adjust prerendering and mixing gain in OSBA encoder. This is fix to float codes*/ #define NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO /* Eri: issue 1233: Address possible division by zero in hf_spectrum_sparseness() */ #define FIX_ISSUE_1062_AND_1068_TON_ENE_EST_FX +#define FIX_1054_IF_ELSE_CMPLX /* VA: Fix 1054 incorrect counting of complexity when ELSE-IF sequence is encoutered in two functions */ #endif diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index e37fecf2ebdec6b1fead6dccf0df4e8ff5bc321c..7bc7bde807706e5faf6efff00a9846e8f1e59b0d 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; }