[xiph-cvs] cvs commit: speex/libspeex filters.c ltp.c misc.h vq.c

Jean-Marc Valin jm at xiph.org
Mon Nov 10 16:19:47 PST 2003



jm          03/11/10 19:19:46

  Modified:    libspeex filters.c ltp.c misc.h vq.c
  Log:
  fixed-point: Defined fused multiply-add operators and some ARM assembly to
  use it.

Revision  Changes    Path
1.60      +8 -6      speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- filters.c	10 Nov 2003 19:38:24 -0000	1.59
+++ filters.c	11 Nov 2003 00:19:46 -0000	1.60
@@ -189,17 +189,18 @@
 void filter_mem2(spx_sig_t *x, spx_coef_t *num, spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
 {
    int i,j;
-   int xi,yi;
+   spx_sig_t xi,yi,nyi;
 
    for (i=0;i<N;i++)
    {
       int xh,xl,yh,yl;
       xi=x[i];
       yi = xi + (mem[0]<<2);
+      nyi = -yi;
       xh = xi>>15; xl=xi&0x00007fff; yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = SUB32(ADD32(mem[j+1],  MULT16_32_Q15(num[j+1],xi)), MULT16_32_Q15(den[j+1],yi));
+         mem[j] = MAC16_32_Q15(MAC16_32_Q15(mem[j+1], num[j+1],xi), den[j+1],nyi);
       }
       mem[ord-1] = SUB32(MULT16_32_Q15(num[ord],xi), MULT16_32_Q15(den[ord],yi));
       y[i] = yi;
@@ -209,17 +210,18 @@
 void iir_mem2(spx_sig_t *x, spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
 {
    int i,j;
-   int xi,yi;
+   spx_word32_t xi,yi,nyi;
 
    for (i=0;i<N;i++)
    {
       int yh,yl;
       xi=x[i];
       yi = xi + (mem[0]<<2);
+      nyi = -yi;
       yh = yi>>15; yl=yi&0x00007fff; 
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = SUB32(mem[j+1], MULT16_32_Q15(den[j+1],yi));
+         mem[j] = MAC16_32_Q15(mem[j+1],den[j+1],nyi);
       }
       mem[ord-1] = - MULT16_32_Q15(den[ord],yi);
       y[i] = yi;
@@ -230,7 +232,7 @@
 void fir_mem2(spx_sig_t *x, spx_coef_t *num, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
 {
    int i,j;
-   int xi,yi;
+   spx_word32_t xi,yi;
 
    for (i=0;i<N;i++)
    {
@@ -240,7 +242,7 @@
       xh = xi>>15; xl=xi&0x00007fff;
       for (j=0;j<ord-1;j++)
       {
-         mem[j] = ADD32(mem[j+1], MULT16_32_Q15(num[j+1],xi));
+         mem[j] = MAC16_32_Q15(mem[j+1], num[j+1],xi);
       }
       mem[ord-1] = MULT16_32_Q15(num[ord],xi);
       y[i] = yi;

<p><p>1.96      +4 -4      speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.95
retrieving revision 1.96
diff -u -r1.95 -r1.96
--- ltp.c	10 Nov 2003 19:28:20 -0000	1.95
+++ ltp.c	11 Nov 2003 00:19:46 -0000	1.96
@@ -48,10 +48,10 @@
    for (i=0;i<len;i+=4)
    {
       spx_word32_t part=0;
-      part = ADD32(part,MULT16_16(x[i],y[i]));
-      part = ADD32(part,MULT16_16(x[i+1],y[i+1]));
-      part = ADD32(part,MULT16_16(x[i+2],y[i+2]));
-      part = ADD32(part,MULT16_16(x[i+3],y[i+3]));
+      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]);
       sum = ADD32(sum,SHR(part,6));
    }
    return sum;

<p><p>1.45      +27 -0     speex/libspeex/misc.h

Index: misc.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- misc.h	10 Nov 2003 19:28:20 -0000	1.44
+++ misc.h	11 Nov 2003 00:19:46 -0000	1.45
@@ -111,6 +111,22 @@
 
 #endif
 
+#ifdef ARM_ASM
+
+static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
+  int res;
+  asm volatile("smlabb  %0,%1,%2,%3;\n"
+              : "=&r"(res)
+               : "%r"(x),"r"(y),"r"(a));
+  return(res);
+}
+
+#else
+
+#define MAC16_16(c,a,b)     (ADD32((c),MULT16_16((a),(b))))
+
+#endif
+
 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),11))
 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
@@ -124,9 +140,17 @@
                : "%r"(y<<1),"r"(x));
   return(res);
 }
+static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) {
+  int res;
+  asm volatile("smlawb  %0,%1,%2,%3;\n"
+              : "=&r"(res)
+               : "%r"(y<<1),"r"(x),"r"(a));
+  return(res);
+}
 
 #else
 #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
+#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
 #endif
 
 
@@ -171,12 +195,15 @@
 #define ADD64(a,b) ((a)+(b))
 #define MULT16_16_16(a,b)     ((a)*(b))
 #define MULT16_16(a,b)     ((a)*(b))
+#define MAC16_16(c,a,b)     ((c)+(a)*(b))
 
 #define MULT16_32_Q11(a,b)     ((a)*(b))
 #define MULT16_32_Q13(a,b)     ((a)*(b))
 #define MULT16_32_Q14(a,b)     ((a)*(b))
 #define MULT16_32_Q15(a,b)     ((a)*(b))
 
+#define MAC16_32_Q15(c,a,b)     ((c)+(a)*(b))
+
 #define MULT16_16_Q13(a,b)     ((a)*(b))
 #define MULT16_16_Q14(a,b)     ((a)*(b))
 #define MULT16_16_Q15(a,b)     ((a)*(b))

<p><p>1.13      +8 -7      speex/libspeex/vq.c

Index: vq.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vq.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- vq.c	2 Nov 2003 06:59:48 -0000	1.12
+++ vq.c	11 Nov 2003 00:19:46 -0000	1.13
@@ -63,13 +63,14 @@
    used = 0;
    for (i=0;i<entries;i++)
    {
+      spx_word32_t dist=0;
+      for (j=0;j<len;j++)
+         dist = MAC16_16(dist,in[j],*codebook++);
 #ifdef FIXED_POINT
-      spx_word32_t dist=SHR(E[i],1);
+      dist=SUB32(SHR(E[i],1),dist);
 #else
-      spx_word32_t dist=.5*E[i];
+      dist=.5*E[i]-dist;
 #endif
-      for (j=0;j<len;j++)
-         dist = SUB32(dist,MULT16_16(in[j],*codebook++));
       if (i<N || dist<best_dist[N-1])
       {
          for (k=N-1; (k >= 1) && (k > used || dist < best_dist[k-1]); k--)
@@ -93,14 +94,14 @@
    {
       spx_word32_t dist=0;
       for (j=0;j<len;j++)
-         dist = SUB32(dist,MULT16_16(in[j],*codebook++));
+         dist = MAC16_16(dist,in[j],*codebook++);
       if (dist>0)
       {
-         sign=1;
+         sign=0;
          dist=-dist;
       } else
       {
-         sign=0;
+         sign=1;
       }
 #ifdef FIXED_POINT
       dist = ADD32(dist,SHR(E[i],1));

<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