<|start_filename|>win32/config.h<|end_filename|>
// Microsoft version of 'inline'
#define inline __inline

// In Visual Studio, _M_IX86_FP=1 means /arch:SSE was used, likewise
// _M_IX86_FP=2 means /arch:SSE2 was used.
// Also, enable both _USE_SSE and _USE_SSE2 if we're compiling for x86-64
#if _M_IX86_FP >= 1 || defined(_M_X64)
#define _USE_SSE
#endif

#if _M_IX86_FP >= 2 || defined(_M_X64)
#define _USE_SSE2
#endif

// Visual Studio support alloca(), but it always align variables to 16-bit
// boundary, while SSE need 128-bit alignment. So we disable alloca() when
// SSE is enabled.
#ifndef _USE_SSE
#  define USE_ALLOCA
#endif

/* Default to floating point */
#ifndef FIXED_POINT
#  define FLOATING_POINT
#  define USE_SMALLFT
#else
#  define USE_KISS_FFT
#endif

/* We don't support visibility on Win32 */
#define EXPORT


<|start_filename|>libspeex/filters_arm4.h<|end_filename|>
/* Copyright (C) 2004 <NAME> */
/**
   @file filters_arm4.h
   @brief Various analysis/synthesis filters (ARM4 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_NORMALIZE16
int normalize16(const spx_sig_t *x, spx_word16_t *y, spx_sig_t max_scale, int len)
{
   spx_sig_t max_val=1;
   int sig_shift;
   int dead1, dead2, dead3, dead4, dead5, dead6;

   __asm__ __volatile__ (
         "\tmov %1, #1 \n"
         "\tmov %3, #0 \n"

         ".normalize16loop1%=: \n"

         "\tldr %4, [%0], #4 \n"
         "\tcmp %4, %1 \n"
         "\tmovgt %1, %4 \n"
         "\tcmp %4, %3 \n"
         "\tmovlt %3, %4 \n"

         "\tsubs %2, %2, #1 \n"
         "\tbne .normalize16loop1%=\n"

         "\trsb %3, %3, #0 \n"
         "\tcmp %1, %3 \n"
         "\tmovlt %1, %3 \n"
   : "=r" (dead1), "=r" (max_val), "=r" (dead3), "=r" (dead4),
   "=r" (dead5), "=r" (dead6)
   : "0" (x), "2" (len)
   : "cc");

   sig_shift=0;
   while (max_val>max_scale)
   {
      sig_shift++;
      max_val >>= 1;
   }
   
   __asm__ __volatile__ (
         ".normalize16loop%=: \n"

         "\tldr %4, [%0], #4 \n"
         "\tldr %5, [%0], #4 \n"
         "\tmov %4, %4, asr %3 \n"
         "\tstrh %4, [%1], #2 \n"
         "\tldr %4, [%0], #4 \n"
         "\tmov %5, %5, asr %3 \n"
         "\tstrh %5, [%1], #2 \n"
         "\tldr %5, [%0], #4 \n"
         "\tmov %4, %4, asr %3 \n"
         "\tstrh %4, [%1], #2 \n"
         "\tsubs %2, %2, #1 \n"
         "\tmov %5, %5, asr %3 \n"
         "\tstrh %5, [%1], #2 \n"

         "\tbgt .normalize16loop%=\n"
   : "=r" (dead1), "=r" (dead2), "=r" (dead3), "=r" (dead4),
   "=r" (dead5), "=r" (dead6)
   : "0" (x), "1" (y), "2" (len>>2), "3" (sig_shift)
   : "cc", "memory");
   return sig_shift;
}



<|start_filename|>libspeex/lsp_tables_nb.c<|end_filename|>
/* Copyright (C) 2002 <NAME>
   File: lsp_tables_nb.c
   Codebooks for LSPs in narrowband CELP mode

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:

   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

   2. 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.

   3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/

const signed char cdbk_nb[640]={
30,19,38,34,40,32,46,43,58,43,
5,-18,-25,-40,-33,-55,-52,20,34,28,
-20,-63,-97,-92,61,53,47,49,53,75,
-14,-53,-77,-79,0,-3,-5,19,22,26,
-9,-53,-55,66,90,72,85,68,74,52,
-4,-41,-58,-31,-18,-31,27,32,30,18,
24,3,8,5,-12,-3,26,28,74,63,
-2,-39,-67,-77,-106,-74,59,59,73,65,
44,40,71,72,82,83,98,88,89,60,
-6,-31,-47,-48,-13,-39,-9,7,2,79,
-1,-39,-60,-17,87,81,65,50,45,19,
-21,-67,-91,-87,-41,-50,7,18,39,74,
10,-31,-28,39,24,13,23,5,56,45,
29,10,-5,-13,-11,-35,-18,-8,-10,-8,
-25,-71,-77,-21,2,16,50,63,87,87,
5,-32,-40,-51,-68,0,12,6,54,34,
5,-12,32,52,68,64,69,59,65,45,
14,-16,-31,-40,-65,-67,41,49,47,37,
-11,-52,-75,-84,-4,57,48,42,42,33,
-11,-51,-68,-6,13,0,8,-8,26,32,
-23,-53,0,36,56,76,97,105,111,97,
-1,-28,-39,-40,-43,-54,-44,-40,-18,35,
16,-20,-19,-28,-42,29,47,38,74,45,
3,-29,-48,-62,-80,-104,-33,56,59,59,
10,17,46,72,84,101,117,123,123,106,
-7,-33,-49,-51,-70,-67,-27,-31,70,67,
-16,-62,-85,-20,82,71,86,80,85,74,
-19,-58,-75,-45,-29,-33,-18,-25,45,57,
-12,-42,-5,12,28,36,52,64,81,82,
13,-9,-27,-28,22,3,2,22,26,6,
-6,-44,-51,2,15,10,48,43,49,34,
-19,-62,-84,-89,-102,-24,8,17,61,68,
39,24,23,19,16,-5,12,15,27,15,
-8,-44,-49,-60,-18,-32,-28,52,54,62,
-8,-48,-77,-70,66,101,83,63,61,37,
-12,-50,-75,-64,33,17,13,25,15,77,
1,-42,-29,72,64,46,49,31,61,44,
-8,-47,-54,-46,-30,19,20,-1,-16,0,
16,-12,-18,-9,-26,-27,-10,-22,53,45,
-10,-47,-75,-82,-105,-109,8,25,49,77,
50,65,114,117,124,118,115,96,90,61,
-9,-45,-63,-60,-75,-57,8,11,20,29,
0,-35,-49,-43,40,47,35,40,55,38,
-24,-76,-103,-112,-27,3,23,34,52,75,
8,-29,-43,12,63,38,35,29,24,8,
25,11,1,-15,-18,-43,-7,37,40,21,
-20,-56,-19,-19,-4,-2,11,29,51,63,
-2,-44,-62,-75,-89,30,57,51,74,51,
50,46,68,64,65,52,63,55,65,43,
18,-9,-26,-35,-55,-69,3,6,8,17,
-15,-61,-86,-97,1,86,93,74,78,67,
-1,-38,-66,-48,48,39,29,25,17,-1,
13,13,29,39,50,51,69,82,97,98,
-2,-36,-46,-27,-16,-30,-13,-4,-7,-4,
25,-5,-11,-6,-25,-21,33,12,31,29,
-8,-38,-52,-63,-68,-89,-33,-1,10,74,
-2,-15,59,91,105,105,101,87,84,62,
-7,-33,-50,-35,-54,-47,25,17,82,81,
-13,-56,-83,21,58,31,42,25,72,65,
-24,-66,-91,-56,9,-2,21,10,69,75,
2,-24,11,22,25,28,38,34,48,33,
7,-29,-26,17,15,-1,14,0,-2,0,
-6,-41,-67,6,-2,-9,19,2,85,74,
-22,-67,-84,-71,-50,3,11,-9,2,62};

const signed char cdbk_nb_low1[320]={
-34,-52,-15,45,2,
23,21,52,24,-33,
-9,-1,9,-44,-41,
-13,-17,44,22,-17,
-6,-4,-1,22,38,
26,16,2,50,27,
-35,-34,-9,-41,6,
0,-16,-34,51,8,
-14,-31,-49,15,-33,
45,49,33,-11,-37,
-62,-54,45,11,-5,
-72,11,-1,-12,-11,
24,27,-11,-43,46,
43,33,-12,-9,-1,
1,-4,-23,-57,-71,
11,8,16,17,-8,
-20,-31,-41,53,48,
-16,3,65,-24,-8,
-23,-32,-37,-32,-49,
-10,-17,6,38,5,
-9,-17,-46,8,52,
3,6,45,40,39,
-7,-6,-34,-74,31,
8,1,-16,43,68,
-11,-19,-31,4,6,
0,-6,-17,-16,-38,
-16,-30,2,9,-39,
-16,-1,43,-10,48,
3,3,-16,-31,-3,
62,68,43,13,3,
-10,8,20,-56,12,
12,-2,-18,22,-15,
-40,-36,1,7,41,
0,1,46,-6,-62,
-4,-12,-2,-11,-83,
-13,-2,91,33,-10,
0,4,-11,-16,79,
32,37,14,9,51,
-21,-28,-56,-34,0,
21,9,-26,11,28,
-42,-54,-23,-2,-15,
31,30,8,-39,-66,
-39,-36,31,-28,-40,
-46,35,40,22,24,
33,48,23,-34,14,
40,32,17,27,-3,
25,26,-13,-61,-17,
11,4,31,60,-6,
-26,-41,-64,13,16,
-26,54,31,-11,-23,
-9,-11,-34,-71,-21,
-34,-35,55,50,29,
-22,-27,-50,-38,57,
33,42,57,48,26,
11,0,-49,-31,26,
-4,-14,5,78,37,
17,0,-49,-12,-23,
26,14,2,2,-43,
-17,-12,10,-8,-4,
8,18,12,-6,20,
-12,-6,-13,-25,34,
15,40,49,7,8,
13,20,20,-19,-22,
-2,-8,2,51,-51};

const signed char cdbk_nb_low2[320]={
-6,53,-21,-24,4,
26,17,-4,-37,25,
17,-36,-13,31,3,
-6,27,15,-10,31,
28,26,-10,-10,-40,
16,-7,15,13,41,
-9,0,-4,50,-6,
-7,14,38,22,0,
-48,2,1,-13,-19,
32,-3,-60,11,-17,
-1,-24,-34,-1,35,
-5,-27,28,44,13,
25,15,42,-11,15,
51,35,-36,20,8,
-4,-12,-29,19,-47,
49,-15,-4,16,-29,
-39,14,-30,4,25,
-9,-5,-51,-14,-3,
-40,-32,38,5,-9,
-8,-4,-1,-22,71,
-3,14,26,-18,-22,
24,-41,-25,-24,6,
23,19,-10,39,-26,
-27,65,45,2,-7,
-26,-8,22,-12,16,
15,16,-35,-5,33,
-21,-8,0,23,33,
34,6,21,36,6,
-7,-22,8,-37,-14,
31,38,11,-4,-3,
-39,-32,-8,32,-23,
-6,-12,16,20,-28,
-4,23,13,-52,-1,
22,6,-33,-40,-6,
4,-62,13,5,-26,
35,39,11,2,57,
-11,9,-20,-28,-33,
52,-5,-6,-2,22,
-14,-16,-48,35,1,
-58,20,13,33,-1,
-74,56,-18,-22,-31,
12,6,-14,4,-2,
-9,-47,10,-3,29,
-17,-5,61,14,47,
-12,2,72,-39,-17,
92,64,-53,-51,-15,
-30,-38,-41,-29,-28,
27,9,36,9,-35,
-42,81,-21,20,25,
-16,-5,-17,-35,21,
15,-28,48,2,-2,
9,-19,29,-40,30,
-18,-18,18,-16,-57,
15,-20,-12,-15,-37,
-15,33,-39,21,-22,
-13,35,11,13,-38,
-63,29,23,-27,32,
18,3,-26,42,33,
-64,-66,-17,16,56,
2,36,3,31,21,
-41,-39,8,-57,14,
37,-2,19,-36,-19,
-23,-29,-16,1,-3,
-8,-10,31,64,-65};

const signed char cdbk_nb_high1[320]={
-26,-8,29,21,4,
19,-39,33,-7,-36,
56,54,48,40,29,
-4,-24,-42,-66,-43,
-60,19,-2,37,41,
-10,-37,-60,-64,18,
-22,77,73,40,25,
4,19,-19,-66,-2,
11,5,21,14,26,
-25,-86,-4,18,1,
26,-37,10,37,-1,
24,-12,-59,-11,20,
-6,34,-16,-16,42,
19,-28,-51,53,32,
4,10,62,21,-12,
-34,27,4,-48,-48,
-50,-49,31,-7,-21,
-42,-25,-4,-43,-22,
59,2,27,12,-9,
-6,-16,-8,-32,-58,
-16,-29,-5,41,23,
-30,-33,-46,-13,-10,
-38,52,52,1,-17,
-9,10,26,-25,-6,
33,-20,53,55,25,
-32,-5,-42,23,21,
66,5,-28,20,9,
75,29,-7,-42,-39,
15,3,-23,21,6,
11,1,-29,14,63,
10,54,26,-24,-51,
-49,7,-23,-51,15,
-66,1,60,25,10,
0,-30,-4,-15,17,
19,59,40,4,-5,
33,6,-22,-58,-70,
-5,23,-6,60,44,
-29,-16,-47,-29,52,
-19,50,28,16,35,
31,36,0,-21,6,
21,27,22,42,7,
-66,-40,-8,7,19,
46,0,-4,60,36,
45,-7,-29,-6,-32,
-39,2,6,-9,33,
20,-51,-34,18,-6,
19,6,11,5,-19,
-29,-2,42,-11,-45,
-21,-55,57,37,2,
-14,-67,-16,-27,-38,
69,48,19,2,-17,
20,-20,-16,-34,-17,
-25,-61,10,73,45,
16,-40,-64,-17,-29,
-22,56,17,-39,8,
-11,8,-25,-18,-13,
-19,8,54,57,36,
-17,-26,-4,6,-21,
40,42,-4,20,31,
53,10,-34,-53,31,
-17,35,0,15,-6,
-20,-63,-73,22,25,
29,17,8,-29,-39,
-69,18,15,-15,-5};

const signed char cdbk_nb_high2[320]={
11,47,16,-9,-46,
-32,26,-64,34,-5,
38,-7,47,20,2,
-73,-99,-3,-45,20,
70,-52,15,-6,-7,
-82,31,21,47,51,
39,-3,9,0,-41,
-7,-15,-54,2,0,
27,-31,9,-45,-22,
-38,-24,-24,8,-33,
23,5,50,-36,-17,
-18,-51,-2,13,19,
43,12,-15,-12,61,
38,38,7,13,0,
6,-1,3,62,9,
27,22,-33,38,-35,
-9,30,-43,-9,-32,
-1,4,-4,1,-5,
-11,-8,38,31,11,
-10,-42,-21,-37,1,
43,15,-13,-35,-19,
-18,15,23,-26,59,
1,-21,53,8,-41,
-50,-14,-28,4,21,
25,-28,-40,5,-40,
-41,4,51,-33,-8,
-8,1,17,-60,12,
25,-41,17,34,43,
19,45,7,-37,24,
-15,56,-2,35,-10,
48,4,-47,-2,5,
-5,-54,5,-3,-33,
-10,30,-2,-44,-24,
-38,9,-9,42,4,
6,-56,44,-16,9,
-40,-26,18,-20,10,
28,-41,-21,-4,13,
-18,32,-30,-3,37,
15,22,28,50,-40,
3,-29,-64,7,51,
-19,-11,17,-27,-40,
-64,24,-12,-7,-27,
3,37,48,-1,2,
-9,-38,-34,46,1,
27,-6,19,-13,26,
10,34,20,25,40,
50,-6,-7,30,9,
-24,0,-23,71,-61,
22,58,-34,-4,2,
-49,-33,25,30,-8,
-6,-16,77,2,38,
-8,-35,-6,-30,56,
78,31,33,-20,13,
-39,20,22,4,21,
-8,4,-6,10,-83,
-41,9,-25,-43,15,
-7,-12,-34,-39,-37,
-33,19,30,16,-33,
42,-25,25,-68,44,
-15,-11,-4,23,50,
14,4,-39,-43,20,
-30,60,9,-20,7,
16,19,-33,37,29,
16,-35,7,38,-27};


<|start_filename|>libspeex/fixed_bfin.h<|end_filename|>
/* Copyright (C) 2005 Analog Devices
   Author: <NAME> */
/**
   @file fixed_bfin.h
   @brief Blackfin fixed-point operations
*/
/*
   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.
*/

#ifndef FIXED_BFIN_H
#define FIXED_BFIN_H

#include "bfin.h"

#undef PDIV32_16
static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b)
{
   spx_word32_t res, bb;
   bb = b;
   a += b>>1;
   __asm__  (
         "P0 = 15;\n\t"
         "R0 = %1;\n\t"
         "R1 = %2;\n\t"
         //"R0 = R0 + R1;\n\t"
         "R0 <<= 1;\n\t"
         "DIVS (R0, R1);\n\t"
         "LOOP divide%= LC0 = P0;\n\t"
         "LOOP_BEGIN divide%=;\n\t"
            "DIVQ (R0, R1);\n\t"
         "LOOP_END divide%=;\n\t"
         "R0 = R0.L;\n\t"
         "%0 = R0;\n\t"
   : "=m" (res)
   : "m" (a), "m" (bb)
   : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS);
   return res;
}

#undef DIV32_16
static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b)
{
   spx_word32_t res, bb;
   bb = b;
   /* Make the roundinf consistent with the C version 
      (do we need to do that?)*/
   if (a<0) 
      a += (b-1);
   __asm__  (
         "P0 = 15;\n\t"
         "R0 = %1;\n\t"
         "R1 = %2;\n\t"
         "R0 <<= 1;\n\t"
         "DIVS (R0, R1);\n\t"
         "LOOP divide%= LC0 = P0;\n\t"
         "LOOP_BEGIN divide%=;\n\t"
            "DIVQ (R0, R1);\n\t"
         "LOOP_END divide%=;\n\t"
         "R0 = R0.L;\n\t"
         "%0 = R0;\n\t"
   : "=m" (res)
   : "m" (a), "m" (bb)
   : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS);
   return res;
}

#undef MAX16
static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b)
{
   spx_word32_t res;
   __asm__  (
         "%1 = %1.L (X);\n\t"
         "%2 = %2.L (X);\n\t"
         "%0 = MAX(%1,%2);"
   : "=d" (res)
   : "%d" (a), "d" (b)
   : "ASTAT"
   );
   return res;
}

#undef MULT16_32_Q15
static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b)
{
   spx_word32_t res;
   __asm__
   (
         "A1 = %2.L*%1.L (M);\n\t"
         "A1 = A1 >>> 15;\n\t"
         "%0 = (A1 += %2.L*%1.H) ;\n\t"
   : "=&W" (res), "=&d" (b)
   : "d" (a), "1" (b)
   : "A1", "ASTAT"
   );
   return res;
}

#undef MAC16_32_Q15
static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b)
{
   spx_word32_t res;
   __asm__
         (
         "A1 = %2.L*%1.L (M);\n\t"
         "A1 = A1 >>> 15;\n\t"
         "%0 = (A1 += %2.L*%1.H);\n\t"
         "%0 = %0 + %4;\n\t"
   : "=&W" (res), "=&d" (b)
   : "d" (a), "1" (b), "d" (c)
   : "A1", "ASTAT"
         );
   return res;
}

#undef MULT16_32_Q14
static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b)
{
   spx_word32_t res;
   __asm__
         (
         "%2 <<= 1;\n\t"
         "A1 = %1.L*%2.L (M);\n\t"
         "A1 = A1 >>> 15;\n\t"
         "%0 = (A1 += %1.L*%2.H);\n\t"
   : "=W" (res), "=d" (a), "=d" (b)
   : "1" (a), "2" (b)
   : "A1", "ASTAT"
         );
   return res;
}

#undef MAC16_32_Q14
static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b)
{
   spx_word32_t res;
   __asm__
         (
         "%1 <<= 1;\n\t"
         "A1 = %2.L*%1.L (M);\n\t"
         "A1 = A1 >>> 15;\n\t"
         "%0 = (A1 += %2.L*%1.H);\n\t"
         "%0 = %0 + %4;\n\t"
   : "=&W" (res), "=&d" (b)
   : "d" (a), "1" (b), "d" (c)
   : "A1", "ASTAT"
         );
   return res;
}

#endif


<|start_filename|>libspeex/gain_table.c<|end_filename|>
/* Copyright (C) 2002 <NAME>
   File: gain_table.c
   Codebook for 3-tap pitch prediction gain (128 entries)

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:

   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

   2. 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.

   3. The name of the author may not be used to endorse or promote products
   derived from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/

const signed char gain_cdbk_nb[512] = {
-32, -32, -32, 0,
-28, -67, -5, 33,
-42, -6, -32, 18,
-57, -10, -54, 35,
-16, 27, -41, 42,
19, -19, -40, 36,
-45, 24, -21, 40,
-8, -14, -18, 28,
1, 14, -58, 53,
-18, -88, -39, 39,
-38, 21, -18, 37,
-19, 20, -43, 38,
10, 17, -48, 54,
-52, -58, -13, 33,
-44, -1, -11, 32,
-12, -11, -34, 22,
14, 0, -46, 46,
-37, -35, -34, 5,
-25, 44, -30, 43,
6, -4, -63, 49,
-31, 43, -41, 43,
-23, 30, -43, 41,
-43, 26, -14, 44,
-33, 1, -13, 27,
-13, 18, -37, 37,
-46, -73, -45, 34,
-36, 24, -25, 34,
-36, -11, -20, 19,
-25, 12, -18, 33,
-36, -69, -59, 34,
-45, 6, 8, 46,
-22, -14, -24, 18,
-1, 13, -44, 44,
-39, -48, -26, 15,
-32, 31, -37, 34,
-33, 15, -46, 31,
-24, 30, -36, 37,
-41, 31, -23, 41,
-50, 22, -4, 50,
-22, 2, -21, 28,
-17, 30, -34, 40,
-7, -60, -28, 29,
-38, 42, -28, 42,
-44, -11, 21, 43,
-16, 8, -44, 34,
-39, -55, -43, 21,
-11, -35, 26, 41,
-9, 0, -34, 29,
-8, 121, -81, 113,
7, -16, -22, 33,
-37, 33, -31, 36,
-27, -7, -36, 17,
-34, 70, -57, 65,
-37, -11, -48, 21,
-40, 17, -1, 44,
-33, 6, -6, 33,
-9, 0, -20, 34,
-21, 69, -33, 57,
-29, 33, -31, 35,
-55, 12, -1, 49,
-33, 27, -22, 35,
-50, -33, -47, 17,
-50, 54, 51, 94,
-1, -5, -44, 35,
-4, 22, -40, 45,
-39, -66, -25, 24,
-33, 1, -26, 20,
-24, -23, -25, 12,
-11, 21, -45, 44,
-25, -45, -19, 17,
-43, 105, -16, 82,
5, -21, 1, 41,
-16, 11, -33, 30,
-13, -99, -4, 57,
-37, 33, -15, 44,
-25, 37, -63, 54,
-36, 24, -31, 31,
-53, -56, -38, 26,
-41, -4, 4, 37,
-33, 13, -30, 24,
49, 52, -94, 114,
-5, -30, -15, 23,
1, 38, -40, 56,
-23, 12, -36, 29,
-17, 40, -47, 51,
-37, -41, -39, 11,
-49, 34, 0, 58,
-18, -7, -4, 34,
-16, 17, -27, 35,
30, 5, -62, 65,
4, 48, -68, 76,
-43, 11, -11, 38,
-18, 19, -15, 41,
-23, -62, -39, 23,
-42, 10, -2, 41,
-21, -13, -13, 25,
-9, 13, -47, 42,
-23, -62, -24, 24,
-44, 60, -21, 58,
-18, -3, -52, 32,
-22, 22, -36, 34,
-75, 57, 16, 90,
-19, 3, 10, 45,
-29, 23, -38, 32,
-5, -62, -51, 38,
-51, 40, -18, 53,
-42, 13, -24, 32,
-34, 14, -20, 30,
-56, -75, -26, 37,
-26, 32, 15, 59,
-26, 17, -29, 29,
-7, 28, -52, 53,
-12, -30, 5, 30,
-5, -48, -5, 35,
2, 2, -43, 40,
21, 16, 16, 75,
-25, -45, -32, 10,
-43, 18, -10, 42,
9, 0, -1, 52,
-1, 7, -30, 36,
19, -48, -4, 48,
-28, 25, -29, 32,
-22, 0, -31, 22,
-32, 17, -10, 36,
-64, -41, -62, 36,
-52, 15, 16, 58,
-30, -22, -32, 6,
-7, 9, -38, 36};


<|start_filename|>libspeex/ltp_bfin.h<|end_filename|>
/* Copyright (C) 2005 Analog Devices */
/**
   @file ltp_bfin.h
   @author <NAME>
   @brief Long-Term Prediction functions (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.
*/

#include "bfin.h"

#define OVERRIDE_INNER_PROD
spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
{
   spx_word32_t sum=0;
   __asm__ __volatile__ (
      "P0 = %3;\n\t"
      "P1 = %1;\n\t"
      "P2 = %2;\n\t"
      "I0 = P1;\n\t"
      "I1 = P2;\n\t"
      "L0 = 0;\n\t"
      "L1 = 0;\n\t"
      "A0 = 0;\n\t"
      "R0.L = W[I0++] || R1.L = W[I1++];\n\t"
      "LOOP inner%= LC0 = P0;\n\t"
      "LOOP_BEGIN inner%=;\n\t"
         "A0 += R0.L*R1.L (IS) || R0.L = W[I0++] || R1.L = W[I1++];\n\t"
      "LOOP_END inner%=;\n\t"
      "A0 += R0.L*R1.L (IS);\n\t"
      "A0 = A0 >>> 6;\n\t"
      "R0 = A0;\n\t"
      "%0 = R0;\n\t"
   : "=m" (sum)
   : "m" (x), "m" (y), "d" (len-1)
   : "P0", "P1", "P2", "R0", "R1", "A0", "I0", "I1", "L0", "L1", "R3", "ASTAT" BFIN_HWLOOP0_REGS
   );
   return sum;
}

#define OVERRIDE_PITCH_XCORR
void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
{
   corr += nb_pitch - 1;
   __asm__ __volatile__ (
      "P2 = %0;\n\t"
      "I0 = P2;\n\t" /* x in I0 */
      "B0 = P2;\n\t" /* x in B0 */
      "R0 = %3;\n\t" /* len in R0 */
      "P3 = %3;\n\t"
      "P3 += -2;\n\t" /* len in R0 */
      "P4 = %4;\n\t" /* nb_pitch in R0 */
      "R1 = R0 << 1;\n\t" /* number of bytes in x */
      "L0 = R1;\n\t"
      "P0 = %1;\n\t"

      "P1 = %2;\n\t"
      "B1 = P1;\n\t"
      "L1 = 0;\n\t" /*Disable looping on I1*/

      "r0 = [I0++];\n\t"
      "LOOP pitch%= LC0 = P4 >> 1;\n\t"
      "LOOP_BEGIN pitch%=;\n\t"
         "I1 = P0;\n\t"
         "A1 = A0 = 0;\n\t"
         "R1 = [I1++];\n\t"
         "LOOP inner_prod%= LC1 = P3 >> 1;\n\t"
         "LOOP_BEGIN inner_prod%=;\n\t"
            "A1 += R0.L*R1.H, A0 += R0.L*R1.L (IS) || R1.L = W[I1++];\n\t"
            "A1 += R0.H*R1.L, A0 += R0.H*R1.H (IS) || R1.H = W[I1++] || R0 = [I0++];\n\t"
         "LOOP_END inner_prod%=;\n\t"
         "A1 += R0.L*R1.H, A0 += R0.L*R1.L (IS) || R1.L = W[I1++];\n\t"
         "A1 += R0.H*R1.L, A0 += R0.H*R1.H (IS) || R0 = [I0++];\n\t"
         "A0 = A0 >>> 6;\n\t"
         "A1 = A1 >>> 6;\n\t"
         "R2 = A0, R3 = A1;\n\t"
         "[P1--] = r2;\n\t"
         "[P1--] = r3;\n\t"
         "P0 += 4;\n\t"
      "LOOP_END pitch%=;\n\t"
      "L0 = 0;\n\t"
   : : "m" (_x), "m" (_y), "m" (corr), "m" (len), "m" (nb_pitch)
   : "A0", "A1", "P0", "P1", "P2", "P3", "P4", "R0", "R1", "R2", "R3", "I0", "I1", "L0", "L1", "B0", "B1", "memory",
     "ASTAT" BFIN_HWLOOP0_REGS BFIN_HWLOOP1_REGS
   );
}

#define OVERRIDE_COMPUTE_PITCH_ERROR
static inline spx_word32_t compute_pitch_error(spx_word16_t *C, spx_word16_t *g, spx_word16_t pitch_control)
{
   spx_word32_t sum;
   __asm__ __volatile__
         (
         "A0 = 0;\n\t"
         
         "R0 = W[%1++];\n\t"
         "R1.L = %2.L*%5.L (IS);\n\t"
         "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %3.L*%5.L (IS);\n\t"
         "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %4.L*%5.L (IS);\n\t"
         "A0 += R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %2.L*%3.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"

         "R1.L = %4.L*%3.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %4.L*%2.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %2.L*%2.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"

         "R1.L = %3.L*%3.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS) || R0 = W[%1++];\n\t"
         
         "R1.L = %4.L*%4.L (IS);\n\t"
         "A0 -= R1.L*R0.L (IS);\n\t"
         
         "%0 = A0;\n\t"
   : "=&D" (sum), "=a" (C)
   : "d" (g[0]), "d" (g[1]), "d" (g[2]), "d" (pitch_control), "1" (C)
   : "R0", "R1", "R2", "A0", "ASTAT"
         );
   return sum;
}

#define OVERRIDE_OPEN_LOOP_NBEST_PITCH
#ifdef OVERRIDE_OPEN_LOOP_NBEST_PITCH
void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack)
{
   int i,j,k;
   VARDECL(spx_word32_t *best_score);
   VARDECL(spx_word32_t *best_ener);
   spx_word32_t e0;
   VARDECL(spx_word32_t *corr);
   VARDECL(spx_word32_t *energy);

   ALLOC(best_score, N, spx_word32_t);
   ALLOC(best_ener, N, spx_word32_t);
   ALLOC(corr, end-start+1, spx_word32_t);
   ALLOC(energy, end-start+2, spx_word32_t);

   for (i=0;i<N;i++)
   {
        best_score[i]=-1;
        best_ener[i]=0;
        pitch[i]=start;
   }

   energy[0]=inner_prod(sw-start, sw-start, len);
   e0=inner_prod(sw, sw, len);

   /* energy update -------------------------------------*/

      __asm__ __volatile__
      (
"        P0 = %0;\n\t"
"        I1 = %1;\n\t"
"        L1 = 0;\n\t"
"        I2 = %2;\n\t"
"        L2 = 0;\n\t"
"        R2 = [P0++];\n\t"
"        R3 = 0;\n\t"
"        LSETUP (eu1, eu2) LC1 = %3;\n\t"
"eu1:      R1.L = W [I1--] || R0.L = W [I2--] ;\n\t"
"          R1 = R1.L * R1.L (IS);\n\t"
"          R0 = R0.L * R0.L (IS);\n\t"
"          R1 >>>= 6;\n\t"
"          R1 = R1 + R2;\n\t"
"          R0 >>>= 6;\n\t"
"          R1 = R1 - R0;\n\t"
"          R2 = MAX(R1,R3);\n\t"
"eu2:      [P0++] = R2;\n\t"
       : : "d" (energy), "d" (&sw[-start-1]), "d" (&sw[-start+len-1]),
           "a" (end-start)  
       : "P0", "I1", "I2", "R0", "R1", "R2", "R3", "ASTAT" BFIN_HWLOOP1_REGS
       );

   pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack);

   /* FIXME: Fixed-point and floating-point code should be merged */
   {
      VARDECL(spx_word16_t *corr16);
      VARDECL(spx_word16_t *ener16);
      ALLOC(corr16, end-start+1, spx_word16_t);
      ALLOC(ener16, end-start+1, spx_word16_t);
      /* Normalize to 180 so we can square it and it still fits in 16 bits */
      normalize16(corr, corr16, 180, end-start+1);
      normalize16(energy, ener16, 180, end-start+1);

      if (N == 1) {
	/* optimised asm to handle N==1 case */
      __asm__ __volatile__
      (
"        I0 = %1;\n\t"                     /* I0: corr16[]    */
"        L0 = 0;\n\t"
"        I1 = %2;\n\t"                     /* I1: energy      */
"        L1 = 0;\n\t"
"        R2 = -1;\n\t"                     /* R2: best score  */
"        R3 = 0;\n\t"                      /* R3: best energy */
"        P0 = %4;\n\t"                     /* P0: best pitch  */
"        P1 = %4;\n\t"                     /* P1: counter     */
"        LSETUP (sl1, sl2) LC1 = %3;\n\t"
"sl1:      R0.L = W [I0++] || R1.L = W [I1++];\n\t"         
"          R0 = R0.L * R0.L (IS);\n\t"
"          R1   += 1;\n\t"
"          R4   = R0.L * R3.L;\n\t"
"          R5   = R2.L * R1.L;\n\t"
"          cc   = R5 < R4;\n\t"
"          if cc R2 = R0;\n\t"
"          if cc R3 = R1;\n\t"
"          if cc P0 = P1;\n\t"
"sl2:      P1 += 1;\n\t"
"        %0 = P0;\n\t"
       : "=&d" (pitch[0])
       : "a" (corr16), "a" (ener16), "a" (end+1-start), "d" (start) 
       : "P0", "P1", "I0", "I1", "R0", "R1", "R2", "R3", "R4", "R5",
         "ASTAT", "CC" BFIN_HWLOOP1_REGS
       );

      }
      else {
	for (i=start;i<=end;i++)
	  {
	    spx_word16_t tmp = MULT16_16_16(corr16[i-start],corr16[i-start]);
	    /* Instead of dividing the tmp by the energy, we multiply on the other side */
	    if (MULT16_16(tmp,best_ener[N-1])>MULT16_16(best_score[N-1],ADD16(1,ener16[i-start])))
	      {
		/* We can safely put it last and then check */
		best_score[N-1]=tmp;
		best_ener[N-1]=ener16[i-start]+1;
		pitch[N-1]=i;
		/* Check if it comes in front of others */
		for (j=0;j<N-1;j++)
		  {
		    if (MULT16_16(tmp,best_ener[j])>MULT16_16(best_score[j],ADD16(1,ener16[i-start])))
		      {
			for (k=N-1;k>j;k--)
			  {
			    best_score[k]=best_score[k-1];
			    best_ener[k]=best_ener[k-1];
			    pitch[k]=pitch[k-1];
			  }
			best_score[j]=tmp;
			best_ener[j]=ener16[i-start]+1;
			pitch[j]=i;
			break;
		      }
		  }
	      }
	  }
      }
   }

   /* Compute open-loop gain */
   if (gain)
   {
       for (j=0;j<N;j++)
       {
          spx_word16_t g;
          i=pitch[j];
          g = DIV32(corr[i-start], 10+SHR32(MULT16_16(spx_sqrt(e0),spx_sqrt(energy[i-start])),6));
          /* FIXME: g = max(g,corr/energy) */
                   if (g<0)
                   g = 0;
             gain[j]=g;
       }
   }
}
#endif

#define OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
#ifdef OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
static int pitch_gain_search_3tap_vq(
  const signed char *gain_cdbk,
  int                gain_cdbk_size,
  spx_word16_t      *C16,
  spx_word16_t       max_gain
)
{
  const signed char *ptr=gain_cdbk;
  int                best_cdbk=0;
  spx_word32_t       best_sum=-VERY_LARGE32;
  spx_word32_t       sum=0;
  spx_word16_t       g[3];
  spx_word16_t       pitch_control=64;
  spx_word16_t       gain_sum;
  int                i;

      /* fast asm version of VQ codebook search */

      __asm__ __volatile__
      (

"        P0 = %2;\n\t"                     /* P0: ptr to gain_cdbk */
"        L1 = 0;\n\t"                      /* no circ addr for L1  */
"        %0 = 0;\n\t"                      /* %0: best_sum         */
"        %1 = 0;\n\t"                      /* %1: best_cbdk        */
"        P1 = 0;\n\t"                      /* P1: loop counter     */

"        LSETUP (pgs1, pgs2) LC1 = %4;\n\t"
"pgs1:     R2  = B [P0++] (X);\n\t"        /* R2: g[0]             */
"          R3  = B [P0++] (X);\n\t"        /* R3: g[1]             */
"          R4  = B [P0++] (X);\n\t"        /* R4: g[2]             */
"          R2 += 32;\n\t"
"          R3 += 32;\n\t"
"          R4 += 32;\n\t"
"          R4.H = 64;\n\t"                 /* R4.H: pitch_control    */

"          R0  = B [P0++] (X);\n\t"              
"          B0  = R0;\n\t"                  /* BO: gain_sum         */
          
           /* compute_pitch_error() -------------------------------*/

"          I1 = %3;\n\t"                   /* I1: ptr to C         */
"          A0 = 0;\n\t"
         
"          R0.L = W[I1++];\n\t"
"          R1.L = R2.L*R4.H (IS);\n\t"
"          A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R3.L*R4.H (IS);\n\t"
"          A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R4.L*R4.H (IS);\n\t"
"          A0 += R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R2.L*R3.L (IS);\n\t"
"          A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"

"          R1.L = R4.L*R3.L (IS);\n\t"
"          A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R4.L*R2.L (IS);\n\t"
"          A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R2.L*R2.L (IS);\n\t"
"          A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"

"          R1.L = R3.L*R3.L (IS);\n\t"
"          A0 -= R1.L*R0.L (IS) || R0.L = W[I1++];\n\t"
         
"          R1.L = R4.L*R4.L (IS);\n\t"
"          R0 = (A0 -= R1.L*R0.L) (IS);\n\t"

/*
    Re-arrange the if-then to code efficiently on the Blackfin:

      if (sum>best_sum && gain_sum<=max_gain)   ------ (1)

      if (sum>best_sum && !(gain_sum>max_gain)) ------ (2)

      if (max_gain<=gain_sum) {                 ------ (3)
      sum = -VERY_LARGE32;
      }
      if (best_sum<=sum)

    The blackin cc instructions are all of the form:

      cc = x < y (or cc = x <= y)
*/
"          R1 = B0\n\t"
"          R2 = %5\n\t"
"          R3 = %6\n\t"
"          cc = R2 <= R1;\n\t" 
"          if cc R0 = R3;\n\t"
"          cc = %0 <= R0;\n\t"
"          if cc %0 = R0;\n\t"
"          if cc %1 = P1;\n\t"

"pgs2:     P1 += 1;\n\t"
   
       : "=&d" (best_sum), "=&d" (best_cdbk) 
       : "a" (gain_cdbk), "a" (C16), "a" (gain_cdbk_size), "a" (max_gain),
         "b" (-VERY_LARGE32)
       : "R0", "R1", "R2", "R3", "R4", "P0", 
         "P1", "I1", "L1", "A0", "B0", "CC", "ASTAT" BFIN_HWLOOP1_REGS
       );

  return best_cdbk;
}
#endif



<|start_filename|>libspeex/bfin.h<|end_filename|>
/* Common Blackfin assembly defines
 *
 * Copyright (C) 2005-2009 Analog Devices
 */

#if __GNUC__ <= 3
/* GCC-3.4 and older did not use hardware loops and thus did not have
 * register constraints for declaring clobbers.
 */
# define BFIN_HWLOOP0_REGS
# define BFIN_HWLOOP1_REGS
#else
# define BFIN_HWLOOP0_REGS , "LB0", "LT0", "LC0"
# define BFIN_HWLOOP1_REGS , "LB1", "LT1", "LC1"
#endif
