summaryrefslogtreecommitdiff
path: root/firmware/asm/m68k/pcm-mixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/asm/m68k/pcm-mixer.c')
-rw-r--r--firmware/asm/m68k/pcm-mixer.c56
1 files changed, 32 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}