forked from PaulStoffregen/Audio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
memcpy_audio.S
241 lines (179 loc) · 4.68 KB
/
memcpy_audio.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* Teensyduino Audio Memcpy
* Copyright (c) 2016, 2017, 2018, 2019 Frank Bösing
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#if defined (__ARM_ARCH_7EM__)
#include <AudioStream.h>
.cpu cortex-m4
.syntax unified
.thumb
.text
/* void memcpy_tointerleave(short *dst, short *srcL, short *srcR); */
.global memcpy_tointerleaveLR
.thumb_func
memcpy_tointerleaveLR:
@ r0: dst
@ r1: srcL
@ r2: srcR
#if AUDIO_BLOCK_SAMPLES > 8
push {r4-r11,r14}
add r14,r0,#(AUDIO_BLOCK_SAMPLES*2)
.align 2
.loopLR:
//Load 2*4 words
ldmia r1!, {r5,r7,r9,r11} //1+4
ldmia r2!, {r6,r8,r10,r12} //1+4
pkhbt r3,r5,r6,LSL #16 //1
pkhtb r4,r6,r5,ASR #16 //1
pkhbt r5,r7,r8,LSL #16 //1
pkhtb r6,r8,r7,ASR #16 //1
pkhbt r7,r9,r10,LSL #16 //1
pkhtb r8,r10,r9,ASR #16 //1
pkhbt r9,r11,r12,LSL #16 //1
pkhtb r10,r12,r11,ASR #16 //1
//Write 8 Words
stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} //1+8 -> 5+5+8+9 = 27 Cycles to interleave 32 bytes.
cmp r14, r0
bne .loopLR
pop {r4-r11,r14}
#elif AUDIO_BLOCK_SAMPLES == 8
push {r4-r8,r14}
ldmia r1!, {r5,r7}
ldmia r2!, {r6,r8}
pkhbt r3,r5,r6,LSL #16
pkhtb r4,r6,r5,ASR #16
pkhbt r5,r7,r8,LSL #16
pkhtb r6,r8,r7,ASR #16
stmia r0!, {r3,r4,r5,r6}
pop {r4-r8,r14}
#endif
BX lr
/* void memcpy_tointerleaveL(short *dst, short *srcL); */
.global memcpy_tointerleaveL
.thumb_func
memcpy_tointerleaveL:
@ r0: dst
@ r1: srcL
mov r2, #0
#if AUDIO_BLOCK_SAMPLES > 8
push {r4-r11}
add r12,r0,#(AUDIO_BLOCK_SAMPLES*2)
.align 2
.loopL:
//Load 4 words
ldmia r1!, {r5,r7,r9,r11} //1+4
pkhbt r3,r5,r2 //1
pkhtb r4,r2,r5,ASR #16 //1
pkhbt r5,r7,r2 //1
pkhtb r6,r2,r7,ASR #16 //1
pkhbt r7,r9,r2 //1
pkhtb r8,r2,r9,ASR #16 //1
pkhbt r9,r11,r2 //1
pkhtb r10,r2,r11,ASR #16 //1
//Write 8 Words
stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10} //1+8
cmp r12, r0
bne .loopL
pop {r4-r11}
#elif AUDIO_BLOCK_SAMPLES == 8
push {r4-r7}
ldmia r1!, {r5,r7}
pkhbt r3,r5,r2
pkhtb r4,r2,r5,ASR #16
pkhbt r5,r7,r2 //1
pkhtb r6,r2,r7,ASR #16
stmia r0!, {r3,r4,r5,r6}
pop {r4-r7}
#endif
BX lr
/* void memcpy_tointerleaveL(short *dst, short *srcR); */
.global memcpy_tointerleaveR
.thumb_func
memcpy_tointerleaveR:
@ r0: dst
@ r1: srcR
mov r2, #0
#if AUDIO_BLOCK_SAMPLES > 8
push {r4-r11}
add r12,r0,#(AUDIO_BLOCK_SAMPLES*2)
.align 2
.loopR:
//Load 4 words
ldmia r1!, {r5,r7,r9,r11}
pkhbt r3,r2,r5,LSL #16
pkhtb r4,r5,r2
pkhbt r5,r2,r7,LSL #16
pkhtb r6,r7,r2
pkhbt r7,r2,r9,LSL #16
pkhtb r8,r9,r2
pkhbt r9,r2,r11,LSL #16
pkhtb r10,r11,r2
//Write 8 Words
stmia r0!, {r3,r4,r5,r6,r7,r8,r9,r10}
cmp r12, r0
bne .loopR
pop {r4-r11}
#elif AUDIO_BLOCK_SAMPLES == 8
push {r4-r7}
ldmia r1!, {r5,r7}
pkhbt r3,r2,r5,LSL #16
pkhtb r4,r5,r2
pkhbt r5,r2,r7,LSL #16
pkhtb r6,r7,r2
stmia r0!, {r3,r4,r5,r6}
pop {r4-r7}
#endif
BX lr
/* void memcpy_tointerleaveQuad(int16_t *dst, const int16_t *src1, const int16_t *src2, const int16_t *src3, const int16_t *src4) */
.global memcpy_tointerleaveQuad
.thumb_func
memcpy_tointerleaveQuad:
@ r0: dst
@ r1: src1
@ r2: src2
@ r3: src3
@ r4: src4
push {r4-r11}
ldr r4, [sp, #(0+32)] //5th parameter is saved on the stack
add r11,r0,#(AUDIO_BLOCK_SAMPLES*4)
.align 2
.loopQuad:
ldr r5, [r1],4
ldr r6, [r3],4
pkhbt r7,r5,r6,LSL #16
pkhtb r9,r6,r5,ASR #16
ldr r5, [r2],4
ldr r6, [r4],4
pkhbt r8,r5,r6,LSL #16
pkhtb r10,r6,r5,ASR #16
stmia r0!, {r7-r10}
cmp r11, r0
bne .loopQuad
pop {r4-r11}
BX lr
.END
#endif