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  * 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 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/cpu.h"
26 #include "libavutil/x86/asm.h"
27 #include "libavcodec/hpeldsp.h"
28 #include "dsputil_x86.h"
29 
30 void ff_put_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
31  ptrdiff_t line_size, int h);
32 void ff_put_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
33  ptrdiff_t line_size, int h);
34 void ff_put_pixels16_x2_mmxext(uint8_t *block, const uint8_t *pixels,
35  ptrdiff_t line_size, int h);
36 void ff_put_pixels16_x2_3dnow(uint8_t *block, const uint8_t *pixels,
37  ptrdiff_t line_size, int h);
39  ptrdiff_t line_size, int h);
41  ptrdiff_t line_size, int h);
43  const uint8_t *pixels,
44  ptrdiff_t line_size, int h);
46  const uint8_t *pixels,
47  ptrdiff_t line_size, int h);
48 void ff_put_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
49  ptrdiff_t line_size, int h);
50 void ff_put_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
51  ptrdiff_t line_size, int h);
53  ptrdiff_t line_size, int h);
55  ptrdiff_t line_size, int h);
57  const uint8_t *pixels,
58  ptrdiff_t line_size, int h);
60  const uint8_t *pixels,
61  ptrdiff_t line_size, int h);
62 void ff_avg_pixels8_3dnow(uint8_t *block, const uint8_t *pixels,
63  ptrdiff_t line_size, int h);
64 void ff_avg_pixels8_x2_mmxext(uint8_t *block, const uint8_t *pixels,
65  ptrdiff_t line_size, int h);
66 void ff_avg_pixels8_x2_3dnow(uint8_t *block, const uint8_t *pixels,
67  ptrdiff_t line_size, int h);
68 void ff_avg_pixels8_y2_mmxext(uint8_t *block, const uint8_t *pixels,
69  ptrdiff_t line_size, int h);
70 void ff_avg_pixels8_y2_3dnow(uint8_t *block, const uint8_t *pixels,
71  ptrdiff_t line_size, int h);
72 void ff_avg_pixels8_xy2_mmxext(uint8_t *block, const uint8_t *pixels,
73  ptrdiff_t line_size, int h);
74 void ff_avg_pixels8_xy2_3dnow(uint8_t *block, const uint8_t *pixels,
75  ptrdiff_t line_size, int h);
76 
77 #define avg_pixels8_mmx ff_avg_pixels8_mmx
78 #define avg_pixels8_x2_mmx ff_avg_pixels8_x2_mmx
79 #define avg_pixels16_mmx ff_avg_pixels16_mmx
80 #define avg_pixels8_xy2_mmx ff_avg_pixels8_xy2_mmx
81 #define avg_pixels16_xy2_mmx ff_avg_pixels16_xy2_mmx
82 #define put_pixels8_mmx ff_put_pixels8_mmx
83 #define put_pixels16_mmx ff_put_pixels16_mmx
84 #define put_pixels8_xy2_mmx ff_put_pixels8_xy2_mmx
85 #define put_pixels16_xy2_mmx ff_put_pixels16_xy2_mmx
86 #define avg_no_rnd_pixels16_mmx ff_avg_pixels16_mmx
87 #define put_no_rnd_pixels8_mmx ff_put_pixels8_mmx
88 #define put_no_rnd_pixels16_mmx ff_put_pixels16_mmx
89 
90 #if HAVE_INLINE_ASM
91 
92 /***********************************/
93 /* MMX no rounding */
94 #define DEF(x, y) x ## _no_rnd_ ## y ## _mmx
95 #define SET_RND MOVQ_WONE
96 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
97 #define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
98 #define STATIC static
99 
100 #include "rnd_template.c"
101 #include "hpeldsp_rnd_template.c"
102 
103 #undef DEF
104 #undef SET_RND
105 #undef PAVGBP
106 #undef PAVGB
107 #undef STATIC
108 
109 PIXELS16(static, avg_no_rnd, , _y2, _mmx)
110 PIXELS16(static, put_no_rnd, , _y2, _mmx)
111 
112 PIXELS16(static, avg_no_rnd, , _xy2, _mmx)
113 PIXELS16(static, put_no_rnd, , _xy2, _mmx)
114 
115 /***********************************/
116 /* MMX rounding */
117 
118 #define DEF(x, y) x ## _ ## y ## _mmx
119 #define SET_RND MOVQ_WTWO
120 #define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
121 #define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
122 
123 #include "hpeldsp_rnd_template.c"
124 
125 #undef DEF
126 #undef SET_RND
127 #undef PAVGBP
128 #undef PAVGB
129 
130 PIXELS16(static, avg, , _y2, _mmx)
131 PIXELS16(static, put, , _y2, _mmx)
132 
133 #endif /* HAVE_INLINE_ASM */
134 
135 
136 #if HAVE_YASM
137 
138 #define HPELDSP_AVG_PIXELS16(CPUEXT) \
139  PIXELS16(static, put_no_rnd, ff_, _x2, CPUEXT) \
140  PIXELS16(static, put, ff_, _y2, CPUEXT) \
141  PIXELS16(static, put_no_rnd, ff_, _y2, CPUEXT) \
142  PIXELS16(static, avg, ff_, , CPUEXT) \
143  PIXELS16(static, avg, ff_, _x2, CPUEXT) \
144  PIXELS16(static, avg, ff_, _y2, CPUEXT) \
145  PIXELS16(static, avg, ff_, _xy2, CPUEXT)
146 
147 HPELDSP_AVG_PIXELS16(_3dnow)
148 HPELDSP_AVG_PIXELS16(_mmxext)
149 
150 #endif /* HAVE_YASM */
151 
152 #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \
153  do { \
154  c->PFX ## _pixels_tab IDX [0] = PFX ## _pixels ## SIZE ## _ ## CPU; \
155  c->PFX ## _pixels_tab IDX [1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \
156  c->PFX ## _pixels_tab IDX [2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \
157  c->PFX ## _pixels_tab IDX [3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU; \
158  } while (0)
159 
160 static void hpeldsp_init_mmx(HpelDSPContext *c, int flags, int mm_flags)
161 {
162 #if HAVE_MMX_INLINE
163  SET_HPEL_FUNCS(put, [0], 16, mmx);
164  SET_HPEL_FUNCS(put_no_rnd, [0], 16, mmx);
165  SET_HPEL_FUNCS(avg, [0], 16, mmx);
166  SET_HPEL_FUNCS(avg_no_rnd, , 16, mmx);
167  SET_HPEL_FUNCS(put, [1], 8, mmx);
168  SET_HPEL_FUNCS(put_no_rnd, [1], 8, mmx);
169  SET_HPEL_FUNCS(avg, [1], 8, mmx);
170 #endif /* HAVE_MMX_INLINE */
171 }
172 
173 static void hpeldsp_init_mmxext(HpelDSPContext *c, int flags, int mm_flags)
174 {
175 #if HAVE_MMXEXT_EXTERNAL
177  c->put_pixels_tab[0][2] = put_pixels16_y2_mmxext;
178 
179  c->avg_pixels_tab[0][0] = avg_pixels16_mmxext;
180  c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmxext;
181  c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmxext;
182 
185 
189 
190  if (!(flags & CODEC_FLAG_BITEXACT)) {
191  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmxext;
192  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmxext;
195 
196  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmxext;
198  }
199 
200  if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
203  }
204 #endif /* HAVE_MMXEXT_EXTERNAL */
205 }
206 
207 static void hpeldsp_init_3dnow(HpelDSPContext *c, int flags, int mm_flags)
208 {
209 #if HAVE_AMD3DNOW_EXTERNAL
211  c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
212 
213  c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
214  c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
215  c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
216 
219 
223 
224  if (!(flags & CODEC_FLAG_BITEXACT)){
225  c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
226  c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
229 
230  c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
232  }
233 
234  if (flags & CODEC_FLAG_BITEXACT && CONFIG_VP3_DECODER) {
237  }
238 #endif /* HAVE_AMD3DNOW_EXTERNAL */
239 }
240 
241 static void hpeldsp_init_sse2(HpelDSPContext *c, int flags, int mm_flags)
242 {
243 #if HAVE_SSE2_EXTERNAL
244  if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) {
245  // these functions are slower than mmx on AMD, but faster on Intel
249  }
250 #endif /* HAVE_SSE2_EXTERNAL */
251 }
252 
254 {
255  int mm_flags = av_get_cpu_flags();
256 
257  if (HAVE_MMX && mm_flags & AV_CPU_FLAG_MMX)
258  hpeldsp_init_mmx(c, flags, mm_flags);
259 
260  if (mm_flags & AV_CPU_FLAG_MMXEXT)
261  hpeldsp_init_mmxext(c, flags, mm_flags);
262 
263  if (mm_flags & AV_CPU_FLAG_3DNOW)
264  hpeldsp_init_3dnow(c, flags, mm_flags);
265 
266  if (mm_flags & AV_CPU_FLAG_SSE2)
267  hpeldsp_init_sse2(c, flags, mm_flags);
268 }