summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspc/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libspc/cpu')
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.c253
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.h45
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.c244
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.h45
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c198
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.h45
6 files changed, 830 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.c b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.c
new file mode 100644
index 0000000000..7eacc3baf9
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.c
@@ -0,0 +1,253 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007-2010 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 "ldrsh %[t0], [%[samp]] \n"
34 "ldrsh %[t2], [%[fwd]] \n"
35 "ldrsh %[t1], [%[samp], #2] \n"
36 "ldrsh %[t3], [%[fwd], #2] \n"
37 "mul %[out], %[t0], %[t2] \n" /* out= fwd[0]*samp[0] */
38 "ldrsh %[t0], [%[samp], #4] \n"
39 "ldrsh %[t2], [%[rev], #2] \n"
40 "mla %[out], %[t1], %[t3], %[out] \n" /* out+=fwd[1]*samp[1] */
41 "ldrsh %[t1], [%[samp], #6] \n"
42 "ldrsh %[t3], [%[rev]] \n"
43 "mla %[out], %[t0], %[t2], %[out] \n" /* out+=rev[1]*samp[2] */
44 "mla %[out], %[t1], %[t3], %[out] \n" /* out+=rev[0]*samp[3] */
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 int t0;
58
59 asm volatile (
60 "mov %[t0], %[out], asr #11 \n"
61 "mul %[out], %[t0], %[envx] \n"
62 : [out]"+r"(output), [t0]"=&r"(t0)
63 : [envx]"r"((int) voice->envx));
64
65 asm volatile (
66 "mov %[out], %[out], asr #11 \n"
67 "mul %[a0], %[out], %[v0] \n"
68 "mul %[a1], %[out], %[v1] \n"
69 : [out]"+r"(output),
70 [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
71 : [v0]"r"((int) voice->volume [0]),
72 [v1]"r"((int) voice->volume [1]));
73
74 return output;
75}
76
77#define SPC_GAUSSIAN_SLOW_INTERP
78static inline int gaussian_slow_interp( int16_t const* samples,
79 int32_t position,
80 int16_t const* fwd,
81 int16_t const* rev )
82{
83 int output;
84 int t0, t1, t2, t3;
85
86 asm volatile (
87 "ldrsh %[t0], [%[samp]] \n"
88 "ldrsh %[t2], [%[fwd]] \n"
89 "ldrsh %[t1], [%[samp], #2] \n"
90 "ldrsh %[t3], [%[fwd], #2] \n"
91 "mul %[out], %[t2], %[t0] \n" /* fwd[0]*samp[0] */
92 "ldrsh %[t2], [%[rev], #2] \n"
93 "mul %[t0], %[t3], %[t1] \n" /* fwd[1]*samp[1] */
94 "ldrsh %[t1], [%[samp], #4] \n"
95 "mov %[out], %[out], asr #12 \n"
96 "ldrsh %[t3], [%[rev]] \n"
97 "mul %[t2], %[t1], %[t2] \n" /* rev[1]*samp[2] */
98 "ldrsh %[t1], [%[samp], #6] \n"
99 "add %[t0], %[out], %[t0], asr #12 \n"
100 "mul %[t3], %[t1], %[t3] \n" /* rev[0]*samp[3] */
101 "add %[t2], %[t0], %[t2], asr #12 \n"
102 "mov %[t2], %[t2], lsl #17 \n"
103 "mov %[t3], %[t3], asr #12 \n"
104 "mov %[t3], %[t3], asl #1 \n"
105 "add %[out], %[t3], %[t2], asr #16 \n"
106 : [out]"=&r"(output),
107 [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=&r"(t3)
108 : [fwd]"r"(fwd), [rev]"r"(rev),
109 [samp]"r"(samples + (position >> 12)));
110
111 return CLAMP16( output );
112}
113
114#define SPC_GAUSSIAN_SLOW_AMP
115static inline int gaussian_slow_amp( struct voice_t* voice, int output,
116 int* amp_0, int* amp_1 )
117{
118 int t0;
119
120 asm volatile (
121 "mul %[t0], %[out], %[envx]"
122 : [t0]"=r"(t0)
123 : [out]"r"(output), [envx]"r"((int) voice->envx));
124 asm volatile (
125 "mov %[t0], %[t0], asr #11 \n"
126 "bic %[t0], %[t0], #0x1 \n"
127 "mul %[a0], %[t0], %[v0] \n"
128 "mul %[a1], %[t0], %[v1] \n"
129 : [t0]"+r"(t0),
130 [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
131 : [v0]"r"((int) voice->volume [0]),
132 [v1]"r"((int) voice->volume [1]));
133
134 return t0;
135}
136
137#else /* SPC_NOINTERP */
138
139#define SPC_LINEAR_INTERP
140static inline int linear_interp( int16_t const* samples, int32_t position )
141{
142 int output = (int) samples;
143 int y1;
144
145 asm volatile(
146 "mov %[y1], %[f], lsr #12 \n"
147 "eor %[f], %[f], %[y1], lsl #12 \n"
148 "add %[y1], %[y0], %[y1], lsl #1 \n"
149 "ldrsh %[y0], [%[y1], #2] \n"
150 "ldrsh %[y1], [%[y1], #4] \n"
151 "sub %[y1], %[y1], %[y0] \n"
152 "mul %[f], %[y1], %[f] \n"
153 "add %[y0], %[y0], %[f], asr #12 \n"
154 : [f]"+r"(position), [y0]"+r"(output), [y1]"=&r"(y1));
155
156 return output;
157}
158
159#define SPC_LINEAR_AMP
160static inline int linear_amp( struct voice_t* voice, int output,
161 int* amp_0, int* amp_1 )
162{
163 int t0;
164
165 asm volatile(
166 "mul %[t0], %[out], %[envx]"
167 : [t0]"=&r"(t0)
168 : [out]"r"(output), [envx]"r"(voice->envx));
169 asm volatile(
170 "mov %[t0], %[t0], asr #11 \n"
171 "mul %[a1], %[t0], %[v1] \n"
172 "mul %[a0], %[t0], %[v0] \n"
173 : [t0]"+r"(t0),
174 [a0]"=&r"(*amp_0), [a1]"=&r"(*amp_1)
175 : [v0]"r"((int) voice->volume [0]),
176 [v1]"r"((int) voice->volume [1]));
177
178 return t0;
179}
180
181#endif /* !SPC_NOINTERP */
182
183
184#if !SPC_NOECHO
185
186#define SPC_DSP_ECHO_APPLY
187
188/* Echo filter history */
189static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
190 __attribute__(( aligned(FIR_BUF_ALIGN*1) ));
191
192static inline void echo_init( struct Spc_Dsp* this )
193{
194 this->fir.ptr = fir_buf;
195 ci->memset( fir_buf, 0, sizeof fir_buf );
196}
197
198static inline void echo_apply( struct Spc_Dsp* this, uint8_t *echo_ptr,
199 int* out_0, int* out_1 )
200{
201 int t0 = GET_LE16SA( echo_ptr );
202 int t1 = GET_LE16SA( echo_ptr + 2 );
203
204 /* Keep last 8 samples */
205 int32_t *fir_ptr;
206 asm volatile (
207 "add %[p], %[t_p], #8 \n"
208 "bic %[t_p], %[p], %[mask] \n"
209 "str %[t0], [%[p], #-8] \n"
210 "str %[t1], [%[p], #-4] \n"
211 /* duplicate at +8 eliminates wrap checking below */
212 "str %[t0], [%[p], #56] \n"
213 "str %[t1], [%[p], #60] \n"
214 : [p]"=&r"(fir_ptr), [t_p]"+r"(this->fir.ptr)
215 : [t0]"r"(t0), [t1]"r"(t1), [mask]"i"(~FIR_BUF_MASK));
216
217 int32_t *fir_coeff = this->fir.coeff;
218
219 asm volatile (
220 "ldmia %[c]!, { r0-r1 } \n"
221 "ldmia %[p]!, { r4-r5 } \n"
222 "mul %[acc0], r0, %[acc0] \n"
223 "mul %[acc1], r0, %[acc1] \n"
224 "mla %[acc0], r4, r1, %[acc0] \n"
225 "mla %[acc1], r5, r1, %[acc1] \n"
226 "ldmia %[c]!, { r0-r1 } \n"
227 "ldmia %[p]!, { r2-r5 } \n"
228 "mla %[acc0], r2, r0, %[acc0] \n"
229 "mla %[acc1], r3, r0, %[acc1] \n"
230 "mla %[acc0], r4, r1, %[acc0] \n"
231 "mla %[acc1], r5, r1, %[acc1] \n"
232 "ldmia %[c]!, { r0-r1 } \n"
233 "ldmia %[p]!, { r2-r5 } \n"
234 "mla %[acc0], r2, r0, %[acc0] \n"
235 "mla %[acc1], r3, r0, %[acc1] \n"
236 "mla %[acc0], r4, r1, %[acc0] \n"
237 "mla %[acc1], r5, r1, %[acc1] \n"
238 "ldmia %[c]!, { r0-r1 } \n"
239 "ldmia %[p]!, { r2-r5 } \n"
240 "mla %[acc0], r2, r0, %[acc0] \n"
241 "mla %[acc1], r3, r0, %[acc1] \n"
242 "mla %[acc0], r4, r1, %[acc0] \n"
243 "mla %[acc1], r5, r1, %[acc1] \n"
244 : [acc0]"+r"(t0), [acc1]"+r"(t1),
245 [p]"+r"(fir_ptr), [c]"+r"(fir_coeff)
246 :
247 : "r0", "r1", "r2", "r3", "r4", "r5");
248
249 *out_0 = t0;
250 *out_1 = t1;
251}
252
253#endif /* SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.h b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.h
new file mode 100644
index 0000000000..c9985e124a
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv4.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007-2010 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_NOECHO
22
23#define SPC_DSP_ECHO_APPLY
24
25enum
26{
27 FIR_BUF_CNT = FIR_BUF_HALF * 2 * 2,
28 FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
29 FIR_BUF_ALIGN = FIR_BUF_SIZE,
30 FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) * 2 - 1))
31};
32
33/* Echo filter structure embedded in struct Spc_Dsp */
34struct echo_filter
35{
36 /* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
37 int32_t* ptr;
38 /* FIR history is interleaved with guard to eliminate wrap checking
39 * when convolving.
40 * |LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|LL|RR|...
41 * |--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--| */
42 /* copy of echo FIR constants as int32_t, for faster access */
43 int32_t coeff [VOICE_COUNT];
44};
45#endif /* SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.c b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.c
new file mode 100644
index 0000000000..2e3de87613
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.c
@@ -0,0 +1,244 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 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 /* NOTE: often-unaligned accesses */
34 "ldr %[t0], [%[samp]] \n" /* t0=i0i1 */
35 "ldr %[t2], [%[fwd]] \n" /* t2=f0f1 */
36 "ldr %[t1], [%[samp], #4] \n" /* t1=i2i3 */
37 "ldr %[t3], [%[rev]] \n" /* t3=r0r1 */
38 "smuad %[out], %[t0], %[t2] \n" /* out=f0*i0+f1*i1 */
39 "smladx %[out], %[t1], %[t3], %[out] \n" /* out+=r1*i2+r0*i3 */
40 : [out]"=r"(output),
41 [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=r"(t3)
42 : [fwd]"r"(fwd), [rev]"r"(rev),
43 [samp]"r"(samples + (position >> 12)));
44
45 return output;
46}
47
48#define SPC_GAUSSIAN_FAST_AMP
49static inline int gaussian_fast_amp( struct voice_t* voice, int output,
50 int* amp_0, int* amp_1 )
51{
52 int t0;
53
54 asm volatile (
55 "mov %[t0], %[out], asr #(11-5) \n" /* To do >> 16 below */
56 "mul %[out], %[t0], %[envx] \n"
57 : [out]"+r"(output), [t0]"=&r"(t0)
58 : [envx]"r"((int) voice->envx));
59
60 asm volatile (
61 "smulwb %[a0], %[out], %[v0] \n" /* amp * vol >> 16 */
62 "smulwb %[a1], %[out], %[v1] \n"
63 : [a0]"=&r"(*amp_0), [a1]"=r"(*amp_1)
64 : [out]"r"(output),
65 [v0]"r"(voice->volume [0]),
66 [v1]"r"(voice->volume [1]));
67
68 return output >> 5; /* 'output' still 5 bits too big */
69}
70
71#define SPC_GAUSSIAN_SLOW_INTERP
72static inline int gaussian_slow_interp( int16_t const* samples,
73 int32_t position,
74 int16_t const* fwd,
75 int16_t const* rev )
76{
77 int output;
78 int t0, t1, t2, t3;
79
80 asm volatile (
81 /* NOTE: often-unaligned accesses */
82 "ldr %[t0], [%[samp]] \n" /* t0=i0i1 */
83 "ldr %[t2], [%[fwd]] \n" /* t2=f0f1 */
84 "ldr %[t1], [%[samp], #4] \n" /* t1=i2i3 */
85 "ldr %[t3], [%[rev]] \n" /* t3=f2f3 */
86 "smulbb %[out], %[t0], %[t2] \n" /* out=f0*i0 */
87 "smultt %[t0], %[t0], %[t2] \n" /* t0=f1*i1 */
88 "smulbt %[t2], %[t1], %[t3] \n" /* t2=r1*i2 */
89 "smultb %[t3], %[t1], %[t3] \n" /* t3=r0*i3 */
90 : [out]"=r"(output),
91 [t0]"=&r"(t0), [t1]"=&r"(t1), [t2]"=&r"(t2), [t3]"=r"(t3)
92 : [fwd]"r"(fwd), [rev]"r"(rev),
93 [samp]"r"(samples + (position >> 12)));
94
95 asm volatile (
96 "mov %[out], %[out], asr #12 \n"
97 "add %[t0], %[out], %[t0], asr #12 \n"
98 "add %[t2], %[t0], %[t2], asr #12 \n"
99 "pkhbt %[t0], %[t2], %[t3], asl #4 \n" /* t3[31:16], t2[15:0] */
100 "sadd16 %[t0], %[t0], %[t0] \n" /* t3[31:16]*2, t2[15:0]*2 */
101 "qsubaddx %[out], %[t0], %[t0] \n" /* out[15:0]=
102 * sat16(t3[31:16]+t2[15:0]) */
103 : [out]"+r"(output),
104 [t0]"+r"(t0), [t2]"+r"(t2), [t3]"+r"(t3));
105
106 /* output will be sign-extended in next step */
107 return output;
108}
109
110#define SPC_GAUSSIAN_SLOW_AMP
111static inline int gaussian_slow_amp( struct voice_t* voice, int output,
112 int* amp_0, int* amp_1 )
113{
114 asm volatile (
115 "smulbb %[out], %[out], %[envx]"
116 : [out]"+r"(output)
117 : [envx]"r"(voice->envx));
118
119 asm volatile (
120 "mov %[out], %[out], asr #11 \n"
121 "bic %[out], %[out], #0x1 \n"
122 "smulbb %[amp_0], %[out], %[v0] \n"
123 "smulbb %[amp_1], %[out], %[v1] \n"
124 : [out]"+r"(output),
125 [amp_0]"=&r"(*amp_0), [amp_1]"=r"(*amp_1)
126 : [v0]"r"(voice->volume[0]), [v1]"r"(voice->volume[1]));
127
128 return output;
129}
130
131#endif /* !SPC_NOINTERP */
132
133#if !SPC_NOECHO
134
135#define SPC_DSP_ECHO_APPLY
136
137/* Echo filter history */
138static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
139 __attribute__(( aligned(FIR_BUF_ALIGN*1) ));
140
141static inline void echo_init( struct Spc_Dsp* this )
142{
143 this->fir.ptr = fir_buf;
144 ci->memset( fir_buf, 0, sizeof fir_buf );
145}
146
147static inline void echo_apply(struct Spc_Dsp* this,
148 uint8_t* const echo_ptr, int* out_0, int* out_1)
149{
150 /* Keep last 8 samples */
151 int32_t* fir_ptr;
152 int t0;
153 asm volatile (
154 "ldr %[t0], [%[ep]] \n"
155 "add %[p], %[t_p], #4 \n"
156 "bic %[t_p], %[p], %[mask] \n"
157 "str %[t0], [%[p], #-4] \n"
158 /* duplicate at +8 eliminates wrap checking below */
159 "str %[t0], [%[p], #28] \n"
160 : [p]"=&r"(fir_ptr), [t_p]"+r"(this->fir.ptr),
161 [t0]"=&r"(t0)
162 : [ep]"r"(echo_ptr), [mask]"i"(~FIR_BUF_MASK));
163
164 int32_t* fir_coeff = (int32_t *)this->fir.coeff;
165
166 asm volatile ( /* L0R0 = acc0 */
167 "ldmia %[p]!, { r2-r5 } \n" /* L1R1-L4R4 = r2-r5 */
168 "ldmia %[c]!, { r0-r1 } \n" /* C0C1-C2C3 = r0-r1 */
169 "pkhbt %[acc0], %[t0], r2, asl #16 \n" /* L0R0,L1R1->L0L1,R0R1 */
170 "pkhtb r2, r2, %[t0], asr #16 \n"
171 "smuad %[acc0], %[acc0], r0 \n" /* acc0=L0*C0+L1*C1 */
172 "smuad %[acc1], r2, r0 \n" /* acc1=R0*C0+R1*C1 */
173 "pkhbt %[t0], r3, r4, asl #16 \n" /* L2R2,L3R3->L2L3,R2R3 */
174 "pkhtb r4, r4, r3, asr #16 \n"
175 "smlad %[acc0], %[t0], r1, %[acc0] \n" /* acc0+=L2*C2+L3*C3 */
176 "smlad %[acc1], r4, r1, %[acc1] \n" /* acc1+=R2*C2+R3*C3 */
177 "ldmia %[p], { r2-r4 } \n" /* L5R5-L7R7 = r2-r4 */
178 "ldmia %[c], { r0-r1 } \n" /* C4C5-C6C7 = r0-r1 */
179 "pkhbt %[t0], r5, r2, asl #16 \n" /* L4R4,L5R5->L4L5,R4R5 */
180 "pkhtb r2, r2, r5, asr #16 \n"
181 "smlad %[acc0], %[t0], r0, %[acc0] \n" /* acc0+=L4*C4+L5*C5 */
182 "smlad %[acc1], r2, r0, %[acc1] \n" /* acc1+=R4*C4+R5*C5 */
183 "pkhbt %[t0], r3, r4, asl #16 \n" /* L6R6,L7R7->L6L7,R6R7 */
184 "pkhtb r4, r4, r3, asr #16 \n"
185 "smlad %[acc0], %[t0], r1, %[acc0] \n" /* acc0+=L6*C6+L7*C7 */
186 "smlad %[acc1], r4, r1, %[acc1] \n" /* acc1+=R6*C6+R7*C7 */
187 : [t0]"+r"(t0), [acc0]"=&r"(*out_0), [acc1]"=&r"(*out_1),
188 [p]"+r"(fir_ptr), [c]"+r"(fir_coeff)
189 :
190 : "r0", "r1", "r2", "r3", "r4", "r5");
191}
192
193#define SPC_DSP_ECHO_FEEDBACK
194static inline void echo_feedback(struct Spc_Dsp* this, uint8_t* echo_ptr,
195 int echo_0, int echo_1, int fb_0, int fb_1)
196{
197 int e0, e1;
198 asm volatile (
199 "mov %[e0], %[ei0], asl #7 \n"
200 "mov %[e1], %[ei1], asl #7 \n"
201 "mla %[e0], %[fb0], %[ef], %[e0] \n"
202 "mla %[e1], %[fb1], %[ef], %[e1] \n"
203 : [e0]"=&r"(e0), [e1]"=&r"(e1)
204 : [ei0]"r"(echo_0), [ei1]"r"(echo_1),
205 [fb0]"r"(fb_0), [fb1]"r"(fb_1),
206 [ef]"r"((int)this->r.g.echo_feedback));
207 asm volatile (
208 "ssat %[e0], #16, %[e0], asr #14 \n"
209 "ssat %[e1], #16, %[e1], asr #14 \n"
210 "pkhbt %[e0], %[e0], %[e1], lsl #16 \n"
211 "str %[e0], [%[ep]] \n"
212 : [e0]"+r"(e0), [e1]"+r"(e1)
213 : [ep]"r"((int32_t *)echo_ptr));
214}
215
216#define SPC_DSP_GENERATE_OUTPUT
217static inline void echo_output( struct Spc_Dsp* this, int global_muting,
218 int global_vol_0, int global_vol_1, int chans_0, int chans_1,
219 int fb_0, int fb_1, int* out_0, int* out_1 )
220{
221 int t0, t1;
222
223 asm volatile (
224 "mul %[t0], %[gv0], %[ch0] \n"
225 "mul %[t1], %[gv1], %[ch1] \n"
226 : [t0]"=&r"(t0), [t1]"=r"(t1)
227 : [gv0]"r"(global_vol_0), [gv1]"r"(global_vol_1),
228 [ch0]"r"(chans_0), [ch1]"r"(chans_1));
229 asm volatile (
230 "mla %[t0], %[i0], %[ev0], %[t0] \n"
231 "mla %[t1], %[i1], %[ev1], %[t1] \n"
232 : [t0]"+r"(t0), [t1]"+r"(t1)
233 : [i0]"r"(fb_0), [i1]"r"(fb_1),
234 [ev0]"r"((int)this->r.g.echo_volume_0),
235 [ev1]"r"((int)this->r.g.echo_volume_1));
236 asm volatile (
237 "mov %[o0], %[t0], asr %[gm] \n"
238 "mov %[o1], %[t1], asr %[gm] \n"
239 : [o0]"=&r"(*out_0), [o1]"=r"(*out_1)
240 : [t0]"r"(t0), [t1]"r"(t1),
241 [gm]"r"(global_muting));
242}
243
244#endif /* SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.h b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.h
new file mode 100644
index 0000000000..a36d8166c2
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv6.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 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_NOECHO
22
23#define SPC_DSP_ECHO_APPLY
24
25enum
26{
27 FIR_BUF_CNT = FIR_BUF_HALF * 2,
28 FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
29 FIR_BUF_ALIGN = FIR_BUF_SIZE,
30 FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) - 1))
31};
32
33/* Echo filter structure embedded in struct Spc_Dsp */
34struct echo_filter
35{ /* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
36 int32_t* ptr;
37 /* FIR history is interleaved with guard to eliminate wrap checking
38 * when convolving.
39 * |LR|LR|LR|LR|LR|LR|LR|LR|--|--|--|--|--|--|--|--| */
40 /* copy of echo FIR constants as int16_t, loaded as int32 for
41 * halfword, packed multiples */
42 int16_t coeff [VOICE_COUNT];
43};
44
45#endif /* SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c
new file mode 100644
index 0000000000..b0d14d157e
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c
@@ -0,0 +1,198 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 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_LINEAR_INTERP
24static inline int linear_interp( int16_t const* samples, int32_t position )
25{
26 uint32_t f = position;
27 int32_t y0, y1;
28
29 /**
30 * output = y0 + f*y1 - f*y0
31 */
32 asm volatile (
33 "move.l %[f], %[y1] \n" /* separate frac and whole */
34 "and.l #0xfff, %[f] \n"
35 "asr.l %[sh], %[y1] \n"
36 "move.l 2(%[s], %[y1].l*2), %[y1] \n" /* y0=upper, y1=lower */
37 "mac.w %[f]l, %[y1]l, %%acc0 \n" /* %acc0 = f*y1 */
38 "msac.w %[f]l, %[y1]u, %%acc0 \n" /* %acc0 -= f*y0 */
39 "swap %[y1] \n" /* separate out y0 and sign extend */
40 "movea.w %[y1], %[y0] \n"
41 "movclr.l %%acc0, %[y1] \n" /* fetch, scale down, add y0 */
42 "asr.l %[sh], %[y1] \n" /* output = y0 + (result >> 12) */
43 "add.l %[y0], %[y1] \n"
44 : [f]"+d"(f), [y0]"=&a"(y0), [y1]"=&d"(y1)
45 : [s]"a"(samples), [sh]"d"(12));
46
47 return y1;
48}
49
50#define SPC_LINEAR_AMP
51static inline int linear_amp( struct voice_t* voice, int output,
52 int* amp_0, int* amp_1 )
53{
54 asm volatile (
55 "mac.w %[out]l, %[envx]l, %%acc0"
56 :
57 : [out]"r"(output), [envx]"r"(voice->envx));
58 asm volatile (
59 "movclr.l %%acc0, %[out] \n"
60 "asr.l #8, %[out] \n"
61 "mac.l %[v0], %[out], %%acc0 \n"
62 "mac.l %[v1], %[out], %%acc1 \n"
63 "asr.l #3, %[out] \n"
64 : [out]"+r"(output)
65 : [v0]"r"((int) voice->volume [0]),
66 [v1]"r"((int) voice->volume [1]));
67 asm volatile (
68 "movclr.l %%acc0, %[a0] \n"
69 "asr.l #3, %[a0] \n"
70 "movclr.l %%acc1, %[a1] \n"
71 "asr.l #3, %[a1] \n"
72 : [a0]"=d"(*amp_0), [a1]"=d"(*amp_1));
73
74 return output;
75}
76
77#endif /* SPC_NOINTERP */
78
79
80#if !SPC_NOECHO
81
82#define SPC_DSP_ECHO_APPLY
83
84/* Echo filter history */
85static int32_t fir_buf[FIR_BUF_CNT] IBSS_ATTR_SPC
86 __attribute__(( aligned(FIR_BUF_ALIGN*1) ));
87
88static inline void echo_init( struct Spc_Dsp* this )
89{
90 /* Initialize mask register with the buffer address mask */
91 asm volatile ("move.l %0, %%mask" : : "i"(FIR_BUF_MASK));
92 this->fir.ptr = fir_buf;
93 this->fir.hist_ptr = &fir_buf [1];
94 ci->memset( fir_buf, 0, sizeof fir_buf );
95}
96
97static inline void echo_apply( struct Spc_Dsp* this, uint8_t* echo_ptr,
98 int* out_0, int* out_1 )
99{
100 int t0, t1, t2;
101
102 t1 = swap_odd_even32( *(int32_t *)echo_ptr );
103
104 /* Keep last 8 samples */
105 *this->fir.ptr = t1;
106 this->fir.ptr = this->fir.hist_ptr;
107
108 asm volatile (
109 "move.l (%[c]) , %[t2] \n"
110 "mac.w %[t1]u, %[t2]u, <<, (%[p])+&, %[t0], %%acc0 \n"
111 "mac.w %[t1]l, %[t2]u, <<, (%[p])& , %[t1], %%acc1 \n"
112 "mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
113 "mac.w %[t0]l, %[t2]l, <<, 4(%[c]) , %[t2], %%acc1 \n"
114 "mac.w %[t1]u, %[t2]u, <<, 4(%[p])& , %[t0], %%acc0 \n"
115 "mac.w %[t1]l, %[t2]u, <<, 8(%[p])& , %[t1], %%acc1 \n"
116 "mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
117 "mac.w %[t0]l, %[t2]l, <<, 8(%[c]) , %[t2], %%acc1 \n"
118 "mac.w %[t1]u, %[t2]u, <<, 12(%[p])& , %[t0], %%acc0 \n"
119 "mac.w %[t1]l, %[t2]u, <<, 16(%[p])& , %[t1], %%acc1 \n"
120 "mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
121 "mac.w %[t0]l, %[t2]l, <<, 12(%[c]) , %[t2], %%acc1 \n"
122 "mac.w %[t1]u, %[t2]u, <<, 20(%[p])& , %[t0], %%acc0 \n"
123 "mac.w %[t1]l, %[t2]u, << , %%acc1 \n"
124 "mac.w %[t0]u, %[t2]l, << , %%acc0 \n"
125 "mac.w %[t0]l, %[t2]l, << , %%acc1 \n"
126 : [t0]"=&r"(t0), [t1]"+r"(t1), [t2]"=&r"(t2),
127 [p]"+a"(this->fir.hist_ptr)
128 : [c]"a"(this->fir.coeff));
129 asm volatile (
130 "movclr.l %%acc0, %[o0] \n"
131 "movclr.l %%acc1, %[o1] \n"
132 "mac.l %[ev0], %[o0], >>, %%acc2 \n" /* echo volume */
133 "mac.l %[ev1], %[o1], >>, %%acc3 \n"
134 : [o0]"=&r"(*out_0), [o1]"=&r"(*out_1)
135 : [ev0]"r"((int) this->r.g.echo_volume_0),
136 [ev1]"r"((int) this->r.g.echo_volume_1));
137}
138
139#define SPC_DSP_ECHO_FEEDBACK
140static inline void echo_feedback( struct Spc_Dsp* this, uint8_t* echo_ptr,
141 int echo_0, int echo_1, int fb_0, int fb_1 )
142{
143 asm volatile (
144 /* scale echo voices; saturate if overflow */
145 "mac.l %[sh], %[e1] , %%acc1 \n"
146 "mac.l %[sh], %[e0] , %%acc0 \n"
147 /* add scaled output from FIR filter */
148 "mac.l %[fb1], %[ef], <<, %%acc1 \n"
149 "mac.l %[fb0], %[ef], <<, %%acc0 \n"
150 :
151 : [e0]"d"(echo_0), [e1]"d"(echo_1),
152 [fb0]"r"(fb_0), [fb1]"r"(fb_1),
153 [ef]"r"((int)this->r.g.echo_feedback),
154 [sh]"r"(1 << 9));
155 /* swap and fetch feedback results */
156 int t0;
157 asm volatile(
158 "move.l #0x00ff00ff, %[t0] \n"
159 "movclr.l %%acc1, %[e1] \n"
160 "swap.w %[e1] \n"
161 "movclr.l %%acc0, %[e0] \n"
162 "move.w %[e1], %[e0] \n"
163 "and.l %[e0], %[t0] \n"
164 "eor.l %[t0], %[e0] \n"
165 "lsl.l #8, %[t0] \n"
166 "lsr.l #8, %[e0] \n"
167 "or.l %[e0], %[t0] \n"
168 : [e0]"=&d"(echo_0), [e1]"=&d"(echo_1),
169 [t0]"=&d"(t0));
170
171 /* save final feedback into echo buffer */
172 *(int32_t *)echo_ptr = t0;
173}
174
175#define SPC_DSP_GENERATE_OUTPUT
176static inline void echo_output( struct Spc_Dsp* this, int global_muting,
177 int global_vol_0, int global_vol_1, int chans_0, int chans_1,
178 int fb_0, int fb_1, int* out_0, int* out_1 )
179{
180 asm volatile (
181 "mac.l %[ch0], %[gv0], %%acc2 \n" /* global volume */
182 "mac.l %[ch1], %[gv1], %%acc3 \n"
183 :
184 : [ch0]"r"(chans_0), [gv0]"r"(global_vol_0),
185 [ch1]"r"(chans_1), [gv1]"r"(global_vol_1));
186 asm volatile (
187 "movclr.l %%acc2, %[a0] \n" /* fetch mixed output */
188 "movclr.l %%acc3, %[a1] \n"
189 "asr.l %[gm], %[a0] \n" /* scale by global_muting shift */
190 "asr.l %[gm], %[a1] \n"
191 : [a0]"=&d"(*out_0), [a1]"=&d"(*out_1)
192 : [gm]"d"(global_muting));
193
194 /* scaled echo is stored in %acc2 and %acc3 */
195 (void)this; (void)fb_0; (void)fb_1;
196}
197
198#endif /* !SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.h b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.h
new file mode 100644
index 0000000000..f9aafabd18
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 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_NOECHO
22
23#define SPC_DSP_ECHO_APPLY
24
25enum
26{
27 FIR_BUF_CNT = FIR_BUF_HALF,
28 FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
29 FIR_BUF_ALIGN = FIR_BUF_SIZE * 2,
30 FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) - 1))
31};
32
33/* Echo filter structure embedded in struct Spc_Dsp */
34struct echo_filter
35{
36 /* FIR history is interleaved. Hardware handles wrapping by mask.
37 * |LR|LR|LR|LR|LR|LR|LR|LR| */
38 int32_t* ptr;
39 /* wrapped address just behind current position -
40 allows mac.w to increment and mask ptr */
41 int32_t* hist_ptr;
42 /* copy of echo FIR constants as int16_t for use with mac.w */
43 int16_t coeff [VOICE_COUNT];
44};
45#endif /* !SPC_NOECHO */