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