28 #ifndef SIGPROCFIX_API_MACROCOUNT_H
29 #define SIGPROCFIX_API_MACROCOUNT_H
32 #ifdef silk_MACRO_COUNT
33 #define varDefine opus_int64 ops_count = 0;
35 extern opus_int64 ops_count;
37 static OPUS_INLINE opus_int64 silk_SaveCount(){
41 static OPUS_INLINE opus_int64 silk_SaveResetCount(){
49 static OPUS_INLINE silk_PrintCount(){
50 printf(
"ops_count = %d \n ", (opus_int32)ops_count);
54 static OPUS_INLINE opus_int32 silk_MUL(opus_int32 a32, opus_int32 b32){
62 static OPUS_INLINE opus_uint32 silk_MUL_uint(opus_uint32 a32, opus_uint32 b32){
69 static OPUS_INLINE opus_int32 silk_MLA(opus_int32 a32, opus_int32 b32, opus_int32 c32){
72 ret = a32 + b32 * c32;
77 static OPUS_INLINE opus_int32 silk_MLA_uint(opus_uint32 a32, opus_uint32 b32, opus_uint32 c32){
80 ret = a32 + b32 * c32;
85 static OPUS_INLINE opus_int32 silk_SMULWB(opus_int32 a32, opus_int32 b32){
88 ret = (a32 >> 16) * (opus_int32)((opus_int16)b32) + (((a32 & 0x0000FFFF) * (opus_int32)((opus_int16)b32)) >> 16);
92 static OPUS_INLINE opus_int32 silk_SMLAWB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
95 ret = ((a32) + ((((b32) >> 16) * (opus_int32)((opus_int16)(c32))) + ((((b32) & 0x0000FFFF) * (opus_int32)((opus_int16)(c32))) >> 16)));
100 static OPUS_INLINE opus_int32 silk_SMULWT(opus_int32 a32, opus_int32 b32){
103 ret = (a32 >> 16) * (b32 >> 16) + (((a32 & 0x0000FFFF) * (b32 >> 16)) >> 16);
107 static OPUS_INLINE opus_int32 silk_SMLAWT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
110 ret = a32 + ((b32 >> 16) * (c32 >> 16)) + (((b32 & 0x0000FFFF) * ((c32 >> 16)) >> 16));
115 static OPUS_INLINE opus_int32 silk_SMULBB(opus_int32 a32, opus_int32 b32){
118 ret = (opus_int32)((opus_int16)a32) * (opus_int32)((opus_int16)b32);
122 static OPUS_INLINE opus_int32 silk_SMLABB(opus_int32 a32, opus_int32 b32, opus_int32 c32){
125 ret = a32 + (opus_int32)((opus_int16)b32) * (opus_int32)((opus_int16)c32);
130 static OPUS_INLINE opus_int32 silk_SMULBT(opus_int32 a32, opus_int32 b32 ){
133 ret = ((opus_int32)((opus_int16)a32)) * (b32 >> 16);
138 static OPUS_INLINE opus_int32 silk_SMLABT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
141 ret = a32 + ((opus_int32)((opus_int16)b32)) * (c32 >> 16);
146 static OPUS_INLINE opus_int32 silk_SMULTT(opus_int32 a32, opus_int32 b32){
149 ret = (a32 >> 16) * (b32 >> 16);
154 static OPUS_INLINE opus_int32 silk_SMLATT(opus_int32 a32, opus_int32 b32, opus_int32 c32){
157 ret = a32 + (b32 >> 16) * (c32 >> 16);
163 #undef silk_MLA_ovflw
164 #define silk_MLA_ovflw silk_MLA
166 #undef silk_SMLABB_ovflw
167 #define silk_SMLABB_ovflw silk_SMLABB
169 #undef silk_SMLABT_ovflw
170 #define silk_SMLABT_ovflw silk_SMLABT
172 #undef silk_SMLATT_ovflw
173 #define silk_SMLATT_ovflw silk_SMLATT
175 #undef silk_SMLAWB_ovflw
176 #define silk_SMLAWB_ovflw silk_SMLAWB
178 #undef silk_SMLAWT_ovflw
179 #define silk_SMLAWT_ovflw silk_SMLAWT
182 static OPUS_INLINE opus_int64 silk_SMULL(opus_int32 a32, opus_int32 b32){
185 ret = ((opus_int64)(a32) * (b32));
190 static OPUS_INLINE opus_int64 silk_SMLAL(opus_int64 a64, opus_int32 b32, opus_int32 c32){
193 ret = a64 + ((opus_int64)(b32) * (c32));
197 static OPUS_INLINE opus_int64 silk_SMLALBB(opus_int64 a64, opus_int16 b16, opus_int16 c16){
200 ret = a64 + ((opus_int64)(b16) * (c16));
204 #undef SigProcFIX_CLZ16
205 static OPUS_INLINE opus_int32 SigProcFIX_CLZ16(opus_int16 in16)
207 opus_int32 out32 = 0;
213 if( in16 & 0xFF00 ) {
214 if( in16 & 0xF000 ) {
221 if( in16 & 0xFFF0 ) {
242 #undef SigProcFIX_CLZ32
243 static OPUS_INLINE opus_int32 SigProcFIX_CLZ32(opus_int32 in32)
247 if( in32 & 0xFFFF0000 ) {
248 return SigProcFIX_CLZ16((opus_int16)(in32 >> 16));
250 return SigProcFIX_CLZ16((opus_int16)in32) + 16;
255 static OPUS_INLINE opus_int32 silk_DIV32(opus_int32 a32, opus_int32 b32){
261 static OPUS_INLINE opus_int32 silk_DIV32_16(opus_int32 a32, opus_int32 b32){
267 static OPUS_INLINE opus_int8 silk_SAT8(opus_int64 a){
270 tmp = (opus_int8)((a) > silk_int8_MAX ? silk_int8_MAX : \
271 ((a) < silk_int8_MIN ? silk_int8_MIN : (a)));
276 static OPUS_INLINE opus_int16 silk_SAT16(opus_int64 a){
279 tmp = (opus_int16)((a) > silk_int16_MAX ? silk_int16_MAX : \
280 ((a) < silk_int16_MIN ? silk_int16_MIN : (a)));
284 static OPUS_INLINE opus_int32 silk_SAT32(opus_int64 a){
287 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : \
288 ((a) < silk_int32_MIN ? silk_int32_MIN : (a)));
291 #undef silk_POS_SAT32
292 static OPUS_INLINE opus_int32 silk_POS_SAT32(opus_int64 a){
295 tmp = (opus_int32)((a) > silk_int32_MAX ? silk_int32_MAX : (a));
299 #undef silk_ADD_POS_SAT8
300 static OPUS_INLINE opus_int8 silk_ADD_POS_SAT8(opus_int64 a, opus_int64 b){
303 tmp = (opus_int8)((((a)+(b)) & 0x80) ? silk_int8_MAX : ((a)+(b)));
306 #undef silk_ADD_POS_SAT16
307 static OPUS_INLINE opus_int16 silk_ADD_POS_SAT16(opus_int64 a, opus_int64 b){
310 tmp = (opus_int16)((((a)+(b)) & 0x8000) ? silk_int16_MAX : ((a)+(b)));
314 #undef silk_ADD_POS_SAT32
315 static OPUS_INLINE opus_int32 silk_ADD_POS_SAT32(opus_int64 a, opus_int64 b){
318 tmp = (opus_int32)((((a)+(b)) & 0x80000000) ? silk_int32_MAX : ((a)+(b)));
323 static OPUS_INLINE opus_int8 silk_LSHIFT8(opus_int8 a, opus_int32 shift){
330 static OPUS_INLINE opus_int16 silk_LSHIFT16(opus_int16 a, opus_int32 shift){
337 static OPUS_INLINE opus_int32 silk_LSHIFT32(opus_int32 a, opus_int32 shift){
344 static OPUS_INLINE opus_int64 silk_LSHIFT64(opus_int64 a, opus_int shift){
349 #undef silk_LSHIFT_ovflw
350 static OPUS_INLINE opus_int32 silk_LSHIFT_ovflw(opus_int32 a, opus_int32 shift){
355 #undef silk_LSHIFT_uint
356 static OPUS_INLINE opus_uint32 silk_LSHIFT_uint(opus_uint32 a, opus_int32 shift){
364 static OPUS_INLINE opus_int8 silk_RSHIFT8(opus_int8 a, opus_int32 shift){
369 static OPUS_INLINE opus_int16 silk_RSHIFT16(opus_int16 a, opus_int32 shift){
374 static OPUS_INLINE opus_int32 silk_RSHIFT32(opus_int32 a, opus_int32 shift){
379 static OPUS_INLINE opus_int64 silk_RSHIFT64(opus_int64 a, opus_int64 shift){
384 #undef silk_RSHIFT_uint
385 static OPUS_INLINE opus_uint32 silk_RSHIFT_uint(opus_uint32 a, opus_int32 shift){
390 #undef silk_ADD_LSHIFT
391 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
394 ret = a + (b << shift);
397 #undef silk_ADD_LSHIFT32
398 static OPUS_INLINE opus_int32 silk_ADD_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
401 ret = a + (b << shift);
404 #undef silk_ADD_LSHIFT_uint
405 static OPUS_INLINE opus_uint32 silk_ADD_LSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
408 ret = a + (b << shift);
411 #undef silk_ADD_RSHIFT
412 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT(opus_int32 a, opus_int32 b, opus_int32 shift){
415 ret = a + (b >> shift);
418 #undef silk_ADD_RSHIFT32
419 static OPUS_INLINE opus_int32 silk_ADD_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
422 ret = a + (b >> shift);
425 #undef silk_ADD_RSHIFT_uint
426 static OPUS_INLINE opus_uint32 silk_ADD_RSHIFT_uint(opus_uint32 a, opus_uint32 b, opus_int32 shift){
429 ret = a + (b >> shift);
432 #undef silk_SUB_LSHIFT32
433 static OPUS_INLINE opus_int32 silk_SUB_LSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
436 ret = a - (b << shift);
439 #undef silk_SUB_RSHIFT32
440 static OPUS_INLINE opus_int32 silk_SUB_RSHIFT32(opus_int32 a, opus_int32 b, opus_int32 shift){
443 ret = a - (b >> shift);
447 #undef silk_RSHIFT_ROUND
448 static OPUS_INLINE opus_int32 silk_RSHIFT_ROUND(opus_int32 a, opus_int32 shift){
451 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
455 #undef silk_RSHIFT_ROUND64
456 static OPUS_INLINE opus_int64 silk_RSHIFT_ROUND64(opus_int64 a, opus_int32 shift){
459 ret = shift == 1 ? (a >> 1) + (a & 1) : ((a >> (shift - 1)) + 1) >> 1;
463 #undef silk_abs_int64
464 static OPUS_INLINE opus_int64 silk_abs_int64(opus_int64 a){
466 return (((a) > 0) ? (a) : -(a));
469 #undef silk_abs_int32
470 static OPUS_INLINE opus_int32 silk_abs_int32(opus_int32 a){
477 static silk_min(a, b){
479 return (((a) < (b)) ? (a) : (b));
482 static silk_max(a, b){
484 return (((a) > (b)) ? (a) : (b));
489 return ((a) > 0 ? 1 : ( (a) < 0 ? -1 : 0 ));
493 static OPUS_INLINE opus_int16 silk_ADD16(opus_int16 a, opus_int16 b){
501 static OPUS_INLINE opus_int32 silk_ADD32(opus_int32 a, opus_int32 b){
509 static OPUS_INLINE opus_int64 silk_ADD64(opus_int64 a, opus_int64 b){
517 static OPUS_INLINE opus_int16 silk_SUB16(opus_int16 a, opus_int16 b){
525 static OPUS_INLINE opus_int32 silk_SUB32(opus_int32 a, opus_int32 b){
533 static OPUS_INLINE opus_int64 silk_SUB64(opus_int64 a, opus_int64 b){
540 #undef silk_ADD_SAT16
541 static OPUS_INLINE opus_int16 silk_ADD_SAT16( opus_int16 a16, opus_int16 b16 ) {
544 res = (opus_int16)silk_SAT16( silk_ADD32( (opus_int32)(a16), (b16) ) );
548 #undef silk_ADD_SAT32
549 static OPUS_INLINE opus_int32 silk_ADD_SAT32(opus_int32 a32, opus_int32 b32){
552 res = ((((a32) + (b32)) & 0x80000000) == 0 ? \
553 ((((a32) & (b32)) & 0x80000000) != 0 ? silk_int32_MIN : (a32)+(b32)) : \
554 ((((a32) | (b32)) & 0x80000000) == 0 ? silk_int32_MAX : (a32)+(b32)) );
558 #undef silk_ADD_SAT64
559 static OPUS_INLINE opus_int64 silk_ADD_SAT64( opus_int64 a64, opus_int64 b64 ) {
562 res = ((((a64) + (b64)) & 0x8000000000000000LL) == 0 ? \
563 ((((a64) & (b64)) & 0x8000000000000000LL) != 0 ? silk_int64_MIN : (a64)+(b64)) : \
564 ((((a64) | (b64)) & 0x8000000000000000LL) == 0 ? silk_int64_MAX : (a64)+(b64)) );
568 #undef silk_SUB_SAT16
569 static OPUS_INLINE opus_int16 silk_SUB_SAT16( opus_int16 a16, opus_int16 b16 ) {
573 res = (opus_int16)silk_SAT16( silk_SUB32( (opus_int32)(a16), (b16) ) );
577 #undef silk_SUB_SAT32
578 static OPUS_INLINE opus_int32 silk_SUB_SAT32( opus_int32 a32, opus_int32 b32 ) {
581 res = ((((a32)-(b32)) & 0x80000000) == 0 ? \
582 (( (a32) & ((b32)^0x80000000) & 0x80000000) ? silk_int32_MIN : (a32)-(b32)) : \
583 ((((a32)^0x80000000) & (b32) & 0x80000000) ? silk_int32_MAX : (a32)-(b32)) );
587 #undef silk_SUB_SAT64
588 static OPUS_INLINE opus_int64 silk_SUB_SAT64( opus_int64 a64, opus_int64 b64 ) {
591 res = ((((a64)-(b64)) & 0x8000000000000000LL) == 0 ? \
592 (( (a64) & ((b64)^0x8000000000000000LL) & 0x8000000000000000LL) ? silk_int64_MIN : (a64)-(b64)) : \
593 ((((a64)^0x8000000000000000LL) & (b64) & 0x8000000000000000LL) ? silk_int64_MAX : (a64)-(b64)) );
599 static OPUS_INLINE opus_int32 silk_SMULWW(opus_int32 a32, opus_int32 b32){
602 ret = silk_MLA(silk_SMULWB((a32), (b32)), (a32), silk_RSHIFT_ROUND((b32), 16));
607 static OPUS_INLINE opus_int32 silk_SMLAWW(opus_int32 a32, opus_int32 b32, opus_int32 c32){
610 ret = silk_MLA(silk_SMLAWB((a32), (b32), (c32)), (b32), silk_RSHIFT_ROUND((c32), 16));
615 static OPUS_INLINE opus_int silk_min_int(opus_int a, opus_int b)
618 return (((a) < (b)) ? (a) : (b));
622 static OPUS_INLINE opus_int16 silk_min_16(opus_int16 a, opus_int16 b)
625 return (((a) < (b)) ? (a) : (b));
628 static OPUS_INLINE opus_int32 silk_min_32(opus_int32 a, opus_int32 b)
631 return (((a) < (b)) ? (a) : (b));
634 static OPUS_INLINE opus_int64 silk_min_64(opus_int64 a, opus_int64 b)
637 return (((a) < (b)) ? (a) : (b));
642 static OPUS_INLINE opus_int silk_max_int(opus_int a, opus_int b)
645 return (((a) > (b)) ? (a) : (b));
648 static OPUS_INLINE opus_int16 silk_max_16(opus_int16 a, opus_int16 b)
651 return (((a) > (b)) ? (a) : (b));
654 static OPUS_INLINE opus_int32 silk_max_32(opus_int32 a, opus_int32 b)
657 return (((a) > (b)) ? (a) : (b));
661 static OPUS_INLINE opus_int64 silk_max_64(opus_int64 a, opus_int64 b)
664 return (((a) > (b)) ? (a) : (b));
668 #undef silk_LIMIT_int
669 static OPUS_INLINE opus_int silk_LIMIT_int(opus_int a, opus_int limit1, opus_int limit2)
674 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
675 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
681 static OPUS_INLINE opus_int16 silk_LIMIT_16(opus_int16 a, opus_int16 limit1, opus_int16 limit2)
686 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
687 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
694 static OPUS_INLINE opus_int32 silk_LIMIT_32(opus_int32 a, opus_int32 limit1, opus_int32 limit2)
699 ret = ((limit1) > (limit2) ? ((a) > (limit1) ? (limit1) : ((a) < (limit2) ? (limit2) : (a))) \
700 : ((a) > (limit2) ? (limit2) : ((a) < (limit1) ? (limit1) : (a))));
706 #define silk_SaveCount()