summaryrefslogtreecommitdiffstats
path: root/lib/rbcodec/codecs/libspeex/quant_lsp_bfin.h
blob: 087b466b753f2e5c1f68dbb2dfe41e88adac5b36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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 (1f, 2f) LC0 = %4;\n\t"
"1:	  R3 = 0;\n\t"                         /* R3: dist           */
"	  LSETUP (3f, 4f) LC1 = %5;\n\t"
"3:       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"
"4:	    R3 = R3 + R0;\n\t"

"	  cc =R3<%0;\n\t"
"	  if cc %0=R3;\n\t"
"	  if cc %1=R5;\n\t"
"2:     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 (1f, 2f) LC0 = %5;\n\t"
"1:	  R3 = 0 (X);\n\t"                     /* R3: dist           */
"	  LSETUP (3f, 4f) LC1 = %6;\n\t"
"3:	    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"
"4:	    R3 = R3 + R1;\n\t"

"	  cc =R3<%0;\n\t"
"	  if cc %0=R3;\n\t"
"	  if cc %1=R5;\n\t"
"2:    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