📄 count.c
字号:
/* Version 2.0 Last modified: 6/30/95 */
#include <stdio.h>
#include "typedef.h"
#include "count.h"
/* global counter variable for calculation of complexity weight */
BASIC_OP counter;
const BASIC_OP op_weight = {
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,
3,3,3,4,15,18,30,1,2,1,2,2};
/* local variable */
#define NbFuncMax 1024
static Word16 funcid, nbframe;
static Word32 glob_wc, wc[NbFuncMax];
static float total_wmops;
static Word32 LastWOper;
Word32 TotalWeightedOperation()
{
Word16 i;
Word32 tot, *ptr, *ptr2;
tot = 0;
ptr = (Word32 *)&counter;
ptr2 = (Word32 *)&op_weight;
for (i=0; i<(sizeof(counter)/sizeof(Word32)); i++)
{
tot += ((*ptr++) * (*ptr2++));
}
return ((Word32)tot);
}
Word32 DeltaWeightedOperation()
{
Word32 NewWOper, delta;
NewWOper = TotalWeightedOperation();
delta = NewWOper - LastWOper;
LastWOper = NewWOper;
return (delta);
}
void move16(void)
{
counter.DataMove16++;
}
void move32(void)
{
counter.DataMove32++;
}
void test(void)
{
counter.Test++;
}
void logic16(void)
{
counter.Logic16++;
}
void logic32(void)
{
counter.Logic32++;
}
void Init_WMOPS_counter(void)
{
Word16 i;
/* reset function weight operation counter variable */
for (i=0; i<NbFuncMax; i++) wc[i] = (Word32)0;
glob_wc = 0;
nbframe=0;
total_wmops = (float)0.0;
}
void Reset_WMOPS_counter(void)
{
Word16 i;
Word32 *ptr;
ptr = (Word32 *)&counter;
for (i=0; i<(sizeof(counter)/sizeof(Word32)); i++)
{
*ptr++ = 0;
}
LastWOper = 0;
funcid = 0; /* new frame, set function id to zero */
}
Word32 fwc(void) /* function worst case */
{
Word32 tot;
tot = DeltaWeightedOperation();
if (tot > wc[funcid]) wc[funcid] = tot;
funcid++;
return (tot);
}
void WMOPS_output(void)
{
Word32 i, tot, tot_wc;
tot = TotalWeightedOperation();
if (tot > glob_wc) glob_wc = tot;
printf("Frame=%6d ",nbframe);
printf("WMOPS=%.2f",((float)tot)*0.0001);
nbframe++;
total_wmops += ((float)tot)*(float)0.0001;
printf(" Average=%.2f",total_wmops/(float)nbframe);
printf(" WorstCase=%.2f",((float)glob_wc)*0.0001);
tot_wc=0;
for (i=0; i<funcid; i++) tot_wc += wc[(int)i];
printf(" WorstWC=%.2f\n",((float)tot_wc)*0.0001);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -