]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/hpeldsp_init.c
libavcodec: fix constness in clobber test avcodec_open2() wrappers
[ffmpeg] / libavcodec / x86 / hpeldsp_init.c
1 /*
2  * SIMD-optimized halfpel functions
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/cpu.h"
28 #include "libavcodec/avcodec.h"
29 #include "libavcodec/hpeldsp.h"
30 #include "libavcodec/pixels.h"
31 #include "fpel.h"
32 #include "hpeldsp.h"
33
34 void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
35                               ptrdiff_t line_size, int h);
36 void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
37                              ptrdiff_t line_size, int h);
38 void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
39                                ptrdiff_t line_size, int h);
40 void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
41                               ptrdiff_t line_size, int h);
42 void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
43                                      ptrdiff_t line_size, int h);
44 void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
45                                     ptrdiff_t line_size, int h);
46 void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block,
47                                            const uint8_t *pixels,
48                                            ptrdiff_t line_size, int h);
49 void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block,
50                                           const uint8_t *pixels,
51                                           ptrdiff_t line_size, int h);
52 void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
53                               ptrdiff_t line_size, int h);
54 void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
55                              ptrdiff_t line_size, int h);
56 void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
57                                      ptrdiff_t line_size, int h);
58 void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
59                                     ptrdiff_t line_size, int h);
60 void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block,
61                                            const uint8_t *pixels,
62                                            ptrdiff_t line_size, int h);
63 void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block,
64                                           const uint8_t *pixels,
65                                           ptrdiff_t line_size, int h);
66 void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
67                           ptrdiff_t line_size, int h);
68 void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
69                               ptrdiff_t line_size, int h);
70 void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
71                              ptrdiff_t line_size, int h);
72 void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
73                               ptrdiff_t line_size, int h);
74 void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
75                              ptrdiff_t line_size, int h);
76 void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
77                                ptrdiff_t line_size, int h);
78 void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
79                               ptrdiff_t line_size, int h);
80
81 #define avg_pixels8_mmx         ff_avg_pixels8_mmx
82 #define avg_pixels8_x2_mmx      ff_avg_pixels8_x2_mmx
83 #define avg_pixels16_mmx        ff_avg_pixels16_mmx
84 #define avg_pixels8_xy2_mmx     ff_avg_pixels8_xy2_mmx
85 #define avg_pixels16_xy2_mmx    ff_avg_pixels16_xy2_mmx
86 #define put_pixels8_mmx         ff_put_pixels8_mmx
87 #define put_pixels16_mmx        ff_put_pixels16_mmx
88 #define put_pixels8_xy2_mmx     ff_put_pixels8_xy2_mmx
89 #define put_pixels16_xy2_mmx    ff_put_pixels16_xy2_mmx
90 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
91 #define put_no_rnd_pixels8_mmx  ff_put_pixels8_mmx
92 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
93
94 #if HAVE_INLINE_ASM
95
96 /***********************************/
97 /* MMX no rounding */
98 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
99 #define SET_RND  MOVQ_WONE
100 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
101 #define PAVGB(a, b, c, e)               PAVGB_MMX_NO_RND(a, b, c, e)
102 #define STATIC static
103
104 #include "rnd_template.c"
105 #include "hpeldsp_rnd_template.c"
106
107 #undef DEF
108 #undef SET_RND
109 #undef PAVGBP
110 #undef PAVGB
111 #undef STATIC
112
113 CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
114 CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
115
116 CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
117 CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
118
119 /***********************************/
120 /* MMX rounding */
121
122 #define DEF(x, y) x ## _ ## y ## _mmx
123 #define SET_RND  MOVQ_WTWO
124 #define PAVGBP(a, b, c, d, e, f)        PAVGBP_MMX(a, b, c, d, e, f)
125 #define PAVGB(a, b, c, e)               PAVGB_MMX(a, b, c, e)
126
127 #include "hpeldsp_rnd_template.c"
128
129 #undef DEF
130 #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
131 #define STATIC
132
133 #include "rnd_template.c"
134
135 #undef DEF
136 #undef SET_RND
137 #undef PAVGBP
138 #undef PAVGB
139
140 CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
141 CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
142
143 CALL_2X_PIXELS_EXPORT(ff_avg_pixels16_xy2_mmx, ff_avg_pixels8_xy2_mmx, 8)
144 CALL_2X_PIXELS_EXPORT(ff_put_pixels16_xy2_mmx, ff_put_pixels8_xy2_mmx, 8)
145
146 #endif /* HAVE_INLINE_ASM */
147
148
149 #if HAVE_YASM
150
151 #define HPELDSP_AVG_PIXELS16(CPUEXT)                      \
152     CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
153     CALL_2X_PIXELS(put_pixels16_y2        ## CPUEXT, ff_put_pixels8_y2        ## CPUEXT, 8) \
154     CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
155     CALL_2X_PIXELS(avg_pixels16           ## CPUEXT, ff_avg_pixels8           ## CPUEXT, 8) \
156     CALL_2X_PIXELS(avg_pixels16_x2        ## CPUEXT, ff_avg_pixels8_x2        ## CPUEXT, 8) \
157     CALL_2X_PIXELS(avg_pixels16_y2        ## CPUEXT, ff_avg_pixels8_y2        ## CPUEXT, 8) \
158     CALL_2X_PIXELS(avg_pixels16_xy2       ## CPUEXT, ff_avg_pixels8_xy2       ## CPUEXT, 8)
159
160 HPELDSP_AVG_PIXELS16(_3dnow)
161 HPELDSP_AVG_PIXELS16(_mmxext)
162
163 #endif /* HAVE_YASM */
164
165 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)                                     \
166     do {                                                                        \
167         c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _     ## CPU; \
168         c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_  ## CPU; \
169         c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_  ## CPU; \
170         c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
171     } while (0)
172
173 static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
174 {
175 #if HAVE_MMX_INLINE
176     SET_HPEL_FUNCS(put,        [0], 16, mmx);
177     SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
178     SET_HPEL_FUNCS(avg,        [0], 16, mmx);
179     SET_HPEL_FUNCS(avg_no_rnd,    , 16, mmx);
180     SET_HPEL_FUNCS(put,        [1],  8, mmx);
181     SET_HPEL_FUNCS(put_no_rnd, [1],  8, mmx);
182     SET_HPEL_FUNCS(avg,        [1],  8, mmx);
183 #endif /* HAVE_MMX_INLINE */
184 }
185
186 static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
187 {
188 #if HAVE_MMXEXT_EXTERNAL
189     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_mmxext;
190     c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
191
192     c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
193     c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
194     c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
195
196     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_mmxext;
197     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_mmxext;
198
199     c->avg_pixels_tab[1][0] = ff_avg_pixels8_mmxext;
200     c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_mmxext;
201     c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_mmxext;
202
203     if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
204         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
205         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
206         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_mmxext;
207         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_mmxext;
208
209         c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
210         c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_mmxext;
211     }
212
213     if (flags & AV_CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
214         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_mmxext;
215         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_mmxext;
216     }
217 #endif /* HAVE_MMXEXT_EXTERNAL */
218 }
219
220 static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
221 {
222 #if HAVE_AMD3DNOW_EXTERNAL
223     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_3dnow;
224     c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
225
226     c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
227     c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
228     c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
229
230     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_3dnow;
231     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_3dnow;
232
233     c->avg_pixels_tab[1][0] = ff_avg_pixels8_3dnow;
234     c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_3dnow;
235     c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_3dnow;
236
237     if (!(flags & AV_CODEC_FLAG_BITEXACT)){
238         c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
239         c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
240         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_3dnow;
241         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_3dnow;
242
243         c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
244         c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_3dnow;
245     }
246
247     if (flags & AV_CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
248         c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_exact_3dnow;
249         c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_exact_3dnow;
250     }
251 #endif /* HAVE_AMD3DNOW_EXTERNAL */
252 }
253
254 static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
255 {
256 #if HAVE_SSE2_EXTERNAL
257     if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
258         // these functions are slower than mmx on AMD, but faster on Intel
259         c->put_pixels_tab[0][0]        = ff_put_pixels16_sse2;
260         c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_sse2;
261         c->avg_pixels_tab[0][0]        = ff_avg_pixels16_sse2;
262     }
263 #endif /* HAVE_SSE2_EXTERNAL */
264 }
265
266 av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
267 {
268     int cpu_flags = av_get_cpu_flags();
269
270     if (INLINE_MMX(cpu_flags))
271         hpeldsp_init_mmx(c, flags, cpu_flags);
272
273     if (EXTERNAL_AMD3DNOW(cpu_flags))
274         hpeldsp_init_3dnow(c, flags, cpu_flags);
275
276     if (EXTERNAL_MMXEXT(cpu_flags))
277         hpeldsp_init_mmxext(c, flags, cpu_flags);
278
279     if (EXTERNAL_SSE2(cpu_flags))
280         hpeldsp_init_sse2(c, flags, cpu_flags);
281 }