FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hpeldsp_init.c
Go to the documentation of this file.
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 FFmpeg.
7  *
8  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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/avcodec.h"
30 #include "libavcodec/hpeldsp.h"
31 #include "libavcodec/pixels.h"
32 #include "fpel.h"
33 #include "hpeldsp.h"
34 
36  ptrdiff_t line_size, int h);
38  ptrdiff_t line_size, int h);
40  ptrdiff_t line_size, int h);
42  ptrdiff_t line_size, int h);
44  ptrdiff_t line_size, int h);
46  ptrdiff_t line_size, int h);
48  ptrdiff_t line_size, int h);
50  ptrdiff_t line_size, int h);
52  ptrdiff_t line_size, int h);
54  ptrdiff_t line_size, int h);
56  const uint8_t *pixels,
57  ptrdiff_t line_size, int h);
59  const uint8_t *pixels,
60  ptrdiff_t line_size, int h);
62  ptrdiff_t line_size, int h);
64  ptrdiff_t line_size, int h);
66  ptrdiff_t line_size, int h);
68  ptrdiff_t line_size, int h);
70  const uint8_t *pixels,
71  ptrdiff_t line_size, int h);
73  const uint8_t *pixels,
74  ptrdiff_t line_size, int h);
76  ptrdiff_t line_size, int h);
78  ptrdiff_t line_size, int h);
80  ptrdiff_t line_size, int h);
82  ptrdiff_t line_size, int h);
84  ptrdiff_t line_size, int h);
86  ptrdiff_t line_size, int h);
88  ptrdiff_t line_size, int h);
90  ptrdiff_t line_size, int h);
91 
92 #define avg_pixels8_mmx ff_avg_pixels8_mmx
93 #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
94 #define avg_pixels16_mmx ff_avg_pixels16_mmx
95 #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
96 #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
97 #define put_pixels8_mmx ff_put_pixels8_mmx
98 #define put_pixels16_mmx ff_put_pixels16_mmx
99 #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
100 #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
101 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
102 #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
103 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
104 
105 #if HAVE_INLINE_ASM
106 
107 /***********************************/
108 /* MMX no rounding */
109 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
110 #define SET_RND MOVQ_WONE
111 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
112 #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
113 #define STATIC static
114 
115 #include "rnd_template.c"
116 #include "hpeldsp_rnd_template.c"
117 
118 #undef DEF
119 #undef SET_RND
120 #undef PAVGBP
121 #undef PAVGB
122 #undef STATIC
123 
124 #if HAVE_MMX
125 CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
126 CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
127 
128 CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
129 CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
130 #endif
131 
132 /***********************************/
133 /* MMX rounding */
134 
135 #define DEF(x, y) x ## _ ## y ## _mmx
136 #define SET_RND MOVQ_WTWO
137 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
138 #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
139 
140 #include "hpeldsp_rnd_template.c"
141 
142 #undef DEF
143 #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
144 #define STATIC
145 
146 #include "rnd_template.c"
147 
148 #undef DEF
149 #undef SET_RND
150 #undef PAVGBP
151 #undef PAVGB
152 
153 #if HAVE_MMX
154 CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
155 CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
156 
159 #endif
160 
161 #endif /* HAVE_INLINE_ASM */
162 
163 
164 #if HAVE_YASM
165 
166 #define HPELDSP_AVG_PIXELS16(CPUEXT) \
167  CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
168  CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
169  CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
170  CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
171  CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
172  CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
173  CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8) \
174  CALL_2X_PIXELS(avg_approx_pixels16_xy2## CPUEXT, ff_avg_approx_pixels8_xy2## CPUEXT, 8)
175 
176 HPELDSP_AVG_PIXELS16(_3dnow)
177 HPELDSP_AVG_PIXELS16(_mmxext)
178 
179 #endif /* HAVE_YASM */
180 
181 #define SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
182  if (HAVE_MMX_EXTERNAL) \
183  c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU;
184 
185 #if HAVE_MMX_INLINE
186 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
187  do { \
188  SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
189  c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
190  c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
191  c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
192  } while (0)
193 #else
194 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
195  do { \
196  SET_HPEL_FUNCS_EXT(PFX, IDX, SIZE, CPU) \
197  } while (0)
198 #endif
199 
200 static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
201 {
202  SET_HPEL_FUNCS(put, [0], 16, mmx);
203  SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
204  SET_HPEL_FUNCS(avg, [0], 16, mmx);
205  SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
206  SET_HPEL_FUNCS(put, [1], 8, mmx);
207  SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
208  if (HAVE_MMX_EXTERNAL) {
211  }
212 #if HAVE_MMX_INLINE
213  c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
215 #endif
216 }
217 
218 static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
219 {
220 #if HAVE_MMXEXT_EXTERNAL
222  c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
223 
224  c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
225  c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
226  c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
227  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
228 
231 
236 
237  if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
238  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
239  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
242 
243  c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_mmxext;
245  }
246 
247  if (CONFIG_VP3_DECODER && flags & AV_CODEC_FLAG_BITEXACT) {
250  }
251 #endif /* HAVE_MMXEXT_EXTERNAL */
252 }
253 
254 static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
255 {
256 #if HAVE_AMD3DNOW_EXTERNAL
258  c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
259 
260  c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
261  c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
262  c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
263  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
264 
267 
272 
273  if (!(flags & AV_CODEC_FLAG_BITEXACT)){
274  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
275  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
278 
279  c->avg_pixels_tab[0][3] = avg_approx_pixels16_xy2_3dnow;
281  }
282 
283  if (CONFIG_VP3_DECODER && flags & AV_CODEC_FLAG_BITEXACT) {
286  }
287 #endif /* HAVE_AMD3DNOW_EXTERNAL */
288 }
289 
290 static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
291 {
292 #if HAVE_SSE2_EXTERNAL
293  if (!(cpu_flags & AV_CPU_FLAG_SSE2SLOW)) {
294  // these functions are slower than mmx on AMD, but faster on Intel
304  }
305 #endif /* HAVE_SSE2_EXTERNAL */
306 }
307 
308 static void hpeldsp_init_ssse3(HpelDSPContext *c, int flags, int cpu_flags)
309 {
310 #if HAVE_SSSE3_EXTERNAL
315 #endif
316 }
317 
319 {
320  int cpu_flags = av_get_cpu_flags();
321 
322  if (INLINE_MMX(cpu_flags))
323  hpeldsp_init_mmx(c, flags, cpu_flags);
324 
325  if (EXTERNAL_AMD3DNOW(cpu_flags))
326  hpeldsp_init_3dnow(c, flags, cpu_flags);
327 
328  if (EXTERNAL_MMXEXT(cpu_flags))
329  hpeldsp_init_mmxext(c, flags, cpu_flags);
330 
331  if (EXTERNAL_SSE2(cpu_flags))
332  hpeldsp_init_sse2(c, flags, cpu_flags);
333 
334  if (EXTERNAL_SSSE3(cpu_flags))
335  hpeldsp_init_ssse3(c, flags, cpu_flags);
336 }
void ff_put_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_y2_exact_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
Definition: hpeldsp.h:68
void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels16_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int cpu_flags)
Definition: hpeldsp_init.c:254
static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int cpu_flags)
Definition: hpeldsp_init.c:200
Macro definitions for various function/variable attributes.
static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int cpu_flags)
Definition: hpeldsp_init.c:218
void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
uint8_t
#define av_cold
Definition: attributes.h:82
void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_y2_exact_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels16_xy2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
av_cold void ff_hpeldsp_init_x86(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:318
void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
Definition: cpu.h:35
#define CALL_2X_PIXELS(a, b, n)
Definition: pixels.h:34
#define EXTERNAL_SSE2(flags)
Definition: cpu.h:57
void ff_avg_pixels16_y2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define INLINE_MMX(flags)
Definition: cpu.h:81
void ff_put_pixels8_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels16_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Half-pel DSP context.
Definition: hpeldsp.h:45
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:787
static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int cpu_flags)
Definition: hpeldsp_init.c:290
#define CALL_2X_PIXELS_EXPORT(a, b, n)
Definition: pixels.h:35
#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)
Definition: hpeldsp_init.c:194
void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels16_x2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Half-pel DSP functions.
Libavcodec external API header.
void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
Definition: hpeldsp.h:56
void ff_put_no_rnd_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define EXTERNAL_SSSE3(flags)
Definition: cpu.h:63
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
Definition: hpeldsp.h:80
void ff_put_pixels8_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
void ff_avg_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels16_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static int flags
Definition: cpu.c:47
void ff_put_pixels16_xy2_ssse3(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define EXTERNAL_MMXEXT(flags)
Definition: cpu.h:55
void ff_avg_pixels8_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels16_xy2_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_x2_exact_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_approx_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static double c[64]
void ff_put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_approx_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
int pixels
Definition: avisynth_c.h:298
void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_x2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
void ff_put_no_rnd_pixels8_x2_exact_3dnow(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static void hpeldsp_init_ssse3(HpelDSPContext *c, int flags, int cpu_flags)
Definition: hpeldsp_init.c:308
#define EXTERNAL_AMD3DNOW(flags)
Definition: cpu.h:52
void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static int16_t block[64]
Definition: dct-test.c:112