1 /* Copyright (C) 2004 Jean-Marc Valin */
2 /**
3 @file filters_arm4.h
4 @brief Various analysis/synthesis filters (ARM4 version)
5 */
6 /*
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17
18 - Neither the name of the Xiph.org Foundation nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #define OVERRIDE_NORMALIZE16
normalize16(const spx_sig_t * x,spx_word16_t * y,int max_scale,int len)36 int normalize16(const spx_sig_t *x, spx_word16_t *y, int max_scale, int len)
37 {
38 int i;
39 spx_sig_t max_val=1;
40 int sig_shift;
41 int dead1, dead2, dead3, dead4, dead5, dead6;
42
43 __asm__ __volatile__ (
44 "\tmov %1, #1 \n"
45 "\tmov %3, #0 \n"
46
47 ".normalize16loop1%=: \n"
48
49 "\tldr %4, [%0], #4 \n"
50 "\tcmps %4, %1 \n"
51 "\tmovgt %1, %4 \n"
52 "\tcmps %4, %3 \n"
53 "\tmovlt %3, %4 \n"
54
55 "\tsubs %2, %2, #1 \n"
56 "\tbne .normalize16loop1%=\n"
57
58 "\trsb %3, %3, #0 \n"
59 "\tcmp %1, %3 \n"
60 "\tmovlt %1, %3 \n"
61 : "=r" (dead1), "=r" (max_val), "=r" (dead3), "=r" (dead4),
62 "=r" (dead5), "=r" (dead6)
63 : "0" (x), "2" (len)
64 : "cc");
65
66 sig_shift=0;
67 while (max_val>max_scale)
68 {
69 sig_shift++;
70 max_val >>= 1;
71 }
72
73 __asm__ __volatile__ (
74 ".normalize16loop%=: \n"
75
76 "\tldr %4, [%0], #4 \n"
77 "\tldr %5, [%0], #4 \n"
78 "\tmov %4, %4, asr %3 \n"
79 "\tstrh %4, [%1], #2 \n"
80 "\tldr %4, [%0], #4 \n"
81 "\tmov %5, %5, asr %3 \n"
82 "\tstrh %5, [%1], #2 \n"
83 "\tldr %5, [%0], #4 \n"
84 "\tmov %4, %4, asr %3 \n"
85 "\tstrh %4, [%1], #2 \n"
86 "\tsubs %2, %2, #1 \n"
87 "\tmov %5, %5, asr %3 \n"
88 "\tstrh %5, [%1], #2 \n"
89
90 "\tbge .normalize16loop%=\n"
91 : "=r" (dead1), "=r" (dead2), "=r" (dead3), "=r" (dead4),
92 "=r" (dead5), "=r" (dead6)
93 : "0" (x), "1" (y), "2" (len>>2), "3" (sig_shift)
94 : "cc", "memory");
95 return sig_shift;
96 }
97
98 #define OVERRIDE_FILTER_MEM2
filter_mem2(const spx_sig_t * x,const spx_coef_t * num,const spx_coef_t * den,spx_sig_t * y,int N,int ord,spx_mem_t * mem)99 void filter_mem2(const spx_sig_t *x, const spx_coef_t *num, const spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
100 {
101 int i,j;
102 spx_sig_t xi,yi,nyi;
103
104 for (i=0;i<N;i++)
105 {
106 int deadm, deadn, deadd, deadidx, x1, y1, dead1, dead2, dead3, dead4, dead5, dead6;
107 xi=SATURATE(x[i],805306368);
108 yi = SATURATE(ADD32(xi, SHL(mem[0],2)),805306368);
109 nyi = -yi;
110 y[i] = yi;
111 __asm__ __volatile__ (
112 "\tldrsh %6, [%1], #2\n"
113 "\tsmull %8, %9, %4, %6\n"
114 #ifdef SHORTCUTS
115 "\tldrsh %6, [%2], #2\n"
116 "\tldr %10, [%0, #4]\n"
117 "\tmov %8, %8, lsr #15\n"
118 "\tsmull %7, %11, %5, %6\n"
119 "\tldrsh %6, [%1], #2\n"
120 "\tadd %8, %8, %9, lsl #17\n"
121 "\tadd %10, %10, %8\n"
122 "\tsmull %8, %9, %4, %6\n"
123 "\tadd %10, %10, %7, lsr #15\n"
124 "\tadd %10, %10, %11, lsl #17\n"
125 "\tstr %10, [%0], #4 \n"
126
127 "\tldrsh %6, [%2], #2\n"
128 "\tldr %10, [%0, #4]\n"
129 "\tmov %8, %8, lsr #15\n"
130 "\tsmull %7, %11, %5, %6\n"
131 "\tldrsh %6, [%1], #2\n"
132 "\tadd %8, %8, %9, lsl #17\n"
133 "\tadd %10, %10, %8\n"
134 "\tsmull %8, %9, %4, %6\n"
135 "\tadd %10, %10, %7, lsr #15\n"
136 "\tadd %10, %10, %11, lsl #17\n"
137 "\tstr %10, [%0], #4 \n"
138
139 "\tldrsh %6, [%2], #2\n"
140 "\tldr %10, [%0, #4]\n"
141 "\tmov %8, %8, lsr #15\n"
142 "\tsmull %7, %11, %5, %6\n"
143 "\tldrsh %6, [%1], #2\n"
144 "\tadd %8, %8, %9, lsl #17\n"
145 "\tadd %10, %10, %8\n"
146 "\tsmull %8, %9, %4, %6\n"
147 "\tadd %10, %10, %7, lsr #15\n"
148 "\tadd %10, %10, %11, lsl #17\n"
149 "\tstr %10, [%0], #4 \n"
150
151 "\tldrsh %6, [%2], #2\n"
152 "\tldr %10, [%0, #4]\n"
153 "\tmov %8, %8, lsr #15\n"
154 "\tsmull %7, %11, %5, %6\n"
155 "\tldrsh %6, [%1], #2\n"
156 "\tadd %8, %8, %9, lsl #17\n"
157 "\tadd %10, %10, %8\n"
158 "\tsmull %8, %9, %4, %6\n"
159 "\tadd %10, %10, %7, lsr #15\n"
160 "\tadd %10, %10, %11, lsl #17\n"
161 "\tstr %10, [%0], #4 \n"
162
163 "\tldrsh %6, [%2], #2\n"
164 "\tldr %10, [%0, #4]\n"
165 "\tmov %8, %8, lsr #15\n"
166 "\tsmull %7, %11, %5, %6\n"
167 "\tldrsh %6, [%1], #2\n"
168 "\tadd %8, %8, %9, lsl #17\n"
169 "\tadd %10, %10, %8\n"
170 "\tsmull %8, %9, %4, %6\n"
171 "\tadd %10, %10, %7, lsr #15\n"
172 "\tadd %10, %10, %11, lsl #17\n"
173 "\tstr %10, [%0], #4 \n"
174
175 "\tldrsh %6, [%2], #2\n"
176 "\tldr %10, [%0, #4]\n"
177 "\tmov %8, %8, lsr #15\n"
178 "\tsmull %7, %11, %5, %6\n"
179 "\tldrsh %6, [%1], #2\n"
180 "\tadd %8, %8, %9, lsl #17\n"
181 "\tadd %10, %10, %8\n"
182 "\tsmull %8, %9, %4, %6\n"
183 "\tadd %10, %10, %7, lsr #15\n"
184 "\tadd %10, %10, %11, lsl #17\n"
185 "\tstr %10, [%0], #4 \n"
186
187 "\tldrsh %6, [%2], #2\n"
188 "\tldr %10, [%0, #4]\n"
189 "\tmov %8, %8, lsr #15\n"
190 "\tsmull %7, %11, %5, %6\n"
191 "\tldrsh %6, [%1], #2\n"
192 "\tadd %8, %8, %9, lsl #17\n"
193 "\tadd %10, %10, %8\n"
194 "\tsmull %8, %9, %4, %6\n"
195 "\tadd %10, %10, %7, lsr #15\n"
196 "\tadd %10, %10, %11, lsl #17\n"
197 "\tstr %10, [%0], #4 \n"
198
199 "\tldrsh %6, [%2], #2\n"
200 "\tldr %10, [%0, #4]\n"
201 "\tmov %8, %8, lsr #15\n"
202 "\tsmull %7, %11, %5, %6\n"
203 "\tldrsh %6, [%1], #2\n"
204 "\tadd %8, %8, %9, lsl #17\n"
205 "\tadd %10, %10, %8\n"
206 "\tsmull %8, %9, %4, %6\n"
207 "\tadd %10, %10, %7, lsr #15\n"
208 "\tadd %10, %10, %11, lsl #17\n"
209 "\tstr %10, [%0], #4 \n"
210
211 "\tldrsh %6, [%2], #2\n"
212 "\tldr %10, [%0, #4]\n"
213 "\tmov %8, %8, lsr #15\n"
214 "\tsmull %7, %11, %5, %6\n"
215 "\tldrsh %6, [%1], #2\n"
216 "\tadd %8, %8, %9, lsl #17\n"
217 "\tadd %10, %10, %8\n"
218 "\tsmull %8, %9, %4, %6\n"
219 "\tadd %10, %10, %7, lsr #15\n"
220 "\tadd %10, %10, %11, lsl #17\n"
221 "\tstr %10, [%0], #4 \n"
222
223
224 #else
225 ".filterloop%=: \n"
226 "\tldrsh %6, [%2], #2\n"
227 "\tldr %10, [%0, #4]\n"
228 "\tmov %8, %8, lsr #15\n"
229 "\tsmull %7, %11, %5, %6\n"
230 "\tadd %8, %8, %9, lsl #17\n"
231 "\tldrsh %6, [%1], #2\n"
232 "\tadd %10, %10, %8\n"
233 "\tsmull %8, %9, %4, %6\n"
234 "\tadd %10, %10, %7, lsr #15\n"
235 "\tsubs %3, %3, #1\n"
236 "\tadd %10, %10, %11, lsl #17\n"
237 "\tstr %10, [%0], #4 \n"
238 "\t bne .filterloop%=\n"
239 #endif
240 "\tmov %8, %8, lsr #15\n"
241 "\tadd %10, %8, %9, lsl #17\n"
242 "\tldrsh %6, [%2], #2\n"
243 "\tsmull %8, %9, %5, %6\n"
244 "\tadd %10, %10, %8, lsr #15\n"
245 "\tadd %10, %10, %9, lsl #17\n"
246 "\tstr %10, [%0], #4 \n"
247
248 : "=r" (deadm), "=r" (deadn), "=r" (deadd), "=r" (deadidx),
249 "=r" (xi), "=r" (nyi), "=r" (dead1), "=r" (dead2),
250 "=r" (dead3), "=r" (dead4), "=r" (dead5), "=r" (dead6)
251 : "0" (mem), "1" (num), "2" (den), "3" (ord-1), "4" (xi), "5" (nyi)
252 : "cc", "memory");
253
254 }
255 }
256
257 #define OVERRIDE_IIR_MEM2
iir_mem2(const spx_sig_t * x,const spx_coef_t * den,spx_sig_t * y,int N,int ord,spx_mem_t * mem)258 void iir_mem2(const spx_sig_t *x, const spx_coef_t *den, spx_sig_t *y, int N, int ord, spx_mem_t *mem)
259 {
260 int i,j;
261 spx_sig_t xi,yi,nyi;
262
263 for (i=0;i<N;i++)
264 {
265 int deadm, deadd, deadidx, dead1, dead2, dead3, dead4, dead5, dead6;
266 xi=SATURATE(x[i],805306368);
267 yi = SATURATE(ADD32(xi, SHL(mem[0],2)),805306368);
268 nyi = -yi;
269 y[i] = yi;
270 __asm__ __volatile__ (
271 "\tldrsh %4, [%1], #2\n"
272 "\tsmull %5, %6, %3, %4\n"
273
274 #ifdef SHORTCUTS
275
276 "\tldrsh %4, [%1], #2\n"
277 "\tmov %5, %5, lsr #15\n"
278 "\tldr %7, [%0, #4]\n"
279 "\tadd %8, %5, %6, lsl #17\n"
280 "\tsmull %5, %6, %3, %4\n"
281 "\tadd %7, %7, %8\n"
282 "\tstr %7, [%0], #4 \n"
283
284
285 "\tldrsh %4, [%1], #2\n"
286 "\tmov %5, %5, lsr #15\n"
287 "\tldr %9, [%0, #4]\n"
288 "\tadd %8, %5, %6, lsl #17\n"
289 "\tsmull %5, %6, %3, %4\n"
290 "\tadd %9, %9, %8\n"
291 "\tstr %9, [%0], #4 \n"
292
293 "\tldrsh %4, [%1], #2\n"
294 "\tmov %5, %5, lsr #15\n"
295 "\tldr %7, [%0, #4]\n"
296 "\tadd %8, %5, %6, lsl #17\n"
297 "\tsmull %5, %6, %3, %4\n"
298 "\tadd %7, %7, %8\n"
299 "\tstr %7, [%0], #4 \n"
300
301
302 "\tldrsh %4, [%1], #2\n"
303 "\tmov %5, %5, lsr #15\n"
304 "\tldr %9, [%0, #4]\n"
305 "\tadd %8, %5, %6, lsl #17\n"
306 "\tsmull %5, %6, %3, %4\n"
307 "\tadd %9, %9, %8\n"
308 "\tstr %9, [%0], #4 \n"
309
310 "\tldrsh %4, [%1], #2\n"
311 "\tmov %5, %5, lsr #15\n"
312 "\tldr %7, [%0, #4]\n"
313 "\tadd %8, %5, %6, lsl #17\n"
314 "\tsmull %5, %6, %3, %4\n"
315 "\tadd %7, %7, %8\n"
316 "\tstr %7, [%0], #4 \n"
317
318
319 "\tldrsh %4, [%1], #2\n"
320 "\tmov %5, %5, lsr #15\n"
321 "\tldr %9, [%0, #4]\n"
322 "\tadd %8, %5, %6, lsl #17\n"
323 "\tsmull %5, %6, %3, %4\n"
324 "\tadd %9, %9, %8\n"
325 "\tstr %9, [%0], #4 \n"
326
327 "\tldrsh %4, [%1], #2\n"
328 "\tmov %5, %5, lsr #15\n"
329 "\tldr %7, [%0, #4]\n"
330 "\tadd %8, %5, %6, lsl #17\n"
331 "\tsmull %5, %6, %3, %4\n"
332 "\tadd %7, %7, %8\n"
333 "\tstr %7, [%0], #4 \n"
334
335
336 "\tldrsh %4, [%1], #2\n"
337 "\tmov %5, %5, lsr #15\n"
338 "\tldr %9, [%0, #4]\n"
339 "\tadd %8, %5, %6, lsl #17\n"
340 "\tsmull %5, %6, %3, %4\n"
341 "\tadd %9, %9, %8\n"
342 "\tstr %9, [%0], #4 \n"
343
344 "\tldrsh %4, [%1], #2\n"
345 "\tmov %5, %5, lsr #15\n"
346 "\tldr %7, [%0, #4]\n"
347 "\tadd %8, %5, %6, lsl #17\n"
348 "\tsmull %5, %6, %3, %4\n"
349 "\tadd %7, %7, %8\n"
350 "\tstr %7, [%0], #4 \n"
351
352
353
354 #else
355 ".iirloop%=: \n"
356 "\tldr %7, [%0, #4]\n"
357
358 "\tldrsh %4, [%1], #2\n"
359 "\tmov %5, %5, lsr #15\n"
360 "\tadd %8, %5, %6, lsl #17\n"
361 "\tsmull %5, %6, %3, %4\n"
362 "\tadd %7, %7, %8\n"
363 "\tstr %7, [%0], #4 \n"
364 "\tsubs %2, %2, #1\n"
365 "\t bne .iirloop%=\n"
366
367 #endif
368 "\tmov %5, %5, lsr #15\n"
369 "\tadd %7, %5, %6, lsl #17\n"
370 "\tstr %7, [%0], #4 \n"
371
372 : "=r" (deadm), "=r" (deadd), "=r" (deadidx), "=r" (nyi),
373 "=r" (dead1), "=r" (dead2), "=r" (dead3), "=r" (dead4),
374 "=r" (dead5), "=r" (dead6)
375 : "0" (mem), "1" (den), "2" (ord-1), "3" (nyi)
376 : "cc", "memory");
377
378 }
379 }
380