1 /* Copyright (C) 2003-2008 Jean-Marc Valin
2 Copyright (C) 2007-2012 Xiph.Org Foundation */
5 @brief Fixed-point operations with debugging
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "opus_defines.h"
39 OPUS_EXPORT opus_int64 celt_mips
=0;
41 extern opus_int64 celt_mips
;
44 #define MULT16_16SU(a,b) ((opus_val32)(opus_val16)(a)*(opus_val32)(opus_uint16)(b))
45 #define MULT32_32_Q31(a,b) ADD32(ADD32(SHL32(MULT16_16(SHR32((a),16),SHR((b),16)),1), SHR32(MULT16_16SU(SHR32((a),16),((b)&0x0000ffff)),15)), SHR32(MULT16_16SU(SHR32((b),16),((a)&0x0000ffff)),15))
47 /** 16x32 multiplication, followed by a 16-bit shift right. Results fits in 32 bits */
48 #define MULT16_32_Q16(a,b) ADD32(MULT16_16((a),SHR32((b),16)), SHR32(MULT16_16SU((a),((b)&0x0000ffff)),16))
50 #define MULT16_32_P16(a,b) MULT16_32_PX(a,b,16)
52 #define QCONST16(x,bits) ((opus_val16)(.5+(x)*(((opus_val32)1)<<(bits))))
53 #define QCONST32(x,bits) ((opus_val32)(.5+(x)*(((opus_val32)1)<<(bits))))
55 #define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768)
56 #define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL)
57 #define VERIFY_UINT(x) ((x)<=(2147483647LLU<<1))
59 #define SHR(a,b) SHR32(a,b)
60 #define PSHR(a,b) PSHR32(a,b)
62 /** Add two 32-bit values, ignore any overflows */
63 #define ADD32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)+(opus_uint32)(b)))
64 /** Subtract two 32-bit values, ignore any overflows */
65 #define SUB32_ovflw(a,b) (celt_mips+=2,(opus_val32)((opus_uint32)(a)-(opus_uint32)(b)))
66 /* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */
67 /** Negate 32-bit value, ignore any overflows */
68 #define NEG32_ovflw(a) (celt_mips+=2,(opus_val32)(0-(opus_uint32)(a)))
70 static OPUS_INLINE
short NEG16(int x
)
75 fprintf (stderr
, "NEG16: input is not short: %d\n", (int)x
);
76 #ifdef FIXED_DEBUG_ASSERT
81 if (!VERIFY_SHORT(res
))
83 fprintf (stderr
, "NEG16: output is not short: %d\n", (int)res
);
84 #ifdef FIXED_DEBUG_ASSERT
91 static OPUS_INLINE
int NEG32(opus_int64 x
)
96 fprintf (stderr
, "NEG16: input is not int: %d\n", (int)x
);
97 #ifdef FIXED_DEBUG_ASSERT
102 if (!VERIFY_INT(res
))
104 fprintf (stderr
, "NEG16: output is not int: %d\n", (int)res
);
105 #ifdef FIXED_DEBUG_ASSERT
113 #define EXTRACT16(x) EXTRACT16_(x, __FILE__, __LINE__)
114 static OPUS_INLINE
short EXTRACT16_(int x
, char *file
, int line
)
117 if (!VERIFY_SHORT(x
))
119 fprintf (stderr
, "EXTRACT16: input is not short: %d in %s: line %d\n", x
, file
, line
);
120 #ifdef FIXED_DEBUG_ASSERT
129 #define EXTEND32(x) EXTEND32_(x, __FILE__, __LINE__)
130 static OPUS_INLINE
int EXTEND32_(int x
, char *file
, int line
)
133 if (!VERIFY_SHORT(x
))
135 fprintf (stderr
, "EXTEND32: input is not short: %d in %s: line %d\n", x
, file
, line
);
136 #ifdef FIXED_DEBUG_ASSERT
145 #define SHR16(a, shift) SHR16_(a, shift, __FILE__, __LINE__)
146 static OPUS_INLINE
short SHR16_(int a
, int shift
, char *file
, int line
)
149 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(shift
))
151 fprintf (stderr
, "SHR16: inputs are not short: %d >> %d in %s: line %d\n", a
, shift
, file
, line
);
152 #ifdef FIXED_DEBUG_ASSERT
157 if (!VERIFY_SHORT(res
))
159 fprintf (stderr
, "SHR16: output is not short: %d in %s: line %d\n", res
, file
, line
);
160 #ifdef FIXED_DEBUG_ASSERT
167 #define SHL16(a, shift) SHL16_(a, shift, __FILE__, __LINE__)
168 static OPUS_INLINE
short SHL16_(int a
, int shift
, char *file
, int line
)
171 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(shift
))
173 fprintf (stderr
, "SHL16: inputs are not short: %d %d in %s: line %d\n", a
, shift
, file
, line
);
174 #ifdef FIXED_DEBUG_ASSERT
178 res
= (opus_int32
)((opus_uint32
)a
<<shift
);
179 if (!VERIFY_SHORT(res
))
181 fprintf (stderr
, "SHL16: output is not short: %d in %s: line %d\n", res
, file
, line
);
182 #ifdef FIXED_DEBUG_ASSERT
190 static OPUS_INLINE
int SHR32(opus_int64 a
, int shift
)
193 if (!VERIFY_INT(a
) || !VERIFY_SHORT(shift
))
195 fprintf (stderr
, "SHR32: inputs are not int: %d %d\n", (int)a
, shift
);
196 #ifdef FIXED_DEBUG_ASSERT
201 if (!VERIFY_INT(res
))
203 fprintf (stderr
, "SHR32: output is not int: %d\n", (int)res
);
204 #ifdef FIXED_DEBUG_ASSERT
211 #define SHL32(a, shift) SHL32_(a, shift, __FILE__, __LINE__)
212 static OPUS_INLINE
int SHL32_(opus_int64 a
, int shift
, char *file
, int line
)
215 if (!VERIFY_INT(a
) || !VERIFY_SHORT(shift
))
217 fprintf (stderr
, "SHL32: inputs are not int: %lld %d in %s: line %d\n", (long long)a
, shift
, file
, line
);
218 #ifdef FIXED_DEBUG_ASSERT
222 res
= (opus_int64
)((opus_uint64
)a
<<shift
);
223 if (!VERIFY_INT(res
))
225 fprintf (stderr
, "SHL32: output is not int: %lld<<%d = %lld in %s: line %d\n", (long long)a
, shift
, (long long)res
, file
, line
);
226 #ifdef FIXED_DEBUG_ASSERT
234 #define PSHR32(a,shift) (celt_mips--,SHR32(ADD32((a),(((opus_val32)(1)<<((shift))>>1))),shift))
235 #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
237 #define ROUND16(x,a) (celt_mips--,EXTRACT16(PSHR32((x),(a))))
238 #define SROUND16(x,a) (celt_mips--,EXTRACT16(SATURATE(PSHR32(x,a), 32767)));
240 #define HALF16(x) (SHR16(x,1))
241 #define HALF32(x) (SHR32(x,1))
243 #define ADD16(a, b) ADD16_(a, b, __FILE__, __LINE__)
244 static OPUS_INLINE
short ADD16_(int a
, int b
, char *file
, int line
)
247 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
249 fprintf (stderr
, "ADD16: inputs are not short: %d %d in %s: line %d\n", a
, b
, file
, line
);
250 #ifdef FIXED_DEBUG_ASSERT
255 if (!VERIFY_SHORT(res
))
257 fprintf (stderr
, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a
,b
,res
, file
, line
);
258 #ifdef FIXED_DEBUG_ASSERT
266 #define SUB16(a, b) SUB16_(a, b, __FILE__, __LINE__)
267 static OPUS_INLINE
short SUB16_(int a
, int b
, char *file
, int line
)
270 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
272 fprintf (stderr
, "SUB16: inputs are not short: %d %d in %s: line %d\n", a
, b
, file
, line
);
273 #ifdef FIXED_DEBUG_ASSERT
278 if (!VERIFY_SHORT(res
))
280 fprintf (stderr
, "SUB16: output is not short: %d in %s: line %d\n", res
, file
, line
);
281 #ifdef FIXED_DEBUG_ASSERT
289 #define ADD32(a, b) ADD32_(a, b, __FILE__, __LINE__)
290 static OPUS_INLINE
int ADD32_(opus_int64 a
, opus_int64 b
, char *file
, int line
)
293 if (!VERIFY_INT(a
) || !VERIFY_INT(b
))
295 fprintf (stderr
, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
296 #ifdef FIXED_DEBUG_ASSERT
301 if (!VERIFY_INT(res
))
303 fprintf (stderr
, "ADD32: output is not int: %d in %s: line %d\n", (int)res
, file
, line
);
304 #ifdef FIXED_DEBUG_ASSERT
312 #define SUB32(a, b) SUB32_(a, b, __FILE__, __LINE__)
313 static OPUS_INLINE
int SUB32_(opus_int64 a
, opus_int64 b
, char *file
, int line
)
316 if (!VERIFY_INT(a
) || !VERIFY_INT(b
))
318 fprintf (stderr
, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
319 #ifdef FIXED_DEBUG_ASSERT
324 if (!VERIFY_INT(res
))
326 fprintf (stderr
, "SUB32: output is not int: %d in %s: line %d\n", (int)res
, file
, line
);
327 #ifdef FIXED_DEBUG_ASSERT
336 #define UADD32(a, b) UADD32_(a, b, __FILE__, __LINE__)
337 static OPUS_INLINE
unsigned int UADD32_(opus_uint64 a
, opus_uint64 b
, char *file
, int line
)
340 if (!VERIFY_UINT(a
) || !VERIFY_UINT(b
))
342 fprintf (stderr
, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\n", (unsigned long long)a
, (unsigned long long)b
, file
, line
);
343 #ifdef FIXED_DEBUG_ASSERT
348 if (!VERIFY_UINT(res
))
350 fprintf (stderr
, "UADD32: output is not uint32: %llu in %s: line %d\n", (unsigned long long)res
, file
, line
);
351 #ifdef FIXED_DEBUG_ASSERT
360 #define USUB32(a, b) USUB32_(a, b, __FILE__, __LINE__)
361 static OPUS_INLINE
unsigned int USUB32_(opus_uint64 a
, opus_uint64 b
, char *file
, int line
)
364 if (!VERIFY_UINT(a
) || !VERIFY_UINT(b
))
366 fprintf (stderr
, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\n", (unsigned long long)a
, (unsigned long long)b
, file
, line
);
367 #ifdef FIXED_DEBUG_ASSERT
373 fprintf (stderr
, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n", (unsigned long long)a
, (unsigned long long)b
, file
, line
);
374 #ifdef FIXED_DEBUG_ASSERT
379 if (!VERIFY_UINT(res
))
381 fprintf (stderr
, "USUB32: output is not uint32: %llu - %llu = %llu in %s: line %d\n", (unsigned long long)a
, (unsigned long long)b
, (unsigned long long)res
, file
, line
);
382 #ifdef FIXED_DEBUG_ASSERT
390 /* result fits in 16 bits */
391 static OPUS_INLINE
short MULT16_16_16(int a
, int b
)
394 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
396 fprintf (stderr
, "MULT16_16_16: inputs are not short: %d %d\n", a
, b
);
397 #ifdef FIXED_DEBUG_ASSERT
402 if (!VERIFY_SHORT(res
))
404 fprintf (stderr
, "MULT16_16_16: output is not short: %d\n", res
);
405 #ifdef FIXED_DEBUG_ASSERT
413 /* result fits in 32 bits */
414 static OPUS_INLINE
int MULT32_32_32(opus_int64 a
, opus_int64 b
)
417 if (!VERIFY_INT(a
) || !VERIFY_INT(b
))
419 fprintf (stderr
, "MULT32_32_32: inputs are not int: %lld %lld\n", (long long)a
, (long long)b
);
420 #ifdef FIXED_DEBUG_ASSERT
425 if (!VERIFY_INT(res
))
427 fprintf (stderr
, "MULT32_32_32: output is not int: %lld\n", (long long)res
);
428 #ifdef FIXED_DEBUG_ASSERT
436 static OPUS_INLINE
int MULT32_32_Q16(opus_int64 a
, opus_int64 b
)
439 if (!VERIFY_INT(a
) || !VERIFY_INT(b
))
441 fprintf (stderr
, "MULT32_32_Q16: inputs are not int: %lld %lld\n", (long long)a
, (long long)b
);
442 #ifdef FIXED_DEBUG_ASSERT
446 res
= ((opus_int64
)(a
)*(opus_int64
)(b
)) >> 16;
447 if (!VERIFY_INT(res
))
449 fprintf (stderr
, "MULT32_32_Q16: output is not int: %lld*%lld=%lld\n", (long long)a
, (long long)b
, (long long)res
);
450 #ifdef FIXED_DEBUG_ASSERT
458 #define MULT16_16(a, b) MULT16_16_(a, b, __FILE__, __LINE__)
459 static OPUS_INLINE
int MULT16_16_(int a
, int b
, char *file
, int line
)
462 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
464 fprintf (stderr
, "MULT16_16: inputs are not short: %d %d in %s: line %d\n", a
, b
, file
, line
);
465 #ifdef FIXED_DEBUG_ASSERT
469 res
= ((opus_int64
)a
)*b
;
470 if (!VERIFY_INT(res
))
472 fprintf (stderr
, "MULT16_16: output is not int: %d in %s: line %d\n", (int)res
, file
, line
);
473 #ifdef FIXED_DEBUG_ASSERT
481 #define MAC16_16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_16((a),(b))))
483 #define MULT16_32_QX(a, b, Q) MULT16_32_QX_(a, b, Q, __FILE__, __LINE__)
484 static OPUS_INLINE
int MULT16_32_QX_(int a
, opus_int64 b
, int Q
, char *file
, int line
)
487 if (!VERIFY_SHORT(a
) || !VERIFY_INT(b
))
489 fprintf (stderr
, "MULT16_32_Q%d: inputs are not short+int: %d %d in %s: line %d\n", Q
, (int)a
, (int)b
, file
, line
);
490 #ifdef FIXED_DEBUG_ASSERT
494 if (ABS32(b
)>=((opus_int64
)(1)<<(16+Q
)))
496 fprintf (stderr
, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q
, (int)a
, (int)b
, file
, line
);
497 #ifdef FIXED_DEBUG_ASSERT
501 res
= (((opus_int64
)a
)*(opus_int64
)b
) >> Q
;
502 if (!VERIFY_INT(res
))
504 fprintf (stderr
, "MULT16_32_Q%d: output is not int: %d*%d=%d in %s: line %d\n", Q
, (int)a
, (int)b
,(int)res
, file
, line
);
505 #ifdef FIXED_DEBUG_ASSERT
516 #define MULT16_32_PX(a, b, Q) MULT16_32_PX_(a, b, Q, __FILE__, __LINE__)
517 static OPUS_INLINE
int MULT16_32_PX_(int a
, opus_int64 b
, int Q
, char *file
, int line
)
520 if (!VERIFY_SHORT(a
) || !VERIFY_INT(b
))
522 fprintf (stderr
, "MULT16_32_P%d: inputs are not short+int: %d %d in %s: line %d\n\n", Q
, (int)a
, (int)b
, file
, line
);
523 #ifdef FIXED_DEBUG_ASSERT
527 if (ABS32(b
)>=((opus_int64
)(1)<<(16+Q
)))
529 fprintf (stderr
, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n\n", Q
, (int)a
, (int)b
,file
, line
);
530 #ifdef FIXED_DEBUG_ASSERT
534 res
= ((((opus_int64
)a
)*(opus_int64
)b
) + (((opus_val32
)(1)<<Q
)>>1))>> Q
;
535 if (!VERIFY_INT(res
))
537 fprintf (stderr
, "MULT16_32_P%d: output is not int: %d*%d=%d in %s: line %d\n\n", Q
, (int)a
, (int)b
,(int)res
, file
, line
);
538 #ifdef FIXED_DEBUG_ASSERT
549 #define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15)
550 #define MAC16_32_Q15(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q15((a),(b))))
551 #define MAC16_32_Q16(c,a,b) (celt_mips-=2,ADD32((c),MULT16_32_Q16((a),(b))))
553 static OPUS_INLINE
int SATURATE(int a
, int b
)
563 static OPUS_INLINE opus_int16
SATURATE16(opus_int32 a
)
573 static OPUS_INLINE
int MULT16_16_Q11_32(int a
, int b
)
576 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
578 fprintf (stderr
, "MULT16_16_Q11: inputs are not short: %d %d\n", a
, b
);
579 #ifdef FIXED_DEBUG_ASSERT
583 res
= ((opus_int64
)a
)*b
;
585 if (!VERIFY_INT(res
))
587 fprintf (stderr
, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a
, (int)b
, (int)res
);
588 #ifdef FIXED_DEBUG_ASSERT
595 static OPUS_INLINE
short MULT16_16_Q13(int a
, int b
)
598 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
600 fprintf (stderr
, "MULT16_16_Q13: inputs are not short: %d %d\n", a
, b
);
601 #ifdef FIXED_DEBUG_ASSERT
605 res
= ((opus_int64
)a
)*b
;
607 if (!VERIFY_SHORT(res
))
609 fprintf (stderr
, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a
, b
, (int)res
);
610 #ifdef FIXED_DEBUG_ASSERT
617 static OPUS_INLINE
short MULT16_16_Q14(int a
, int b
)
620 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
622 fprintf (stderr
, "MULT16_16_Q14: inputs are not short: %d %d\n", a
, b
);
623 #ifdef FIXED_DEBUG_ASSERT
627 res
= ((opus_int64
)a
)*b
;
629 if (!VERIFY_SHORT(res
))
631 fprintf (stderr
, "MULT16_16_Q14: output is not short: %d\n", (int)res
);
632 #ifdef FIXED_DEBUG_ASSERT
640 #define MULT16_16_Q15(a, b) MULT16_16_Q15_(a, b, __FILE__, __LINE__)
641 static OPUS_INLINE
short MULT16_16_Q15_(int a
, int b
, char *file
, int line
)
644 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
646 fprintf (stderr
, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a
, b
, file
, line
);
647 #ifdef FIXED_DEBUG_ASSERT
651 res
= ((opus_int64
)a
)*b
;
653 if (!VERIFY_SHORT(res
))
655 fprintf (stderr
, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res
, file
, line
);
656 #ifdef FIXED_DEBUG_ASSERT
664 static OPUS_INLINE
short MULT16_16_P13(int a
, int b
)
667 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
669 fprintf (stderr
, "MULT16_16_P13: inputs are not short: %d %d\n", a
, b
);
670 #ifdef FIXED_DEBUG_ASSERT
674 res
= ((opus_int64
)a
)*b
;
676 if (!VERIFY_INT(res
))
678 fprintf (stderr
, "MULT16_16_P13: overflow: %d*%d=%d\n", a
, b
, (int)res
);
679 #ifdef FIXED_DEBUG_ASSERT
684 if (!VERIFY_SHORT(res
))
686 fprintf (stderr
, "MULT16_16_P13: output is not short: %d*%d=%d\n", a
, b
, (int)res
);
687 #ifdef FIXED_DEBUG_ASSERT
694 static OPUS_INLINE
short MULT16_16_P14(int a
, int b
)
697 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
699 fprintf (stderr
, "MULT16_16_P14: inputs are not short: %d %d\n", a
, b
);
700 #ifdef FIXED_DEBUG_ASSERT
704 res
= ((opus_int64
)a
)*b
;
706 if (!VERIFY_INT(res
))
708 fprintf (stderr
, "MULT16_16_P14: overflow: %d*%d=%d\n", a
, b
, (int)res
);
709 #ifdef FIXED_DEBUG_ASSERT
714 if (!VERIFY_SHORT(res
))
716 fprintf (stderr
, "MULT16_16_P14: output is not short: %d*%d=%d\n", a
, b
, (int)res
);
717 #ifdef FIXED_DEBUG_ASSERT
724 static OPUS_INLINE
short MULT16_16_P15(int a
, int b
)
727 if (!VERIFY_SHORT(a
) || !VERIFY_SHORT(b
))
729 fprintf (stderr
, "MULT16_16_P15: inputs are not short: %d %d\n", a
, b
);
730 #ifdef FIXED_DEBUG_ASSERT
734 res
= ((opus_int64
)a
)*b
;
736 if (!VERIFY_INT(res
))
738 fprintf (stderr
, "MULT16_16_P15: overflow: %d*%d=%d\n", a
, b
, (int)res
);
739 #ifdef FIXED_DEBUG_ASSERT
744 if (!VERIFY_SHORT(res
))
746 fprintf (stderr
, "MULT16_16_P15: output is not short: %d*%d=%d\n", a
, b
, (int)res
);
747 #ifdef FIXED_DEBUG_ASSERT
755 #define DIV32_16(a, b) DIV32_16_(a, b, __FILE__, __LINE__)
757 static OPUS_INLINE
int DIV32_16_(opus_int64 a
, opus_int64 b
, char *file
, int line
)
762 fprintf(stderr
, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
763 #ifdef FIXED_DEBUG_ASSERT
768 if (!VERIFY_INT(a
) || !VERIFY_SHORT(b
))
770 fprintf (stderr
, "DIV32_16: inputs are not int/short: %d %d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
771 #ifdef FIXED_DEBUG_ASSERT
776 if (!VERIFY_SHORT(res
))
778 fprintf (stderr
, "DIV32_16: output is not short: %d / %d = %d in %s: line %d\n", (int)a
,(int)b
,(int)res
, file
, line
);
783 #ifdef FIXED_DEBUG_ASSERT
791 #define DIV32(a, b) DIV32_(a, b, __FILE__, __LINE__)
792 static OPUS_INLINE
int DIV32_(opus_int64 a
, opus_int64 b
, char *file
, int line
)
797 fprintf(stderr
, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
798 #ifdef FIXED_DEBUG_ASSERT
804 if (!VERIFY_INT(a
) || !VERIFY_INT(b
))
806 fprintf (stderr
, "DIV32: inputs are not int/short: %d %d in %s: line %d\n", (int)a
, (int)b
, file
, line
);
807 #ifdef FIXED_DEBUG_ASSERT
812 if (!VERIFY_INT(res
))
814 fprintf (stderr
, "DIV32: output is not int: %d in %s: line %d\n", (int)res
, file
, line
);
815 #ifdef FIXED_DEBUG_ASSERT
823 static OPUS_INLINE opus_val16
SIG2WORD16_generic(celt_sig x
)
825 x
= PSHR32(x
, SIG_SHIFT
);
826 x
= MAX32(x
, -32768);
830 #define SIG2WORD16(x) (SIG2WORD16_generic(x))
834 #define PRINT_MIPS(file) do {fprintf (file, "total complexity = %llu MIPS\n", (unsigned long long)celt_mips);} while (0);