3 * Copyright (c) 2000, 2001 Fabrice Bellard.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
23 #include "mpegvideo.h"
27 UINT8 cropTbl[256 + 2 * MAX_NEG_CROP];
28 UINT32 squareTbl[512];
30 const UINT8 ff_zigzag_direct[64] = {
31 0, 1, 8, 16, 9, 2, 3, 10,
32 17, 24, 32, 25, 18, 11, 4, 5,
33 12, 19, 26, 33, 40, 48, 41, 34,
34 27, 20, 13, 6, 7, 14, 21, 28,
35 35, 42, 49, 56, 57, 50, 43, 36,
36 29, 22, 15, 23, 30, 37, 44, 51,
37 58, 59, 52, 45, 38, 31, 39, 46,
38 53, 60, 61, 54, 47, 55, 62, 63
41 /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
42 UINT16 __align8 inv_zigzag_direct16[64];
44 const UINT8 ff_alternate_horizontal_scan[64] = {
45 0, 1, 2, 3, 8, 9, 16, 17,
46 10, 11, 4, 5, 6, 7, 15, 14,
47 13, 12, 19, 18, 24, 25, 32, 33,
48 26, 27, 20, 21, 22, 23, 28, 29,
49 30, 31, 34, 35, 40, 41, 48, 49,
50 42, 43, 36, 37, 38, 39, 44, 45,
51 46, 47, 50, 51, 56, 57, 58, 59,
52 52, 53, 54, 55, 60, 61, 62, 63,
55 const UINT8 ff_alternate_vertical_scan[64] = {
56 0, 8, 16, 24, 1, 9, 2, 10,
57 17, 25, 32, 40, 48, 56, 57, 49,
58 41, 33, 26, 18, 3, 11, 4, 12,
59 19, 27, 34, 42, 50, 58, 35, 43,
60 51, 59, 20, 28, 5, 13, 6, 14,
61 21, 29, 36, 44, 52, 60, 37, 45,
62 53, 61, 22, 30, 7, 15, 23, 31,
63 38, 46, 54, 62, 39, 47, 55, 63,
66 /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
67 const UINT32 inverse[256]={
68 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
69 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
70 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
71 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
72 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
73 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
74 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
75 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
76 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
77 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
78 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
79 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
80 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
81 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
82 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
83 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
84 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
85 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
86 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
87 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
88 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
89 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
90 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
91 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
92 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
93 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
94 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
95 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
96 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
97 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
98 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
99 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
102 static int pix_sum_c(UINT8 * pix, int line_size)
107 for (i = 0; i < 16; i++) {
108 for (j = 0; j < 16; j += 8) {
119 pix += line_size - 16;
124 static int pix_norm1_c(UINT8 * pix, int line_size)
127 UINT32 *sq = squareTbl + 256;
130 for (i = 0; i < 16; i++) {
131 for (j = 0; j < 16; j += 8) {
142 pix += line_size - 16;
148 static int sse8_c(void *v, UINT8 * pix1, UINT8 * pix2, int line_size)
151 UINT32 *sq = squareTbl + 256;
154 for (i = 0; i < 8; i++) {
155 s += sq[pix1[0] - pix2[0]];
156 s += sq[pix1[1] - pix2[1]];
157 s += sq[pix1[2] - pix2[2]];
158 s += sq[pix1[3] - pix2[3]];
159 s += sq[pix1[4] - pix2[4]];
160 s += sq[pix1[5] - pix2[5]];
161 s += sq[pix1[6] - pix2[6]];
162 s += sq[pix1[7] - pix2[7]];
169 static int sse16_c(void *v, UINT8 * pix1, UINT8 * pix2, int line_size)
172 UINT32 *sq = squareTbl + 256;
175 for (i = 0; i < 16; i++) {
176 for (j = 0; j < 16; j += 8) {
177 s += sq[pix1[0] - pix2[0]];
178 s += sq[pix1[1] - pix2[1]];
179 s += sq[pix1[2] - pix2[2]];
180 s += sq[pix1[3] - pix2[3]];
181 s += sq[pix1[4] - pix2[4]];
182 s += sq[pix1[5] - pix2[5]];
183 s += sq[pix1[6] - pix2[6]];
184 s += sq[pix1[7] - pix2[7]];
188 pix1 += line_size - 16;
189 pix2 += line_size - 16;
194 static void get_pixels_c(DCTELEM *restrict block, const UINT8 *pixels, int line_size)
198 /* read the pixels */
200 block[0] = pixels[0];
201 block[1] = pixels[1];
202 block[2] = pixels[2];
203 block[3] = pixels[3];
204 block[4] = pixels[4];
205 block[5] = pixels[5];
206 block[6] = pixels[6];
207 block[7] = pixels[7];
213 static void diff_pixels_c(DCTELEM *restrict block, const UINT8 *s1,
214 const UINT8 *s2, int stride){
217 /* read the pixels */
219 block[0] = s1[0] - s2[0];
220 block[1] = s1[1] - s2[1];
221 block[2] = s1[2] - s2[2];
222 block[3] = s1[3] - s2[3];
223 block[4] = s1[4] - s2[4];
224 block[5] = s1[5] - s2[5];
225 block[6] = s1[6] - s2[6];
226 block[7] = s1[7] - s2[7];
234 static void put_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
238 UINT8 *cm = cropTbl + MAX_NEG_CROP;
240 /* read the pixels */
242 pixels[0] = cm[block[0]];
243 pixels[1] = cm[block[1]];
244 pixels[2] = cm[block[2]];
245 pixels[3] = cm[block[3]];
246 pixels[4] = cm[block[4]];
247 pixels[5] = cm[block[5]];
248 pixels[6] = cm[block[6]];
249 pixels[7] = cm[block[7]];
256 static void add_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels,
260 UINT8 *cm = cropTbl + MAX_NEG_CROP;
262 /* read the pixels */
264 pixels[0] = cm[pixels[0] + block[0]];
265 pixels[1] = cm[pixels[1] + block[1]];
266 pixels[2] = cm[pixels[2] + block[2]];
267 pixels[3] = cm[pixels[3] + block[3]];
268 pixels[4] = cm[pixels[4] + block[4]];
269 pixels[5] = cm[pixels[5] + block[5]];
270 pixels[6] = cm[pixels[6] + block[6]];
271 pixels[7] = cm[pixels[7] + block[7]];
278 #define PIXOP2(OPNAME, OP) \
279 static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
283 OP(*((uint64_t*)block), LD64(pixels));\
289 static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
293 const uint64_t a= LD64(pixels );\
294 const uint64_t b= LD64(pixels+1);\
295 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
301 static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
305 const uint64_t a= LD64(pixels );\
306 const uint64_t b= LD64(pixels+1);\
307 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
313 static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
317 const uint64_t a= LD64(pixels );\
318 const uint64_t b= LD64(pixels+line_size);\
319 OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
325 static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
329 const uint64_t a= LD64(pixels );\
330 const uint64_t b= LD64(pixels+line_size);\
331 OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
337 static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
340 const uint64_t a= LD64(pixels );\
341 const uint64_t b= LD64(pixels+1);\
342 uint64_t l0= (a&0x0303030303030303ULL)\
343 + (b&0x0303030303030303ULL)\
344 + 0x0202020202020202ULL;\
345 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
346 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
350 for(i=0; i<h; i+=2){\
351 uint64_t a= LD64(pixels );\
352 uint64_t b= LD64(pixels+1);\
353 l1= (a&0x0303030303030303ULL)\
354 + (b&0x0303030303030303ULL);\
355 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
356 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
357 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
362 l0= (a&0x0303030303030303ULL)\
363 + (b&0x0303030303030303ULL)\
364 + 0x0202020202020202ULL;\
365 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
366 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
367 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
373 static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
376 const uint64_t a= LD64(pixels );\
377 const uint64_t b= LD64(pixels+1);\
378 uint64_t l0= (a&0x0303030303030303ULL)\
379 + (b&0x0303030303030303ULL)\
380 + 0x0101010101010101ULL;\
381 uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
382 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
386 for(i=0; i<h; i+=2){\
387 uint64_t a= LD64(pixels );\
388 uint64_t b= LD64(pixels+1);\
389 l1= (a&0x0303030303030303ULL)\
390 + (b&0x0303030303030303ULL);\
391 h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
392 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
393 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
398 l0= (a&0x0303030303030303ULL)\
399 + (b&0x0303030303030303ULL)\
400 + 0x0101010101010101ULL;\
401 h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
402 + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
403 OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
409 CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
410 CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
411 CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
412 CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
413 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
414 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
415 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
417 #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
418 #else // 64 bit variant
420 #define PIXOP2(OPNAME, OP) \
421 static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
424 OP(*((uint32_t*)(block )), LD32(pixels ));\
425 OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
430 static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
431 OPNAME ## _pixels8_c(block, pixels, line_size, h);\
434 static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
435 int src_stride1, int src_stride2, int h){\
439 a= LD32(&src1[i*src_stride1 ]);\
440 b= LD32(&src2[i*src_stride2 ]);\
441 OP(*((uint32_t*)&dst[i*dst_stride ]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
442 a= LD32(&src1[i*src_stride1+4]);\
443 b= LD32(&src2[i*src_stride2+4]);\
444 OP(*((uint32_t*)&dst[i*dst_stride+4]), (a&b) + (((a^b)&0xFEFEFEFEUL)>>1));\
448 static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
449 int src_stride1, int src_stride2, int h){\
453 a= LD32(&src1[i*src_stride1 ]);\
454 b= LD32(&src2[i*src_stride2 ]);\
455 OP(*((uint32_t*)&dst[i*dst_stride ]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
456 a= LD32(&src1[i*src_stride1+4]);\
457 b= LD32(&src2[i*src_stride2+4]);\
458 OP(*((uint32_t*)&dst[i*dst_stride+4]), (a|b) - (((a^b)&0xFEFEFEFEUL)>>1));\
462 static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
463 int src_stride1, int src_stride2, int h){\
464 OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
465 OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
468 static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
469 int src_stride1, int src_stride2, int h){\
470 OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
471 OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
474 static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
475 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
478 static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
479 OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
482 static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
483 OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
486 static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
487 OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
490 static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
491 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
494 uint32_t a, b, c, d, l0, l1, h0, h1;\
495 a= LD32(&src1[i*src_stride1]);\
496 b= LD32(&src2[i*src_stride2]);\
497 c= LD32(&src3[i*src_stride3]);\
498 d= LD32(&src4[i*src_stride4]);\
499 l0= (a&0x03030303UL)\
502 h0= ((a&0xFCFCFCFCUL)>>2)\
503 + ((b&0xFCFCFCFCUL)>>2);\
504 l1= (c&0x03030303UL)\
506 h1= ((c&0xFCFCFCFCUL)>>2)\
507 + ((d&0xFCFCFCFCUL)>>2);\
508 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
509 a= LD32(&src1[i*src_stride1+4]);\
510 b= LD32(&src2[i*src_stride2+4]);\
511 c= LD32(&src3[i*src_stride3+4]);\
512 d= LD32(&src4[i*src_stride4+4]);\
513 l0= (a&0x03030303UL)\
516 h0= ((a&0xFCFCFCFCUL)>>2)\
517 + ((b&0xFCFCFCFCUL)>>2);\
518 l1= (c&0x03030303UL)\
520 h1= ((c&0xFCFCFCFCUL)>>2)\
521 + ((d&0xFCFCFCFCUL)>>2);\
522 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
525 static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
526 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
529 uint32_t a, b, c, d, l0, l1, h0, h1;\
530 a= LD32(&src1[i*src_stride1]);\
531 b= LD32(&src2[i*src_stride2]);\
532 c= LD32(&src3[i*src_stride3]);\
533 d= LD32(&src4[i*src_stride4]);\
534 l0= (a&0x03030303UL)\
537 h0= ((a&0xFCFCFCFCUL)>>2)\
538 + ((b&0xFCFCFCFCUL)>>2);\
539 l1= (c&0x03030303UL)\
541 h1= ((c&0xFCFCFCFCUL)>>2)\
542 + ((d&0xFCFCFCFCUL)>>2);\
543 OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
544 a= LD32(&src1[i*src_stride1+4]);\
545 b= LD32(&src2[i*src_stride2+4]);\
546 c= LD32(&src3[i*src_stride3+4]);\
547 d= LD32(&src4[i*src_stride4+4]);\
548 l0= (a&0x03030303UL)\
551 h0= ((a&0xFCFCFCFCUL)>>2)\
552 + ((b&0xFCFCFCFCUL)>>2);\
553 l1= (c&0x03030303UL)\
555 h1= ((c&0xFCFCFCFCUL)>>2)\
556 + ((d&0xFCFCFCFCUL)>>2);\
557 OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
560 static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
561 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
562 OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
563 OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
565 static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
566 int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
567 OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
568 OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
571 static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
576 const uint32_t a= LD32(pixels );\
577 const uint32_t b= LD32(pixels+1);\
578 uint32_t l0= (a&0x03030303UL)\
581 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
582 + ((b&0xFCFCFCFCUL)>>2);\
586 for(i=0; i<h; i+=2){\
587 uint32_t a= LD32(pixels );\
588 uint32_t b= LD32(pixels+1);\
589 l1= (a&0x03030303UL)\
591 h1= ((a&0xFCFCFCFCUL)>>2)\
592 + ((b&0xFCFCFCFCUL)>>2);\
593 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
598 l0= (a&0x03030303UL)\
601 h0= ((a&0xFCFCFCFCUL)>>2)\
602 + ((b&0xFCFCFCFCUL)>>2);\
603 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
607 pixels+=4-line_size*(h+1);\
608 block +=4-line_size*h;\
612 static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
617 const uint32_t a= LD32(pixels );\
618 const uint32_t b= LD32(pixels+1);\
619 uint32_t l0= (a&0x03030303UL)\
622 uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
623 + ((b&0xFCFCFCFCUL)>>2);\
627 for(i=0; i<h; i+=2){\
628 uint32_t a= LD32(pixels );\
629 uint32_t b= LD32(pixels+1);\
630 l1= (a&0x03030303UL)\
632 h1= ((a&0xFCFCFCFCUL)>>2)\
633 + ((b&0xFCFCFCFCUL)>>2);\
634 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
639 l0= (a&0x03030303UL)\
642 h0= ((a&0xFCFCFCFCUL)>>2)\
643 + ((b&0xFCFCFCFCUL)>>2);\
644 OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
648 pixels+=4-line_size*(h+1);\
649 block +=4-line_size*h;\
653 CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
654 CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
655 CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
656 CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
657 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
658 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
659 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
660 CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
662 #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
664 #define op_put(a, b) a = b
671 #define avg2(a,b) ((a+b+1)>>1)
672 #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
675 static void gmc1_c(UINT8 *dst, UINT8 *src, int stride, int h, int x16, int y16, int rounder)
677 const int A=(16-x16)*(16-y16);
678 const int B=( x16)*(16-y16);
679 const int C=(16-x16)*( y16);
680 const int D=( x16)*( y16);
685 dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
686 dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
687 dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
688 dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
689 dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
690 dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
691 dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
692 dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
698 static void gmc_c(UINT8 *dst, UINT8 *src, int stride, int h, int ox, int oy,
699 int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
702 const int s= 1<<shift;
712 for(x=0; x<8; x++){ //XXX FIXME optimize
713 int src_x, src_y, frac_x, frac_y, index;
722 if((unsigned)src_x < width){
723 if((unsigned)src_y < height){
724 index= src_x + src_y*stride;
725 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
726 + src[index +1]* frac_x )*(s-frac_y)
727 + ( src[index+stride ]*(s-frac_x)
728 + src[index+stride+1]* frac_x )* frac_y
731 index= src_x + clip(src_y, 0, height)*stride;
732 dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
733 + src[index +1]* frac_x )*s
737 if((unsigned)src_y < height){
738 index= clip(src_x, 0, width) + src_y*stride;
739 dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
740 + src[index+stride ]* frac_y )*s
743 index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
744 dst[y*stride + x]= src[index ];
756 static inline void copy_block17(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
761 ST32(dst , LD32(src ));
762 ST32(dst+4 , LD32(src+4 ));
763 ST32(dst+8 , LD32(src+8 ));
764 ST32(dst+12, LD32(src+12));
771 static inline void copy_block9(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h)
776 ST32(dst , LD32(src ));
777 ST32(dst+4 , LD32(src+4 ));
785 #define QPEL_MC(r, OPNAME, RND, OP) \
786 static void OPNAME ## mpeg4_qpel8_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
787 UINT8 *cm = cropTbl + MAX_NEG_CROP;\
791 OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
792 OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
793 OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
794 OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
795 OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
796 OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
797 OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
798 OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
804 static void OPNAME ## mpeg4_qpel8_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int w){\
805 UINT8 *cm = cropTbl + MAX_NEG_CROP;\
809 const int src0= src[0*srcStride];\
810 const int src1= src[1*srcStride];\
811 const int src2= src[2*srcStride];\
812 const int src3= src[3*srcStride];\
813 const int src4= src[4*srcStride];\
814 const int src5= src[5*srcStride];\
815 const int src6= src[6*srcStride];\
816 const int src7= src[7*srcStride];\
817 const int src8= src[8*srcStride];\
818 OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
819 OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
820 OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
821 OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
822 OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
823 OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
824 OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
825 OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
831 static void OPNAME ## mpeg4_qpel16_h_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride, int h){\
832 UINT8 *cm = cropTbl + MAX_NEG_CROP;\
837 OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
838 OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
839 OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
840 OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
841 OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
842 OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
843 OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
844 OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
845 OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
846 OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
847 OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
848 OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
849 OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
850 OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
851 OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
852 OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
858 static void OPNAME ## mpeg4_qpel16_v_lowpass(UINT8 *dst, UINT8 *src, int dstStride, int srcStride){\
859 UINT8 *cm = cropTbl + MAX_NEG_CROP;\
864 const int src0= src[0*srcStride];\
865 const int src1= src[1*srcStride];\
866 const int src2= src[2*srcStride];\
867 const int src3= src[3*srcStride];\
868 const int src4= src[4*srcStride];\
869 const int src5= src[5*srcStride];\
870 const int src6= src[6*srcStride];\
871 const int src7= src[7*srcStride];\
872 const int src8= src[8*srcStride];\
873 const int src9= src[9*srcStride];\
874 const int src10= src[10*srcStride];\
875 const int src11= src[11*srcStride];\
876 const int src12= src[12*srcStride];\
877 const int src13= src[13*srcStride];\
878 const int src14= src[14*srcStride];\
879 const int src15= src[15*srcStride];\
880 const int src16= src[16*srcStride];\
881 OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
882 OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
883 OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
884 OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
885 OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
886 OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
887 OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
888 OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
889 OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
890 OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
891 OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
892 OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
893 OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
894 OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
895 OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
896 OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
902 static void OPNAME ## qpel8_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
903 OPNAME ## pixels8_c(dst, src, stride, 8);\
906 static void OPNAME ## qpel8_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
908 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
909 OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
912 static void OPNAME ## qpel8_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
913 OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
916 static void OPNAME ## qpel8_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
918 put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
919 OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
922 static void OPNAME ## qpel8_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
925 copy_block9(full, src, 16, stride, 9);\
926 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
927 OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
930 static void OPNAME ## qpel8_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
932 copy_block9(full, src, 16, stride, 9);\
933 OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16, 8);\
936 static void OPNAME ## qpel8_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
939 copy_block9(full, src, 16, stride, 9);\
940 put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16, 8);\
941 OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
943 static void OPNAME ## qpel8_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
948 copy_block9(full, src, 16, stride, 9);\
949 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
950 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
951 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
952 OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
954 static void OPNAME ## qpel8_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
959 copy_block9(full, src, 16, stride, 9);\
960 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
961 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
962 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
963 OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
965 static void OPNAME ## qpel8_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
970 copy_block9(full, src, 16, stride, 9);\
971 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
972 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
973 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
974 OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
976 static void OPNAME ## qpel8_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
981 copy_block9(full, src, 16, stride, 9);\
982 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
983 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
984 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
985 OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
987 static void OPNAME ## qpel8_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
990 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
991 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
992 OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
994 static void OPNAME ## qpel8_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
997 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
998 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
999 OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
1001 static void OPNAME ## qpel8_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
1006 copy_block9(full, src, 16, stride, 9);\
1007 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1008 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16, 8);\
1009 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
1010 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1012 static void OPNAME ## qpel8_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
1017 copy_block9(full, src, 16, stride, 9);\
1018 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
1019 put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16, 8);\
1020 put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8, 8);\
1021 OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
1023 static void OPNAME ## qpel8_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
1025 put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
1026 OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8, 8);\
1028 static void OPNAME ## qpel16_mc00_c (UINT8 *dst, UINT8 *src, int stride){\
1029 OPNAME ## pixels16_c(dst, src, stride, 16);\
1032 static void OPNAME ## qpel16_mc10_c(UINT8 *dst, UINT8 *src, int stride){\
1034 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1035 OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
1038 static void OPNAME ## qpel16_mc20_c(UINT8 *dst, UINT8 *src, int stride){\
1039 OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
1042 static void OPNAME ## qpel16_mc30_c(UINT8 *dst, UINT8 *src, int stride){\
1044 put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
1045 OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
1048 static void OPNAME ## qpel16_mc01_c(UINT8 *dst, UINT8 *src, int stride){\
1051 copy_block17(full, src, 24, stride, 17);\
1052 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
1053 OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
1056 static void OPNAME ## qpel16_mc02_c(UINT8 *dst, UINT8 *src, int stride){\
1058 copy_block17(full, src, 24, stride, 17);\
1059 OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
1062 static void OPNAME ## qpel16_mc03_c(UINT8 *dst, UINT8 *src, int stride){\
1065 copy_block17(full, src, 24, stride, 17);\
1066 put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
1067 OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
1069 static void OPNAME ## qpel16_mc11_c(UINT8 *dst, UINT8 *src, int stride){\
1074 copy_block17(full, src, 24, stride, 17);\
1075 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
1076 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
1077 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1078 OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
1080 static void OPNAME ## qpel16_mc31_c(UINT8 *dst, UINT8 *src, int stride){\
1085 copy_block17(full, src, 24, stride, 17);\
1086 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
1087 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
1088 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1089 OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
1091 static void OPNAME ## qpel16_mc13_c(UINT8 *dst, UINT8 *src, int stride){\
1096 copy_block17(full, src, 24, stride, 17);\
1097 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
1098 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
1099 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1100 OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
1102 static void OPNAME ## qpel16_mc33_c(UINT8 *dst, UINT8 *src, int stride){\
1107 copy_block17(full, src, 24, stride, 17);\
1108 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
1109 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
1110 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1111 OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
1113 static void OPNAME ## qpel16_mc21_c(UINT8 *dst, UINT8 *src, int stride){\
1116 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
1117 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1118 OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
1120 static void OPNAME ## qpel16_mc23_c(UINT8 *dst, UINT8 *src, int stride){\
1123 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
1124 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1125 OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
1127 static void OPNAME ## qpel16_mc12_c(UINT8 *dst, UINT8 *src, int stride){\
1132 copy_block17(full, src, 24, stride, 17);\
1133 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
1134 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
1135 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1136 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
1138 static void OPNAME ## qpel16_mc32_c(UINT8 *dst, UINT8 *src, int stride){\
1143 copy_block17(full, src, 24, stride, 17);\
1144 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
1145 put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
1146 put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
1147 OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
1149 static void OPNAME ## qpel16_mc22_c(UINT8 *dst, UINT8 *src, int stride){\
1151 put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
1152 OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
1155 #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
1156 #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
1157 #define op_put(a, b) a = cm[((b) + 16)>>5]
1158 #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
1160 QPEL_MC(0, put_ , _ , op_put)
1161 QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
1162 QPEL_MC(0, avg_ , _ , op_avg)
1163 //QPEL_MC(1, avg_no_rnd , _ , op_avg)
1165 #undef op_avg_no_rnd
1167 #undef op_put_no_rnd
1169 static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
1170 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1174 dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
1175 dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
1176 dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
1177 dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
1178 dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
1179 dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
1180 dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
1181 dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
1187 static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
1188 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1192 const int src_1= src[ -srcStride];
1193 const int src0 = src[0 ];
1194 const int src1 = src[ srcStride];
1195 const int src2 = src[2*srcStride];
1196 const int src3 = src[3*srcStride];
1197 const int src4 = src[4*srcStride];
1198 const int src5 = src[5*srcStride];
1199 const int src6 = src[6*srcStride];
1200 const int src7 = src[7*srcStride];
1201 const int src8 = src[8*srcStride];
1202 const int src9 = src[9*srcStride];
1203 dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
1204 dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
1205 dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
1206 dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
1207 dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
1208 dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
1209 dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
1210 dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
1216 static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
1217 put_pixels8_c(dst, src, stride, 8);
1220 static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
1222 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
1223 put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
1226 static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
1227 wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
1230 static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
1232 wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
1233 put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
1236 static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
1237 wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
1240 static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
1244 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
1245 wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
1246 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
1247 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
1249 static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
1253 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
1254 wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
1255 wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
1256 put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
1258 static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
1260 wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
1261 wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
1265 static inline int pix_abs16x16_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1271 s += abs(pix1[0] - pix2[0]);
1272 s += abs(pix1[1] - pix2[1]);
1273 s += abs(pix1[2] - pix2[2]);
1274 s += abs(pix1[3] - pix2[3]);
1275 s += abs(pix1[4] - pix2[4]);
1276 s += abs(pix1[5] - pix2[5]);
1277 s += abs(pix1[6] - pix2[6]);
1278 s += abs(pix1[7] - pix2[7]);
1279 s += abs(pix1[8] - pix2[8]);
1280 s += abs(pix1[9] - pix2[9]);
1281 s += abs(pix1[10] - pix2[10]);
1282 s += abs(pix1[11] - pix2[11]);
1283 s += abs(pix1[12] - pix2[12]);
1284 s += abs(pix1[13] - pix2[13]);
1285 s += abs(pix1[14] - pix2[14]);
1286 s += abs(pix1[15] - pix2[15]);
1293 static int pix_abs16x16_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1299 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
1300 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
1301 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
1302 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
1303 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
1304 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
1305 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
1306 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
1307 s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
1308 s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
1309 s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
1310 s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
1311 s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
1312 s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
1313 s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
1314 s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
1321 static int pix_abs16x16_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1324 UINT8 *pix3 = pix2 + line_size;
1328 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
1329 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
1330 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
1331 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
1332 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
1333 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
1334 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
1335 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
1336 s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
1337 s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
1338 s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
1339 s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
1340 s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
1341 s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
1342 s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
1343 s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
1351 static int pix_abs16x16_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1354 UINT8 *pix3 = pix2 + line_size;
1358 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
1359 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
1360 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
1361 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
1362 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
1363 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
1364 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
1365 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
1366 s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
1367 s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
1368 s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
1369 s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
1370 s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
1371 s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
1372 s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
1373 s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
1381 static inline int pix_abs8x8_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1387 s += abs(pix1[0] - pix2[0]);
1388 s += abs(pix1[1] - pix2[1]);
1389 s += abs(pix1[2] - pix2[2]);
1390 s += abs(pix1[3] - pix2[3]);
1391 s += abs(pix1[4] - pix2[4]);
1392 s += abs(pix1[5] - pix2[5]);
1393 s += abs(pix1[6] - pix2[6]);
1394 s += abs(pix1[7] - pix2[7]);
1401 static int pix_abs8x8_x2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1407 s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
1408 s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
1409 s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
1410 s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
1411 s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
1412 s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
1413 s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
1414 s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
1421 static int pix_abs8x8_y2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1424 UINT8 *pix3 = pix2 + line_size;
1428 s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
1429 s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
1430 s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
1431 s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
1432 s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
1433 s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
1434 s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
1435 s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
1443 static int pix_abs8x8_xy2_c(UINT8 *pix1, UINT8 *pix2, int line_size)
1446 UINT8 *pix3 = pix2 + line_size;
1450 s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
1451 s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
1452 s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
1453 s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
1454 s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
1455 s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
1456 s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
1457 s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
1465 static int sad16x16_c(void *s, uint8_t *a, uint8_t *b, int stride){
1466 return pix_abs16x16_c(a,b,stride);
1469 static int sad8x8_c(void *s, uint8_t *a, uint8_t *b, int stride){
1470 return pix_abs8x8_c(a,b,stride);
1473 void ff_block_permute(DCTELEM *block, UINT8 *permutation, const UINT8 *scantable, int last)
1479 //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
1481 for(i=0; i<=last; i++){
1482 const int j= scantable[i];
1487 for(i=0; i<=last; i++){
1488 const int j= scantable[i];
1489 const int perm_j= permutation[j];
1490 block[perm_j]= temp[j];
1494 static void clear_blocks_c(DCTELEM *blocks)
1496 memset(blocks, 0, sizeof(DCTELEM)*6*64);
1499 static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
1501 for(i=0; i+7<w; i++){
1502 dst[i+0] += src[i+0];
1503 dst[i+1] += src[i+1];
1504 dst[i+2] += src[i+2];
1505 dst[i+3] += src[i+3];
1506 dst[i+4] += src[i+4];
1507 dst[i+5] += src[i+5];
1508 dst[i+6] += src[i+6];
1509 dst[i+7] += src[i+7];
1512 dst[i+0] += src[i+0];
1515 static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
1517 for(i=0; i+7<w; i++){
1518 dst[i+0] = src1[i+0]-src2[i+0];
1519 dst[i+1] = src1[i+1]-src2[i+1];
1520 dst[i+2] = src1[i+2]-src2[i+2];
1521 dst[i+3] = src1[i+3]-src2[i+3];
1522 dst[i+4] = src1[i+4]-src2[i+4];
1523 dst[i+5] = src1[i+5]-src2[i+5];
1524 dst[i+6] = src1[i+6]-src2[i+6];
1525 dst[i+7] = src1[i+7]-src2[i+7];
1528 dst[i+0] = src1[i+0]-src2[i+0];
1531 #define BUTTERFLY2(o1,o2,i1,i2) \
1535 #define BUTTERFLY1(x,y) \
1544 #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
1546 static int hadamard8_diff_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride){
1552 //FIXME try pointer walks
1553 BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
1554 BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
1555 BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
1556 BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
1558 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
1559 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
1560 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
1561 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
1563 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
1564 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
1565 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
1566 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
1570 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
1571 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
1572 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
1573 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
1575 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
1576 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
1577 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
1578 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
1581 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
1582 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
1583 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
1584 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
1590 printf("MAX:%d\n", maxi);
1596 static int hadamard8_abs_c(uint8_t *src, int stride, int mean){
1600 //FIXME OOOPS ignore 0 term instead of mean mess
1602 //FIXME try pointer walks
1603 BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-mean,src[stride*i+1]-mean);
1604 BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-mean,src[stride*i+3]-mean);
1605 BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-mean,src[stride*i+5]-mean);
1606 BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-mean,src[stride*i+7]-mean);
1608 BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
1609 BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
1610 BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
1611 BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
1613 BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
1614 BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
1615 BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
1616 BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
1620 BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
1621 BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
1622 BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
1623 BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
1625 BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
1626 BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
1627 BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
1628 BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
1631 BUTTERFLYA(temp[8*0+i], temp[8*4+i])
1632 +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
1633 +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
1634 +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
1640 static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
1641 MpegEncContext * const s= (MpegEncContext *)c;
1645 s->dsp.diff_pixels(temp, src1, src2, stride);
1654 void simple_idct(INT16 *block); //FIXME
1656 static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
1657 MpegEncContext * const s= (MpegEncContext *)c;
1658 DCTELEM temp[64], bak[64];
1663 s->dsp.diff_pixels(temp, src1, src2, stride);
1665 memcpy(bak, temp, 64*sizeof(DCTELEM));
1667 s->dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
1668 s->dct_unquantize(s, temp, 0, s->qscale);
1669 simple_idct(temp); //FIXME
1672 sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
1677 WARPER88_1616(hadamard8_diff_c, hadamard8_diff16_c)
1678 WARPER88_1616(dct_sad8x8_c, dct_sad16x16_c)
1679 WARPER88_1616(quant_psnr8x8_c, quant_psnr16x16_c)
1681 void dsputil_init(DSPContext* c, unsigned mask)
1683 static int init_done = 0;
1687 for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
1688 for(i=0;i<MAX_NEG_CROP;i++) {
1690 cropTbl[i + MAX_NEG_CROP + 256] = 255;
1693 for(i=0;i<512;i++) {
1694 squareTbl[i] = (i - 256) * (i - 256);
1697 for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
1702 c->get_pixels = get_pixels_c;
1703 c->diff_pixels = diff_pixels_c;
1704 c->put_pixels_clamped = put_pixels_clamped_c;
1705 c->add_pixels_clamped = add_pixels_clamped_c;
1708 c->clear_blocks = clear_blocks_c;
1709 c->pix_sum = pix_sum_c;
1710 c->pix_norm1 = pix_norm1_c;
1714 /* TODO [0] 16 [1] 8 */
1715 c->pix_abs16x16 = pix_abs16x16_c;
1716 c->pix_abs16x16_x2 = pix_abs16x16_x2_c;
1717 c->pix_abs16x16_y2 = pix_abs16x16_y2_c;
1718 c->pix_abs16x16_xy2 = pix_abs16x16_xy2_c;
1719 c->pix_abs8x8 = pix_abs8x8_c;
1720 c->pix_abs8x8_x2 = pix_abs8x8_x2_c;
1721 c->pix_abs8x8_y2 = pix_abs8x8_y2_c;
1722 c->pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
1724 #define dspfunc(PFX, IDX, NUM) \
1725 c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
1726 c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
1727 c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
1728 c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
1730 dspfunc(put, 0, 16);
1731 dspfunc(put_no_rnd, 0, 16);
1733 dspfunc(put_no_rnd, 1, 8);
1735 dspfunc(avg, 0, 16);
1736 dspfunc(avg_no_rnd, 0, 16);
1738 dspfunc(avg_no_rnd, 1, 8);
1741 #define dspfunc(PFX, IDX, NUM) \
1742 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
1743 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
1744 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
1745 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
1746 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
1747 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
1748 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
1749 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
1750 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
1751 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
1752 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
1753 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
1754 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
1755 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
1756 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
1757 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
1759 dspfunc(put_qpel, 0, 16);
1760 dspfunc(put_no_rnd_qpel, 0, 16);
1762 dspfunc(avg_qpel, 0, 16);
1763 /* dspfunc(avg_no_rnd_qpel, 0, 16); */
1765 dspfunc(put_qpel, 1, 8);
1766 dspfunc(put_no_rnd_qpel, 1, 8);
1768 dspfunc(avg_qpel, 1, 8);
1769 /* dspfunc(avg_no_rnd_qpel, 1, 8); */
1772 c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
1773 c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
1774 c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
1775 c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
1776 c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
1777 c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
1778 c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
1779 c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
1781 c->hadamard8_diff[0]= hadamard8_diff16_c;
1782 c->hadamard8_diff[1]= hadamard8_diff_c;
1783 c->hadamard8_abs = hadamard8_abs_c;
1785 c->dct_sad[0]= dct_sad16x16_c;
1786 c->dct_sad[1]= dct_sad8x8_c;
1788 c->sad[0]= sad16x16_c;
1789 c->sad[1]= sad8x8_c;
1791 c->quant_psnr[0]= quant_psnr16x16_c;
1792 c->quant_psnr[1]= quant_psnr8x8_c;
1794 c->add_bytes= add_bytes_c;
1795 c->diff_bytes= diff_bytes_c;
1798 dsputil_init_mmx(c, mask);
1801 /* FIXME - AVCodec context should have flag for bitexact match */
1802 /* fprintf(stderr, "\n\n\nff_bit_exact %d\n\n\n\n", ff_bit_exact); */
1803 dsputil_set_bit_exact_mmx(c, mask);
1807 dsputil_init_armv4l(c, mask);
1810 dsputil_init_mlib(c, mask);
1813 dsputil_init_alpha(c, mask);
1816 dsputil_init_ppc(c, mask);
1819 dsputil_init_mmi(c, mask);
1823 /* remove any non bit exact operation (testing purpose) */
1824 void avcodec_set_bit_exact(void)
1828 // FIXME - better set_bit_exact
1829 // dsputil_set_bit_exact_mmx();