[xiph-cvs] cvs commit: speex/libspeex fixed_debug.h lsp.c testenc.c testenc_uwb.c testenc_wb.c

Jean-Marc Valin jm at xiph.org
Fri Nov 28 23:38:24 PST 2003



jm          03/11/29 02:38:24

  Modified:    libspeex fixed_debug.h lsp.c testenc.c testenc_uwb.c
                        testenc_wb.c
  Log:
  debug code for fixed-point operators. Already fixed an overflow in lsp code

Revision  Changes    Path
1.2       +128 -13   speex/libspeex/fixed_debug.h

Index: fixed_debug.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/fixed_debug.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fixed_debug.h	29 Nov 2003 07:03:58 -0000	1.1
+++ fixed_debug.h	29 Nov 2003 07:38:24 -0000	1.2
@@ -35,28 +35,104 @@
 #ifndef FIXED_DEBUG_H
 #define FIXED_DEBUG_H
 
-#ifdef FIXED_DEBUG
+#include <stdio.h>
+
 extern long long spx_mips;
 #define MIPS_INC spx_mips++,
-#else
-#define MIPS_INC
-#endif
+
+#define VERIFY_SHORT(x) ((x)<=32767&&(x)>=-32768)
+#define VERIFY_INT(x) ((x)<=2147483647LL&&(x)>=-2147483648LL)
 
 #define SHR(a,shift) ((a) >> (shift))
 #define SHL(a,shift) ((a) << (shift))
 
+static inline short ADD16(int a, int b) 
+{
+   int res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "ADD16: inputs are not short: %d %d\n", a, b);
+   }
+   res = a+b;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "ADD16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+static inline short SUB16(int a, int b) 
+{
+   int res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "SUB16: inputs are not short: %d %d\n", a, b);
+   }
+   res = a-b;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "SUB16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+static inline int ADD32(long long a, long long b) 
+{
+   long long res;
+   if (!VERIFY_INT(a) || !VERIFY_INT(b))
+   {
+      fprintf (stderr, "ADD32: inputs are not int: %d %d\n", a, b);
+   }
+   res = a+b;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "ADD32: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+static inline int SUB32(long long a, long long b) 
+{
+   long long res;
+   if (!VERIFY_INT(a) || !VERIFY_INT(b))
+   {
+      fprintf (stderr, "SUB32: inputs are not int: %d %d\n", a, b);
+   }
+   res = a-b;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "SUB32: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
 
-#define ADD16(a,b) (MIPS_INC(short)((short)(a)+(short)(b)))
-#define SUB16(a,b) (MIPS_INC(a)-(b))
-#define ADD32(a,b) (MIPS_INC(a)+(b))
-#define SUB32(a,b) (MIPS_INC(a)-(b))
 #define ADD64(a,b) (MIPS_INC(a)+(b))
 
 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
 
 /* result fits in 16 bits */
-#define MULT16_16_16(a,b)     (MIPS_INC(short)(((short)(a))*((short)(b))))
-#define MULT16_16(a,b)     (MIPS_INC((short)(a))*((short)(b)))
+static inline short MULT16_16_16(int a, int b) 
+{
+   int res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "MULT16_16_16: inputs are not short: %d %d\n", a, b);
+   }
+   res = a*b;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "MULT16_16_16: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+
+static inline int MULT16_16(int a, int b) 
+{
+   long long res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "MULT16_16: inputs are not short: %d %d\n", a, b);
+   }
+   res = ((long long)a)*b;
+   if (!VERIFY_INT(res))
+      fprintf (stderr, "MULT16_16: output is not int: %d\n", res);
+   spx_mips++;
+   return res;
+}
 
 #define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
 
@@ -71,9 +147,48 @@
 #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
 
 
-#define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
-#define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
-#define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
+static inline short MULT16_16_Q13(int a, int b) 
+{
+   long long res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "MULT16_16_Q13: inputs are not short: %d %d\n", a, 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, res);
+   spx_mips++;
+   return res;
+}
+static inline short MULT16_16_Q14(int a, int b) 
+{
+   long long res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "MULT16_16_Q14: inputs are not short: %d %d\n", a, b);
+   }
+   res = ((long long)a)*b;
+   res >>= 14;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "MULT16_16_Q14: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
+static inline short MULT16_16_Q15(int a, int b) 
+{
+   long long res;
+   if (!VERIFY_SHORT(a) || !VERIFY_SHORT(b))
+   {
+      fprintf (stderr, "MULT16_16_Q15: inputs are not short: %d %d\n", a, b);
+   }
+   res = ((long long)a)*b;
+   res >>= 15;
+   if (!VERIFY_SHORT(res))
+      fprintf (stderr, "MULT16_16_Q15: output is not short: %d\n", res);
+   spx_mips++;
+   return res;
+}
 
 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))

<p><p>1.48      +4 -0      speex/libspeex/lsp.c

Index: lsp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/lsp.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- lsp.c	27 Nov 2003 08:42:06 -0000	1.47
+++ lsp.c	29 Nov 2003 07:38:24 -0000	1.48
@@ -125,6 +125,10 @@
     int m2=m>>1;
     spx_word16_t *coefn;
 
+    /*Prevents overflows*/
+    if (x>16383)
+       x = 16383;
+
     /* Allocate memory for Chebyshev series formulation */
     T=PUSH(stack, m2+1, spx_word16_t);
     coefn=PUSH(stack, m2+1, spx_word16_t);

<p><p>1.56      +1 -1      speex/libspeex/testenc.c

Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- testenc.c	29 Nov 2003 07:03:58 -0000	1.55
+++ testenc.c	29 Nov 2003 07:38:24 -0000	1.56
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include "speex_callbacks.h"
 
-#ifdef COUNT_MIPS
+#ifdef FIXED_DEBUG
 extern long long spx_mips;
 #endif
 

<p><p>1.7       +1 -1      speex/libspeex/testenc_uwb.c

Index: testenc_uwb.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc_uwb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- testenc_uwb.c	29 Nov 2003 07:03:58 -0000	1.6
+++ testenc_uwb.c	29 Nov 2003 07:38:24 -0000	1.7
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include "speex_callbacks.h"
 
-#ifdef COUNT_MIPS
+#ifdef FIXED_DEBUG
 extern long long spx_mips;
 #endif
 

<p><p>1.37      +1 -1      speex/libspeex/testenc_wb.c

Index: testenc_wb.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc_wb.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- testenc_wb.c	29 Nov 2003 07:03:58 -0000	1.36
+++ testenc_wb.c	29 Nov 2003 07:38:24 -0000	1.37
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include "speex_callbacks.h"
 
-#ifdef COUNT_MIPS
+#ifdef FIXED_DEBUG
 extern long long spx_mips;
 #endif
 

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list