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

jm at svn.xiph.org jm at svn.xiph.org
Wed Jun 7 02:27:35 PDT 2006


Author: jm
Date: 2006-06-07 02:27:32 -0700 (Wed, 07 Jun 2006)
New Revision: 11533

Added:
   trunk/speex/libspeex/quant_lsp_bfin.h
Modified:
   trunk/speex/libspeex/Makefile.am
   trunk/speex/libspeex/quant_lsp.c
Log:
LSP quantization: minor C optimisation and hooks for Blackfin assembly


Modified: trunk/speex/libspeex/Makefile.am
===================================================================
--- trunk/speex/libspeex/Makefile.am	2006-06-07 08:52:59 UTC (rev 11532)
+++ trunk/speex/libspeex/Makefile.am	2006-06-07 09:27:32 UTC (rev 11533)
@@ -24,7 +24,7 @@
 				ltp_bfin.h 	filters_sse.h 	filters_arm4.h 	filters_bfin.h 	math_approx.h \
 				smallft.h 	arch.h 	fixed_arm4.h 	fixed_arm5e.h 	fixed_bfin.h 	fixed_debug.h \
 				fixed_generic.h 	cb_search_sse.h 	cb_search_arm4.h 	cb_search_bfin.h vorbis_psy.h \
-		fftwrap.h pseudofloat.h lsp_bfin.h
+		fftwrap.h pseudofloat.h lsp_bfin.h quant_lsp_bfin.h
 
 
 libspeex_la_LDFLAGS = -no-undefined -version-info @SPEEX_LT_CURRENT@:@SPEEX_LT_REVISION@:@SPEEX_LT_AGE@

Modified: trunk/speex/libspeex/quant_lsp.c
===================================================================
--- trunk/speex/libspeex/quant_lsp.c	2006-06-07 08:52:59 UTC (rev 11532)
+++ trunk/speex/libspeex/quant_lsp.c	2006-06-07 09:27:32 UTC (rev 11533)
@@ -40,9 +40,12 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-
 #include "misc.h"
 
+#ifdef BFIN_ASM
+#include "quant_lsp_bfin.h"
+#endif
+
 #ifdef FIXED_POINT
 
 #define LSP_LINEAR(i) (SHL16(i+1,11))
@@ -90,12 +93,13 @@
 }
 
 /* Note: x is modified*/
+#ifndef OVERRIDE_LSP_QUANT
 static int lsp_quant(spx_word16_t *x, const signed char *cdbk, int nbVec, int nbDim)
 {
    int i,j;
    spx_word32_t dist;
    spx_word16_t tmp;
-   spx_word32_t best_dist=0;
+   spx_word32_t best_dist=VERY_LARGE32;
    int best_id=0;
    const signed char *ptr=cdbk;
    for (i=0;i<nbVec;i++)
@@ -105,8 +109,8 @@
       {
          tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
          dist=MAC16_16(dist,tmp,tmp);
-      }
-      if (dist<best_dist || i==0)
+      } 
+      if (dist<best_dist)
       {
          best_dist=dist;
          best_id=i;
@@ -118,14 +122,16 @@
     
    return best_id;
 }
+#endif
 
 /* Note: x is modified*/
+#ifndef OVERRIDE_LSP_WEIGHT_QUANT
 static int lsp_weight_quant(spx_word16_t *x, spx_word16_t *weight, const signed char *cdbk, int nbVec, int nbDim)
 {
    int i,j;
    spx_word32_t dist;
    spx_word16_t tmp;
-   spx_word32_t best_dist=0;
+   spx_word32_t best_dist=VERY_LARGE32;
    int best_id=0;
    const signed char *ptr=cdbk;
    for (i=0;i<nbVec;i++)
@@ -136,7 +142,7 @@
          tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5));
          dist=MAC16_32_Q15(dist,weight[j],MULT16_16(tmp,tmp));
       }
-      if (dist<best_dist || i==0)
+      if (dist<best_dist)
       {
          best_dist=dist;
          best_id=i;
@@ -147,8 +153,8 @@
       x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
    return best_id;
 }
+#endif
 
-
 void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
 {
    int i;

Added: trunk/speex/libspeex/quant_lsp_bfin.h
===================================================================
--- trunk/speex/libspeex/quant_lsp_bfin.h	2006-06-07 08:52:59 UTC (rev 11532)
+++ trunk/speex/libspeex/quant_lsp_bfin.h	2006-06-07 09:27:32 UTC (rev 11533)
@@ -0,0 +1,165 @@
+/* Copyright (C) 2006 David Rowe */
+/**
+   @file quant_lsp_bfin.h
+   @author David Rowe
+   @brief Various compatibility routines for Speex (Blackfin version)
+*/
+/*
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+   
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+   
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+   
+   - Neither the name of the Xiph.org Foundation nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+   
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define OVERRIDE_LSP_QUANT
+#ifdef OVERRIDE_LSP_QUANT
+
+/*
+  Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
+  well tell you all the magic resgister constraints used below
+  for gcc in-line asm.
+*/
+
+static int lsp_quant(
+  spx_word16_t      *x, 
+  const signed char *cdbk, 
+  int                nbVec, 
+  int                nbDim
+)
+{
+   int          j;
+   spx_word32_t best_dist=1<<30;
+   int          best_id=0;
+
+   __asm__ __volatile__
+     (
+"	%0 = 1 (X);\n\t"                       /* %0: best_dist */    
+"	%0 <<= 30;\n\t"     
+"	%1 = 0 (X);\n\t"                       /* %1: best_i         */
+"       P2 = %3\n\t"                           /* P2: ptr to cdbk    */
+"       R5 = 0;\n\t"                           /* R5: best cb entry  */
+
+"       R0 = %5;\n\t"                          /* set up circ addr   */
+"       R0 <<= 1;\n\t"
+"       L0 = R0;\n\t"                          
+"       I0 = %2;\n\t"                          /* %2: &x[0]          */
+"       B0 = %2;\n\t"                          
+
+"       R2.L = W [I0++];\n\t"
+"	LSETUP (lq1, lq2) LC0 = %4;\n\t"
+"lq1:	  R3 = 0;\n\t"                         /* R3: dist           */
+"	  LSETUP (lq3, lq4) LC1 = %5;\n\t"
+"lq3:       R1 = B [P2++] (X);\n\t"            
+"	    R1 <<= 5;\n\t"
+"	    R0.L = R2.L - R1.L || R2.L = W [I0++];\n\t"
+"	    R0 = R0.L*R0.L;\n\t"
+"lq4:	    R3 = R3 + R0;\n\t"
+
+"	  cc =R3<%0;\n\t"
+"	  if cc %0=R3;\n\t"
+"	  if cc %1=R5;\n\t"
+"lq2:     R5 += 1;\n\t"
+"         L0 = 0;\n\t"
+   : "=&d" (best_dist), "=&d" (best_id)
+   : "a" (x), "b" (cdbk), "a" (nbVec), "a" (nbDim)
+   : "I0", "P2", "R0", "R1", "R2", "R3", "R5", "L0", "B0", "A0"
+   );
+
+   for (j=0;j<nbDim;j++) {
+      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
+   }
+   return best_id;
+}
+#endif
+
+#define OVERRIDE_LSP_WEIGHT_QUANT
+#ifdef OVERRIDE_LSP_WEIGHT_QUANT
+
+/*
+  Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
+  well tell you all the magic resgister constraints used below
+  for gcc in-line asm.
+*/
+
+static int lsp_weight_quant(
+  spx_word16_t      *x, 
+  spx_word16_t      *weight, 
+  const signed char *cdbk, 
+  int                nbVec, 
+  int                nbDim
+)
+{
+   int          j;
+   spx_word32_t best_dist=1<<30;
+   int          best_id=0;
+
+   __asm__ __volatile__
+     (
+"	%0 = 1 (X);\n\t"                       /* %0: best_dist */    
+"	%0 <<= 30;\n\t"     
+"	%1 = 0 (X);\n\t"                       /* %1: best_i         */
+"       P2 = %4\n\t"                           /* P2: ptr to cdbk    */
+"       R5 = 0;\n\t"                           /* R5: best cb entry  */
+
+"       R0 = %6;\n\t"                          /* set up circ addr   */
+"       R0 <<= 1;\n\t"
+"       L0 = R0;\n\t"                          
+"       L1 = R0;\n\t"
+"       I0 = %2;\n\t"                          /* %2: &x[0]          */
+"	I1 = %3;\n\t"                          /* %3: &weight[0]     */
+"       B0 = %2;\n\t"                          
+"	B1 = %3;\n\t"                          
+
+"	LSETUP (lwq1, lwq2) LC0 = %5;\n\t"
+"lwq1:	  R3 = 0 (X);\n\t"                     /* R3: dist           */
+"	  LSETUP (lwq3, lwq4) LC1 = %6;\n\t"
+"lwq3:	    R0.L = W [I0++] || R2.L = W [I1++];\n\t"
+"           R1 = B [P2++] (X);\n\t"            
+"	    R1 <<= 5;\n\t"
+"	    R0.L = R0.L - R1.L;\n\t"
+"           R0 = R0.L*R0.L;\n\t"
+"	    A1 = R2.L*R0.L (M,IS);\n\t"
+"	    A1 = A1 >>> 16;\n\t"
+"	    R1 = (A1 += R2.L*R0.H) (IS);\n\t"
+"lwq4:	    R3 = R3 + R1;\n\t"
+
+"	  cc =R3<%0;\n\t"
+"	  if cc %0=R3;\n\t"
+"	  if cc %1=R5;\n\t"
+"lwq2:    R5 += 1;\n\t"
+"         L0 = 0;\n\t"
+"         L1 = 0;\n\t"
+   : "=&d" (best_dist), "=&d" (best_id)
+   : "a" (x), "a" (weight), "b" (cdbk), "a" (nbVec), "a" (nbDim)
+   : "I0", "I1", "P2", "R0", "R1", "R2", "R3", "R5", "A1",
+     "L0", "L1", "B0", "B1"
+   );
+
+   for (j=0;j<nbDim;j++) {
+      x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
+   }
+   return best_id;
+}
+#endif



More information about the commits mailing list