blob: 834817d058b9e9e4b8e7c244a9ce735278cf3544 [file] [log] [blame]
Alexandre Lision744f7422013-09-25 11:39:37 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
Alexandre Lision85382382014-01-27 15:54:16 -050011- Neither the name of Internet Society, IETF or IETF Trust, nor the
Alexandre Lision744f7422013-09-25 11:39:37 -040012names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
Alexandre Lision85382382014-01-27 15:54:16 -050015THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Alexandre Lision744f7422013-09-25 11:39:37 -040016AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SIGPROCFIX_API_MACROCOUNT_H
29#define SIGPROCFIX_API_MACROCOUNT_H
30#include <stdio.h>
31
32#ifdef silk_MACRO_COUNT
33#define varDefine opus_int64 ops_count = 0;
34
35extern opus_int64 ops_count;
36
Alexandre Lision85382382014-01-27 15:54:16 -050037static OPUS_INLINE opus_int64 silk_SaveCount(){
Alexandre Lision744f7422013-09-25 11:39:37 -040038 return(ops_count);
39}
40
Alexandre Lision85382382014-01-27 15:54:16 -050041static OPUS_INLINE opus_int64 silk_SaveResetCount(){
Alexandre Lision744f7422013-09-25 11:39:37 -040042 opus_int64 ret;
43
44 ret = ops_count;
45 ops_count = 0;
46 return(ret);
47}
48
Alexandre Lision85382382014-01-27 15:54:16 -050049static OPUS_INLINE silk_PrintCount(){
Alexandre Lision744f7422013-09-25 11:39:37 -040050 printf("ops_count = %d \n ", (opus_int32)ops_count);
51}
52
53#undef silk_MUL
Alexandre Lision85382382014-01-27 15:54:16 -050054static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -040055 opus_int32 ret;
56 ops_count += 4;
57 ret = a32 * b32;
58 return ret;
59}
60
61#undef silk_MUL_uint
Alexandre Lision85382382014-01-27 15:54:16 -050062static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -040063 opus_uint32 ret;
64 ops_count += 4;
65 ret = a32 * b32;
66 return ret;
67}
68#undef silk_MLA
Alexandre Lision85382382014-01-27 15:54:16 -050069static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -040070 opus_int32 ret;
71 ops_count += 4;
72 ret = a32 + b32 * c32;
73 return ret;
74}
75
76#undef silk_MLA_uint
Alexandre Lision85382382014-01-27 15:54:16 -050077static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -040078 opus_uint32 ret;
79 ops_count += 4;
80 ret = a32 + b32 * c32;
81 return ret;
82}
83
84#undef silk_SMULWB
Alexandre Lision85382382014-01-27 15:54:16 -050085static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -040086 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
Alexandre Lision85382382014-01-27 15:54:16 -050092static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -040093 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
Alexandre Lision85382382014-01-27 15:54:16 -0500100static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400101 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
Alexandre Lision85382382014-01-27 15:54:16 -0500107static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400108 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
Alexandre Lision85382382014-01-27 15:54:16 -0500115static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400116 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
Alexandre Lision85382382014-01-27 15:54:16 -0500122static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400123 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
Alexandre Lision85382382014-01-27 15:54:16 -0500130static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
Alexandre Lision744f7422013-09-25 11:39:37 -0400131 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
Alexandre Lision85382382014-01-27 15:54:16 -0500138static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400139 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
Alexandre Lision85382382014-01-27 15:54:16 -0500146static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400147 opus_int32 ret;
148 ops_count += 1;
149 ret = (a32 >> 16) * (b32 >> 16);
150 return ret;
151}
152
153#undef silk_SMLATT
Alexandre Lision85382382014-01-27 15:54:16 -0500154static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400155 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
Alexandre Lision85382382014-01-27 15:54:16 -0500182static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400183 opus_int64 ret;
184 ops_count += 8;
185 ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32));
186 return ret;
187}
188
189#undef silk_SMLAL
Alexandre Lision85382382014-01-27 15:54:16 -0500190static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400191 opus_int64 ret;
192 ops_count += 8;
193 ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32));
194 return ret;
195}
196#undef silk_SMLALBB
Alexandre Lision85382382014-01-27 15:54:16 -0500197static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
Alexandre Lision744f7422013-09-25 11:39:37 -0400198 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
Alexandre Lision85382382014-01-27 15:54:16 -0500205static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
Alexandre Lision744f7422013-09-25 11:39:37 -0400206{
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
Alexandre Lision85382382014-01-27 15:54:16 -0500243static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
Alexandre Lision744f7422013-09-25 11:39:37 -0400244{
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
Alexandre Lision85382382014-01-27 15:54:16 -0500255static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400256 ops_count += 64;
257 return a32 / b32;
258}
259
260#undef silk_DIV32_16
Alexandre Lision85382382014-01-27 15:54:16 -0500261static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400262 ops_count += 32;
263 return a32 / b32;
264}
265
266#undef silk_SAT8
Alexandre Lision85382382014-01-27 15:54:16 -0500267static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400268 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
Alexandre Lision85382382014-01-27 15:54:16 -0500276static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400277 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
Alexandre Lision85382382014-01-27 15:54:16 -0500284static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400285 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
Alexandre Lision85382382014-01-27 15:54:16 -0500292static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400293 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
Alexandre Lision85382382014-01-27 15:54:16 -0500300static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400301 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
Alexandre Lision85382382014-01-27 15:54:16 -0500307static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400308 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
Alexandre Lision85382382014-01-27 15:54:16 -0500315static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400316 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_ADD_POS_SAT64
Alexandre Lision85382382014-01-27 15:54:16 -0500323static OPUS_INLINE opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400324 opus_int64 tmp;
325 ops_count += 1;
326 tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)));
327 return(tmp);
328}
329
330#undef silk_LSHIFT8
Alexandre Lision85382382014-01-27 15:54:16 -0500331static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400332 opus_int8 ret;
333 ops_count += 1;
334 ret = a << shift;
335 return ret;
336}
337#undef silk_LSHIFT16
Alexandre Lision85382382014-01-27 15:54:16 -0500338static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400339 opus_int16 ret;
340 ops_count += 1;
341 ret = a << shift;
342 return ret;
343}
344#undef silk_LSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500345static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400346 opus_int32 ret;
347 ops_count += 1;
348 ret = a << shift;
349 return ret;
350}
351#undef silk_LSHIFT64
Alexandre Lision85382382014-01-27 15:54:16 -0500352static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400353 ops_count += 1;
354 return a << shift;
355}
356
357#undef silk_LSHIFT_ovflw
Alexandre Lision85382382014-01-27 15:54:16 -0500358static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400359 ops_count += 1;
360 return a << shift;
361}
362
363#undef silk_LSHIFT_uint
Alexandre Lision85382382014-01-27 15:54:16 -0500364static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400365 opus_uint32 ret;
366 ops_count += 1;
367 ret = a << shift;
368 return ret;
369}
370
371#undef silk_RSHIFT8
Alexandre Lision85382382014-01-27 15:54:16 -0500372static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400373 ops_count += 1;
374 return a >> shift;
375}
376#undef silk_RSHIFT16
Alexandre Lision85382382014-01-27 15:54:16 -0500377static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400378 ops_count += 1;
379 return a >> shift;
380}
381#undef silk_RSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500382static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400383 ops_count += 1;
384 return a >> shift;
385}
386#undef silk_RSHIFT64
Alexandre Lision85382382014-01-27 15:54:16 -0500387static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400388 ops_count += 1;
389 return a >> shift;
390}
391
392#undef silk_RSHIFT_uint
Alexandre Lision85382382014-01-27 15:54:16 -0500393static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400394 ops_count += 1;
395 return a >> shift;
396}
397
398#undef silk_ADD_LSHIFT
Alexandre Lision85382382014-01-27 15:54:16 -0500399static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400400 opus_int32 ret;
401 ops_count += 1;
402 ret = a + (b << shift);
403 return ret; /* shift >= 0*/
404}
405#undef silk_ADD_LSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500406static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400407 opus_int32 ret;
408 ops_count += 1;
409 ret = a + (b << shift);
410 return ret; /* shift >= 0*/
411}
412#undef silk_ADD_LSHIFT_uint
Alexandre Lision85382382014-01-27 15:54:16 -0500413static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400414 opus_uint32 ret;
415 ops_count += 1;
416 ret = a + (b << shift);
417 return ret; /* shift >= 0*/
418}
419#undef silk_ADD_RSHIFT
Alexandre Lision85382382014-01-27 15:54:16 -0500420static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400421 opus_int32 ret;
422 ops_count += 1;
423 ret = a + (b >> shift);
424 return ret; /* shift > 0*/
425}
426#undef silk_ADD_RSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500427static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400428 opus_int32 ret;
429 ops_count += 1;
430 ret = a + (b >> shift);
431 return ret; /* shift > 0*/
432}
433#undef silk_ADD_RSHIFT_uint
Alexandre Lision85382382014-01-27 15:54:16 -0500434static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400435 opus_uint32 ret;
436 ops_count += 1;
437 ret = a + (b >> shift);
438 return ret; /* shift > 0*/
439}
440#undef silk_SUB_LSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500441static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400442 opus_int32 ret;
443 ops_count += 1;
444 ret = a - (b << shift);
445 return ret; /* shift >= 0*/
446}
447#undef silk_SUB_RSHIFT32
Alexandre Lision85382382014-01-27 15:54:16 -0500448static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400449 opus_int32 ret;
450 ops_count += 1;
451 ret = a - (b >> shift);
452 return ret; /* shift > 0*/
453}
454
455#undef silk_RSHIFT_ROUND
Alexandre Lision85382382014-01-27 15:54:16 -0500456static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400457 opus_int32 ret;
458 ops_count += 3;
459 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
460 return ret;
461}
462
463#undef silk_RSHIFT_ROUND64
Alexandre Lision85382382014-01-27 15:54:16 -0500464static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
Alexandre Lision744f7422013-09-25 11:39:37 -0400465 opus_int64 ret;
466 ops_count += 6;
467 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
468 return ret;
469}
470
471#undef silk_abs_int64
Alexandre Lision85382382014-01-27 15:54:16 -0500472static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400473 ops_count += 1;
474 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
475}
476
477#undef silk_abs_int32
Alexandre Lision85382382014-01-27 15:54:16 -0500478static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){
Alexandre Lision744f7422013-09-25 11:39:37 -0400479 ops_count += 1;
480 return silk_abs(a);
481}
482
483
484#undef silk_min
485static silk_min(a, b){
486 ops_count += 1;
487 return (((a) < (b)) ? (a) : (b));
488}
489#undef silk_max
490static silk_max(a, b){
491 ops_count += 1;
492 return (((a) > (b)) ? (a) : (b));
493}
494#undef silk_sign
495static silk_sign(a){
496 ops_count += 1;
497 return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
498}
499
500#undef silk_ADD16
Alexandre Lision85382382014-01-27 15:54:16 -0500501static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400502 opus_int16 ret;
503 ops_count += 1;
504 ret = a + b;
505 return ret;
506}
507
508#undef silk_ADD32
Alexandre Lision85382382014-01-27 15:54:16 -0500509static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400510 opus_int32 ret;
511 ops_count += 1;
512 ret = a + b;
513 return ret;
514}
515
516#undef silk_ADD64
Alexandre Lision85382382014-01-27 15:54:16 -0500517static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400518 opus_int64 ret;
519 ops_count += 2;
520 ret = a + b;
521 return ret;
522}
523
524#undef silk_SUB16
Alexandre Lision85382382014-01-27 15:54:16 -0500525static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400526 opus_int16 ret;
527 ops_count += 1;
528 ret = a - b;
529 return ret;
530}
531
532#undef silk_SUB32
Alexandre Lision85382382014-01-27 15:54:16 -0500533static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400534 opus_int32 ret;
535 ops_count += 1;
536 ret = a - b;
537 return ret;
538}
539
540#undef silk_SUB64
Alexandre Lision85382382014-01-27 15:54:16 -0500541static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
Alexandre Lision744f7422013-09-25 11:39:37 -0400542 opus_int64 ret;
543 ops_count += 2;
544 ret = a - b;
545 return ret;
546}
547
548#undef silk_ADD_SAT16
Alexandre Lision85382382014-01-27 15:54:16 -0500549static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
Alexandre Lision744f7422013-09-25 11:39:37 -0400550 opus_int16 res;
551 /* Nb will be counted in AKP_add32 and silk_SAT16*/
552 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
553 return res;
554}
555
556#undef silk_ADD_SAT32
Alexandre Lision85382382014-01-27 15:54:16 -0500557static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400558 opus_int32 res;
559 ops_count += 1;
560 res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
561 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
562 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
563 return res;
564}
565
566#undef silk_ADD_SAT64
Alexandre Lision85382382014-01-27 15:54:16 -0500567static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
Alexandre Lision744f7422013-09-25 11:39:37 -0400568 opus_int64 res;
569 ops_count += 1;
570 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
571 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
572 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
573 return res;
574}
575
576#undef silk_SUB_SAT16
Alexandre Lision85382382014-01-27 15:54:16 -0500577static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
Alexandre Lision744f7422013-09-25 11:39:37 -0400578 opus_int16 res;
579 silk_assert(0);
580 /* Nb will be counted in sub-macros*/
581 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
582 return res;
583}
584
585#undef silk_SUB_SAT32
Alexandre Lision85382382014-01-27 15:54:16 -0500586static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
Alexandre Lision744f7422013-09-25 11:39:37 -0400587 opus_int32 res;
588 ops_count += 1;
589 res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
590 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
591 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
592 return res;
593}
594
595#undef silk_SUB_SAT64
Alexandre Lision85382382014-01-27 15:54:16 -0500596static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
Alexandre Lision744f7422013-09-25 11:39:37 -0400597 opus_int64 res;
598 ops_count += 1;
599 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
600 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
601 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
602
603 return res;
604}
605
606#undef silk_SMULWW
Alexandre Lision85382382014-01-27 15:54:16 -0500607static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400608 opus_int32 ret;
609 /* Nb will be counted in sub-macros*/
610 ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
611 return ret;
612}
613
614#undef silk_SMLAWW
Alexandre Lision85382382014-01-27 15:54:16 -0500615static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Alexandre Lision744f7422013-09-25 11:39:37 -0400616 opus_int32 ret;
617 /* Nb will be counted in sub-macros*/
618 ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
619 return ret;
620}
621
622#undef silk_min_int
Alexandre Lision85382382014-01-27 15:54:16 -0500623static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400624{
625 ops_count += 1;
626 return (((a) < (b)) ? (a) : (b));
627}
628
629#undef silk_min_16
Alexandre Lision85382382014-01-27 15:54:16 -0500630static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400631{
632 ops_count += 1;
633 return (((a) < (b)) ? (a) : (b));
634}
635#undef silk_min_32
Alexandre Lision85382382014-01-27 15:54:16 -0500636static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400637{
638 ops_count += 1;
639 return (((a) < (b)) ? (a) : (b));
640}
641#undef silk_min_64
Alexandre Lision85382382014-01-27 15:54:16 -0500642static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400643{
644 ops_count += 1;
645 return (((a) < (b)) ? (a) : (b));
646}
647
648/* silk_min() versions with typecast in the function call */
649#undef silk_max_int
Alexandre Lision85382382014-01-27 15:54:16 -0500650static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400651{
652 ops_count += 1;
653 return (((a) > (b)) ? (a) : (b));
654}
655#undef silk_max_16
Alexandre Lision85382382014-01-27 15:54:16 -0500656static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400657{
658 ops_count += 1;
659 return (((a) > (b)) ? (a) : (b));
660}
661#undef silk_max_32
Alexandre Lision85382382014-01-27 15:54:16 -0500662static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400663{
664 ops_count += 1;
665 return (((a) > (b)) ? (a) : (b));
666}
667
668#undef silk_max_64
Alexandre Lision85382382014-01-27 15:54:16 -0500669static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
Alexandre Lision744f7422013-09-25 11:39:37 -0400670{
671 ops_count += 1;
672 return (((a) > (b)) ? (a) : (b));
673}
674
675
676#undef silk_LIMIT_int
Alexandre Lision85382382014-01-27 15:54:16 -0500677static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
Alexandre Lision744f7422013-09-25 11:39:37 -0400678{
679 opus_int ret;
680 ops_count += 6;
681
682 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
683 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
684
685 return(ret);
686}
687
688#undef silk_LIMIT_16
Alexandre Lision85382382014-01-27 15:54:16 -0500689static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
Alexandre Lision744f7422013-09-25 11:39:37 -0400690{
691 opus_int16 ret;
692 ops_count += 6;
693
694 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
695 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
696
697return(ret);
698}
699
700
701#undef silk_LIMIT_32
Alexandre Lision85382382014-01-27 15:54:16 -0500702static OPUS_INLINE opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
Alexandre Lision744f7422013-09-25 11:39:37 -0400703{
704 opus_int32 ret;
705 ops_count += 6;
706
707 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
708 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
709 return(ret);
710}
711
712#else
713#define varDefine
714#define silk_SaveCount()
715
716#endif
717#endif
718