annotate libao2/fir.h @ 4111:0fc9488c87ef

gawk->awk
author nick
date Sat, 12 Jan 2002 17:59:22 +0000
parents d6f8feeac656
children 585f0c77d8f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
1 /*=============================================================================
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
2 //
4049
d6f8feeac656 Correction of lisensing comment
anders
parents: 3631
diff changeset
3 // This software has been released under the terms of the GNU Public
d6f8feeac656 Correction of lisensing comment
anders
parents: 3631
diff changeset
4 // license. See http://www.gnu.org/copyleft/gpl.html for details.
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
5 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
6 // Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
7 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
8 //=============================================================================
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
9 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
10
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
11 #ifndef __FIR_H__
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
12 #define __FIR_H__
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
13
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
14 /* 4, 8 and 16 tap FIR filters implemented using SSE instructions
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
15 int16_t* x Input data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
16 int16_t* y Output value
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
17 int16_t* w Filter weights
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
18
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
19 C function
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
20 for(int i = 0 ; i < L ; i++)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
21 *y += w[i]*x[i];
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
22 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
23
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
24 #ifdef HAVE_SSE
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
25
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
26 // This block should be MMX only compatible, but it isn't...
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
27 #ifdef L4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
28 #define LOAD_QUE(x) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
29 __asm __volatile("movq %0, %%mm2\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
30 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
31 :"m"((x)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
32 :"memory");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
33 #define SAVE_QUE(x) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
34 __asm __volatile("movq %%mm2, %0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
35 :"=m"(x[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
36 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
37 :"memory");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
38 #define UPDATE_QUE(in) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
39 __asm __volatile("psllq $16, %%mm2\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
40 "pinsrw $0, %0,%%mm2\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
41 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
42 :"m" ((in)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
43 :"memory");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
44 #define FIR(x,w,y) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
45 __asm __volatile("movq %%mm2, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
46 "pmaddwd %1, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
47 "movq %%mm0, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
48 "psrlq $32, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
49 "paddd %%mm0, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
50 "movd %%mm1, %%esi\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
51 "shrl $16, %%esi\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
52 "movw %%si, %0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
53 : "=m" ((y)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
54 : "m" ((w)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
55 : "memory", "%esi");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
56 #endif /* L4 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
57
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
58 // It is possible to make the 8 bit filter a lot faster by using the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
59 // 128 bit registers, feel free to optimize.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
60 #ifdef L8
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
61 #define LOAD_QUE(x) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
62 __asm __volatile("movq %0, %%mm5\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
63 "movq %1, %%mm4\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
64 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
65 :"m"((x)[0]), \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
66 "m"((x)[4]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
67 :"memory");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
68 #define SAVE_QUE(x) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
69 __asm __volatile("movq %%mm5, %0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
70 "movq %%mm4, %1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
71 :"=m"((x)[0]), \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
72 "=m"((x)[4]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
73 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
74 :"memory");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
75
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
76 // Below operation could replace line 2 to 5 in macro below but can
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
77 // not cause of compiler bug ???
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
78 // "pextrw $3, %%mm5,%%eax\n\t"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
79 #define UPDATE_QUE(in) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
80 __asm __volatile("psllq $16, %%mm4\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
81 "movq %%mm5, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
82 "psrlq $48, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
83 "movd %%mm0, %%eax\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
84 "pinsrw $0, %%eax,%%mm4\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
85 "psllq $16, %%mm5\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
86 "pinsrw $0, %0,%%mm5\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
87 : \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
88 :"m" ((in)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
89 :"memory", "%eax");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
90 #define FIR(x,w,y) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
91 __asm __volatile("movq %%mm5, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
92 "pmaddwd %1, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
93 "movq %%mm4, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
94 "pmaddwd %2, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
95 "paddd %%mm1, %%mm0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
96 "movq %%mm0, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
97 "psrlq $32, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
98 "paddd %%mm0, %%mm1\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
99 "movd %%mm1, %%esi\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
100 "shrl $16, %%esi\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
101 "movw %%si, %0\n\t" \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
102 : "=m" ((y)[0]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
103 : "m" ((w)[0]), \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
104 "m" ((w)[4]) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
105 : "memory", "%esi");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
106 #endif /* L8 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
107
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
108 #else /* HAVE_SSE */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
109
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
110 #define LOAD_QUE(x)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
111 #define SAVE_QUE(x)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
112 #define UPDATE_QUE(inm) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
113 xi=(--xi)&(L-1); \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
114 x[xi]=x[xi+L]=*inm;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
115
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
116 #ifdef L4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
117 #define FIR(x,w,y) \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
118 y[0]=(w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3]*x[3]) >> 16;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
119 #else
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
120 #define FIR(x,w,y){ \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
121 int16_t a = (w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3]*x[3]) >> 16; \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
122 int16_t b = (w[4]*x[4]+w[5]*x[5]+w[6]*x[6]+w[7]*x[7]) >> 16; \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
123 y[0] = a+b; \
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
124 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
125 #endif /* L4 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
126
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
127 #endif /* HAVE_SSE */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
128
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
129 #endif /* __FIR_H__ */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
130
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
131