9688
|
1 /*
|
|
2 * MLP DSP functions x86-optimized
|
|
3 * Copyright (c) 2009 Ramiro Polla
|
|
4 *
|
|
5 * This file is part of FFmpeg.
|
|
6 *
|
|
7 * FFmpeg is free software; you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Lesser General Public
|
|
9 * License as published by the Free Software Foundation; either
|
|
10 * version 2.1 of the License, or (at your option) any later version.
|
|
11 *
|
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Lesser General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Lesser General Public
|
|
18 * License along with FFmpeg; if not, write to the Free Software
|
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20 */
|
|
21
|
|
22 #include "libavutil/x86_cpu.h"
|
|
23 #include "libavcodec/dsputil.h"
|
|
24 #include "libavcodec/mlp.h"
|
|
25
|
|
26 #if HAVE_7REGS && HAVE_TEN_OPERANDS
|
|
27
|
|
28 extern void ff_mlp_firorder_8;
|
|
29 extern void ff_mlp_firorder_7;
|
|
30 extern void ff_mlp_firorder_6;
|
|
31 extern void ff_mlp_firorder_5;
|
|
32 extern void ff_mlp_firorder_4;
|
|
33 extern void ff_mlp_firorder_3;
|
|
34 extern void ff_mlp_firorder_2;
|
|
35 extern void ff_mlp_firorder_1;
|
|
36 extern void ff_mlp_firorder_0;
|
|
37
|
|
38 extern void ff_mlp_iirorder_4;
|
|
39 extern void ff_mlp_iirorder_3;
|
|
40 extern void ff_mlp_iirorder_2;
|
|
41 extern void ff_mlp_iirorder_1;
|
|
42 extern void ff_mlp_iirorder_0;
|
|
43
|
|
44 static const void *firtable[9] = { &ff_mlp_firorder_0, &ff_mlp_firorder_1,
|
|
45 &ff_mlp_firorder_2, &ff_mlp_firorder_3,
|
|
46 &ff_mlp_firorder_4, &ff_mlp_firorder_5,
|
|
47 &ff_mlp_firorder_6, &ff_mlp_firorder_7,
|
|
48 &ff_mlp_firorder_8 };
|
|
49 static const void *iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
|
|
50 &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
|
|
51 &ff_mlp_iirorder_4 };
|
|
52
|
|
53 #if ARCH_X86_64
|
|
54
|
|
55 #define MLPMUL(label, offset, offs, offc) \
|
|
56 MANGLE(label)": \n\t" \
|
|
57 "movslq "offset"+"offs"(%0), %%rax\n\t" \
|
|
58 "movslq "offset"+"offc"(%1), %%rdx\n\t" \
|
|
59 "imul %%rdx, %%rax\n\t" \
|
|
60 "add %%rax, %%rsi\n\t"
|
|
61
|
|
62 #define FIRMULREG(label, offset, firc)\
|
|
63 MANGLE(label)": \n\t" \
|
|
64 "movslq "#offset"(%0), %%rax\n\t" \
|
|
65 "imul %"#firc", %%rax\n\t" \
|
|
66 "add %%rax, %%rsi\n\t"
|
|
67
|
|
68 #define CLEAR_ACCUM \
|
|
69 "xor %%rsi, %%rsi\n\t"
|
|
70
|
|
71 #define SHIFT_ACCUM \
|
|
72 "shr %%cl, %%rsi\n\t"
|
|
73
|
|
74 #define ACCUM "%%rdx"
|
|
75 #define RESULT "%%rsi"
|
|
76 #define RESULT32 "%%esi"
|
|
77
|
|
78 #define READVAL "r"
|
|
79 #define RDWRVAL "+r"
|
|
80 #define COUNTER "c"
|
|
81 #define ECXUSED
|
|
82
|
|
83 #else /* if ARCH_X86_32 */
|
|
84
|
|
85 #define MLPMUL(label, offset, offs, offc) \
|
|
86 MANGLE(label)": \n\t" \
|
|
87 "mov "offset"+"offs"(%0), %%eax\n\t" \
|
|
88 "imull "offset"+"offc"(%1) \n\t" \
|
|
89 "add %%eax , %%esi\n\t" \
|
|
90 "adc %%edx , %%ecx\n\t"
|
|
91
|
|
92 #define FIRMULREG(label, offset, firc) \
|
|
93 MLPMUL(label, #offset, "0", "0")
|
|
94
|
|
95 #define CLEAR_ACCUM \
|
|
96 "xor %%esi, %%esi\n\t" \
|
|
97 "xor %%ecx, %%ecx\n\t"
|
|
98
|
|
99 #define SHIFT_ACCUM \
|
|
100 "mov %%ecx, %%edx\n\t" \
|
|
101 "mov %%esi, %%eax\n\t" \
|
|
102 "movzbl %7 , %%ecx\n\t" \
|
|
103 "shrd %%cl, %%edx, %%eax\n\t" \
|
|
104
|
|
105 #define ACCUM "%%edx"
|
|
106 #define RESULT "%%eax"
|
|
107 #define RESULT32 "%%eax"
|
|
108
|
|
109 #define READVAL "m"
|
|
110 #define RDWRVAL "+m"
|
|
111 #define COUNTER "m"
|
|
112 #define ECXUSED , "ecx"
|
|
113
|
|
114 #endif /* !ARCH_X86_64 */
|
|
115
|
|
116 #define BINC AV_STRINGIFY(4* MAX_CHANNELS)
|
|
117 #define IOFFS AV_STRINGIFY(4*(MAX_FIR_ORDER + MAX_BLOCKSIZE))
|
|
118 #define IOFFC AV_STRINGIFY(4* MAX_FIR_ORDER)
|
|
119
|
|
120 #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
|
|
121 #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
|
|
122
|
|
123 static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
|
|
124 int firorder, int iirorder,
|
|
125 unsigned int filter_shift, int32_t mask,
|
|
126 int blocksize, int32_t *sample_buffer)
|
|
127 {
|
|
128 const void *firjump = firtable[firorder];
|
|
129 const void *iirjump = iirtable[iirorder];
|
|
130
|
|
131 blocksize = -blocksize;
|
|
132
|
|
133 __asm__ volatile(
|
|
134 "1: \n\t"
|
|
135 CLEAR_ACCUM
|
|
136 "jmp *%5 \n\t"
|
|
137 FIRMUL (ff_mlp_firorder_8, 0x1c )
|
|
138 FIRMUL (ff_mlp_firorder_7, 0x18 )
|
|
139 FIRMUL (ff_mlp_firorder_6, 0x14 )
|
|
140 FIRMUL (ff_mlp_firorder_5, 0x10 )
|
|
141 FIRMUL (ff_mlp_firorder_4, 0x0c )
|
|
142 FIRMULREG(ff_mlp_firorder_3, 0x08,10)
|
|
143 FIRMULREG(ff_mlp_firorder_2, 0x04, 9)
|
|
144 FIRMULREG(ff_mlp_firorder_1, 0x00, 8)
|
|
145 MANGLE (ff_mlp_firorder_0)":\n\t"
|
|
146 "jmp *%6 \n\t"
|
|
147 IIRMUL (ff_mlp_iirorder_4, 0x0c )
|
|
148 IIRMUL (ff_mlp_iirorder_3, 0x08 )
|
|
149 IIRMUL (ff_mlp_iirorder_2, 0x04 )
|
|
150 IIRMUL (ff_mlp_iirorder_1, 0x00 )
|
|
151 MANGLE (ff_mlp_iirorder_0)":\n\t"
|
|
152 SHIFT_ACCUM
|
|
153 "mov "RESULT" ,"ACCUM" \n\t"
|
|
154 "add (%2) ,"RESULT" \n\t"
|
|
155 "and %4 ,"RESULT" \n\t"
|
|
156 "sub $4 , %0 \n\t"
|
|
157 "mov "RESULT32", (%0) \n\t"
|
|
158 "mov "RESULT32", (%2) \n\t"
|
|
159 "add $"BINC" , %2 \n\t"
|
|
160 "sub "ACCUM" ,"RESULT" \n\t"
|
|
161 "mov "RESULT32","IOFFS"(%0) \n\t"
|
|
162 "incl %3 \n\t"
|
|
163 "js 1b \n\t"
|
|
164 : /* 0*/"+r"(state),
|
|
165 /* 1*/"+r"(coeff),
|
|
166 /* 2*/"+r"(sample_buffer),
|
|
167 /* 3*/RDWRVAL(blocksize)
|
|
168 :
|
|
169 /* 4*/READVAL((x86_reg)mask),
|
|
170 /* 5*/READVAL(firjump),
|
|
171 /* 6*/READVAL(iirjump),
|
|
172 /* 7*/COUNTER(filter_shift)
|
|
173 #if ARCH_X86_64
|
|
174 , /* 8*/"r"((int64_t)coeff[0])
|
|
175 , /* 9*/"r"((int64_t)coeff[1])
|
|
176 , /*10*/"r"((int64_t)coeff[2])
|
|
177 #endif /* ARCH_X86_64 */
|
|
178 : REG_a, REG_d, REG_S
|
|
179 ECXUSED
|
|
180 );
|
|
181 }
|
|
182
|
|
183 #endif /* HAVE_7REGS && HAVE_TEN_OPERANDS */
|
|
184
|
|
185 void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx)
|
|
186 {
|
|
187 #if HAVE_7REGS && HAVE_TEN_OPERANDS
|
|
188 c->mlp_filter_channel = mlp_filter_channel_x86;
|
|
189 #endif
|
|
190 }
|