summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-05-18 01:45:03 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-05-21 00:02:14 -0400
commit87021f7c0ac4620eafd185ff11905ee643f72b6c (patch)
tree03ae48f3d999cd8743af40cc5df933f64f6df2d2 /lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c
parenta17d6de5bc727b0bb55764ecef2605ae689e8dab (diff)
downloadrockbox-87021f7c0ac4620eafd185ff11905ee643f72b6c.tar.gz
rockbox-87021f7c0ac4620eafd185ff11905ee643f72b6c.zip
SPC Codec: Refactor for CPU and clean up some things.
CPU optimization gets its own files in which to fill-in optimizable routines. Some pointless #if 0's for profiling need removal. Those macros are empty if not profiling. Force some functions that are undesirable to be force-inlined by the compiler to be not inlined. Change-Id: Ia7b7e45380d7efb20c9b1a4d52e05db3ef6bbaab
Diffstat (limited to 'lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c')
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_coldfire.c198
1 files changed, 198 insertions, 0 deletions
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 */