Line data Source code
1 : /*
2 : * (C) 2024 copyright VoiceAge Corporation. All Rights Reserved.
3 : *
4 : * This software is protected by copyright law and by international treaties. The source code, and all of its derivations,
5 : * is provided by VoiceAge Corporation under the "ITU-T Software Tools' General Public License". Please, read the license file
6 : * or refer to ITU-T Recommendation G.191 on "SOFTWARE TOOLS FOR SPEECH AND AUDIO CODING STANDARDS".
7 : *
8 : * Any use of this software is permitted provided that this notice is not removed and that neither the authors nor
9 : * VoiceAge Corporation are deemed to have made any representations as to the suitability of this software
10 : * for any purpose nor are held responsible for any defects of this software. THERE IS NO WARRANTY FOR THIS SOFTWARE.
11 : *
12 : * Authors: Guy Richard, Vladimir Malenovsky (Vladimir.Malenovsky@USherbrooke.ca)
13 : */
14 :
15 : #ifndef WMOPS_H
16 : #define WMOPS_H
17 :
18 : #ifndef EXIT_FAILURE
19 : #include <stdlib.h> /* stdlib is needed for exit() */
20 : #endif
21 :
22 : #ifndef EOF
23 : #include <stdio.h> /* stdio is needed for fprintf() */
24 : #endif
25 :
26 : #include "options.h"
27 :
28 : /* To Prevent "warning: '$' in identifier or number" message under GCC */
29 : #ifdef __GNUC__
30 : #pragma GCC system_header
31 : #endif
32 :
33 : #define ENH_32_BIT_OPERATOR
34 : #define ENH_64_BIT_OPERATOR
35 : #define ENH_U_32_BIT_OPERATOR
36 : #define COMPLEX_OPERATOR
37 : #define CONTROL_CODE_OPS /* enable control code operators such as LT_16, GT_16, ... */
38 : #define WMOPS_DISABLE_FCN_CALL_PENALIZATION /* do not count the complexity of function calls */
39 :
40 : #ifdef WMOPS
41 : enum instructions
42 : {
43 : _ADD,
44 : _ABS,
45 : _MULT,
46 : _MAC,
47 : _MOVE,
48 : _STORE,
49 : _LOGIC,
50 : _SHIFT,
51 : _BRANCH,
52 : _DIV,
53 : _SQRT,
54 : _TRANS,
55 : _FUNC,
56 : _LOOP,
57 : _INDIRECT,
58 : _PTR_INIT,
59 : _TEST,
60 : _POWER,
61 : _LOG,
62 : _MISC,
63 : NUM_INST
64 : };
65 :
66 : extern double ops_cnt;
67 : extern double inst_cnt[NUM_INST];
68 :
69 : /******************************************************************/
70 : /* NOTES: */
71 : /* The 'wmc_flag_' flag is global to avoid declaration in every */
72 : /* function and 'static' to avoid clashing with other modules */
73 : /* that include this header file. */
74 : /* */
75 : /* The declarations of 'wmc_flag_' and 'wops_' in this header */
76 : /* file prevent the addition of a 'C' file to the Project. */
77 : /******************************************************************/
78 :
79 : /* General Purpose Global int */
80 : static int wmc_flag_ = 0;
81 :
82 : #define push_wmops( ... ) push_wmops_fct( __VA_ARGS__, NULL )
83 : void push_wmops_fct( const char *label, ... );
84 : void pop_wmops( void );
85 : void reset_wmops( void );
86 : void print_wmops( void );
87 : void update_wmops( void );
88 : void update_mem( void );
89 :
90 : #define _ADD_C 1
91 : #define _ABS_C 1
92 : #define _MULT_C 1
93 : #define _MAC_C 1
94 : #define _MOVE_C 1
95 : #define _STORE_C 1
96 : #define _LOGIC_C 1
97 : #define _SHIFT_C 1
98 : #define _BRANCH_C 4
99 : #define _DIV_C 18
100 : #define _SQRT_C 10
101 : #define _TRANS_C 25
102 : #define _FUNC_C 2 /* need to add number of arguments */
103 : #define _LOOP_C 3
104 : #define _INDIRECT_C 2
105 : #define _PTR_INIT_C 1
106 : #define _TEST_C 2
107 : #define _POWER_C 25
108 : #define _LOG_C 25
109 : #define _MISC_C 1
110 :
111 : #define ADD( x ) \
112 : { \
113 : ops_cnt += ( _ADD_C * ( x ) ); \
114 : inst_cnt[_ADD] += ( x ); \
115 : }
116 : #define ABS( x ) \
117 : { \
118 : ops_cnt += ( _ABS_C * ( x ) ); \
119 : inst_cnt[_ABS] += ( x ); \
120 : }
121 : #define MULT( x ) \
122 : { \
123 : ops_cnt += ( _MULT_C * ( x ) ); \
124 : inst_cnt[_MULT] += ( x ); \
125 : }
126 : #define MAC( x ) \
127 : { \
128 : ops_cnt += ( _MAC_C * ( x ) ); \
129 : inst_cnt[_MAC] += ( x ); \
130 : }
131 : #define MOVE( x ) \
132 : { \
133 : ops_cnt += ( _MOVE_C * ( x ) ); \
134 : inst_cnt[_MOVE] += ( x ); \
135 : }
136 : #define STORE( x ) \
137 : { \
138 : ops_cnt += ( _STORE_C * ( x ) ); \
139 : inst_cnt[_STORE] += ( x ); \
140 : }
141 : #define LOGIC( x ) \
142 : { \
143 : ops_cnt += ( _LOGIC_C * ( x ) ); \
144 : inst_cnt[_LOGIC] += ( x ); \
145 : }
146 : #define SHIFT( x ) \
147 : { \
148 : ops_cnt += ( _SHIFT_C * ( x ) ); \
149 : inst_cnt[_SHIFT] += ( x ); \
150 : }
151 : #define BRANCH( x ) \
152 : { \
153 : ops_cnt += ( _BRANCH_C * ( x ) ); \
154 : inst_cnt[_BRANCH] += ( x ); \
155 : }
156 : #define DIV( x ) \
157 : { \
158 : ops_cnt += ( _DIV_C * ( x ) ); \
159 : inst_cnt[_DIV] += ( x ); \
160 : }
161 : #define SQRT( x ) \
162 : { \
163 : ops_cnt += ( _SQRT_C * ( x ) ); \
164 : inst_cnt[_SQRT] += ( x ); \
165 : }
166 : #define TRANS( x ) \
167 : { \
168 : ops_cnt += ( _TRANS_C * ( x ) ); \
169 : inst_cnt[_TRANS] += ( x ); \
170 : }
171 : #define LOOP( x ) \
172 : { \
173 : ops_cnt += ( _LOOP_C * ( x ) ); \
174 : inst_cnt[_LOOP] += ( x ); \
175 : }
176 : #define INDIRECT( x ) \
177 : { \
178 : ops_cnt += ( _INDIRECT_C * ( x ) ); \
179 : inst_cnt[_INDIRECT] += ( x ); \
180 : }
181 : #define PTR_INIT( x ) \
182 : { \
183 : ops_cnt += ( _PTR_INIT_C * ( x ) ); \
184 : inst_cnt[_PTR_INIT] += ( x ); \
185 : }
186 : #define TEST( x ) \
187 : { \
188 : ops_cnt += ( _TEST_C * ( x ) ); \
189 : inst_cnt[_TEST] += ( x ); \
190 : }
191 : #define POWER( x ) \
192 : { \
193 : ops_cnt += ( _POWER_C * ( x ) ); \
194 : inst_cnt[_POWER] += ( x ); \
195 : }
196 : #define LOG( x ) \
197 : { \
198 : ops_cnt += ( _LOG_C * ( x ) ); \
199 : inst_cnt[_LOG] += ( x ); \
200 : }
201 : #define MISC( x ) \
202 : { \
203 : ops_cnt += ( _MISC_C * ( x ) ); \
204 : inst_cnt[_MISC] += ( x ); \
205 : }
206 : #define FUNC( x ) \
207 : { \
208 : ops_cnt += ( _FUNC_C + _MOVE_C * ( x ) ); \
209 : inst_cnt[_FUNC]++; \
210 : inst_cnt[_MOVE] += ( x ); \
211 : }
212 : #define DADD( x ) \
213 : { \
214 : ops_cnt += ( 2 * _ADD_C * ( x ) ); \
215 : inst_cnt[_ADD] += ( x ); \
216 : }
217 : #define DMULT( x ) \
218 : { \
219 : ops_cnt += ( 2 * _MULT_C * ( x ) ); \
220 : inst_cnt[_MULT] += ( x ); \
221 : }
222 : #define DMAC( x ) \
223 : { \
224 : ops_cnt += ( 2 * _MAC_C * ( x ) ); \
225 : inst_cnt[_MAC] += ( x ); \
226 : }
227 : #define DMOVE( x ) \
228 : { \
229 : ops_cnt += ( 2 * _MOVE_C * ( x ) ); \
230 : inst_cnt[_MOVE] += ( x ); \
231 : }
232 : #define DSTORE( x ) \
233 : { \
234 : ops_cnt += ( 2 * _STORE_C * ( x ) ); \
235 : inst_cnt[_STORE] += ( x ); \
236 : }
237 : #define DLOGIC( x ) \
238 : { \
239 : ops_cnt += ( 2 * _LOGIC_C * ( x ) ); \
240 : inst_cnt[_LOGIC] += ( x ); \
241 : }
242 : #define DSHIFT( x ) \
243 : { \
244 : ops_cnt += ( 2 * _SHIFT_C * ( x ) ); \
245 : inst_cnt[_SHIFT] += ( x ); \
246 : }
247 : #define DDIV( x ) \
248 : { \
249 : ops_cnt += ( 2 * _DIV_C * ( x ) ); \
250 : inst_cnt[_DIV] += ( x ); \
251 : }
252 : #define DSQRT( x ) \
253 : { \
254 : ops_cnt += ( 2 * _SQRT_C * ( x ) ); \
255 : inst_cnt[_SQRT] += ( x ); \
256 : }
257 : #define DTRANS( x ) \
258 : { \
259 : ops_cnt += ( 2 * _TRANS_C * ( x ) ); \
260 : inst_cnt[_TRANS] += ( x ); \
261 : }
262 :
263 : #else
264 :
265 : extern int cntr_push_pop;
266 : #define push_wmops( x ) ( cntr_push_pop++ )
267 : #define pop_wmops() ( cntr_push_pop-- )
268 : #define reset_wmops()
269 : #define print_wmops()
270 : #define update_wmops() ( assert( cntr_push_pop == 0 ) )
271 : #define update_mem()
272 :
273 : #define ADD( x )
274 : #define ABS( x )
275 : #define MULT( x )
276 : #define MAC( x )
277 : #define MOVE( x )
278 : #define STORE( x )
279 : #define LOGIC( x )
280 : #define SHIFT( x )
281 : #define BRANCH( x )
282 : #define DIV( x )
283 : #define SQRT( x )
284 : #define TRANS( x )
285 : #define FUNC( x )
286 : #define LOOP( x )
287 : #define INDIRECT( x )
288 : #define PTR_INIT( x )
289 : #define TEST( x )
290 : #define POWER( x )
291 : #define LOG( x )
292 : #define MISC( x )
293 :
294 : #define DADD( x )
295 : #define DMULT( x )
296 : #define DMAC( x )
297 : #define DMOVE( x )
298 : #define DSTORE( x )
299 : #define DLOGIC( x )
300 : #define DSHIFT( x )
301 : #define DDIV( x )
302 : #define DSQRT( x )
303 : #define DTRANS( x )
304 :
305 : #endif
306 :
307 : #ifndef WMOPS
308 : /* DESACTIVATE the Counting Mechanism */
309 : #define OP_COUNT_( op, n )
310 :
311 : /* DESACTIVATE Operation Counter Wrappers */
312 : #define OP_COUNT_WRAPPER1_( op, val ) ( val )
313 : #define OP_COUNT_WRAPPER2_( expr )
314 : #define OP_COUNT_WRAPPER3_( op, expr ) expr
315 :
316 : /* DESACTIVATE Logical & Ternary Operators */
317 : #define __
318 : #define _
319 :
320 : #else
321 :
322 : /* Operation Counter Wrappers */
323 : #define OP_COUNT_( op, x ) ( ops_cnt += ( op##_C * ( x ) ), inst_cnt[op] += ( x ) )
324 : #define OP_COUNT_WRAPPER1_( op, val ) ( op, val )
325 : #define OP_COUNT_WRAPPER2_( expr ) \
326 : if ( expr, 0 ) \
327 : ; \
328 : else
329 : #define OP_COUNT_WRAPPER3_( op, expr ) \
330 : if ( op, 0 ) \
331 : ; \
332 : else \
333 : expr
334 :
335 : #endif
336 :
337 : /* Define all Macros without '{' & '}' (None of these should be called externally!) */
338 : #define ABS_( x ) OP_COUNT_( _ABS, ( x ) )
339 : #define ADD_( x ) OP_COUNT_( _ADD, ( x ) )
340 : #define MULT_( x ) OP_COUNT_( _MULT, ( x ) )
341 : #define MAC_( x ) OP_COUNT_( _MAC, ( x ) )
342 : #define MOVE_( x ) OP_COUNT_( _MOVE, ( x ) )
343 : #define STORE_( x ) OP_COUNT_( _STORE, ( x ) )
344 : #define LOGIC_( x ) OP_COUNT_( _LOGIC, ( x ) )
345 : #define SHIFT_( x ) OP_COUNT_( _SHIFT, ( x ) )
346 : #define BRANCH_( x ) OP_COUNT_( _BRANCH, ( x ) )
347 : #define DIV_( x ) OP_COUNT_( _DIV, ( x ) )
348 : #define SQRT_( x ) OP_COUNT_( _SQRT, ( x ) )
349 : #define TRANS_( x ) OP_COUNT_( _TRANS, ( x ) )
350 : #define POWER_( x ) TRANS_( x )
351 : #define LOG_( x ) TRANS_( x )
352 : #define LOOP_( x ) OP_COUNT_( _LOOP, ( x ) )
353 : #define INDIRECT_( x ) OP_COUNT_( _INDIRECT, ( x ) )
354 : #define PTR_INIT_( x ) OP_COUNT_( _PTR_INIT, ( x ) )
355 : #ifdef WMOPS_DISABLE_FCN_CALL_PENALIZATION
356 : #define FUNC_( x ) ( x )
357 : #else
358 : #define FUNC_( x ) ( OP_COUNT_( _MOVE, ( x ) ), OP_COUNT_( _FUNC, 1 ) )
359 : #endif
360 : #define MISC_( x ) ABS_( x )
361 :
362 : /* Math Operations */
363 : #define abs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), abs )
364 : #define fabs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), fabs )
365 : #define fabsf_ OP_COUNT_WRAPPER1_( ABS_( 1 ), fabsf )
366 : #define labs_ OP_COUNT_WRAPPER1_( ABS_( 1 ), labs )
367 : #define floor_ OP_COUNT_WRAPPER1_( MISC_( 1 ), floor )
368 : #define floorf_ OP_COUNT_WRAPPER1_( MISC_( 1 ), floorf )
369 : #define sqrt_ OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrt )
370 : #define sqrtf_ OP_COUNT_WRAPPER1_( SQRT_( 1 ), sqrtf )
371 : #define pow_ OP_COUNT_WRAPPER1_( POWER_( 1 ), pow )
372 : #define powf_ OP_COUNT_WRAPPER1_( POWER_( 1 ), powf )
373 : #define exp_ OP_COUNT_WRAPPER1_( POWER_( 1 ), exp )
374 : #define expf_ OP_COUNT_WRAPPER1_( POWER_( 1 ), expf )
375 : #define log_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log )
376 : #define logf_ OP_COUNT_WRAPPER1_( LOG_( 1 ), logf )
377 : #define log10_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log10 )
378 : #define log10f_ OP_COUNT_WRAPPER1_( LOG_( 1 ), log10f )
379 : #define cos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cos )
380 : #define cosf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cosf )
381 : #define sin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sin )
382 : #define sinf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinf )
383 : #define tan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tan )
384 : #define tanf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanf )
385 : #define acos_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), acos )
386 : #define acosf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), acosf )
387 : #define asin_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), asin )
388 : #define asinf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), asinf )
389 : #define atan_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan )
390 : #define atanf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atanf )
391 : #define atan2_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan2 )
392 : #define atan2f_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), atan2f )
393 : #define cosh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), cosh )
394 : #define coshf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), coshf )
395 : #define sinh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinh )
396 : #define sinhf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), sinhf )
397 : #define tanh_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanh )
398 : #define tanhf_ OP_COUNT_WRAPPER1_( TRANS_( 1 ), tanhf )
399 : #define fmod_ OP_COUNT_WRAPPER1_( DIV_( 1 ), fmod )
400 : #define fmodf_ OP_COUNT_WRAPPER1_( DIV_( 1 ), fmodf )
401 : #define frexp_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexp )
402 : #define frexpf_ OP_COUNT_WRAPPER1_( MISC_( 2 ), frexpf )
403 :
404 : /* the macros below are instrumented versions of user-defined macros that might be used in the source code
405 : representing some well-known and recognized mathematical operations (that are not defined in math.h)
406 : Note: the 'wmc_flag_=wmc_flag_' is used to avoid warning: left-hand operand of comma expression has no effect with gcc */
407 :
408 : #define min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), min( ( a ), ( b ) ) )
409 : #define max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), max( ( a ), ( b ) ) )
410 : #define MIN_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MIN( ( a ), ( b ) ) )
411 : #define MAX_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), MAX( ( a ), ( b ) ) )
412 : #define Min_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Min( ( a ), ( b ) ) )
413 : #define Max_( a, b ) OP_COUNT_WRAPPER1_( MISC_( 1 ), Max( ( a ), ( b ) ) )
414 : #define sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), sqr( ( x ) ) )
415 : #define Sqr_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Sqr( ( x ) ) )
416 : #define SQR_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQR( ( x ) ) )
417 : #define square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), square( ( x ) ) )
418 : #define Square_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), Square( ( x ) ) )
419 : #define SQUARE_( x ) OP_COUNT_WRAPPER1_( MULT_( 1 ), SQUARE( ( x ) ) )
420 : #define sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), sign( ( x ) ) )
421 : #define Sign_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), Sign( ( x ) ) )
422 : #define SIGN_( x ) OP_COUNT_WRAPPER1_( MOVE_( 1 ), SIGN( ( x ) ) )
423 : #define inv_sqrt_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), inv_sqrt( ( x ) ) )
424 : #define inv_sqrtf_( x ) OP_COUNT_WRAPPER1_( SQRT_( 1 ), inv_sqrtf( ( x ) ) )
425 : #define log_base_2_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log_base_2( ( x ) ) )
426 : #define log2_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2( ( x ) ) )
427 : #define log2f_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2f( ( x ) ) )
428 : #define log2_f_( x ) OP_COUNT_WRAPPER1_( ( LOG_( 1 ), MULT_( 1 ) ), log2_f( ( x ) ) )
429 : #define _round_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, _round( ( x ) ) )
430 : #define round_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, round( ( x ) ) )
431 : #define round_f_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, round_f( ( x ) ) )
432 : #define roundf_( x ) OP_COUNT_WRAPPER1_( wmc_flag_ = wmc_flag_, roundf( ( x ) ) )
433 : #define set_min_( a, b ) OP_COUNT_WRAPPER3_( ( ADD_( 1 ), BRANCH_( 1 ), MOVE_( 1 ) ), set_min( ( a ), ( b ) ) )
434 : #define set_max_( a, b ) OP_COUNT_WRAPPER3_( ( ADD_( 1 ), BRANCH_( 1 ), MOVE_( 1 ) ), set_max( ( a ), ( b ) ) )
435 :
436 : /* Functions */
437 : #define func_( name, x ) OP_COUNT_WRAPPER1_( FUNC_( x ), name )
438 :
439 : /* Logical Operators */
440 : #ifndef __
441 : #define __ ( BRANCH_( 1 ), 1 ) &&
442 : #endif
443 :
444 : /* Ternary Operators (? and :) */
445 : #ifndef _
446 : #define _ ( BRANCH_( 1 ), 0 ) ? 0:
447 : #endif
448 :
449 : /* Flow Control keywords */
450 : #define if_ \
451 : OP_COUNT_WRAPPER2_( BRANCH_( 1 ) ) \
452 : if
453 : #define for_ OP_COUNT_WRAPPER2_( LOOP_(1)) for
454 : #define while_( c ) \
455 : while \
456 : OP_COUNT_WRAPPER1_( BRANCH_( 1 ), ( c ) ) /* needs extra "()" if ',' encountered */
457 : #define do_ \
458 : do \
459 : {
460 : #define _while \
461 : BRANCH_( 1 ); \
462 : } \
463 : while
464 :
465 : #define goto_ \
466 : OP_COUNT_WRAPPER2_( BRANCH_( 1 ) ) \
467 : goto
468 : #define break_ \
469 : OP_COUNT_WRAPPER2_( BRANCH_( 1 ) ) \
470 : break
471 : #define continue_ \
472 : OP_COUNT_WRAPPER2_( BRANCH_( 1 ) ) \
473 : continue
474 : #define return_ \
475 : OP_COUNT_WRAPPER2_( ( wmc_flag_ = stack_tree_level_, STACK_DEPTH_FCT_RETURN ) ) \
476 : return
477 : #define switch_ \
478 : OP_COUNT_WRAPPER2_( ( BRANCH_( 1 ), wmc_flag_ = 1 ) ) \
479 : switch
480 : #define cost_( n ) OP_COUNT_WRAPPER2_( wmc_flag_ ? ( ADD_( n ), BRANCH_( n ), wmc_flag_ = 0 ) : 0 );
481 :
482 : #ifdef WMOPS
483 :
484 : #define ACC 2
485 : #define MUL 1
486 :
487 : /* Counting Function (should not be called externally!) */
488 : static void wops_( const char *ops )
489 : {
490 : char lm = 0; /* lm: Last Operation is Math */
491 : static char lo = 0; /* Last Operation */
492 :
493 : void ( *fct )( const char *ops ) = wops_;
494 :
495 : st:
496 : while ( *ops != '\0' )
497 : {
498 : switch ( *ops++ )
499 : {
500 : int cnt;
501 : case '-':
502 : for ( cnt = 0; ops[cnt] == '>'; cnt++ )
503 : ;
504 : if ( cnt & 1 )
505 : goto ind;
506 : case '+':
507 : lm = 2;
508 : if ( lo & MUL )
509 : {
510 : MULT_( -1 );
511 : MAC_( 1 );
512 : break;
513 : }
514 : lo = ACC << 2;
515 : case 'U':
516 : case 'D':
517 : ADD_( 1 );
518 : break;
519 : case '*':
520 : lm = 2;
521 : if ( lo & ACC )
522 : {
523 : ADD_( -1 );
524 : MAC_( 1 );
525 : break;
526 : }
527 : lo = MUL << 2;
528 : MULT_( 1 );
529 : break;
530 : case '/':
531 : case '%':
532 : lm = 2;
533 : DIV_( 1 );
534 : break;
535 : case '&':
536 : case '|':
537 : case '^':
538 : lm = 2;
539 : case '~':
540 : LOGIC_( 1 );
541 : break;
542 : case '<':
543 : case '>':
544 : if ( *ops != ops[-1] )
545 : goto error;
546 : ops++;
547 : case -85:
548 : case -69:
549 : lm = 2;
550 : SHIFT_( 1 );
551 : break;
552 : case 'L':
553 : case 'G':
554 : if ( *ops == 't' )
555 : goto comp;
556 : case 'E':
557 : case 'N':
558 : if ( *ops != 'e' )
559 : goto error;
560 : comp:
561 : ops++;
562 : ADD_( 1 );
563 : break;
564 : case '!':
565 : MISC_( 2 );
566 : break;
567 : case 'M':
568 : MOVE_( 1 );
569 : break;
570 : case 'S':
571 : STORE_( 1 );
572 : break;
573 : case 'P':
574 : PTR_INIT_( 1 );
575 : break;
576 : case '[':
577 : case ']':
578 : goto st;
579 : ind:
580 : ops++;
581 : case 'I':
582 : case '.':
583 : INDIRECT_( 1 );
584 : break;
585 : case '=':
586 : if ( lm )
587 : goto st;
588 : case '\0':
589 : /* This Shouldn't Happen */
590 : /* These are Used to Avoid: "warning: 'name' defined but not used" with Cygwin gcc Compiler */
591 : wmc_flag_ = wmc_flag_;
592 : fct( "" );
593 : error:
594 : default:
595 : fprintf( stderr, "\r wops: Invalid Counting Operation '%s'\n", ops - 1 );
596 : exit( -1 );
597 : }
598 : lm >>= 1;
599 : lo >>= 2;
600 : }
601 :
602 : return;
603 : }
604 :
605 : #endif
606 :
607 : /* All Other Operations */
608 : #define $( str ) OP_COUNT_WRAPPER2_( wops_( str ) )
609 :
610 :
611 : /*-------------------------------------------------------------------*
612 : * Memory counting tool
613 : *-------------------------------------------------------------------*/
614 :
615 : /* Enhanced Const Data Size Counting (Rounding Up to the Nearest 'Integer' Size) */
616 : #define rsize( item ) ( ( sizeof( item ) + sizeof( int ) - 1 ) / sizeof( int ) * sizeof( int ) )
617 :
618 : #ifdef _MSC_VER
619 : /* Disable "warning C4210: nonstandard extension used : function given file scope" with Visual Studio Compiler */
620 : #pragma warning( disable : 4210 )
621 : #endif
622 :
623 : /* Const Data Size and PROM Size Wrapper Functions */
624 : #define Const_Data_Size_Func( file ) Const_Data_Size_##file( void )
625 : #define Get_Const_Data_Size( file, val_ptr ) \
626 : { \
627 : extern int Const_Data_Size_##file( void ); \
628 : *( val_ptr ) = Const_Data_Size_##file(); \
629 : }
630 : #define PROM_Size_Func( file ) PROM_Size_##file( void )
631 : #define Get_PROM_Size( file, val_ptr ) \
632 : { \
633 : int PROM_Size_##file( void ); \
634 : *( val_ptr ) = PROM_Size_##file(); \
635 : }
636 :
637 : /* ROM Size Lookup Table - contains information about PROM size and Const Data Size in all source files */
638 : /* The print_mem() function looks for this table to print the results of Const Data usage and PROM usage */
639 : typedef struct ROM_Size_Lookup_Table
640 : {
641 : const char file_spec[255];
642 : int PROM_size;
643 : int ( *Get_Const_Data_Size_Func )( void );
644 : } ROM_Size_Lookup_Table;
645 :
646 : /* The WMC tool inserts the following declaration during the innstrumentation process in the .c file where the function print_mem() is located */
647 : /* and modifies it to print_mem(Const_Data_PROM_Table) */
648 :
649 : /* #ifdef WMOPS
650 : * ROM_Size_Lookup_Table Const_Data_PROM_Table[] =
651 : * {
652 : * {"../lib_enc/rom_enc.c", 0, NULL},
653 : * {"../lib_com/[star].c", 0, NULL},
654 : * {"", -1, NULL}
655 : * };
656 : * #endif
657 : */
658 :
659 : /*#define MEM_ALIGN_64BITS */ /* Define this when using 64 Bits values in the code (ex: double), otherwise it will align on 32 Bits */
660 : /*#define MEM_COUNT_DETAILS*/
661 :
662 : typedef enum
663 : {
664 : USE_BYTES = 0,
665 : USE_16BITS = 1,
666 : USE_32BITS = 2
667 : } Counting_Size;
668 :
669 :
670 : #ifdef WMOPS
671 :
672 : void *mem_alloc( const char *func_name, int func_lineno, size_t size, char *alloc_str );
673 : void mem_free( const char *func_name, int func_lineno, void *ptr );
674 :
675 : #define malloc_( size ) mem_alloc( __func__, __LINE__, size, "m:" #size )
676 : #define calloc_( n, size ) mem_alloc( __func__, __LINE__, ( n ) * ( size ), "c:" #n ", " #size )
677 : #define free_( ptr ) mem_free( __func__, __LINE__, ptr )
678 :
679 : void reset_mem( Counting_Size cnt_size );
680 : void print_mem( ROM_Size_Lookup_Table Const_Data_PROM_Table[] );
681 :
682 : int push_stack( const char *filename, const char *fctname );
683 : int pop_stack( const char *filename, const char *fctname );
684 :
685 : #ifdef WMOPS_DETAIL
686 : #define STACK_DEPTH_FCT_CALL ( push_wmops( __func__, "[WMC_AUTO]" ), push_stack( __FILE__, __func__ ) ) /* add push_wmops() in all function calls */
687 : #define STACK_DEPTH_FCT_RETURN ( pop_wmops(), pop_stack( __FILE__, __func__ ) ) /* add pop_wmops() in all function returns */
688 : #else
689 : #define STACK_DEPTH_FCT_CALL push_stack( __FILE__, __func__ )
690 : #define STACK_DEPTH_FCT_RETURN pop_stack( __FILE__, __func__ )
691 : #endif
692 :
693 : void reset_stack( void );
694 : #define func_start_ int stack_tree_level_ = STACK_DEPTH_FCT_CALL;
695 :
696 : #else
697 : #define malloc_( n1 ) malloc( n1 )
698 : #define calloc_( n1, n2 ) calloc( n1, n2 )
699 : #define free_( ptr ) free( ptr )
700 : #define reset_mem( cnt_size )
701 : #define print_mem( Const_Data_PROM_Table )
702 :
703 : #define push_stack( file, fct )
704 : #define pop_stack( file, fct )
705 : #define reset_stack()
706 : #define func_start_
707 :
708 : #endif
709 :
710 : /* Global counter variable for calculation of complexity weight */
711 : typedef struct
712 : {
713 : unsigned int add; /* Complexity Weight of 1 */
714 : unsigned int sub; /* Complexity Weight of 1 */
715 : unsigned int abs_s; /* Complexity Weight of 1 */
716 : unsigned int shl; /* Complexity Weight of 1 */
717 : unsigned int shr; /* Complexity Weight of 1 */
718 :
719 : unsigned int extract_h; /* Complexity Weight of 1 */
720 : unsigned int extract_l; /* Complexity Weight of 1 */
721 : unsigned int mult; /* Complexity Weight of 1 */
722 : unsigned int L_mult; /* Complexity Weight of 1 */
723 : unsigned int negate; /* Complexity Weight of 1 */
724 :
725 : unsigned int round; /* Complexity Weight of 1 */
726 : unsigned int L_mac; /* Complexity Weight of 1 */
727 : unsigned int L_msu; /* Complexity Weight of 1 */
728 : unsigned int L_macNs; /* Complexity Weight of 1 */
729 : unsigned int L_msuNs; /* Complexity Weight of 1 */
730 :
731 : unsigned int L_add; /* Complexity Weight of 1 */
732 : unsigned int L_sub; /* Complexity Weight of 1 */
733 : unsigned int L_add_c; /* Complexity Weight of 2 */
734 : unsigned int L_sub_c; /* Complexity Weight of 2 */
735 : unsigned int L_negate; /* Complexity Weight of 1 */
736 :
737 : unsigned int L_shl; /* Complexity Weight of 1 */
738 : unsigned int L_shr; /* Complexity Weight of 1 */
739 : unsigned int mult_r; /* Complexity Weight of 1 */
740 : unsigned int shr_r; /* Complexity Weight of 3 */
741 : unsigned int mac_r; /* Complexity Weight of 1 */
742 :
743 : unsigned int msu_r; /* Complexity Weight of 1 */
744 : unsigned int L_deposit_h; /* Complexity Weight of 1 */
745 : unsigned int L_deposit_l; /* Complexity Weight of 1 */
746 : unsigned int L_shr_r; /* Complexity Weight of 3 */
747 : unsigned int L_abs; /* Complexity Weight of 1 */
748 :
749 : unsigned int L_sat; /* Complexity Weight of 4 */
750 : unsigned int norm_s; /* Complexity Weight of 1 */
751 : unsigned int div_s; /* Complexity Weight of 18 */
752 : unsigned int norm_l; /* Complexity Weight of 1 */
753 : unsigned int move16; /* Complexity Weight of 1 */
754 :
755 : unsigned int move32; /* Complexity Weight of 2 */
756 : unsigned int Logic16; /* Complexity Weight of 1 */
757 : unsigned int Logic32; /* Complexity Weight of 2 */
758 : unsigned int Test; /* Complexity Weight of 2 */
759 : unsigned int s_max; /* Complexity Weight of 1 */
760 :
761 : unsigned int s_min; /* Complexity Weight of 1 */
762 : unsigned int L_max; /* Complexity Weight of 1 */
763 : unsigned int L_min; /* Complexity Weight of 1 */
764 : unsigned int L40_max; /* Complexity Weight of 1 */
765 : unsigned int L40_min; /* Complexity Weight of 1 */
766 :
767 : unsigned int shl_r; /* Complexity Weight of 2 */
768 : unsigned int L_shl_r; /* Complexity Weight of 2 */
769 : unsigned int L40_shr_r; /* Complexity Weight of 2 */
770 : unsigned int L40_shl_r; /* Complexity Weight of 2 */
771 : unsigned int norm_L40; /* Complexity Weight of 1 */
772 :
773 : unsigned int L40_shl; /* Complexity Weight of 1 */
774 : unsigned int L40_shr; /* Complexity Weight of 1 */
775 : unsigned int L40_negate; /* Complexity Weight of 1 */
776 : unsigned int L40_add; /* Complexity Weight of 1 */
777 : unsigned int L40_sub; /* Complexity Weight of 1 */
778 :
779 : unsigned int L40_abs; /* Complexity Weight of 1 */
780 : unsigned int L40_mult; /* Complexity Weight of 1 */
781 : unsigned int L40_mac; /* Complexity Weight of 1 */
782 : unsigned int mac_r40; /* Complexity Weight of 2 */
783 :
784 : unsigned int L40_msu; /* Complexity Weight of 1 */
785 : unsigned int msu_r40; /* Complexity Weight of 2 */
786 : unsigned int Mpy_32_16_ss; /* Complexity Weight of 2 */
787 : unsigned int Mpy_32_32_ss; /* Complexity Weight of 2 */
788 : unsigned int L_mult0; /* Complexity Weight of 1 */
789 :
790 : unsigned int L_mac0; /* Complexity Weight of 1 */
791 : unsigned int L_msu0; /* Complexity Weight of 1 */
792 : unsigned int lshl; /* Complexity Weight of 1 */
793 : unsigned int lshr; /* Complexity Weight of 1 */
794 : unsigned int L_lshl; /* Complexity Weight of 1 */
795 :
796 : unsigned int L_lshr; /* Complexity Weight of 1 */
797 : unsigned int L40_lshl; /* Complexity Weight of 1 */
798 : unsigned int L40_lshr; /* Complexity Weight of 1 */
799 : unsigned int s_and; /* Complexity Weight of 1 */
800 : unsigned int s_or; /* Complexity Weight of 1 */
801 :
802 : unsigned int s_xor; /* Complexity Weight of 1 */
803 : unsigned int L_and; /* Complexity Weight of 1 */
804 : unsigned int L_or; /* Complexity Weight of 1 */
805 : unsigned int L_xor; /* Complexity Weight of 1 */
806 : unsigned int rotl; /* Complexity Weight of 3 */
807 :
808 : unsigned int rotr; /* Complexity Weight of 3 */
809 : unsigned int L_rotl; /* Complexity Weight of 3 */
810 : unsigned int L_rotr; /* Complexity Weight of 3 */
811 : unsigned int L40_set; /* Complexity Weight of 1 */
812 : unsigned int L40_deposit_h; /* Complexity Weight of 1 */
813 :
814 : unsigned int L40_deposit_l; /* Complexity Weight of 1 */
815 : unsigned int L40_deposit32; /* Complexity Weight of 1 */
816 : unsigned int Extract40_H; /* Complexity Weight of 1 */
817 : unsigned int Extract40_L; /* Complexity Weight of 1 */
818 : unsigned int L_Extract40; /* Complexity Weight of 1 */
819 :
820 : unsigned int L40_round; /* Complexity Weight of 1 */
821 : unsigned int L_saturate40; /* Complexity Weight of 1 */
822 : unsigned int round40; /* Complexity Weight of 1 */
823 : unsigned int If; /* Complexity Weight of 3 */
824 : unsigned int Goto; /* Complexity Weight of 2 */
825 :
826 : unsigned int Break; /* Complexity Weight of 2 */
827 : unsigned int Switch; /* Complexity Weight of 6 */
828 : unsigned int For; /* Complexity Weight of 3 */
829 : unsigned int While; /* Complexity Weight of 3 */
830 : unsigned int Continue; /* Complexity Weight of 2 */
831 :
832 : unsigned int L_mls; /* Complexity Weight of 1 */
833 : unsigned int div_l; /* Complexity Weight of 32 */
834 : unsigned int i_mult; /* Complexity Weight of 1 */
835 :
836 : /* New complex basic operators */
837 : #ifdef COMPLEX_OPERATOR
838 : unsigned int CL_shr; /* Complexity Weight of 1 */
839 : unsigned int CL_shl; /* Complexity Weight of 1 */
840 : unsigned int CL_add; /* Complexity Weight of 1 */
841 : unsigned int CL_sub; /* Complexity Weight of 1 */
842 : unsigned int CL_scale; /* Complexity Weight of 1 */
843 : unsigned int CL_dscale; /* Complexity Weight of 1 */
844 : unsigned int CL_msu_j; /* Complexity Weight of 1 */
845 : unsigned int CL_mac_j; /* Complexity Weight of 1 */
846 : unsigned int CL_move; /* Complexity Weight of 1 */
847 : unsigned int CL_Extract_real; /* Complexity Weight of 1 */
848 : unsigned int CL_Extract_imag; /* Complexity Weight of 1 */
849 : unsigned int CL_form; /* Complexity Weight of 1 */
850 : unsigned int CL_multr_32x16; /* Complexity Weight of 2 */
851 : unsigned int CL_negate; /* Complexity Weight of 1 */
852 : unsigned int CL_conjugate; /* Complexity Weight of 1 */
853 : unsigned int CL_mul_j; /* Complexity Weight of 1 */
854 : unsigned int CL_swap_real_imag; /* Complexity Weight of 1 */
855 : unsigned int C_add; /* Complexity Weight of 1 */
856 : unsigned int C_sub; /* Complexity Weight of 1 */
857 : unsigned int C_mul_j; /* Complexity Weight of 1 */
858 : unsigned int C_multr; /* Complexity Weight of 2 */
859 : unsigned int C_form; /* Complexity Weight of 1 */
860 :
861 : unsigned int C_scale; /* Complexity Weight of 1 */
862 : unsigned int CL_round32_16; /* Complexity Weight of 1 */
863 : unsigned int CL_scale_32; /* Complexity Weight of 1 */
864 : unsigned int CL_dscale_32; /* Complexity Weight of 1 */
865 : unsigned int CL_multr_32x32; /* Complexity Weight of 2 */
866 : unsigned int C_mac_r; /* Complexity Weight of 2 */
867 : unsigned int C_msu_r; /* Complexity Weight of 2 */
868 : unsigned int C_Extract_real; /* Complexity Weight of 1 */
869 : unsigned int C_Extract_imag; /* Complexity Weight of 1 */
870 : unsigned int C_negate; /* Complexity Weight of 1 */
871 : unsigned int C_conjugate; /* Complexity Weight of 1 */
872 : unsigned int C_shr; /* Complexity Weight of 1 */
873 : unsigned int C_shl; /* Complexity Weight of 1 */
874 :
875 : #endif /* #ifdef COMPLEX_OPERATOR */
876 :
877 : /* New 64 bit basops */
878 : #ifdef ENH_64_BIT_OPERATOR
879 : unsigned int move64; /* Complexity Weight of 1 */
880 : unsigned int W_add_nosat; /* Complexity Weight of 1 */
881 : unsigned int W_sub_nosat; /* Complexity Weight of 1 */
882 : unsigned int W_shl; /* Complexity Weight of 1 */
883 : unsigned int W_shr; /* Complexity Weight of 1 */
884 : unsigned int W_shl_nosat; /* Complexity Weight of 1 */
885 : unsigned int W_shr_nosat; /* Complexity Weight of 1 */
886 : unsigned int W_mac_32_16; /* Complexity Weight of 1 */
887 : unsigned int W_msu_32_16; /* Complexity Weight of 1 */
888 : unsigned int W_mult_32_16; /* Complexity Weight of 1 */
889 : unsigned int W_mult0_16_16; /* Complexity Weight of 1 */
890 : unsigned int W_mac0_16_16; /* Complexity Weight of 1 */
891 : unsigned int W_msu0_16_16; /* Complexity Weight of 1 */
892 : unsigned int W_mult_16_16; /* Complexity Weight of 1 */
893 : unsigned int W_mac_16_16; /* Complexity Weight of 1 */
894 : unsigned int W_msu_16_16; /* Complexity Weight of 1 */
895 : unsigned int W_shl_sat_l; /* Complexity Weight of 1 */
896 : unsigned int W_sat_l; /* Complexity Weight of 1 */
897 : unsigned int W_sat_m; /* Complexity Weight of 1 */
898 : unsigned int W_deposit32_l; /* Complexity Weight of 1 */
899 : unsigned int W_deposit32_h; /* Complexity Weight of 1 */
900 : unsigned int W_extract_l; /* Complexity Weight of 1 */
901 : unsigned int W_extract_h; /* Complexity Weight of 1 */
902 : unsigned int W_round48_L; /* Complexity Weight of 1 */
903 : unsigned int W_round32_s; /* Complexity Weight of 1 */
904 : unsigned int W_norm; /* Complexity Weight of 1 */
905 :
906 : unsigned int W_add; /* Complexity Weight of 1 */
907 : unsigned int W_sub; /* Complexity Weight of 1 */
908 : unsigned int W_neg; /* Complexity Weight of 1 */
909 : unsigned int W_abs; /* Complexity Weight of 1 */
910 : unsigned int W_mult_32_32; /* Complexity Weight of 1 */
911 : unsigned int W_mult0_32_32; /* Complexity Weight of 1 */
912 : unsigned int W_lshl; /* Complexity Weight of 1 */
913 : unsigned int W_lshr; /* Complexity Weight of 1 */
914 : unsigned int W_round64_L; /* Complexity Weight of 1 */
915 :
916 : #endif /* #ifdef ENH_64_BIT_OPERATOR */
917 :
918 : #ifdef ENH_32_BIT_OPERATOR
919 : unsigned int Mpy_32_16_1; /* Complexity Weight of 1 */
920 : unsigned int Mpy_32_16_r; /* Complexity Weight of 1 */
921 : unsigned int Mpy_32_32; /* Complexity Weight of 1 */
922 : unsigned int Mpy_32_32_r; /* Complexity Weight of 1 */
923 : unsigned int Madd_32_16; /* Complexity Weight of 1 */
924 : unsigned int Madd_32_16_r; /* Complexity Weight of 1 */
925 : unsigned int Msub_32_16; /* Complexity Weight of 1 */
926 : unsigned int Msub_32_16_r; /* Complexity Weight of 1 */
927 : unsigned int Madd_32_32; /* Complexity Weight of 1 */
928 : unsigned int Madd_32_32_r; /* Complexity Weight of 1 */
929 : unsigned int Msub_32_32; /* Complexity Weight of 1 */
930 : unsigned int Msub_32_32_r; /* Complexity Weight of 1 */
931 : #endif /* #ifdef ENH_32_BIT_OPERATOR */
932 :
933 : #ifdef ENH_U_32_BIT_OPERATOR
934 : unsigned int UL_addNs; /* Complexity Weight of 1 */
935 : unsigned int UL_subNs; /* Complexity Weight of 1 */
936 : unsigned int UL_Mpy_32_32; /* Complexity Weight of 1 */
937 : unsigned int Mpy_32_32_uu; /* Complexity Weight of 2 */
938 : unsigned int Mpy_32_16_uu; /* Complexity Weight of 2 */
939 : unsigned int norm_ul_float; /* Complexity Weight of 1 */
940 : unsigned int UL_deposit_l; /* Complexity Weight of 1 */
941 : #endif /* #ifdef ENH_U_32_BIT_OPERATOR */
942 :
943 : #ifdef CONTROL_CODE_OPS
944 : unsigned int LT_16; /* Complexity Weight of 1 */
945 : unsigned int GT_16; /* Complexity Weight of 1 */
946 : unsigned int LE_16; /* Complexity Weight of 1 */
947 : unsigned int GE_16; /* Complexity Weight of 1 */
948 : unsigned int EQ_16; /* Complexity Weight of 1 */
949 : unsigned int NE_16; /* Complexity Weight of 1 */
950 : unsigned int LT_32; /* Complexity Weight of 1 */
951 : unsigned int GT_32; /* Complexity Weight of 1 */
952 : unsigned int LE_32; /* Complexity Weight of 1 */
953 : unsigned int GE_32; /* Complexity Weight of 1 */
954 : unsigned int EQ_32; /* Complexity Weight of 1 */
955 : unsigned int NE_32; /* Complexity Weight of 1 */
956 : unsigned int LT_64; /* Complexity Weight of 1 */
957 : unsigned int GT_64; /* Complexity Weight of 1 */
958 : unsigned int LE_64; /* Complexity Weight of 1 */
959 : unsigned int GE_64; /* Complexity Weight of 1 */
960 : unsigned int EQ_64; /* Complexity Weight of 1 */
961 : unsigned int NE_64; /* Complexity Weight of 1 */
962 :
963 : #endif /* #ifdef CONTROL_CODE_OPS */
964 : } BASIC_OP;
965 :
966 : #ifdef WMOPS
967 : extern BASIC_OP *multiCounter;
968 : extern unsigned int currCounter;
969 : extern long funcid_total_wmops_at_last_call_to_else;
970 : extern char func_name_where_last_call_to_else_occurred[];
971 :
972 : long TotalWeightedOperation( unsigned int counterId );
973 : long DeltaWeightedOperation( unsigned int counterId );
974 : void Reset_BASOP_WMOPS_counter( unsigned int counterId );
975 :
976 : #endif
977 :
978 : /*****************************************************************************
979 : *
980 : * Function Name : FOR
981 : *
982 : * Purpose :
983 : *
984 : * The macro FOR should be used instead of the 'for' C statement.
985 : * The complexity is independent of the number of loop iterations that are
986 : * performed.
987 : *
988 : * Complexity weight : 3 (regardless of number of iterations).
989 : *
990 : *****************************************************************************/
991 : #ifndef WMOPS
992 : #define FOR( a ) for ( a )
993 :
994 : #else /* ifndef WMOPS */
995 : #define FOR( a ) \
996 : if ( incrFor(), 0 ) \
997 : ; \
998 : else \
999 : for ( a )
1000 :
1001 : static __inline void incrFor( void )
1002 : {
1003 : multiCounter[currCounter].For++;
1004 : }
1005 : #endif /* ifndef WMOPS */
1006 :
1007 :
1008 : /*****************************************************************************
1009 : *
1010 : * Function Name : WHILE
1011 : *
1012 : * Purpose :
1013 : *
1014 : * The macro WHILE should be used instead of the 'while' C statement.
1015 : * The complexity is proportional to the number of loop iterations that
1016 : * are performed.
1017 : *
1018 : * Complexity weight : 4 x 'number of loop iterations'.
1019 : *
1020 : *****************************************************************************/
1021 : #ifndef WMOPS
1022 : #define WHILE( a ) while ( a )
1023 :
1024 : #else /* ifndef WMOPS */
1025 : #define WHILE( a ) while ( incrWhile(), a )
1026 :
1027 : static __inline void incrWhile( void )
1028 : {
1029 : multiCounter[currCounter].While++;
1030 : }
1031 : #endif /* ifndef WMOPS */
1032 :
1033 :
1034 : /*****************************************************************************
1035 : *
1036 : * Function Name : DO
1037 : *
1038 : * Purpose :
1039 : *
1040 : * The macro DO should be used instead of the 'do' C statement.
1041 : *
1042 : * Complexity weight : 0 (complexity counted by WHILE macro).
1043 : *
1044 : *****************************************************************************/
1045 : #ifndef WMOPS
1046 : #define DO do
1047 :
1048 : #else /* ifndef WMOPS */
1049 : #define DO do
1050 :
1051 : #endif /* ifndef WMOPS */
1052 :
1053 :
1054 : /*****************************************************************************
1055 : *
1056 : * Function Name : IF
1057 : *
1058 : * Purpose :
1059 : *
1060 : * The macro IF should :
1061 : *
1062 : * - not be used when :
1063 : * - the 'if' structure does not have any 'else if' nor 'else' statement
1064 : * - and it conditions only one DSP basic operations.
1065 : *
1066 : * - be used instead of the 'if' C statement in every other case :
1067 : * - when there is an 'else' or 'else if' statement,
1068 : * - or when the 'if' conditions several DSP basic operations,
1069 : * - or when the 'if' conditions a function call.
1070 : *
1071 : * Complexity weight : 3
1072 : *
1073 : *****************************************************************************/
1074 :
1075 : #ifndef WMOPS
1076 : #define IF( a ) if ( a )
1077 : #else /* ifndef WMOPS */
1078 : #define IF( a ) if ( incrIf( __func__ ), a )
1079 : void incrIf( const char *func_name );
1080 : #endif /* ifndef WMOPS */
1081 :
1082 :
1083 : /*****************************************************************************
1084 : *
1085 : * Function Name : ELSE
1086 : *
1087 : * Purpose :
1088 : *
1089 : * The macro ELSE should be used instead of the 'else' C statement.
1090 : *
1091 : * Complexity weight : 3
1092 : *
1093 : *****************************************************************************/
1094 :
1095 : #ifndef WMOPS
1096 : #define ELSE else
1097 : #else /* ifndef WMOPS */
1098 : #define ELSE else if ( incrElse( __func__ ), 0 ); else
1099 : void incrElse( const char *func_name );
1100 : #endif /* ifndef WMOPS */
1101 :
1102 :
1103 : /*****************************************************************************
1104 : *
1105 : * Function Name : SWITCH
1106 : *
1107 : * Purpose :
1108 : *
1109 : * The macro SWITCH should be used instead of the 'switch' C statement.
1110 : *
1111 : * Complexity weight : 6
1112 : *
1113 : *****************************************************************************/
1114 : #ifndef WMOPS
1115 : #define SWITCH( a ) switch ( a )
1116 :
1117 : #else /* ifndef WMOPS */
1118 : #define SWITCH( a ) switch ( incrSwitch(), a )
1119 :
1120 : static __inline void incrSwitch( void )
1121 : {
1122 : multiCounter[currCounter].Switch++;
1123 : }
1124 : #endif /* ifndef WMOPS */
1125 :
1126 :
1127 : /*****************************************************************************
1128 : *
1129 : * Function Name : CONTINUE
1130 : *
1131 : * Purpose :
1132 : *
1133 : * The macro CONTINUE should be used instead of the 'continue' C statement.
1134 : *
1135 : * Complexity weight : 2
1136 : *
1137 : *****************************************************************************/
1138 : #ifndef WMOPS
1139 : #define CONTINUE continue
1140 :
1141 : #else /* ifndef WMOPS */
1142 : #define CONTINUE \
1143 : if ( incrContinue(), 0 ) \
1144 : ; \
1145 : else \
1146 : continue
1147 :
1148 : static __inline void incrContinue( void )
1149 : {
1150 : multiCounter[currCounter].Continue++;
1151 : }
1152 : #endif /* ifndef WMOPS */
1153 :
1154 :
1155 : /*****************************************************************************
1156 : *
1157 : * Function Name : BREAK
1158 : *
1159 : * Purpose :
1160 : *
1161 : * The macro BREAK should be used instead of the 'break' C statement.
1162 : *
1163 : * Complexity weight : 2
1164 : *
1165 : *****************************************************************************/
1166 : #ifndef WMOPS
1167 : #define BREAK break
1168 :
1169 : #else /* ifndef WMOPS */
1170 : #define BREAK \
1171 : if ( incrBreak(), 0 ) \
1172 : ; \
1173 : else \
1174 : break
1175 :
1176 : static __inline void incrBreak( void )
1177 : {
1178 : multiCounter[currCounter].Break++;
1179 : }
1180 : #endif /* ifndef WMOPS */
1181 :
1182 :
1183 : /*****************************************************************************
1184 : *
1185 : * Function Name : GOTO
1186 : *
1187 : * Purpose :
1188 : *
1189 : * The macro GOTO should be used instead of the 'goto' C statement.
1190 : *
1191 : * Complexity weight : 2
1192 : *
1193 : *****************************************************************************/
1194 : #ifndef WMOPS
1195 : #define GOTO goto
1196 :
1197 : #else /* ifndef WMOPS */
1198 : #define GOTO \
1199 : if ( incrGoto(), 0 ) \
1200 : ; \
1201 : else \
1202 : goto
1203 :
1204 : static __inline void incrGoto( void )
1205 : {
1206 : multiCounter[currCounter].Goto++;
1207 : }
1208 : #endif /* ifndef WMOPS */
1209 :
1210 :
1211 : #ifdef CONTROL_CODE_OPS
1212 :
1213 8912768759 : extern int LT_16( short var1, short var2 );
1214 5369280904 : extern int GT_16( short var1, short var2 );
1215 324545841 : extern int LE_16( short var1, short var2 );
1216 2643831754 : extern int GE_16( short var1, short var2 );
1217 5049149226 : extern int EQ_16( short var1, short var2 );
1218 1898552358 : extern int NE_16( short var1, short var2 );
1219 :
1220 7065742668 : extern int LT_32( int L_var1, int L_var2 );
1221 14446730941 : extern int GT_32( int L_var1, int L_var2 );
1222 672106519 : extern int LE_32( int L_var1, int L_var2 );
1223 554423689 : extern int GE_32( int L_var1, int L_var2 );
1224 3194153415 : extern int EQ_32( int L_var1, int L_var2 );
1225 436669955 : extern int NE_32( int L_var1, int L_var2 );
1226 :
1227 1521565607 : extern int LT_64( long long int L64_var1, long long int L64_var2 );
1228 531116969 : extern int GT_64( long long int L64_var1, long long int L64_var2 );
1229 12518150 : extern int LE_64( long long int L64_var1, long long int L64_var2 );
1230 262735865 : extern int GE_64( long long int L64_var1, long long int L64_var2 );
1231 3349853 : extern int EQ_64( long long int L64_var1, long long int L64_var2 );
1232 29157647 : extern int NE_64( long long int L64_var1, long long int L64_var2 );
1233 :
1234 : #endif /* #ifdef CONTROL_CODE_OPS */
1235 :
1236 :
1237 : #endif /* WMOPS_H */
|