Commit f7dbe7fb authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch...

Merge branch '1051-incorrect-complexity-counting-of-certain-if-else-statements-in-the-basop-code' into 'main'

Resolve "Incorrect complexity counting of certain IF-ELSE statements in the BASOP code"

Closes #1051

See merge request !808
parents 26e6dea5 5d00848b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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

+47 −6
Original line number Diff line number Diff line
@@ -33,9 +33,9 @@
#ifndef _CONTROL_H
#define _CONTROL_H

#include <string.h>
#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 */

+4 −0
Original line number Diff line number Diff line
@@ -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;
+1 −0
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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;
}