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