Rename variables sectorbuf and verbose to avoid clashes in rbutil. Cleanup exports...
[Rockbox.git] / apps / eq_cf.S
blob954b9d697d55c222263bda74a9d21db5cd8d7939
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2006-2007 Thom Johansen
11  *
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.
14  *
15  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16  * KIND, either express or implied.
17  *
18  ****************************************************************************/
20 /* uncomment this to make filtering calculate lower bits after shifting.
21  * without this, "shift" - 1 of the lower bits will be lost here.
22  */
23 /* #define HIGH_PRECISION */
26  * void eq_filter(int32_t **x, struct eqfilter *f, unsigned num,
27  *                unsigned channels, unsigned shift)
28  */
29     .text
30     .global eq_filter
31 eq_filter:
32     lea.l (-11*4, %sp), %sp 
33     movem.l %d2-%d7/%a2-%a6, (%sp)    | save clobbered regs
34     move.l (11*4+8, %sp), %a5         | fetch filter structure address
35     move.l (11*4+20, %sp), %d7        | load shift count
36     subq.l #1, %d7                    | EMAC gives us one free shift
37 #ifdef HIGH_PRECISION
38     moveq.l #8, %d6
39     sub.l %d7, %d6                    | shift for lower part of accumulator
40 #endif
41     movem.l (%a5), %a0-%a4            | load coefs
42     lea.l (5*4, %a5), %a5             | point to filter history
44 .filterloop:
45     move.l (11*4+4, %sp), %a6         | load input channel pointer
46     addq.l #4, (11*4+4, %sp)          | point x to next channel
47     move.l (%a6), %a6
48     move.l (11*4+12, %sp), %d5        | number of samples
49     movem.l (%a5), %d0-%d3            | load filter history
51     /* d0-d3 = history, d4 = temp, d5 = sample count, d6 = lower shift amount,
52      * d7 = upper shift amount, a0-a4 = coefs, a5 = history pointer, a6 = x[]
53      */
54 .loop:
55     /* Direct form 1 filtering code. We assume DSP has put EMAC in frac mode.
56      * y[n] = b0*x[i] + b1*x[i - 1] + b2*x[i - 2] + a1*y[i - 1] + a2*y[i - 2],
57      * where y[] is output and x[] is input. This is performed out of order
58      * to do parallel load of input value.
59      */
60     mac.l %a2, %d1, %acc0               | acc = b2*x[i - 2]
61     move.l %d0, %d1                     | fix input history
62     mac.l %a1, %d0, (%a6), %d0, %acc0   | acc += b1*x[i - 1], x[i] -> d0
63     mac.l %a0, %d0, %acc0               | acc += b0*x[i]
64     mac.l %a3, %d2, %acc0               | acc += a1*y[i - 1]
65     mac.l %a4, %d3, %acc0               | acc += a2*y[i - 2]
66     move.l %d2, %d3                     | fix output history
67 #ifdef HIGH_PRECISION
68     move.l %accext01, %d2               | fetch lower part of accumulator
69     move.b %d2, %d4                     | clear upper three bytes
70     lsr.l %d6, %d4                      | shift lower bits
71 #endif
72     movclr.l %acc0, %d2                 | fetch upper part of result
73     asl.l %d7, %d2                      | restore fixed point format
74 #ifdef HIGH_PRECISION
75     or.l %d2, %d4                       | combine lower and upper parts
76 #endif
77     move.l %d2, (%a6)+                  | save result
78     subq.l #1, %d5                      | are we done with this channel?
79     jne .loop
80     
81     movem.l %d0-%d3, (%a5)              | save history back to struct
82     lea.l (4*4, %a5), %a5               | point to next channel's history
83     subq.l #1, (11*4+16, %sp)           | have we processed both channels?
84     jne .filterloop
86     movem.l (%sp), %d2-%d7/%a2-%a6
87     lea.l (11*4, %sp), %sp
88     rts