1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by David Bryant
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* This is an assembly optimized version of the following WavPack function:
24 * void decorr_stereo_pass_cont_arml (struct decorr_pass *dpp,
25 * long *buffer, long sample_count);
27 * It performs a single pass of stereo decorrelation on the provided buffer.
28 * Note that this version of the function requires that the 8 previous stereo
29 * samples are visible and correct. In other words, it ignores the "samples_*"
30 * fields in the decorr_pass structure and gets the history data directly
31 * from the buffer. It does, however, return the appropriate history samples
32 * to the decorr_pass structure before returning.
34 * This is written to work on a ARM7TDMI processor. This version uses the
35 * 64-bit multiply-accumulate instruction and so can be used with all
36 * WavPack files. However, for optimum performance with 16-bit WavPack
37 * files, there is a faster version that only uses the 32-bit MLA
45 .global decorr_stereo_pass_cont_arml
50 * r0 = struct decorr_pass *dpp
52 * r2 = long sample_count
55 decorr_stereo_pass_cont_arml:
57 stmfd sp!, {r4 - r8, r10, r11, lr}
59 mov r11, #512 @ r11 = 512 for rounding
60 ldrsh r6, [r0, #2] @ r6 = dpp->delta
61 ldrsh r4, [r0, #4] @ r4 = dpp->weight_A
62 ldrsh r0, [r0, #6] @ r0 = dpp->weight_B
63 cmp r2, #0 @ exit if no samples to process
66 mov r0, r0, asl #18 @ for 64-bit math we use weights << 18
69 add r7, r1, r2, asl #3 @ r7 = buffer ending position
70 ldrsh r2, [r5, #0] @ r2 = dpp->term
74 ldr lr, [r1, #-16] @ load 2 sample history from buffer
75 ldr r10, [r1, #-12] @ for terms 2, 17, and 18
90 mov r10, #(1024 << 18) @ r10 = -1024 << 18 for weight clipping
91 rsb r10, r10, #0 @ (only used for negative terms)
101 ******************************************************************************
102 * Loop to handle term = 17 condition
104 * r0 = dpp->weight_B r8 = previous left sample
106 * r2 = current sample r10 = second previous left sample << 4
107 * r3 = previous right sample r11 = lo accumulator (for rounding)
108 * r4 = dpp->weight_A ip = current decorrelation value
110 * r6 = dpp->delta lr = second previous right sample << 4
112 *******************************************************************************
116 rsbs ip, lr, r8, asl #5 @ decorr value = (2 * prev) - 2nd prev
117 mov lr, r8, asl #4 @ previous becomes 2nd previous
118 ldr r2, [r1], #4 @ get sample & update pointer
121 smlalne r11, r8, r4, ip
122 strne r8, [r1, #-4] @ if change possible, store sample back
125 teq ip, r2 @ update weight based on signs
129 .L325: rsbs ip, r10, r3, asl #5 @ do same thing for right channel
134 smlalne r11, r3, r0, ip
142 .L329: cmp r7, r1 @ loop back if more samples to do
146 b store_1718 @ common exit for terms 17 & 18
149 ******************************************************************************
150 * Loop to handle term = 18 condition
152 * r0 = dpp->weight_B r8 = previous left sample
154 * r2 = current sample r10 = second previous left sample
155 * r3 = previous right sample r11 = lo accumulator (for rounding)
156 * r4 = dpp->weight_A ip = decorrelation value
158 * r6 = dpp->delta lr = second previous right sample
160 *******************************************************************************
164 rsb ip, lr, r8 @ decorr value =
165 mov lr, r8 @ ((3 * prev) - 2nd prev) >> 1
166 add ip, lr, ip, asr #1
168 ldr r2, [r1], #4 @ get sample & update pointer
171 smlalne r11, r8, r4, ip
172 strne r8, [r1, #-4] @ if change possible, store sample back
175 teq ip, r2 @ update weight based on signs
179 .L337: rsb ip, r10, r3 @ do same thing for right channel
181 add ip, r10, ip, asr #1
186 smlalne r11, r3, r0, ip
194 .L341: cmp r7, r1 @ loop back if more samples to do
197 /* common exit for terms 17 & 18 */
200 str r3, [r5, #40] @ store sample history into struct
204 b common_exit @ and return
207 ******************************************************************************
208 * Loop to handle term = 2 condition
209 * (note that this case can be handled by the default term handler (1-8), but
210 * this special case is faster because it doesn't have to read memory twice)
212 * r0 = dpp->weight_B r8 = previous left sample
214 * r2 = current sample r10 = second previous left sample << 4
215 * r3 = previous right sample r11 = lo accumulator (for rounding)
216 * r4 = dpp->weight_A ip = decorrelation value
218 * r6 = dpp->delta lr = second previous right sample << 4
220 *******************************************************************************
224 movs ip, lr @ get decorrelation value & test
225 ldr r2, [r1], #4 @ get sample & update pointer
226 mov lr, r8, asl #4 @ previous becomes 2nd previous
229 smlalne r11, r8, r4, ip
230 strne r8, [r1, #-4] @ if change possible, store sample back
233 teq ip, r2 @ update weight based on signs
237 .L225: movs ip, r10 @ do same thing for right channel
242 smlalne r11, r3, r0, ip
250 .L229: cmp r7, r1 @ loop back if more samples to do
253 b default_term_exit @ this exit updates all dpp->samples
256 ******************************************************************************
257 * Loop to handle default term condition
259 * r0 = dpp->weight_B r8 = result accumulator
261 * r2 = dpp->term r10 =
262 * r3 = decorrelation value r11 = lo accumulator (for rounding)
263 * r4 = dpp->weight_A ip = current sample
265 * r6 = dpp->delta lr =
267 *******************************************************************************
271 ldr r3, [r1, -r2, asl #3] @ get decorrelation value based on term
272 ldr ip, [r1], #4 @ get original sample and bump ptr
276 smlalne r11, r8, r4, r3
277 strne r8, [r1, #-4] @ if possibly changed, store updated sample
280 teq ip, r3 @ update weight based on signs
284 .L350: ldr r3, [r1, -r2, asl #3] @ do the same thing for right channel
289 smlalne r11, r8, r0, r3
297 .L354: cmp r7, r1 @ loop back if more samples to do
298 bhi term_default_loop
301 * This exit is used by terms 1-8 to store the previous 8 samples into the decorr
302 * structure (even if they are not all used for the given term)
310 .L358: and r3, ip, #7
311 add r3, r5, r3, asl #2
323 ******************************************************************************
324 * Loop to handle term = -1 condition
326 * r0 = dpp->weight_B r8 =
328 * r2 = intermediate result r10 = -1024 (for clipping)
329 * r3 = previous right sample r11 = lo accumulator (for rounding)
330 * r4 = dpp->weight_A ip = current sample
332 * r6 = dpp->delta lr = updated left sample
334 *******************************************************************************
341 ldr ip, [r1], #8 @ for left channel the decorrelation value
342 movs r3, r3, asl #4 @ is the previous right sample (in r3)
345 smlalne r11, lr, r4, r3
349 teq ip, r3 @ update weight based on signs
352 cmp r4, #(1024 << 18)
353 movgt r4, #(1024 << 18)
357 .L361: ldr r2, [r1, #-4] @ for right channel the decorrelation value
361 smlalne r11, r3, r0, lr
368 cmp r0, #(1024 << 18) @ then clip weight to +/-1024
369 movgt r0, #(1024 << 18)
373 .L369: cmp r7, r1 @ loop back if more samples to do
374 bhi term_minus_1_loop
376 str r3, [r5, #8] @ else store right sample and exit
380 ******************************************************************************
381 * Loop to handle term = -2 condition
382 * (note that the channels are processed in the reverse order here)
384 * r0 = dpp->weight_B r8 =
386 * r2 = intermediate result r10 = -1024 (for clipping)
387 * r3 = previous left sample r11 = lo accumulator (for rounding)
388 * r4 = dpp->weight_A ip = current sample
390 * r6 = dpp->delta lr = updated right sample
392 *******************************************************************************
399 ldr ip, [r1, #4] @ for right channel the decorrelation value
400 movs r3, r3, asl #4 @ is the previous left sample (in r3)
403 smlalne r11, lr, r0, r3
407 teq ip, r3 @ update weight based on signs
410 cmp r0, #(1024 << 18) @ then clip weight to +/-1024
411 movgt r0, #(1024 << 18)
415 .L380: ldr r2, [r1], #8 @ for left channel the decorrelation value
419 smlalne r11, r3, r4, lr
426 cmp r4, #(1024 << 18)
427 movgt r4, #(1024 << 18)
431 .L388: cmp r7, r1 @ loop back if more samples to do
432 bhi term_minus_2_loop
434 str r3, [r5, #40] @ else store left channel and exit
438 ******************************************************************************
439 * Loop to handle term = -3 condition
441 * r0 = dpp->weight_B r8 = previous left sample
443 * r2 = current left sample r10 = -1024 (for clipping)
444 * r3 = previous right sample r11 = lo accumulator (for rounding)
445 * r4 = dpp->weight_A ip = intermediate result
447 * r6 = dpp->delta lr =
449 *******************************************************************************
453 ldr r3, [r1, #-4] @ load previous samples
461 smlalne r11, r2, r4, r3
465 teq ip, r3 @ update weight based on signs
468 cmp r4, #(1024 << 18) @ then clip weight to +/-1024
469 movgt r4, #(1024 << 18)
473 .L399: movs ip, r8, asl #4 @ ip = previous left we use now
474 mov r8, r2 @ r8 = current left we use next time
478 smlalne r11, r3, r0, ip
485 cmp r0, #(1024 << 18)
486 movgt r0, #(1024 << 18)
490 .L407: cmp r7, r1 @ loop back if more samples to do
491 bhi term_minus_3_loop
493 str r3, [r5, #8] @ else store previous samples & exit
497 * Before finally exiting we must store weights back for next time
501 mov r0, r0, asr #18 @ restore weights to real magnitude
505 ldmpc regs="r4-r8, r10-r11"