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/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);
43  ptrdiff_t line_size, int h);
45  ptrdiff_t line_size, int h);
46 void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
47  ptrdiff_t line_size, int h);
48 void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
49  ptrdiff_t line_size, int h);
51  ptrdiff_t line_size, int h);
53  ptrdiff_t line_size, int h);
54 void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
55  ptrdiff_t line_size, int h);
56 void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
57  ptrdiff_t line_size, int h);
58 void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
59  ptrdiff_t line_size, int h);
60 void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
61  ptrdiff_t line_size, int h);
62 void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
63  ptrdiff_t line_size, int h);
64 void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
65  ptrdiff_t line_size, int h);
66 void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
67  ptrdiff_t line_size, int h);
68 
69 #define avg_pixels8_mmx ff_avg_pixels8_mmx
70 #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
71 #define avg_pixels16_mmx ff_avg_pixels16_mmx
72 #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
73 #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
74 #define put_pixels8_mmx ff_put_pixels8_mmx
75 #define put_pixels16_mmx ff_put_pixels16_mmx
76 #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
77 #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
78 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
79 #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
80 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
81 
82 #if HAVE_INLINE_ASM
83 
84 /***********************************/
85 /* MMX no rounding */
86 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
87 #define SET_RND MOVQ_WONE
88 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
89 #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
90 #define STATIC static
91 
92 #include "rnd_template.c"
93 #include "hpeldsp_rnd_template.c"
94 
95 #undef DEF
96 #undef SET_RND
97 #undef PAVGBP
98 #undef PAVGB
99 #undef STATIC
100 
101 CALL_2X_PIXELS(avg_no_rnd_pixels16_y2_mmx, avg_no_rnd_pixels8_y2_mmx, 8)
102 CALL_2X_PIXELS(put_no_rnd_pixels16_y2_mmx, put_no_rnd_pixels8_y2_mmx, 8)
103 
104 CALL_2X_PIXELS(avg_no_rnd_pixels16_xy2_mmx, avg_no_rnd_pixels8_xy2_mmx, 8)
105 CALL_2X_PIXELS(put_no_rnd_pixels16_xy2_mmx, put_no_rnd_pixels8_xy2_mmx, 8)
106 
107 /***********************************/
108 /* MMX rounding */
109 
110 #define DEF(x, y) x ## _ ## y ## _mmx
111 #define SET_RND MOVQ_WTWO
112 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
113 #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
114 
115 #include "hpeldsp_rnd_template.c"
116 
117 #undef DEF
118 #define DEF(x, y) ff_ ## x ## _ ## y ## _mmx
119 #define STATIC
120 
121 #include "rnd_template.c"
122 
123 #undef DEF
124 #undef SET_RND
125 #undef PAVGBP
126 #undef PAVGB
127 
128 CALL_2X_PIXELS(avg_pixels16_y2_mmx, avg_pixels8_y2_mmx, 8)
129 CALL_2X_PIXELS(put_pixels16_y2_mmx, put_pixels8_y2_mmx, 8)
130 
133 
134 #endif /* HAVE_INLINE_ASM */
135 
136 
137 #if HAVE_YASM
138 
139 #define HPELDSP_AVG_PIXELS16(CPUEXT) \
140  CALL_2X_PIXELS(put_no_rnd_pixels16_x2 ## CPUEXT, ff_put_no_rnd_pixels8_x2 ## CPUEXT, 8) \
141  CALL_2X_PIXELS(put_pixels16_y2 ## CPUEXT, ff_put_pixels8_y2 ## CPUEXT, 8) \
142  CALL_2X_PIXELS(put_no_rnd_pixels16_y2 ## CPUEXT, ff_put_no_rnd_pixels8_y2 ## CPUEXT, 8) \
143  CALL_2X_PIXELS(avg_pixels16 ## CPUEXT, ff_avg_pixels8 ## CPUEXT, 8) \
144  CALL_2X_PIXELS(avg_pixels16_x2 ## CPUEXT, ff_avg_pixels8_x2 ## CPUEXT, 8) \
145  CALL_2X_PIXELS(avg_pixels16_y2 ## CPUEXT, ff_avg_pixels8_y2 ## CPUEXT, 8) \
146  CALL_2X_PIXELS(avg_pixels16_xy2 ## CPUEXT, ff_avg_pixels8_xy2 ## CPUEXT, 8)
147 
148 HPELDSP_AVG_PIXELS16(_3dnow)
149 HPELDSP_AVG_PIXELS16(_mmxext)
150 
151 #endif /* HAVE_YASM */
152 
153 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
154  do { \
155  c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
156  c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
157  c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
158  c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
159  } while (0)
160 
162 {
163 #if HAVE_MMX_INLINE
164  SET_HPEL_FUNCS(put, [0], 16, mmx);
165  SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
166  SET_HPEL_FUNCS(avg, [0], 16, mmx);
167  SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
168  SET_HPEL_FUNCS(put, [1], 8, mmx);
169  SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
170  SET_HPEL_FUNCS(avg, [1], 8, mmx);
171 #endif /* HAVE_MMX_INLINE */
172 }
173 
175 {
176 #if HAVE_MMXEXT_EXTERNAL
178  c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
179 
180  c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
181  c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
182  c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
183 
186 
190 
191  if (!(flags & AV_CODEC_FLAG_BITEXACT)) {
192  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
193  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
196 
197  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
199  }
200 #endif /* HAVE_MMXEXT_EXTERNAL */
201 }
202 
204 {
205 #if HAVE_AMD3DNOW_EXTERNAL
207  c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
208 
209  c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
210  c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
211  c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
212 
215 
219 
220  if (!(flags & AV_CODEC_FLAG_BITEXACT)){
221  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
222  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
225 
226  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
228  }
229 #endif /* HAVE_AMD3DNOW_EXTERNAL */
230 }
231 
233 {
234 #if HAVE_SSE2_EXTERNAL
238 #endif /* HAVE_SSE2_EXTERNAL */
239 }
240 
242 {
243  int cpu_flags = av_get_cpu_flags();
244 
245  if (INLINE_MMX(cpu_flags))
246  hpeldsp_init_mmx(c, flags);
247 
248  if (EXTERNAL_AMD3DNOW(cpu_flags))
249  hpeldsp_init_3dnow(c, flags);
250 
251  if (EXTERNAL_MMXEXT(cpu_flags))
252  hpeldsp_init_mmxext(c, flags);
253 
254  if (EXTERNAL_SSE2_FAST(cpu_flags))
255  hpeldsp_init_sse2_fast(c, flags);
256 
257  if (CONFIG_VP3_DECODER)
258  ff_hpeldsp_vp3_init_x86(c, cpu_flags);
259 }
void ff_put_pixels8_x2_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
static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:203
void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static void hpeldsp_init_mmx(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:161
Macro definitions for various function/variable attributes.
static int16_t block[64]
Definition: dct.c:97
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_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:241
void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define EXTERNAL_SSE2_FAST(flags)
Definition: cpu.h:59
static int flags
Definition: log.c:50
void ff_hpeldsp_vp3_init_x86(HpelDSPContext *c, int cpu_flags)
void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
#define CALL_2X_PIXELS(a, b, n)
Definition: pixels.h:34
#define INLINE_MMX(flags)
Definition: cpu.h:79
void ff_put_pixels8_xy2_mmx(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:174
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)
static void hpeldsp_init_sse2_fast(HpelDSPContext *c, int flags)
Definition: hpeldsp_init.c:232
Half-pel DSP context.
Definition: hpeldsp.h:45
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:788
#define CALL_2X_PIXELS_EXPORT(a, b, n)
Definition: pixels.h:35
#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU)
Definition: hpeldsp_init.c:153
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[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
Definition: hpeldsp.h:82
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:56
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)
#define CONFIG_VP3_DECODER
Definition: config.h:701
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)
#define EXTERNAL_AMD3DNOW(flags)
Definition: cpu.h:53