]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/hpeldsp_init.c
x86: synth filter float: implement SSE2 version
[ffmpeg] / libavcodec / x86 / hpeldsp_init.c
1 /*
2  * MMX optimized DSP utils
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
23  */
24
25 #include "libavutil/attributes.h"
26 #include "libavutil/cpu.h"
27 #include "libavutil/x86/asm.h"
28 #include "libavutil/x86/cpu.h"
29 #include "libavcodec/hpeldsp.h"
30 #include "dsputil_x86.h"
31
32 void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
33                               ptrdiff_t line_size, int h);
34 void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
35                              ptrdiff_t line_size, int h);
36 void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
37                                ptrdiff_t line_size, int h);
38 void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
39                               ptrdiff_t line_size, int h);
40 void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
41                                      ptrdiff_t line_size, int h);
42 void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
43                                     ptrdiff_t line_size, int h);
44 void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
45                                            const uint8_t *pixels,
46                                            ptrdiff_t line_size, int h);
47 void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
48                                           const uint8_t *pixels,
49                                           ptrdiff_t line_size, int h);
50 void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
51                               ptrdiff_t line_size, int h);
52 void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
53                              ptrdiff_t line_size, int h);
54 void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
55                                      ptrdiff_t line_size, int h);
56 void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
57                                     ptrdiff_t line_size, int h);
58 void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
59                                            const uint8_t *pixels,
60                                            ptrdiff_t line_size, int h);
61 void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
62                                           const uint8_t *pixels,
63                                           ptrdiff_t line_size, int h);
64 void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
65                           ptrdiff_t line_size, int h);
66 void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
67                               ptrdiff_t line_size, int h);
68 void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
69                              ptrdiff_t line_size, int h);
70 void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
71                               ptrdiff_t line_size, int h);
72 void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
73                              ptrdiff_t line_size, int h);
74 void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
75                                ptrdiff_t line_size, int h);
76 void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
77                               ptrdiff_t line_size, int h);
78
79 #define avg_pixels8_mmx         ff_avg_pixels8_mmx
80 #define avg_pixels8_x2_mmx      ff_avg_pixels8_x2_mmx
81 #define avg_pixels16_mmx        ff_avg_pixels16_mmx
82 #define avg_pixels8_xy2_mmx     ff_avg_pixels8_xy2_mmx
83 #define avg_pixels16_xy2_mmx    ff_avg_pixels16_xy2_mmx
84 #define put_pixels8_mmx         ff_put_pixels8_mmx
85 #define put_pixels16_mmx        ff_put_pixels16_mmx
86 #define put_pixels8_xy2_mmx     ff_put_pixels8_xy2_mmx
87 #define put_pixels16_xy2_mmx    ff_put_pixels16_xy2_mmx
88 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
89 #define put_no_rnd_pixels8_mmx  ff_put_pixels8_mmx
90 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
91
92 #if HAVE_INLINE_ASM
93
94 /***********************************/
95 /* MMX no rounding */
96 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
97 #define SET_RND  MOVQ_WONE
98 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
99 #define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
100 #define STATIC static
101
102 #include "rnd_template.c"
103 #include "hpeldsp_rnd_template.c"
104
105 #undef DEF
106 #undef SET_RND
107 #undef PAVGBP
108 #undef PAVGB
109 #undef STATIC
110
111 PIXELS16(static, avg_no_rnd, , _y2, _mmx)
112 PIXELS16(static, put_no_rnd, , _y2, _mmx)
113
114 PIXELS16(static, avg_no_rnd, , _xy2, _mmx)
115 PIXELS16(static, put_no_rnd, , _xy2, _mmx)
116
117 /***********************************/
118 /* MMX rounding */
119
120 #define DEF(x, y) x ## _ ## y ## _mmx
121 #define SET_RND  MOVQ_WTWO
122 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
123 #define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
124
125 #include "hpeldsp_rnd_template.c"
126
127 #undef DEF
128 #undef SET_RND
129 #undef PAVGBP
130 #undef PAVGB
131
132 PIXELS16(static, avg, , _y2, _mmx)
133 PIXELS16(static, put, , _y2, _mmx)
134
135 #endif /* HAVE_INLINE_ASM */
136
137
138 #if HAVE_YASM
139
140 #define HPELDSP_AVG_PIXELS16(CPUEXT)                \
141     PIXELS16(static, put_no_rnd, ff_,  _x2, CPUEXT) \
142     PIXELS16(static, put,        ff_,  _y2, CPUEXT) \
143     PIXELS16(static, put_no_rnd, ff_,  _y2, CPUEXT) \
144     PIXELS16(static, avg,        ff_,     , CPUEXT) \
145     PIXELS16(static, avg,        ff_,  _x2, CPUEXT) \
146     PIXELS16(static, avg,        ff_,  _y2, CPUEXT) \
147     PIXELS16(static, avg,        ff_, _xy2, CPUEXT)
148
149 HPELDSP_AVG_PIXELS16(_3dnow)
150 HPELDSP_AVG_PIXELS16(_mmxext)
151
152 #endif /* HAVE_YASM */
153
154 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)                                     \
155     do {                                                                        \
156         c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _     ## CPU; \
157         c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_  ## CPU; \
158         c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_  ## CPU; \
159         c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
160     } while (0)
161
162 static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
163 {
164 #if HAVE_MMX_INLINE
165     SET_HPEL_FUNCS(put,        [0], 16, mmx);
166     SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
167     SET_HPEL_FUNCS(avg,        [0], 16, mmx);
168     SET_HPEL_FUNCS(avg_no_rnd,    , 16, mmx);
169     SET_HPEL_FUNCS(put,        [1],  8, mmx);
170     SET_HPEL_FUNCS(put_no_rnd, [1],  8, mmx);
171     SET_HPEL_FUNCS(avg,        [1],  8, mmx);
172 #endif /* HAVE_MMX_INLINE */
173 }
174
175 static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
176 {
177 #if HAVE_MMXEXT_EXTERNAL
178     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
179     c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
180
181     c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
182     c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
183     c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
184
185     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
186     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
187
188     c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
189     c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
190     c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
191
192     if (!(flags & CODEC_FLAG_BITEXACT)) {
193         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
194         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
195         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
196         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
197
198         c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
199         c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
200     }
201
202     if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
203         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
204         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
205     }
206 #endif /* HAVE_MMXEXT_EXTERNAL */
207 }
208
209 static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
210 {
211 #if HAVE_AMD3DNOW_EXTERNAL
212     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
213     c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
214
215     c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
216     c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
217     c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
218
219     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
220     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
221
222     c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
223     c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
224     c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
225
226     if (!(flags & CODEC_FLAG_BITEXACT)){
227         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
228         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
229         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
230         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
231
232         c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
233         c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
234     }
235
236     if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
237         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
238         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
239     }
240 #endif /* HAVE_AMD3DNOW_EXTERNAL */
241 }
242
243 static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
244 {
245 #if HAVE_SSE2_EXTERNAL
246     if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
247         // these functions are slower than mmx on AMD, but faster on Intel
248         c->put_pixels_tab[0][0]        = ff_put_pixels16_sse2;
249         c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
250         c->avg_pixels_tab[0][0]        = ff_avg_pixels16_sse2;
251     }
252 #endif /* HAVE_SSE2_EXTERNAL */
253 }
254
255 av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
256 {
257     int cpu_flags = av_get_cpu_flags();
258
259     if (INLINE_MMX(cpu_flags))
260         hpeldsp_init_mmx(c, flags, cpu_flags);
261
262     if (EXTERNAL_AMD3DNOW(cpu_flags))
263         hpeldsp_init_3dnow(c, flags, cpu_flags);
264
265     if (EXTERNAL_MMXEXT(cpu_flags))
266         hpeldsp_init_mmxext(c, flags, cpu_flags);
267
268     if (EXTERNAL_SSE2(cpu_flags))
269         hpeldsp_init_sse2(c, flags, cpu_flags);
270 }