FreeCalypso > hg > efr-experiments
comparison src/count.c @ 0:56410792419a
src: original EFR source from ETSI
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 03 Apr 2024 05:31:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:56410792419a |
---|---|
1 /*********************************************************************** | |
2 * | |
3 * This file contains functions for the automatic complexity calculation | |
4 * | |
5 *************************************************************************/ | |
6 | |
7 #include <stdio.h> | |
8 #include "typedef.h" | |
9 #include "count.h" | |
10 | |
11 /* Global counter variable for calculation of complexity weight */ | |
12 | |
13 BASIC_OP counter; | |
14 | |
15 const BASIC_OP op_weight = | |
16 { | |
17 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
18 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
19 3, 3, 3, 4, 15, 18, 30, 1, 2, 1, 2, 2 | |
20 }; | |
21 | |
22 /* local variable */ | |
23 | |
24 #define NbFuncMax 1024 | |
25 | |
26 static Word16 funcid, nbframe; | |
27 static Word32 glob_wc, wc[NbFuncMax]; | |
28 static float total_wmops; | |
29 | |
30 static Word32 LastWOper; | |
31 | |
32 Word32 TotalWeightedOperation () | |
33 { | |
34 Word16 i; | |
35 Word32 tot, *ptr, *ptr2; | |
36 | |
37 tot = 0; | |
38 ptr = (Word32 *) &counter; | |
39 ptr2 = (Word32 *) &op_weight; | |
40 for (i = 0; i < (sizeof (counter) / sizeof (Word32)); i++) | |
41 | |
42 { | |
43 tot += ((*ptr++) * (*ptr2++)); | |
44 } | |
45 | |
46 return ((Word32) tot); | |
47 } | |
48 | |
49 Word32 DeltaWeightedOperation () | |
50 { | |
51 Word32 NewWOper, delta; | |
52 | |
53 NewWOper = TotalWeightedOperation (); | |
54 delta = NewWOper - LastWOper; | |
55 LastWOper = NewWOper; | |
56 return (delta); | |
57 } | |
58 | |
59 void move16 (void) | |
60 { | |
61 counter.DataMove16++; | |
62 } | |
63 | |
64 void move32 (void) | |
65 { | |
66 counter.DataMove32++; | |
67 } | |
68 | |
69 void test (void) | |
70 { | |
71 counter.Test++; | |
72 } | |
73 | |
74 void logic16 (void) | |
75 { | |
76 counter.Logic16++; | |
77 } | |
78 | |
79 void logic32 (void) | |
80 { | |
81 counter.Logic32++; | |
82 } | |
83 | |
84 void Init_WMOPS_counter (void) | |
85 { | |
86 Word16 i; | |
87 | |
88 /* reset function weight operation counter variable */ | |
89 | |
90 for (i = 0; i < NbFuncMax; i++) | |
91 wc[i] = (Word32) 0; | |
92 glob_wc = 0; | |
93 nbframe = 0; | |
94 total_wmops = 0.0; | |
95 | |
96 } | |
97 | |
98 void Reset_WMOPS_counter (void) | |
99 { | |
100 Word16 i; | |
101 Word32 *ptr; | |
102 | |
103 ptr = (Word32 *) &counter; | |
104 for (i = 0; i < (sizeof (counter) / sizeof (Word32)); i++) | |
105 | |
106 { | |
107 *ptr++ = 0; | |
108 } | |
109 LastWOper = 0; | |
110 | |
111 funcid = 0; /* new frame, set function id to zero */ | |
112 } | |
113 | |
114 Word32 fwc (void) /* function worst case */ | |
115 { | |
116 Word32 tot; | |
117 | |
118 tot = DeltaWeightedOperation (); | |
119 if (tot > wc[funcid]) | |
120 wc[funcid] = tot; | |
121 | |
122 funcid++; | |
123 | |
124 return (tot); | |
125 } | |
126 | |
127 void WMOPS_output (Word16 dtx_mode) | |
128 { | |
129 Word16 i; | |
130 Word32 tot, tot_wc; | |
131 | |
132 tot = TotalWeightedOperation (); | |
133 if (tot > glob_wc) | |
134 glob_wc = tot; | |
135 | |
136 fprintf (stderr, "WMOPS=%.2f", ((float) tot) * 0.00005); | |
137 | |
138 nbframe++; | |
139 total_wmops += ((float) tot) * 0.00005; | |
140 fprintf (stderr, " Average=%.2f", total_wmops / (float) nbframe); | |
141 | |
142 fprintf (stderr, " WorstCase=%.2f", ((float) glob_wc) * 0.00005); | |
143 | |
144 /* Worst worst case printed only when not in DTX mode */ | |
145 if (dtx_mode == 0) | |
146 { | |
147 tot_wc = 0L; | |
148 for (i = 0; i < funcid; i++) | |
149 tot_wc += wc[i]; | |
150 fprintf (stderr, " WorstWC=%.2f", ((float) tot_wc) * 0.00005); | |
151 } | |
152 fprintf (stderr, "\n"); | |
153 } |