blob: 98eacfb64e9f67e86e1e38ccdd5940da5b9772e3 [file] [log] [blame]
Gregory Maxwellae231142011-07-30 08:18:48 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, (subject to the limitations in the disclaimer below)
5are permitted provided that the following conditions are 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.
11- Neither the name of Skype Limited, nor the names of specific
12contributors, may be used to endorse or promote products derived from
13this software without specific prior written permission.
14NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef _SIGPROCFIX_API_MACROCOUNT_H_
29#define _SIGPROCFIX_API_MACROCOUNT_H_
30#include <stdio.h>
31
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070032#ifdef silk_MACRO_COUNT
Gregory Maxwellae231142011-07-30 08:18:48 -040033#define varDefine opus_int64 ops_count = 0;
34
35extern opus_int64 ops_count;
36
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070037static inline opus_int64 silk_SaveCount(){
Gregory Maxwellae231142011-07-30 08:18:48 -040038 return(ops_count);
39}
40
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070041static inline opus_int64 silk_SaveResetCount(){
Gregory Maxwellae231142011-07-30 08:18:48 -040042 opus_int64 ret;
43
44 ret = ops_count;
45 ops_count = 0;
46 return(ret);
47}
48
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070049static inline silk_PrintCount(){
Gregory Maxwellae231142011-07-30 08:18:48 -040050 printf("ops_count = %d \n ", (opus_int32)ops_count);
51}
52
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070053#undef silk_MUL
54static inline opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -040055 opus_int32 ret;
56 ops_count += 4;
57 ret = a32 * b32;
58 return ret;
59}
60
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070061#undef silk_MUL_uint
62static inline opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -040063 opus_uint32 ret;
64 ops_count += 4;
65 ret = a32 * b32;
66 return ret;
67}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070068#undef silk_MLA
69static inline opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -040070 opus_int32 ret;
71 ops_count += 4;
72 ret = a32 + b32 * c32;
73 return ret;
74}
75
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070076#undef silk_MLA_uint
77static inline opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -040078 opus_uint32 ret;
79 ops_count += 4;
80 ret = a32 + b32 * c32;
81 return ret;
82}
83
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070084#undef silk_SMULWB
85static inline opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -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}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070091#undef silk_SMLAWB
92static inline opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070099#undef silk_SMULWT
100static inline opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400101 opus_int32 ret;
102 ops_count += 4;
103 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
104 return ret;
105}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700106#undef silk_SMLAWT
107static inline opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700114#undef silk_SMULBB
115static inline opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400116 opus_int32 ret;
117 ops_count += 1;
118 ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32);
119 return ret;
120}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700121#undef silk_SMLABB
122static inline opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700129#undef silk_SMULBT
130static inline opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
Gregory Maxwellae231142011-07-30 08:18:48 -0400131 opus_int32 ret;
132 ops_count += 4;
133 ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16);
134 return ret;
135}
136
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700137#undef silk_SMLABT
138static inline opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400139 opus_int32 ret;
140 ops_count += 1;
141 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
142 return ret;
143}
144
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700145#undef silk_SMULTT
146static inline opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400147 opus_int32 ret;
148 ops_count += 1;
149 ret = (a32 >> 16) * (b32 >> 16);
150 return ret;
151}
152
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700153#undef silk_SMLATT
154static inline opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400155 opus_int32 ret;
156 ops_count += 1;
157 ret = a32 + (b32 >> 16) * (c32 >> 16);
158 return ret;
159}
160
161
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400162/* multiply-accumulate macros that allow overflow in the addition (ie, no asserts in debug mode)*/
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700163#undef silk_MLA_ovflw
164#define silk_MLA_ovflw silk_MLA
Gregory Maxwellae231142011-07-30 08:18:48 -0400165
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700166#undef silk_SMLABB_ovflw
167#define silk_SMLABB_ovflw silk_SMLABB
Gregory Maxwellae231142011-07-30 08:18:48 -0400168
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700169#undef silk_SMLABT_ovflw
170#define silk_SMLABT_ovflw silk_SMLABT
Gregory Maxwellae231142011-07-30 08:18:48 -0400171
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700172#undef silk_SMLATT_ovflw
173#define silk_SMLATT_ovflw silk_SMLATT
Gregory Maxwellae231142011-07-30 08:18:48 -0400174
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700175#undef silk_SMLAWB_ovflw
176#define silk_SMLAWB_ovflw silk_SMLAWB
Gregory Maxwellae231142011-07-30 08:18:48 -0400177
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700178#undef silk_SMLAWT_ovflw
179#define silk_SMLAWT_ovflw silk_SMLAWT
Gregory Maxwellae231142011-07-30 08:18:48 -0400180
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700181#undef silk_SMULL
182static inline opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400183 opus_int64 ret;
184 ops_count += 8;
185 ret = ((opus_int64)(a32) * /*(opus_int64)*/(b32));
186 return ret;
187}
188
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700189#undef silk_SMLAL
190static inline opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400191 opus_int64 ret;
192 ops_count += 8;
193 ret = a64 + ((opus_int64)(b32) * /*(opus_int64)*/(c32));
194 return ret;
195}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700196#undef silk_SMLALBB
197static inline opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valin4dc0b392011-08-15 11:24:37 -0400205static inline opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valin4dc0b392011-08-15 11:24:37 -0400243static inline opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700254#undef silk_DIV32
255static inline opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400256 ops_count += 64;
257 return a32 / b32;
258}
259
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700260#undef silk_DIV32_16
261static inline opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400262 ops_count += 32;
263 return a32 / b32;
264}
265
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700266#undef silk_SAT8
267static inline opus_int8 silk_SAT8(opus_int64 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400268 opus_int8 tmp;
269 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700270 tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \
271 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400272 return(tmp);
273}
274
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700275#undef silk_SAT16
276static inline opus_int16 silk_SAT16(opus_int64 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400277 opus_int16 tmp;
278 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700279 tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \
280 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400281 return(tmp);
282}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700283#undef silk_SAT32
284static inline opus_int32 silk_SAT32(opus_int64 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400285 opus_int32 tmp;
286 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700287 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \
288 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400289 return(tmp);
290}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700291#undef silk_POS_SAT32
292static inline opus_int32 silk_POS_SAT32(opus_int64 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400293 opus_int32 tmp;
294 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700295 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a));
Gregory Maxwellae231142011-07-30 08:18:48 -0400296 return(tmp);
297}
298
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700299#undef silk_ADD_POS_SAT8
300static inline opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400301 opus_int8 tmp;
302 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700303 tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400304 return(tmp);
305}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700306#undef silk_ADD_POS_SAT16
307static inline opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400308 opus_int16 tmp;
309 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700310 tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400311 return(tmp);
312}
313
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700314#undef silk_ADD_POS_SAT32
315static inline opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400316 opus_int32 tmp;
317 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700318 tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400319 return(tmp);
320}
321
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700322#undef silk_ADD_POS_SAT64
323static inline opus_int64 silk_ADD_POS_SAT64(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400324 opus_int64 tmp;
325 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700326 tmp = ((((a)+(b)) & 0x8000000000000000LL) ? silk_int64_MAX : ((a)+(b)));
Gregory Maxwellae231142011-07-30 08:18:48 -0400327 return(tmp);
328}
329
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700330#undef silk_LSHIFT8
331static inline opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400332 opus_int8 ret;
333 ops_count += 1;
334 ret = a << shift;
335 return ret;
336}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700337#undef silk_LSHIFT16
338static inline opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400339 opus_int16 ret;
340 ops_count += 1;
341 ret = a << shift;
342 return ret;
343}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700344#undef silk_LSHIFT32
345static inline opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400346 opus_int32 ret;
347 ops_count += 1;
348 ret = a << shift;
349 return ret;
350}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700351#undef silk_LSHIFT64
352static inline opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400353 ops_count += 1;
354 return a << shift;
355}
356
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700357#undef silk_LSHIFT_ovflw
358static inline opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400359 ops_count += 1;
360 return a << shift;
361}
362
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700363#undef silk_LSHIFT_uint
364static inline opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400365 opus_uint32 ret;
366 ops_count += 1;
367 ret = a << shift;
368 return ret;
369}
370
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700371#undef silk_RSHIFT8
372static inline opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400373 ops_count += 1;
374 return a >> shift;
375}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700376#undef silk_RSHIFT16
377static inline opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400378 ops_count += 1;
379 return a >> shift;
380}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700381#undef silk_RSHIFT32
382static inline opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400383 ops_count += 1;
384 return a >> shift;
385}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700386#undef silk_RSHIFT64
387static inline opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400388 ops_count += 1;
389 return a >> shift;
390}
391
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700392#undef silk_RSHIFT_uint
393static inline opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400394 ops_count += 1;
395 return a >> shift;
396}
397
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700398#undef silk_ADD_LSHIFT
399static inline opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400400 opus_int32 ret;
401 ops_count += 1;
402 ret = a + (b << shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400403 return ret; /* shift >= 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400404}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700405#undef silk_ADD_LSHIFT32
406static inline opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400407 opus_int32 ret;
408 ops_count += 1;
409 ret = a + (b << shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400410 return ret; /* shift >= 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400411}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700412#undef silk_ADD_LSHIFT_uint
413static inline opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400414 opus_uint32 ret;
415 ops_count += 1;
416 ret = a + (b << shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400417 return ret; /* shift >= 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400418}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700419#undef silk_ADD_RSHIFT
420static inline opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400421 opus_int32 ret;
422 ops_count += 1;
423 ret = a + (b >> shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400424 return ret; /* shift > 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400425}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700426#undef silk_ADD_RSHIFT32
427static inline opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400428 opus_int32 ret;
429 ops_count += 1;
430 ret = a + (b >> shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400431 return ret; /* shift > 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400432}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700433#undef silk_ADD_RSHIFT_uint
434static inline opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400435 opus_uint32 ret;
436 ops_count += 1;
437 ret = a + (b >> shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400438 return ret; /* shift > 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400439}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700440#undef silk_SUB_LSHIFT32
441static inline opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400442 opus_int32 ret;
443 ops_count += 1;
444 ret = a - (b << shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400445 return ret; /* shift >= 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400446}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700447#undef silk_SUB_RSHIFT32
448static inline opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -0400449 opus_int32 ret;
450 ops_count += 1;
451 ret = a - (b >> shift);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400452 return ret; /* shift > 0*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400453}
454
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700455#undef silk_RSHIFT_ROUND
456static inline opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700463#undef silk_RSHIFT_ROUND64
464static inline opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700471#undef silk_abs_int64
472static inline opus_int64 silk_abs_int64(opus_int64 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400473 ops_count += 1;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700474 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN*/
Gregory Maxwellae231142011-07-30 08:18:48 -0400475}
476
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700477#undef silk_abs_int32
478static inline opus_int32 silk_abs_int32(opus_int32 a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400479 ops_count += 1;
480 return abs(a);
481}
482
483
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700484#undef silk_min
485static silk_min(a, b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400486 ops_count += 1;
487 return (((a) < (b)) ? (a) : (b));
488}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700489#undef silk_max
490static silk_max(a, b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400491 ops_count += 1;
492 return (((a) > (b)) ? (a) : (b));
493}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700494#undef silk_sign
495static silk_sign(a){
Gregory Maxwellae231142011-07-30 08:18:48 -0400496 ops_count += 1;
497 return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
498}
499
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700500#undef silk_ADD16
501static inline opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400502 opus_int16 ret;
503 ops_count += 1;
504 ret = a + b;
505 return ret;
506}
507
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700508#undef silk_ADD32
509static inline opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400510 opus_int32 ret;
511 ops_count += 1;
512 ret = a + b;
513 return ret;
514}
515
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700516#undef silk_ADD64
517static inline opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400518 opus_int64 ret;
519 ops_count += 2;
520 ret = a + b;
521 return ret;
522}
523
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700524#undef silk_SUB16
525static inline opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400526 opus_int16 ret;
527 ops_count += 1;
528 ret = a - b;
529 return ret;
530}
531
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700532#undef silk_SUB32
533static inline opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400534 opus_int32 ret;
535 ops_count += 1;
536 ret = a - b;
537 return ret;
538}
539
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700540#undef silk_SUB64
541static inline opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
Gregory Maxwellae231142011-07-30 08:18:48 -0400542 opus_int64 ret;
543 ops_count += 2;
544 ret = a - b;
545 return ret;
546}
547
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700548#undef silk_ADD_SAT16
549static inline opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
Gregory Maxwellae231142011-07-30 08:18:48 -0400550 opus_int16 res;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700551 /* Nb will be counted in AKP_add32 and silk_SAT16*/
552 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400553 return res;
554}
555
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700556#undef silk_ADD_SAT32
557static inline opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400558 opus_int32 res;
559 ops_count += 1;
560 res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700561 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
562 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400563 return res;
564}
565
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700566#undef silk_ADD_SAT64
567static inline opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
Gregory Maxwellae231142011-07-30 08:18:48 -0400568 opus_int64 res;
569 ops_count += 1;
570 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700571 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
572 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400573 return res;
574}
575
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700576#undef silk_SUB_SAT16
577static inline opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
Gregory Maxwellae231142011-07-30 08:18:48 -0400578 opus_int16 res;
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700579 silk_assert(0);
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400580 /* Nb will be counted in sub-macros*/
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700581 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400582 return res;
583}
584
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700585#undef silk_SUB_SAT32
586static inline opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
Gregory Maxwellae231142011-07-30 08:18:48 -0400587 opus_int32 res;
588 ops_count += 1;
589 res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700590 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
591 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400592 return res;
593}
594
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700595#undef silk_SUB_SAT64
596static inline opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
Gregory Maxwellae231142011-07-30 08:18:48 -0400597 opus_int64 res;
598 ops_count += 1;
599 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700600 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
601 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
Gregory Maxwellae231142011-07-30 08:18:48 -0400602
603 return res;
604}
605
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700606#undef silk_SMULWW
607static inline opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400608 opus_int32 ret;
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400609 /* Nb will be counted in sub-macros*/
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700610 ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
Gregory Maxwellae231142011-07-30 08:18:48 -0400611 return ret;
612}
613
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700614#undef silk_SMLAWW
615static inline opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
Gregory Maxwellae231142011-07-30 08:18:48 -0400616 opus_int32 ret;
Jean-Marc Valinccaa6d22011-08-28 02:09:55 -0400617 /* Nb will be counted in sub-macros*/
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700618 ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
Gregory Maxwellae231142011-07-30 08:18:48 -0400619 return ret;
620}
621
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700622#undef silk_min_int
623static inline opus_int silk_min_int(opus_int a, opus_int b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400624{
625 ops_count += 1;
626 return (((a) < (b)) ? (a) : (b));
627}
628
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700629#undef silk_min_16
630static inline opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400631{
632 ops_count += 1;
633 return (((a) < (b)) ? (a) : (b));
634}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700635#undef silk_min_32
636static inline opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400637{
638 ops_count += 1;
639 return (((a) < (b)) ? (a) : (b));
640}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700641#undef silk_min_64
642static inline opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400643{
644 ops_count += 1;
645 return (((a) < (b)) ? (a) : (b));
646}
647
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700648/* silk_min() versions with typecast in the function call */
649#undef silk_max_int
650static inline opus_int silk_max_int(opus_int a, opus_int b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400651{
652 ops_count += 1;
653 return (((a) > (b)) ? (a) : (b));
654}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700655#undef silk_max_16
656static inline opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400657{
658 ops_count += 1;
659 return (((a) > (b)) ? (a) : (b));
660}
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700661#undef silk_max_32
662static inline opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400663{
664 ops_count += 1;
665 return (((a) > (b)) ? (a) : (b));
666}
667
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700668#undef silk_max_64
669static inline opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
Gregory Maxwellae231142011-07-30 08:18:48 -0400670{
671 ops_count += 1;
672 return (((a) > (b)) ? (a) : (b));
673}
674
675
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700676#undef silk_LIMIT_int
677static inline opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700688#undef silk_LIMIT_16
689static inline opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
Gregory Maxwellae231142011-07-30 08:18:48 -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
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700701#undef silk_LIMIT_32
702static inline opus_int silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
Gregory Maxwellae231142011-07-30 08:18:48 -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 exVarDefine
714#define varDefine
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -0700715#define silk_SaveCount()
Gregory Maxwellae231142011-07-30 08:18:48 -0400716
717#endif
718#endif
719