2 * MLP DSP functions x86-optimized
3 * Copyright (c) 2009 Ramiro Polla
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/x86_cpu.h"
23 #include "libavcodec/dsputil.h"
24 #include "libavcodec/mlp.h"
26 #if HAVE_7REGS && HAVE_TEN_OPERANDS
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;
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;
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,
49 static const void *iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
50 &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
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"
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"
69 "xor %%rsi, %%rsi\n\t"
75 #define RESULT "%%rsi"
76 #define RESULT32 "%%esi"
83 #else /* if ARCH_X86_32 */
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"
92 #define FIRMULREG(label, offset, firc) \
93 MLPMUL(label, #offset, "0", "0")
96 "xor %%esi, %%esi\n\t" \
97 "xor %%ecx, %%ecx\n\t"
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" \
105 #define ACCUM "%%edx"
106 #define RESULT "%%eax"
107 #define RESULT32 "%%eax"
112 #define ECXUSED , "ecx"
114 #endif /* !ARCH_X86_64 */
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)
120 #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
121 #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
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)
128 const void *firjump = firtable[firorder];
129 const void *iirjump = iirtable[iirorder];
131 blocksize = -blocksize;
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"
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"
153 "mov "RESULT" ,"ACCUM" \n\t"
154 "add (%2) ,"RESULT" \n\t"
155 "and %4 ,"RESULT" \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"
166 /* 2*/"+r"(sample_buffer),
167 /* 3*/RDWRVAL(blocksize)
169 /* 4*/READVAL((x86_reg)mask),
170 /* 5*/READVAL(firjump),
171 /* 6*/READVAL(iirjump),
172 /* 7*/COUNTER(filter_shift)
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
183 #endif /* HAVE_7REGS && HAVE_TEN_OPERANDS */
185 void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx)
187 #if HAVE_7REGS && HAVE_TEN_OPERANDS
188 c->mlp_filter_channel = mlp_filter_channel_x86;