summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-03-09 21:00:49 -0500
committerMichael Sevakis <jethead71@rockbox.org>2012-03-12 00:16:12 +0100
commit64bb720edf8a738685c9f0a18957a1b15e984cf6 (patch)
tree039401182143da0652c15e86d94cc29cb6d39b3c
parentd2aafd19e4fbe0ef8ec053e59085bcac85e64491 (diff)
downloadrockbox-64bb720edf8a738685c9f0a18957a1b15e984cf6.tar.gz
rockbox-64bb720edf8a738685c9f0a18957a1b15e984cf6.zip
Coldfire: Optimize emac context save/restore in mixer ISR.
Save only once if emac is used in ISR and restore only once per ISR call if already saved. Change-Id: I0e40db5d4aab2a8552480f76873f59ff6ccd9977 Reviewed-on: http://gerrit.rockbox.org/176 Tested-by: Michael Sevakis <jethead71@rockbox.org> Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
-rw-r--r--firmware/asm/m68k/pcm-mixer.c56
-rw-r--r--firmware/asm/pcm-mixer.c4
-rw-r--r--firmware/pcm_mixer.c3
3 files changed, 39 insertions, 24 deletions
diff --git a/firmware/asm/m68k/pcm-mixer.c b/firmware/asm/m68k/pcm-mixer.c
index 730ae4ace7..2969546e56 100644
--- a/firmware/asm/m68k/pcm-mixer.c
+++ b/firmware/asm/m68k/pcm-mixer.c
@@ -23,37 +23,51 @@
23#define MIXER_OPTIMIZED_WRITE_SAMPLES 23#define MIXER_OPTIMIZED_WRITE_SAMPLES
24static struct emac_context 24static struct emac_context
25{ 25{
26 unsigned long saved;
26 unsigned long r[4]; 27 unsigned long r[4];
27} emac_context IBSS_ATTR; 28} emac_context IBSS_ATTR;
28 29
29/* Save emac context affected in ISR */ 30/* Save emac context affected in ISR */
30static FORCE_INLINE void save_emac_context(void) 31static FORCE_INLINE void save_emac_context(void)
31{ 32{
32 asm volatile ( 33 /* Save only if not already saved */
33 "move.l %%macsr, %%d0 \n" 34 if (emac_context.saved == 0)
34 "move.l %%accext01, %%d1 \n" 35 {
35 "movclr.l %%acc0, %%a0 \n" 36 emac_context.saved = 1;
36 "movclr.l %%acc1, %%a1 \n" 37 asm volatile (
37 "movem.l %%d0-%%d1/%%a0-%%a1, (%0) \n" 38 "move.l %%macsr, %%d0 \n"
38 : 39 "move.l %%accext01, %%d1 \n"
39 : "a"(&emac_context) 40 "movclr.l %%acc0, %%a0 \n"
40 : "d0", "d1", "a0", "a1"); 41 "movclr.l %%acc1, %%a1 \n"
42 "movem.l %%d0-%%d1/%%a0-%%a1, (%0) \n"
43 "move.l %1, %%macsr \n"
44 :
45 : "a"(&emac_context.r), "i"(EMAC_ROUND | EMAC_SATURATE)
46 : "d0", "d1", "a0", "a1");
47 }
41} 48}
42 49
43/* Restore emac context affected in ISR */ 50/* Restore emac context affected in ISR */
44static FORCE_INLINE void restore_emac_context(void) 51static FORCE_INLINE void restore_emac_context(void)
45{ 52{
46 asm volatile ( 53 /* Restore only if saved */
47 "movem.l (%0), %%d0-%%d1/%%a0-%%a1 \n" 54 if (UNLIKELY(emac_context.saved != 0))
48 "move.l %%a1, %%acc1 \n" 55 {
49 "move.l %%a0, %%acc0 \n" 56 asm volatile (
50 "move.l %%d1, %%accext01 \n" 57 "movem.l (%0), %%d0-%%d1/%%a0-%%a1 \n"
51 "move.l %%d0, %%macsr \n" 58 "move.l %%a1, %%acc1 \n"
52 : 59 "move.l %%a0, %%acc0 \n"
53 : "a"(&emac_context) 60 "move.l %%d1, %%accext01 \n"
54 : "d0", "d1", "a0", "a1"); 61 "move.l %%d0, %%macsr \n"
62 :
63 : "a"(&emac_context.r)
64 : "d0", "d1", "a0", "a1");
65 emac_context.saved = 0;
66 }
55} 67}
56 68
69#define mixer_buffer_callback_exit() restore_emac_context()
70
57/* Mix channels' samples and apply gain factors */ 71/* Mix channels' samples and apply gain factors */
58static FORCE_INLINE void mix_samples(void *out, 72static FORCE_INLINE void mix_samples(void *out,
59 const void *src0, 73 const void *src0,
@@ -64,7 +78,6 @@ static FORCE_INLINE void mix_samples(void *out,
64{ 78{
65 uint32_t s0, s1, s2, s3; 79 uint32_t s0, s1, s2, s3;
66 save_emac_context(); 80 save_emac_context();
67 coldfire_set_macsr(EMAC_ROUND | EMAC_SATURATE);
68 81
69 asm volatile ( 82 asm volatile (
70 "move.l (%1)+, %5 \n" 83 "move.l (%1)+, %5 \n"
@@ -88,8 +101,6 @@ static FORCE_INLINE void mix_samples(void *out,
88 "=&a"(s0), "=&d"(s1), "=&d"(s2), "=&d"(s3) 101 "=&a"(s0), "=&d"(s1), "=&d"(s2), "=&d"(s3)
89 : "r"(src0_amp), "r"(src1_amp), "d"(16) 102 : "r"(src0_amp), "r"(src1_amp), "d"(16)
90 ); 103 );
91
92 restore_emac_context();
93} 104}
94 105
95/* Write channel's samples and apply gain factor */ 106/* Write channel's samples and apply gain factor */
@@ -108,7 +119,6 @@ static FORCE_INLINE void write_samples(void *out,
108 /* Channel needs amplitude cut */ 119 /* Channel needs amplitude cut */
109 uint32_t s0, s1, s2, s3; 120 uint32_t s0, s1, s2, s3;
110 save_emac_context(); 121 save_emac_context();
111 coldfire_set_macsr(EMAC_ROUND | EMAC_SATURATE);
112 122
113 asm volatile ( 123 asm volatile (
114 "move.l (%1)+, %4 \n" 124 "move.l (%1)+, %4 \n"
@@ -128,7 +138,5 @@ static FORCE_INLINE void write_samples(void *out,
128 "=&a"(s0), "=&d"(s1), "=&d"(s2), "=&d"(s3) 138 "=&a"(s0), "=&d"(s1), "=&d"(s2), "=&d"(s3)
129 : "r"(amp), "d"(16) 139 : "r"(amp), "d"(16)
130 ); 140 );
131
132 restore_emac_context();
133 } 141 }
134} 142}
diff --git a/firmware/asm/pcm-mixer.c b/firmware/asm/pcm-mixer.c
index 3e6e2fff78..9bdb962576 100644
--- a/firmware/asm/pcm-mixer.c
+++ b/firmware/asm/pcm-mixer.c
@@ -109,3 +109,7 @@ static FORCE_INLINE void write_samples(int16_t *out,
109 109
110 110
111#endif /* CPU_* */ 111#endif /* CPU_* */
112
113#ifndef mixer_buffer_callback_exit
114#define mixer_buffer_callback_exit() do{}while(0)
115#endif
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c
index 9077c6f271..00891f367d 100644
--- a/firmware/pcm_mixer.c
+++ b/firmware/pcm_mixer.c
@@ -232,6 +232,9 @@ fill_frame:
232 *downmix_buf[downmix_index] = downmix_index ? 0x7fff7fff : 0x80008000; 232 *downmix_buf[downmix_index] = downmix_index ? 0x7fff7fff : 0x80008000;
233#endif 233#endif
234 234
235 /* Certain SoC's have to do cleanup */
236 mixer_buffer_callback_exit();
237
235 return PCM_DMAST_OK; 238 return PCM_DMAST_OK;
236} 239}
237 240