x86/h264_qpel.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt
3  * Copyright (c) 2011 Daniel Kang
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/x86/asm.h"
25 #include "libavutil/x86/cpu.h"
26 #include "libavcodec/h264qpel.h"
27 #include "libavcodec/mpegvideo.h"
28 #include "dsputil_mmx.h"
29 
30 #if HAVE_YASM
31 void ff_put_pixels4_mmxext(uint8_t *block, const uint8_t *pixels,
32  ptrdiff_t line_size, int h);
33 void ff_avg_pixels4_mmxext(uint8_t *block, const uint8_t *pixels,
34  ptrdiff_t line_size, int h);
35 static void ff_put_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
36  ptrdiff_t line_size, int h)
37 {
38  ff_put_pixels8_mmxext(block, pixels, line_size, h);
39  ff_put_pixels8_mmxext(block + 8, pixels + 8, line_size, h);
40 }
41 static void ff_avg_pixels16_mmxext(uint8_t *block, const uint8_t *pixels,
42  ptrdiff_t line_size, int h)
43 {
44  ff_avg_pixels8_mmxext(block, pixels, line_size, h);
45  ff_avg_pixels8_mmxext(block + 8, pixels + 8, line_size, h);
46 }
47 void ff_put_pixels4_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
48  int dstStride, int src1Stride, int h);
49 void ff_avg_pixels4_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
50  int dstStride, int src1Stride, int h);
51 void ff_put_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
52  int dstStride, int src1Stride, int h);
53 void ff_avg_pixels8_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
54  int dstStride, int src1Stride, int h);
55 void ff_put_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
56  int dstStride, int src1Stride, int h);
57 void ff_avg_pixels16_l2_mmxext(uint8_t *dst, uint8_t *src1, uint8_t *src2,
58  int dstStride, int src1Stride, int h);
59 #define ff_put_pixels8_l2_sse2 ff_put_pixels8_l2_mmxext
60 #define ff_avg_pixels8_l2_sse2 ff_avg_pixels8_l2_mmxext
61 #define ff_put_pixels16_l2_sse2 ff_put_pixels16_l2_mmxext
62 #define ff_avg_pixels16_l2_sse2 ff_avg_pixels16_l2_mmxext
63 
64 #define DEF_QPEL(OPNAME)\
65 void ff_ ## OPNAME ## _h264_qpel4_h_lowpass_mmxext(uint8_t *dst, uint8_t *src, int dstStride, int srcStride);\
66 void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_mmxext(uint8_t *dst, uint8_t *src, int dstStride, int srcStride);\
67 void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_ssse3(uint8_t *dst, uint8_t *src, int dstStride, int srcStride);\
68 void ff_ ## OPNAME ## _h264_qpel4_h_lowpass_l2_mmxext(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride);\
69 void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_l2_mmxext(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride);\
70 void ff_ ## OPNAME ## _h264_qpel8_h_lowpass_l2_ssse3(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride);\
71 void ff_ ## OPNAME ## _h264_qpel4_v_lowpass_mmxext(uint8_t *dst, uint8_t *src, int dstStride, int srcStride);\
72 void ff_ ## OPNAME ## _h264_qpel8or16_v_lowpass_op_mmxext(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h);\
73 void ff_ ## OPNAME ## _h264_qpel8or16_v_lowpass_sse2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h);\
74 void ff_ ## OPNAME ## _h264_qpel4_hv_lowpass_v_mmxext(uint8_t *src, int16_t *tmp, int srcStride);\
75 void ff_ ## OPNAME ## _h264_qpel4_hv_lowpass_h_mmxext(int16_t *tmp, uint8_t *dst, int dstStride);\
76 void ff_ ## OPNAME ## _h264_qpel8or16_hv1_lowpass_op_mmxext(uint8_t *src, int16_t *tmp, int srcStride, int size);\
77 void ff_ ## OPNAME ## _h264_qpel8or16_hv1_lowpass_op_sse2(uint8_t *src, int16_t *tmp, int srcStride, int size);\
78 void ff_ ## OPNAME ## _h264_qpel8or16_hv2_lowpass_op_mmxext(uint8_t *dst, int16_t *tmp, int dstStride, int unused, int h);\
79 void ff_ ## OPNAME ## _h264_qpel8or16_hv2_lowpass_ssse3(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size);\
80 void ff_ ## OPNAME ## _pixels4_l2_shift5_mmxext(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h);\
81 void ff_ ## OPNAME ## _pixels8_l2_shift5_mmxext(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h);
82 
83 DEF_QPEL(avg)
84 DEF_QPEL(put)
85 
86 #define QPEL_H264(OPNAME, OP, MMX)\
87 static av_always_inline void ff_ ## OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
88  int w=3;\
89  src -= 2*srcStride+2;\
90  while(w--){\
91  ff_ ## OPNAME ## h264_qpel4_hv_lowpass_v_mmxext(src, tmp, srcStride);\
92  tmp += 4;\
93  src += 4;\
94  }\
95  tmp -= 3*4;\
96  ff_ ## OPNAME ## h264_qpel4_hv_lowpass_h_mmxext(tmp, dst, dstStride);\
97 }\
98 \
99 static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
100  src -= 2*srcStride;\
101  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_op_mmxext(dst, src, dstStride, srcStride, h);\
102  src += 4;\
103  dst += 4;\
104  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_op_mmxext(dst, src, dstStride, srcStride, h);\
105 }\
106 static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){\
107  int w = (size+8)>>2;\
108  src -= 2*srcStride+2;\
109  while(w--){\
110  ff_ ## OPNAME ## h264_qpel8or16_hv1_lowpass_op_mmxext(src, tmp, srcStride, size);\
111  tmp += 4;\
112  src += 4;\
113  }\
114 }\
115 static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\
116  int w = size>>4;\
117  do{\
118  ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_op_mmxext(dst, tmp, dstStride, 0, size);\
119  tmp += 8;\
120  dst += 8;\
121  }while(w--);\
122 }\
123 \
124 static av_always_inline void ff_ ## OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
125  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
126 }\
127 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
128  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
129  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
130 }\
131 \
132 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
133  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
134  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
135  src += 8*srcStride;\
136  dst += 8*dstStride;\
137  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
138  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
139 }\
140 \
141 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
142  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
143  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
144  src += 8*dstStride;\
145  dst += 8*dstStride;\
146  src2 += 8*src2Stride;\
147  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
148  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
149 }\
150 \
151 static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
152  ff_put_h264_qpel8or16_hv1_lowpass_ ## MMX(tmp, src, tmpStride, srcStride, size);\
153  ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
154 }\
155 static av_always_inline void ff_ ## OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
156  ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\
157 }\
158 \
159 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
160  ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 16);\
161 }\
162 \
163 static av_always_inline void ff_ ## OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\
164 {\
165  ff_ ## OPNAME ## pixels8_l2_shift5_ ## MMX(dst , src16 , src8 , dstStride, src8Stride, h);\
166  ff_ ## OPNAME ## pixels8_l2_shift5_ ## MMX(dst+8, src16+8, src8+8, dstStride, src8Stride, h);\
167 }\
168 
169 
170 #if ARCH_X86_64
171 #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
172 
173 void ff_avg_h264_qpel16_h_lowpass_l2_ssse3(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride);
174 void ff_put_h264_qpel16_h_lowpass_l2_ssse3(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride);
175 
176 #else // ARCH_X86_64
177 #define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
178 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\
179  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
180  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
181  src += 8*dstStride;\
182  dst += 8*dstStride;\
183  src2 += 8*src2Stride;\
184  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\
185  ff_ ## OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\
186 }
187 #endif // ARCH_X86_64
188 
189 #define QPEL_H264_H_XMM(OPNAME, OP, MMX)\
190 QPEL_H264_H16_XMM(OPNAME, OP, MMX)\
191 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
192  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
193  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
194  src += 8*srcStride;\
195  dst += 8*dstStride;\
196  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\
197  ff_ ## OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\
198 }\
199 
200 #define QPEL_H264_V_XMM(OPNAME, OP, MMX)\
201 static av_always_inline void ff_ ## OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
202  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\
203 }\
204 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
205  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\
206  ff_ ## OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\
207 }
208 
209 static av_always_inline void ff_put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){
210  int w = (size+8)>>3;
211  src -= 2*srcStride+2;
212  while(w--){
213  ff_put_h264_qpel8or16_hv1_lowpass_op_sse2(src, tmp, srcStride, size);
214  tmp += 8;
215  src += 8;
216  }
217 }
218 
219 #define QPEL_H264_HV_XMM(OPNAME, OP, MMX)\
220 static av_always_inline void ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\
221  ff_put_h264_qpel8or16_hv1_lowpass_sse2(tmp, src, tmpStride, srcStride, size);\
222  ff_ ## OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\
223 }\
224 static av_always_inline void ff_ ## OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
225  ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 8);\
226 }\
227 static av_always_inline void ff_ ## OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
228  ff_ ## OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 16);\
229 }\
230 
231 #define ff_put_h264_qpel8_h_lowpass_l2_sse2 ff_put_h264_qpel8_h_lowpass_l2_mmxext
232 #define ff_avg_h264_qpel8_h_lowpass_l2_sse2 ff_avg_h264_qpel8_h_lowpass_l2_mmxext
233 #define ff_put_h264_qpel16_h_lowpass_l2_sse2 ff_put_h264_qpel16_h_lowpass_l2_mmxext
234 #define ff_avg_h264_qpel16_h_lowpass_l2_sse2 ff_avg_h264_qpel16_h_lowpass_l2_mmxext
235 
236 #define ff_put_h264_qpel8_v_lowpass_ssse3 ff_put_h264_qpel8_v_lowpass_sse2
237 #define ff_avg_h264_qpel8_v_lowpass_ssse3 ff_avg_h264_qpel8_v_lowpass_sse2
238 #define ff_put_h264_qpel16_v_lowpass_ssse3 ff_put_h264_qpel16_v_lowpass_sse2
239 #define ff_avg_h264_qpel16_v_lowpass_ssse3 ff_avg_h264_qpel16_v_lowpass_sse2
240 
241 #define ff_put_h264_qpel8or16_hv2_lowpass_sse2 ff_put_h264_qpel8or16_hv2_lowpass_mmxext
242 #define ff_avg_h264_qpel8or16_hv2_lowpass_sse2 ff_avg_h264_qpel8or16_hv2_lowpass_mmxext
243 
244 #define H264_MC(OPNAME, SIZE, MMX, ALIGN) \
245 H264_MC_C(OPNAME, SIZE, MMX, ALIGN)\
246 H264_MC_V(OPNAME, SIZE, MMX, ALIGN)\
247 H264_MC_H(OPNAME, SIZE, MMX, ALIGN)\
248 H264_MC_HV(OPNAME, SIZE, MMX, ALIGN)\
249 
250 static void put_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src,
251  ptrdiff_t stride)
252 {
253  ff_put_pixels16_sse2(dst, src, stride, 16);
254 }
255 static void avg_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src,
256  ptrdiff_t stride)
257 {
258  ff_avg_pixels16_sse2(dst, src, stride, 16);
259 }
260 #define put_h264_qpel8_mc00_sse2 put_h264_qpel8_mc00_mmxext
261 #define avg_h264_qpel8_mc00_sse2 avg_h264_qpel8_mc00_mmxext
262 
263 #define H264_MC_C(OPNAME, SIZE, MMX, ALIGN) \
264 static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
265 {\
266  ff_ ## OPNAME ## pixels ## SIZE ## _ ## MMX(dst, src, stride, SIZE);\
267 }\
268 
269 #define H264_MC_H(OPNAME, SIZE, MMX, ALIGN) \
270 static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
271 {\
272  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\
273 }\
274 \
275 static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
276 {\
277  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## MMX(dst, src, stride, stride);\
278 }\
279 \
280 static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
281 {\
282  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\
283 }\
284 
285 #define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \
286 static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
287 {\
288  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
289  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
290  ff_ ## OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\
291 }\
292 \
293 static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
294 {\
295  ff_ ## OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## MMX(dst, src, stride, stride);\
296 }\
297 \
298 static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
299 {\
300  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
301  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
302  ff_ ## OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\
303 }\
304 
305 #define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \
306 static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
307 {\
308  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
309  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
310  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
311 }\
312 \
313 static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
314 {\
315  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
316  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
317  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\
318 }\
319 \
320 static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
321 {\
322  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
323  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\
324  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
325 }\
326 \
327 static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
328 {\
329  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\
330  ff_put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\
331  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\
332 }\
333 \
334 static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
335 {\
336  DECLARE_ALIGNED(ALIGN, uint16_t, temp)[SIZE*(SIZE<8?12:24)];\
337  ff_ ## OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\
338 }\
339 \
340 static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
341 {\
342  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
343  uint8_t * const halfHV= temp;\
344  int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
345  av_assert2(((int)temp & 7) == 0);\
346  ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
347  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\
348 }\
349 \
350 static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
351 {\
352  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
353  uint8_t * const halfHV= temp;\
354  int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
355  av_assert2(((int)temp & 7) == 0);\
356  ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
357  ff_ ## OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\
358 }\
359 \
360 static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
361 {\
362  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
363  uint8_t * const halfHV= temp;\
364  int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
365  av_assert2(((int)temp & 7) == 0);\
366  ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
367  ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+2, halfHV, stride, SIZE, SIZE);\
368 }\
369 \
370 static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride)\
371 {\
372  DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\
373  uint8_t * const halfHV= temp;\
374  int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\
375  av_assert2(((int)temp & 7) == 0);\
376  ff_put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\
377  ff_ ## OPNAME ## pixels ## SIZE ## _l2_shift5_mmxext(dst, halfV+3, halfHV, stride, SIZE, SIZE);\
378 }\
379 
380 #define H264_MC_4816(MMX)\
381 H264_MC(put_, 4, MMX, 8)\
382 H264_MC(put_, 8, MMX, 8)\
383 H264_MC(put_, 16,MMX, 8)\
384 H264_MC(avg_, 4, MMX, 8)\
385 H264_MC(avg_, 8, MMX, 8)\
386 H264_MC(avg_, 16,MMX, 8)\
387 
388 #define H264_MC_816(QPEL, XMM)\
389 QPEL(put_, 8, XMM, 16)\
390 QPEL(put_, 16,XMM, 16)\
391 QPEL(avg_, 8, XMM, 16)\
392 QPEL(avg_, 16,XMM, 16)\
393 
394 QPEL_H264(put_, PUT_OP, mmxext)
395 QPEL_H264(avg_, AVG_MMXEXT_OP, mmxext)
396 QPEL_H264_V_XMM(put_, PUT_OP, sse2)
397 QPEL_H264_V_XMM(avg_,AVG_MMXEXT_OP, sse2)
398 QPEL_H264_HV_XMM(put_, PUT_OP, sse2)
399 QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, sse2)
400 QPEL_H264_H_XMM(put_, PUT_OP, ssse3)
401 QPEL_H264_H_XMM(avg_,AVG_MMXEXT_OP, ssse3)
402 QPEL_H264_HV_XMM(put_, PUT_OP, ssse3)
403 QPEL_H264_HV_XMM(avg_,AVG_MMXEXT_OP, ssse3)
404 
405 H264_MC_4816(mmxext)
406 H264_MC_816(H264_MC_V, sse2)
407 H264_MC_816(H264_MC_HV, sse2)
408 H264_MC_816(H264_MC_H, ssse3)
409 H264_MC_816(H264_MC_HV, ssse3)
410 
411 
412 //10bit
413 #define LUMA_MC_OP(OP, NUM, DEPTH, TYPE, OPT) \
414 void ff_ ## OP ## _h264_qpel ## NUM ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT \
415  (uint8_t *dst, uint8_t *src, ptrdiff_t stride);
416 
417 #define LUMA_MC_ALL(DEPTH, TYPE, OPT) \
418  LUMA_MC_OP(put, 4, DEPTH, TYPE, OPT) \
419  LUMA_MC_OP(avg, 4, DEPTH, TYPE, OPT) \
420  LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \
421  LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \
422  LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \
423  LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT)
424 
425 #define LUMA_MC_816(DEPTH, TYPE, OPT) \
426  LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \
427  LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \
428  LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \
429  LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT)
430 
431 LUMA_MC_ALL(10, mc00, mmxext)
432 LUMA_MC_ALL(10, mc10, mmxext)
433 LUMA_MC_ALL(10, mc20, mmxext)
434 LUMA_MC_ALL(10, mc30, mmxext)
435 LUMA_MC_ALL(10, mc01, mmxext)
436 LUMA_MC_ALL(10, mc11, mmxext)
437 LUMA_MC_ALL(10, mc21, mmxext)
438 LUMA_MC_ALL(10, mc31, mmxext)
439 LUMA_MC_ALL(10, mc02, mmxext)
440 LUMA_MC_ALL(10, mc12, mmxext)
441 LUMA_MC_ALL(10, mc22, mmxext)
442 LUMA_MC_ALL(10, mc32, mmxext)
443 LUMA_MC_ALL(10, mc03, mmxext)
444 LUMA_MC_ALL(10, mc13, mmxext)
445 LUMA_MC_ALL(10, mc23, mmxext)
446 LUMA_MC_ALL(10, mc33, mmxext)
447 
448 LUMA_MC_816(10, mc00, sse2)
449 LUMA_MC_816(10, mc10, sse2)
450 LUMA_MC_816(10, mc10, sse2_cache64)
451 LUMA_MC_816(10, mc10, ssse3_cache64)
452 LUMA_MC_816(10, mc20, sse2)
453 LUMA_MC_816(10, mc20, sse2_cache64)
454 LUMA_MC_816(10, mc20, ssse3_cache64)
455 LUMA_MC_816(10, mc30, sse2)
456 LUMA_MC_816(10, mc30, sse2_cache64)
457 LUMA_MC_816(10, mc30, ssse3_cache64)
458 LUMA_MC_816(10, mc01, sse2)
459 LUMA_MC_816(10, mc11, sse2)
460 LUMA_MC_816(10, mc21, sse2)
461 LUMA_MC_816(10, mc31, sse2)
462 LUMA_MC_816(10, mc02, sse2)
463 LUMA_MC_816(10, mc12, sse2)
464 LUMA_MC_816(10, mc22, sse2)
465 LUMA_MC_816(10, mc32, sse2)
466 LUMA_MC_816(10, mc03, sse2)
467 LUMA_MC_816(10, mc13, sse2)
468 LUMA_MC_816(10, mc23, sse2)
469 LUMA_MC_816(10, mc33, sse2)
470 
471 #define QPEL16_OPMC(OP, MC, MMX)\
472 void ff_ ## OP ## _h264_qpel16_ ## MC ## _10_ ## MMX(uint8_t *dst, uint8_t *src, ptrdiff_t stride){\
473  ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\
474  ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\
475  src += 8*stride;\
476  dst += 8*stride;\
477  ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\
478  ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\
479 }
480 
481 #define QPEL16_OP(MC, MMX)\
482 QPEL16_OPMC(put, MC, MMX)\
483 QPEL16_OPMC(avg, MC, MMX)
484 
485 #define QPEL16(MMX)\
486 QPEL16_OP(mc00, MMX)\
487 QPEL16_OP(mc01, MMX)\
488 QPEL16_OP(mc02, MMX)\
489 QPEL16_OP(mc03, MMX)\
490 QPEL16_OP(mc10, MMX)\
491 QPEL16_OP(mc11, MMX)\
492 QPEL16_OP(mc12, MMX)\
493 QPEL16_OP(mc13, MMX)\
494 QPEL16_OP(mc20, MMX)\
495 QPEL16_OP(mc21, MMX)\
496 QPEL16_OP(mc22, MMX)\
497 QPEL16_OP(mc23, MMX)\
498 QPEL16_OP(mc30, MMX)\
499 QPEL16_OP(mc31, MMX)\
500 QPEL16_OP(mc32, MMX)\
501 QPEL16_OP(mc33, MMX)
502 
503 #if ARCH_X86_32 && HAVE_YASM && CONFIG_H264QPEL // ARCH_X86_64 implies SSE2+
504 QPEL16(mmxext)
505 #endif
506 
507 #endif /* HAVE_YASM */
508 
509 #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \
510  do { \
511  c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \
512  c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \
513  c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \
514  c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \
515  c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \
516  c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \
517  c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \
518  c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \
519  c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \
520  c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \
521  c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \
522  c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \
523  c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \
524  c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \
525  c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \
526  c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU; \
527  } while (0)
528 
529 #define H264_QPEL_FUNCS(x, y, CPU) \
530  do { \
531  c->put_h264_qpel_pixels_tab[0][x + y * 4] = put_h264_qpel16_mc ## x ## y ## _ ## CPU; \
532  c->put_h264_qpel_pixels_tab[1][x + y * 4] = put_h264_qpel8_mc ## x ## y ## _ ## CPU; \
533  c->avg_h264_qpel_pixels_tab[0][x + y * 4] = avg_h264_qpel16_mc ## x ## y ## _ ## CPU; \
534  c->avg_h264_qpel_pixels_tab[1][x + y * 4] = avg_h264_qpel8_mc ## x ## y ## _ ## CPU; \
535  } while (0)
536 
537 #define H264_QPEL_FUNCS_10(x, y, CPU) \
538  do { \
539  c->put_h264_qpel_pixels_tab[0][x + y * 4] = ff_put_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
540  c->put_h264_qpel_pixels_tab[1][x + y * 4] = ff_put_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
541  c->avg_h264_qpel_pixels_tab[0][x + y * 4] = ff_avg_h264_qpel16_mc ## x ## y ## _10_ ## CPU; \
542  c->avg_h264_qpel_pixels_tab[1][x + y * 4] = ff_avg_h264_qpel8_mc ## x ## y ## _10_ ## CPU; \
543  } while (0)
544 
546 {
547 #if HAVE_YASM
548  int high_bit_depth = bit_depth > 8;
549  int mm_flags = av_get_cpu_flags();
550 
551  if (EXTERNAL_MMXEXT(mm_flags)) {
552  if (!high_bit_depth) {
553  SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmxext, );
554  SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmxext, );
555  SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmxext, );
556  SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmxext, );
557  SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmxext, );
558  SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmxext, );
559  } else if (bit_depth == 10) {
560 #if ARCH_X86_32
561  SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_);
562  SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_);
563  SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_);
564  SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_);
565 #endif
566  SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_);
567  SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_);
568  }
569  }
570 
571  if (EXTERNAL_SSE2(mm_flags)) {
572  if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW) && !high_bit_depth) {
573  // these functions are slower than mmx on AMD, but faster on Intel
574  H264_QPEL_FUNCS(0, 0, sse2);
575  }
576 
577  if (!high_bit_depth) {
578  H264_QPEL_FUNCS(0, 1, sse2);
579  H264_QPEL_FUNCS(0, 2, sse2);
580  H264_QPEL_FUNCS(0, 3, sse2);
581  H264_QPEL_FUNCS(1, 1, sse2);
582  H264_QPEL_FUNCS(1, 2, sse2);
583  H264_QPEL_FUNCS(1, 3, sse2);
584  H264_QPEL_FUNCS(2, 1, sse2);
585  H264_QPEL_FUNCS(2, 2, sse2);
586  H264_QPEL_FUNCS(2, 3, sse2);
587  H264_QPEL_FUNCS(3, 1, sse2);
588  H264_QPEL_FUNCS(3, 2, sse2);
589  H264_QPEL_FUNCS(3, 3, sse2);
590  }
591 
592  if (bit_depth == 10) {
593  SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_);
594  SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_);
595  SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_);
596  SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_);
597  H264_QPEL_FUNCS_10(1, 0, sse2_cache64);
598  H264_QPEL_FUNCS_10(2, 0, sse2_cache64);
599  H264_QPEL_FUNCS_10(3, 0, sse2_cache64);
600  }
601  }
602 
603  if (EXTERNAL_SSSE3(mm_flags)) {
604  if (!high_bit_depth) {
605  H264_QPEL_FUNCS(1, 0, ssse3);
606  H264_QPEL_FUNCS(1, 1, ssse3);
607  H264_QPEL_FUNCS(1, 2, ssse3);
608  H264_QPEL_FUNCS(1, 3, ssse3);
609  H264_QPEL_FUNCS(2, 0, ssse3);
610  H264_QPEL_FUNCS(2, 1, ssse3);
611  H264_QPEL_FUNCS(2, 2, ssse3);
612  H264_QPEL_FUNCS(2, 3, ssse3);
613  H264_QPEL_FUNCS(3, 0, ssse3);
614  H264_QPEL_FUNCS(3, 1, ssse3);
615  H264_QPEL_FUNCS(3, 2, ssse3);
616  H264_QPEL_FUNCS(3, 3, ssse3);
617  }
618 
619  if (bit_depth == 10) {
620  H264_QPEL_FUNCS_10(1, 0, ssse3_cache64);
621  H264_QPEL_FUNCS_10(2, 0, ssse3_cache64);
622  H264_QPEL_FUNCS_10(3, 0, ssse3_cache64);
623  }
624  }
625 
626  if (EXTERNAL_AVX(mm_flags)) {
627  /* AVX implies 64 byte cache lines without the need to avoid unaligned
628  * memory accesses that cross the boundary between two cache lines.
629  * TODO: Port X264_CPU_CACHELINE_32/64 detection from x264 to avoid
630  * having to treat SSE2 functions with such properties as AVX. */
631  if (bit_depth == 10) {
632  H264_QPEL_FUNCS_10(1, 0, sse2);
633  H264_QPEL_FUNCS_10(2, 0, sse2);
634  H264_QPEL_FUNCS_10(3, 0, sse2);
635  }
636  }
637 #endif
638 }
void ff_put_pixels8_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)
mpegvideo header.
int stride
Definition: mace.c:144
output residual component w
Macro definitions for various function/variable attributes.
uint8_t
#define av_cold
Definition: attributes.h:78
av_cold void ff_h264qpel_init_x86(H264QpelContext *c, int bit_depth)
#define put(d, s)
Definition: dsputil_align.c:51
#define AV_CPU_FLAG_SSE2SLOW
SSE2 supported, but usually not faster.
Definition: cpu.h:35
#define EXTERNAL_SSE2(flags)
Definition: x86/cpu.h:36
void ff_avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
int size
#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX)
AVS_Value src
Definition: avisynth_c.h:523
#define H264_QPEL_FUNCS(x, y, CPU)
#define EXTERNAL_SSSE3(flags)
Definition: x86/cpu.h:38
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:30
#define EXTERNAL_MMXEXT(flags)
Definition: x86/cpu.h:34
#define H264_QPEL_FUNCS_10(x, y, CPU)
static double c[64]
#define avg(d, s)
Definition: dsputil_align.c:52
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
#define av_always_inline
Definition: attributes.h:41
#define EXTERNAL_AVX(flags)
Definition: x86/cpu.h:41
void ff_avg_pixels8_mmxext(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)