1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by David Bryant
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 /* This is an assembly optimized version of the following WavPack function:
22 * void decorr_stereo_pass_cont_arm (struct decorr_pass *dpp,
23 * long *buffer, long sample_count);
25 * It performs a single pass of stereo decorrelation on the provided buffer.
26 * Note that this version of the function requires that the 8 previous stereo
27 * samples are visible and correct. In other words, it ignores the "samples_*"
28 * fields in the decorr_pass structure and gets the history data directly
29 * from the buffer. It does, however, return the appropriate history samples
30 * to the decorr_pass structure before returning.
32 * This is written to work on a ARM7TDMI processor. This version only uses the
33 * 32-bit multiply-accumulate instruction and so will overflow with 24-bit
38 .global decorr_stereo_pass_cont_arm
43 * r0 = struct decorr_pass *dpp
45 * r2 = long sample_count
48 decorr_stereo_pass_cont_arm:
50 stmfd sp!, {r4 - r8, r10, r11, lr}
52 mov r11, #512 @ r11 = 512 for rounding
53 ldrsh r6, [r0, #2] @ r6 = dpp->delta
54 ldrsh r4, [r0, #4] @ r4 = dpp->weight_A
55 ldrsh r0, [r0, #6] @ r0 = dpp->weight_B
56 cmp r2, #0 @ exit if no samples to process
59 add r7, r1, r2, asl #3 @ r7 = buffer ending position
60 ldrsh r2, [r5, #0] @ r2 = dpp->term
64 ldr lr, [r1, #-16] @ load 2 sample history from buffer
65 ldr r10, [r1, #-12] @ for terms 2, 17, and 18
74 b term_default_loop @ else handle default (1-8, except 2)
77 mov r10, #1024 @ r10 = -1024 for weight clipping
78 rsb r10, r10, #0 @ (only used for negative terms)
88 ******************************************************************************
89 * Loop to handle term = 17 condition
91 * r0 = dpp->weight_B r8 = previous left sample
93 * r2 = current sample r10 = second previous left sample
94 * r3 = previous right sample r11 = 512 (for rounding)
95 * r4 = dpp->weight_A ip = current decorrelation value
97 * r6 = dpp->delta lr = second previous right sample
99 *******************************************************************************
103 rsbs ip, lr, r8, asl #1 @ decorr value = (2 * prev) - 2nd prev
104 mov lr, r8 @ previous becomes 2nd previous
105 ldr r2, [r1], #4 @ get sample & update pointer
106 mla r8, ip, r4, r11 @ mult decorr value by weight, round,
107 add r8, r2, r8, asr #10 @ shift, and add to new sample
108 strne r8, [r1, #-4] @ if change possible, store sample back
111 teq ip, r2 @ update weight based on signs
115 .L325: rsbs ip, r10, r3, asl #1 @ do same thing for right channel
119 add r3, r2, r3, asr #10
127 .L329: cmp r7, r1 @ loop back if more samples to do
129 b store_1718 @ common exit for terms 17 & 18
132 ******************************************************************************
133 * Loop to handle term = 18 condition
135 * r0 = dpp->weight_B r8 = previous left sample
137 * r2 = current sample r10 = second previous left sample
138 * r3 = previous right sample r11 = 512 (for rounding)
139 * r4 = dpp->weight_A ip = decorrelation value
141 * r6 = dpp->delta lr = second previous right sample
143 *******************************************************************************
147 sub ip, r8, lr @ decorr value =
148 mov lr, r8 @ ((3 * prev) - 2nd prev) >> 1
149 adds ip, r8, ip, asr #1
150 ldr r2, [r1], #4 @ get sample & update pointer
151 mla r8, ip, r4, r11 @ mult decorr value by weight, round,
152 add r8, r2, r8, asr #10 @ shift, and add to new sample
153 strne r8, [r1, #-4] @ if change possible, store sample back
156 teq ip, r2 @ update weight based on signs
160 .L337: sub ip, r3, r10 @ do same thing for right channel
162 adds ip, r3, ip, asr #1
165 add r3, r2, r3, asr #10
173 .L341: cmp r7, r1 @ loop back if more samples to do
176 /* common exit for terms 17 & 18 */
179 str r3, [r5, #40] @ store sample history into struct
183 b common_exit @ and return
186 ******************************************************************************
187 * Loop to handle term = 2 condition
188 * (note that this case can be handled by the default term handler (1-8), but
189 * this special case is faster because it doesn't have to read memory twice)
191 * r0 = dpp->weight_B r8 = previous left sample
193 * r2 = current sample r10 = second previous left sample
194 * r3 = previous right sample r11 = 512 (for rounding)
195 * r4 = dpp->weight_A ip = decorrelation value
197 * r6 = dpp->delta lr = second previous right sample
199 *******************************************************************************
203 movs ip, lr @ get decorrelation value & test
204 mov lr, r8 @ previous becomes 2nd previous
205 ldr r2, [r1], #4 @ get sample & update pointer
206 mla r8, ip, r4, r11 @ mult decorr value by weight, round,
207 add r8, r2, r8, asr #10 @ shift, and add to new sample
208 strne r8, [r1, #-4] @ if change possible, store sample back
211 teq ip, r2 @ update weight based on signs
215 .L225: movs ip, r10 @ do same thing for right channel
219 add r3, r2, r3, asr #10
227 .L229: cmp r7, r1 @ loop back if more samples to do
229 b default_term_exit @ this exit updates all dpp->samples
232 ******************************************************************************
233 * Loop to handle default term condition
235 * r0 = dpp->weight_B r8 = result accumulator
237 * r2 = dpp->term r10 =
238 * r3 = decorrelation value r11 = 512 (for rounding)
239 * r4 = dpp->weight_A ip = current sample
241 * r6 = dpp->delta lr =
243 *******************************************************************************
247 ldr ip, [r1] @ get original sample
248 ldr r3, [r1, -r2, asl #3] @ get decorrelation value based on term
249 mla r8, r3, r4, r11 @ mult decorr value by weight, round,
250 add r8, ip, r8, asr #10 @ shift and add to new sample
251 str r8, [r1], #4 @ store update sample
255 teq ip, r3 @ update weight based on signs
259 .L350: ldr ip, [r1] @ do the same thing for right channel
260 ldr r3, [r1, -r2, asl #3]
262 add r8, ip, r8, asr #10
271 .L354: cmp r7, r1 @ loop back if more samples to do
272 bhi term_default_loop
275 * This exit is used by terms 1-8 to store the previous 8 samples into the decorr
276 * structure (even if they are not all used for the given term)
284 .L358: and r3, ip, #7
285 add r3, r5, r3, asl #2
297 ******************************************************************************
298 * Loop to handle term = -1 condition
300 * r0 = dpp->weight_B r8 =
302 * r2 = intermediate result r10 = -1024 (for clipping)
303 * r3 = previous right sample r11 = 512 (for rounding)
304 * r4 = dpp->weight_A ip = current sample
306 * r6 = dpp->delta lr = updated left sample
308 *******************************************************************************
315 ldr ip, [r1] @ for left channel the decorrelation value
316 mla r2, r3, r4, r11 @ is the previous right sample (in r3)
317 add lr, ip, r2, asr #10
322 teq ip, r3 @ update weight based on signs
330 .L361: ldr r2, [r1, #-4] @ for right channel the decorrelation value
331 mla r3, lr, r0, r11 @ is the just updated right sample (in lr)
332 add r3, r2, r3, asr #10
340 cmp r0, #1024 @ then clip weight to +/-1024
345 .L369: cmp r7, r1 @ loop back if more samples to do
346 bhi term_minus_1_loop
348 str r3, [r5, #8] @ else store right sample and exit
352 ******************************************************************************
353 * Loop to handle term = -2 condition
354 * (note that the channels are processed in the reverse order here)
356 * r0 = dpp->weight_B r8 =
358 * r2 = intermediate result r10 = -1024 (for clipping)
359 * r3 = previous left sample r11 = 512 (for rounding)
360 * r4 = dpp->weight_A ip = current sample
362 * r6 = dpp->delta lr = updated right sample
364 *******************************************************************************
371 ldr ip, [r1, #4] @ for right channel the decorrelation value
372 mla r2, r3, r0, r11 @ is the previous left sample (in r3)
373 add lr, ip, r2, asr #10
378 teq ip, r3 @ update weight based on signs
381 cmp r0, #1024 @ then clip weight to +/-1024
386 .L380: ldr r2, [r1, #0] @ for left channel the decorrelation value
387 mla r3, lr, r4, r11 @ is the just updated left sample (in lr)
388 add r3, r2, r3, asr #10
401 .L388: cmp r7, r1 @ loop back if more samples to do
402 bhi term_minus_2_loop
404 str r3, [r5, #40] @ else store left channel and exit
408 ******************************************************************************
409 * Loop to handle term = -3 condition
411 * r0 = dpp->weight_B r8 = previous left sample
413 * r2 = current left sample r10 = -1024 (for clipping)
414 * r3 = previous right sample r11 = 512 (for rounding)
415 * r4 = dpp->weight_A ip = intermediate result
417 * r6 = dpp->delta lr =
419 *******************************************************************************
423 ldr r3, [r1, #-4] @ load previous samples
429 add r2, ip, r2, asr #10
434 teq ip, r3 @ update weight based on signs
437 cmp r4, #1024 @ then clip weight to +/-1024
442 .L399: movs ip, r8 @ ip = previous left we use now
443 mov r8, r2 @ r8 = current left we use next time
446 add r3, r2, r3, asr #10
458 .L407: cmp r7, r1 @ loop back if more samples to do
459 bhi term_minus_3_loop
461 str r3, [r5, #8] @ else store previous samples & exit
465 * Before finally exiting we must store weights back for next time
471 ldmfd sp!, {r4 - r8, r10, r11, pc}