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