📄 count.c
字号:
/*
===========================================================================
File: COUNT.C v.2.0 - 15.Nov.2004
===========================================================================
ITU-T STL BASIC OPERATORS
COMPLEXITY EVALUATION FUNCTIONS
History:
15 Nov 04 v2.0 L_mls() weight of 5.
div_l() weight of 32.
i_mult() weight of 3.
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.
============================================================================
*/
/*****************************************************************************
*
* This file contains functions for the automatic complexity calculation
*
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "stl.h"
#ifdef WMOPS
/* Global counter variable for calculation of complexity weight */
BASIC_OP multiCounter[MAXCOUNTERS];
int currCounter=0; /* Zero equals global counter */
#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"
};
#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, 3, 1,
1, 1, 1, 3, 1,
4, 1, 18, 1, 1,
2, 1, 2, 2, 1,
1, 1, 1, 1, 1,
3, 3, 3, 3, 1,
1, 1, 1, 1, 1,
1, 1, 1, 2,
1, 2, 2, 4, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 3,
3, 3, 3, 3, 1,
1, 1, 1, 1, 1,
1, 1, 1, 4, 4,
4, 8, 3, 4, 4
, 5, 32, 3
};
#endif /* ifdef WMOPS */
Word32 TotalWeightedOperation (void);
Word32 DeltaWeightedOperation (void);
#ifdef WMOPS
/* Counters for separating counting for different objects */
static int maxCounter=0;
static char* objectName[MAXCOUNTERS+1];
static Word16 fwc_corr[MAXCOUNTERS+1];
static long int nbTimeObjectIsCalled[MAXCOUNTERS+1];
#define NbFuncMax 1024
static Word16 funcid[MAXCOUNTERS], nbframe[MAXCOUNTERS];
static Word32 glob_wc[MAXCOUNTERS], wc[MAXCOUNTERS][NbFuncMax];
static float total_wmops[MAXCOUNTERS];
static Word32 LastWOper[MAXCOUNTERS];
#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 */
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;
#endif /* ifdef WMOPS */
}
void incrementNbTimeObjectIsCalled( int counterId) {
#if WMOPS
if( (counterId > maxCounter)
|| (counterId < 0)) {
nbTimeObjectIsCalled[0]++;
return;
}
nbTimeObjectIsCalled[counterId]++;
#endif /* ifdef WMOPS */
}
#if WMOPS
static Word32 WMOPS_frameStat() {
/* 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;
/* 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() {
Word16 i;
Word32 *ptr = (Word32 *) &multiCounter[currCounter];
for( i = 0; i < (sizeof (multiCounter[currCounter])/ sizeof (Word32)); i++) {
*ptr++ = 0;
}
}
#endif /* ifdef WMOPS */
void ClearNbTimeObjectsAreCalled() {
#if WMOPS
Word16 i;
for (i = 0; i < (sizeof (multiCounter[currCounter])/ sizeof (Word32)); i++) {
nbTimeObjectIsCalled[i] = 0;
}
#endif /* ifdef WMOPS */
}
Word32 TotalWeightedOperation () {
#if WMOPS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -