[xiph-commits] r9176 - trunk/speex/libspeex

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Sat Apr 23 21:45:46 PDT 2005


Author: jm
Date: 2005-04-23 21:45:44 -0700 (Sat, 23 Apr 2005)
New Revision: 9176

Modified:
   trunk/speex/libspeex/cb_search.c
   trunk/speex/libspeex/fixed_debug.h
   trunk/speex/libspeex/lsp.c
   trunk/speex/libspeex/ltp.c
Log:
some cleaning up


Modified: trunk/speex/libspeex/cb_search.c
===================================================================
--- trunk/speex/libspeex/cb_search.c	2005-04-24 03:23:01 UTC (rev 9175)
+++ trunk/speex/libspeex/cb_search.c	2005-04-24 04:45:44 UTC (rev 9176)
@@ -61,16 +61,17 @@
       for(j=0;j<subvect_size;j++)
       {
          spx_word32_t resj=0;
+         spx_word16_t res16;
          for (k=0;k<=j;k++)
             resj = MAC16_16(resj,shape[k],r[j-k]);
 #ifdef FIXED_POINT
-         resj = SHR32(resj, 11);
+         res16 = EXTRACT16(SHR32(resj, 11));
 #else
-         resj *= 0.03125;
+         res16 = 0.03125f*resj;
 #endif
          /* Compute codeword energy */
-         E[i]=ADD32(E[i],MULT16_16(EXTRACT16(resj),EXTRACT16(resj)));
-         res[j] = resj;
+         E[i]=MAC16_16(E[i],res16,res16);
+         res[j] = res16;
          /*printf ("%d\n", (int)res[j]);*/
       }
    }

Modified: trunk/speex/libspeex/fixed_debug.h
===================================================================
--- trunk/speex/libspeex/fixed_debug.h	2005-04-24 03:23:01 UTC (rev 9175)
+++ trunk/speex/libspeex/fixed_debug.h	2005-04-24 04:45:44 UTC (rev 9176)
@@ -245,19 +245,32 @@
    return res;
 }
 
-#define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
+#define MAC16_16(c,a,b)     (spx_mips--,ADD32((c),MULT16_16((a),(b))))
 #define MAC16_16_Q11(c,a,b)     (ADD16((c),EXTRACT16(SHR32(MULT16_16((a),(b)),11))))
 #define MAC16_16_Q13(c,a,b)     (ADD16((c),EXTRACT16(SHR32(MULT16_16((a),(b)),13))))
 
-#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR32((b),12)), SHR32(MULT16_16((a),((b)&0x00000fff)),12))
-#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR32((b),13)), SHR32(MULT16_16((a),((b)&0x00001fff)),13))
-#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR32((b),14)), SHR32(MULT16_16((a),((b)&0x00003fff)),14))
+static inline int MULT16_32_QX(int a, long long b, int Q)
+{
+   long long res;
+   if (!VERIFY_SHORT(a) || !VERIFY_INT(b))
+   {
+      fprintf (stderr, "MULT16_32_Q%d: inputs are not short+int: %d %d\n", Q, a, b);
+   }
+   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\n", Q, a, b,(int)res);
+   spx_mips+=5;
+   return res;
+}
 
-#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR32((b),11)), SHR32(MULT16_16((a),((b)&0x000007ff)),11))
-#define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR32((b),11)), SHR32(MULT16_16((a),((b)&0x000007ff)),11)))
 
-#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR32((b),15)), SHR32(MULT16_16((a),((b)&0x00007fff)),15))
-#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR32((b),15)), SHR32(MULT16_16((a),((b)&0x00007fff)),15)))
+#define MULT16_32_Q11(a,b) MULT16_32_QX(a,b,11)
+#define MAC16_32_Q11(c,a,b) ADD32((c),MULT16_32_Q11((a),(b)))
+#define MULT16_32_Q12(a,b) MULT16_32_QX(a,b,12)
+#define MULT16_32_Q13(a,b) MULT16_32_QX(a,b,13)
+#define MULT16_32_Q14(a,b) MULT16_32_QX(a,b,14)
+#define MULT16_32_Q15(a,b) MULT16_32_QX(a,b,15)
+#define MAC16_32_Q15(c,a,b) ADD32((c),MULT16_32_Q15((a),(b)))
 
 static inline int SATURATE(int a, int b)
 {
@@ -377,9 +390,7 @@
    return res;
 }
 
-#define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
 
-
 static inline int DIV32_16(long long a, long long b) 
 {
    long long res;
@@ -401,7 +412,7 @@
       if (res<-32768)
          res = -32768;
    }
-   spx_mips++;
+   spx_mips+=20;
    return res;
 }
 static inline int DIV32(long long a, long long b) 
@@ -420,7 +431,7 @@
    res = a/b;
    if (!VERIFY_INT(res))
       fprintf (stderr, "DIV32: output is not int: %d\n", (int)res);
-   spx_mips++;
+   spx_mips+=36;
    return res;
 }
 

Modified: trunk/speex/libspeex/lsp.c
===================================================================
--- trunk/speex/libspeex/lsp.c	2005-04-24 03:23:01 UTC (rev 9175)
+++ trunk/speex/libspeex/lsp.c	2005-04-24 04:45:44 UTC (rev 9176)
@@ -287,27 +287,28 @@
           speex_warning_int("px", *px);
        if (fabs(*qx)>=32768)
        speex_warning_int("qx", *qx);*/
-       *px = (2+*px)>>2;
-       *qx = (2+*qx)>>2;
+       *px = PSHR32(*px,2);
+       *qx = PSHR32(*qx,2);
        px++;
        qx++;
     }
+    /* The reason for this lies in the way cheb_poly_eva() is implemented for fixed-point */
     P[m] = PSHR32(P[m],3);
     Q[m] = PSHR32(Q[m],3);
 #else
     *px++ = LPC_SCALING;
     *qx++ = LPC_SCALING;
     for(i=1;i<=m;i++){
-	*px++ = (a[i]+a[lpcrdr+1-i]) - *p++;
-	*qx++ = (a[i]-a[lpcrdr+1-i]) + *q++;
+       *px++ = (a[i]+a[lpcrdr+1-i]) - *p++;
+       *qx++ = (a[i]-a[lpcrdr+1-i]) + *q++;
     }
     px = P;
     qx = Q;
     for(i=0;i<m;i++){
-	*px = 2**px;
-	*qx = 2**qx;
-	 px++;
-	 qx++;
+       *px = 2**px;
+       *qx = 2**qx;
+       px++;
+       qx++;
     }
 #endif
 

Modified: trunk/speex/libspeex/ltp.c
===================================================================
--- trunk/speex/libspeex/ltp.c	2005-04-24 03:23:01 UTC (rev 9175)
+++ trunk/speex/libspeex/ltp.c	2005-04-24 04:45:44 UTC (rev 9176)
@@ -54,21 +54,23 @@
 
 static spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
 {
-   int i;
+   int i=0;
    spx_word32_t sum=0;
-   for (i=0;i<len;i+=4)
+   len >>= 2;
+   while(len--)
    {
       spx_word32_t part=0;
-      part = MAC16_16(part,x[i],y[i]);
-      part = MAC16_16(part,x[i+1],y[i+1]);
-      part = MAC16_16(part,x[i+2],y[i+2]);
-      part = MAC16_16(part,x[i+3],y[i+3]);
+      part = MAC16_16(part,*x++,*y++);
+      part = MAC16_16(part,*x++,*y++);
+      part = MAC16_16(part,*x++,*y++);
+      part = MAC16_16(part,*x++,*y++);
+      /* HINT: If you had a 40-bit accumulator, you could shift only at the end */
       sum = ADD32(sum,SHR32(part,6));
    }
    return sum;
 }
 
-#if 0 /* Enable this for machines with enough registers (i.e. not x86) */
+#if 0 /* HINT: Enable this for machines with enough registers (i.e. not x86) */
 static void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
 {
    int i,j;



More information about the commits mailing list