• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions
5 are met:
6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
12 names of specific contributors, may be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27 
28 #ifndef SIGPROCFIX_API_MACROCOUNT_H
29 #define SIGPROCFIX_API_MACROCOUNT_H
30 
31 #ifdef    silk_MACRO_COUNT
32 #include <stdio.h>
33 #define varDefine opus_int64 ops_count = 0;
34 
35 extern opus_int64 ops_count;
36 
silk_SaveCount()37 static OPUS_INLINE opus_int64 silk_SaveCount(){
38     return(ops_count);
39 }
40 
silk_SaveResetCount()41 static OPUS_INLINE opus_int64 silk_SaveResetCount(){
42     opus_int64 ret;
43 
44     ret = ops_count;
45     ops_count = 0;
46     return(ret);
47 }
48 
silk_PrintCount()49 static OPUS_INLINE silk_PrintCount(){
50     printf("ops_count = %d \n ", (opus_int32)ops_count);
51 }
52 
53 #undef silk_MUL
silk_MUL(opus_int32 a32,opus_int32 b32)54 static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
55     opus_int32 ret;
56     ops_count += 4;
57     ret = a32 * b32;
58     return ret;
59 }
60 
61 #undef silk_MUL_uint
silk_MUL_uint(opus_uint32 a32,opus_uint32 b32)62 static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
63     opus_uint32 ret;
64     ops_count += 4;
65     ret = a32 * b32;
66     return ret;
67 }
68 #undef silk_MLA
silk_MLA(opus_int32 a32,opus_int32 b32,opus_int32 c32)69 static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
70     opus_int32 ret;
71     ops_count += 4;
72     ret = a32 + b32 * c32;
73     return ret;
74 }
75 
76 #undef silk_MLA_uint
silk_MLA_uint(opus_uint32 a32,opus_uint32 b32,opus_uint32 c32)77 static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
78     opus_uint32 ret;
79     ops_count += 4;
80     ret = a32 + b32 * c32;
81     return ret;
82 }
83 
84 #undef silk_SMULWB
silk_SMULWB(opus_int32 a32,opus_int32 b32)85 static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
86     opus_int32 ret;
87     ops_count += 5;
88     ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
89     return ret;
90 }
91 #undef    silk_SMLAWB
silk_SMLAWB(opus_int32 a32,opus_int32 b32,opus_int32 c32)92 static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
93     opus_int32 ret;
94     ops_count += 5;
95     ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)));
96     return ret;
97 }
98 
99 #undef silk_SMULWT
silk_SMULWT(opus_int32 a32,opus_int32 b32)100 static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
101     opus_int32 ret;
102     ops_count += 4;
103     ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
104     return ret;
105 }
106 #undef silk_SMLAWT
silk_SMLAWT(opus_int32 a32,opus_int32 b32,opus_int32 c32)107 static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
108     opus_int32 ret;
109     ops_count += 4;
110     ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
111     return ret;
112 }
113 
114 #undef silk_SMULBB
silk_SMULBB(opus_int32 a32,opus_int32 b32)115 static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
116     opus_int32 ret;
117     ops_count += 1;
118     ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32);
119     return ret;
120 }
121 #undef silk_SMLABB
silk_SMLABB(opus_int32 a32,opus_int32 b32,opus_int32 c32)122 static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
123     opus_int32 ret;
124     ops_count += 1;
125     ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
126     return ret;
127 }
128 
129 #undef silk_SMULBT
silk_SMULBT(opus_int32 a32,opus_int32 b32)130 static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
131     opus_int32 ret;
132     ops_count += 4;
133     ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16);
134     return ret;
135 }
136 
137 #undef silk_SMLABT
silk_SMLABT(opus_int32 a32,opus_int32 b32,opus_int32 c32)138 static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
139     opus_int32 ret;
140     ops_count += 1;
141     ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
142     return ret;
143 }
144 
145 #undef silk_SMULTT
silk_SMULTT(opus_int32 a32,opus_int32 b32)146 static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
147     opus_int32 ret;
148     ops_count += 1;
149     ret = (a32 >> 16) * (b32 >> 16);
150     return ret;
151 }
152 
153 #undef    silk_SMLATT
silk_SMLATT(opus_int32 a32,opus_int32 b32,opus_int32 c32)154 static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
155     opus_int32 ret;
156     ops_count += 1;
157     ret = a32 + (b32 >> 16) * (c32 >> 16);
158     return ret;
159 }
160 
161 
162 /* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/
163 #undef    silk_MLA_ovflw
164 #define silk_MLA_ovflw silk_MLA
165 
166 #undef silk_SMLABB_ovflw
167 #define silk_SMLABB_ovflw silk_SMLABB
168 
169 #undef silk_SMLABT_ovflw
170 #define silk_SMLABT_ovflw silk_SMLABT
171 
172 #undef silk_SMLATT_ovflw
173 #define silk_SMLATT_ovflw silk_SMLATT
174 
175 #undef silk_SMLAWB_ovflw
176 #define silk_SMLAWB_ovflw silk_SMLAWB
177 
178 #undef silk_SMLAWT_ovflw
179 #define silk_SMLAWT_ovflw silk_SMLAWT
180 
181 #undef silk_SMULL
silk_SMULL(opus_int32 a32,opus_int32 b32)182 static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
183     opus_int64 ret;
184     ops_count += 8;
185     ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32));
186     return ret;
187 }
188 
189 #undef    silk_SMLAL
silk_SMLAL(opus_int64 a64,opus_int32 b32,opus_int32 c32)190 static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
191     opus_int64 ret;
192     ops_count += 8;
193     ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32));
194     return ret;
195 }
196 #undef    silk_SMLALBB
silk_SMLALBB(opus_int64 a64,opus_int16 b16,opus_int16 c16)197 static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
198     opus_int64 ret;
199     ops_count += 4;
200     ret = a64 + ((opus_int64)(b16) * /*(opus_int64)*/(c16));
201     return ret;
202 }
203 
204 #undef    SigProcFIX_CLZ16
SigProcFIX_CLZ16(opus_int16 in16)205 static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
206 {
207     opus_int32 out32 = 0;
208     ops_count += 10;
209     if( in16 == 0 ) {
210         return 16;
211     }
212     /* test nibbles */
213     if( in16 & 0xFF00 ) {
214         if( in16 & 0xF000 ) {
215             in16 >>= 12;
216         } else {
217             out32 += 4;
218             in16 >>= 8;
219         }
220     } else {
221         if( in16 & 0xFFF0 ) {
222             out32 += 8;
223             in16 >>= 4;
224         } else {
225             out32 += 12;
226         }
227     }
228     /* test bits and return */
229     if( in16 & 0xC ) {
230         if( in16 & 0x8 )
231             return out32 + 0;
232         else
233             return out32 + 1;
234     } else {
235         if( in16 & 0xE )
236             return out32 + 2;
237         else
238             return out32 + 3;
239     }
240 }
241 
242 #undef SigProcFIX_CLZ32
SigProcFIX_CLZ32(opus_int32 in32)243 static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
244 {
245     /* test highest 16 bits and convert to opus_int16 */
246     ops_count += 2;
247     if( in32 & 0xFFFF0000 ) {
248         return SigProcFIX_CLZ16((opus_int16)(in32 >> 16));
249     } else {
250         return SigProcFIX_CLZ16((opus_int16)in32) + 16;
251     }
252 }
253 
254 #undef silk_DIV32
silk_DIV32(opus_int32 a32,opus_int32 b32)255 static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
256     ops_count += 64;
257     return a32 / b32;
258 }
259 
260 #undef silk_DIV32_16
silk_DIV32_16(opus_int32 a32,opus_int32 b32)261 static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
262     ops_count += 32;
263     return a32 / b32;
264 }
265 
266 #undef silk_SAT8
silk_SAT8(opus_int64 a)267 static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){
268     opus_int8 tmp;
269     ops_count += 1;
270     tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX  : \
271                     ((a) < silk_int8_MIN ? silk_int8_MIN  : (a)));
272     return(tmp);
273 }
274 
275 #undef silk_SAT16
silk_SAT16(opus_int64 a)276 static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){
277     opus_int16 tmp;
278     ops_count += 1;
279     tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX  : \
280                      ((a) < silk_int16_MIN ? silk_int16_MIN  : (a)));
281     return(tmp);
282 }
283 #undef silk_SAT32
silk_SAT32(opus_int64 a)284 static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){
285     opus_int32 tmp;
286     ops_count += 1;
287     tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX  : \
288                      ((a) < silk_int32_MIN ? silk_int32_MIN  : (a)));
289     return(tmp);
290 }
291 #undef silk_POS_SAT32
silk_POS_SAT32(opus_int64 a)292 static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){
293     opus_int32 tmp;
294     ops_count += 1;
295     tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a));
296     return(tmp);
297 }
298 
299 #undef silk_ADD_POS_SAT8
silk_ADD_POS_SAT8(opus_int64 a,opus_int64 b)300 static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
301     opus_int8 tmp;
302     ops_count += 1;
303     tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX  : ((a)+(b)));
304     return(tmp);
305 }
306 #undef silk_ADD_POS_SAT16
silk_ADD_POS_SAT16(opus_int64 a,opus_int64 b)307 static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
308     opus_int16 tmp;
309     ops_count += 1;
310     tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)));
311     return(tmp);
312 }
313 
314 #undef silk_ADD_POS_SAT32
silk_ADD_POS_SAT32(opus_int64 a,opus_int64 b)315 static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
316     opus_int32 tmp;
317     ops_count += 1;
318     tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)));
319     return(tmp);
320 }
321 
322 #undef    silk_LSHIFT8
silk_LSHIFT8(opus_int8 a,opus_int32 shift)323 static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
324     opus_int8 ret;
325     ops_count += 1;
326     ret = a << shift;
327     return ret;
328 }
329 #undef    silk_LSHIFT16
silk_LSHIFT16(opus_int16 a,opus_int32 shift)330 static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
331     opus_int16 ret;
332     ops_count += 1;
333     ret = a << shift;
334     return ret;
335 }
336 #undef    silk_LSHIFT32
silk_LSHIFT32(opus_int32 a,opus_int32 shift)337 static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
338     opus_int32 ret;
339     ops_count += 1;
340     ret = a << shift;
341     return ret;
342 }
343 #undef    silk_LSHIFT64
silk_LSHIFT64(opus_int64 a,opus_int shift)344 static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
345     ops_count += 1;
346     return a << shift;
347 }
348 
349 #undef    silk_LSHIFT_ovflw
silk_LSHIFT_ovflw(opus_int32 a,opus_int32 shift)350 static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
351     ops_count += 1;
352     return a << shift;
353 }
354 
355 #undef    silk_LSHIFT_uint
silk_LSHIFT_uint(opus_uint32 a,opus_int32 shift)356 static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
357     opus_uint32 ret;
358     ops_count += 1;
359     ret = a << shift;
360     return ret;
361 }
362 
363 #undef    silk_RSHIFT8
silk_RSHIFT8(opus_int8 a,opus_int32 shift)364 static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
365     ops_count += 1;
366     return a >> shift;
367 }
368 #undef    silk_RSHIFT16
silk_RSHIFT16(opus_int16 a,opus_int32 shift)369 static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
370     ops_count += 1;
371     return a >> shift;
372 }
373 #undef    silk_RSHIFT32
silk_RSHIFT32(opus_int32 a,opus_int32 shift)374 static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
375     ops_count += 1;
376     return a >> shift;
377 }
378 #undef    silk_RSHIFT64
silk_RSHIFT64(opus_int64 a,opus_int64 shift)379 static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
380     ops_count += 1;
381     return a >> shift;
382 }
383 
384 #undef    silk_RSHIFT_uint
silk_RSHIFT_uint(opus_uint32 a,opus_int32 shift)385 static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
386     ops_count += 1;
387     return a >> shift;
388 }
389 
390 #undef    silk_ADD_LSHIFT
silk_ADD_LSHIFT(opus_int32 a,opus_int32 b,opus_int32 shift)391 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
392     opus_int32 ret;
393     ops_count += 1;
394     ret = a + (b << shift);
395     return ret;                /* shift >= 0*/
396 }
397 #undef    silk_ADD_LSHIFT32
silk_ADD_LSHIFT32(opus_int32 a,opus_int32 b,opus_int32 shift)398 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
399     opus_int32 ret;
400     ops_count += 1;
401     ret = a + (b << shift);
402     return ret;                /* shift >= 0*/
403 }
404 #undef    silk_ADD_LSHIFT_uint
silk_ADD_LSHIFT_uint(opus_uint32 a,opus_uint32 b,opus_int32 shift)405 static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
406     opus_uint32 ret;
407     ops_count += 1;
408     ret = a + (b << shift);
409     return ret;                /* shift >= 0*/
410 }
411 #undef    silk_ADD_RSHIFT
silk_ADD_RSHIFT(opus_int32 a,opus_int32 b,opus_int32 shift)412 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
413     opus_int32 ret;
414     ops_count += 1;
415     ret = a + (b >> shift);
416     return ret;                /* shift  > 0*/
417 }
418 #undef    silk_ADD_RSHIFT32
silk_ADD_RSHIFT32(opus_int32 a,opus_int32 b,opus_int32 shift)419 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
420     opus_int32 ret;
421     ops_count += 1;
422     ret = a + (b >> shift);
423     return ret;                /* shift  > 0*/
424 }
425 #undef    silk_ADD_RSHIFT_uint
silk_ADD_RSHIFT_uint(opus_uint32 a,opus_uint32 b,opus_int32 shift)426 static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
427     opus_uint32 ret;
428     ops_count += 1;
429     ret = a + (b >> shift);
430     return ret;                /* shift  > 0*/
431 }
432 #undef    silk_SUB_LSHIFT32
silk_SUB_LSHIFT32(opus_int32 a,opus_int32 b,opus_int32 shift)433 static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
434     opus_int32 ret;
435     ops_count += 1;
436     ret = a - (b << shift);
437     return ret;                /* shift >= 0*/
438 }
439 #undef    silk_SUB_RSHIFT32
silk_SUB_RSHIFT32(opus_int32 a,opus_int32 b,opus_int32 shift)440 static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
441     opus_int32 ret;
442     ops_count += 1;
443     ret = a - (b >> shift);
444     return ret;                /* shift  > 0*/
445 }
446 
447 #undef    silk_RSHIFT_ROUND
silk_RSHIFT_ROUND(opus_int32 a,opus_int32 shift)448 static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
449     opus_int32 ret;
450     ops_count += 3;
451     ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
452     return ret;
453 }
454 
455 #undef    silk_RSHIFT_ROUND64
silk_RSHIFT_ROUND64(opus_int64 a,opus_int32 shift)456 static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
457     opus_int64 ret;
458     ops_count += 6;
459     ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
460     return ret;
461 }
462 
463 #undef    silk_abs_int64
silk_abs_int64(opus_int64 a)464 static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){
465     ops_count += 1;
466     return (((a) >  0)  ? (a) : -(a));            /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
467 }
468 
469 #undef    silk_abs_int32
silk_abs_int32(opus_int32 a)470 static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){
471     ops_count += 1;
472     return silk_abs(a);
473 }
474 
475 
476 #undef silk_min
silk_min(a,b)477 static silk_min(a, b){
478     ops_count += 1;
479     return (((a) < (b)) ? (a) :  (b));
480 }
481 #undef silk_max
silk_max(a,b)482 static silk_max(a, b){
483     ops_count += 1;
484     return (((a) > (b)) ? (a) :  (b));
485 }
486 #undef silk_sign
silk_sign(a)487 static silk_sign(a){
488     ops_count += 1;
489     return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
490 }
491 
492 #undef    silk_ADD16
silk_ADD16(opus_int16 a,opus_int16 b)493 static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
494     opus_int16 ret;
495     ops_count += 1;
496     ret = a + b;
497     return ret;
498 }
499 
500 #undef    silk_ADD32
silk_ADD32(opus_int32 a,opus_int32 b)501 static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
502     opus_int32 ret;
503     ops_count += 1;
504     ret = a + b;
505     return ret;
506 }
507 
508 #undef    silk_ADD64
silk_ADD64(opus_int64 a,opus_int64 b)509 static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
510     opus_int64 ret;
511     ops_count += 2;
512     ret = a + b;
513     return ret;
514 }
515 
516 #undef    silk_SUB16
silk_SUB16(opus_int16 a,opus_int16 b)517 static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
518     opus_int16 ret;
519     ops_count += 1;
520     ret = a - b;
521     return ret;
522 }
523 
524 #undef    silk_SUB32
silk_SUB32(opus_int32 a,opus_int32 b)525 static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
526     opus_int32 ret;
527     ops_count += 1;
528     ret = a - b;
529     return ret;
530 }
531 
532 #undef    silk_SUB64
silk_SUB64(opus_int64 a,opus_int64 b)533 static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
534     opus_int64 ret;
535     ops_count += 2;
536     ret = a - b;
537     return ret;
538 }
539 
540 #undef silk_ADD_SAT16
silk_ADD_SAT16(opus_int16 a16,opus_int16 b16)541 static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
542     opus_int16 res;
543     /* Nb will be counted in AKP_add32 and silk_SAT16*/
544     res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
545     return res;
546 }
547 
548 #undef silk_ADD_SAT32
silk_ADD_SAT32(opus_int32 a32,opus_int32 b32)549 static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
550     opus_int32 res;
551     ops_count += 1;
552     res =    ((((a32) + (b32)) & 0x80000000) == 0 ?                                    \
553             ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) :    \
554             ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
555     return res;
556 }
557 
558 #undef silk_ADD_SAT64
silk_ADD_SAT64(opus_int64 a64,opus_int64 b64)559 static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
560     opus_int64 res;
561     ops_count += 1;
562     res =    ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ?                                \
563             ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) :    \
564             ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
565     return res;
566 }
567 
568 #undef silk_SUB_SAT16
silk_SUB_SAT16(opus_int16 a16,opus_int16 b16)569 static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
570     opus_int16 res;
571     silk_assert(0);
572     /* Nb will be counted in sub-macros*/
573     res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
574     return res;
575 }
576 
577 #undef silk_SUB_SAT32
silk_SUB_SAT32(opus_int32 a32,opus_int32 b32)578 static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
579     opus_int32 res;
580     ops_count += 1;
581     res =     ((((a32)-(b32)) & 0x80000000) == 0 ?                                            \
582             (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) :    \
583             ((((a32)^0x80000000) & (b32)  & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
584     return res;
585 }
586 
587 #undef silk_SUB_SAT64
silk_SUB_SAT64(opus_int64 a64,opus_int64 b64)588 static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
589     opus_int64 res;
590     ops_count += 1;
591     res =    ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ?                                                        \
592             (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) :    \
593             ((((a64)^0x8000000000000000LL) & (b64)  & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
594 
595     return res;
596 }
597 
598 #undef    silk_SMULWW
silk_SMULWW(opus_int32 a32,opus_int32 b32)599 static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
600     opus_int32 ret;
601     /* Nb will be counted in sub-macros*/
602     ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
603     return ret;
604 }
605 
606 #undef    silk_SMLAWW
silk_SMLAWW(opus_int32 a32,opus_int32 b32,opus_int32 c32)607 static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
608     opus_int32 ret;
609     /* Nb will be counted in sub-macros*/
610     ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
611     return ret;
612 }
613 
614 #undef    silk_min_int
silk_min_int(opus_int a,opus_int b)615 static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
616 {
617     ops_count += 1;
618     return (((a) < (b)) ? (a) : (b));
619 }
620 
621 #undef    silk_min_16
silk_min_16(opus_int16 a,opus_int16 b)622 static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
623 {
624     ops_count += 1;
625     return (((a) < (b)) ? (a) : (b));
626 }
627 #undef    silk_min_32
silk_min_32(opus_int32 a,opus_int32 b)628 static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
629 {
630     ops_count += 1;
631     return (((a) < (b)) ? (a) : (b));
632 }
633 #undef    silk_min_64
silk_min_64(opus_int64 a,opus_int64 b)634 static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
635 {
636     ops_count += 1;
637     return (((a) < (b)) ? (a) : (b));
638 }
639 
640 /* silk_min() versions with typecast in the function call */
641 #undef    silk_max_int
silk_max_int(opus_int a,opus_int b)642 static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
643 {
644     ops_count += 1;
645     return (((a) > (b)) ? (a) : (b));
646 }
647 #undef    silk_max_16
silk_max_16(opus_int16 a,opus_int16 b)648 static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
649 {
650     ops_count += 1;
651     return (((a) > (b)) ? (a) : (b));
652 }
653 #undef    silk_max_32
silk_max_32(opus_int32 a,opus_int32 b)654 static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
655 {
656     ops_count += 1;
657     return (((a) > (b)) ? (a) : (b));
658 }
659 
660 #undef    silk_max_64
silk_max_64(opus_int64 a,opus_int64 b)661 static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
662 {
663     ops_count += 1;
664     return (((a) > (b)) ? (a) : (b));
665 }
666 
667 
668 #undef silk_LIMIT_int
silk_LIMIT_int(opus_int a,opus_int limit1,opus_int limit2)669 static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
670 {
671     opus_int ret;
672     ops_count += 6;
673 
674     ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
675         : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
676 
677     return(ret);
678 }
679 
680 #undef silk_LIMIT_16
silk_LIMIT_16(opus_int16 a,opus_int16 limit1,opus_int16 limit2)681 static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
682 {
683     opus_int16 ret;
684     ops_count += 6;
685 
686     ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
687         : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
688 
689 return(ret);
690 }
691 
692 
693 #undef silk_LIMIT_32
silk_LIMIT_32(opus_int32 a,opus_int32 limit1,opus_int32 limit2)694 static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
695 {
696     opus_int32 ret;
697     ops_count += 6;
698 
699     ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
700         : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
701     return(ret);
702 }
703 
704 #else
705 #define varDefine
706 #define silk_SaveCount()
707 
708 #endif
709 #endif
710 
711