From e42283d6389378feaef863d663570ca6e7d99abe Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 29 Jan 2024 16:19:34 -0500 Subject: [PATCH 01/11] make the decoder to compile with fixed point complexity enabled --- apps/decoder.c | 67 ++++++++++++++++---- lib_com/count.h | 4 +- lib_com/move.h | 10 ++- lib_com/move.h.bak | 94 ++++++++++++++++++++++++++++ lib_com/options.h | 2 +- lib_com/stl.h | 3 +- lib_debug/wmc_auto.c | 6 +- lib_debug/wmc_auto.h | 10 +-- lib_dec/TonalComponentDetection_fx.c | 1 + lib_dec/ivas_jbm_dec.c | 4 ++ lib_dec/tonalMDCTconcealment_fx.c | 1 + 11 files changed, 176 insertions(+), 26 deletions(-) create mode 100644 lib_com/move.h.bak diff --git a/apps/decoder.c b/apps/decoder.c index f9f681bd4..58df9a702 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -53,7 +53,7 @@ * Local constants *------------------------------------------------------------------------------------------*/ -#if !defined( WMOPS ) +#if !defined( WMOPS_FLT ) static #endif int32_t frame = 0; /* Counter of frames */ @@ -76,7 +76,12 @@ static /*------------------------------------------------------------------------------------------* * Local structure for storing cmdln arguments *------------------------------------------------------------------------------------------*/ - +#ifdef WMOPS +#include "stl.h" +extern int currCounter; +int idxG192; +int idxVOIP; +#endif typedef struct { char *inputBitstreamFilename; @@ -160,11 +165,15 @@ int main( IVAS_RENDER_FRAMESIZE asked_frame_size; int16_t run_unit_tests = 0; -#ifdef WMOPS +#ifdef WMOPS_FLT reset_wmops(); reset_mem( USE_BYTES ); #endif - +#if ( WMOPS ) + Init_WMOPS_counter(); + Reset_WMOPS_counter(); + setFrameRate( 48000, 960 ); +#endif /*------------------------------------------------------------------------------------------* * Parse command-line arguments *------------------------------------------------------------------------------------------*/ @@ -628,7 +637,7 @@ cleanup: fprintf( stderr, "\nError while closing file: %s\nContinuing...\n\n", arg.inputBitstreamFilename ); } -#ifdef WMOPS +#ifdef WMOPS_FLT print_wmops(); print_mem( NULL ); #endif @@ -1526,10 +1535,18 @@ static ivas_error decodeG192( delayNumSamples_orig[0] = -1; -#ifdef WMOPS +#ifdef WMOPS_FLT reset_stack(); reset_wmops(); #endif +#ifdef WMOPS + //BASOP_end_noprint; + //BASOP_init; + Init_WMOPS_counter(); + Reset_WMOPS_counter(); + setFrameRate( 48000, 960 ); +#endif + nSamplesAvailableNext = 0; vec_pos_update = 0; @@ -1555,7 +1572,10 @@ static ivas_error decodeG192( while ( 1 ) { /* Read next frame if not enough samples availble */ - +#if ( WMOPS ) + fwc(); + Reset_WMOPS_counter(); +#endif /* reference vector */ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) { @@ -1671,13 +1691,18 @@ static ivas_error decodeG192( goto cleanup; } } - +#ifdef WMOPS +SUB_WMOPS_INIT( "IVAS_DEC_GetSamples" ); +#endif if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } +#ifdef WMOPS +END_SUB_WMOPS; +#endif nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; if ( needNewFrame ) @@ -1783,7 +1808,7 @@ static ivas_error decodeG192( } } vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; -#ifdef WMOPS +#ifdef WMOPS_FLT if ( vec_pos_update == 0 ) { update_wmops(); @@ -1792,6 +1817,16 @@ static ivas_error decodeG192( export_mem( "mem_analysis.csv" ); #endif } +#endif +#ifdef WMOPS + if ( vec_pos_update == 0 ) + { + /* update WMPOS counting (end of frame) */ + //BASOP_frame_update(); +#if ( WMOPS ) + fwc(); +#endif + } #endif } @@ -1972,9 +2007,15 @@ static ivas_error decodeG192( *------------------------------------------------------------------------------------------*/ decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ - + //BASOP_end cleanup: - + /* free memory etc. */ +#ifdef WMOPS + fwc(); + printf( "\ndecoder complexity\n" ); + WMOPS_output( 0 ); + printf( "\n" ); +#endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) @@ -2163,7 +2204,7 @@ static ivas_error decodeVoIP( fprintf( stdout, "\n-- Start the decoder (quiet mode) --\n\n" ); } -#ifdef WMOPS +#ifdef WMOPS_FLT reset_stack(); reset_wmops(); #endif @@ -2446,7 +2487,7 @@ static ivas_error decodeVoIP( frame++; systemTime_ms += systemTimeInc_ms; -#ifdef WMOPS +#ifdef WMOPS_FLT update_mem(); update_wmops(); #endif diff --git a/lib_com/count.h b/lib_com/count.h index 4e853d6f4..b8b7ed5c4 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -59,9 +59,9 @@ #ifndef _COUNT_H #define _COUNT_H "$Id$" -#if 0 +#if 1 #define WMOPS 1 /* enable WMOPS profiling features */ -#undef WMOPS /* disable WMOPS profiling features */ +//#undef WMOPS /* disable WMOPS profiling features */ #endif #define MAXCOUNTERS (256) diff --git a/lib_com/move.h b/lib_com/move.h index 21f34e2a1..afe73d537 100644 --- a/lib_com/move.h +++ b/lib_com/move.h @@ -36,9 +36,14 @@ #ifndef _MOVE_H #define _MOVE_H - +#include "stl.h" /* BASOP -> FLC brigde: data move counting */ +#if (WMOPS) +extern BASIC_OP multiCounter[MAXCOUNTERS]; +extern int currCounter; +#endif /* ifdef WMOPS */ + static __inline void move16( void ) { #ifdef WMOPS @@ -55,6 +60,9 @@ static __inline void move32( void ) #ifdef ENH_64_BIT_OPERATOR static __inline void move64(void) { +#ifdef WMOPS + multiCounter[currCounter].move64++; +#endif /* if WMOPS */ } #endif /* #ifdef ENH_64_BIT_OPERATOR */ diff --git a/lib_com/move.h.bak b/lib_com/move.h.bak new file mode 100644 index 000000000..81b4c7d60 --- /dev/null +++ b/lib_com/move.h.bak @@ -0,0 +1,94 @@ +/****************************************************************************************************** + + (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ + +/*==================================================================================== + EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 + ====================================================================================*/ + +#ifndef _MOVE_H +#define _MOVE_H +#include "stl.h" +/* BASOP -> FLC brigde: data move counting */ + +static __inline void move16( void ) +{ +#ifdef WMOPS + multiCounter[currCounter].move16++; +#endif +} + +static __inline void move32( void ) +{ +#ifdef WMOPS + multiCounter[currCounter].move32++; +#endif +} + +#ifdef ENH_64_BIT_OPERATOR +static __inline void move64(void) { +#ifdef WMOPS + multiCounter[currCounter].move64++; +#endif /* if WMOPS */ +} +#endif /* #ifdef ENH_64_BIT_OPERATOR */ + +static __inline void test( void ) +{ +#ifdef WMOPS + multiCounter[currCounter].Test++; +#endif +} + +static __inline void logic16( void ) +{ +#ifdef WMOPS + multiCounter[currCounter].Logic16++; +#endif +} + +static __inline void logic32( void ) +{ +#ifdef WMOPS + multiCounter[currCounter].Logic32++; +#endif +} + +/*-------- legacy ----------*/ +#define data_move() move16() +#define L_data_move() move32() +#define data_move_external() move16() +#define compare_zero() test() +/*-------- end legacy ----------*/ + +#define cast16 move16 + +#endif /* _MOVE_H */ diff --git a/lib_com/options.h b/lib_com/options.h index 099a28570..7e9ea311c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -53,7 +53,7 @@ #pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ #endif -/*#define WMOPS*/ /* Activate complexity and memory counters */ +#define WMOPS 1 /* Activate complexity and memory counters */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ diff --git a/lib_com/stl.h b/lib_com/stl.h index a94ab6ec6..3a0127760 100644 --- a/lib_com/stl.h +++ b/lib_com/stl.h @@ -71,7 +71,8 @@ #include "options.h" /* note: needed until BASOP_NOGLOB is accepted */ #include "typedef.h" #include "basop32.h" -#include "wmc_auto.h" +#include "count.h" +//#include "wmc_auto.h" #include "move.h" #include "control.h" #include "oper_32b.h" diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index 029640a1d..eafa02a2e 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -31,8 +31,7 @@ #define WMC_TOOL_SKIP /* Skip the instrumentation of this file, if invoked by accident */ -#ifdef WMOPS - +#ifdef WMOPS_FLT /*-------------------------------------------------------------------* * Complexity counting tool *--------------------------------------------------------------------*/ @@ -1921,6 +1920,7 @@ void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] ) #endif /* WMOPS */ -#ifndef WMOPS +#ifndef WMOPS_FLT int cntr_push_pop = 0; /* global counter for checking balanced push_wmops()/pop_wmops() pairs when WMOPS is not activated */ +double ops_cnt; #endif diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 9e20a4c7c..8bc6dba8c 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -37,7 +37,7 @@ #define NUM_INST 20 /* Total number of instruction types (in enum below) */ -#ifdef WMOPS +#ifdef WMOPS_FLT enum instructions { _ADD, @@ -571,7 +571,7 @@ void update_mem( void ); void print_wmops( void ); #else /* WMOPS counting disabled */ - +#include #define reset_wmops() extern int cntr_push_pop; #define push_wmops( x ) ( cntr_push_pop++ ) @@ -622,7 +622,7 @@ extern int cntr_push_pop; #define msu( a, b, c ) ( ( a ) - ( b ) * ( c ) ) #endif -#ifndef WMOPS +#ifndef WMOPS_FLT /* DESACTIVATE the Counting Mechanism */ #define OP_COUNT_( op, n ) @@ -795,7 +795,7 @@ static int wmc_flag_ = 0; switch #define cost_( n ) OP_COUNT_WRAPPER2_( wmc_flag_ ? ( ADD_( n ), BRANCH_( n ), wmc_flag_ = 0 ) : 0 ); -#ifdef WMOPS +#ifdef WMOPS_FLT #define ACC 2 #define MUL 1 @@ -996,7 +996,7 @@ typedef enum #endif -#ifdef WMOPS +#ifdef WMOPS_FLT void *mem_alloc( const char *func_name, int func_lineno, size_t size, char *alloc_str ); void mem_free( const char *func_name, int func_lineno, void *ptr ); diff --git a/lib_dec/TonalComponentDetection_fx.c b/lib_dec/TonalComponentDetection_fx.c index ccc1421d6..eb3ba5f01 100644 --- a/lib_dec/TonalComponentDetection_fx.c +++ b/lib_dec/TonalComponentDetection_fx.c @@ -14,6 +14,7 @@ #include "rom_com.h" #include "basop_util.h" + /*---------------------------------------------------------------------* * Local function prototypes *---------------------------------------------------------------------*/ diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 329ae0059..5fa094dce 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -60,6 +60,10 @@ static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas ); static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t nCldfbTs ); +#ifdef WMOPS_FX +extern int currCounter; +int idxId; +#endif /*--------------------------------------------------------------------------* * ivas_jbm_dec_tc() diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 9da79f6fa..630393b8b 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -15,6 +15,7 @@ #include "prot_fx2.h" #include "stat_com.h" #include "prot.h" +#include "wmc_auto.h" #define CROSSFADE_THRESHOLD (32762) // close to 1.0f in Q15 such that (x == 1.0f) is true -- GitLab From 0e755f9e31a3dd674533cf738faa70cc7505a166 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Mon, 29 Jan 2024 18:29:47 -0500 Subject: [PATCH 02/11] add improvment similar to FLC to easy the usage of wmops complexity counter --- apps/decoder.c | 13 +- lib_com/count.c | 692 ++++++++++++++++++++++++++++++++++++++++++++- lib_com/count.h | 75 +++-- lib_com/move.h.bak | 94 ------ lib_com/options.h | 1 + 5 files changed, 753 insertions(+), 122 deletions(-) delete mode 100644 lib_com/move.h.bak diff --git a/apps/decoder.c b/apps/decoder.c index 58df9a702..d9d7a7783 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1513,7 +1513,14 @@ static ivas_error decodeG192( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; +#ifdef WMOPS + int GetId, GetTCId, cheId; + /* initiate counters and objects */ + GetId = getCounterId( "IVAS_DEC_GetSamples" ); + GetTCId = getCounterId( "IVAS_DEC_GetTCSamples" ); + cheId = getCounterId( "ivas_jbm_dec_tc" ); +#endif for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { ismWriters[i] = NULL; @@ -1824,6 +1831,7 @@ END_SUB_WMOPS; /* update WMPOS counting (end of frame) */ //BASOP_frame_update(); #if ( WMOPS ) + //WMOPS_output( 0 ); fwc(); #endif } @@ -2011,9 +2019,10 @@ END_SUB_WMOPS; cleanup: /* free memory etc. */ #ifdef WMOPS - fwc(); - printf( "\ndecoder complexity\n" ); WMOPS_output( 0 ); + fwc(); + printf( "\ndecoder complexity\n" ); + generic_WMOPS_output( 0, "dec_complx.txt" ); printf( "\n" ); #endif AudioFileWriter_close( &afWriter ); diff --git a/lib_com/count.c b/lib_com/count.c index edb33a24d..ada2c8b91 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -47,7 +47,7 @@ #include #include #include "stl.h" - +#include #ifdef WMOPS static double frameRate = FRAME_RATE; /* default value : 10 ms */ #endif /* ifdef WMOPS */ @@ -55,6 +55,9 @@ static double frameRate = FRAME_RATE; /* default value : 10 ms */ #ifdef WMOPS /* Global counter variable for calculation of complexity weight */ BASIC_OP multiCounter[MAXCOUNTERS]; +#ifdef FROM_EVS_DEV +BASIC_OP glob_multiCounter; +#endif int currCounter = 0; /* Zero equals global counter */ #endif /* ifdef WMOPS */ @@ -320,20 +323,69 @@ Word32 DeltaWeightedOperation (void); #ifdef WMOPS /* Counters for separating counting for different objects */ - +#ifdef FROM_EVS_DEV +/** + maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. + objectName: Name of each counter passed to BASOP_sub_start(). + fwc_corr: + nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. + */ +#endif static int maxCounter = 0; static char *objectName[MAXCOUNTERS + 1]; static Word16 fwc_corr[MAXCOUNTERS + 1]; static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; -#define NbFuncMax 1024 +#ifndef FROM_EVS_DEV +#define NbFuncMax 1024 static Word16 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS]; static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax]; +#else +#define NbFuncMax (5000L*20L) + + +/** + funcid: current function call for each counter + bc : best case for each counter and function call + wc : worst case for each counter and function call + nbframe: number of frames for each counter. + glob_bc: global best case self time for each counter for current frame. + glob_wc: global worst case self time for each counter for current frame. + glob_sum_curr: global cummulative time for each counter for current frame. + glob_sum_bc: global best case cummulative time for each counter for current frame. + glob_sum_wc: global worst case cummulative time for each counter for current frame. + + total_wmops: total wmops self time for each counter for current frame. + total_sum: total wmops cummulative time for each counter for current frame. + LastWOper: values used for WMOPS deltas + */ + +static Word32 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS], nbcalls[MAXCOUNTERS]; +static Word32 glob_bc[MAXCOUNTERS], glob_wc[MAXCOUNTERS], bc[MAXCOUNTERS][NbFuncMax], wc[MAXCOUNTERS][NbFuncMax]; + +#endif static float total_wmops[MAXCOUNTERS]; static Word32 LastWOper[MAXCOUNTERS]; +#ifdef FROM_EVS_DEV + +static float total_sum[MAXCOUNTERS]; +static Word16 call_tree[MAXCOUNTERS][MAXCOUNTERS]; +static int sum_curr[MAXCOUNTERS+1]; +static int sum_bc[MAXCOUNTERS+1]; +static int sum_wc[MAXCOUNTERS+1]; +static int glob_sum_curr[MAXCOUNTERS+1]; +static int glob_sum_bc[MAXCOUNTERS+1]; +static int glob_sum_wc[MAXCOUNTERS+1]; +#if MAX_CALLERS_SAVED_FRAMES +#define MAX_CALLERS_PRINT 20 +static float callers_frames[MAX_CALLERS_SAVED_FRAMES+1][MAXCOUNTERS+1]; +static int callers_frames_nos[MAX_CALLERS_SAVED_FRAMES]; +static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; +#endif +#endif #endif /* ifdef WMOPS */ @@ -429,7 +481,10 @@ static Word32 WMOPS_frameStat (void) { tot = TotalWeightedOperation (); if (tot > glob_wc[currCounter]) glob_wc[currCounter] = tot; - +#ifdef FROM_EVS_DEV + if (tot < glob_bc[currCounter]) + glob_bc[currCounter] = tot; +#endif /* check if fwc() was forgotten at end of last frame */ if (tot > LastWOper[currCounter]) { if (!fwc_corr[currCounter]) { @@ -515,7 +570,11 @@ void Init_WMOPS_counter (void) { glob_wc[currCounter] = 0; nbframe[currCounter] = 0; total_wmops[currCounter] = 0.0; - +#ifdef FROM_EVS_DEV + glob_bc[currCounter] = MAX_32; + nbcalls[currCounter] = 0; + total_sum[currCounter] = 0.0; +#endif /* initially clear all counters */ WMOPS_clearMultiCounter (); LastWOper[currCounter] = 0; @@ -524,11 +583,35 @@ void Init_WMOPS_counter (void) { /* Following line is useful for incrIf(), see control.h */ call_occurred = 1; funcId_where_last_call_to_else_occurred = MAXCOUNTERS; + +#ifdef FROM_EVS_DEV + for (i = 0; i < NbFuncMax; i++) + { + bc[currCounter][i] = (Word32)MAX_32; + } + + sum_bc[currCounter] = MAX_32; + sum_wc[currCounter] = 0; + sum_curr[currCounter] = 0; + for (i = 0; i < MAXCOUNTERS; i++) + { + call_tree[currCounter][i] = -1; + } + + glob_sum_curr[currCounter] = 0; + glob_sum_wc[currCounter] = 0; + glob_sum_bc[currCounter] = MAX_32; +#endif + #endif /* ifdef WMOPS */ } +#ifdef FROM_EVS_DEV +Word32 Reset_WMOPS_counter(void) { +#else void Reset_WMOPS_counter (void) { +#endif #if WMOPS Word32 tot = WMOPS_frameStat (); @@ -537,11 +620,22 @@ void Reset_WMOPS_counter (void) { /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ total_wmops[currCounter] += (float) (tot * frameRate); +#ifdef FROM_EVS_DEV + /* Call counter */ + nbcalls[currCounter] += funcid[currCounter]; + total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); +#endif /* clear counter before new frame starts */ WMOPS_clearMultiCounter (); LastWOper[currCounter] = 0; funcid[currCounter] = 0; /* new frame, set function id to zero */ +#ifdef FROM_EVS_DEV + glob_sum_curr[currCounter] = 0; + sum_curr[currCounter] = 0; + return tot; +#endif + #endif /* ifdef WMOPS */ } @@ -554,13 +648,21 @@ Word32 fwc (void) { tot = DeltaWeightedOperation (); if (tot > wc[currCounter][funcid[currCounter]]) wc[currCounter][funcid[currCounter]] = tot; - +#ifdef FROM_EVS_DEV + if (tot < bc[currCounter][funcid[currCounter]]) + bc[currCounter][funcid[currCounter]] = tot; +#endif funcid[currCounter]++; - return (tot); - +#ifdef FROM_EVS_DEV + /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ + if (funcid[currCounter] >= NbFuncMax) { + printf("to many function calls\n"); + } + assert(funcid[currCounter] < NbFuncMax); + return (tot); #else /* ifdef WMOPS */ return 0; /* Dummy */ - +#endif #endif /* ifdef WMOPS */ } @@ -596,7 +698,6 @@ void WMOPS_output (Word16 dtx_mode) { #endif /* ifdef WMOPS */ } - void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word16 * num_frames) { #if WMOPS Word16 i; @@ -767,6 +868,577 @@ void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) { (void)test_file_name; #endif /* ifdef WMOPS */ } +#ifdef FROM_EVS_DEV + +#define MAX_STACK 64 +static int stack[MAX_STACK]; +static int sptr; +static int sum_stack[MAX_STACK]; + +/* jdr 20120117: add FLC similar functions */ +void BASOP_frame_update(void) +{ +#if WMOPS + int i, current; +#if MAX_CALLERS_SAVED_FRAMES + int k; +#endif + float total = 0.0f; + +#ifdef DEBUG + { + static int sptr_target=-2; + + if (sptr_target == -2) { + sptr_target = sptr; + } else { + if (sptr_target != sptr) { + fprintf(stderr, "BASOP_sub_start/BASOP_sub_end imbalance detected!!!\n"); + sptr_target = sptr; + } + } + } +#endif + + /* Get current counter */ + current = readCounterId(); + + /* Update global operation counters */ + for (i=1; i<=maxCounter; i++) + { + int j; + + for (j=0; j< (int)(sizeof(BASIC_OP)/sizeof(UWord32)); j++) + { + ((UWord32*)&glob_multiCounter)[j] += ((UWord32*)&multiCounter[i])[j]; + } + } + +#if MAX_CALLERS_SAVED_FRAMES + /* Reset all counters */ + for (i=1; i<=maxCounter; i++) + { + callers_frames[0][i] = 0.0f; + } +#endif + /* Reset all counters */ + for (i=1; i<=maxCounter; i++) + { + if (current != i && funcid[i] > 0) { + setCounter(i); + + glob_sum_curr[currCounter] += sum_curr[currCounter]; + + if (glob_sum_curr[currCounter] > glob_sum_wc[currCounter]) { + glob_sum_wc[currCounter] = glob_sum_curr[currCounter]; + } + if (glob_sum_curr[currCounter] < glob_sum_bc[currCounter]) { + glob_sum_bc[currCounter] = glob_sum_curr[currCounter]; + } +#if MAX_CALLERS_SAVED_FRAMES + /* Keep a Copy before it is Reset */ + callers_frames[0][currCounter] = (float)Reset_WMOPS_counter(); + total += callers_frames[0][currCounter]; +#else + total += (float)Reset_WMOPS_counter(); +#endif + } + } + +#if MAX_CALLERS_SAVED_FRAMES + /* Keep Callers for this Worst Case Frame */ + /* Select Slot to Use (Slot 0 is the Current) */ + k = 0; + for (i=k+1; i callers_totals[k]) + { + k+=1; + /* Save Info of Callers */ + for (i=1; i<=maxCounter; i++) + { + callers_frames[k][i] = callers_frames[0][i]; + } + if (i < MAXCOUNTERS) + callers_frames[k][i] = -1; + /* Save Total */ + callers_totals[k-1] = total; + /* Save Frame Number */ + callers_frames_nos[k-1] = nbframe[0]; + } +#endif + if (total < glob_bc[0]) { + glob_bc[0] = (Word32) total; + } + if (total > glob_wc[0]) { + glob_wc[0] = (Word32) total; + + } + /* Restore current counter */ + setCounter(current); + + nbframe[0] ++; +#endif /* if WMOPS */ +} + +void printStack(char *text, char* Id) +{ +#if WMOPS + int i; + if (!Id) return; + if (!strcmp("*", Id) || (!strcmp(Id,objectName[currCounter]))) + { + printf ("%s %s", text, objectName[currCounter]); + for (i=sptr-1; i>0; i--) { + printf(" <- %s", objectName[stack[i]]); + } + printf("\n"); + } +#else + printf("%s %s\n", text, Id ? Id : "(no name)"); +#endif +} + +void BASOP_push_wmops (const char *label) +{ +#if WMOPS + int new_flag, prev_counter; + int i, j; + + /* Check if new counter label */ + new_flag = 1; + for (i = 1; i <= maxCounter; i++) + { + if (strcmp(objectName[i], label) == 0) + { + new_flag = 0; + break; + } + } + + prev_counter = readCounterId(); + + /* Configure new record */ + if (new_flag) + { + i = (int)getCounterId(label); + setCounter(i); + Init_WMOPS_counter(); + } + else + { + setCounter(i); + } + + + /* Push current context onto stack */ + if (currCounter >= 0) + { + if (sptr >= MAX_STACK) + { + fprintf (stderr, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n"); + exit (-1); + } + stack[sptr++] = prev_counter; + + /* Reset accumulated WMOPS */ + sum_stack[sptr] = 0; + + /* update call tree */ + for (j = 0; j < MAXCOUNTERS; j++) + { + if (call_tree[i][j] == prev_counter) + { + break; + } + else if (call_tree[i][j] == -1) + { + call_tree[i][j] = prev_counter; + break; + } + } + } + + /*wmops[currCounter].start_selfcnt = ops_cnt; + wmops[currCounter].start_cnt = ops_cnt; + nbTimeObjectIsCalled[currCounter]++;*/ + + incrementNbTimeObjectIsCalled(currCounter); + + sum_curr[currCounter] = 0; + +#ifdef DEBUG_COUNTER + printf("Entering: %s\n", readCounterIdName()); +#endif + +#endif /* if WMOPS */ +} + + +Word32 BASOP_pop_wmops (void) +{ +#if WMOPS + Word32 ops_cnt; + +#ifdef DEBUG_COUNTER + printf("Exiting: %s\n", readCounterIdName()); +#endif + + ops_cnt = fwc(); + + /* Get back previous context from stack */ + if (sptr > 0) + { + int prevCounter; + + sum_stack[sptr] += ops_cnt; + prevCounter = currCounter; + setCounter(stack[--sptr]); + sum_stack[sptr] += sum_stack[sptr+1]; + sum_curr[prevCounter] += sum_stack[sptr+1]; + } + else + { + /* current_record = -1; */ + setCounter(0); + } + + if (sum_curr[currCounter] > sum_wc[currCounter]) { + sum_wc[currCounter] = sum_curr[currCounter]; + } + if (sum_curr[currCounter] < sum_bc[currCounter]) { + sum_bc[currCounter] = sum_curr[currCounter]; + } + + return ops_cnt; +#else /* if WMOPS */ + return 0; +#endif /* if WMOPS */ +} + +Word32 BASOP_get_wops (void) +{ + return BASOP_pop_wmops(); +} + +#define FRAMES_PER_SECOND 50.0 +#define MILLION_CYCLES 1e6 +#define FAC (FRAMES_PER_SECOND/MILLION_CYCLES) + +static Word32 prom_cnt = 0; + +void WMOPS_destroy(void) +{ +#if WMOPS + int i; + + /* release the memory allocated for the objectName array */ + for (i = 0; i < MAXCOUNTERS+1; i++) + { + if (NULL != objectName[i]) + { + free(objectName[i]); + objectName[i] = NULL; + } + } + + maxCounter = 0; +#endif + + return; +} + + +void WMOPS_output_all(Word16 dtx_mode) +{ +#if WMOPS + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf (stderr, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); + /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf (stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ + for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) + { + fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); + } + + fprintf (stderr, "\n\nWeighted MOPS Analysis:\n"); + fprintf (stderr, "%74s %23s\n", "|------ SELF ------|" + ,"|--- CUMULATIVE ---|"); + fprintf (stderr, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); + fprintf (stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); + for (i = 1; i <= maxCounter; i++) + { + fprintf (stderr, dfmt, + objectName[i], + (nbframe[i] == 0) ? 0 : (float)nbcalls[i]/(float)nbframe[0], + (glob_bc[i] == 0) ? 0 : frameRate*(float)glob_bc[i], + (glob_wc[i] == 0) ? 0 : frameRate*(float)glob_wc[i], + (nbframe[i] == 0) ? 0 : (float)total_wmops[i]/(float)nbframe[i], + frameRate*(glob_sum_bc[i]), + frameRate*(glob_sum_wc[i]), + (nbframe[i] == 0) ? 0 : (float)(total_sum[i] /(float)nbframe[i])); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ + + ops_cnt += total_wmops[i]; + } + + fprintf (stderr, sfmts, " -----------------", " ------", "------", "------", "------"); + fprintf (stderr, dfmts, + "total", + (double)nbframe[0], + frameRate*glob_bc[0], + frameRate*glob_wc[0], + (nbframe[0] == 0) ? 0 : ops_cnt/nbframe[0]); + +#if 0 + { + char *sfmtt = "%20s %4s %15s\n"; + char *dfmtt = "%20s %4d "; + + fprintf (stderr, "\nCall Tree:\n\n"); + fprintf (stderr, sfmtt, " function", "num", "called by: "); + fprintf (stderr, sfmtt, "---------------", "---", "--------------"); + + for (i = 1; i <= maxCounter; i++) + { + int j; + + fprintf (stderr, dfmtt, objectName[i], i); + for (j = 0; call_tree[i][j] != -1; j++) + { + if (j != 0) + { + fprintf (stderr, ", "); + } + fprintf (stderr, "%s", objectName[call_tree[i][j]]); + } + fprintf (stderr, "\n"); + + } + fprintf (stderr, sfmtt, "---------------", "---", "--------------"); + fprintf (stderr, "\n\n"); + } +#endif + +#if 0 + fprintf (stderr, "\n\n"); + for (i=1; i<=maxCounter; i++) + { + setCounter(i); + WMOPS_output(dtx_mode); + } +#else + (void)dtx_mode; +#endif + +#if MAX_CALLERS_SAVED_FRAMES + for (i = 1; i <= MAX_CALLERS_SAVED_FRAMES; i++) + { + int j, k, l, m; + const char *frame_rank[] = { "st", "nd", "rd", "th" }; + float current; + + k = 0; + for (j=k+1; j callers_totals[k]) + { /* Yes */ + k = j; + } + } + k+=1; + + fprintf(stderr, "\nActive Callers Report for %i%s Worst Case Frame #: %i\n", + i, i<=3?frame_rank[i-1]:frame_rank[3], + callers_frames_nos[k-1]); + /* Print up to 'MAX_CALLERS_PRINT' Callers */ + current = 0.0f; + for (l = 0; l < MAX_CALLERS_PRINT; l++) + { + /* Find Highest Complexity */ + m = 1; + for (j = m+1; j <= maxCounter; j++) + { + if (callers_frames[k][j] < 0) + break; + if (callers_frames[k][j] > callers_frames[k][m]) + m = j; + } + /* Done ? */ + if (callers_frames[k][m] == 0) + break; + fprintf(stderr, " %-52s %10.3f\n", objectName[m], callers_frames[k][m]*frameRate); + /* Count it */ + current += callers_frames[k][m]; + /* Mark as Done */ + callers_frames[k][m] = 0.0f; + } + /* Check if All Printed */ + if (current+0.001f < callers_totals[k-1]) + { + fprintf(stderr, " Only first %i Callers have been Printed!\n", MAX_CALLERS_PRINT); + fprintf(stderr, " %-52s %10.3f\n", "Total for non Printed", (callers_totals[k-1]-current)*frameRate); + } + fprintf(stderr, " %-52s %10.3f\n", "Total", callers_totals[k-1]*frameRate); + /* Mark as Done */ + callers_totals[k-1] = 0.0f; + } +#endif + WMOPS_destroy(); + +#endif /* if WMOPS */ +} +void WMOPS_output_all_std(Word16 dtx_mode) +{ +#if WMOPS + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf (stdout, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); + /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf (stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ + for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) + { + fprintf (stdout, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); + } + + fprintf (stdout, "\n\nWeighted MOPS Analysis:\n"); + fprintf (stdout, "%74s %23s\n", "|------ SELF ------|" + ,"|--- CUMULATIVE ---|"); + fprintf (stdout, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); + fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); + for (i = 1; i <= maxCounter; i++) + { + fprintf (stdout, dfmt, + objectName[i], + (nbframe[i] == 0) ? 0 : (float)nbcalls[i]/(float)nbframe[0], + (glob_bc[i] == 0) ? 0 : frameRate*(float)glob_bc[i], + (glob_wc[i] == 0) ? 0 : frameRate*(float)glob_wc[i], + (nbframe[i] == 0) ? 0 : (float)total_wmops[i]/(float)nbframe[i], + frameRate*(glob_sum_bc[i]), + frameRate*(glob_sum_wc[i]), + (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ + + ops_cnt += total_wmops[i]; + } + + fprintf (stdout, sfmts, " -----------------", " ------", "------", "------", "------"); + fprintf (stdout, dfmts, + "total", + (double)nbframe[0], + frameRate*glob_bc[0], + frameRate*glob_wc[0], + (nbframe[0] == 0) ? 0 : ops_cnt/nbframe[0]); + +#if 0 + { + char *sfmtt = "%20s %4s %15s\n"; + char *dfmtt = "%20s %4d "; + + fprintf (stdout, "\nCall Tree:\n\n"); + fprintf (stdout, sfmtt, " function", "num", "called by: "); + fprintf (stdout, sfmtt, "---------------", "---", "--------------"); + + for (i = 1; i <= maxCounter; i++) + { + int j; + + fprintf (stdout, dfmtt, objectName[i], i); + for (j = 0; call_tree[i][j] != -1; j++) + { + if (j != 0) + { + fprintf (stdout, ", "); + } + fprintf (stdout, "%s", objectName[call_tree[i][j]]); + } + fprintf (stdout, "\n"); + + } + fprintf (stdout, sfmtt, "---------------", "---", "--------------"); + fprintf (stdout, "\n\n"); + } +#endif + +#if 0 + fprintf (stdout, "\n\n"); + for (i=1; i<=maxCounter; i++) + { + setCounter(i); + WMOPS_output(dtx_mode); + } +#else + (void)dtx_mode; +#endif + + + WMOPS_destroy(); + +#endif /* if WMOPS */ +} + +void Reset_all_WMOPS_counter (void) +{ +#if WMOPS + int i; + int currCounterSave; + + currCounterSave = currCounter; + for (i=2; i <= maxCounter; i++) + { + setCounter(i); + Init_WMOPS_counter(); + objectName[i] = 0; + } + + currCounter = currCounterSave; + maxCounter = 1; +#endif /* if WMOPS */ +} + +/* Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ +void BASOP_get_total_wmops(double *min, double *max, double *avg) +{ +#if WMOPS + if(min != NULL) + *min = frameRate * glob_bc[0]; + if(max != NULL) + *max = frameRate * glob_wc[0]; + if(avg != NULL) { + int i; + double ops_cnt = 0; + for(i = 1; i <= maxCounter; i++) + ops_cnt += total_wmops[i]; + *avg = (nbframe[0] == 0) ? 0 : ops_cnt / nbframe[0]; + } +#endif /* if WMOPS */ +} +#endif /* end of file */ diff --git a/lib_com/count.h b/lib_com/count.h index b8b7ed5c4..e12840ccb 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -63,18 +63,10 @@ #define WMOPS 1 /* enable WMOPS profiling features */ //#undef WMOPS /* disable WMOPS profiling features */ #endif -#define MAXCOUNTERS (256) - - -#define BASOP_sub_start(label) -#define BASOP_sub_end() -#define SUB_WMOPS_INIT(label) BASOP_sub_start(label) -#define END_SUB_WMOPS BASOP_sub_end() -#define BASOP_push_wmops(label) -#define BASOP_pop_wmops() -#define BASOP_end_noprint -#define BASOP_end -#define BASOP_init +#define MAXCOUNTERS (512) +#ifdef FROM_EVS_DEV +#define MAX_CALLERS_SAVED_FRAMES 5 /* # of Frame for which WMOPS Complexity Details will be saved, 0 = Disabled */ +#endif int getCounterId (char *objectName); /* @@ -101,7 +93,16 @@ char *readCounterIdName (void); /* * Returns the current CounterId name. */ - +#ifdef FROM_EVS_DEV +void printStack(char *text, char * Id); +/* + * print stack + * text: Any text to print initially + * Id: NULL, if no prints are wanted + * "*", if all prints are wanted (default) + * "pitch_ol" or any other function name + */ +#endif void incrementNbTimeObjectIsCalled (int counterId); /* @@ -126,8 +127,12 @@ void Init_WMOPS_counter (void); */ -void Reset_WMOPS_counter (void); -/* +#ifdef FROM_EVS_DEV +Word32 Reset_WMOPS_counter( void ); +#else +void Reset_WMOPS_counter( void ); +#endif + /* * Resets the current counter group. */ @@ -482,8 +487,15 @@ void generic_WMOPS_output (Word16 notPrintWorstWorstCase, char *test_file_name); * * notPrintWorstWorstCase : Same usage as in WMOPS_output(). */ +#ifdef FROM_EVS_DEV +void WMOPS_output_all(Word16 dtx_mode); +void WMOPS_output_all_std(Word16 dtx_mode); - +/* + * free all allocated counter memory + */ +void WMOPS_destroy(void); +#endif #if 0 /* * Example of how count.h could be used. @@ -535,6 +547,37 @@ int main () { } #endif /* #if 0 */ +/* jdr 20120117: add FLC similar functions */ +/* mul 20130729: set BASOP_COUNT_SUBROUTINES to count on a per-BASOP_sub_start()/BASOP_sub_end() base; + otherwise, count only between BASOP_push_wmops(), BASOP_push_wmops() */ +#define BASOP_COUNT_SUBROUTINES +void BASOP_push_wmops (const char *label); +Word32 BASOP_pop_wmops (void); + +#define BASOP_init { setFrameRate(32000, 640); Init_WMOPS_counter(); /* 20ms frames */ } +#define BASOP_end { WMOPS_output_all_std(0); } +/*#define BASOP_end { WMOPS_output_all(0); }*/ +#define BASOP_end_noprint { WMOPS_destroy(); } + +#ifdef BASOP_COUNT_SUBROUTINES +#define BASOP_sub_start(label) { BASOP_push_wmops(label); } +#define BASOP_sub_end() { BASOP_pop_wmops(); } +#else +#define BASOP_sub_start(label) +#define BASOP_sub_end() +#endif + +void BASOP_frame_update(void); +void Reset_all_WMOPS_counter (void); + +Word32 BASOP_get_wops (void); + +/*! Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ +void BASOP_get_total_wmops(double *min, double *max, double *avg); + + +#define SUB_WMOPS_INIT( label ) BASOP_sub_start( label ) +#define END_SUB_WMOPS BASOP_sub_end() #endif /* _COUNT_H */ diff --git a/lib_com/move.h.bak b/lib_com/move.h.bak deleted file mode 100644 index 81b4c7d60..000000000 --- a/lib_com/move.h.bak +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 - ====================================================================================*/ - -#ifndef _MOVE_H -#define _MOVE_H -#include "stl.h" -/* BASOP -> FLC brigde: data move counting */ - -static __inline void move16( void ) -{ -#ifdef WMOPS - multiCounter[currCounter].move16++; -#endif -} - -static __inline void move32( void ) -{ -#ifdef WMOPS - multiCounter[currCounter].move32++; -#endif -} - -#ifdef ENH_64_BIT_OPERATOR -static __inline void move64(void) { -#ifdef WMOPS - multiCounter[currCounter].move64++; -#endif /* if WMOPS */ -} -#endif /* #ifdef ENH_64_BIT_OPERATOR */ - -static __inline void test( void ) -{ -#ifdef WMOPS - multiCounter[currCounter].Test++; -#endif -} - -static __inline void logic16( void ) -{ -#ifdef WMOPS - multiCounter[currCounter].Logic16++; -#endif -} - -static __inline void logic32( void ) -{ -#ifdef WMOPS - multiCounter[currCounter].Logic32++; -#endif -} - -/*-------- legacy ----------*/ -#define data_move() move16() -#define L_data_move() move32() -#define data_move_external() move16() -#define compare_zero() test() -/*-------- end legacy ----------*/ - -#define cast16 move16 - -#endif /* _MOVE_H */ diff --git a/lib_com/options.h b/lib_com/options.h index 7e9ea311c..05a27acd0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -54,6 +54,7 @@ #endif #define WMOPS 1 /* Activate complexity and memory counters */ +#define FROM_EVS_DEV /* Some enhancement written by gr and Markus during EVS time */ /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ -- GitLab From 22efb51fba68bbd5b2558ea940d44459bea454e0 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 30 Jan 2024 09:11:35 -0500 Subject: [PATCH 03/11] Fix fix point complexity printing and make push_wmops() and pop_wmops() to point to their fixed point equivalent --- apps/decoder.c | 80 ++++++++++---------------- apps/encoder.c | 1 + lib_com/count.c | 118 +++++++++++++++++++++----------------- lib_com/count.h | 13 +++++ lib_com/options.h | 2 + lib_debug/wmc_auto.h | 4 +- lib_dec/ivas_cpe_dec_fx.c | 2 +- lib_dec/ivas_jbm_dec.c | 1 + lib_dec/lib_dec_fx.c | 3 +- 9 files changed, 117 insertions(+), 107 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index d9d7a7783..7e0ec2890 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -45,6 +45,7 @@ #include "rotation_file_reader.h" #include "vector3_pair_file_reader.h" #include "wmc_auto.h" +#include "stl.h" #define WMC_TOOL_SKIP @@ -76,12 +77,7 @@ static /*------------------------------------------------------------------------------------------* * Local structure for storing cmdln arguments *------------------------------------------------------------------------------------------*/ -#ifdef WMOPS -#include "stl.h" -extern int currCounter; -int idxG192; -int idxVOIP; -#endif + typedef struct { char *inputBitstreamFilename; @@ -170,9 +166,9 @@ int main( reset_mem( USE_BYTES ); #endif #if ( WMOPS ) - Init_WMOPS_counter(); - Reset_WMOPS_counter(); - setFrameRate( 48000, 960 ); +#ifndef DONT_COUNT + BASOP_init +#endif #endif /*------------------------------------------------------------------------------------------* * Parse command-line arguments @@ -575,7 +571,6 @@ int main( /*-----------------------------------------------------------------* * Decoding *-----------------------------------------------------------------*/ - if ( arg.voipMode ) { error = decodeVoIP( arg, hBsReader, headRotReader, externalOrientationFileReader, refRotReader, referenceVectorReader, hIvasDec ); @@ -610,7 +605,11 @@ int main( mainFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ cleanup: - +#ifndef DONT_COUNT + /* end of WMOPS counting */ + BASOP_end + BASOP_end_noprint +#endif free( pcmBuf ); if ( arg.hrtfReaderEnabled ) @@ -1513,14 +1512,8 @@ static ivas_error decodeG192( IsmFileWriter *ismWriters[IVAS_MAX_NUM_OBJECTS]; IVAS_VECTOR3 Pos[IVAS_MAX_PARAM_SPATIAL_SUBFRAMES] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; int16_t vec_pos_update, vec_pos_len; -#ifdef WMOPS - int GetId, GetTCId, cheId; - /* initiate counters and objects */ - GetId = getCounterId( "IVAS_DEC_GetSamples" ); - GetTCId = getCounterId( "IVAS_DEC_GetTCSamples" ); - cheId = getCounterId( "ivas_jbm_dec_tc" ); -#endif + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; ++i ) { ismWriters[i] = NULL; @@ -1546,13 +1539,6 @@ static ivas_error decodeG192( reset_stack(); reset_wmops(); #endif -#ifdef WMOPS - //BASOP_end_noprint; - //BASOP_init; - Init_WMOPS_counter(); - Reset_WMOPS_counter(); - setFrameRate( 48000, 960 ); -#endif nSamplesAvailableNext = 0; @@ -1575,14 +1561,9 @@ static ivas_error decodeG192( * - Run the decoder * - Write the synthesized signal into output file *------------------------------------------------------------------------------------------*/ - while ( 1 ) { /* Read next frame if not enough samples availble */ -#if ( WMOPS ) - fwc(); - Reset_WMOPS_counter(); -#endif /* reference vector */ if ( arg.enableReferenceVectorTracking && vec_pos_update == 0 ) { @@ -1698,22 +1679,17 @@ static ivas_error decodeG192( goto cleanup; } } -#ifdef WMOPS -SUB_WMOPS_INIT( "IVAS_DEC_GetSamples" ); -#endif if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, ( pcmBuf + nOutChannels * nSamplesRendered ), &nSamplesRendered_loop, &needNewFrame ) ) != IVAS_ERR_OK ) { fprintf( stderr, "\nError in IVAS_DEC_GetSamples: %s\n", IVAS_DEC_GetErrorMessage( error ) ); goto cleanup; } -#ifdef WMOPS -END_SUB_WMOPS; -#endif nSamplesRendered += nSamplesRendered_loop; nSamplesToRender -= nSamplesRendered_loop; if ( needNewFrame ) { + frame++; if ( !arg.quietModeEnabled ) { @@ -1723,6 +1699,7 @@ END_SUB_WMOPS; } while ( nSamplesRendered < nOutSamples && error == IVAS_ERR_OK ); + if ( error == IVAS_ERR_END_OF_FILE ) { break; @@ -1826,18 +1803,16 @@ END_SUB_WMOPS; } #endif #ifdef WMOPS +#ifndef DONT_COUNT if ( vec_pos_update == 0 ) { /* update WMPOS counting (end of frame) */ - //BASOP_frame_update(); -#if ( WMOPS ) - //WMOPS_output( 0 ); - fwc(); -#endif + BASOP_frame_update(); } + +#endif #endif } - /*------------------------------------------------------------------------------------------* * Flush what is still left in the VoIP Buffers.... *------------------------------------------------------------------------------------------*/ @@ -1958,7 +1933,12 @@ END_SUB_WMOPS; } } } - +#ifdef WMOPS +#ifndef DONT_COUNT + /* update WMPOS counting (end of frame) */ + BASOP_frame_update(); +#endif +#endif frame++; if ( !arg.quietModeEnabled ) { @@ -2018,13 +1998,6 @@ END_SUB_WMOPS; //BASOP_end cleanup: /* free memory etc. */ -#ifdef WMOPS - WMOPS_output( 0 ); - fwc(); - printf( "\ndecoder complexity\n" ); - generic_WMOPS_output( 0, "dec_complx.txt" ); - printf( "\n" ); -#endif AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) @@ -2495,7 +2468,12 @@ static ivas_error decodeVoIP( vec_pos_update = ( vec_pos_update + 1 ) % vec_pos_len; frame++; systemTime_ms += systemTimeInc_ms; - +#ifdef WMOPS +#ifndef DONT_COUNT + /* update WMPOS counting (end of frame) */ + BASOP_frame_update(); +#endif +#endif #ifdef WMOPS_FLT update_mem(); update_wmops(); diff --git a/apps/encoder.c b/apps/encoder.c index fdecc217a..adaa584a9 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -39,6 +39,7 @@ #include "jbm_file_reader.h" #include "masa_file_reader.h" #include "wmc_auto.h" +#include "stl.h" #define WMC_TOOL_SKIP diff --git a/lib_com/count.c b/lib_com/count.c index ada2c8b91..3c205f8f8 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -343,7 +343,7 @@ static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; static Word16 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS]; static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax]; #else -#define NbFuncMax (5000L*20L) +#define NbFuncMax (4096) /** @@ -571,6 +571,10 @@ void Init_WMOPS_counter (void) { nbframe[currCounter] = 0; total_wmops[currCounter] = 0.0; #ifdef FROM_EVS_DEV + for (i = 0; i < NbFuncMax; i++) + { + bc[currCounter][i] = (Word32)MAX_32; + } glob_bc[currCounter] = MAX_32; nbcalls[currCounter] = 0; total_sum[currCounter] = 0.0; @@ -585,11 +589,6 @@ void Init_WMOPS_counter (void) { funcId_where_last_call_to_else_occurred = MAXCOUNTERS; #ifdef FROM_EVS_DEV - for (i = 0; i < NbFuncMax; i++) - { - bc[currCounter][i] = (Word32)MAX_32; - } - sum_bc[currCounter] = MAX_32; sum_wc[currCounter] = 0; sum_curr[currCounter] = 0; @@ -617,12 +616,15 @@ void Reset_WMOPS_counter (void) { /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ nbframe[currCounter]++; - +#ifndef FROM_EVS_DEV /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ total_wmops[currCounter] += (float) (tot * frameRate); +#endif #ifdef FROM_EVS_DEV /* Call counter */ nbcalls[currCounter] += funcid[currCounter]; + /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ + total_wmops[currCounter] += (float) (tot * frameRate); total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); #endif @@ -1182,30 +1184,34 @@ void WMOPS_output_all(Word16 dtx_mode) fprintf (stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); for (i = 1; i <= maxCounter; i++) { - fprintf (stderr, dfmt, - objectName[i], - (nbframe[i] == 0) ? 0 : (float)nbcalls[i]/(float)nbframe[0], - (glob_bc[i] == 0) ? 0 : frameRate*(float)glob_bc[i], - (glob_wc[i] == 0) ? 0 : frameRate*(float)glob_wc[i], - (nbframe[i] == 0) ? 0 : (float)total_wmops[i]/(float)nbframe[i], - frameRate*(glob_sum_bc[i]), - frameRate*(glob_sum_wc[i]), - (nbframe[i] == 0) ? 0 : (float)(total_sum[i] /(float)nbframe[i])); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ - + if ( nbcalls[i] > 0 ) + { + fprintf( stderr, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( total_sum[i] / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ + } ops_cnt += total_wmops[i]; } fprintf (stderr, sfmts, " -----------------", " ------", "------", "------", "------"); - fprintf (stderr, dfmts, - "total", - (double)nbframe[0], - frameRate*glob_bc[0], - frameRate*glob_wc[0], - (nbframe[0] == 0) ? 0 : ops_cnt/nbframe[0]); - + if ( nbframe[i] > 0 ) + { + fprintf( stderr, dfmts, + "total", + (double) nbframe[0], + frameRate * glob_bc[0], + frameRate * glob_wc[0], + ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); + } #if 0 { char *sfmtt = "%20s %4s %15s\n"; @@ -1319,42 +1325,48 @@ void WMOPS_output_all_std(Word16 dtx_mode) fprintf (stdout, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ fprintf (stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ - for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) - { - fprintf (stdout, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); - } - + if ( nbframe[0] > 0 ) + { + for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) + { + fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); + } + } fprintf (stdout, "\n\nWeighted MOPS Analysis:\n"); fprintf (stdout, "%74s %23s\n", "|------ SELF ------|" ,"|--- CUMULATIVE ---|"); - fprintf (stdout, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); + fprintf (stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg "); fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); for (i = 1; i <= maxCounter; i++) { - fprintf (stdout, dfmt, - objectName[i], - (nbframe[i] == 0) ? 0 : (float)nbcalls[i]/(float)nbframe[0], - (glob_bc[i] == 0) ? 0 : frameRate*(float)glob_bc[i], - (glob_wc[i] == 0) ? 0 : frameRate*(float)glob_wc[i], - (nbframe[i] == 0) ? 0 : (float)total_wmops[i]/(float)nbframe[i], - frameRate*(glob_sum_bc[i]), - frameRate*(glob_sum_wc[i]), - (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ - + if ( nbcalls[i] > 0 ) + { + fprintf( stdout, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( ( total_sum[i] ) / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ + } ops_cnt += total_wmops[i]; } fprintf (stdout, sfmts, " -----------------", " ------", "------", "------", "------"); - fprintf (stdout, dfmts, - "total", - (double)nbframe[0], - frameRate*glob_bc[0], - frameRate*glob_wc[0], - (nbframe[0] == 0) ? 0 : ops_cnt/nbframe[0]); - + if ( nbframe[0] > 0 ) + { + fprintf( stdout, dfmts, + "total", + (double) nbframe[0], + frameRate * glob_bc[0], + frameRate * glob_wc[0], + ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); + } #if 0 { char *sfmtt = "%20s %4s %15s\n"; diff --git a/lib_com/count.h b/lib_com/count.h index e12840ccb..5bc5952b3 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -579,6 +579,19 @@ void BASOP_get_total_wmops(double *min, double *max, double *avg); #define SUB_WMOPS_INIT( label ) BASOP_sub_start( label ) #define END_SUB_WMOPS BASOP_sub_end() + +#ifndef WMOPS_FL +#include +#define reset_wmops() BASOP_init +//extern int cntr_push_pop; +#define push_wmops( x ) { BASOP_push_wmops(x); } +#define pop_wmops() { BASOP_pop_wmops(); } +#define update_wmops() { BASOP_frame_update(); } +#define print_wmops() { WMOPS_output_all_std(0); } +#define update_mem(); +#endif + + #endif /* _COUNT_H */ diff --git a/lib_com/options.h b/lib_com/options.h index 05a27acd0..de3c953e1 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -55,6 +55,8 @@ #define WMOPS 1 /* Activate complexity and memory counters */ #define FROM_EVS_DEV /* Some enhancement written by gr and Markus during EVS time */ +/*#define DONT_COUNT */ /* To prevent the complexity counting */ + /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 8bc6dba8c..53ed59ee5 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -570,7 +570,8 @@ void update_wmops( void ); void update_mem( void ); void print_wmops( void ); -#else /* WMOPS counting disabled */ +#else /* WMOPS_FL counting disabled */ +#ifndef WMOPS #include #define reset_wmops() extern int cntr_push_pop; @@ -579,6 +580,7 @@ extern int cntr_push_pop; #define update_wmops() ( assert( cntr_push_pop == 0 ) ) #define update_mem() #define print_wmops() +#endif #define ADD( x ) #define ABS( x ) diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index c9cfa8a39..5407a6cfd 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -442,7 +442,7 @@ ivas_error ivas_cpe_dec_fx( IF( st_ivas->hMCT ) { pop_wmops(); - + return error; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 5fa094dce..e74c619f4 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -1218,6 +1218,7 @@ ivas_error ivas_jbm_dec_tc( pop_wmops(); + return IVAS_ERR_OK; } diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 24d311a10..62382c1f7 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -905,7 +905,6 @@ ivas_error IVAS_DEC_GetSamples( { return error; } - /* JBM */ IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm ) { @@ -1048,6 +1047,7 @@ static ivas_error IVAS_DEC_GetTcSamples( { Decoder_Struct *st_ivas; ivas_error error; + SUB_WMOPS_INIT( "IVAS_DEC_GetTcSamples" ); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1080,6 +1080,7 @@ static ivas_error IVAS_DEC_GetTcSamples( { hIvasDec->hasDecodedFirstGoodFrame = true; } + END_SUB_WMOPS; /*IVAS_DEC_GetTcSamples*/ return IVAS_ERR_OK; } -- GitLab From 4e9edd5d45c7a1108e394069ad384ce50405f767 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 30 Jan 2024 09:20:16 -0500 Subject: [PATCH 04/11] clean-up to make it easier to merge --- apps/decoder.c | 4 ++-- lib_dec/ivas_jbm_dec.c | 4 ---- lib_dec/lib_dec_fx.c | 2 -- lib_dec/tonalMDCTconcealment_fx.c | 1 - 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 7e0ec2890..d2bfec993 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1995,9 +1995,9 @@ static ivas_error decodeG192( *------------------------------------------------------------------------------------------*/ decodingFailed = false; /* This will stay set to true if cleanup is reached via a goto due to an error */ - //BASOP_end + cleanup: - /* free memory etc. */ + AudioFileWriter_close( &afWriter ); MasaFileWriter_close( &masaWriter ); for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index e74c619f4..871a67ebf 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -60,10 +60,6 @@ static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas ); static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const int16_t nCldfbTs ); -#ifdef WMOPS_FX -extern int currCounter; -int idxId; -#endif /*--------------------------------------------------------------------------* * ivas_jbm_dec_tc() diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index 62382c1f7..63d119102 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1047,7 +1047,6 @@ static ivas_error IVAS_DEC_GetTcSamples( { Decoder_Struct *st_ivas; ivas_error error; - SUB_WMOPS_INIT( "IVAS_DEC_GetTcSamples" ); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -1080,7 +1079,6 @@ static ivas_error IVAS_DEC_GetTcSamples( { hIvasDec->hasDecodedFirstGoodFrame = true; } - END_SUB_WMOPS; /*IVAS_DEC_GetTcSamples*/ return IVAS_ERR_OK; } diff --git a/lib_dec/tonalMDCTconcealment_fx.c b/lib_dec/tonalMDCTconcealment_fx.c index 630393b8b..9da79f6fa 100644 --- a/lib_dec/tonalMDCTconcealment_fx.c +++ b/lib_dec/tonalMDCTconcealment_fx.c @@ -15,7 +15,6 @@ #include "prot_fx2.h" #include "stat_com.h" #include "prot.h" -#include "wmc_auto.h" #define CROSSFADE_THRESHOLD (32762) // close to 1.0f in Q15 such that (x == 1.0f) is true -- GitLab From 1da44342a3dab2a15af5146f8178e8c6518dcba8 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Tue, 30 Jan 2024 10:06:04 -0500 Subject: [PATCH 05/11] some more cleaning --- lib_com/count.c | 90 ++++++++++++++++++----------------------------- lib_com/count.h | 13 ++----- lib_com/options.h | 8 ++--- 3 files changed, 40 insertions(+), 71 deletions(-) diff --git a/lib_com/count.c b/lib_com/count.c index 3c205f8f8..9022d5a03 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -54,10 +54,10 @@ static double frameRate = FRAME_RATE; /* default value : 10 ms */ #ifdef WMOPS /* Global counter variable for calculation of complexity weight */ +/* Some enhancement written by Vail., GJR and M.Mul. during EVS time */ + BASIC_OP multiCounter[MAXCOUNTERS]; -#ifdef FROM_EVS_DEV BASIC_OP glob_multiCounter; -#endif int currCounter = 0; /* Zero equals global counter */ #endif /* ifdef WMOPS */ @@ -323,14 +323,14 @@ Word32 DeltaWeightedOperation (void); #ifdef WMOPS /* Counters for separating counting for different objects */ -#ifdef FROM_EVS_DEV -/** +/* FROM_EVS_DEV */ + /** maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. objectName: Name of each counter passed to BASOP_sub_start(). fwc_corr: nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. */ -#endif + static int maxCounter = 0; static char *objectName[MAXCOUNTERS + 1]; @@ -338,11 +338,6 @@ static Word16 fwc_corr[MAXCOUNTERS + 1]; static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; -#ifndef FROM_EVS_DEV -#define NbFuncMax 1024 -static Word16 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS]; -static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax]; -#else #define NbFuncMax (4096) @@ -364,13 +359,9 @@ static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax]; static Word32 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS], nbcalls[MAXCOUNTERS]; static Word32 glob_bc[MAXCOUNTERS], glob_wc[MAXCOUNTERS], bc[MAXCOUNTERS][NbFuncMax], wc[MAXCOUNTERS][NbFuncMax]; - -#endif static float total_wmops[MAXCOUNTERS]; - static Word32 LastWOper[MAXCOUNTERS]; -#ifdef FROM_EVS_DEV - +/* FROM_EVS_DEV */ static float total_sum[MAXCOUNTERS]; static Word16 call_tree[MAXCOUNTERS][MAXCOUNTERS]; static int sum_curr[MAXCOUNTERS+1]; @@ -385,7 +376,7 @@ static float callers_frames[MAX_CALLERS_SAVED_FRAMES+1][MAXCOUNTERS+1]; static int callers_frames_nos[MAX_CALLERS_SAVED_FRAMES]; static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; #endif -#endif + #endif /* ifdef WMOPS */ @@ -479,12 +470,15 @@ static Word32 WMOPS_frameStat (void) { Word32 tot; tot = TotalWeightedOperation (); - if (tot > glob_wc[currCounter]) - glob_wc[currCounter] = tot; -#ifdef FROM_EVS_DEV - if (tot < glob_bc[currCounter]) - glob_bc[currCounter] = tot; -#endif + if ( tot > glob_wc[currCounter] ) + { + glob_wc[currCounter] = tot; + } + + if ( tot < glob_bc[currCounter] ) + { + glob_bc[currCounter] = tot; + } /* check if fwc() was forgotten at end of last frame */ if (tot > LastWOper[currCounter]) { if (!fwc_corr[currCounter]) { @@ -570,7 +564,6 @@ void Init_WMOPS_counter (void) { glob_wc[currCounter] = 0; nbframe[currCounter] = 0; total_wmops[currCounter] = 0.0; -#ifdef FROM_EVS_DEV for (i = 0; i < NbFuncMax; i++) { bc[currCounter][i] = (Word32)MAX_32; @@ -578,7 +571,7 @@ void Init_WMOPS_counter (void) { glob_bc[currCounter] = MAX_32; nbcalls[currCounter] = 0; total_sum[currCounter] = 0.0; -#endif + /* initially clear all counters */ WMOPS_clearMultiCounter (); LastWOper[currCounter] = 0; @@ -588,7 +581,6 @@ void Init_WMOPS_counter (void) { call_occurred = 1; funcId_where_last_call_to_else_occurred = MAXCOUNTERS; -#ifdef FROM_EVS_DEV sum_bc[currCounter] = MAX_32; sum_wc[currCounter] = 0; sum_curr[currCounter] = 0; @@ -600,43 +592,31 @@ void Init_WMOPS_counter (void) { glob_sum_curr[currCounter] = 0; glob_sum_wc[currCounter] = 0; glob_sum_bc[currCounter] = MAX_32; -#endif #endif /* ifdef WMOPS */ } -#ifdef FROM_EVS_DEV Word32 Reset_WMOPS_counter(void) { -#else -void Reset_WMOPS_counter (void) { -#endif #if WMOPS Word32 tot = WMOPS_frameStat (); /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ nbframe[currCounter]++; -#ifndef FROM_EVS_DEV - /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ - total_wmops[currCounter] += (float) (tot * frameRate); -#endif -#ifdef FROM_EVS_DEV /* Call counter */ nbcalls[currCounter] += funcid[currCounter]; /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ total_wmops[currCounter] += (float) (tot * frameRate); total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); -#endif /* clear counter before new frame starts */ WMOPS_clearMultiCounter (); LastWOper[currCounter] = 0; funcid[currCounter] = 0; /* new frame, set function id to zero */ -#ifdef FROM_EVS_DEV + glob_sum_curr[currCounter] = 0; sum_curr[currCounter] = 0; return tot; -#endif #endif /* ifdef WMOPS */ } @@ -650,21 +630,19 @@ Word32 fwc (void) { tot = DeltaWeightedOperation (); if (tot > wc[currCounter][funcid[currCounter]]) wc[currCounter][funcid[currCounter]] = tot; -#ifdef FROM_EVS_DEV - if (tot < bc[currCounter][funcid[currCounter]]) - bc[currCounter][funcid[currCounter]] = tot; -#endif + + if (tot < bc[currCounter][funcid[currCounter]]) + bc[currCounter][funcid[currCounter]] = tot; + funcid[currCounter]++; -#ifdef FROM_EVS_DEV - /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ - if (funcid[currCounter] >= NbFuncMax) { - printf("to many function calls\n"); - } - assert(funcid[currCounter] < NbFuncMax); - return (tot); -#else /* ifdef WMOPS */ - return 0; /* Dummy */ -#endif + + /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ + if (funcid[currCounter] >= NbFuncMax) + { + printf("to many function calls\n"); + } + assert(funcid[currCounter] < NbFuncMax); + return (tot); #endif /* ifdef WMOPS */ } @@ -700,7 +678,7 @@ void WMOPS_output (Word16 dtx_mode) { #endif /* ifdef WMOPS */ } -void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word16 * num_frames) { +void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames) { #if WMOPS Word16 i; Word32 tot, tot_wc; @@ -870,7 +848,7 @@ void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) { (void)test_file_name; #endif /* ifdef WMOPS */ } -#ifdef FROM_EVS_DEV +/* FROM_EVS_DEV */ #define MAX_STACK 64 static int stack[MAX_STACK]; @@ -1062,7 +1040,7 @@ void BASOP_push_wmops (const char *label) } else if (call_tree[i][j] == -1) { - call_tree[i][j] = prev_counter; + call_tree[i][j] = (Word16)prev_counter; break; } } @@ -1452,5 +1430,5 @@ void BASOP_get_total_wmops(double *min, double *max, double *avg) } #endif /* if WMOPS */ } -#endif + /* end of file */ diff --git a/lib_com/count.h b/lib_com/count.h index 5bc5952b3..70d608fd2 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -64,9 +64,7 @@ //#undef WMOPS /* disable WMOPS profiling features */ #endif #define MAXCOUNTERS (512) -#ifdef FROM_EVS_DEV #define MAX_CALLERS_SAVED_FRAMES 5 /* # of Frame for which WMOPS Complexity Details will be saved, 0 = Disabled */ -#endif int getCounterId (char *objectName); /* @@ -93,7 +91,6 @@ char *readCounterIdName (void); /* * Returns the current CounterId name. */ -#ifdef FROM_EVS_DEV void printStack(char *text, char * Id); /* * print stack @@ -102,7 +99,6 @@ void printStack(char *text, char * Id); * "*", if all prints are wanted (default) * "pitch_ol" or any other function name */ -#endif void incrementNbTimeObjectIsCalled (int counterId); /* @@ -127,11 +123,8 @@ void Init_WMOPS_counter (void); */ -#ifdef FROM_EVS_DEV + Word32 Reset_WMOPS_counter( void ); -#else -void Reset_WMOPS_counter( void ); -#endif /* * Resets the current counter group. */ @@ -145,7 +138,7 @@ void WMOPS_output (Word16 notPrintWorstWorstCase); * */ -void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word16 * num_frames); +void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames); /* * same as WMOPS_output + returns the total wmops counter and the number of frames * to support the computation of global average. @@ -487,7 +480,6 @@ void generic_WMOPS_output (Word16 notPrintWorstWorstCase, char *test_file_name); * * notPrintWorstWorstCase : Same usage as in WMOPS_output(). */ -#ifdef FROM_EVS_DEV void WMOPS_output_all(Word16 dtx_mode); void WMOPS_output_all_std(Word16 dtx_mode); @@ -495,7 +487,6 @@ void WMOPS_output_all_std(Word16 dtx_mode); * free all allocated counter memory */ void WMOPS_destroy(void); -#endif #if 0 /* * Example of how count.h could be used. diff --git a/lib_com/options.h b/lib_com/options.h index de3c953e1..e2d146b8b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -53,15 +53,15 @@ #pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ #endif -#define WMOPS 1 /* Activate complexity and memory counters */ -#define FROM_EVS_DEV /* Some enhancement written by gr and Markus during EVS time */ -/*#define DONT_COUNT */ /* To prevent the complexity counting */ +#define WMOPS 1 /* Activate FIXED-POINT complexity counters */ +/*#define DONT_COUNT */ /* To prevent the complexity counting */ +#ifdef WMOPS_FLT /*#define WMOPS_PER_FRAME*/ /* Output per-frame complexity (writes one float value per frame to the file "wmops_analysis") */ /*#define WMOPS_DETAIL*/ /* Output detailed complexity printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output detailed complexity analysis for the worst-case frame */ /*#define MEM_COUNT_DETAILS*/ /* Output detailed memory analysis for the worst-case frame (writes to the file "mem_analysis.csv") */ - +#endif /* #################### End DEBUGGING switches ############################ */ -- GitLab From dd57be8b55e2db6eef737ae948b3d2172efe36de Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 31 Jan 2024 08:28:11 -0500 Subject: [PATCH 06/11] fix compilation warnings --- lib_com/count.c | 5 +- lib_com/count.c.bak | 1437 ++++++++++++++++++++++++++++++++++++++++++ lib_com/count.h | 2 +- lib_com/options.h | 2 +- lib_debug/wmc_auto.h | 2 +- 5 files changed, 1444 insertions(+), 4 deletions(-) create mode 100644 lib_com/count.c.bak diff --git a/lib_com/count.c b/lib_com/count.c index 9022d5a03..afc32be8a 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -617,7 +617,8 @@ Word32 Reset_WMOPS_counter(void) { glob_sum_curr[currCounter] = 0; sum_curr[currCounter] = 0; return tot; - +#else + return 0; #endif /* ifdef WMOPS */ } @@ -643,6 +644,8 @@ Word32 fwc (void) { } assert(funcid[currCounter] < NbFuncMax); return (tot); +#else + return 0; #endif /* ifdef WMOPS */ } diff --git a/lib_com/count.c.bak b/lib_com/count.c.bak new file mode 100644 index 000000000..16082bcf4 --- /dev/null +++ b/lib_com/count.c.bak @@ -0,0 +1,1437 @@ +/* + =========================================================================== + File: COUNT.C v.2.3 - 30.Nov.2009 + =========================================================================== + + ITU-T STL BASIC OPERATORS + + COMPLEXITY EVALUATION FUNCTIONS + + History: + 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control + operators for the ITU-T Standard Tool Library as + described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 + TD 11 document and subsequent discussions on the + wp3audio@yahoogroups.com email reflector. + norm_s() weight reduced from 15 to 1. + norm_l() weight reduced from 30 to 1. + L_abs() weight reduced from 2 to 1. + L_add() weight reduced from 2 to 1. + L_negate() weight reduced from 2 to 1. + L_shl() weight reduced from 2 to 1. + L_shr() weight reduced from 2 to 1. + L_sub() weight reduced from 2 to 1. + mac_r() weight reduced from 2 to 1. + msu_r() weight reduced from 2 to 1. + mult_r() weight reduced from 2 to 1. + L_deposit_h() weight reduced from 2 to 1. + L_deposit_l() weight reduced from 2 to 1. + March 06 v2.1 Changed to improve portability. + Dec 06 v2.2 Changed to specify frame rate using setFrameRate() + Adding WMOPS_output_avg() for global average computation + L_mls() weight of 5. + div_l() weight of 32. + i_mult() weight of 3. + ============================================================================ +*/ + + +/***************************************************************************** + * + * This file contains functions for the automatic complexity calculation + * + *****************************************************************************/ + + +#include +#include +#include +#include "stl.h" +#include +#ifdef WMOPS +static double frameRate = FRAME_RATE; /* default value : 10 ms */ +#endif /* ifdef WMOPS */ + +#ifdef WMOPS +/* Global counter variable for calculation of complexity weight */ +/* Some enhancement written by Vail., GJR and M.Mul. during EVS time */ + +BASIC_OP multiCounter[MAXCOUNTERS]; +BASIC_OP glob_multiCounter; +int currCounter = 0; /* Zero equals global counter */ +#endif /* ifdef WMOPS */ + +#ifdef WMOPS +void setFrameRate (int samplingFreq, int frameLength) { + if (frameLength > 0) { + frameRate = samplingFreq / 1000000.0 / frameLength; + } + return; +} + +#endif /* ifdef WMOPS */ + +#ifdef WMOPS +/* + * Below list is used for displaying the code profiling information in + * the file which name is defined by CODE_PROFILE_FILENAME. + * For further details see generic_WMOPS_output() function. + * Attention, the ordering in this table must be kept in synchronisation + * with the structure definition BASIC_OP. + */ +char *BasicOperationList[] = { + "add", "sub", "abs_s", "shl", "shr", + "extract_h", "extract_l", "mult", "L_mult", "negate", + "round", "L_mac", "L_msu", "L_macNs", "L_msuNs", + "L_add", "L_sub", "L_add_c", "L_sub_c", "L_negate", + "L_shl", "L_shr", "mult_r", "shr_r", "mac_r", + + "msu_r", "L_deposit_h", "L_deposit_l", "L_shr_r", "L_abs", + "L_sat", "norm_s", "div_s", "norm_l", "move16", + "move32", "Logic16", "Logic32", "Test", "s_max", + "s_min", "L_max", "L_min", "L40_max", "L40_min", + "shl_r", "L_shl_r", "L40_shr_r", "L40_shl_r", "norm_L40", + + "L40_shl", "L40_shr", "L40_negate", "L40_add", "L40_sub", + "L40_abs", "L40_mult", "L40_mac", "mac_r40", + "L40_msu", "msu_r40", "Mpy_32_16_ss", "Mpy_32_32_ss", "L_mult0", + "L_mac0", "L_msu0", "lshl", "lshr", "L_lshl", + "L_lshr", "L40_lshl", "L40_lshr", "s_and", "s_or", + + "s_xor", "L_and", "L_or", "L_xor", "rotl", + "rotr", "L_rotl", "L_rotr", "L40_set", "L40_deposit_h", + "L40_deposit_l", "L40_deposit32", "Extract40_H", "Extract40_L", "L_Extract40", + "L40_round", "L_saturate40", "round40", "IF", "GOTO", + "BREAK", "SWITCH", "FOR", "WHILE", "CONTINUE", + + "L_mls", "div_l", "i_mult" + + /* New complex basops */ + #ifdef COMPLEX_OPERATOR + , "CL_shr", "CL_shl", "CL_add" + , "CL_sub", "CL_scale", "CL_dscale" + , "CL_msu_j", "CL_mac_j", "CL_move" + , "CL_Extract_real", "CL_Extract_imag", "CL_form" + , "CL_multr_32x16", "CL_negate", "CL_conjugate" + , "CL_mul_j" + , "CL_swap_real_imag" + , "C_add" + , "C_sub" + , "C_mul_j" + , "C_multr" + , "C_form" + + , "C_scale" + , "CL_round32_16", "CL_scale_32", "CL_dscale_32", "CL_multr_32x32" + , "C_mac_r", "C_msu_r", "C_Extract_real", "C_Extract_imag" + , "C_negate", "C_conjugate" + , "C_shr", "C_shl" + +#endif /* #ifdef COMPLEX_OPERATOR */ + + /* New 64 bit basops */ +#ifdef ENH_64_BIT_OPERATOR + , "move64" , "W_add_nosat" ,"W_sub_nosat" + , "W_shl" , "W_shr" + , "W_shl_nosat" , "W_shr_nosat" + , "W_mac_32_16" , "W_msu_32_16" , "W_mult_32_16" + , "W_mult0_16_16" , "W_mac0_16_16" , "W_msu0_16_16" + , "W_mult_16_16" , "W_mac_16_16" , "W_msu_16_16" + , "W_shl_sat_l" , "W_sat_l" + , "W_sat_m" , "W_deposit32_l" ,"W_deposit32_h" + , "W_extract_l" , "W_extract_h" + , "W_round48_L" , "W_round32_s" + , "W_norm" + , "W_add" , "W_sub" ,"W_neg" ,"W_abs" + , "W_mult_32_32" , "W_mult0_32_32" + , "W_lshl" , "W_lshr" ,"W_round64_L" + +#endif /* #ifdef ENH_64_BIT_OPERATOR */ + +#ifdef ENH_32_BIT_OPERATOR + , "Mpy_32_16_1" + , "Mpy_32_16_r" + , "Mpy_32_32" + , "Mpy_32_32_r" + , "Madd_32_16" + , "Madd_32_16_r" + , "Msub_32_16" + , "Msub_32_16_r" + , "Madd_32_32" + , "Madd_32_32_r" + , "Msub_32_32" + , "Msub_32_32_r" +#endif /* #ifdef ENH_32_BIT_OPERATOR */ + +#ifdef ENH_U_32_BIT_OPERATOR + , "UL_addNs" + , "UL_subNs" + , "UL_Mpy_32_32" + , "Mpy_32_32_uu" + , "Mpy_32_16_uu" + , "norm_ul_float" + , "UL_deposit_l" +#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ + +#ifdef CONTROL_CODE_OPS + , "LT_16" + , "GT_16" + , "LE_16" + , "GE_16" + , "EQ_16" + , "NE_16" + , "LT_32" + , "GT_32" + , "LE_32" + , "GE_32" + , "EQ_32" + , "NE_32" + , "LT_64" + , "GT_64" + , "LE_64" + , "GE_64" + , "EQ_64" + , "NE_64" +#endif /* #ifdef CONTROL_CODE_OPS */ + +}; +#endif /* ifdef WMOPS */ + + +#ifdef WMOPS +const BASIC_OP op_weight = { + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 2, 2, 1, + 1, 1, 1, 2, 1, + + 1, 1, 1, 2, 1, + 1, 1, 18, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 2, 2, 2, 2, 1, + + 1, 1, 1, 1, 1, + 1, 1, 1, 2, + 1, 2, 2, 2, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 3, + 3, 3, 3, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 3, 2, + 2, 6, 3, 3, 2, + + 1, 32, 1 + +/* New complex basops */ + #ifdef COMPLEX_OPERATOR + , 1, 1, 1 + , 1, 1, 1 + , 1, 1, 1 + , 1, 1, 1 + , 2, 1, 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 2 + , 1 + + , 1 + , 1, 1, 1, 2 + , 2, 2, 1, 1 + , 1, 1 + , 1, 1 + +#endif /* #ifdef COMPLEX_OPERATOR */ + +#ifdef ENH_64_BIT_OPERATOR + /* Weights of new 64 bit basops */ + , 1 , 1 ,1 + , 1 , 1 + , 1 , 1 + , 1 , 1 , 1 + , 1 , 1 , 1 + , 1 , 1 , 1 + , 1 , 1 + , 1 , 1 , 1 + , 1 , 1 + , 1 , 1 + , 1 + , 1 , 1 , 1 , 1 + , 1 , 1 + , 1 , 1 , 1 +#endif /* #ifdef ENH_64_BIT_OPERATOR */ + +#ifdef ENH_32_BIT_OPERATOR + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 +#endif /* #ifdef ENH_32_BIT_OPERATOR */ + +#ifdef ENH_U_32_BIT_OPERATOR + , 1 + , 1 + , 1 + , 2 + , 2 + , 1 + , 1 +#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ + +#ifdef CONTROL_CODE_OPS + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 + , 1 +#endif /* #ifdef CONTROL_CODE_OPS */ +}; +#endif /* ifdef WMOPS */ + + +Word32 TotalWeightedOperation (void); +Word32 DeltaWeightedOperation (void); + + +#ifdef WMOPS +/* Counters for separating counting for different objects */ + +/* FROM_EVS_DEV */ + /** + maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. + objectName: Name of each counter passed to BASOP_sub_start(). + fwc_corr: + nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. + */ + +static int maxCounter = 0; +static char *objectName[MAXCOUNTERS + 1]; + +static Word16 fwc_corr[MAXCOUNTERS + 1]; +static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; + + +#define NbFuncMax (4096) + + +/** + funcid: current function call for each counter + bc : best case for each counter and function call + wc : worst case for each counter and function call + nbframe: number of frames for each counter. + glob_bc: global best case self time for each counter for current frame. + glob_wc: global worst case self time for each counter for current frame. + glob_sum_curr: global cummulative time for each counter for current frame. + glob_sum_bc: global best case cummulative time for each counter for current frame. + glob_sum_wc: global worst case cummulative time for each counter for current frame. + + total_wmops: total wmops self time for each counter for current frame. + total_sum: total wmops cummulative time for each counter for current frame. + LastWOper: values used for WMOPS deltas + */ + +static Word32 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS], nbcalls[MAXCOUNTERS]; +static Word32 glob_bc[MAXCOUNTERS], glob_wc[MAXCOUNTERS], bc[MAXCOUNTERS][NbFuncMax], wc[MAXCOUNTERS][NbFuncMax]; +static float total_wmops[MAXCOUNTERS]; +static Word32 LastWOper[MAXCOUNTERS]; +/* FROM_EVS_DEV */ +static float total_sum[MAXCOUNTERS]; +static Word16 call_tree[MAXCOUNTERS][MAXCOUNTERS]; +static int sum_curr[MAXCOUNTERS+1]; +static int sum_bc[MAXCOUNTERS+1]; +static int sum_wc[MAXCOUNTERS+1]; +static int glob_sum_curr[MAXCOUNTERS+1]; +static int glob_sum_bc[MAXCOUNTERS+1]; +static int glob_sum_wc[MAXCOUNTERS+1]; +#if MAX_CALLERS_SAVED_FRAMES +#define MAX_CALLERS_PRINT 20 +static float callers_frames[MAX_CALLERS_SAVED_FRAMES+1][MAXCOUNTERS+1]; +static int callers_frames_nos[MAX_CALLERS_SAVED_FRAMES]; +static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; +#endif + +#endif /* ifdef WMOPS */ + + +#ifdef WMOPS +static char *my_strdup (const char *s) { + /* + * duplicates UNIX function strdup() which is not ANSI standard: + * -- malloc() memory area big enough to hold the string s + * -- copy string into new area + * -- return pointer to new area + * + * returns NULL if either s==NULL or malloc() fails + */ + char *dup; + + if (s == NULL) + return NULL; + + /* allocate memory for copy of ID string (including string terminator) */ + /* NOTE: the ID strings will never be deallocated because there is no way to "destroy" a counter that is not longer needed */ + if ((dup = (char *) malloc (strlen (s) + 1)) == NULL) + return NULL; + + return strcpy (dup, s); +} +#endif /* ifdef WMOPS */ + + +int getCounterId (char *objectNameArg) { +#if WMOPS + if (maxCounter >= MAXCOUNTERS - 1) + return 0; + objectName[++maxCounter] = my_strdup (objectNameArg); + return maxCounter; + +#else /* ifdef WMOPS */ + (void)objectNameArg; + return 0; /* Dummy */ + +#endif /* ifdef WMOPS */ +} + + +#if WMOPS +int readCounterId () { + return currCounter; +} +#endif /* ifdef WMOPS */ + + +#ifdef WMOPS +char *readCounterIdName () { + return objectName[currCounter]; +} +#endif /* ifdef WMOPS */ + +void setCounter (int counterId) { +#if WMOPS + if ((counterId > maxCounter) + || (counterId < 0)) { + currCounter = 0; + return; + } + currCounter = counterId; + call_occurred = 1; +#else + (void)counterId; +#endif /* ifdef WMOPS */ +} + + +void incrementNbTimeObjectIsCalled (int counterId) { +#if WMOPS + if ((counterId > maxCounter) + || (counterId < 0)) { + nbTimeObjectIsCalled[0]++; + return; + } + nbTimeObjectIsCalled[counterId]++; +#else + (void)counterId; +#endif /* ifdef WMOPS */ +} + + +#if WMOPS +static Word32 WMOPS_frameStat (void) { +/* calculate the WMOPS seen so far and update the global + per-frame maximum (glob_wc) + */ + Word32 tot; + + tot = TotalWeightedOperation (); + if ( tot > glob_wc[currCounter] ) + { + glob_wc[currCounter] = tot; + } + + if ( tot < glob_bc[currCounter] ) + { + glob_bc[currCounter] = tot; + } + /* check if fwc() was forgotten at end of last frame */ + if (tot > LastWOper[currCounter]) { + if (!fwc_corr[currCounter]) { + fprintf (stderr, + "count: operations counted after last fwc() for '%s'; " "-> fwc() called\n", + objectName[currCounter] ? objectName[currCounter] : ""); + } + fwc (); + } + + return tot; +} +#endif /* ifdef WMOPS */ + + +#ifdef WMOPS +static void WMOPS_clearMultiCounter (void) { + Word16 i; + + Word32 *ptr = (Word32 *) & multiCounter[currCounter]; + for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { + *ptr++ = 0; + } +} +#endif /* ifdef WMOPS */ + + +void ClearNbTimeObjectsAreCalled () { +#if WMOPS + Word16 i; + + for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { + nbTimeObjectIsCalled[i] = 0; + } +#endif /* ifdef WMOPS */ +} + +Word32 TotalWeightedOperation () { +#if WMOPS + Word16 i; + Word32 tot, *ptr, *ptr2; + + tot = 0; + ptr = (Word32 *) & multiCounter[currCounter]; + ptr2 = (Word32 *) & op_weight; + for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { + tot += ((*ptr++) * (*ptr2++)); + } + + return ((Word32) tot); + +#else /* ifdef WMOPS */ + return 0; /* Dummy */ + +#endif /* ifdef WMOPS */ + +} + +Word32 DeltaWeightedOperation () { +#if WMOPS + Word32 NewWOper, delta; + + NewWOper = TotalWeightedOperation (); + delta = NewWOper - LastWOper[currCounter]; + LastWOper[currCounter] = NewWOper; + return (delta); + +#else /* ifdef WMOPS */ + return 0; /* Dummy */ + +#endif /* ifdef WMOPS */ +} + + +void Init_WMOPS_counter (void) { +#if WMOPS + Word16 i; + + /* reset function weight operation counter variable */ + + for (i = 0; i < NbFuncMax; i++) + wc[currCounter][i] = (Word32) 0; + glob_wc[currCounter] = 0; + nbframe[currCounter] = 0; + total_wmops[currCounter] = 0.0; + for (i = 0; i < NbFuncMax; i++) + { + bc[currCounter][i] = (Word32)MAX_32; + } + glob_bc[currCounter] = MAX_32; + nbcalls[currCounter] = 0; + total_sum[currCounter] = 0.0; + + /* initially clear all counters */ + WMOPS_clearMultiCounter (); + LastWOper[currCounter] = 0; + funcid[currCounter] = 0; + + /* Following line is useful for incrIf(), see control.h */ + call_occurred = 1; + funcId_where_last_call_to_else_occurred = MAXCOUNTERS; + + sum_bc[currCounter] = MAX_32; + sum_wc[currCounter] = 0; + sum_curr[currCounter] = 0; + for (i = 0; i < MAXCOUNTERS; i++) + { + call_tree[currCounter][i] = -1; + } + + glob_sum_curr[currCounter] = 0; + glob_sum_wc[currCounter] = 0; + glob_sum_bc[currCounter] = MAX_32; + +#endif /* ifdef WMOPS */ +} + + +Word32 Reset_WMOPS_counter(void) { +#if WMOPS + Word32 tot = WMOPS_frameStat (); + + /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ + nbframe[currCounter]++; + /* Call counter */ + nbcalls[currCounter] += funcid[currCounter]; + /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ + total_wmops[currCounter] += (float) (tot * frameRate); + total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); + + /* clear counter before new frame starts */ + WMOPS_clearMultiCounter (); + LastWOper[currCounter] = 0; + funcid[currCounter] = 0; /* new frame, set function id to zero */ + + glob_sum_curr[currCounter] = 0; + sum_curr[currCounter] = 0; + return tot; +#else + return 0; +#endif /* ifdef WMOPS */ +} + + +Word32 fwc (void) { +/* function worst case */ +#if WMOPS + Word32 tot; + + tot = DeltaWeightedOperation (); + if (tot > wc[currCounter][funcid[currCounter]]) + wc[currCounter][funcid[currCounter]] = tot; + + if (tot < bc[currCounter][funcid[currCounter]]) + bc[currCounter][funcid[currCounter]] = tot; + + funcid[currCounter]++; + + /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ + if (funcid[currCounter] >= NbFuncMax) + { + printf("to many function calls\n"); + } + assert(funcid[currCounter] < NbFuncMax); + return (tot); + #else + return 0; +#endif /* ifdef WMOPS */ +} + +void WMOPS_output (Word16 dtx_mode) { +#if WMOPS + Word16 i; + Word32 tot, tot_wm, tot_wc; + + /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) + so output CAN be called in each frame without problems. The frame counter is NOT updated! */ + tot = WMOPS_frameStat (); + tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); + + fprintf (stdout, + "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", + ((float) tot) * frameRate); + + if (nbframe[currCounter] != 0) { + fprintf (stdout, " Average=%.3f", tot_wm / (float) nbframe[currCounter]); + } + fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); + + /* Worst worst case printed only when not in DTX mode */ + if (dtx_mode == 0) { + tot_wc = 0L; + for (i = 0; i < funcid[currCounter]; i++) + tot_wc += wc[currCounter][i]; + fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); + } + fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); +#else + (void)dtx_mode; +#endif /* ifdef WMOPS */ +} + +void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames) { +#if WMOPS + Word16 i; + Word32 tot, tot_wc; + + /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) + so output CAN be called in each frame without problems. The frame counter is NOT updated! */ + tot = WMOPS_frameStat (); + *tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); + *num_frames = nbframe[currCounter]; + + fprintf (stdout, "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", ((float) tot) * frameRate); + + if (nbframe[currCounter] != 0) { + fprintf (stdout, " Average=%.3f", *tot_wm / (float) nbframe[currCounter]); + } + fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); + + /* Worst worst case printed only when not in DTX mode */ + if (dtx_mode == 0) { + tot_wc = 0L; + for (i = 0; i < funcid[currCounter]; i++) + tot_wc += wc[currCounter][i]; + fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); + } + fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); +#else + (void)dtx_mode; + (void)tot_wm; + (void)num_frames; +#endif /* ifdef WMOPS */ +} + +void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) { +#if WMOPS + int saved_value; + Word16 i; + Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; + Word40 grand_total; + FILE *WMOPS_file; + + saved_value = currCounter; + + /* Count the grand_total WMOPS so that % ratio per function group can be displayed. */ + grand_total = 0; + for (currCounter = 0; currCounter <= maxCounter; currCounter++) { + tot = WMOPS_frameStat (); + grand_total += tot; + } + + + if ((WMOPS_file = fopen (WMOPS_DATA_FILENAME, "a")) != NULL) { + + printf ("opened file %s in order to print WMOPS for each function group.\n", WMOPS_DATA_FILENAME); + + /* Print the file header line. */ + fprintf (WMOPS_file, "Test file name\tFunction Name \tFrame\tNb Times Called\tWMOPS\t%% versus grand total"); + + if (nbframe[saved_value] != 0) + fprintf (WMOPS_file, "\tAverage"); + + fprintf (WMOPS_file, "\tWorstCase"); + + /* Worst worst case printed only when not in DTX mode */ + if (dtx_mode == 0) + fprintf (WMOPS_file, "\tWorstWC"); + + fprintf (WMOPS_file, "\n"); + + /* Print the WMOPS for each Function Group by scanning all the function groups with currCounter index. */ + for (currCounter = 0; currCounter <= maxCounter; currCounter++) { + + fprintf (WMOPS_file, "%s", test_file_name); + fprintf (WMOPS_file, "\t%s", objectName[currCounter] ? objectName[currCounter] : ""); + fprintf (WMOPS_file, "\t%d", nbframe[currCounter]); + + tot = WMOPS_frameStat (); + tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); + + fprintf (WMOPS_file, "\t\t%ld", nbTimeObjectIsCalled[currCounter]); + fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); + fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); + + if (nbframe[currCounter] != 0) + fprintf (WMOPS_file, "\t%.3f", tot_wm / (float) nbframe[currCounter]); + + fprintf (WMOPS_file, "\t%.3f", ((float) glob_wc[currCounter]) * frameRate); + + /* Worst worst case printed only when not in DTX mode */ + if (dtx_mode == 0) { + tot_wc = 0L; + for (i = 0; i < funcid[currCounter]; i++) + tot_wc += wc[currCounter][i]; + fprintf (WMOPS_file, "\t%.3f", ((float) tot_wc) * frameRate); + } + fprintf (WMOPS_file, "\n"); + + } + + /* Print the file Grand Total line */ + fprintf (WMOPS_file, "%s", test_file_name); + fprintf (WMOPS_file, "\tGrand Total"); + fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); + fprintf (WMOPS_file, "\t\t%.6f", ((float) grand_total) * frameRate); + fprintf (WMOPS_file, "\t100.000"); + fprintf (WMOPS_file, "\n"); + fclose (WMOPS_file); + + } else + printf ("Can not open file %s for WMOPS editing\n", WMOPS_DATA_FILENAME); + + + if ((WMOPS_file = fopen (WMOPS_TOTAL_FILENAME, "a")) != NULL) { + printf ("opened file %s in order to print application's total WMOPS.\n", WMOPS_TOTAL_FILENAME); + fprintf (WMOPS_file, "%s", test_file_name); + fprintf (WMOPS_file, "\tframe=%d", nbframe[currCounter]); + fprintf (WMOPS_file, "\tWMOPS=%.6f", ((float) grand_total) * frameRate); + fprintf (WMOPS_file, "\n"); + fclose (WMOPS_file); + + } else + printf ("Can not open file %s for WMOPS editing.\n", WMOPS_TOTAL_FILENAME); + + + if ((WMOPS_file = fopen (CODE_PROFILE_FILENAME, "a")) != NULL) { + + printf ("opened file %s in order to print basic operation distribution statistics.\n", CODE_PROFILE_FILENAME); + + /* Print the file header line. */ + fprintf (WMOPS_file, "Test file name\tBasic Operation Name\tframe\tWMOPS\t\t%% versus grand total\n"); + + /* Print the WMOPS for each Basic Operation across all the defined */ + /* Function Groups. */ + for (i = 0; i < (Word16)(sizeof (op_weight) / sizeof (Word32)); i++) { + fprintf (WMOPS_file, "%-16s", test_file_name); + fprintf (WMOPS_file, "\t%s", BasicOperationList[i]); + fprintf (WMOPS_file, "\t%d", nbframe[0]); + + tot = 0; + ptr = (Word32 *) & multiCounter[0] + i; + ptr2 = (Word32 *) & op_weight + i; + for (currCounter = 0; currCounter <= maxCounter; currCounter++) { + tot += ((*ptr) * (*ptr2)); + ptr += (sizeof (op_weight) / sizeof (Word32)); + } + + fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); + fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); + fprintf (WMOPS_file, "\n"); + } + + /* Print the file Grand Total line */ + fprintf (WMOPS_file, "%s", test_file_name); + fprintf (WMOPS_file, "\tGrand Total"); + fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); + fprintf (WMOPS_file, "\t%.6f", ((float) grand_total) * frameRate); + fprintf (WMOPS_file, "\t100.000"); + fprintf (WMOPS_file, "\n"); + fclose (WMOPS_file); + + } else + printf ("Can not open file %s for basic operations distribution statistic editing\n", CODE_PROFILE_FILENAME); + + currCounter = saved_value; + +#else + (void)dtx_mode; + (void)test_file_name; +#endif /* ifdef WMOPS */ +} +/* FROM_EVS_DEV */ + +#define MAX_STACK 64 +static int stack[MAX_STACK]; +static int sptr; +static int sum_stack[MAX_STACK]; + +/* jdr 20120117: add FLC similar functions */ +void BASOP_frame_update(void) +{ +#if WMOPS + int i, current; +#if MAX_CALLERS_SAVED_FRAMES + int k; +#endif + float total = 0.0f; + +#ifdef DEBUG + { + static int sptr_target=-2; + + if (sptr_target == -2) { + sptr_target = sptr; + } else { + if (sptr_target != sptr) { + fprintf(stderr, "BASOP_sub_start/BASOP_sub_end imbalance detected!!!\n"); + sptr_target = sptr; + } + } + } +#endif + + /* Get current counter */ + current = readCounterId(); + + /* Update global operation counters */ + for (i=1; i<=maxCounter; i++) + { + int j; + + for (j=0; j< (int)(sizeof(BASIC_OP)/sizeof(UWord32)); j++) + { + ((UWord32*)&glob_multiCounter)[j] += ((UWord32*)&multiCounter[i])[j]; + } + } + +#if MAX_CALLERS_SAVED_FRAMES + /* Reset all counters */ + for (i=1; i<=maxCounter; i++) + { + callers_frames[0][i] = 0.0f; + } +#endif + /* Reset all counters */ + for (i=1; i<=maxCounter; i++) + { + if (current != i && funcid[i] > 0) { + setCounter(i); + + glob_sum_curr[currCounter] += sum_curr[currCounter]; + + if (glob_sum_curr[currCounter] > glob_sum_wc[currCounter]) { + glob_sum_wc[currCounter] = glob_sum_curr[currCounter]; + } + if (glob_sum_curr[currCounter] < glob_sum_bc[currCounter]) { + glob_sum_bc[currCounter] = glob_sum_curr[currCounter]; + } +#if MAX_CALLERS_SAVED_FRAMES + /* Keep a Copy before it is Reset */ + callers_frames[0][currCounter] = (float)Reset_WMOPS_counter(); + total += callers_frames[0][currCounter]; +#else + total += (float)Reset_WMOPS_counter(); +#endif + } + } + +#if MAX_CALLERS_SAVED_FRAMES + /* Keep Callers for this Worst Case Frame */ + /* Select Slot to Use (Slot 0 is the Current) */ + k = 0; + for (i=k+1; i callers_totals[k]) + { + k+=1; + /* Save Info of Callers */ + for (i=1; i<=maxCounter; i++) + { + callers_frames[k][i] = callers_frames[0][i]; + } + if (i < MAXCOUNTERS) + callers_frames[k][i] = -1; + /* Save Total */ + callers_totals[k-1] = total; + /* Save Frame Number */ + callers_frames_nos[k-1] = nbframe[0]; + } +#endif + if (total < glob_bc[0]) { + glob_bc[0] = (Word32) total; + } + if (total > glob_wc[0]) { + glob_wc[0] = (Word32) total; + + } + /* Restore current counter */ + setCounter(current); + + nbframe[0] ++; +#endif /* if WMOPS */ +} + +void printStack(char *text, char* Id) +{ +#if WMOPS + int i; + if (!Id) return; + if (!strcmp("*", Id) || (!strcmp(Id,objectName[currCounter]))) + { + printf ("%s %s", text, objectName[currCounter]); + for (i=sptr-1; i>0; i--) { + printf(" <- %s", objectName[stack[i]]); + } + printf("\n"); + } +#else + printf("%s %s\n", text, Id ? Id : "(no name)"); +#endif +} + +void BASOP_push_wmops (const char *label) +{ +#if WMOPS + int new_flag, prev_counter; + int i, j; + + /* Check if new counter label */ + new_flag = 1; + for (i = 1; i <= maxCounter; i++) + { + if (strcmp(objectName[i], label) == 0) + { + new_flag = 0; + break; + } + } + + prev_counter = readCounterId(); + + /* Configure new record */ + if (new_flag) + { + i = (int)getCounterId(label); + setCounter(i); + Init_WMOPS_counter(); + } + else + { + setCounter(i); + } + + + /* Push current context onto stack */ + if (currCounter >= 0) + { + if (sptr >= MAX_STACK) + { + fprintf (stderr, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n"); + exit (-1); + } + stack[sptr++] = prev_counter; + + /* Reset accumulated WMOPS */ + sum_stack[sptr] = 0; + + /* update call tree */ + for (j = 0; j < MAXCOUNTERS; j++) + { + if (call_tree[i][j] == prev_counter) + { + break; + } + else if (call_tree[i][j] == -1) + { + call_tree[i][j] = (Word16)prev_counter; + break; + } + } + } + + /*wmops[currCounter].start_selfcnt = ops_cnt; + wmops[currCounter].start_cnt = ops_cnt; + nbTimeObjectIsCalled[currCounter]++;*/ + + incrementNbTimeObjectIsCalled(currCounter); + + sum_curr[currCounter] = 0; + +#ifdef DEBUG_COUNTER + printf("Entering: %s\n", readCounterIdName()); +#endif + +#endif /* if WMOPS */ +} + + +Word32 BASOP_pop_wmops (void) +{ +#if WMOPS + Word32 ops_cnt; + +#ifdef DEBUG_COUNTER + printf("Exiting: %s\n", readCounterIdName()); +#endif + + ops_cnt = fwc(); + + /* Get back previous context from stack */ + if (sptr > 0) + { + int prevCounter; + + sum_stack[sptr] += ops_cnt; + prevCounter = currCounter; + setCounter(stack[--sptr]); + sum_stack[sptr] += sum_stack[sptr+1]; + sum_curr[prevCounter] += sum_stack[sptr+1]; + } + else + { + /* current_record = -1; */ + setCounter(0); + } + + if (sum_curr[currCounter] > sum_wc[currCounter]) { + sum_wc[currCounter] = sum_curr[currCounter]; + } + if (sum_curr[currCounter] < sum_bc[currCounter]) { + sum_bc[currCounter] = sum_curr[currCounter]; + } + + return ops_cnt; +#else /* if WMOPS */ + return 0; +#endif /* if WMOPS */ +} + +Word32 BASOP_get_wops (void) +{ + return BASOP_pop_wmops(); +} + +#define FRAMES_PER_SECOND 50.0 +#define MILLION_CYCLES 1e6 +#define FAC (FRAMES_PER_SECOND/MILLION_CYCLES) + +static Word32 prom_cnt = 0; + +void WMOPS_destroy(void) +{ +#if WMOPS + int i; + + /* release the memory allocated for the objectName array */ + for (i = 0; i < MAXCOUNTERS+1; i++) + { + if (NULL != objectName[i]) + { + free(objectName[i]); + objectName[i] = NULL; + } + } + + maxCounter = 0; +#endif + + return; +} + + +void WMOPS_output_all(Word16 dtx_mode) +{ +#if WMOPS + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf (stderr, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); + /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf (stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ + for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) + { + fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); + } + + fprintf (stderr, "\n\nWeighted MOPS Analysis:\n"); + fprintf (stderr, "%74s %23s\n", "|------ SELF ------|" + ,"|--- CUMULATIVE ---|"); + fprintf (stderr, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); + fprintf (stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); + for (i = 1; i <= maxCounter; i++) + { + if ( nbcalls[i] > 0 ) + { + fprintf( stderr, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( total_sum[i] / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ + } + ops_cnt += total_wmops[i]; + } + + fprintf (stderr, sfmts, " -----------------", " ------", "------", "------", "------"); + if ( nbframe[i] > 0 ) + { + fprintf( stderr, dfmts, + "total", + (double) nbframe[0], + frameRate * glob_bc[0], + frameRate * glob_wc[0], + ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); + } +#if 0 + { + char *sfmtt = "%20s %4s %15s\n"; + char *dfmtt = "%20s %4d "; + + fprintf (stderr, "\nCall Tree:\n\n"); + fprintf (stderr, sfmtt, " function", "num", "called by: "); + fprintf (stderr, sfmtt, "---------------", "---", "--------------"); + + for (i = 1; i <= maxCounter; i++) + { + int j; + + fprintf (stderr, dfmtt, objectName[i], i); + for (j = 0; call_tree[i][j] != -1; j++) + { + if (j != 0) + { + fprintf (stderr, ", "); + } + fprintf (stderr, "%s", objectName[call_tree[i][j]]); + } + fprintf (stderr, "\n"); + + } + fprintf (stderr, sfmtt, "---------------", "---", "--------------"); + fprintf (stderr, "\n\n"); + } +#endif + +#if 0 + fprintf (stderr, "\n\n"); + for (i=1; i<=maxCounter; i++) + { + setCounter(i); + WMOPS_output(dtx_mode); + } +#else + (void)dtx_mode; +#endif + +#if MAX_CALLERS_SAVED_FRAMES + for (i = 1; i <= MAX_CALLERS_SAVED_FRAMES; i++) + { + int j, k, l, m; + const char *frame_rank[] = { "st", "nd", "rd", "th" }; + float current; + + k = 0; + for (j=k+1; j callers_totals[k]) + { /* Yes */ + k = j; + } + } + k+=1; + + fprintf(stderr, "\nActive Callers Report for %i%s Worst Case Frame #: %i\n", + i, i<=3?frame_rank[i-1]:frame_rank[3], + callers_frames_nos[k-1]); + /* Print up to 'MAX_CALLERS_PRINT' Callers */ + current = 0.0f; + for (l = 0; l < MAX_CALLERS_PRINT; l++) + { + /* Find Highest Complexity */ + m = 1; + for (j = m+1; j <= maxCounter; j++) + { + if (callers_frames[k][j] < 0) + break; + if (callers_frames[k][j] > callers_frames[k][m]) + m = j; + } + /* Done ? */ + if (callers_frames[k][m] == 0) + break; + fprintf(stderr, " %-52s %10.3f\n", objectName[m], callers_frames[k][m]*frameRate); + /* Count it */ + current += callers_frames[k][m]; + /* Mark as Done */ + callers_frames[k][m] = 0.0f; + } + /* Check if All Printed */ + if (current+0.001f < callers_totals[k-1]) + { + fprintf(stderr, " Only first %i Callers have been Printed!\n", MAX_CALLERS_PRINT); + fprintf(stderr, " %-52s %10.3f\n", "Total for non Printed", (callers_totals[k-1]-current)*frameRate); + } + fprintf(stderr, " %-52s %10.3f\n", "Total", callers_totals[k-1]*frameRate); + /* Mark as Done */ + callers_totals[k-1] = 0.0f; + } +#endif + WMOPS_destroy(); + +#endif /* if WMOPS */ +} +void WMOPS_output_all_std(Word16 dtx_mode) +{ +#if WMOPS + float ops_cnt = 0.0f; + int i; + + char *sfmts = "%-40s %8s %8s %7s %7s\n"; + char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; + char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; + char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; + + fprintf (stdout, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); + /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ + fprintf (stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ + if ( nbframe[0] > 0 ) + { + for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) + { + fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); + } + } + fprintf (stdout, "\n\nWeighted MOPS Analysis:\n"); + fprintf (stdout, "%74s %23s\n", "|------ SELF ------|" + ,"|--- CUMULATIVE ---|"); + fprintf (stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg "); + fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); + for (i = 1; i <= maxCounter; i++) + { + if ( nbcalls[i] > 0 ) + { + fprintf( stdout, dfmt, + objectName[i], + ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], + ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], + ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], + frameRate * ( glob_sum_bc[i] ), + frameRate * ( glob_sum_wc[i] ), + ( nbframe[i] == 0 ) ? 0 : (float) ( ( total_sum[i] ) / (float) nbframe[i] ) ); + /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ + /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ + /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ + } + ops_cnt += total_wmops[i]; + } + + fprintf (stdout, sfmts, " -----------------", " ------", "------", "------", "------"); + if ( nbframe[0] > 0 ) + { + fprintf( stdout, dfmts, + "total", + (double) nbframe[0], + frameRate * glob_bc[0], + frameRate * glob_wc[0], + ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); + } +#if 0 + { + char *sfmtt = "%20s %4s %15s\n"; + char *dfmtt = "%20s %4d "; + + fprintf (stdout, "\nCall Tree:\n\n"); + fprintf (stdout, sfmtt, " function", "num", "called by: "); + fprintf (stdout, sfmtt, "---------------", "---", "--------------"); + + for (i = 1; i <= maxCounter; i++) + { + int j; + + fprintf (stdout, dfmtt, objectName[i], i); + for (j = 0; call_tree[i][j] != -1; j++) + { + if (j != 0) + { + fprintf (stdout, ", "); + } + fprintf (stdout, "%s", objectName[call_tree[i][j]]); + } + fprintf (stdout, "\n"); + + } + fprintf (stdout, sfmtt, "---------------", "---", "--------------"); + fprintf (stdout, "\n\n"); + } +#endif + +#if 0 + fprintf (stdout, "\n\n"); + for (i=1; i<=maxCounter; i++) + { + setCounter(i); + WMOPS_output(dtx_mode); + } +#else + (void)dtx_mode; +#endif + + + WMOPS_destroy(); + +#endif /* if WMOPS */ +} + + +void Reset_all_WMOPS_counter (void) +{ +#if WMOPS + int i; + int currCounterSave; + + currCounterSave = currCounter; + + for (i=2; i <= maxCounter; i++) + { + setCounter(i); + Init_WMOPS_counter(); + objectName[i] = 0; + } + + currCounter = currCounterSave; + maxCounter = 1; +#endif /* if WMOPS */ +} + +/* Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ +void BASOP_get_total_wmops(double *min, double *max, double *avg) +{ +#if WMOPS + if(min != NULL) + *min = frameRate * glob_bc[0]; + if(max != NULL) + *max = frameRate * glob_wc[0]; + if(avg != NULL) { + int i; + double ops_cnt = 0; + for(i = 1; i <= maxCounter; i++) + ops_cnt += total_wmops[i]; + *avg = (nbframe[0] == 0) ? 0 : ops_cnt / nbframe[0]; + } +#endif /* if WMOPS */ +} + +/* end of file */ diff --git a/lib_com/count.h b/lib_com/count.h index 70d608fd2..26a9e488a 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -571,7 +571,7 @@ void BASOP_get_total_wmops(double *min, double *max, double *avg); #define END_SUB_WMOPS BASOP_sub_end() -#ifndef WMOPS_FL +#if !defined WMOPS_FL //&& defined WMOPS #include #define reset_wmops() BASOP_init //extern int cntr_push_pop; diff --git a/lib_com/options.h b/lib_com/options.h index e2d146b8b..de19111e7 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -53,7 +53,7 @@ #pragma warning(disable:4310) /* cast truncates constant value this affects mainly constants tables*/ #endif -#define WMOPS 1 /* Activate FIXED-POINT complexity counters */ +/*#define WMOPS 1 --> activation or deactivation in count.h*/ /* Activate FIXED-POINT complexity counters */ /*#define DONT_COUNT */ /* To prevent the complexity counting */ #ifdef WMOPS_FLT diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 53ed59ee5..7d07a84a0 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -571,7 +571,7 @@ void update_mem( void ); void print_wmops( void ); #else /* WMOPS_FL counting disabled */ -#ifndef WMOPS +#if 0 /* -> defined in count.h instead */ #include #define reset_wmops() extern int cntr_push_pop; -- GitLab From 348356a870417f7592b184a489c4642f610dea8d Mon Sep 17 00:00:00 2001 From: Tommy Date: Wed, 31 Jan 2024 08:29:52 -0500 Subject: [PATCH 07/11] Addition of count.c to lib_com of MSVC projet --- Workspace_msvc/lib_com.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index c885d6c39..728f4cd51 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -154,6 +154,7 @@ + -- GitLab From 31f11e6792581d1cacfc04b998671a223da7146f Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 31 Jan 2024 08:45:24 -0500 Subject: [PATCH 08/11] slight improvment in summary printing --- lib_com/count.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib_com/count.c b/lib_com/count.c index afc32be8a..2ee28cee4 100644 --- a/lib_com/count.c +++ b/lib_com/count.c @@ -1155,7 +1155,8 @@ void WMOPS_output_all(Word16 dtx_mode) fprintf (stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) { - fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); + if ( ( (UWord32 *) &glob_multiCounter )[i] > 0) + fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); } fprintf (stderr, "\n\nWeighted MOPS Analysis:\n"); @@ -1310,6 +1311,7 @@ void WMOPS_output_all_std(Word16 dtx_mode) { for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) { + if ( ((UWord32 *) &glob_multiCounter )[i] > 0 ) fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); } } @@ -1319,13 +1321,11 @@ void WMOPS_output_all_std(Word16 dtx_mode) fprintf (stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg "); fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); for (i = 1; i <= maxCounter; i++) - { - if ( nbcalls[i] > 0 ) { fprintf( stdout, dfmt, objectName[i], ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], - ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], + ( glob_bc[i] == MAX_32 ) ? 0 : frameRate * (float) glob_bc[i], ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], frameRate * ( glob_sum_bc[i] ), @@ -1334,7 +1334,6 @@ void WMOPS_output_all_std(Word16 dtx_mode) /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ - } ops_cnt += total_wmops[i]; } -- GitLab From 83bb13794852119900fc0633750cd38727b7c1db Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Wed, 31 Jan 2024 09:07:57 -0500 Subject: [PATCH 09/11] deactivate complexity counting per default --- lib_com/count.h | 7 +++---- lib_com/options.h | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib_com/count.h b/lib_com/count.h index 26a9e488a..76dfae2ed 100644 --- a/lib_com/count.h +++ b/lib_com/count.h @@ -59,10 +59,9 @@ #ifndef _COUNT_H #define _COUNT_H "$Id$" -#if 1 -#define WMOPS 1 /* enable WMOPS profiling features */ -//#undef WMOPS /* disable WMOPS profiling features */ -#endif + +/*#define WMOPS 1*/ /* <<<- enable or disable WMOPS profiling features here */ + #define MAXCOUNTERS (512) #define MAX_CALLERS_SAVED_FRAMES 5 /* # of Frame for which WMOPS Complexity Details will be saved, 0 = Disabled */ diff --git a/lib_com/options.h b/lib_com/options.h index de19111e7..c82f6d30d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -40,6 +40,9 @@ #ifdef DEBUGGING #include "debug.h" #endif + +#include "stl.h" + /* clang-format off */ /* ################### Start compiler switches ######################## */ -- GitLab From 634c703d7a527463bb22ce0fc01f3a682e0eb2df Mon Sep 17 00:00:00 2001 From: knj Date: Thu, 1 Feb 2024 15:21:35 +0100 Subject: [PATCH 10/11] add build test for instrumentation active --- .gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 63e4770c1..20a9b39b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -237,6 +237,22 @@ build-codec-linux-make: - *print-common-info - make -j +# ensure that codec builds on linux with instrumentation active +build-codec-linux-instrumented-make: + rules: + - if: $CI_PIPELINE_SOURCE == 'web' + - if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" # only have MR pipelines for MRs to main + - if: $CI_PIPELINE_SOURCE == 'schedule' + - if: $CI_PIPELINE_SOURCE == 'push' + when: never + extends: + - .build-job-linux + script: + - *print-common-info + - sed -i".bak" "s/\/\*#define WMOPS 1\*\//#define WMOPS 1/g" lib_com/count.h + - make -j + # --------------------------------------------------------------- # Short test jobs # --------------------------------------------------------------- -- GitLab From 40ffc0c40d18fe102f5627e0c792070869dd0f68 Mon Sep 17 00:00:00 2001 From: Tommy Vaillancourt Date: Fri, 9 Feb 2024 12:29:59 -0500 Subject: [PATCH 11/11] remove .bak --- lib_com/count.c.bak | 1437 ------------------------------------------- 1 file changed, 1437 deletions(-) delete mode 100644 lib_com/count.c.bak diff --git a/lib_com/count.c.bak b/lib_com/count.c.bak deleted file mode 100644 index 16082bcf4..000000000 --- a/lib_com/count.c.bak +++ /dev/null @@ -1,1437 +0,0 @@ -/* - =========================================================================== - File: COUNT.C v.2.3 - 30.Nov.2009 - =========================================================================== - - ITU-T STL BASIC OPERATORS - - COMPLEXITY EVALUATION FUNCTIONS - - History: - 03 Nov 04 v2.0 Incorporation of new 32-bit / 40-bit / control - operators for the ITU-T Standard Tool Library as - described in Geneva, 20-30 January 2004 WP 3/16 Q10/16 - TD 11 document and subsequent discussions on the - wp3audio@yahoogroups.com email reflector. - norm_s() weight reduced from 15 to 1. - norm_l() weight reduced from 30 to 1. - L_abs() weight reduced from 2 to 1. - L_add() weight reduced from 2 to 1. - L_negate() weight reduced from 2 to 1. - L_shl() weight reduced from 2 to 1. - L_shr() weight reduced from 2 to 1. - L_sub() weight reduced from 2 to 1. - mac_r() weight reduced from 2 to 1. - msu_r() weight reduced from 2 to 1. - mult_r() weight reduced from 2 to 1. - L_deposit_h() weight reduced from 2 to 1. - L_deposit_l() weight reduced from 2 to 1. - March 06 v2.1 Changed to improve portability. - Dec 06 v2.2 Changed to specify frame rate using setFrameRate() - Adding WMOPS_output_avg() for global average computation - L_mls() weight of 5. - div_l() weight of 32. - i_mult() weight of 3. - ============================================================================ -*/ - - -/***************************************************************************** - * - * This file contains functions for the automatic complexity calculation - * - *****************************************************************************/ - - -#include -#include -#include -#include "stl.h" -#include -#ifdef WMOPS -static double frameRate = FRAME_RATE; /* default value : 10 ms */ -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -/* Global counter variable for calculation of complexity weight */ -/* Some enhancement written by Vail., GJR and M.Mul. during EVS time */ - -BASIC_OP multiCounter[MAXCOUNTERS]; -BASIC_OP glob_multiCounter; -int currCounter = 0; /* Zero equals global counter */ -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -void setFrameRate (int samplingFreq, int frameLength) { - if (frameLength > 0) { - frameRate = samplingFreq / 1000000.0 / frameLength; - } - return; -} - -#endif /* ifdef WMOPS */ - -#ifdef WMOPS -/* - * Below list is used for displaying the code profiling information in - * the file which name is defined by CODE_PROFILE_FILENAME. - * For further details see generic_WMOPS_output() function. - * Attention, the ordering in this table must be kept in synchronisation - * with the structure definition BASIC_OP. - */ -char *BasicOperationList[] = { - "add", "sub", "abs_s", "shl", "shr", - "extract_h", "extract_l", "mult", "L_mult", "negate", - "round", "L_mac", "L_msu", "L_macNs", "L_msuNs", - "L_add", "L_sub", "L_add_c", "L_sub_c", "L_negate", - "L_shl", "L_shr", "mult_r", "shr_r", "mac_r", - - "msu_r", "L_deposit_h", "L_deposit_l", "L_shr_r", "L_abs", - "L_sat", "norm_s", "div_s", "norm_l", "move16", - "move32", "Logic16", "Logic32", "Test", "s_max", - "s_min", "L_max", "L_min", "L40_max", "L40_min", - "shl_r", "L_shl_r", "L40_shr_r", "L40_shl_r", "norm_L40", - - "L40_shl", "L40_shr", "L40_negate", "L40_add", "L40_sub", - "L40_abs", "L40_mult", "L40_mac", "mac_r40", - "L40_msu", "msu_r40", "Mpy_32_16_ss", "Mpy_32_32_ss", "L_mult0", - "L_mac0", "L_msu0", "lshl", "lshr", "L_lshl", - "L_lshr", "L40_lshl", "L40_lshr", "s_and", "s_or", - - "s_xor", "L_and", "L_or", "L_xor", "rotl", - "rotr", "L_rotl", "L_rotr", "L40_set", "L40_deposit_h", - "L40_deposit_l", "L40_deposit32", "Extract40_H", "Extract40_L", "L_Extract40", - "L40_round", "L_saturate40", "round40", "IF", "GOTO", - "BREAK", "SWITCH", "FOR", "WHILE", "CONTINUE", - - "L_mls", "div_l", "i_mult" - - /* New complex basops */ - #ifdef COMPLEX_OPERATOR - , "CL_shr", "CL_shl", "CL_add" - , "CL_sub", "CL_scale", "CL_dscale" - , "CL_msu_j", "CL_mac_j", "CL_move" - , "CL_Extract_real", "CL_Extract_imag", "CL_form" - , "CL_multr_32x16", "CL_negate", "CL_conjugate" - , "CL_mul_j" - , "CL_swap_real_imag" - , "C_add" - , "C_sub" - , "C_mul_j" - , "C_multr" - , "C_form" - - , "C_scale" - , "CL_round32_16", "CL_scale_32", "CL_dscale_32", "CL_multr_32x32" - , "C_mac_r", "C_msu_r", "C_Extract_real", "C_Extract_imag" - , "C_negate", "C_conjugate" - , "C_shr", "C_shl" - -#endif /* #ifdef COMPLEX_OPERATOR */ - - /* New 64 bit basops */ -#ifdef ENH_64_BIT_OPERATOR - , "move64" , "W_add_nosat" ,"W_sub_nosat" - , "W_shl" , "W_shr" - , "W_shl_nosat" , "W_shr_nosat" - , "W_mac_32_16" , "W_msu_32_16" , "W_mult_32_16" - , "W_mult0_16_16" , "W_mac0_16_16" , "W_msu0_16_16" - , "W_mult_16_16" , "W_mac_16_16" , "W_msu_16_16" - , "W_shl_sat_l" , "W_sat_l" - , "W_sat_m" , "W_deposit32_l" ,"W_deposit32_h" - , "W_extract_l" , "W_extract_h" - , "W_round48_L" , "W_round32_s" - , "W_norm" - , "W_add" , "W_sub" ,"W_neg" ,"W_abs" - , "W_mult_32_32" , "W_mult0_32_32" - , "W_lshl" , "W_lshr" ,"W_round64_L" - -#endif /* #ifdef ENH_64_BIT_OPERATOR */ - -#ifdef ENH_32_BIT_OPERATOR - , "Mpy_32_16_1" - , "Mpy_32_16_r" - , "Mpy_32_32" - , "Mpy_32_32_r" - , "Madd_32_16" - , "Madd_32_16_r" - , "Msub_32_16" - , "Msub_32_16_r" - , "Madd_32_32" - , "Madd_32_32_r" - , "Msub_32_32" - , "Msub_32_32_r" -#endif /* #ifdef ENH_32_BIT_OPERATOR */ - -#ifdef ENH_U_32_BIT_OPERATOR - , "UL_addNs" - , "UL_subNs" - , "UL_Mpy_32_32" - , "Mpy_32_32_uu" - , "Mpy_32_16_uu" - , "norm_ul_float" - , "UL_deposit_l" -#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ - -#ifdef CONTROL_CODE_OPS - , "LT_16" - , "GT_16" - , "LE_16" - , "GE_16" - , "EQ_16" - , "NE_16" - , "LT_32" - , "GT_32" - , "LE_32" - , "GE_32" - , "EQ_32" - , "NE_32" - , "LT_64" - , "GT_64" - , "LE_64" - , "GE_64" - , "EQ_64" - , "NE_64" -#endif /* #ifdef CONTROL_CODE_OPS */ - -}; -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -const BASIC_OP op_weight = { - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 2, 2, 1, - 1, 1, 1, 2, 1, - - 1, 1, 1, 2, 1, - 1, 1, 18, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - 2, 2, 2, 2, 1, - - 1, 1, 1, 1, 1, - 1, 1, 1, 2, - 1, 2, 2, 2, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 3, - 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, - 1, 1, 1, 3, 2, - 2, 6, 3, 3, 2, - - 1, 32, 1 - -/* New complex basops */ - #ifdef COMPLEX_OPERATOR - , 1, 1, 1 - , 1, 1, 1 - , 1, 1, 1 - , 1, 1, 1 - , 2, 1, 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 2 - , 1 - - , 1 - , 1, 1, 1, 2 - , 2, 2, 1, 1 - , 1, 1 - , 1, 1 - -#endif /* #ifdef COMPLEX_OPERATOR */ - -#ifdef ENH_64_BIT_OPERATOR - /* Weights of new 64 bit basops */ - , 1 , 1 ,1 - , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 - , 1 - , 1 , 1 , 1 , 1 - , 1 , 1 - , 1 , 1 , 1 -#endif /* #ifdef ENH_64_BIT_OPERATOR */ - -#ifdef ENH_32_BIT_OPERATOR - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 -#endif /* #ifdef ENH_32_BIT_OPERATOR */ - -#ifdef ENH_U_32_BIT_OPERATOR - , 1 - , 1 - , 1 - , 2 - , 2 - , 1 - , 1 -#endif /* #ifdef ENH_U_32_BIT_OPERATOR */ - -#ifdef CONTROL_CODE_OPS - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 - , 1 -#endif /* #ifdef CONTROL_CODE_OPS */ -}; -#endif /* ifdef WMOPS */ - - -Word32 TotalWeightedOperation (void); -Word32 DeltaWeightedOperation (void); - - -#ifdef WMOPS -/* Counters for separating counting for different objects */ - -/* FROM_EVS_DEV */ - /** - maxCounter: current number of counters. Each scope initialized with BASOP_sub_start() gets a own counter assigned. - objectName: Name of each counter passed to BASOP_sub_start(). - fwc_corr: - nbTimeObjectIsCalled: number of times a counter (object) is referenced in the current frame. - */ - -static int maxCounter = 0; -static char *objectName[MAXCOUNTERS + 1]; - -static Word16 fwc_corr[MAXCOUNTERS + 1]; -static long int nbTimeObjectIsCalled[MAXCOUNTERS + 1]; - - -#define NbFuncMax (4096) - - -/** - funcid: current function call for each counter - bc : best case for each counter and function call - wc : worst case for each counter and function call - nbframe: number of frames for each counter. - glob_bc: global best case self time for each counter for current frame. - glob_wc: global worst case self time for each counter for current frame. - glob_sum_curr: global cummulative time for each counter for current frame. - glob_sum_bc: global best case cummulative time for each counter for current frame. - glob_sum_wc: global worst case cummulative time for each counter for current frame. - - total_wmops: total wmops self time for each counter for current frame. - total_sum: total wmops cummulative time for each counter for current frame. - LastWOper: values used for WMOPS deltas - */ - -static Word32 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS], nbcalls[MAXCOUNTERS]; -static Word32 glob_bc[MAXCOUNTERS], glob_wc[MAXCOUNTERS], bc[MAXCOUNTERS][NbFuncMax], wc[MAXCOUNTERS][NbFuncMax]; -static float total_wmops[MAXCOUNTERS]; -static Word32 LastWOper[MAXCOUNTERS]; -/* FROM_EVS_DEV */ -static float total_sum[MAXCOUNTERS]; -static Word16 call_tree[MAXCOUNTERS][MAXCOUNTERS]; -static int sum_curr[MAXCOUNTERS+1]; -static int sum_bc[MAXCOUNTERS+1]; -static int sum_wc[MAXCOUNTERS+1]; -static int glob_sum_curr[MAXCOUNTERS+1]; -static int glob_sum_bc[MAXCOUNTERS+1]; -static int glob_sum_wc[MAXCOUNTERS+1]; -#if MAX_CALLERS_SAVED_FRAMES -#define MAX_CALLERS_PRINT 20 -static float callers_frames[MAX_CALLERS_SAVED_FRAMES+1][MAXCOUNTERS+1]; -static int callers_frames_nos[MAX_CALLERS_SAVED_FRAMES]; -static float callers_totals[MAX_CALLERS_SAVED_FRAMES]; -#endif - -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -static char *my_strdup (const char *s) { - /* - * duplicates UNIX function strdup() which is not ANSI standard: - * -- malloc() memory area big enough to hold the string s - * -- copy string into new area - * -- return pointer to new area - * - * returns NULL if either s==NULL or malloc() fails - */ - char *dup; - - if (s == NULL) - return NULL; - - /* allocate memory for copy of ID string (including string terminator) */ - /* NOTE: the ID strings will never be deallocated because there is no way to "destroy" a counter that is not longer needed */ - if ((dup = (char *) malloc (strlen (s) + 1)) == NULL) - return NULL; - - return strcpy (dup, s); -} -#endif /* ifdef WMOPS */ - - -int getCounterId (char *objectNameArg) { -#if WMOPS - if (maxCounter >= MAXCOUNTERS - 1) - return 0; - objectName[++maxCounter] = my_strdup (objectNameArg); - return maxCounter; - -#else /* ifdef WMOPS */ - (void)objectNameArg; - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ -} - - -#if WMOPS -int readCounterId () { - return currCounter; -} -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -char *readCounterIdName () { - return objectName[currCounter]; -} -#endif /* ifdef WMOPS */ - -void setCounter (int counterId) { -#if WMOPS - if ((counterId > maxCounter) - || (counterId < 0)) { - currCounter = 0; - return; - } - currCounter = counterId; - call_occurred = 1; -#else - (void)counterId; -#endif /* ifdef WMOPS */ -} - - -void incrementNbTimeObjectIsCalled (int counterId) { -#if WMOPS - if ((counterId > maxCounter) - || (counterId < 0)) { - nbTimeObjectIsCalled[0]++; - return; - } - nbTimeObjectIsCalled[counterId]++; -#else - (void)counterId; -#endif /* ifdef WMOPS */ -} - - -#if WMOPS -static Word32 WMOPS_frameStat (void) { -/* calculate the WMOPS seen so far and update the global - per-frame maximum (glob_wc) - */ - Word32 tot; - - tot = TotalWeightedOperation (); - if ( tot > glob_wc[currCounter] ) - { - glob_wc[currCounter] = tot; - } - - if ( tot < glob_bc[currCounter] ) - { - glob_bc[currCounter] = tot; - } - /* check if fwc() was forgotten at end of last frame */ - if (tot > LastWOper[currCounter]) { - if (!fwc_corr[currCounter]) { - fprintf (stderr, - "count: operations counted after last fwc() for '%s'; " "-> fwc() called\n", - objectName[currCounter] ? objectName[currCounter] : ""); - } - fwc (); - } - - return tot; -} -#endif /* ifdef WMOPS */ - - -#ifdef WMOPS -static void WMOPS_clearMultiCounter (void) { - Word16 i; - - Word32 *ptr = (Word32 *) & multiCounter[currCounter]; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - *ptr++ = 0; - } -} -#endif /* ifdef WMOPS */ - - -void ClearNbTimeObjectsAreCalled () { -#if WMOPS - Word16 i; - - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - nbTimeObjectIsCalled[i] = 0; - } -#endif /* ifdef WMOPS */ -} - -Word32 TotalWeightedOperation () { -#if WMOPS - Word16 i; - Word32 tot, *ptr, *ptr2; - - tot = 0; - ptr = (Word32 *) & multiCounter[currCounter]; - ptr2 = (Word32 *) & op_weight; - for (i = 0; i < (Word16)(sizeof (multiCounter[currCounter]) / sizeof (Word32)); i++) { - tot += ((*ptr++) * (*ptr2++)); - } - - return ((Word32) tot); - -#else /* ifdef WMOPS */ - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ - -} - -Word32 DeltaWeightedOperation () { -#if WMOPS - Word32 NewWOper, delta; - - NewWOper = TotalWeightedOperation (); - delta = NewWOper - LastWOper[currCounter]; - LastWOper[currCounter] = NewWOper; - return (delta); - -#else /* ifdef WMOPS */ - return 0; /* Dummy */ - -#endif /* ifdef WMOPS */ -} - - -void Init_WMOPS_counter (void) { -#if WMOPS - Word16 i; - - /* reset function weight operation counter variable */ - - for (i = 0; i < NbFuncMax; i++) - wc[currCounter][i] = (Word32) 0; - glob_wc[currCounter] = 0; - nbframe[currCounter] = 0; - total_wmops[currCounter] = 0.0; - for (i = 0; i < NbFuncMax; i++) - { - bc[currCounter][i] = (Word32)MAX_32; - } - glob_bc[currCounter] = MAX_32; - nbcalls[currCounter] = 0; - total_sum[currCounter] = 0.0; - - /* initially clear all counters */ - WMOPS_clearMultiCounter (); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; - - /* Following line is useful for incrIf(), see control.h */ - call_occurred = 1; - funcId_where_last_call_to_else_occurred = MAXCOUNTERS; - - sum_bc[currCounter] = MAX_32; - sum_wc[currCounter] = 0; - sum_curr[currCounter] = 0; - for (i = 0; i < MAXCOUNTERS; i++) - { - call_tree[currCounter][i] = -1; - } - - glob_sum_curr[currCounter] = 0; - glob_sum_wc[currCounter] = 0; - glob_sum_bc[currCounter] = MAX_32; - -#endif /* ifdef WMOPS */ -} - - -Word32 Reset_WMOPS_counter(void) { -#if WMOPS - Word32 tot = WMOPS_frameStat (); - - /* increase the frame counter --> a frame is counted WHEN IT BEGINS */ - nbframe[currCounter]++; - /* Call counter */ - nbcalls[currCounter] += funcid[currCounter]; - /* add wmops used in last frame to count, then reset counter (in first frame, this is a no-op */ - total_wmops[currCounter] += (float) (tot * frameRate); - total_sum[currCounter] += (float)((glob_sum_curr[currCounter]) * frameRate); - - /* clear counter before new frame starts */ - WMOPS_clearMultiCounter (); - LastWOper[currCounter] = 0; - funcid[currCounter] = 0; /* new frame, set function id to zero */ - - glob_sum_curr[currCounter] = 0; - sum_curr[currCounter] = 0; - return tot; -#else - return 0; -#endif /* ifdef WMOPS */ -} - - -Word32 fwc (void) { -/* function worst case */ -#if WMOPS - Word32 tot; - - tot = DeltaWeightedOperation (); - if (tot > wc[currCounter][funcid[currCounter]]) - wc[currCounter][funcid[currCounter]] = tot; - - if (tot < bc[currCounter][funcid[currCounter]]) - bc[currCounter][funcid[currCounter]] = tot; - - funcid[currCounter]++; - - /*make sure that BASOP_frame_update(); is put at the end of the main loop*/ - if (funcid[currCounter] >= NbFuncMax) - { - printf("to many function calls\n"); - } - assert(funcid[currCounter] < NbFuncMax); - return (tot); - #else - return 0; -#endif /* ifdef WMOPS */ -} - -void WMOPS_output (Word16 dtx_mode) { -#if WMOPS - Word16 i; - Word32 tot, tot_wm, tot_wc; - - /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. The frame counter is NOT updated! */ - tot = WMOPS_frameStat (); - tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); - - fprintf (stdout, - "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", - ((float) tot) * frameRate); - - if (nbframe[currCounter] != 0) { - fprintf (stdout, " Average=%.3f", tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); -#else - (void)dtx_mode; -#endif /* ifdef WMOPS */ -} - -void WMOPS_output_avg (Word16 dtx_mode, Word32 * tot_wm, Word32 * num_frames) { -#if WMOPS - Word16 i; - Word32 tot, tot_wc; - - /* get operations since last reset (or init), but do not update the counters (except the glob_wc[] maximum) - so output CAN be called in each frame without problems. The frame counter is NOT updated! */ - tot = WMOPS_frameStat (); - *tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); - *num_frames = nbframe[currCounter]; - - fprintf (stdout, "%10s:WMOPS=%.3f", objectName[currCounter] ? objectName[currCounter] : "", ((float) tot) * frameRate); - - if (nbframe[currCounter] != 0) { - fprintf (stdout, " Average=%.3f", *tot_wm / (float) nbframe[currCounter]); - } - fprintf (stdout, " WorstCase=%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (stdout, " WorstWC=%.3f", ((float) tot_wc) * frameRate); - } - fprintf (stdout, " (%d frames)\n", nbframe[currCounter]); -#else - (void)dtx_mode; - (void)tot_wm; - (void)num_frames; -#endif /* ifdef WMOPS */ -} - -void generic_WMOPS_output (Word16 dtx_mode, char *test_file_name) { -#if WMOPS - int saved_value; - Word16 i; - Word32 tot, tot_wm, tot_wc, *ptr, *ptr2; - Word40 grand_total; - FILE *WMOPS_file; - - saved_value = currCounter; - - /* Count the grand_total WMOPS so that % ratio per function group can be displayed. */ - grand_total = 0; - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot = WMOPS_frameStat (); - grand_total += tot; - } - - - if ((WMOPS_file = fopen (WMOPS_DATA_FILENAME, "a")) != NULL) { - - printf ("opened file %s in order to print WMOPS for each function group.\n", WMOPS_DATA_FILENAME); - - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tFunction Name \tFrame\tNb Times Called\tWMOPS\t%% versus grand total"); - - if (nbframe[saved_value] != 0) - fprintf (WMOPS_file, "\tAverage"); - - fprintf (WMOPS_file, "\tWorstCase"); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) - fprintf (WMOPS_file, "\tWorstWC"); - - fprintf (WMOPS_file, "\n"); - - /* Print the WMOPS for each Function Group by scanning all the function groups with currCounter index. */ - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { - - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\t%s", objectName[currCounter] ? objectName[currCounter] : ""); - fprintf (WMOPS_file, "\t%d", nbframe[currCounter]); - - tot = WMOPS_frameStat (); - tot_wm = (Word32) (total_wmops[currCounter] + ((float) tot) * frameRate); - - fprintf (WMOPS_file, "\t\t%ld", nbTimeObjectIsCalled[currCounter]); - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); - - if (nbframe[currCounter] != 0) - fprintf (WMOPS_file, "\t%.3f", tot_wm / (float) nbframe[currCounter]); - - fprintf (WMOPS_file, "\t%.3f", ((float) glob_wc[currCounter]) * frameRate); - - /* Worst worst case printed only when not in DTX mode */ - if (dtx_mode == 0) { - tot_wc = 0L; - for (i = 0; i < funcid[currCounter]; i++) - tot_wc += wc[currCounter][i]; - fprintf (WMOPS_file, "\t%.3f", ((float) tot_wc) * frameRate); - } - fprintf (WMOPS_file, "\n"); - - } - - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); - - } else - printf ("Can not open file %s for WMOPS editing\n", WMOPS_DATA_FILENAME); - - - if ((WMOPS_file = fopen (WMOPS_TOTAL_FILENAME, "a")) != NULL) { - printf ("opened file %s in order to print application's total WMOPS.\n", WMOPS_TOTAL_FILENAME); - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tframe=%d", nbframe[currCounter]); - fprintf (WMOPS_file, "\tWMOPS=%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); - - } else - printf ("Can not open file %s for WMOPS editing.\n", WMOPS_TOTAL_FILENAME); - - - if ((WMOPS_file = fopen (CODE_PROFILE_FILENAME, "a")) != NULL) { - - printf ("opened file %s in order to print basic operation distribution statistics.\n", CODE_PROFILE_FILENAME); - - /* Print the file header line. */ - fprintf (WMOPS_file, "Test file name\tBasic Operation Name\tframe\tWMOPS\t\t%% versus grand total\n"); - - /* Print the WMOPS for each Basic Operation across all the defined */ - /* Function Groups. */ - for (i = 0; i < (Word16)(sizeof (op_weight) / sizeof (Word32)); i++) { - fprintf (WMOPS_file, "%-16s", test_file_name); - fprintf (WMOPS_file, "\t%s", BasicOperationList[i]); - fprintf (WMOPS_file, "\t%d", nbframe[0]); - - tot = 0; - ptr = (Word32 *) & multiCounter[0] + i; - ptr2 = (Word32 *) & op_weight + i; - for (currCounter = 0; currCounter <= maxCounter; currCounter++) { - tot += ((*ptr) * (*ptr2)); - ptr += (sizeof (op_weight) / sizeof (Word32)); - } - - fprintf (WMOPS_file, "\t%.6f", ((float) tot) * frameRate); - fprintf (WMOPS_file, "\t%.3f", ((float) tot) / grand_total * 100); - fprintf (WMOPS_file, "\n"); - } - - /* Print the file Grand Total line */ - fprintf (WMOPS_file, "%s", test_file_name); - fprintf (WMOPS_file, "\tGrand Total"); - fprintf (WMOPS_file, "\t%d", nbframe[saved_value]); - fprintf (WMOPS_file, "\t%.6f", ((float) grand_total) * frameRate); - fprintf (WMOPS_file, "\t100.000"); - fprintf (WMOPS_file, "\n"); - fclose (WMOPS_file); - - } else - printf ("Can not open file %s for basic operations distribution statistic editing\n", CODE_PROFILE_FILENAME); - - currCounter = saved_value; - -#else - (void)dtx_mode; - (void)test_file_name; -#endif /* ifdef WMOPS */ -} -/* FROM_EVS_DEV */ - -#define MAX_STACK 64 -static int stack[MAX_STACK]; -static int sptr; -static int sum_stack[MAX_STACK]; - -/* jdr 20120117: add FLC similar functions */ -void BASOP_frame_update(void) -{ -#if WMOPS - int i, current; -#if MAX_CALLERS_SAVED_FRAMES - int k; -#endif - float total = 0.0f; - -#ifdef DEBUG - { - static int sptr_target=-2; - - if (sptr_target == -2) { - sptr_target = sptr; - } else { - if (sptr_target != sptr) { - fprintf(stderr, "BASOP_sub_start/BASOP_sub_end imbalance detected!!!\n"); - sptr_target = sptr; - } - } - } -#endif - - /* Get current counter */ - current = readCounterId(); - - /* Update global operation counters */ - for (i=1; i<=maxCounter; i++) - { - int j; - - for (j=0; j< (int)(sizeof(BASIC_OP)/sizeof(UWord32)); j++) - { - ((UWord32*)&glob_multiCounter)[j] += ((UWord32*)&multiCounter[i])[j]; - } - } - -#if MAX_CALLERS_SAVED_FRAMES - /* Reset all counters */ - for (i=1; i<=maxCounter; i++) - { - callers_frames[0][i] = 0.0f; - } -#endif - /* Reset all counters */ - for (i=1; i<=maxCounter; i++) - { - if (current != i && funcid[i] > 0) { - setCounter(i); - - glob_sum_curr[currCounter] += sum_curr[currCounter]; - - if (glob_sum_curr[currCounter] > glob_sum_wc[currCounter]) { - glob_sum_wc[currCounter] = glob_sum_curr[currCounter]; - } - if (glob_sum_curr[currCounter] < glob_sum_bc[currCounter]) { - glob_sum_bc[currCounter] = glob_sum_curr[currCounter]; - } -#if MAX_CALLERS_SAVED_FRAMES - /* Keep a Copy before it is Reset */ - callers_frames[0][currCounter] = (float)Reset_WMOPS_counter(); - total += callers_frames[0][currCounter]; -#else - total += (float)Reset_WMOPS_counter(); -#endif - } - } - -#if MAX_CALLERS_SAVED_FRAMES - /* Keep Callers for this Worst Case Frame */ - /* Select Slot to Use (Slot 0 is the Current) */ - k = 0; - for (i=k+1; i callers_totals[k]) - { - k+=1; - /* Save Info of Callers */ - for (i=1; i<=maxCounter; i++) - { - callers_frames[k][i] = callers_frames[0][i]; - } - if (i < MAXCOUNTERS) - callers_frames[k][i] = -1; - /* Save Total */ - callers_totals[k-1] = total; - /* Save Frame Number */ - callers_frames_nos[k-1] = nbframe[0]; - } -#endif - if (total < glob_bc[0]) { - glob_bc[0] = (Word32) total; - } - if (total > glob_wc[0]) { - glob_wc[0] = (Word32) total; - - } - /* Restore current counter */ - setCounter(current); - - nbframe[0] ++; -#endif /* if WMOPS */ -} - -void printStack(char *text, char* Id) -{ -#if WMOPS - int i; - if (!Id) return; - if (!strcmp("*", Id) || (!strcmp(Id,objectName[currCounter]))) - { - printf ("%s %s", text, objectName[currCounter]); - for (i=sptr-1; i>0; i--) { - printf(" <- %s", objectName[stack[i]]); - } - printf("\n"); - } -#else - printf("%s %s\n", text, Id ? Id : "(no name)"); -#endif -} - -void BASOP_push_wmops (const char *label) -{ -#if WMOPS - int new_flag, prev_counter; - int i, j; - - /* Check if new counter label */ - new_flag = 1; - for (i = 1; i <= maxCounter; i++) - { - if (strcmp(objectName[i], label) == 0) - { - new_flag = 0; - break; - } - } - - prev_counter = readCounterId(); - - /* Configure new record */ - if (new_flag) - { - i = (int)getCounterId(label); - setCounter(i); - Init_WMOPS_counter(); - } - else - { - setCounter(i); - } - - - /* Push current context onto stack */ - if (currCounter >= 0) - { - if (sptr >= MAX_STACK) - { - fprintf (stderr, "\r push_wmops(): stack exceeded, try inreasing MAX_STACK\n"); - exit (-1); - } - stack[sptr++] = prev_counter; - - /* Reset accumulated WMOPS */ - sum_stack[sptr] = 0; - - /* update call tree */ - for (j = 0; j < MAXCOUNTERS; j++) - { - if (call_tree[i][j] == prev_counter) - { - break; - } - else if (call_tree[i][j] == -1) - { - call_tree[i][j] = (Word16)prev_counter; - break; - } - } - } - - /*wmops[currCounter].start_selfcnt = ops_cnt; - wmops[currCounter].start_cnt = ops_cnt; - nbTimeObjectIsCalled[currCounter]++;*/ - - incrementNbTimeObjectIsCalled(currCounter); - - sum_curr[currCounter] = 0; - -#ifdef DEBUG_COUNTER - printf("Entering: %s\n", readCounterIdName()); -#endif - -#endif /* if WMOPS */ -} - - -Word32 BASOP_pop_wmops (void) -{ -#if WMOPS - Word32 ops_cnt; - -#ifdef DEBUG_COUNTER - printf("Exiting: %s\n", readCounterIdName()); -#endif - - ops_cnt = fwc(); - - /* Get back previous context from stack */ - if (sptr > 0) - { - int prevCounter; - - sum_stack[sptr] += ops_cnt; - prevCounter = currCounter; - setCounter(stack[--sptr]); - sum_stack[sptr] += sum_stack[sptr+1]; - sum_curr[prevCounter] += sum_stack[sptr+1]; - } - else - { - /* current_record = -1; */ - setCounter(0); - } - - if (sum_curr[currCounter] > sum_wc[currCounter]) { - sum_wc[currCounter] = sum_curr[currCounter]; - } - if (sum_curr[currCounter] < sum_bc[currCounter]) { - sum_bc[currCounter] = sum_curr[currCounter]; - } - - return ops_cnt; -#else /* if WMOPS */ - return 0; -#endif /* if WMOPS */ -} - -Word32 BASOP_get_wops (void) -{ - return BASOP_pop_wmops(); -} - -#define FRAMES_PER_SECOND 50.0 -#define MILLION_CYCLES 1e6 -#define FAC (FRAMES_PER_SECOND/MILLION_CYCLES) - -static Word32 prom_cnt = 0; - -void WMOPS_destroy(void) -{ -#if WMOPS - int i; - - /* release the memory allocated for the objectName array */ - for (i = 0; i < MAXCOUNTERS+1; i++) - { - if (NULL != objectName[i]) - { - free(objectName[i]); - objectName[i] = NULL; - } - } - - maxCounter = 0; -#endif - - return; -} - - -void WMOPS_output_all(Word16 dtx_mode) -{ -#if WMOPS - float ops_cnt = 0.0f; - int i; - - char *sfmts = "%-40s %8s %8s %7s %7s\n"; - char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; - char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; - char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - - fprintf (stderr, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); - /*fprintf (stderr, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ - fprintf (stderr, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ - for (i = 0; i < (int)(sizeof(BasicOperationList)/sizeof(char*)) ; i++) - { - fprintf (stderr, "\t%16s: %12d\n", BasicOperationList[i], ((UWord32*)&glob_multiCounter)[i]); - } - - fprintf (stderr, "\n\nWeighted MOPS Analysis:\n"); - fprintf (stderr, "%74s %23s\n", "|------ SELF ------|" - ,"|--- CUMULATIVE ---|"); - fprintf (stderr, sfmt, " routine", " calls", " min ", " max ", " avg ", " min ", " max ", " avg "); - fprintf (stderr, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); - for (i = 1; i <= maxCounter; i++) - { - if ( nbcalls[i] > 0 ) - { - fprintf( stderr, dfmt, - objectName[i], - ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], - ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], - ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], - ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], - frameRate * ( glob_sum_bc[i] ), - frameRate * ( glob_sum_wc[i] ), - ( nbframe[i] == 0 ) ? 0 : (float) ( total_sum[i] / (float) nbframe[i] ) ); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_wmops[i] + total_wmops_children[i]) /(float)nbframe[i])); */ - } - ops_cnt += total_wmops[i]; - } - - fprintf (stderr, sfmts, " -----------------", " ------", "------", "------", "------"); - if ( nbframe[i] > 0 ) - { - fprintf( stderr, dfmts, - "total", - (double) nbframe[0], - frameRate * glob_bc[0], - frameRate * glob_wc[0], - ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); - } -#if 0 - { - char *sfmtt = "%20s %4s %15s\n"; - char *dfmtt = "%20s %4d "; - - fprintf (stderr, "\nCall Tree:\n\n"); - fprintf (stderr, sfmtt, " function", "num", "called by: "); - fprintf (stderr, sfmtt, "---------------", "---", "--------------"); - - for (i = 1; i <= maxCounter; i++) - { - int j; - - fprintf (stderr, dfmtt, objectName[i], i); - for (j = 0; call_tree[i][j] != -1; j++) - { - if (j != 0) - { - fprintf (stderr, ", "); - } - fprintf (stderr, "%s", objectName[call_tree[i][j]]); - } - fprintf (stderr, "\n"); - - } - fprintf (stderr, sfmtt, "---------------", "---", "--------------"); - fprintf (stderr, "\n\n"); - } -#endif - -#if 0 - fprintf (stderr, "\n\n"); - for (i=1; i<=maxCounter; i++) - { - setCounter(i); - WMOPS_output(dtx_mode); - } -#else - (void)dtx_mode; -#endif - -#if MAX_CALLERS_SAVED_FRAMES - for (i = 1; i <= MAX_CALLERS_SAVED_FRAMES; i++) - { - int j, k, l, m; - const char *frame_rank[] = { "st", "nd", "rd", "th" }; - float current; - - k = 0; - for (j=k+1; j callers_totals[k]) - { /* Yes */ - k = j; - } - } - k+=1; - - fprintf(stderr, "\nActive Callers Report for %i%s Worst Case Frame #: %i\n", - i, i<=3?frame_rank[i-1]:frame_rank[3], - callers_frames_nos[k-1]); - /* Print up to 'MAX_CALLERS_PRINT' Callers */ - current = 0.0f; - for (l = 0; l < MAX_CALLERS_PRINT; l++) - { - /* Find Highest Complexity */ - m = 1; - for (j = m+1; j <= maxCounter; j++) - { - if (callers_frames[k][j] < 0) - break; - if (callers_frames[k][j] > callers_frames[k][m]) - m = j; - } - /* Done ? */ - if (callers_frames[k][m] == 0) - break; - fprintf(stderr, " %-52s %10.3f\n", objectName[m], callers_frames[k][m]*frameRate); - /* Count it */ - current += callers_frames[k][m]; - /* Mark as Done */ - callers_frames[k][m] = 0.0f; - } - /* Check if All Printed */ - if (current+0.001f < callers_totals[k-1]) - { - fprintf(stderr, " Only first %i Callers have been Printed!\n", MAX_CALLERS_PRINT); - fprintf(stderr, " %-52s %10.3f\n", "Total for non Printed", (callers_totals[k-1]-current)*frameRate); - } - fprintf(stderr, " %-52s %10.3f\n", "Total", callers_totals[k-1]*frameRate); - /* Mark as Done */ - callers_totals[k-1] = 0.0f; - } -#endif - WMOPS_destroy(); - -#endif /* if WMOPS */ -} -void WMOPS_output_all_std(Word16 dtx_mode) -{ -#if WMOPS - float ops_cnt = 0.0f; - int i; - - char *sfmts = "%-40s %8s %8s %7s %7s\n"; - char *dfmts = "%-40s %8.2f %8.3f %7.3f %7.3f\n"; - char *sfmt = "%-40s %8s %8s %7s %7s %7s %7s %7s\n"; - char *dfmt = "%-40s %8.2f %8.3f %7.3f %7.3f %7.3f %7.3f %7.3f\n"; - - fprintf (stdout, "\nProgram Memory Analysis: %12.0f words\n", (float)prom_cnt); - /*fprintf (stdout, "\nInstruction Type Analysis (for worst case frame):\n\n");*/ - fprintf (stdout, "\nInstruction Type Analysis (for worst case frame number %ld):\n\n", (long int)nbframe[0]); /* added -- JPA */ - if ( nbframe[0] > 0 ) - { - for ( i = 0; i < (int) ( sizeof( BasicOperationList ) / sizeof( char * ) ); i++ ) - { - fprintf( stdout, "\t%16s: %12d\n", BasicOperationList[i], ( (UWord32 *) &glob_multiCounter )[i] ); - } - } - fprintf (stdout, "\n\nWeighted MOPS Analysis:\n"); - fprintf (stdout, "%74s %23s\n", "|------ SELF ------|" - ,"|--- CUMULATIVE ---|"); - fprintf (stdout, sfmt, " routine", "calls/fr", " min ", " max ", " avg ", " min ", " max ", " avg "); - fprintf (stdout, sfmt, " ------------------------", " ------", "------", "------", "------", "------", "------", "------"); - for (i = 1; i <= maxCounter; i++) - { - if ( nbcalls[i] > 0 ) - { - fprintf( stdout, dfmt, - objectName[i], - ( nbframe[i] == 0 ) ? 0 : (float) nbcalls[i] / (float) nbframe[0], - ( glob_bc[i] == 0 ) ? 0 : frameRate * (float) glob_bc[i], - ( glob_wc[i] == 0 ) ? 0 : frameRate * (float) glob_wc[i], - ( nbframe[i] == 0 ) ? 0 : (float) total_wmops[i] / (float) nbframe[i], - frameRate * ( glob_sum_bc[i] ), - frameRate * ( glob_sum_wc[i] ), - ( nbframe[i] == 0 ) ? 0 : (float) ( ( total_sum[i] ) / (float) nbframe[i] ) ); - /* frameRate*(glob_bc[i]+wmops_children_bc[i]), */ - /* frameRate*(glob_wc[i]+wmops_children_wc[i]), */ - /* (nbframe[i] == 0) ? 0 : (float)((total_sum[i]) /(float)nbframe[i])); */ - } - ops_cnt += total_wmops[i]; - } - - fprintf (stdout, sfmts, " -----------------", " ------", "------", "------", "------"); - if ( nbframe[0] > 0 ) - { - fprintf( stdout, dfmts, - "total", - (double) nbframe[0], - frameRate * glob_bc[0], - frameRate * glob_wc[0], - ( nbframe[0] == 0 ) ? 0 : ops_cnt / nbframe[0] ); - } -#if 0 - { - char *sfmtt = "%20s %4s %15s\n"; - char *dfmtt = "%20s %4d "; - - fprintf (stdout, "\nCall Tree:\n\n"); - fprintf (stdout, sfmtt, " function", "num", "called by: "); - fprintf (stdout, sfmtt, "---------------", "---", "--------------"); - - for (i = 1; i <= maxCounter; i++) - { - int j; - - fprintf (stdout, dfmtt, objectName[i], i); - for (j = 0; call_tree[i][j] != -1; j++) - { - if (j != 0) - { - fprintf (stdout, ", "); - } - fprintf (stdout, "%s", objectName[call_tree[i][j]]); - } - fprintf (stdout, "\n"); - - } - fprintf (stdout, sfmtt, "---------------", "---", "--------------"); - fprintf (stdout, "\n\n"); - } -#endif - -#if 0 - fprintf (stdout, "\n\n"); - for (i=1; i<=maxCounter; i++) - { - setCounter(i); - WMOPS_output(dtx_mode); - } -#else - (void)dtx_mode; -#endif - - - WMOPS_destroy(); - -#endif /* if WMOPS */ -} - - -void Reset_all_WMOPS_counter (void) -{ -#if WMOPS - int i; - int currCounterSave; - - currCounterSave = currCounter; - - for (i=2; i <= maxCounter; i++) - { - setCounter(i); - Init_WMOPS_counter(); - objectName[i] = 0; - } - - currCounter = currCounterSave; - maxCounter = 1; -#endif /* if WMOPS */ -} - -/* Returns the total min/max/avg WMOPS values like printed in BASOP_end(). */ -void BASOP_get_total_wmops(double *min, double *max, double *avg) -{ -#if WMOPS - if(min != NULL) - *min = frameRate * glob_bc[0]; - if(max != NULL) - *max = frameRate * glob_wc[0]; - if(avg != NULL) { - int i; - double ops_cnt = 0; - for(i = 1; i <= maxCounter; i++) - ops_cnt += total_wmops[i]; - *avg = (nbframe[0] == 0) ? 0 : ops_cnt / nbframe[0]; - } -#endif /* if WMOPS */ -} - -/* end of file */ -- GitLab