summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-05-22 18:50:28 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-05-23 03:15:12 -0400
commit33f3af2b8dbda1e67f07c9c63a07fb3e9af6fa59 (patch)
tree7ae40e143a1009f736195a7463d65d36ff4c7f0e
parent7738660effc7fcb4eb70a8b408b28af7c682e547 (diff)
downloadrockbox-33f3af2b8dbda1e67f07c9c63a07fb3e9af6fa59.tar.gz
rockbox-33f3af2b8dbda1e67f07c9c63a07fb3e9af6fa59.zip
SPC Codec: Add ARMv5 optimized code. Easy peasy.
Why? Why not? Cuts a few MHz. Change-Id: Ied5c70b1aedd255cbe5d42b7d3028bbe47aad01d
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.c238
-rw-r--r--lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.h30
-rw-r--r--lib/rbcodec/codecs/libspc/spc_codec.h11
-rw-r--r--lib/rbcodec/codecs/libspc/spc_dsp.c13
4 files changed, 291 insertions, 1 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 */
diff --git a/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.h b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.h
new file mode 100644
index 0000000000..7056928856
--- /dev/null
+++ b/lib/rbcodec/codecs/libspc/cpu/spc_dsp_armv5.h
@@ -0,0 +1,30 @@
1#if !SPC_NOINTERP
2/* Want scale optimized for smulw(y) */
3#define GAUSS_TABLE_SCALE 4
4#endif
5
6#if !SPC_NOECHO
7
8#define SPC_DSP_ECHO_APPLY
9
10enum
11{
12 FIR_BUF_CNT = FIR_BUF_HALF * 2,
13 FIR_BUF_SIZE = FIR_BUF_CNT * sizeof ( int32_t ),
14 FIR_BUF_ALIGN = FIR_BUF_SIZE,
15 FIR_BUF_MASK = ~((FIR_BUF_ALIGN / 2) | (sizeof ( int32_t ) - 1))
16};
17
18/* Echo filter structure embedded in struct Spc_Dsp */
19struct echo_filter
20{
21 /* fir_buf [i + 8] == fir_buf [i], to avoid wrap checking in FIR code */
22 int32_t* ptr;
23 /* FIR history is interleaved with guard to eliminate wrap checking
24 * when convolving.
25 * |LR|LR|LR|LR|LR|LR|LR|LR|--|--|--|--|--|--|--|--| */
26 /* copy of echo FIR constants as int16_t, loaded as int32 for
27 * halfword, packed multiples */
28 int16_t coeff [VOICE_COUNT];
29};
30#endif /* SPC_NOECHO */
diff --git a/lib/rbcodec/codecs/libspc/spc_codec.h b/lib/rbcodec/codecs/libspc/spc_codec.h
index 96ca734f4c..446690f726 100644
--- a/lib/rbcodec/codecs/libspc/spc_codec.h
+++ b/lib/rbcodec/codecs/libspc/spc_codec.h
@@ -82,6 +82,7 @@
82#define IBSS_ATTR_SPC IBSS_ATTR 82#define IBSS_ATTR_SPC IBSS_ATTR
83#define ICODE_ATTR_SPC ICODE_ATTR 83#define ICODE_ATTR_SPC ICODE_ATTR
84#define ICONST_ATTR_SPC ICONST_ATTR 84#define ICONST_ATTR_SPC ICONST_ATTR
85#define IDATA_ATTR_SPC IDATA_ATTR
85/* Not enough IRAM available to move further data to it. */ 86/* Not enough IRAM available to move further data to it. */
86#define IBSS_ATTR_SPC_LARGE_IRAM 87#define IBSS_ATTR_SPC_LARGE_IRAM
87 88
@@ -90,6 +91,7 @@
90#define IBSS_ATTR_SPC 91#define IBSS_ATTR_SPC
91#define ICODE_ATTR_SPC 92#define ICODE_ATTR_SPC
92#define ICONST_ATTR_SPC 93#define ICONST_ATTR_SPC
94#define IDATA_ATTR_SPC
93/* Not enough IRAM available to move further data to it. */ 95/* Not enough IRAM available to move further data to it. */
94#define IBSS_ATTR_SPC_LARGE_IRAM 96#define IBSS_ATTR_SPC_LARGE_IRAM
95 97
@@ -97,6 +99,7 @@
97#define IBSS_ATTR_SPC IBSS_ATTR 99#define IBSS_ATTR_SPC IBSS_ATTR
98#define ICODE_ATTR_SPC ICODE_ATTR 100#define ICODE_ATTR_SPC ICODE_ATTR
99#define ICONST_ATTR_SPC ICONST_ATTR 101#define ICONST_ATTR_SPC ICONST_ATTR
102#define IDATA_ATTR_SPC IDATA_ATTR
100/* Not enough IRAM available to move further data to it. */ 103/* Not enough IRAM available to move further data to it. */
101#define IBSS_ATTR_SPC_LARGE_IRAM 104#define IBSS_ATTR_SPC_LARGE_IRAM
102 105
@@ -104,6 +107,7 @@
104#define IBSS_ATTR_SPC IBSS_ATTR 107#define IBSS_ATTR_SPC IBSS_ATTR
105#define ICODE_ATTR_SPC ICODE_ATTR 108#define ICODE_ATTR_SPC ICODE_ATTR
106#define ICONST_ATTR_SPC ICONST_ATTR 109#define ICONST_ATTR_SPC ICONST_ATTR
110#define IDATA_ATTR_SPC IDATA_ATTR
107/* Very large IRAM. Move even more data to it. */ 111/* Very large IRAM. Move even more data to it. */
108#define IBSS_ATTR_SPC_LARGE_IRAM IBSS_ATTR 112#define IBSS_ATTR_SPC_LARGE_IRAM IBSS_ATTR
109 113
@@ -111,6 +115,7 @@
111#define IBSS_ATTR_SPC IBSS_ATTR 115#define IBSS_ATTR_SPC IBSS_ATTR
112#define ICODE_ATTR_SPC ICODE_ATTR 116#define ICODE_ATTR_SPC ICODE_ATTR
113#define ICONST_ATTR_SPC ICONST_ATTR 117#define ICONST_ATTR_SPC ICONST_ATTR
118#define IDATA_ATTR_SPC IDATA_ATTR
114/* Not enough IRAM available to move further data to it. */ 119/* Not enough IRAM available to move further data to it. */
115#define IBSS_ATTR_SPC_LARGE_IRAM 120#define IBSS_ATTR_SPC_LARGE_IRAM
116#endif 121#endif
@@ -318,6 +323,8 @@ struct Spc_Dsp;
318#if defined(CPU_ARM) 323#if defined(CPU_ARM)
319#if ARM_ARCH >= 6 324#if ARM_ARCH >= 6
320#include "cpu/spc_dsp_armv6.h" 325#include "cpu/spc_dsp_armv6.h"
326#elif ARM_ARCH >= 5
327#include "cpu/spc_dsp_armv5.h"
321#else 328#else
322#include "cpu/spc_dsp_armv4.h" 329#include "cpu/spc_dsp_armv4.h"
323#endif 330#endif
@@ -329,6 +336,10 @@ struct Spc_Dsp;
329 function names. */ 336 function names. */
330#include "spc_dsp_generic.h" 337#include "spc_dsp_generic.h"
331 338
339#if !SPC_NOINTERP && !defined (GAUSS_TABLE_SCALE)
340#define GAUSS_TABLE_SCALE 0
341#endif
342
332struct Spc_Dsp 343struct Spc_Dsp
333{ 344{
334 union 345 union
diff --git a/lib/rbcodec/codecs/libspc/spc_dsp.c b/lib/rbcodec/codecs/libspc/spc_dsp.c
index 6ad194aba6..28385c6498 100644
--- a/lib/rbcodec/codecs/libspc/spc_dsp.c
+++ b/lib/rbcodec/codecs/libspc/spc_dsp.c
@@ -32,6 +32,8 @@
32#if defined(CPU_ARM) 32#if defined(CPU_ARM)
33#if ARM_ARCH >= 6 33#if ARM_ARCH >= 6
34#include "cpu/spc_dsp_armv6.c" 34#include "cpu/spc_dsp_armv6.c"
35#elif ARM_ARCH >= 5
36#include "cpu/spc_dsp_armv5.c"
35#else 37#else
36#include "cpu/spc_dsp_armv4.c" 38#include "cpu/spc_dsp_armv4.c"
37#endif 39#endif
@@ -55,7 +57,7 @@ static unsigned short const env_rates [0x20] ICONST_ATTR_SPC =
55#if !SPC_NOINTERP 57#if !SPC_NOINTERP
56/* Interleved gauss table (to improve cache coherency). */ 58/* Interleved gauss table (to improve cache coherency). */
57/* gauss [i * 2 + j] = normal_gauss [(1 - j) * 256 + i] */ 59/* gauss [i * 2 + j] = normal_gauss [(1 - j) * 256 + i] */
58static int16_t const gauss_table [512] ICONST_ATTR_SPC MEM_ALIGN_ATTR = 60static int16_t gauss_table [512] IDATA_ATTR_SPC MEM_ALIGN_ATTR =
59{ 61{
60 370,1305, 366,1305, 362,1304, 358,1304, 62 370,1305, 366,1305, 362,1304, 358,1304,
61 354,1304, 351,1304, 347,1304, 343,1303, 63 354,1304, 351,1304, 347,1304, 343,1303,
@@ -956,6 +958,15 @@ void DSP_reset( struct Spc_Dsp* this )
956 this->wave_entry [i].start_addr = 0xffff; 958 this->wave_entry [i].start_addr = 0xffff;
957#endif /* SPC_BRRCACHE */ 959#endif /* SPC_BRRCACHE */
958 960
961#if !SPC_NOINTERP && GAUSS_TABLE_SCALE
962 if (gauss_table[0] == 370)
963 {
964 /* Not yet scaled */
965 for ( int i = 0; i < 512; i++)
966 gauss_table[i] <<= GAUSS_TABLE_SCALE;
967 }
968#endif /* !SPC_NOINTERP && GAUSS_TABLE_SCALE */
969
959#if !SPC_NOECHO 970#if !SPC_NOECHO
960 this->echo_pos = 0; 971 this->echo_pos = 0;
961 echo_init(this); 972 echo_init(this);