summaryrefslogtreecommitdiff
path: root/celt/fixed_debug.h
diff options
context:
space:
mode:
authorGregory Maxwell <greg@xiph.org>2012-05-13 11:10:58 -0400
committerJean-Marc Valin <jmvalin@jmvalin.ca>2012-05-15 09:18:06 -0400
commit4ea14918f4282f8c5a4429883a5c48927034c543 (patch)
tree6821c9eedb7ac0ccdc055c6b7f134f83b5014f24 /celt/fixed_debug.h
parent6ae5101fb43846dea3ae6613d6f8ce04e5294572 (diff)
downloadopus-4ea14918f4282f8c5a4429883a5c48927034c543.tar.gz
When FIXED_DEBUG_ASSERT CELT will assert on fixed-debug error.
Diffstat (limited to 'celt/fixed_debug.h')
-rw-r--r--celt/fixed_debug.h213
1 files changed, 212 insertions, 1 deletions
diff --git a/celt/fixed_debug.h b/celt/fixed_debug.h
index 3c6b5e0c..89b3cf72 100644
--- a/celt/fixed_debug.h
+++ b/celt/fixed_debug.h
@@ -1,5 +1,5 @@
/* Copyright (C) 2003-2008 Jean-Marc Valin
- Copyright (C) 2007-2009 Xiph.Org Foundation */
+ Copyright (C) 2007-2012 Xiph.Org Foundation */
/**
@file fixed_debug.h
@brief Fixed-point operations with debugging
@@ -63,10 +63,18 @@ static inline short NEG16(int x)
if (!VERIFY_SHORT(x))
{
fprintf (stderr, "NEG16: input is not short: %d\n", (int)x);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = -x;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "NEG16: output is not short: %d\n", (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -76,10 +84,18 @@ static inline int NEG32(long long x)
if (!VERIFY_INT(x))
{
fprintf (stderr, "NEG16: input is not int: %d\n", (int)x);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = -x;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "NEG16: output is not int: %d\n", (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=2;
return res;
}
@@ -91,6 +107,9 @@ static inline short EXTRACT16_(int x, char *file, int line)
if (!VERIFY_SHORT(x))
{
fprintf (stderr, "EXTRACT16: input is not short: %d in %s: line %d\n", x, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = x;
celt_mips++;
@@ -104,6 +123,9 @@ static inline int EXTEND32_(int x, char *file, int line)
if (!VERIFY_SHORT(x))
{
fprintf (stderr, "EXTEND32: input is not short: %d in %s: line %d\n", x, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = x;
celt_mips++;
@@ -117,10 +139,18 @@ static inline short SHR16_(int a, int shift, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift))
{
fprintf (stderr, "SHR16: inputs are not short: %d >> %d in %s: line %d\n", a, shift, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a>>shift;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -131,10 +161,18 @@ static inline short SHL16_(int a, int shift, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(shift))
{
fprintf (stderr, "SHL16: inputs are not short: %d %d in %s: line %d\n", a, shift, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a<<shift;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "SHL16: output is not short: %d in %s: line %d\n", res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -145,11 +183,17 @@ static inline int SHR32(long long a, int shift)
if (!VERIFY_INT(a) || !VERIFY_SHORT(shift))
{
fprintf (stderr, "SHR32: inputs are not int: %d %d\n", (int)a, shift);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a>>shift;
if (!VERIFY_INT(res))
{
fprintf (stderr, "SHR32: output is not int: %d\n", (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=2;
return res;
@@ -161,11 +205,17 @@ static inline int SHL32_(long long a, int shift, char *file, int line)
if (!VERIFY_INT(a) || !VERIFY_SHORT(shift))
{
fprintf (stderr, "SHL32: inputs are not int: %lld %d in %s: line %d\n", a, shift, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a<<shift;
if (!VERIFY_INT(res))
{
fprintf (stderr, "SHL32: output is not int: %lld<<%d = %lld in %s: line %d\n", a, shift, res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=2;
return res;
@@ -188,11 +238,17 @@ static inline short ADD16_(int a, int b, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "ADD16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a+b;
if (!VERIFY_SHORT(res))
{
fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a,b,res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips++;
return res;
@@ -205,10 +261,18 @@ static inline short SUB16_(int a, int b, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "SUB16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a-b;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -220,11 +284,17 @@ static inline int ADD32_(long long a, long long b, char *file, int line)
if (!VERIFY_INT(a) || !VERIFY_INT(b))
{
fprintf (stderr, "ADD32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a+b;
if (!VERIFY_INT(res))
{
fprintf (stderr, "ADD32: output is not int: %d in %s: line %d\n", (int)res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=2;
return res;
@@ -237,10 +307,18 @@ static inline int SUB32_(long long a, long long b, char *file, int line)
if (!VERIFY_INT(a) || !VERIFY_INT(b))
{
fprintf (stderr, "SUB32: inputs are not int: %d %d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a-b;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "SUB32: output is not int: %d in %s: line %d\n", (int)res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=2;
return res;
}
@@ -253,11 +331,17 @@ static inline unsigned int UADD32_(unsigned long long a, unsigned long long b, c
if (!VERIFY_UINT(a) || !VERIFY_UINT(b))
{
fprintf (stderr, "UADD32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a+b;
if (!VERIFY_UINT(res))
{
fprintf (stderr, "UADD32: output is not uint32: %llu in %s: line %d\n", res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=2;
return res;
@@ -271,15 +355,24 @@ static inline unsigned int USUB32_(unsigned long long a, unsigned long long b, c
if (!VERIFY_UINT(a) || !VERIFY_UINT(b))
{
fprintf (stderr, "USUB32: inputs are not uint32: %llu %llu in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
if (a<b)
{
fprintf (stderr, "USUB32: inputs underflow: %llu < %llu in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a-b;
if (!VERIFY_UINT(res))
{
fprintf (stderr, "USUB32: output is not uint32: %llu - %llu = %llu in %s: line %d\n", a, b, res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=2;
return res;
@@ -292,10 +385,18 @@ static inline short MULT16_16_16(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_16: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a*b;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -307,10 +408,18 @@ static inline int MULT16_16_(int a, int b, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "MULT16_16: output is not int: %d in %s: line %d\n", (int)res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips++;
return res;
}
@@ -324,12 +433,25 @@ static inline int MULT16_32_QX_(int a, long long b, int Q, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_INT(b))
{
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);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
if (ABS32(b)>=((opus_val32)(1)<<(15+Q)))
+ {
fprintf (stderr, "MULT16_32_Q%d: second operand too large: %d %d in %s: line %d\n", Q, (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
res = (((long long)a)*(long long)b) >> Q;
if (!VERIFY_INT(res))
+ {
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);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
if (Q==15)
celt_mips+=3;
else
@@ -356,11 +478,19 @@ static inline int MULT16_16_Q11_32(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_Q11: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res >>= 11;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a, (int)b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=3;
return res;
}
@@ -370,11 +500,19 @@ static inline short MULT16_16_Q13(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res >>= 13;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=3;
return res;
}
@@ -384,11 +522,19 @@ static inline short MULT16_16_Q14(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res >>= 14;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=3;
return res;
}
@@ -400,12 +546,18 @@ static inline short MULT16_16_Q15_(int a, int b, char *file, int line)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d in %s: line %d\n", a, b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res >>= 15;
if (!VERIFY_SHORT(res))
{
fprintf (stderr, "MULT16_16_Q15: output is not short: %d in %s: line %d\n", (int)res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=1;
return res;
@@ -417,14 +569,27 @@ static inline short MULT16_16_P13(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_P13: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res += 4096;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
res >>= 13;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=4;
return res;
}
@@ -434,14 +599,27 @@ static inline short MULT16_16_P14(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_P14: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res += 8192;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
res >>= 14;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=4;
return res;
}
@@ -451,14 +629,27 @@ static inline short MULT16_16_P15(int a, int b)
if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "MULT16_16_P15: inputs are not short: %d %d\n", a, b);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = ((long long)a)*b;
res += 16384;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "MULT16_16_P15: overflow: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
res >>= 15;
if (!VERIFY_SHORT(res))
+ {
fprintf (stderr, "MULT16_16_P15: output is not short: %d*%d=%d\n", a, b, (int)res);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=2;
return res;
}
@@ -471,11 +662,17 @@ static inline int DIV32_16_(long long a, long long b, char *file, int line)
if (b==0)
{
fprintf(stderr, "DIV32_16: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
return 0;
}
if (!VERIFY_INT(a) || !VERIFY_SHORT(b))
{
fprintf (stderr, "DIV32_16: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a/b;
if (!VERIFY_SHORT(res))
@@ -485,6 +682,9 @@ static inline int DIV32_16_(long long a, long long b, char *file, int line)
res = 32767;
if (res<-32768)
res = -32768;
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
celt_mips+=35;
return res;
@@ -497,16 +697,27 @@ static inline int DIV32_(long long a, long long b, char *file, int line)
if (b==0)
{
fprintf(stderr, "DIV32: divide by zero: %d/%d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
return 0;
}
if (!VERIFY_INT(a) || !VERIFY_INT(b))
{
fprintf (stderr, "DIV32: inputs are not int/short: %d %d in %s: line %d\n", (int)a, (int)b, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
}
res = a/b;
if (!VERIFY_INT(res))
+ {
fprintf (stderr, "DIV32: output is not int: %d in %s: line %d\n", (int)res, file, line);
+#ifdef FIXED_DEBUG_ASSERT
+ celt_assert(0);
+#endif
+ }
celt_mips+=70;
return res;
}