summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c')
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c238
1 files changed, 238 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c
new file mode 100644
index 0000000000..dd08e9edef
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c
@@ -0,0 +1,238 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2013 Michael Sevakis (jhMikeS)
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#if !SPC_NOINTERP
22
23#define SPC_GAUSSIAN_FAST_INTERP
24static inline int gaussian_fast_interp( int16_t const* samples,
25 int32_t position,
26 int16_t const* fwd,
27 int16_t const* rev )
28{
29 int output;
30 int t0, t1, t2, t3;
31
32 asm volatile (
33 "ldrh %[t0], [%[samp]] \n" /* t0=s0 */
34 "ldrh %[t2], [%[fwd]] \n" /* t2=f0 */
35 "ldrh %[t1], [%[samp], #2] \n" /* t1=s1 */
36 "ldrh %[t3], [%[fwd], #2] \n" /* r3=f1 */
37 "smulbb %[out], %[t0], %[t2] \n" /* out=s0*f0 */
38 "ldrh %[t2], [%[rev], #2] \n" /* r2=r1 */
39 "ldrh %[t0], [%[samp], #4] \n" /* t0=s2 */
40 "smlabb %[out], %[t1], %[t3], %[out] \n" /* out+=s1*f1 */
41 "ldrh %[t3], [%[rev]] \n" /* t3=r0 */
42 "ldrh %[t1], [%[samp], #6] \n" /* t1=s3 */
43 "smlabb %[out], %[t0], %[t2], %[out] \n" /* out+=s2*r1 */
44 "smlabb %[out], %[t1], %[t3], %[out] \n" /* out+=s3*r0 */
45 : [out]"=&r"(output),
46 [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3)
47 : [fwd]"r"(fwd), [rev]"r"(rev),
48 [samp]"r"(samples + (position >> 12)));
49
50 return output;
51}
52
53#define SPC_GAUSSIAN_FAST_AMP
54static inline int gaussian_fast_amp( struct voice_t* voice, int output,
55 int* amp_0, int* amp_1 )
56{
57 asm volatile (
58 "mov %[out], %[out], asr #15 \n"
59 "smulbb %[out], %[out], %[envx] \n"
60 : [out]"+r"(output)
61 : [envx]"r"(voice->envx));
62 asm volatile (
63 "mov %[out], %[out], asr #11 \n"
64 "smulbb %[a0], %[out], %[v0] \n"
65 "smulbb %[a1], %[out], %[v1] \n"
66 : [out]"+r"(output),
67 [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
68 : [v0]"r"(voice->volume [0]),
69 [v1]"r"(voice->volume [1]));
70
71 return output;
72}
73
74#define SPC_GAUSSIAN_SLOW_INTERP
75static inline int gaussian_slow_interp( int16_t const* samples,
76 int32_t position,
77 int16_t const* fwd,
78 int16_t const* rev )
79{
80 int output;
81 int t0, t1, t2, t3;
82 asm volatile (
83 "ldrsh %[t0], [%[samp]] \n" /* t0=s0 */
84 "ldrh %[t2], [%[fwd]] \n" /* t2=f0 */
85 "ldrsh %[t1], [%[samp], #2] \n" /* t1=s1 */
86 "ldrh %[t3], [%[fwd], #2] \n" /* t3=f1 */
87 "smulwb %[out], %[t0], %[t2] \n" /* out=s0*f0>>16 */
88 "ldrsh %[t0], [%[samp], #4] \n" /* t0=s2 */
89 "ldrh %[t2], [%[rev], #2] \n" /* t2=r1 */
90 "smlawb %[out], %[t1], %[t3], %[out] \n" /* out+=s1*f1>>16 */
91 "ldrsh %[t1], [%[samp], #6] \n" /* t1=s3 */
92 "ldrh %[t3], [%[rev]] \n" /* t3=r0 */
93 "smlawb %[out], %[t0], %[t2], %[out] \n" /* out+=s2*r1>>16 */
94 "smulwb %[t0], %[t1], %[t3] \n" /* t0=s3*r0>>16 */
95 "mov %[out], %[out], asl #17 \n" /* out=(int16_t)(out*2) */
96 "mov %[t0], %[t0], asl #1 \n" /* out+=t0*2 */
97 "add %[out], %[t0], %[out], asr #16 \n"
98 : [out]"=&r"(output),
99 [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3)
100 : [fwd]"r"(fwd), [rev]"r"(rev),
101 [samp]"r"(samples + (position >> 12)));
102
103 return CLAMP16( output );
104}
105
106#define SPC_GAUSSIAN_SLOW_AMP
107static inline int gaussian_slow_amp( struct voice_t* voice, int output,
108 int* amp_0, int* amp_1 )
109{
110 asm volatile (
111 "smulbb %[out], %[out], %[envx]"
112 : [out]"+r"(output)
113 : [envx]"r"(voice->envx));
114 asm volatile (
115 "mov %[out], %[out], asr #11 \n"
116 "bic %[out], %[out], #0x1 \n"
117 "smulbb %[a0], %[out], %[v0] \n"
118 "smulbb %[a1], %[out], %[v1] \n"
119 : [out]"+r"(output),
120 [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
121 : [v0]"r"(voice->volume [0]), [v1]"r"(voice->volume [1]));
122
123 return output;
124}
125
126#endif /* !SPC_NOINTERP */
127
128
129#if !SPC_NOECHO
130
131#define SPC_DSP_ECHO_APPLY
132
133/* Echo filter history */
134static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
135 __attribute__(( aligned(FIR_BUF_ALIGN*1) ));
136
137static inline void echo_init( struct Spc_Dsp* this )
138{
139 this->fir.ptr = fir_buf;
140 ci->memset( fir_buf, 0, sizeof fir_buf );
141}
142
143static inline void echo_apply( struct Spc_Dsp* this, uint8_t *echo_ptr,
144 int* out_0, int* out_1 )
145{
146 /* Keep last 8 samples */
147 int32_t* fir_ptr;
148 int t0;
149 asm volatile (
150 "ldr %[t0], [%[ep]] \n"
151 "add %[p], %[t_p], #4 \n"
152 "bic %[t_p], %[p], %[mask] \n"
153 "str %[t0], [%[p], #-4] \n"
154 /* duplicate at +8 eliminates wrap checking below */
155 "str %[t0], [%[p], #28] \n"
156 : [p]"=&r"(fir_ptr), [t_p]"+r"(this->fir.ptr),
157 [t0]"=&r"(t0)
158 : [ep]"r"(echo_ptr), [mask]"i"(~FIR_BUF_MASK));
159
160 int32_t* fir_coeff = (int32_t *)this->fir.coeff;
161
162 asm volatile (
163 "ldmia %[c]!, { r0-r1 } \n" /* C0C1-C2C3 = r0-r1 */
164 "ldmia %[p]!, { r2-r5 } \n" /* L1R1-L4R4 = r2-r5 */
165 "smulbb %[acc0], %[t0], r0 \n" /* acc0 = L0*C0 */
166 "smultb %[acc1], %[t0], r0 \n" /* acc1 = R0*C0 */
167 "smlabt %[acc0], r2, r0, %[acc0] \n" /* acc0 += L1*C1 */
168 "smlatt %[acc1], r2, r0, %[acc1] \n" /* acc1 += R1*C1 */
169 "smlabb %[acc0], r3, r1, %[acc0] \n" /* acc0 += L2*C2 */
170 "smlatb %[acc1], r3, r1, %[acc1] \n" /* acc1 += R2*C2 */
171 "smlabt %[acc0], r4, r1, %[acc0] \n" /* acc0 += L3*C3 */
172 "smlatt %[acc1], r4, r1, %[acc1] \n" /* acc1 += R3*C3 */
173 "ldmia %[c], { r0-r1 } \n" /* C4C5-C6C7 = r0-r1 */
174 "ldmia %[p], { r2-r4 } \n" /* L5R5-L7R7 = r2-r5 */
175 "smlabb %[acc0], r5, r0, %[acc0] \n" /* acc0 += L4*C4 */
176 "smlatb %[acc1], r5, r0, %[acc1] \n" /* acc1 += R4*C4 */
177 "smlabt %[acc0], r2, r0, %[acc0] \n" /* acc0 += L5*C5 */
178 "smlatt %[acc1], r2, r0, %[acc1] \n" /* acc1 += R5*C5 */
179 "smlabb %[acc0], r3, r1, %[acc0] \n" /* acc0 += L6*C6 */
180 "smlatb %[acc1], r3, r1, %[acc1] \n" /* acc1 += R6*C6 */
181 "smlabt %[acc0], r4, r1, %[acc0] \n" /* acc0 += L7*C7 */
182 "smlatt %[acc1], r4, r1, %[acc1] \n" /* acc1 += R7*C7 */
183 : [t0]"+r"(t0), [acc0]"=&r"(*out_0), [acc1]"=&r"(*out_1),
184 [p]"+r"(fir_ptr), [c]"+r"(fir_coeff)
185 :
186 : "r0", "r1", "r2", "r3", "r4", "r5");
187}
188
189#define SPC_DSP_ECHO_FEEDBACK
190static inline void echo_feedback(struct Spc_Dsp* this, uint8_t* echo_ptr,
191 int echo_0, int echo_1, int fb_0, int fb_1)
192{
193 int e0, e1;
194 asm volatile (
195 "mov %[e0], %[ei0], asl #7 \n"
196 "mov %[e1], %[ei1], asl #7 \n"
197 "mla %[e0], %[fb0], %[ef], %[e0] \n"
198 "mla %[e1], %[fb1], %[ef], %[e1] \n"
199 : [e0]"=&r"(e0), [e1]"=&r"(e1)
200 : [ei0]"r"(echo_0), [ei1]"r"(echo_1),
201 [fb0]"r"(fb_0), [fb1]"r"(fb_1),
202 [ef]"r"((int)this->r.g.echo_feedback));
203
204 e0 = CLAMP16( e0 >> 14 );
205 SET_LE16A( echo_ptr , e0 );
206 e1 = CLAMP16( e1 >> 14 );
207 SET_LE16A( echo_ptr + 2, e1 );
208}
209
210#define SPC_DSP_GENERATE_OUTPUT
211static inline void echo_output( struct Spc_Dsp* this, int global_muting,
212 int global_vol_0, int global_vol_1, int chans_0, int chans_1,
213 int fb_0, int fb_1, int* out_0, int* out_1 )
214{
215 int t0, t1;
216
217 asm volatile (
218 "mul %[t0], %[gv0], %[ch0] \n"
219 "mul %[t1], %[gv1], %[ch1] \n"
220 : [t0]"=&r"(t0), [t1]"=r"(t1)
221 : [gv0]"r"(global_vol_0), [gv1]"r"(global_vol_1),
222 [ch0]"r"(chans_0), [ch1]"r"(chans_1));
223 asm volatile (
224 "mla %[t0], %[i0], %[ev0], %[t0] \n"
225 "mla %[t1], %[i1], %[ev1], %[t1] \n"
226 : [t0]"+r"(t0), [t1]"+r"(t1)
227 : [i0]"r"(fb_0), [i1]"r"(fb_1),
228 [ev0]"r"((int)this->r.g.echo_volume_0),
229 [ev1]"r"((int)this->r.g.echo_volume_1));
230 asm volatile (
231 "mov %[o0], %[t0], asr %[gm] \n"
232 "mov %[o1], %[t1], asr %[gm] \n"
233 : [o0]"=&r"(*out_0), [o1]"=r"(*out_1)
234 : [t0]"r"(t0), [t1]"r"(t1),
235 [gm]"r"(global_muting));
236}
237
238#endif /* SPC_NOECHO */