Debian Codegraph @

libspeex/quant_lsp_bfin.h

raw
1 /* Copyright (C) 2006 David Rowe */
2 /**
3 @file quant_lsp_bfin.h
4 @author David Rowe
5 @brief Various compatibility routines for Speex (Blackfin version)
6 */
7 /*
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18
19 - Neither the name of the Xiph.org Foundation nor the names of its
20 contributors may be used to endorse or promote products derived from
21 this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #define OVERRIDE_LSP_QUANT
37 #ifdef OVERRIDE_LSP_QUANT
38
39 #include "bfin.h"
40
41 /*
42 Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
43 well tell you all the magic resgister constraints used below
44 for gcc in-line asm.
45 */
46
47 static int lsp_quant(
48 spx_word16_t *x,
49 const signed char *cdbk,
50 int nbVec,
51 int nbDim
52 )
53 {
54 int j;
55 spx_word32_t best_dist=1<<30;
56 int best_id=0;
57
58 __asm__ __volatile__
59 (
60 " %0 = 1 (X);\n\t" /* %0: best_dist */
61 " %0 <<= 30;\n\t"
62 " %1 = 0 (X);\n\t" /* %1: best_i */
63 " P2 = %3\n\t" /* P2: ptr to cdbk */
64 " R5 = 0;\n\t" /* R5: best cb entry */
65
66 " R0 = %5;\n\t" /* set up circ addr */
67 " R0 <<= 1;\n\t"
68 " L0 = R0;\n\t"
69 " I0 = %2;\n\t" /* %2: &x[0] */
70 " B0 = %2;\n\t"
71
72 " R2.L = W [I0++];\n\t"
73 " LSETUP (1f, 2f) LC0 = %4;\n\t"
74 "1: R3 = 0;\n\t" /* R3: dist */
75 " LSETUP (3f, 4f) LC1 = %5;\n\t"
76 "3: R1 = B [P2++] (X);\n\t"
77 " R1 <<= 5;\n\t"
78 " R0.L = R2.L - R1.L || R2.L = W [I0++];\n\t"
79 " R0 = R0.L*R0.L;\n\t"
80 "4: R3 = R3 + R0;\n\t"
81
82 " cc =R3<%0;\n\t"
83 " if cc %0=R3;\n\t"
84 " if cc %1=R5;\n\t"
85 "2: R5 += 1;\n\t"
86 " L0 = 0;\n\t"
87 : "=&d" (best_dist), "=&d" (best_id)
88 : "a" (x), "b" (cdbk), "a" (nbVec), "a" (nbDim)
89 : "I0", "P2", "R0", "R1", "R2", "R3", "R5", "L0", "B0", "A0",
90 "CC", "ASTAT" BFIN_HWLOOP0_REGS BFIN_HWLOOP1_REGS
91 );
92
93 for (j=0;j<nbDim;j++) {
94 x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
95 }
96 return best_id;
97 }
98 #endif
99
100 #define OVERRIDE_LSP_WEIGHT_QUANT
101 #ifdef OVERRIDE_LSP_WEIGHT_QUANT
102
103 /*
104 Note http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
105 well tell you all the magic resgister constraints used below
106 for gcc in-line asm.
107 */
108
109 static int lsp_weight_quant(
110 spx_word16_t *x,
111 spx_word16_t *weight,
112 const signed char *cdbk,
113 int nbVec,
114 int nbDim
115 )
116 {
117 int j;
118 spx_word32_t best_dist=1<<30;
119 int best_id=0;
120
121 __asm__ __volatile__
122 (
123 " %0 = 1 (X);\n\t" /* %0: best_dist */
124 " %0 <<= 30;\n\t"
125 " %1 = 0 (X);\n\t" /* %1: best_i */
126 " P2 = %4\n\t" /* P2: ptr to cdbk */
127 " R5 = 0;\n\t" /* R5: best cb entry */
128
129 " R0 = %6;\n\t" /* set up circ addr */
130 " R0 <<= 1;\n\t"
131 " L0 = R0;\n\t"
132 " L1 = R0;\n\t"
133 " I0 = %2;\n\t" /* %2: &x[0] */
134 " I1 = %3;\n\t" /* %3: &weight[0] */
135 " B0 = %2;\n\t"
136 " B1 = %3;\n\t"
137
138 " LSETUP (1f, 2f) LC0 = %5;\n\t"
139 "1: R3 = 0 (X);\n\t" /* R3: dist */
140 " LSETUP (3f, 4f) LC1 = %6;\n\t"
141 "3: R0.L = W [I0++] || R2.L = W [I1++];\n\t"
142 " R1 = B [P2++] (X);\n\t"
143 " R1 <<= 5;\n\t"
144 " R0.L = R0.L - R1.L;\n\t"
145 " R0 = R0.L*R0.L;\n\t"
146 " A1 = R2.L*R0.L (M,IS);\n\t"
147 " A1 = A1 >>> 16;\n\t"
148 " R1 = (A1 += R2.L*R0.H) (IS);\n\t"
149 "4: R3 = R3 + R1;\n\t"
150
151 " cc =R3<%0;\n\t"
152 " if cc %0=R3;\n\t"
153 " if cc %1=R5;\n\t"
154 "2: R5 += 1;\n\t"
155 " L0 = 0;\n\t"
156 " L1 = 0;\n\t"
157 : "=&d" (best_dist), "=&d" (best_id)
158 : "a" (x), "a" (weight), "b" (cdbk), "a" (nbVec), "a" (nbDim)
159 : "I0", "I1", "P2", "R0", "R1", "R2", "R3", "R5", "A1",
160 "L0", "L1", "B0", "B1", "CC", "ASTAT" BFIN_HWLOOP0_REGS BFIN_HWLOOP1_REGS
161 );
162
163 for (j=0;j<nbDim;j++) {
164 x[j] = SUB16(x[j],SHL16((spx_word16_t)cdbk[best_id*nbDim+j],5));
165 }
166 return best_id;
167 }
168 #endif