no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / media / libopus / silk / MacroDebug.h
blob3110da9a7560fe42699247ad89c8f97cca032f8c
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Copyright (C) 2012 Xiph.Org Foundation
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 - Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 - Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 - Neither the name of Internet Society, IETF or IETF Trust, nor the
13 names of specific contributors, may be used to endorse or promote
14 products derived from this software without specific prior written
15 permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 ***********************************************************************/
29 #ifndef MACRO_DEBUG_H
30 #define MACRO_DEBUG_H
32 /* Redefine macro functions with extensive assertion in DEBUG mode.
33 As functions can't be undefined, this file can't work with SigProcFIX_MacroCount.h */
35 #if ( defined (FIXED_DEBUG) || ( 0 && defined (_DEBUG) ) ) && !defined (silk_MACRO_COUNT)
37 #undef silk_ADD16
38 #define silk_ADD16(a,b) silk_ADD16_((a), (b), __FILE__, __LINE__)
39 static OPUS_INLINE opus_int16 silk_ADD16_(opus_int16 a, opus_int16 b, char *file, int line){
40 opus_int16 ret;
42 ret = a + b;
43 if ( ret != silk_ADD_SAT16( a, b ) )
45 fprintf (stderr, "silk_ADD16(%d, %d) in %s: line %d\n", a, b, file, line);
46 #ifdef FIXED_DEBUG_ASSERT
47 silk_assert( 0 );
48 #endif
50 return ret;
53 #undef silk_ADD32
54 #define silk_ADD32(a,b) silk_ADD32_((a), (b), __FILE__, __LINE__)
55 static OPUS_INLINE opus_int32 silk_ADD32_(opus_int32 a, opus_int32 b, char *file, int line){
56 opus_int32 ret;
58 ret = (opus_int32)((opus_uint32)a + (opus_uint32)b);
59 if ( ret != silk_ADD_SAT32( a, b ) )
61 fprintf (stderr, "silk_ADD32(%d, %d) in %s: line %d\n", a, b, file, line);
62 #ifdef FIXED_DEBUG_ASSERT
63 silk_assert( 0 );
64 #endif
66 return ret;
69 #undef silk_ADD64
70 #define silk_ADD64(a,b) silk_ADD64_((a), (b), __FILE__, __LINE__)
71 static OPUS_INLINE opus_int64 silk_ADD64_(opus_int64 a, opus_int64 b, char *file, int line){
72 opus_int64 ret;
74 ret = a + b;
75 if ( ret != silk_ADD_SAT64( a, b ) )
77 fprintf (stderr, "silk_ADD64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
78 #ifdef FIXED_DEBUG_ASSERT
79 silk_assert( 0 );
80 #endif
82 return ret;
85 #undef silk_SUB16
86 #define silk_SUB16(a,b) silk_SUB16_((a), (b), __FILE__, __LINE__)
87 static OPUS_INLINE opus_int16 silk_SUB16_(opus_int16 a, opus_int16 b, char *file, int line){
88 opus_int16 ret;
90 ret = a - b;
91 if ( ret != silk_SUB_SAT16( a, b ) )
93 fprintf (stderr, "silk_SUB16(%d, %d) in %s: line %d\n", a, b, file, line);
94 #ifdef FIXED_DEBUG_ASSERT
95 silk_assert( 0 );
96 #endif
98 return ret;
101 #undef silk_SUB32
102 #define silk_SUB32(a,b) silk_SUB32_((a), (b), __FILE__, __LINE__)
103 static OPUS_INLINE opus_int32 silk_SUB32_(opus_int32 a, opus_int32 b, char *file, int line){
104 opus_int64 ret;
106 ret = a - (opus_int64)b;
107 if ( ret != silk_SUB_SAT32( a, b ) )
109 fprintf (stderr, "silk_SUB32(%d, %d) in %s: line %d\n", a, b, file, line);
110 #ifdef FIXED_DEBUG_ASSERT
111 silk_assert( 0 );
112 #endif
114 return ret;
117 #undef silk_SUB64
118 #define silk_SUB64(a,b) silk_SUB64_((a), (b), __FILE__, __LINE__)
119 static OPUS_INLINE opus_int64 silk_SUB64_(opus_int64 a, opus_int64 b, char *file, int line){
120 opus_int64 ret;
122 ret = a - b;
123 if ( ret != silk_SUB_SAT64( a, b ) )
125 fprintf (stderr, "silk_SUB64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)b, file, line);
126 #ifdef FIXED_DEBUG_ASSERT
127 silk_assert( 0 );
128 #endif
130 return ret;
133 #undef silk_ADD_SAT16
134 #define silk_ADD_SAT16(a,b) silk_ADD_SAT16_((a), (b), __FILE__, __LINE__)
135 static OPUS_INLINE opus_int16 silk_ADD_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line) {
136 opus_int16 res;
137 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
138 if ( res != silk_SAT16( (opus_int32)a16 + (opus_int32)b16 ) )
140 fprintf (stderr, "silk_ADD_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
141 #ifdef FIXED_DEBUG_ASSERT
142 silk_assert( 0 );
143 #endif
145 return res;
148 #undef silk_ADD_SAT32
149 #define silk_ADD_SAT32(a,b) silk_ADD_SAT32_((a), (b), __FILE__, __LINE__)
150 static OPUS_INLINE opus_int32 silk_ADD_SAT32_(opus_int32 a32, opus_int32 b32, char *file, int line){
151 opus_int32 res;
152 res = ((((opus_uint32)(a32) + (opus_uint32)(b32)) & 0x80000000) == 0 ? \
153 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
154 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
155 if ( res != silk_SAT32( (opus_int64)a32 + (opus_int64)b32 ) )
157 fprintf (stderr, "silk_ADD_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
158 #ifdef FIXED_DEBUG_ASSERT
159 silk_assert( 0 );
160 #endif
162 return res;
165 #undef silk_ADD_SAT64
166 #define silk_ADD_SAT64(a,b) silk_ADD_SAT64_((a), (b), __FILE__, __LINE__)
167 static OPUS_INLINE opus_int64 silk_ADD_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line) {
168 opus_int64 res;
169 int fail = 0;
170 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
171 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
172 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
173 if( res != a64 + b64 ) {
174 /* Check that we saturated to the correct extreme value */
175 if ( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
176 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ) )
178 fail = 1;
180 } else {
181 /* Saturation not necessary */
182 fail = res != a64 + b64;
184 if ( fail )
186 fprintf (stderr, "silk_ADD_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
187 #ifdef FIXED_DEBUG_ASSERT
188 silk_assert( 0 );
189 #endif
191 return res;
194 #undef silk_SUB_SAT16
195 #define silk_SUB_SAT16(a,b) silk_SUB_SAT16_((a), (b), __FILE__, __LINE__)
196 static OPUS_INLINE opus_int16 silk_SUB_SAT16_( opus_int16 a16, opus_int16 b16, char *file, int line ) {
197 opus_int16 res;
198 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
199 if ( res != silk_SAT16( (opus_int32)a16 - (opus_int32)b16 ) )
201 fprintf (stderr, "silk_SUB_SAT16(%d, %d) in %s: line %d\n", a16, b16, file, line);
202 #ifdef FIXED_DEBUG_ASSERT
203 silk_assert( 0 );
204 #endif
206 return res;
209 #undef silk_SUB_SAT32
210 #define silk_SUB_SAT32(a,b) silk_SUB_SAT32_((a), (b), __FILE__, __LINE__)
211 static OPUS_INLINE opus_int32 silk_SUB_SAT32_( opus_int32 a32, opus_int32 b32, char *file, int line ) {
212 opus_int32 res;
213 res = ((((opus_uint32)(a32)-(opus_uint32)(b32)) & 0x80000000) == 0 ? \
214 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
215 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
216 if ( res != silk_SAT32( (opus_int64)a32 - (opus_int64)b32 ) )
218 fprintf (stderr, "silk_SUB_SAT32(%d, %d) in %s: line %d\n", a32, b32, file, line);
219 #ifdef FIXED_DEBUG_ASSERT
220 silk_assert( 0 );
221 #endif
223 return res;
226 #undef silk_SUB_SAT64
227 #define silk_SUB_SAT64(a,b) silk_SUB_SAT64_((a), (b), __FILE__, __LINE__)
228 static OPUS_INLINE opus_int64 silk_SUB_SAT64_( opus_int64 a64, opus_int64 b64, char *file, int line ) {
229 opus_int64 res;
230 int fail = 0;
231 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
232 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
233 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
234 if( res != a64 - b64 ) {
235 /* Check that we saturated to the correct extreme value */
236 if( !(( res == silk_int64_MAX && ( ( a64 >> 1 ) + ( b64 >> 1 ) > ( silk_int64_MAX >> 3 ) ) ) ||
237 ( res == silk_int64_MIN && ( ( a64 >> 1 ) + ( b64 >> 1 ) < ( silk_int64_MIN >> 3 ) ) ) ))
239 fail = 1;
241 } else {
242 /* Saturation not necessary */
243 fail = res != a64 - b64;
245 if ( fail )
247 fprintf (stderr, "silk_SUB_SAT64(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
248 #ifdef FIXED_DEBUG_ASSERT
249 silk_assert( 0 );
250 #endif
252 return res;
255 #undef silk_MUL
256 #define silk_MUL(a,b) silk_MUL_((a), (b), __FILE__, __LINE__)
257 static OPUS_INLINE opus_int32 silk_MUL_(opus_int32 a32, opus_int32 b32, char *file, int line){
258 opus_int32 ret;
259 opus_int64 ret64;
260 ret = (opus_int32)((opus_uint32)a32 * (opus_uint32)b32);
261 ret64 = (opus_int64)a32 * (opus_int64)b32;
262 if ( (opus_int64)ret != ret64 )
264 fprintf (stderr, "silk_MUL(%d, %d) in %s: line %d\n", a32, b32, file, line);
265 #ifdef FIXED_DEBUG_ASSERT
266 silk_assert( 0 );
267 #endif
269 return ret;
272 #undef silk_MUL_uint
273 #define silk_MUL_uint(a,b) silk_MUL_uint_((a), (b), __FILE__, __LINE__)
274 static OPUS_INLINE opus_uint32 silk_MUL_uint_(opus_uint32 a32, opus_uint32 b32, char *file, int line){
275 opus_uint32 ret;
276 ret = a32 * b32;
277 if ( (opus_uint64)ret != (opus_uint64)a32 * (opus_uint64)b32 )
279 fprintf (stderr, "silk_MUL_uint(%u, %u) in %s: line %d\n", a32, b32, file, line);
280 #ifdef FIXED_DEBUG_ASSERT
281 silk_assert( 0 );
282 #endif
284 return ret;
287 #undef silk_MLA
288 #define silk_MLA(a,b,c) silk_MLA_((a), (b), (c), __FILE__, __LINE__)
289 static OPUS_INLINE opus_int32 silk_MLA_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
290 opus_int32 ret;
291 ret = a32 + b32 * c32;
292 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
294 fprintf (stderr, "silk_MLA(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
295 #ifdef FIXED_DEBUG_ASSERT
296 silk_assert( 0 );
297 #endif
299 return ret;
302 #undef silk_MLA_uint
303 #define silk_MLA_uint(a,b,c) silk_MLA_uint_((a), (b), (c), __FILE__, __LINE__)
304 static OPUS_INLINE opus_int32 silk_MLA_uint_(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32, char *file, int line){
305 opus_uint32 ret;
306 ret = a32 + b32 * c32;
307 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int64)c32 )
309 fprintf (stderr, "silk_MLA_uint(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
310 #ifdef FIXED_DEBUG_ASSERT
311 silk_assert( 0 );
312 #endif
314 return ret;
317 #undef silk_SMULWB
318 #define silk_SMULWB(a,b) silk_SMULWB_((a), (b), __FILE__, __LINE__)
319 static OPUS_INLINE opus_int32 silk_SMULWB_(opus_int32 a32, opus_int32 b32, char *file, int line){
320 opus_int32 ret;
321 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
322 if ( (opus_int64)ret != ((opus_int64)a32 * (opus_int16)b32) >> 16 )
324 fprintf (stderr, "silk_SMULWB(%d, %d) in %s: line %d\n", a32, b32, file, line);
325 #ifdef FIXED_DEBUG_ASSERT
326 silk_assert( 0 );
327 #endif
329 return ret;
332 #undef silk_SMLAWB
333 #define silk_SMLAWB(a,b,c) silk_SMLAWB_((a), (b), (c), __FILE__, __LINE__)
334 static OPUS_INLINE opus_int32 silk_SMLAWB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
335 opus_int32 ret;
336 ret = silk_ADD32_ovflw( a32, silk_SMULWB( b32, c32 ) );
337 if ( ret != silk_ADD_SAT32( a32, silk_SMULWB( b32, c32 ) ) )
339 fprintf (stderr, "silk_SMLAWB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
340 #ifdef FIXED_DEBUG_ASSERT
341 silk_assert( 0 );
342 #endif
344 return ret;
347 #undef silk_SMULWT
348 #define silk_SMULWT(a,b) silk_SMULWT_((a), (b), __FILE__, __LINE__)
349 static OPUS_INLINE opus_int32 silk_SMULWT_(opus_int32 a32, opus_int32 b32, char *file, int line){
350 opus_int32 ret;
351 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
352 if ( (opus_int64)ret != ((opus_int64)a32 * (b32 >> 16)) >> 16 )
354 fprintf (stderr, "silk_SMULWT(%d, %d) in %s: line %d\n", a32, b32, file, line);
355 #ifdef FIXED_DEBUG_ASSERT
356 silk_assert( 0 );
357 #endif
359 return ret;
362 #undef silk_SMLAWT
363 #define silk_SMLAWT(a,b,c) silk_SMLAWT_((a), (b), (c), __FILE__, __LINE__)
364 static OPUS_INLINE opus_int32 silk_SMLAWT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
365 opus_int32 ret;
366 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
367 if ( (opus_int64)ret != (opus_int64)a32 + (((opus_int64)b32 * (c32 >> 16)) >> 16) )
369 fprintf (stderr, "silk_SMLAWT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
370 #ifdef FIXED_DEBUG_ASSERT
371 silk_assert( 0 );
372 #endif
374 return ret;
377 #undef silk_SMULL
378 #define silk_SMULL(a,b) silk_SMULL_((a), (b), __FILE__, __LINE__)
379 static OPUS_INLINE opus_int64 silk_SMULL_(opus_int64 a64, opus_int64 b64, char *file, int line){
380 opus_int64 ret64;
381 int fail = 0;
382 ret64 = a64 * b64;
383 if( b64 != 0 ) {
384 fail = a64 != (ret64 / b64);
385 } else if( a64 != 0 ) {
386 fail = b64 != (ret64 / a64);
388 if ( fail )
390 fprintf (stderr, "silk_SMULL(%lld, %lld) in %s: line %d\n", (long long)a64, (long long)b64, file, line);
391 #ifdef FIXED_DEBUG_ASSERT
392 silk_assert( 0 );
393 #endif
395 return ret64;
398 /* no checking needed for silk_SMULBB */
399 #undef silk_SMLABB
400 #define silk_SMLABB(a,b,c) silk_SMLABB_((a), (b), (c), __FILE__, __LINE__)
401 static OPUS_INLINE opus_int32 silk_SMLABB_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
402 opus_int32 ret;
403 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
404 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (opus_int16)c32 )
406 fprintf (stderr, "silk_SMLABB(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
407 #ifdef FIXED_DEBUG_ASSERT
408 silk_assert( 0 );
409 #endif
411 return ret;
414 /* no checking needed for silk_SMULBT */
415 #undef silk_SMLABT
416 #define silk_SMLABT(a,b,c) silk_SMLABT_((a), (b), (c), __FILE__, __LINE__)
417 static OPUS_INLINE opus_int32 silk_SMLABT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
418 opus_int32 ret;
419 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
420 if ( (opus_int64)ret != (opus_int64)a32 + (opus_int64)b32 * (c32 >> 16) )
422 fprintf (stderr, "silk_SMLABT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
423 #ifdef FIXED_DEBUG_ASSERT
424 silk_assert( 0 );
425 #endif
427 return ret;
430 /* no checking needed for silk_SMULTT */
431 #undef silk_SMLATT
432 #define silk_SMLATT(a,b,c) silk_SMLATT_((a), (b), (c), __FILE__, __LINE__)
433 static OPUS_INLINE opus_int32 silk_SMLATT_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
434 opus_int32 ret;
435 ret = a32 + (b32 >> 16) * (c32 >> 16);
436 if ( (opus_int64)ret != (opus_int64)a32 + (b32 >> 16) * (c32 >> 16) )
438 fprintf (stderr, "silk_SMLATT(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
439 #ifdef FIXED_DEBUG_ASSERT
440 silk_assert( 0 );
441 #endif
443 return ret;
446 #undef silk_SMULWW
447 #define silk_SMULWW(a,b) silk_SMULWW_((a), (b), __FILE__, __LINE__)
448 static OPUS_INLINE opus_int32 silk_SMULWW_(opus_int32 a32, opus_int32 b32, char *file, int line){
449 opus_int32 ret, tmp1, tmp2;
450 opus_int64 ret64;
451 int fail = 0;
453 ret = silk_SMULWB( a32, b32 );
454 tmp1 = silk_RSHIFT_ROUND( b32, 16 );
455 tmp2 = silk_MUL( a32, tmp1 );
457 fail |= (opus_int64)tmp2 != (opus_int64) a32 * (opus_int64) tmp1;
459 tmp1 = ret;
460 ret = silk_ADD32( tmp1, tmp2 );
461 fail |= silk_ADD32( tmp1, tmp2 ) != silk_ADD_SAT32( tmp1, tmp2 );
463 ret64 = silk_RSHIFT64( silk_SMULL( a32, b32 ), 16 );
464 fail |= (opus_int64)ret != ret64;
466 if ( fail )
468 fprintf (stderr, "silk_SMULWW(%d, %d) in %s: line %d\n", a32, b32, file, line);
469 #ifdef FIXED_DEBUG_ASSERT
470 silk_assert( 0 );
471 #endif
474 return ret;
477 #undef silk_SMLAWW
478 #define silk_SMLAWW(a,b,c) silk_SMLAWW_((a), (b), (c), __FILE__, __LINE__)
479 static OPUS_INLINE opus_int32 silk_SMLAWW_(opus_int32 a32, opus_int32 b32, opus_int32 c32, char *file, int line){
480 opus_int32 ret, tmp;
482 tmp = silk_SMULWW( b32, c32 );
483 ret = silk_ADD32( a32, tmp );
484 if ( ret != silk_ADD_SAT32( a32, tmp ) )
486 fprintf (stderr, "silk_SMLAWW(%d, %d, %d) in %s: line %d\n", a32, b32, c32, file, line);
487 #ifdef FIXED_DEBUG_ASSERT
488 silk_assert( 0 );
489 #endif
491 return ret;
494 /* no checking needed for silk_SMULL
495 no checking needed for silk_SMLAL
496 no checking needed for silk_SMLALBB
497 no checking needed for SigProcFIX_CLZ16
498 no checking needed for SigProcFIX_CLZ32*/
500 #undef silk_DIV32
501 #define silk_DIV32(a,b) silk_DIV32_((a), (b), __FILE__, __LINE__)
502 static OPUS_INLINE opus_int32 silk_DIV32_(opus_int32 a32, opus_int32 b32, char *file, int line){
503 if ( b32 == 0 )
505 fprintf (stderr, "silk_DIV32(%d, %d) in %s: line %d\n", a32, b32, file, line);
506 #ifdef FIXED_DEBUG_ASSERT
507 silk_assert( 0 );
508 #endif
510 return a32 / b32;
513 #undef silk_DIV32_16
514 #define silk_DIV32_16(a,b) silk_DIV32_16_((a), (b), __FILE__, __LINE__)
515 static OPUS_INLINE opus_int32 silk_DIV32_16_(opus_int32 a32, opus_int32 b32, char *file, int line){
516 int fail = 0;
517 fail |= b32 == 0;
518 fail |= b32 > silk_int16_MAX;
519 fail |= b32 < silk_int16_MIN;
520 if ( fail )
522 fprintf (stderr, "silk_DIV32_16(%d, %d) in %s: line %d\n", a32, b32, file, line);
523 #ifdef FIXED_DEBUG_ASSERT
524 silk_assert( 0 );
525 #endif
527 return a32 / b32;
530 /* no checking needed for silk_SAT8
531 no checking needed for silk_SAT16
532 no checking needed for silk_SAT32
533 no checking needed for silk_POS_SAT32
534 no checking needed for silk_ADD_POS_SAT8
535 no checking needed for silk_ADD_POS_SAT16
536 no checking needed for silk_ADD_POS_SAT32 */
538 #undef silk_LSHIFT8
539 #define silk_LSHIFT8(a,b) silk_LSHIFT8_((a), (b), __FILE__, __LINE__)
540 static OPUS_INLINE opus_int8 silk_LSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
541 opus_int8 ret;
542 int fail = 0;
543 ret = (opus_int8)((opus_uint8)a << shift);
544 fail |= shift < 0;
545 fail |= shift >= 8;
546 fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift);
547 if ( fail )
549 fprintf (stderr, "silk_LSHIFT8(%d, %d) in %s: line %d\n", a, shift, file, line);
550 #ifdef FIXED_DEBUG_ASSERT
551 silk_assert( 0 );
552 #endif
554 return ret;
557 #undef silk_LSHIFT16
558 #define silk_LSHIFT16(a,b) silk_LSHIFT16_((a), (b), __FILE__, __LINE__)
559 static OPUS_INLINE opus_int16 silk_LSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
560 opus_int16 ret;
561 int fail = 0;
562 ret = (opus_int16)((opus_uint16)a << shift);
563 fail |= shift < 0;
564 fail |= shift >= 16;
565 fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift);
566 if ( fail )
568 fprintf (stderr, "silk_LSHIFT16(%d, %d) in %s: line %d\n", a, shift, file, line);
569 #ifdef FIXED_DEBUG_ASSERT
570 silk_assert( 0 );
571 #endif
573 return ret;
576 #undef silk_LSHIFT32
577 #define silk_LSHIFT32(a,b) silk_LSHIFT32_((a), (b), __FILE__, __LINE__)
578 static OPUS_INLINE opus_int32 silk_LSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
579 opus_int32 ret;
580 int fail = 0;
581 ret = (opus_int32)((opus_uint32)a << shift);
582 fail |= shift < 0;
583 fail |= shift >= 32;
584 fail |= (opus_int64)ret != (opus_int64)(((opus_uint64)a) << shift);
585 if ( fail )
587 fprintf (stderr, "silk_LSHIFT32(%d, %d) in %s: line %d\n", a, shift, file, line);
588 #ifdef FIXED_DEBUG_ASSERT
589 silk_assert( 0 );
590 #endif
592 return ret;
595 #undef silk_LSHIFT64
596 #define silk_LSHIFT64(a,b) silk_LSHIFT64_((a), (b), __FILE__, __LINE__)
597 static OPUS_INLINE opus_int64 silk_LSHIFT64_(opus_int64 a, opus_int shift, char *file, int line){
598 opus_int64 ret;
599 int fail = 0;
600 ret = (opus_int64)((opus_uint64)a << shift);
601 fail |= shift < 0;
602 fail |= shift >= 64;
603 fail |= (ret>>shift) != ((opus_int64)a);
604 if ( fail )
606 fprintf (stderr, "silk_LSHIFT64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
607 #ifdef FIXED_DEBUG_ASSERT
608 silk_assert( 0 );
609 #endif
611 return ret;
614 #undef silk_LSHIFT_ovflw
615 #define silk_LSHIFT_ovflw(a,b) silk_LSHIFT_ovflw_((a), (b), __FILE__, __LINE__)
616 static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw_(opus_int32 a, opus_int32 shift, char *file, int line){
617 if ( (shift < 0) || (shift >= 32) ) /* no check for overflow */
619 fprintf (stderr, "silk_LSHIFT_ovflw(%d, %d) in %s: line %d\n", a, shift, file, line);
620 #ifdef FIXED_DEBUG_ASSERT
621 silk_assert( 0 );
622 #endif
624 return a << shift;
627 #undef silk_LSHIFT_uint
628 #define silk_LSHIFT_uint(a,b) silk_LSHIFT_uint_((a), (b), __FILE__, __LINE__)
629 static OPUS_INLINE opus_uint32 silk_LSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
630 opus_uint32 ret;
631 ret = a << shift;
632 if ( (shift < 0) || ((opus_int64)ret != ((opus_int64)a) << shift))
634 fprintf (stderr, "silk_LSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
635 #ifdef FIXED_DEBUG_ASSERT
636 silk_assert( 0 );
637 #endif
639 return ret;
642 #undef silk_RSHIFT8
643 #define silk_RSHITF8(a,b) silk_RSHIFT8_((a), (b), __FILE__, __LINE__)
644 static OPUS_INLINE opus_int8 silk_RSHIFT8_(opus_int8 a, opus_int32 shift, char *file, int line){
645 if ( (shift < 0) || (shift>=8) )
647 fprintf (stderr, "silk_RSHITF8(%d, %d) in %s: line %d\n", a, shift, file, line);
648 #ifdef FIXED_DEBUG_ASSERT
649 silk_assert( 0 );
650 #endif
652 return a >> shift;
655 #undef silk_RSHIFT16
656 #define silk_RSHITF16(a,b) silk_RSHIFT16_((a), (b), __FILE__, __LINE__)
657 static OPUS_INLINE opus_int16 silk_RSHIFT16_(opus_int16 a, opus_int32 shift, char *file, int line){
658 if ( (shift < 0) || (shift>=16) )
660 fprintf (stderr, "silk_RSHITF16(%d, %d) in %s: line %d\n", a, shift, file, line);
661 #ifdef FIXED_DEBUG_ASSERT
662 silk_assert( 0 );
663 #endif
665 return a >> shift;
668 #undef silk_RSHIFT32
669 #define silk_RSHIFT32(a,b) silk_RSHIFT32_((a), (b), __FILE__, __LINE__)
670 static OPUS_INLINE opus_int32 silk_RSHIFT32_(opus_int32 a, opus_int32 shift, char *file, int line){
671 if ( (shift < 0) || (shift>=32) )
673 fprintf (stderr, "silk_RSHITF32(%d, %d) in %s: line %d\n", a, shift, file, line);
674 #ifdef FIXED_DEBUG_ASSERT
675 silk_assert( 0 );
676 #endif
678 return a >> shift;
681 #undef silk_RSHIFT64
682 #define silk_RSHIFT64(a,b) silk_RSHIFT64_((a), (b), __FILE__, __LINE__)
683 static OPUS_INLINE opus_int64 silk_RSHIFT64_(opus_int64 a, opus_int64 shift, char *file, int line){
684 if ( (shift < 0) || (shift>=64) )
686 fprintf (stderr, "silk_RSHITF64(%lld, %lld) in %s: line %d\n", (long long)a, (long long)shift, file, line);
687 #ifdef FIXED_DEBUG_ASSERT
688 silk_assert( 0 );
689 #endif
691 return a >> shift;
694 #undef silk_RSHIFT_uint
695 #define silk_RSHIFT_uint(a,b) silk_RSHIFT_uint_((a), (b), __FILE__, __LINE__)
696 static OPUS_INLINE opus_uint32 silk_RSHIFT_uint_(opus_uint32 a, opus_int32 shift, char *file, int line){
697 if ( (shift < 0) || (shift>32) )
699 fprintf (stderr, "silk_RSHIFT_uint(%u, %d) in %s: line %d\n", a, shift, file, line);
700 #ifdef FIXED_DEBUG_ASSERT
701 silk_assert( 0 );
702 #endif
704 return a >> shift;
707 #undef silk_ADD_LSHIFT
708 #define silk_ADD_LSHIFT(a,b,c) silk_ADD_LSHIFT_((a), (b), (c), __FILE__, __LINE__)
709 static OPUS_INLINE int silk_ADD_LSHIFT_(int a, int b, int shift, char *file, int line){
710 opus_int16 ret;
711 ret = a + (opus_int16)((opus_uint16)b << shift);
712 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (opus_int64)(((opus_uint64)b) << shift)) )
714 fprintf (stderr, "silk_ADD_LSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
715 #ifdef FIXED_DEBUG_ASSERT
716 silk_assert( 0 );
717 #endif
719 return ret; /* shift >= 0 */
722 #undef silk_ADD_LSHIFT32
723 #define silk_ADD_LSHIFT32(a,b,c) silk_ADD_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
724 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
725 opus_int32 ret;
726 ret = silk_ADD32_ovflw(a, (opus_int32)((opus_uint32)b << shift));
727 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (opus_int64)(((opus_uint64)b) << shift)) )
729 fprintf (stderr, "silk_ADD_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
730 #ifdef FIXED_DEBUG_ASSERT
731 silk_assert( 0 );
732 #endif
734 return ret; /* shift >= 0 */
737 #undef silk_ADD_LSHIFT_uint
738 #define silk_ADD_LSHIFT_uint(a,b,c) silk_ADD_LSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
739 static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
740 opus_uint32 ret;
741 ret = a + (b << shift);
742 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) << shift)) )
744 fprintf (stderr, "silk_ADD_LSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
745 #ifdef FIXED_DEBUG_ASSERT
746 silk_assert( 0 );
747 #endif
749 return ret; /* shift >= 0 */
752 #undef silk_ADD_RSHIFT
753 #define silk_ADD_RSHIFT(a,b,c) silk_ADD_RSHIFT_((a), (b), (c), __FILE__, __LINE__)
754 static OPUS_INLINE int silk_ADD_RSHIFT_(int a, int b, int shift, char *file, int line){
755 opus_int16 ret;
756 ret = a + (b >> shift);
757 if ( (shift < 0) || (shift>15) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
759 fprintf (stderr, "silk_ADD_RSHIFT(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
760 #ifdef FIXED_DEBUG_ASSERT
761 silk_assert( 0 );
762 #endif
764 return ret; /* shift > 0 */
767 #undef silk_ADD_RSHIFT32
768 #define silk_ADD_RSHIFT32(a,b,c) silk_ADD_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
769 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
770 opus_int32 ret;
771 ret = silk_ADD32_ovflw(a, (b >> shift));
772 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
774 fprintf (stderr, "silk_ADD_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
775 #ifdef FIXED_DEBUG_ASSERT
776 silk_assert( 0 );
777 #endif
779 return ret; /* shift > 0 */
782 #undef silk_ADD_RSHIFT_uint
783 #define silk_ADD_RSHIFT_uint(a,b,c) silk_ADD_RSHIFT_uint_((a), (b), (c), __FILE__, __LINE__)
784 static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint_(opus_uint32 a, opus_uint32 b, opus_int32 shift, char *file, int line){
785 opus_uint32 ret;
786 ret = a + (b >> shift);
787 if ( (shift < 0) || (shift>32) || ((opus_int64)ret != (opus_int64)a + (((opus_int64)b) >> shift)) )
789 fprintf (stderr, "silk_ADD_RSHIFT_uint(%u, %u, %d) in %s: line %d\n", a, b, shift, file, line);
790 #ifdef FIXED_DEBUG_ASSERT
791 silk_assert( 0 );
792 #endif
794 return ret; /* shift > 0 */
797 #undef silk_SUB_LSHIFT32
798 #define silk_SUB_LSHIFT32(a,b,c) silk_SUB_LSHIFT32_((a), (b), (c), __FILE__, __LINE__)
799 static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
800 opus_int32 ret;
801 ret = silk_SUB32_ovflw(a, (opus_int32)((opus_uint32)b << shift));
802 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (opus_int64)(((opus_uint64)b) << shift)) )
804 fprintf (stderr, "silk_SUB_LSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
805 #ifdef FIXED_DEBUG_ASSERT
806 silk_assert( 0 );
807 #endif
809 return ret; /* shift >= 0 */
812 #undef silk_SUB_RSHIFT32
813 #define silk_SUB_RSHIFT32(a,b,c) silk_SUB_RSHIFT32_((a), (b), (c), __FILE__, __LINE__)
814 static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32_(opus_int32 a, opus_int32 b, opus_int32 shift, char *file, int line){
815 opus_int32 ret;
816 ret = silk_SUB32_ovflw(a, (b >> shift));
817 if ( (shift < 0) || (shift>31) || ((opus_int64)ret != (opus_int64)a - (((opus_int64)b) >> shift)) )
819 fprintf (stderr, "silk_SUB_RSHIFT32(%d, %d, %d) in %s: line %d\n", a, b, shift, file, line);
820 #ifdef FIXED_DEBUG_ASSERT
821 silk_assert( 0 );
822 #endif
824 return ret; /* shift > 0 */
827 #undef silk_RSHIFT_ROUND
828 #define silk_RSHIFT_ROUND(a,b) silk_RSHIFT_ROUND_((a), (b), __FILE__, __LINE__)
829 static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND_(opus_int32 a, opus_int32 shift, char *file, int line){
830 opus_int32 ret;
831 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
832 /* the macro definition can't handle a shift of zero */
833 if ( (shift <= 0) || (shift>31) || ((opus_int64)ret != ((opus_int64)a + ((opus_int64)1 << (shift - 1))) >> shift) )
835 fprintf (stderr, "silk_RSHIFT_ROUND(%d, %d) in %s: line %d\n", a, shift, file, line);
836 #ifdef FIXED_DEBUG_ASSERT
837 silk_assert( 0 );
838 #endif
840 return ret;
843 #undef silk_RSHIFT_ROUND64
844 #define silk_RSHIFT_ROUND64(a,b) silk_RSHIFT_ROUND64_((a), (b), __FILE__, __LINE__)
845 static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64_(opus_int64 a, opus_int32 shift, char *file, int line){
846 opus_int64 ret;
847 /* the macro definition can't handle a shift of zero */
848 if ( (shift <= 0) || (shift>=64) )
850 fprintf (stderr, "silk_RSHIFT_ROUND64(%lld, %d) in %s: line %d\n", (long long)a, shift, file, line);
851 #ifdef FIXED_DEBUG_ASSERT
852 silk_assert( 0 );
853 #endif
855 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
856 return ret;
859 /* silk_abs is used on floats also, so doesn't work... */
860 /*#undef silk_abs
861 static OPUS_INLINE opus_int32 silk_abs(opus_int32 a){
862 silk_assert(a != 0x80000000);
863 return (((a) > 0) ? (a) : -(a)); // Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN
866 #undef silk_abs_int64
867 #define silk_abs_int64(a) silk_abs_int64_((a), __FILE__, __LINE__)
868 static OPUS_INLINE opus_int64 silk_abs_int64_(opus_int64 a, char *file, int line){
869 if ( a == silk_int64_MIN )
871 fprintf (stderr, "silk_abs_int64(%lld) in %s: line %d\n", (long long)a, file, line);
872 #ifdef FIXED_DEBUG_ASSERT
873 silk_assert( 0 );
874 #endif
876 return (((a) > 0) ? (a) : -(a)); /* Be careful, silk_abs returns wrong when input equals to silk_intXX_MIN */
879 #undef silk_abs_int32
880 #define silk_abs_int32(a) silk_abs_int32_((a), __FILE__, __LINE__)
881 static OPUS_INLINE opus_int32 silk_abs_int32_(opus_int32 a, char *file, int line){
882 if ( a == silk_int32_MIN )
884 fprintf (stderr, "silk_abs_int32(%d) in %s: line %d\n", a, file, line);
885 #ifdef FIXED_DEBUG_ASSERT
886 silk_assert( 0 );
887 #endif
889 return silk_abs(a);
892 #undef silk_CHECK_FIT8
893 #define silk_CHECK_FIT8(a) silk_CHECK_FIT8_((a), __FILE__, __LINE__)
894 static OPUS_INLINE opus_int8 silk_CHECK_FIT8_( opus_int64 a, char *file, int line ){
895 opus_int8 ret;
896 ret = (opus_int8)a;
897 if ( (opus_int64)ret != a )
899 fprintf (stderr, "silk_CHECK_FIT8(%lld) in %s: line %d\n", (long long)a, file, line);
900 #ifdef FIXED_DEBUG_ASSERT
901 silk_assert( 0 );
902 #endif
904 return( ret );
907 #undef silk_CHECK_FIT16
908 #define silk_CHECK_FIT16(a) silk_CHECK_FIT16_((a), __FILE__, __LINE__)
909 static OPUS_INLINE opus_int16 silk_CHECK_FIT16_( opus_int64 a, char *file, int line ){
910 opus_int16 ret;
911 ret = (opus_int16)a;
912 if ( (opus_int64)ret != a )
914 fprintf (stderr, "silk_CHECK_FIT16(%lld) in %s: line %d\n", (long long)a, file, line);
915 #ifdef FIXED_DEBUG_ASSERT
916 silk_assert( 0 );
917 #endif
919 return( ret );
922 #undef silk_CHECK_FIT32
923 #define silk_CHECK_FIT32(a) silk_CHECK_FIT32_((a), __FILE__, __LINE__)
924 static OPUS_INLINE opus_int32 silk_CHECK_FIT32_( opus_int64 a, char *file, int line ){
925 opus_int32 ret;
926 ret = (opus_int32)a;
927 if ( (opus_int64)ret != a )
929 fprintf (stderr, "silk_CHECK_FIT32(%lld) in %s: line %d\n", (long long)a, file, line);
930 #ifdef FIXED_DEBUG_ASSERT
931 silk_assert( 0 );
932 #endif
934 return( ret );
937 /* no checking for silk_NSHIFT_MUL_32_32
938 no checking for silk_NSHIFT_MUL_16_16
939 no checking needed for silk_min
940 no checking needed for silk_max
941 no checking needed for silk_sign
944 #endif
945 #endif /* MACRO_DEBUG_H */