1 /* Copyright (C) 2005 Analog Devices */
2 /**
3 @file ltp_bfin.h
4 @author Jean-Marc Valin
5 @brief Long-Term Prediction functions (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_INNER_PROD
inner_prod(const spx_word16_t * x,const spx_word16_t * y,int len)37 static spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
38 {
39 spx_word32_t sum=0;
40 __asm__ __volatile__ (
41 "P0 = %3;\n\t"
42 "P1 = %1;\n\t"
43 "P2 = %2;\n\t"
44 "I0 = P1;\n\t"
45 "I1 = P2;\n\t"
46 "L0 = 0;\n\t"
47 "L1 = 0;\n\t"
48 "A0 = 0;\n\t"
49 "R0.L = W[I0++] || R1.L = W[I1++];\n\t"
50 "LOOP inner%= LC0 = P0;\n\t"
51 "LOOP_BEGIN inner%=;\n\t"
52 "A0 += R0.L*R1.L (IS) || R0.L = W[I0++] || R1.L = W[I1++];\n\t"
53 "LOOP_END inner%=;\n\t"
54 "A0 += R0.L*R1.L (IS);\n\t"
55 "A0 = A0 >>> 6;\n\t"
56 "R0 = A0;\n\t"
57 "%0 = R0;\n\t"
58 : "=m" (sum)
59 : "m" (x), "m" (y), "d" (len-1)
60 : "P0", "P1", "P2", "R0", "R1", "A0", "I0", "I1", "L0", "L1", "R3"
61 );
62 return sum;
63 }
64
65 #define OVERRIDE_PITCH_XCORR
pitch_xcorr(const spx_word16_t * _x,const spx_word16_t * _y,spx_word32_t * corr,int len,int nb_pitch,char * stack)66 static void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
67 {
68 corr += nb_pitch - 1;
69 __asm__ __volatile__ (
70 "P2 = %0;\n\t"
71 "I0 = P2;\n\t" /* x in I0 */
72 "B0 = P2;\n\t" /* x in B0 */
73 "R0 = %3;\n\t" /* len in R0 */
74 "P3 = %3;\n\t"
75 "P3 += -2;\n\t" /* len in R0 */
76 "P4 = %4;\n\t" /* nb_pitch in R0 */
77 "R1 = R0 << 1;\n\t" /* number of bytes in x */
78 "L0 = R1;\n\t"
79 "P0 = %1;\n\t"
80
81 "P1 = %2;\n\t"
82 "B1 = P1;\n\t"
83 "L1 = 0;\n\t" /*Disable looping on I1*/
84
85 "r0 = [I0++];\n\t"
86 "LOOP pitch%= LC0 = P4 >> 1;\n\t"
87 "LOOP_BEGIN pitch%=;\n\t"
88 "I1 = P0;\n\t"
89 "A1 = A0 = 0;\n\t"
90 "R1 = [I1++];\n\t"
91 "LOOP inner_prod%= LC1 = P3 >> 1;\n\t"
92 "LOOP_BEGIN inner_prod%=;\n\t"
93 "A0 += R0.L*R1.L , A1 += R0.L*R1.H (is) || R1.L = W[I1++];\n\t"
94 "A0 += R0.H*R1.H , A1 += R0.H*R1.L (is) || R1.H = W[I1++] || R0 = [I0++];\n\t"
95 "LOOP_END inner_prod%=;\n\t"
96 "A0 += R0.L*R1.L , A1 += R0.L*R1.H (is) || R1.L = W[I1++];\n\t"
97 "A0 += R0.H*R1.H , A1 += R0.H*R1.L (is) || R0 = [I0++];\n\t"
98 "A0 = A0 >>> 6;\n\t"
99 "A1 = A1 >>> 6;\n\t"
100 "R2 = A0, R3 = A1;\n\t"
101 "[P1--] = r2;\n\t"
102 "[P1--] = r3;\n\t"
103 "P0 += 4;\n\t"
104 "LOOP_END pitch%=;\n\t"
105 "L0 = 0;\n\t"
106 : : "m" (_x), "m" (_y), "m" (corr), "m" (len), "m" (nb_pitch)
107 : "A0", "A1", "P0", "P1", "P2", "P3", "P4", "R0", "R1", "R2", "R3", "I0", "I1", "L0", "L1", "B0", "B1", "memory"
108 );
109 }
110
111 #define OVERRIDE_COMPUTE_PITCH_ERROR
compute_pitch_error(spx_word32_t * C,spx_word16_t * g,spx_word16_t pitch_control)112 static inline spx_word32_t compute_pitch_error(spx_word32_t *C, spx_word16_t *g, spx_word16_t pitch_control)
113 {
114 spx_word32_t sum;
115 __asm__ __volatile__
116 (
117 "A0 = A1 = 0;\n\t"
118
119 "R0 = [%1++];\n\t"
120 "R1.L = %2.L*%5.L (IS);\n\t"
121 "R0 <<= 1;\n\t"
122 "A0 += R1.L*R0.H (IS), A1 += R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
123
124 "R1.L = %3.L*%5.L (IS);\n\t"
125 "R0 <<= 1;\n\t"
126 "A0 += R1.L*R0.H (IS), A1 += R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
127
128 "R1.L = %4.L*%5.L (IS);\n\t"
129 "R0 <<= 1;\n\t"
130 "A0 += R1.L*R0.H (IS), A1 += R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
131
132 "R1.L = %2.L*%3.L (IS);\n\t"
133 "R0 <<= 1;\n\t"
134 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
135
136 "R1.L = %4.L*%3.L (IS);\n\t"
137 "R0 <<= 1;\n\t"
138 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
139
140 "R1.L = %4.L*%2.L (IS);\n\t"
141 "R0 <<= 1;\n\t"
142 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
143
144 "R1.L = %2.L*%2.L (IS);\n\t"
145 "R0 <<= 1;\n\t"
146 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
147
148 "R1.L = %3.L*%3.L (IS);\n\t"
149 "R0 <<= 1;\n\t"
150 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS) || R0 = [%1++];\n\t"
151
152 "R1.L = %4.L*%4.L (IS);\n\t"
153 "R0 <<= 1;\n\t"
154 "A0 -= R1.L*R0.H (IS), A1 -= R1.L*R0.L (M,IS);\n\t"
155
156 "A1 = A1 >>> 16;\n\t"
157 "A0 += A1;\n\t"
158 "%0 = A0;\n\t"
159 : "=&D" (sum), "=a" (C)
160 : "d" (g[0]), "d" (g[1]), "d" (g[2]), "d" (pitch_control), "1" (C)
161 : "R0", "R1", "R2", "A0"
162 );
163 return sum;
164 }
165
166