Template dsputil_template.c with respect to pixel size, etc.
[libav.git] / libavcodec / dsputil_template.c
1 /*
2 * DSP utils
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of Libav.
9 *
10 * Libav is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * Libav is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with Libav; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * DSP utils
28 */
29
30 #include "dsputil.h"
31
32 #define BIT_DEPTH 8
33
34 #define pixel uint8_t
35 #define pixel2 uint16_t
36 #define pixel4 uint32_t
37 #define dctcoef int16_t
38
39 #define FUNC(a) a
40 #define FUNCC(a) a ## _c
41 #define INIT_CLIP uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
42 #define CLIP(a) cm[a]
43 #define AV_RN2P AV_RN16
44 #define AV_RN4P AV_RN32
45 #define PIXEL_MAX ((1<<BIT_DEPTH)-1)
46
47 #define no_rnd_avg_pixel4 no_rnd_avg32
48 #define rnd_avg_pixel4 rnd_avg32
49
50 /* draw the edges of width 'w' of an image of size width, height */
51 //FIXME check that this is ok for mpeg4 interlaced
52 static void FUNCC(draw_edges)(uint8_t *_buf, int _wrap, int width, int height, int w, int sides)
53 {
54 pixel *buf = (pixel*)_buf;
55 int wrap = _wrap / sizeof(pixel);
56 pixel *ptr, *last_line;
57 int i;
58
59 /* left and right */
60 ptr = buf;
61 for(i=0;i<height;i++) {
62 #if BIT_DEPTH > 8
63 int j;
64 for (j = 0; j < w; j++) {
65 ptr[j-w] = ptr[0];
66 ptr[j+width] = ptr[width-1];
67 }
68 #else
69 memset(ptr - w, ptr[0], w);
70 memset(ptr + width, ptr[width-1], w);
71 #endif
72 ptr += wrap;
73 }
74
75 /* top and bottom + corners */
76 buf -= w;
77 last_line = buf + (height - 1) * wrap;
78 if (sides & EDGE_TOP)
79 for(i = 0; i < w; i++)
80 memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top
81 if (sides & EDGE_BOTTOM)
82 for (i = 0; i < w; i++)
83 memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom
84 }
85
86 /**
87 * Copy a rectangular area of samples to a temporary buffer and replicate the border samples.
88 * @param buf destination buffer
89 * @param src source buffer
90 * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
91 * @param block_w width of block
92 * @param block_h height of block
93 * @param src_x x coordinate of the top left sample of the block in the source buffer
94 * @param src_y y coordinate of the top left sample of the block in the source buffer
95 * @param w width of the source buffer
96 * @param h height of the source buffer
97 */
98 void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h,
99 int src_x, int src_y, int w, int h){
100 int x, y;
101 int start_y, start_x, end_y, end_x;
102
103 if(src_y>= h){
104 src+= (h-1-src_y)*linesize;
105 src_y=h-1;
106 }else if(src_y<=-block_h){
107 src+= (1-block_h-src_y)*linesize;
108 src_y=1-block_h;
109 }
110 if(src_x>= w){
111 src+= (w-1-src_x)*sizeof(pixel);
112 src_x=w-1;
113 }else if(src_x<=-block_w){
114 src+= (1-block_w-src_x)*sizeof(pixel);
115 src_x=1-block_w;
116 }
117
118 start_y= FFMAX(0, -src_y);
119 start_x= FFMAX(0, -src_x);
120 end_y= FFMIN(block_h, h-src_y);
121 end_x= FFMIN(block_w, w-src_x);
122 assert(start_y < end_y && block_h);
123 assert(start_x < end_x && block_w);
124
125 w = end_x - start_x;
126 src += start_y*linesize + start_x*sizeof(pixel);
127 buf += start_x*sizeof(pixel);
128
129 //top
130 for(y=0; y<start_y; y++){
131 memcpy(buf, src, w*sizeof(pixel));
132 buf += linesize;
133 }
134
135 // copy existing part
136 for(; y<end_y; y++){
137 memcpy(buf, src, w*sizeof(pixel));
138 src += linesize;
139 buf += linesize;
140 }
141
142 //bottom
143 src -= linesize;
144 for(; y<block_h; y++){
145 memcpy(buf, src, w*sizeof(pixel));
146 buf += linesize;
147 }
148
149 buf -= block_h * linesize + start_x*sizeof(pixel);
150 while (block_h--){
151 pixel *bufp = (pixel*)buf;
152 //left
153 for(x=0; x<start_x; x++){
154 bufp[x] = bufp[start_x];
155 }
156
157 //right
158 for(x=end_x; x<block_w; x++){
159 bufp[x] = bufp[end_x - 1];
160 }
161 buf += linesize;
162 }
163 }
164
165 static void FUNCC(add_pixels8)(uint8_t *restrict _pixels, DCTELEM *_block, int line_size)
166 {
167 int i;
168 pixel *restrict pixels = (pixel *restrict)_pixels;
169 dctcoef *block = (dctcoef*)_block;
170 line_size /= sizeof(pixel);
171
172 for(i=0;i<8;i++) {
173 pixels[0] += block[0];
174 pixels[1] += block[1];
175 pixels[2] += block[2];
176 pixels[3] += block[3];
177 pixels[4] += block[4];
178 pixels[5] += block[5];
179 pixels[6] += block[6];
180 pixels[7] += block[7];
181 pixels += line_size;
182 block += 8;
183 }
184 }
185
186 static void FUNCC(add_pixels4)(uint8_t *restrict _pixels, DCTELEM *_block, int line_size)
187 {
188 int i;
189 pixel *restrict pixels = (pixel *restrict)_pixels;
190 dctcoef *block = (dctcoef*)_block;
191 line_size /= sizeof(pixel);
192
193 for(i=0;i<4;i++) {
194 pixels[0] += block[0];
195 pixels[1] += block[1];
196 pixels[2] += block[2];
197 pixels[3] += block[3];
198 pixels += line_size;
199 block += 4;
200 }
201 }
202
203 #if 0
204
205 #define PIXOP2(OPNAME, OP) \
206 static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
207 {\
208 int i;\
209 for(i=0; i<h; i++){\
210 OP(*((uint64_t*)block), AV_RN64(pixels));\
211 pixels+=line_size;\
212 block +=line_size;\
213 }\
214 }\
215 \
216 static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
217 {\
218 int i;\
219 for(i=0; i<h; i++){\
220 const uint64_t a= AV_RN64(pixels );\
221 const uint64_t b= AV_RN64(pixels+1);\
222 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
223 pixels+=line_size;\
224 block +=line_size;\
225 }\
226 }\
227 \
228 static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
229 {\
230 int i;\
231 for(i=0; i<h; i++){\
232 const uint64_t a= AV_RN64(pixels );\
233 const uint64_t b= AV_RN64(pixels+1);\
234 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
235 pixels+=line_size;\
236 block +=line_size;\
237 }\
238 }\
239 \
240 static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
241 {\
242 int i;\
243 for(i=0; i<h; i++){\
244 const uint64_t a= AV_RN64(pixels );\
245 const uint64_t b= AV_RN64(pixels+line_size);\
246 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
247 pixels+=line_size;\
248 block +=line_size;\
249 }\
250 }\
251 \
252 static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
253 {\
254 int i;\
255 for(i=0; i<h; i++){\
256 const uint64_t a= AV_RN64(pixels );\
257 const uint64_t b= AV_RN64(pixels+line_size);\
258 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
259 pixels+=line_size;\
260 block +=line_size;\
261 }\
262 }\
263 \
264 static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
265 {\
266 int i;\
267 const uint64_t a= AV_RN64(pixels );\
268 const uint64_t b= AV_RN64(pixels+1);\
269 uint64_t l0= (a&0x0303030303030303ULL)\
270 + (b&0x0303030303030303ULL)\
271 + 0x0202020202020202ULL;\
272 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
273 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
274 uint64_t l1,h1;\
275 \
276 pixels+=line_size;\
277 for(i=0; i<h; i+=2){\
278 uint64_t a= AV_RN64(pixels );\
279 uint64_t b= AV_RN64(pixels+1);\
280 l1= (a&0x0303030303030303ULL)\
281 + (b&0x0303030303030303ULL);\
282 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
283 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
284 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
285 pixels+=line_size;\
286 block +=line_size;\
287 a= AV_RN64(pixels );\
288 b= AV_RN64(pixels+1);\
289 l0= (a&0x0303030303030303ULL)\
290 + (b&0x0303030303030303ULL)\
291 + 0x0202020202020202ULL;\
292 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
293 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
294 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
295 pixels+=line_size;\
296 block +=line_size;\
297 }\
298 }\
299 \
300 static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
301 {\
302 int i;\
303 const uint64_t a= AV_RN64(pixels );\
304 const uint64_t b= AV_RN64(pixels+1);\
305 uint64_t l0= (a&0x0303030303030303ULL)\
306 + (b&0x0303030303030303ULL)\
307 + 0x0101010101010101ULL;\
308 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
309 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
310 uint64_t l1,h1;\
311 \
312 pixels+=line_size;\
313 for(i=0; i<h; i+=2){\
314 uint64_t a= AV_RN64(pixels );\
315 uint64_t b= AV_RN64(pixels+1);\
316 l1= (a&0x0303030303030303ULL)\
317 + (b&0x0303030303030303ULL);\
318 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
319 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
320 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
321 pixels+=line_size;\
322 block +=line_size;\
323 a= AV_RN64(pixels );\
324 b= AV_RN64(pixels+1);\
325 l0= (a&0x0303030303030303ULL)\
326 + (b&0x0303030303030303ULL)\
327 + 0x0101010101010101ULL;\
328 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
329 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
330 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
331 pixels+=line_size;\
332 block +=line_size;\
333 }\
334 }\
335 \
336 CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8*sizeof(pixel))\
337 CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8*sizeof(pixel))\
338 CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8*sizeof(pixel))\
339 CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8*sizeof(pixel))\
340 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8*sizeof(pixel))\
341 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8*sizeof(pixel))\
342 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8*sizeof(pixel))
343
344 #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
345 #else // 64 bit variant
346
347 #define PIXOP2(OPNAME, OP) \
348 static void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
349 int i;\
350 for(i=0; i<h; i++){\
351 OP(*((pixel2*)(block )), AV_RN2P(pixels ));\
352 pixels+=line_size;\
353 block +=line_size;\
354 }\
355 }\
356 static void FUNCC(OPNAME ## _pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
357 int i;\
358 for(i=0; i<h; i++){\
359 OP(*((pixel4*)(block )), AV_RN4P(pixels ));\
360 pixels+=line_size;\
361 block +=line_size;\
362 }\
363 }\
364 static void FUNCC(OPNAME ## _pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
365 int i;\
366 for(i=0; i<h; i++){\
367 OP(*((pixel4*)(block )), AV_RN4P(pixels ));\
368 OP(*((pixel4*)(block+4*sizeof(pixel))), AV_RN4P(pixels+4*sizeof(pixel)));\
369 pixels+=line_size;\
370 block +=line_size;\
371 }\
372 }\
373 static inline void FUNCC(OPNAME ## _no_rnd_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
374 FUNCC(OPNAME ## _pixels8)(block, pixels, line_size, h);\
375 }\
376 \
377 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
378 int src_stride1, int src_stride2, int h){\
379 int i;\
380 for(i=0; i<h; i++){\
381 pixel4 a,b;\
382 a= AV_RN4P(&src1[i*src_stride1 ]);\
383 b= AV_RN4P(&src2[i*src_stride2 ]);\
384 OP(*((pixel4*)&dst[i*dst_stride ]), no_rnd_avg_pixel4(a, b));\
385 a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
386 b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
387 OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), no_rnd_avg_pixel4(a, b));\
388 }\
389 }\
390 \
391 static inline void FUNC(OPNAME ## _pixels8_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
392 int src_stride1, int src_stride2, int h){\
393 int i;\
394 for(i=0; i<h; i++){\
395 pixel4 a,b;\
396 a= AV_RN4P(&src1[i*src_stride1 ]);\
397 b= AV_RN4P(&src2[i*src_stride2 ]);\
398 OP(*((pixel4*)&dst[i*dst_stride ]), rnd_avg_pixel4(a, b));\
399 a= AV_RN4P(&src1[i*src_stride1+4*sizeof(pixel)]);\
400 b= AV_RN4P(&src2[i*src_stride2+4*sizeof(pixel)]);\
401 OP(*((pixel4*)&dst[i*dst_stride+4*sizeof(pixel)]), rnd_avg_pixel4(a, b));\
402 }\
403 }\
404 \
405 static inline void FUNC(OPNAME ## _pixels4_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
406 int src_stride1, int src_stride2, int h){\
407 int i;\
408 for(i=0; i<h; i++){\
409 pixel4 a,b;\
410 a= AV_RN4P(&src1[i*src_stride1 ]);\
411 b= AV_RN4P(&src2[i*src_stride2 ]);\
412 OP(*((pixel4*)&dst[i*dst_stride ]), rnd_avg_pixel4(a, b));\
413 }\
414 }\
415 \
416 static inline void FUNC(OPNAME ## _pixels2_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
417 int src_stride1, int src_stride2, int h){\
418 int i;\
419 for(i=0; i<h; i++){\
420 pixel4 a,b;\
421 a= AV_RN2P(&src1[i*src_stride1 ]);\
422 b= AV_RN2P(&src2[i*src_stride2 ]);\
423 OP(*((pixel2*)&dst[i*dst_stride ]), rnd_avg_pixel4(a, b));\
424 }\
425 }\
426 \
427 static inline void FUNC(OPNAME ## _pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
428 int src_stride1, int src_stride2, int h){\
429 FUNC(OPNAME ## _pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
430 FUNC(OPNAME ## _pixels8_l2)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, h);\
431 }\
432 \
433 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
434 int src_stride1, int src_stride2, int h){\
435 FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
436 FUNC(OPNAME ## _no_rnd_pixels8_l2)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, h);\
437 }\
438 \
439 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
440 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
441 }\
442 \
443 static inline void FUNCC(OPNAME ## _pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
444 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
445 }\
446 \
447 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
448 FUNC(OPNAME ## _no_rnd_pixels8_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
449 }\
450 \
451 static inline void FUNCC(OPNAME ## _pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
452 FUNC(OPNAME ## _pixels8_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
453 }\
454 \
455 static inline void FUNC(OPNAME ## _pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
456 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
457 /* FIXME HIGH BIT DEPTH */\
458 int i;\
459 for(i=0; i<h; i++){\
460 uint32_t a, b, c, d, l0, l1, h0, h1;\
461 a= AV_RN32(&src1[i*src_stride1]);\
462 b= AV_RN32(&src2[i*src_stride2]);\
463 c= AV_RN32(&src3[i*src_stride3]);\
464 d= AV_RN32(&src4[i*src_stride4]);\
465 l0= (a&0x03030303UL)\
466 + (b&0x03030303UL)\
467 + 0x02020202UL;\
468 h0= ((a&0xFCFCFCFCUL)>>2)\
469 + ((b&0xFCFCFCFCUL)>>2);\
470 l1= (c&0x03030303UL)\
471 + (d&0x03030303UL);\
472 h1= ((c&0xFCFCFCFCUL)>>2)\
473 + ((d&0xFCFCFCFCUL)>>2);\
474 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
475 a= AV_RN32(&src1[i*src_stride1+4]);\
476 b= AV_RN32(&src2[i*src_stride2+4]);\
477 c= AV_RN32(&src3[i*src_stride3+4]);\
478 d= AV_RN32(&src4[i*src_stride4+4]);\
479 l0= (a&0x03030303UL)\
480 + (b&0x03030303UL)\
481 + 0x02020202UL;\
482 h0= ((a&0xFCFCFCFCUL)>>2)\
483 + ((b&0xFCFCFCFCUL)>>2);\
484 l1= (c&0x03030303UL)\
485 + (d&0x03030303UL);\
486 h1= ((c&0xFCFCFCFCUL)>>2)\
487 + ((d&0xFCFCFCFCUL)>>2);\
488 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
489 }\
490 }\
491 \
492 static inline void FUNCC(OPNAME ## _pixels4_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
493 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
494 }\
495 \
496 static inline void FUNCC(OPNAME ## _pixels4_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
497 FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
498 }\
499 \
500 static inline void FUNCC(OPNAME ## _pixels2_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
501 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\
502 }\
503 \
504 static inline void FUNCC(OPNAME ## _pixels2_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
505 FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
506 }\
507 \
508 static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
509 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
510 /* FIXME HIGH BIT DEPTH*/\
511 int i;\
512 for(i=0; i<h; i++){\
513 uint32_t a, b, c, d, l0, l1, h0, h1;\
514 a= AV_RN32(&src1[i*src_stride1]);\
515 b= AV_RN32(&src2[i*src_stride2]);\
516 c= AV_RN32(&src3[i*src_stride3]);\
517 d= AV_RN32(&src4[i*src_stride4]);\
518 l0= (a&0x03030303UL)\
519 + (b&0x03030303UL)\
520 + 0x01010101UL;\
521 h0= ((a&0xFCFCFCFCUL)>>2)\
522 + ((b&0xFCFCFCFCUL)>>2);\
523 l1= (c&0x03030303UL)\
524 + (d&0x03030303UL);\
525 h1= ((c&0xFCFCFCFCUL)>>2)\
526 + ((d&0xFCFCFCFCUL)>>2);\
527 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
528 a= AV_RN32(&src1[i*src_stride1+4]);\
529 b= AV_RN32(&src2[i*src_stride2+4]);\
530 c= AV_RN32(&src3[i*src_stride3+4]);\
531 d= AV_RN32(&src4[i*src_stride4+4]);\
532 l0= (a&0x03030303UL)\
533 + (b&0x03030303UL)\
534 + 0x01010101UL;\
535 h0= ((a&0xFCFCFCFCUL)>>2)\
536 + ((b&0xFCFCFCFCUL)>>2);\
537 l1= (c&0x03030303UL)\
538 + (d&0x03030303UL);\
539 h1= ((c&0xFCFCFCFCUL)>>2)\
540 + ((d&0xFCFCFCFCUL)>>2);\
541 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
542 }\
543 }\
544 static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
545 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
546 FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
547 FUNC(OPNAME ## _pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
548 }\
549 static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\
550 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
551 FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
552 FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
553 }\
554 \
555 static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *_block, const uint8_t *_pixels, int line_size, int h)\
556 {\
557 int i, a0, b0, a1, b1;\
558 pixel *block = (pixel*)_block;\
559 const pixel *pixels = (const pixel*)_pixels;\
560 line_size /= sizeof(pixel);\
561 a0= pixels[0];\
562 b0= pixels[1] + 2;\
563 a0 += b0;\
564 b0 += pixels[2];\
565 \
566 pixels+=line_size;\
567 for(i=0; i<h; i+=2){\
568 a1= pixels[0];\
569 b1= pixels[1];\
570 a1 += b1;\
571 b1 += pixels[2];\
572 \
573 block[0]= (a1+a0)>>2; /* FIXME non put */\
574 block[1]= (b1+b0)>>2;\
575 \
576 pixels+=line_size;\
577 block +=line_size;\
578 \
579 a0= pixels[0];\
580 b0= pixels[1] + 2;\
581 a0 += b0;\
582 b0 += pixels[2];\
583 \
584 block[0]= (a1+a0)>>2;\
585 block[1]= (b1+b0)>>2;\
586 pixels+=line_size;\
587 block +=line_size;\
588 }\
589 }\
590 \
591 static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
592 {\
593 /* FIXME HIGH BIT DEPTH */\
594 int i;\
595 const uint32_t a= AV_RN32(pixels );\
596 const uint32_t b= AV_RN32(pixels+1);\
597 uint32_t l0= (a&0x03030303UL)\
598 + (b&0x03030303UL)\
599 + 0x02020202UL;\
600 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
601 + ((b&0xFCFCFCFCUL)>>2);\
602 uint32_t l1,h1;\
603 \
604 pixels+=line_size;\
605 for(i=0; i<h; i+=2){\
606 uint32_t a= AV_RN32(pixels );\
607 uint32_t b= AV_RN32(pixels+1);\
608 l1= (a&0x03030303UL)\
609 + (b&0x03030303UL);\
610 h1= ((a&0xFCFCFCFCUL)>>2)\
611 + ((b&0xFCFCFCFCUL)>>2);\
612 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
613 pixels+=line_size;\
614 block +=line_size;\
615 a= AV_RN32(pixels );\
616 b= AV_RN32(pixels+1);\
617 l0= (a&0x03030303UL)\
618 + (b&0x03030303UL)\
619 + 0x02020202UL;\
620 h0= ((a&0xFCFCFCFCUL)>>2)\
621 + ((b&0xFCFCFCFCUL)>>2);\
622 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
623 pixels+=line_size;\
624 block +=line_size;\
625 }\
626 }\
627 \
628 static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
629 {\
630 /* FIXME HIGH BIT DEPTH */\
631 int j;\
632 for(j=0; j<2; j++){\
633 int i;\
634 const uint32_t a= AV_RN32(pixels );\
635 const uint32_t b= AV_RN32(pixels+1);\
636 uint32_t l0= (a&0x03030303UL)\
637 + (b&0x03030303UL)\
638 + 0x02020202UL;\
639 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
640 + ((b&0xFCFCFCFCUL)>>2);\
641 uint32_t l1,h1;\
642 \
643 pixels+=line_size;\
644 for(i=0; i<h; i+=2){\
645 uint32_t a= AV_RN32(pixels );\
646 uint32_t b= AV_RN32(pixels+1);\
647 l1= (a&0x03030303UL)\
648 + (b&0x03030303UL);\
649 h1= ((a&0xFCFCFCFCUL)>>2)\
650 + ((b&0xFCFCFCFCUL)>>2);\
651 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
652 pixels+=line_size;\
653 block +=line_size;\
654 a= AV_RN32(pixels );\
655 b= AV_RN32(pixels+1);\
656 l0= (a&0x03030303UL)\
657 + (b&0x03030303UL)\
658 + 0x02020202UL;\
659 h0= ((a&0xFCFCFCFCUL)>>2)\
660 + ((b&0xFCFCFCFCUL)>>2);\
661 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
662 pixels+=line_size;\
663 block +=line_size;\
664 }\
665 pixels+=4-line_size*(h+1);\
666 block +=4-line_size*h;\
667 }\
668 }\
669 \
670 static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
671 {\
672 /* FIXME HIGH BIT DEPTH */\
673 int j;\
674 for(j=0; j<2; j++){\
675 int i;\
676 const uint32_t a= AV_RN32(pixels );\
677 const uint32_t b= AV_RN32(pixels+1);\
678 uint32_t l0= (a&0x03030303UL)\
679 + (b&0x03030303UL)\
680 + 0x01010101UL;\
681 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
682 + ((b&0xFCFCFCFCUL)>>2);\
683 uint32_t l1,h1;\
684 \
685 pixels+=line_size;\
686 for(i=0; i<h; i+=2){\
687 uint32_t a= AV_RN32(pixels );\
688 uint32_t b= AV_RN32(pixels+1);\
689 l1= (a&0x03030303UL)\
690 + (b&0x03030303UL);\
691 h1= ((a&0xFCFCFCFCUL)>>2)\
692 + ((b&0xFCFCFCFCUL)>>2);\
693 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
694 pixels+=line_size;\
695 block +=line_size;\
696 a= AV_RN32(pixels );\
697 b= AV_RN32(pixels+1);\
698 l0= (a&0x03030303UL)\
699 + (b&0x03030303UL)\
700 + 0x01010101UL;\
701 h0= ((a&0xFCFCFCFCUL)>>2)\
702 + ((b&0xFCFCFCFCUL)>>2);\
703 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
704 pixels+=line_size;\
705 block +=line_size;\
706 }\
707 pixels+=4-line_size*(h+1);\
708 block +=4-line_size*h;\
709 }\
710 }\
711 \
712 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\
713 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2) , FUNCC(OPNAME ## _pixels8_x2) , 8*sizeof(pixel))\
714 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2) , FUNCC(OPNAME ## _pixels8_y2) , 8*sizeof(pixel))\
715 CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\
716 av_unused CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\
717 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_x2) , FUNCC(OPNAME ## _no_rnd_pixels8_x2) , 8*sizeof(pixel))\
718 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2) , FUNCC(OPNAME ## _no_rnd_pixels8_y2) , 8*sizeof(pixel))\
719 CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pixels8_xy2), 8*sizeof(pixel))\
720
721 #define op_avg(a, b) a = rnd_avg_pixel4(a, b)
722 #endif
723 #define op_put(a, b) a = b
724
725 PIXOP2(avg, op_avg)
726 PIXOP2(put, op_put)
727 #undef op_avg
728 #undef op_put
729
730 #define put_no_rnd_pixels8_c put_pixels8_c
731 #define put_no_rnd_pixels16_c put_pixels16_c
732
733 static void FUNCC(put_no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
734 FUNC(put_no_rnd_pixels16_l2)(dst, a, b, stride, stride, stride, h);
735 }
736
737 static void FUNCC(put_no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
738 FUNC(put_no_rnd_pixels8_l2)(dst, a, b, stride, stride, stride, h);
739 }
740
741 #define H264_CHROMA_MC(OPNAME, OP)\
742 static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
743 pixel *dst = (pixel*)_dst;\
744 pixel *src = (pixel*)_src;\
745 const int A=(8-x)*(8-y);\
746 const int B=( x)*(8-y);\
747 const int C=(8-x)*( y);\
748 const int D=( x)*( y);\
749 int i;\
750 stride /= sizeof(pixel);\
751 \
752 assert(x<8 && y<8 && x>=0 && y>=0);\
753 \
754 if(D){\
755 for(i=0; i<h; i++){\
756 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
757 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
758 dst+= stride;\
759 src+= stride;\
760 }\
761 }else{\
762 const int E= B+C;\
763 const int step= C ? stride : 1;\
764 for(i=0; i<h; i++){\
765 OP(dst[0], (A*src[0] + E*src[step+0]));\
766 OP(dst[1], (A*src[1] + E*src[step+1]));\
767 dst+= stride;\
768 src+= stride;\
769 }\
770 }\
771 }\
772 \
773 static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
774 pixel *dst = (pixel*)_dst;\
775 pixel *src = (pixel*)_src;\
776 const int A=(8-x)*(8-y);\
777 const int B=( x)*(8-y);\
778 const int C=(8-x)*( y);\
779 const int D=( x)*( y);\
780 int i;\
781 stride /= sizeof(pixel);\
782 \
783 assert(x<8 && y<8 && x>=0 && y>=0);\
784 \
785 if(D){\
786 for(i=0; i<h; i++){\
787 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
788 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
789 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
790 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
791 dst+= stride;\
792 src+= stride;\
793 }\
794 }else{\
795 const int E= B+C;\
796 const int step= C ? stride : 1;\
797 for(i=0; i<h; i++){\
798 OP(dst[0], (A*src[0] + E*src[step+0]));\
799 OP(dst[1], (A*src[1] + E*src[step+1]));\
800 OP(dst[2], (A*src[2] + E*src[step+2]));\
801 OP(dst[3], (A*src[3] + E*src[step+3]));\
802 dst+= stride;\
803 src+= stride;\
804 }\
805 }\
806 }\
807 \
808 static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *_src/*align 1*/, int stride, int h, int x, int y){\
809 pixel *dst = (pixel*)_dst;\
810 pixel *src = (pixel*)_src;\
811 const int A=(8-x)*(8-y);\
812 const int B=( x)*(8-y);\
813 const int C=(8-x)*( y);\
814 const int D=( x)*( y);\
815 int i;\
816 stride /= sizeof(pixel);\
817 \
818 assert(x<8 && y<8 && x>=0 && y>=0);\
819 \
820 if(D){\
821 for(i=0; i<h; i++){\
822 OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
823 OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
824 OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
825 OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
826 OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
827 OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
828 OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
829 OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
830 dst+= stride;\
831 src+= stride;\
832 }\
833 }else{\
834 const int E= B+C;\
835 const int step= C ? stride : 1;\
836 for(i=0; i<h; i++){\
837 OP(dst[0], (A*src[0] + E*src[step+0]));\
838 OP(dst[1], (A*src[1] + E*src[step+1]));\
839 OP(dst[2], (A*src[2] + E*src[step+2]));\
840 OP(dst[3], (A*src[3] + E*src[step+3]));\
841 OP(dst[4], (A*src[4] + E*src[step+4]));\
842 OP(dst[5], (A*src[5] + E*src[step+5]));\
843 OP(dst[6], (A*src[6] + E*src[step+6]));\
844 OP(dst[7], (A*src[7] + E*src[step+7]));\
845 dst+= stride;\
846 src+= stride;\
847 }\
848 }\
849 }
850
851 #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
852 #define op_put(a, b) a = (((b) + 32)>>6)
853
854 H264_CHROMA_MC(put_ , op_put)
855 H264_CHROMA_MC(avg_ , op_avg)
856 #undef op_avg
857 #undef op_put
858
859 #define H264_LOWPASS(OPNAME, OP, OP2) \
860 static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
861 const int h=2;\
862 INIT_CLIP\
863 int i;\
864 pixel *dst = (pixel*)_dst;\
865 pixel *src = (pixel*)_src;\
866 dstStride /= sizeof(pixel);\
867 srcStride /= sizeof(pixel);\
868 for(i=0; i<h; i++)\
869 {\
870 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
871 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
872 dst+=dstStride;\
873 src+=srcStride;\
874 }\
875 }\
876 \
877 static av_unused void FUNC(OPNAME ## h264_qpel2_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
878 const int w=2;\
879 INIT_CLIP\
880 int i;\
881 pixel *dst = (pixel*)_dst;\
882 pixel *src = (pixel*)_src;\
883 dstStride /= sizeof(pixel);\
884 srcStride /= sizeof(pixel);\
885 for(i=0; i<w; i++)\
886 {\
887 const int srcB= src[-2*srcStride];\
888 const int srcA= src[-1*srcStride];\
889 const int src0= src[0 *srcStride];\
890 const int src1= src[1 *srcStride];\
891 const int src2= src[2 *srcStride];\
892 const int src3= src[3 *srcStride];\
893 const int src4= src[4 *srcStride];\
894 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
895 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
896 dst++;\
897 src++;\
898 }\
899 }\
900 \
901 static av_unused void FUNC(OPNAME ## h264_qpel2_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
902 const int h=2;\
903 const int w=2;\
904 const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
905 INIT_CLIP\
906 int i;\
907 pixel *dst = (pixel*)_dst;\
908 pixel *src = (pixel*)_src;\
909 dstStride /= sizeof(pixel);\
910 srcStride /= sizeof(pixel);\
911 src -= 2*srcStride;\
912 for(i=0; i<h+5; i++)\
913 {\
914 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
915 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
916 tmp+=tmpStride;\
917 src+=srcStride;\
918 }\
919 tmp -= tmpStride*(h+5-2);\
920 for(i=0; i<w; i++)\
921 {\
922 const int tmpB= tmp[-2*tmpStride] - pad;\
923 const int tmpA= tmp[-1*tmpStride] - pad;\
924 const int tmp0= tmp[0 *tmpStride] - pad;\
925 const int tmp1= tmp[1 *tmpStride] - pad;\
926 const int tmp2= tmp[2 *tmpStride] - pad;\
927 const int tmp3= tmp[3 *tmpStride] - pad;\
928 const int tmp4= tmp[4 *tmpStride] - pad;\
929 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
930 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
931 dst++;\
932 tmp++;\
933 }\
934 }\
935 static void FUNC(OPNAME ## h264_qpel4_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
936 const int h=4;\
937 INIT_CLIP\
938 int i;\
939 pixel *dst = (pixel*)_dst;\
940 pixel *src = (pixel*)_src;\
941 dstStride /= sizeof(pixel);\
942 srcStride /= sizeof(pixel);\
943 for(i=0; i<h; i++)\
944 {\
945 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
946 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
947 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
948 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
949 dst+=dstStride;\
950 src+=srcStride;\
951 }\
952 }\
953 \
954 static void FUNC(OPNAME ## h264_qpel4_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
955 const int w=4;\
956 INIT_CLIP\
957 int i;\
958 pixel *dst = (pixel*)_dst;\
959 pixel *src = (pixel*)_src;\
960 dstStride /= sizeof(pixel);\
961 srcStride /= sizeof(pixel);\
962 for(i=0; i<w; i++)\
963 {\
964 const int srcB= src[-2*srcStride];\
965 const int srcA= src[-1*srcStride];\
966 const int src0= src[0 *srcStride];\
967 const int src1= src[1 *srcStride];\
968 const int src2= src[2 *srcStride];\
969 const int src3= src[3 *srcStride];\
970 const int src4= src[4 *srcStride];\
971 const int src5= src[5 *srcStride];\
972 const int src6= src[6 *srcStride];\
973 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
974 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
975 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
976 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
977 dst++;\
978 src++;\
979 }\
980 }\
981 \
982 static void FUNC(OPNAME ## h264_qpel4_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
983 const int h=4;\
984 const int w=4;\
985 const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
986 INIT_CLIP\
987 int i;\
988 pixel *dst = (pixel*)_dst;\
989 pixel *src = (pixel*)_src;\
990 dstStride /= sizeof(pixel);\
991 srcStride /= sizeof(pixel);\
992 src -= 2*srcStride;\
993 for(i=0; i<h+5; i++)\
994 {\
995 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]) + pad;\
996 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]) + pad;\
997 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]) + pad;\
998 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]) + pad;\
999 tmp+=tmpStride;\
1000 src+=srcStride;\
1001 }\
1002 tmp -= tmpStride*(h+5-2);\
1003 for(i=0; i<w; i++)\
1004 {\
1005 const int tmpB= tmp[-2*tmpStride] - pad;\
1006 const int tmpA= tmp[-1*tmpStride] - pad;\
1007 const int tmp0= tmp[0 *tmpStride] - pad;\
1008 const int tmp1= tmp[1 *tmpStride] - pad;\
1009 const int tmp2= tmp[2 *tmpStride] - pad;\
1010 const int tmp3= tmp[3 *tmpStride] - pad;\
1011 const int tmp4= tmp[4 *tmpStride] - pad;\
1012 const int tmp5= tmp[5 *tmpStride] - pad;\
1013 const int tmp6= tmp[6 *tmpStride] - pad;\
1014 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
1015 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
1016 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
1017 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
1018 dst++;\
1019 tmp++;\
1020 }\
1021 }\
1022 \
1023 static void FUNC(OPNAME ## h264_qpel8_h_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
1024 const int h=8;\
1025 INIT_CLIP\
1026 int i;\
1027 pixel *dst = (pixel*)_dst;\
1028 pixel *src = (pixel*)_src;\
1029 dstStride /= sizeof(pixel);\
1030 srcStride /= sizeof(pixel);\
1031 for(i=0; i<h; i++)\
1032 {\
1033 OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
1034 OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
1035 OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
1036 OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
1037 OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
1038 OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
1039 OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
1040 OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
1041 dst+=dstStride;\
1042 src+=srcStride;\
1043 }\
1044 }\
1045 \
1046 static void FUNC(OPNAME ## h264_qpel8_v_lowpass)(uint8_t *_dst, uint8_t *_src, int dstStride, int srcStride){\
1047 const int w=8;\
1048 INIT_CLIP\
1049 int i;\
1050 pixel *dst = (pixel*)_dst;\
1051 pixel *src = (pixel*)_src;\
1052 dstStride /= sizeof(pixel);\
1053 srcStride /= sizeof(pixel);\
1054 for(i=0; i<w; i++)\
1055 {\
1056 const int srcB= src[-2*srcStride];\
1057 const int srcA= src[-1*srcStride];\
1058 const int src0= src[0 *srcStride];\
1059 const int src1= src[1 *srcStride];\
1060 const int src2= src[2 *srcStride];\
1061 const int src3= src[3 *srcStride];\
1062 const int src4= src[4 *srcStride];\
1063 const int src5= src[5 *srcStride];\
1064 const int src6= src[6 *srcStride];\
1065 const int src7= src[7 *srcStride];\
1066 const int src8= src[8 *srcStride];\
1067 const int src9= src[9 *srcStride];\
1068 const int src10=src[10*srcStride];\
1069 OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
1070 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
1071 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
1072 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
1073 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
1074 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
1075 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
1076 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
1077 dst++;\
1078 src++;\
1079 }\
1080 }\
1081 \
1082 static void FUNC(OPNAME ## h264_qpel8_hv_lowpass)(uint8_t *_dst, int16_t *tmp, uint8_t *_src, int dstStride, int tmpStride, int srcStride){\
1083 const int h=8;\
1084 const int w=8;\
1085 const int pad = (BIT_DEPTH > 9) ? (-10 * ((1<<BIT_DEPTH)-1)) : 0;\
1086 INIT_CLIP\
1087 int i;\
1088 pixel *dst = (pixel*)_dst;\
1089 pixel *src = (pixel*)_src;\
1090 dstStride /= sizeof(pixel);\
1091 srcStride /= sizeof(pixel);\
1092 src -= 2*srcStride;\
1093 for(i=0; i<h+5; i++)\
1094 {\
1095 tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]) + pad;\
1096 tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]) + pad;\
1097 tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]) + pad;\
1098 tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]) + pad;\
1099 tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]) + pad;\
1100 tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]) + pad;\
1101 tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]) + pad;\
1102 tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]) + pad;\
1103 tmp+=tmpStride;\
1104 src+=srcStride;\
1105 }\
1106 tmp -= tmpStride*(h+5-2);\
1107 for(i=0; i<w; i++)\
1108 {\
1109 const int tmpB= tmp[-2*tmpStride] - pad;\
1110 const int tmpA= tmp[-1*tmpStride] - pad;\
1111 const int tmp0= tmp[0 *tmpStride] - pad;\
1112 const int tmp1= tmp[1 *tmpStride] - pad;\
1113 const int tmp2= tmp[2 *tmpStride] - pad;\
1114 const int tmp3= tmp[3 *tmpStride] - pad;\
1115 const int tmp4= tmp[4 *tmpStride] - pad;\
1116 const int tmp5= tmp[5 *tmpStride] - pad;\
1117 const int tmp6= tmp[6 *tmpStride] - pad;\
1118 const int tmp7= tmp[7 *tmpStride] - pad;\
1119 const int tmp8= tmp[8 *tmpStride] - pad;\
1120 const int tmp9= tmp[9 *tmpStride] - pad;\
1121 const int tmp10=tmp[10*tmpStride] - pad;\
1122 OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
1123 OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
1124 OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
1125 OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
1126 OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
1127 OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
1128 OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
1129 OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
1130 dst++;\
1131 tmp++;\
1132 }\
1133 }\
1134 \
1135 static void FUNC(OPNAME ## h264_qpel16_v_lowpass)(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1136 FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst , src , dstStride, srcStride);\
1137 FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
1138 src += 8*srcStride;\
1139 dst += 8*dstStride;\
1140 FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst , src , dstStride, srcStride);\
1141 FUNC(OPNAME ## h264_qpel8_v_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
1142 }\
1143 \
1144 static void FUNC(OPNAME ## h264_qpel16_h_lowpass)(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
1145 FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst , src , dstStride, srcStride);\
1146 FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
1147 src += 8*srcStride;\
1148 dst += 8*dstStride;\
1149 FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst , src , dstStride, srcStride);\
1150 FUNC(OPNAME ## h264_qpel8_h_lowpass)(dst+8*sizeof(pixel), src+8*sizeof(pixel), dstStride, srcStride);\
1151 }\
1152 \
1153 static void FUNC(OPNAME ## h264_qpel16_hv_lowpass)(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
1154 FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst , tmp , src , dstStride, tmpStride, srcStride);\
1155 FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
1156 src += 8*srcStride;\
1157 dst += 8*dstStride;\
1158 FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst , tmp , src , dstStride, tmpStride, srcStride);\
1159 FUNC(OPNAME ## h264_qpel8_hv_lowpass)(dst+8*sizeof(pixel), tmp+8, src+8*sizeof(pixel), dstStride, tmpStride, srcStride);\
1160 }\
1161
1162 #define H264_MC(OPNAME, SIZE) \
1163 static av_unused void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc00)(uint8_t *dst, uint8_t *src, int stride){\
1164 FUNCC(OPNAME ## pixels ## SIZE)(dst, src, stride, SIZE);\
1165 }\
1166 \
1167 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc10)(uint8_t *dst, uint8_t *src, int stride){\
1168 uint8_t half[SIZE*SIZE*sizeof(pixel)];\
1169 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
1170 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src, half, stride, stride, SIZE*sizeof(pixel), SIZE);\
1171 }\
1172 \
1173 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc20)(uint8_t *dst, uint8_t *src, int stride){\
1174 FUNC(OPNAME ## h264_qpel ## SIZE ## _h_lowpass)(dst, src, stride, stride);\
1175 }\
1176 \
1177 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc30)(uint8_t *dst, uint8_t *src, int stride){\
1178 uint8_t half[SIZE*SIZE*sizeof(pixel)];\
1179 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(half, src, SIZE*sizeof(pixel), stride);\
1180 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, src+sizeof(pixel), half, stride, stride, SIZE*sizeof(pixel), SIZE);\
1181 }\
1182 \
1183 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc01)(uint8_t *dst, uint8_t *src, int stride){\
1184 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1185 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1186 uint8_t half[SIZE*SIZE*sizeof(pixel)];\
1187 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1188 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1189 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid, half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1190 }\
1191 \
1192 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc02)(uint8_t *dst, uint8_t *src, int stride){\
1193 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1194 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1195 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1196 FUNC(OPNAME ## h264_qpel ## SIZE ## _v_lowpass)(dst, full_mid, stride, SIZE*sizeof(pixel));\
1197 }\
1198 \
1199 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc03)(uint8_t *dst, uint8_t *src, int stride){\
1200 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1201 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1202 uint8_t half[SIZE*SIZE*sizeof(pixel)];\
1203 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1204 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(half, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1205 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, full_mid+SIZE*sizeof(pixel), half, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1206 }\
1207 \
1208 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc11)(uint8_t *dst, uint8_t *src, int stride){\
1209 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1210 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1211 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1212 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1213 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
1214 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1215 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1216 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1217 }\
1218 \
1219 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc31)(uint8_t *dst, uint8_t *src, int stride){\
1220 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1221 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1222 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1223 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1224 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
1225 FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
1226 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1227 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1228 }\
1229 \
1230 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc13)(uint8_t *dst, uint8_t *src, int stride){\
1231 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1232 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1233 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1234 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1235 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
1236 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1237 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1238 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1239 }\
1240 \
1241 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc33)(uint8_t *dst, uint8_t *src, int stride){\
1242 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1243 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1244 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1245 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1246 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
1247 FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
1248 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1249 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1250 }\
1251 \
1252 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc22)(uint8_t *dst, uint8_t *src, int stride){\
1253 int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
1254 FUNC(OPNAME ## h264_qpel ## SIZE ## _hv_lowpass)(dst, tmp, src, stride, SIZE*sizeof(pixel), stride);\
1255 }\
1256 \
1257 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc21)(uint8_t *dst, uint8_t *src, int stride){\
1258 int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
1259 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1260 uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
1261 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src, SIZE*sizeof(pixel), stride);\
1262 FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
1263 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1264 }\
1265 \
1266 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc23)(uint8_t *dst, uint8_t *src, int stride){\
1267 int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
1268 uint8_t halfH[SIZE*SIZE*sizeof(pixel)];\
1269 uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
1270 FUNC(put_h264_qpel ## SIZE ## _h_lowpass)(halfH, src + stride, SIZE*sizeof(pixel), stride);\
1271 FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
1272 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfH, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1273 }\
1274 \
1275 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc12)(uint8_t *dst, uint8_t *src, int stride){\
1276 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1277 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1278 int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
1279 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1280 uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
1281 FUNC(copy_block ## SIZE )(full, src - stride*2, SIZE*sizeof(pixel), stride, SIZE + 5);\
1282 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1283 FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
1284 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1285 }\
1286 \
1287 static void FUNCC(OPNAME ## h264_qpel ## SIZE ## _mc32)(uint8_t *dst, uint8_t *src, int stride){\
1288 uint8_t full[SIZE*(SIZE+5)*sizeof(pixel)];\
1289 uint8_t * const full_mid= full + SIZE*2*sizeof(pixel);\
1290 int16_t tmp[SIZE*(SIZE+5)*sizeof(pixel)];\
1291 uint8_t halfV[SIZE*SIZE*sizeof(pixel)];\
1292 uint8_t halfHV[SIZE*SIZE*sizeof(pixel)];\
1293 FUNC(copy_block ## SIZE )(full, src - stride*2 + sizeof(pixel), SIZE*sizeof(pixel), stride, SIZE + 5);\
1294 FUNC(put_h264_qpel ## SIZE ## _v_lowpass)(halfV, full_mid, SIZE*sizeof(pixel), SIZE*sizeof(pixel));\
1295 FUNC(put_h264_qpel ## SIZE ## _hv_lowpass)(halfHV, tmp, src, SIZE*sizeof(pixel), SIZE*sizeof(pixel), stride);\
1296 FUNC(OPNAME ## pixels ## SIZE ## _l2)(dst, halfV, halfHV, stride, SIZE*sizeof(pixel), SIZE*sizeof(pixel), SIZE);\
1297 }\
1298
1299 #define op_avg(a, b) a = (((a)+CLIP(((b) + 16)>>5)+1)>>1)
1300 //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
1301 #define op_put(a, b) a = CLIP(((b) + 16)>>5)
1302 #define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1)
1303 #define op2_put(a, b) a = CLIP(((b) + 512)>>10)
1304
1305 H264_LOWPASS(put_ , op_put, op2_put)
1306 H264_LOWPASS(avg_ , op_avg, op2_avg)
1307 H264_MC(put_, 2)
1308 H264_MC(put_, 4)
1309 H264_MC(put_, 8)
1310 H264_MC(put_, 16)
1311 H264_MC(avg_, 4)
1312 H264_MC(avg_, 8)
1313 H264_MC(avg_, 16)
1314
1315 #undef op_avg
1316 #undef op_put
1317 #undef op2_avg
1318 #undef op2_put
1319
1320 #define put_h264_qpel8_mc00_c ff_put_pixels8x8_c
1321 #define avg_h264_qpel8_mc00_c ff_avg_pixels8x8_c
1322 #define put_h264_qpel16_mc00_c ff_put_pixels16x16_c
1323 #define avg_h264_qpel16_mc00_c ff_avg_pixels16x16_c
1324
1325 void FUNCC(ff_put_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) {
1326 FUNCC(put_pixels8)(dst, src, stride, 8);
1327 }
1328 void FUNCC(ff_avg_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) {
1329 FUNCC(avg_pixels8)(dst, src, stride, 8);
1330 }
1331 void FUNCC(ff_put_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) {
1332 FUNCC(put_pixels16)(dst, src, stride, 16);
1333 }
1334 void FUNCC(ff_avg_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) {
1335 FUNCC(avg_pixels16)(dst, src, stride, 16);
1336 }
1337
1338 static void FUNCC(clear_block)(DCTELEM *block)
1339 {
1340 memset(block, 0, sizeof(dctcoef)*64);
1341 }
1342
1343 /**
1344 * memset(blocks, 0, sizeof(DCTELEM)*6*64)
1345 */
1346 static void FUNCC(clear_blocks)(DCTELEM *blocks)
1347 {
1348 memset(blocks, 0, sizeof(dctcoef)*6*64);
1349 }