diff --git a/libspeex/fixed_debug.h b/libspeex/fixed_debug.h index 756138b8..7ad61726 100644 --- a/libspeex/fixed_debug.h +++ b/libspeex/fixed_debug.h @@ -56,7 +56,13 @@ static inline short NEG16(int x) } res = -x; if (!VERIFY_SHORT(res)) - fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); + { + fprintf (stderr, "NEG16: output is not short: %d\n", (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -110,7 +116,13 @@ static inline short _SHR16(int a, int shift, char *file, int line) } res = a>>shift; if (!VERIFY_SHORT(res)) - fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line); + { + fprintf (stderr, "SHR16: output is not short: %d in %s: line %d\n", res, file, line); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -124,7 +136,13 @@ static inline short _SHL16(int a, int shift, char *file, int line) } res = (int)((unsigned)a< 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -181,7 +199,11 @@ static inline short _ADD16(int a, int b, char *file, int line) 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); + fprintf (stderr, "ADD16: output is not short: %d+%d=%d in %s: line %d\n", a,b,res, file, line); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; } spx_mips++; return res; @@ -197,7 +219,13 @@ static inline short _SUB16(int a, int b, char *file, int line) } res = a-b; if (!VERIFY_SHORT(res)) - fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line); + { + fprintf (stderr, "SUB16: output is not short: %d in %s: line %d\n", res, file, line); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -227,8 +255,14 @@ static inline int SUB32(long long a, long long b) fprintf (stderr, "SUB32: inputs are not int: %d %d\n", (int)a, (int)b); } res = a-b; - if (!VERIFY_INT(res)) - fprintf (stderr, "SUB32: output is not int: %d\n", (int)res); + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "SUB32: output is not int: %d\n", (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -245,7 +279,13 @@ static inline short MULT16_16_16(int a, int b) } res = a*b; if (!VERIFY_SHORT(res)) - fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res); + { + fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips++; return res; } @@ -329,8 +369,14 @@ static inline int MULT16_16_Q11_32(int a, int b) } 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); + if (!VERIFY_SHORT(res)) + { + fprintf (stderr, "MULT16_16_Q11: output is not short: %d*%d=%d\n", (int)a, (int)b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=3; return res; } @@ -344,7 +390,13 @@ static inline short MULT16_16_Q13(int a, int b) 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); + { + fprintf (stderr, "MULT16_16_Q13: output is not short: %d*%d=%d\n", a, b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=3; return res; } @@ -358,7 +410,13 @@ static inline short MULT16_16_Q14(int a, int b) res = ((long long)a)*b; res >>= 14; if (!VERIFY_SHORT(res)) - fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); + { + fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=3; return res; } @@ -373,7 +431,11 @@ static inline short MULT16_16_Q15(int a, int b) res >>= 15; if (!VERIFY_SHORT(res)) { - fprintf (stderr, "MULT16_16_Q15: output is not short: %d\n", (int)res); + fprintf(stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; } spx_mips+=3; return res; @@ -392,7 +454,13 @@ static inline short MULT16_16_P13(int a, int b) fprintf (stderr, "MULT16_16_P13: overflow: %d*%d=%d\n", a, b, (int)res); res >>= 13; if (!VERIFY_SHORT(res)) - fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res); + { + fprintf (stderr, "MULT16_16_P13: output is not short: %d*%d=%d\n", a, b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=4; return res; } @@ -409,7 +477,13 @@ static inline short MULT16_16_P14(int a, int b) fprintf (stderr, "MULT16_16_P14: overflow: %d*%d=%d\n", a, b, (int)res); res >>= 14; if (!VERIFY_SHORT(res)) - fprintf (stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); + { + fprintf(stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=4; return res; } @@ -426,7 +500,13 @@ static inline short MULT16_16_P15(int a, int b) fprintf (stderr, "MULT16_16_P15: overflow: %d*%d=%d\n", a, b, (int)res); res >>= 15; if (!VERIFY_SHORT(res)) - fprintf (stderr, "MULT16_16_P15: output is not short: %d*%d=%d\n", a, b, (int)res); + { + fprintf(stderr, "MULT16_16_P14: output is not short: %d*%d=%d\n", a, b, (int)res); + if (res > 32767) + res = 32767; + if (res < -32768) + res = -32768; + } spx_mips+=4; return res; }