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