2 * MLP DSP functions x86-optimized
3 * Copyright (c) 2009 Ramiro Polla
5 * This file is part of Libav.
7 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/attributes.h"
23 #include "libavutil/internal.h"
24 #include "libavutil/x86/asm.h"
25 #include "libavcodec/mlpdsp.h"
26 #include "libavcodec/mlp.h"
28 #if HAVE_7REGS && HAVE_INLINE_ASM
30 extern char ff_mlp_firorder_8;
31 extern char ff_mlp_firorder_7;
32 extern char ff_mlp_firorder_6;
33 extern char ff_mlp_firorder_5;
34 extern char ff_mlp_firorder_4;
35 extern char ff_mlp_firorder_3;
36 extern char ff_mlp_firorder_2;
37 extern char ff_mlp_firorder_1;
38 extern char ff_mlp_firorder_0;
40 extern char ff_mlp_iirorder_4;
41 extern char ff_mlp_iirorder_3;
42 extern char ff_mlp_iirorder_2;
43 extern char ff_mlp_iirorder_1;
44 extern char ff_mlp_iirorder_0;
46 static const void *firtable[9] = { &ff_mlp_firorder_0, &ff_mlp_firorder_1,
47 &ff_mlp_firorder_2, &ff_mlp_firorder_3,
48 &ff_mlp_firorder_4, &ff_mlp_firorder_5,
49 &ff_mlp_firorder_6, &ff_mlp_firorder_7,
51 static const void *iirtable[5] = { &ff_mlp_iirorder_0, &ff_mlp_iirorder_1,
52 &ff_mlp_iirorder_2, &ff_mlp_iirorder_3,
57 #define MLPMUL(label, offset, offs, offc) \
58 LABEL_MANGLE(label)": \n\t" \
59 "movslq "offset"+"offs"(%0), %%rax\n\t" \
60 "movslq "offset"+"offc"(%1), %%rdx\n\t" \
61 "imul %%rdx, %%rax\n\t" \
62 "add %%rax, %%rsi\n\t"
64 #define FIRMULREG(label, offset, firc)\
65 LABEL_MANGLE(label)": \n\t" \
66 "movslq "#offset"(%0), %%rax\n\t" \
67 "imul %"#firc", %%rax\n\t" \
68 "add %%rax, %%rsi\n\t"
71 "xor %%rsi, %%rsi\n\t"
77 #define RESULT "%%rsi"
78 #define RESULT32 "%%esi"
80 #else /* if ARCH_X86_32 */
82 #define MLPMUL(label, offset, offs, offc) \
83 LABEL_MANGLE(label)": \n\t" \
84 "mov "offset"+"offs"(%0), %%eax\n\t" \
85 "imull "offset"+"offc"(%1) \n\t" \
86 "add %%eax , %%esi\n\t" \
87 "adc %%edx , %%ecx\n\t"
89 #define FIRMULREG(label, offset, firc) \
90 MLPMUL(label, #offset, "0", "0")
93 "xor %%esi, %%esi\n\t" \
94 "xor %%ecx, %%ecx\n\t"
97 "mov %%ecx, %%edx\n\t" \
98 "mov %%esi, %%eax\n\t" \
99 "movzbl %7 , %%ecx\n\t" \
100 "shrd %%cl, %%edx, %%eax\n\t" \
102 #define ACCUM "%%edx"
103 #define RESULT "%%eax"
104 #define RESULT32 "%%eax"
106 #endif /* !ARCH_X86_64 */
108 #define BINC AV_STRINGIFY(4* MAX_CHANNELS)
109 #define IOFFS AV_STRINGIFY(4*(MAX_FIR_ORDER + MAX_BLOCKSIZE))
110 #define IOFFC AV_STRINGIFY(4* MAX_FIR_ORDER)
112 #define FIRMUL(label, offset) MLPMUL(label, #offset, "0", "0")
113 #define IIRMUL(label, offset) MLPMUL(label, #offset, IOFFS, IOFFC)
115 static void mlp_filter_channel_x86(int32_t *state, const int32_t *coeff,
116 int firorder, int iirorder,
117 unsigned int filter_shift, int32_t mask,
118 int blocksize, int32_t *sample_buffer)
120 const void *firjump = firtable[firorder];
121 const void *iirjump = iirtable[iirorder];
123 blocksize = -blocksize;
129 FIRMUL (ff_mlp_firorder_8, 0x1c )
130 FIRMUL (ff_mlp_firorder_7, 0x18 )
131 FIRMUL (ff_mlp_firorder_6, 0x14 )
132 FIRMUL (ff_mlp_firorder_5, 0x10 )
133 FIRMUL (ff_mlp_firorder_4, 0x0c )
134 FIRMULREG(ff_mlp_firorder_3, 0x08,10)
135 FIRMULREG(ff_mlp_firorder_2, 0x04, 9)
136 FIRMULREG(ff_mlp_firorder_1, 0x00, 8)
137 LABEL_MANGLE(ff_mlp_firorder_0)":\n\t"
139 IIRMUL (ff_mlp_iirorder_4, 0x0c )
140 IIRMUL (ff_mlp_iirorder_3, 0x08 )
141 IIRMUL (ff_mlp_iirorder_2, 0x04 )
142 IIRMUL (ff_mlp_iirorder_1, 0x00 )
143 LABEL_MANGLE(ff_mlp_iirorder_0)":\n\t"
145 "mov "RESULT" ,"ACCUM" \n\t"
146 "add (%2) ,"RESULT" \n\t"
147 "and %4 ,"RESULT" \n\t"
149 "mov "RESULT32", (%0) \n\t"
150 "mov "RESULT32", (%2) \n\t"
151 "add $"BINC" , %2 \n\t"
152 "sub "ACCUM" ,"RESULT" \n\t"
153 "mov "RESULT32","IOFFS"(%0) \n\t"
158 /* 2*/"+r"(sample_buffer),
160 /* 3*/"+r"(blocksize)
161 : /* 4*/"r"((x86_reg)mask), /* 5*/"r"(firjump),
162 /* 6*/"r"(iirjump) , /* 7*/"c"(filter_shift)
163 , /* 8*/"r"((int64_t)coeff[0])
164 , /* 9*/"r"((int64_t)coeff[1])
165 , /*10*/"r"((int64_t)coeff[2])
166 : "rax", "rdx", "rsi"
167 #else /* ARCH_X86_32 */
168 /* 3*/"+m"(blocksize)
169 : /* 4*/"m"( mask), /* 5*/"m"(firjump),
170 /* 6*/"m"(iirjump) , /* 7*/"m"(filter_shift)
171 : "eax", "edx", "esi", "ecx"
172 #endif /* !ARCH_X86_64 */
176 #endif /* HAVE_7REGS && HAVE_INLINE_ASM */
178 av_cold void ff_mlpdsp_init_x86(MLPDSPContext *c)
180 #if HAVE_7REGS && HAVE_INLINE_ASM
181 c->mlp_filter_channel = mlp_filter_channel_x86;