You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2119 lines
79KB

  1. /*
  2. * DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard.
  4. *
  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.
  9. *
  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.
  14. *
  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
  18. *
  19. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  20. */
  21. #include "avcodec.h"
  22. #include "dsputil.h"
  23. #include "mpegvideo.h"
  24. int ff_bit_exact=0;
  25. uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
  26. uint32_t squareTbl[512];
  27. const uint8_t ff_zigzag_direct[64] = {
  28. 0, 1, 8, 16, 9, 2, 3, 10,
  29. 17, 24, 32, 25, 18, 11, 4, 5,
  30. 12, 19, 26, 33, 40, 48, 41, 34,
  31. 27, 20, 13, 6, 7, 14, 21, 28,
  32. 35, 42, 49, 56, 57, 50, 43, 36,
  33. 29, 22, 15, 23, 30, 37, 44, 51,
  34. 58, 59, 52, 45, 38, 31, 39, 46,
  35. 53, 60, 61, 54, 47, 55, 62, 63
  36. };
  37. /* not permutated inverse zigzag_direct + 1 for MMX quantizer */
  38. uint16_t __align8 inv_zigzag_direct16[64];
  39. const uint8_t ff_alternate_horizontal_scan[64] = {
  40. 0, 1, 2, 3, 8, 9, 16, 17,
  41. 10, 11, 4, 5, 6, 7, 15, 14,
  42. 13, 12, 19, 18, 24, 25, 32, 33,
  43. 26, 27, 20, 21, 22, 23, 28, 29,
  44. 30, 31, 34, 35, 40, 41, 48, 49,
  45. 42, 43, 36, 37, 38, 39, 44, 45,
  46. 46, 47, 50, 51, 56, 57, 58, 59,
  47. 52, 53, 54, 55, 60, 61, 62, 63,
  48. };
  49. const uint8_t ff_alternate_vertical_scan[64] = {
  50. 0, 8, 16, 24, 1, 9, 2, 10,
  51. 17, 25, 32, 40, 48, 56, 57, 49,
  52. 41, 33, 26, 18, 3, 11, 4, 12,
  53. 19, 27, 34, 42, 50, 58, 35, 43,
  54. 51, 59, 20, 28, 5, 13, 6, 14,
  55. 21, 29, 36, 44, 52, 60, 37, 45,
  56. 53, 61, 22, 30, 7, 15, 23, 31,
  57. 38, 46, 54, 62, 39, 47, 55, 63,
  58. };
  59. /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
  60. const uint32_t inverse[256]={
  61. 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
  62. 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
  63. 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
  64. 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
  65. 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
  66. 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
  67. 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
  68. 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
  69. 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
  70. 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
  71. 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
  72. 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
  73. 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
  74. 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
  75. 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
  76. 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
  77. 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
  78. 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
  79. 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
  80. 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
  81. 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
  82. 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
  83. 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
  84. 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
  85. 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
  86. 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
  87. 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
  88. 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
  89. 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
  90. 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
  91. 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
  92. 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
  93. };
  94. static int pix_sum_c(uint8_t * pix, int line_size)
  95. {
  96. int s, i, j;
  97. s = 0;
  98. for (i = 0; i < 16; i++) {
  99. for (j = 0; j < 16; j += 8) {
  100. s += pix[0];
  101. s += pix[1];
  102. s += pix[2];
  103. s += pix[3];
  104. s += pix[4];
  105. s += pix[5];
  106. s += pix[6];
  107. s += pix[7];
  108. pix += 8;
  109. }
  110. pix += line_size - 16;
  111. }
  112. return s;
  113. }
  114. static int pix_norm1_c(uint8_t * pix, int line_size)
  115. {
  116. int s, i, j;
  117. uint32_t *sq = squareTbl + 256;
  118. s = 0;
  119. for (i = 0; i < 16; i++) {
  120. for (j = 0; j < 16; j += 8) {
  121. #if 0
  122. s += sq[pix[0]];
  123. s += sq[pix[1]];
  124. s += sq[pix[2]];
  125. s += sq[pix[3]];
  126. s += sq[pix[4]];
  127. s += sq[pix[5]];
  128. s += sq[pix[6]];
  129. s += sq[pix[7]];
  130. #else
  131. #if LONG_MAX > 2147483647
  132. register uint64_t x=*(uint64_t*)pix;
  133. s += sq[x&0xff];
  134. s += sq[(x>>8)&0xff];
  135. s += sq[(x>>16)&0xff];
  136. s += sq[(x>>24)&0xff];
  137. s += sq[(x>>32)&0xff];
  138. s += sq[(x>>40)&0xff];
  139. s += sq[(x>>48)&0xff];
  140. s += sq[(x>>56)&0xff];
  141. #else
  142. register uint32_t x=*(uint32_t*)pix;
  143. s += sq[x&0xff];
  144. s += sq[(x>>8)&0xff];
  145. s += sq[(x>>16)&0xff];
  146. s += sq[(x>>24)&0xff];
  147. x=*(uint32_t*)(pix+4);
  148. s += sq[x&0xff];
  149. s += sq[(x>>8)&0xff];
  150. s += sq[(x>>16)&0xff];
  151. s += sq[(x>>24)&0xff];
  152. #endif
  153. #endif
  154. pix += 8;
  155. }
  156. pix += line_size - 16;
  157. }
  158. return s;
  159. }
  160. static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size)
  161. {
  162. int s, i;
  163. uint32_t *sq = squareTbl + 256;
  164. s = 0;
  165. for (i = 0; i < 8; i++) {
  166. s += sq[pix1[0] - pix2[0]];
  167. s += sq[pix1[1] - pix2[1]];
  168. s += sq[pix1[2] - pix2[2]];
  169. s += sq[pix1[3] - pix2[3]];
  170. s += sq[pix1[4] - pix2[4]];
  171. s += sq[pix1[5] - pix2[5]];
  172. s += sq[pix1[6] - pix2[6]];
  173. s += sq[pix1[7] - pix2[7]];
  174. pix1 += line_size;
  175. pix2 += line_size;
  176. }
  177. return s;
  178. }
  179. static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size)
  180. {
  181. int s, i;
  182. uint32_t *sq = squareTbl + 256;
  183. s = 0;
  184. for (i = 0; i < 16; i++) {
  185. s += sq[pix1[ 0] - pix2[ 0]];
  186. s += sq[pix1[ 1] - pix2[ 1]];
  187. s += sq[pix1[ 2] - pix2[ 2]];
  188. s += sq[pix1[ 3] - pix2[ 3]];
  189. s += sq[pix1[ 4] - pix2[ 4]];
  190. s += sq[pix1[ 5] - pix2[ 5]];
  191. s += sq[pix1[ 6] - pix2[ 6]];
  192. s += sq[pix1[ 7] - pix2[ 7]];
  193. s += sq[pix1[ 8] - pix2[ 8]];
  194. s += sq[pix1[ 9] - pix2[ 9]];
  195. s += sq[pix1[10] - pix2[10]];
  196. s += sq[pix1[11] - pix2[11]];
  197. s += sq[pix1[12] - pix2[12]];
  198. s += sq[pix1[13] - pix2[13]];
  199. s += sq[pix1[14] - pix2[14]];
  200. s += sq[pix1[15] - pix2[15]];
  201. pix1 += line_size;
  202. pix2 += line_size;
  203. }
  204. return s;
  205. }
  206. static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  207. {
  208. int i;
  209. /* read the pixels */
  210. for(i=0;i<8;i++) {
  211. block[0] = pixels[0];
  212. block[1] = pixels[1];
  213. block[2] = pixels[2];
  214. block[3] = pixels[3];
  215. block[4] = pixels[4];
  216. block[5] = pixels[5];
  217. block[6] = pixels[6];
  218. block[7] = pixels[7];
  219. pixels += line_size;
  220. block += 8;
  221. }
  222. }
  223. static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
  224. const uint8_t *s2, int stride){
  225. int i;
  226. /* read the pixels */
  227. for(i=0;i<8;i++) {
  228. block[0] = s1[0] - s2[0];
  229. block[1] = s1[1] - s2[1];
  230. block[2] = s1[2] - s2[2];
  231. block[3] = s1[3] - s2[3];
  232. block[4] = s1[4] - s2[4];
  233. block[5] = s1[5] - s2[5];
  234. block[6] = s1[6] - s2[6];
  235. block[7] = s1[7] - s2[7];
  236. s1 += stride;
  237. s2 += stride;
  238. block += 8;
  239. }
  240. }
  241. static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  242. int line_size)
  243. {
  244. int i;
  245. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  246. /* read the pixels */
  247. for(i=0;i<8;i++) {
  248. pixels[0] = cm[block[0]];
  249. pixels[1] = cm[block[1]];
  250. pixels[2] = cm[block[2]];
  251. pixels[3] = cm[block[3]];
  252. pixels[4] = cm[block[4]];
  253. pixels[5] = cm[block[5]];
  254. pixels[6] = cm[block[6]];
  255. pixels[7] = cm[block[7]];
  256. pixels += line_size;
  257. block += 8;
  258. }
  259. }
  260. static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
  261. int line_size)
  262. {
  263. int i;
  264. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  265. /* read the pixels */
  266. for(i=0;i<8;i++) {
  267. pixels[0] = cm[pixels[0] + block[0]];
  268. pixels[1] = cm[pixels[1] + block[1]];
  269. pixels[2] = cm[pixels[2] + block[2]];
  270. pixels[3] = cm[pixels[3] + block[3]];
  271. pixels[4] = cm[pixels[4] + block[4]];
  272. pixels[5] = cm[pixels[5] + block[5]];
  273. pixels[6] = cm[pixels[6] + block[6]];
  274. pixels[7] = cm[pixels[7] + block[7]];
  275. pixels += line_size;
  276. block += 8;
  277. }
  278. }
  279. #if 0
  280. #define PIXOP2(OPNAME, OP) \
  281. static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  282. {\
  283. int i;\
  284. for(i=0; i<h; i++){\
  285. OP(*((uint64_t*)block), LD64(pixels));\
  286. pixels+=line_size;\
  287. block +=line_size;\
  288. }\
  289. }\
  290. \
  291. static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  292. {\
  293. int i;\
  294. for(i=0; i<h; i++){\
  295. const uint64_t a= LD64(pixels );\
  296. const uint64_t b= LD64(pixels+1);\
  297. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  298. pixels+=line_size;\
  299. block +=line_size;\
  300. }\
  301. }\
  302. \
  303. static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  304. {\
  305. int i;\
  306. for(i=0; i<h; i++){\
  307. const uint64_t a= LD64(pixels );\
  308. const uint64_t b= LD64(pixels+1);\
  309. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  310. pixels+=line_size;\
  311. block +=line_size;\
  312. }\
  313. }\
  314. \
  315. static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  316. {\
  317. int i;\
  318. for(i=0; i<h; i++){\
  319. const uint64_t a= LD64(pixels );\
  320. const uint64_t b= LD64(pixels+line_size);\
  321. OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  322. pixels+=line_size;\
  323. block +=line_size;\
  324. }\
  325. }\
  326. \
  327. static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  328. {\
  329. int i;\
  330. for(i=0; i<h; i++){\
  331. const uint64_t a= LD64(pixels );\
  332. const uint64_t b= LD64(pixels+line_size);\
  333. OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
  334. pixels+=line_size;\
  335. block +=line_size;\
  336. }\
  337. }\
  338. \
  339. static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  340. {\
  341. int i;\
  342. const uint64_t a= LD64(pixels );\
  343. const uint64_t b= LD64(pixels+1);\
  344. uint64_t l0= (a&0x0303030303030303ULL)\
  345. + (b&0x0303030303030303ULL)\
  346. + 0x0202020202020202ULL;\
  347. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  348. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  349. uint64_t l1,h1;\
  350. \
  351. pixels+=line_size;\
  352. for(i=0; i<h; i+=2){\
  353. uint64_t a= LD64(pixels );\
  354. uint64_t b= LD64(pixels+1);\
  355. l1= (a&0x0303030303030303ULL)\
  356. + (b&0x0303030303030303ULL);\
  357. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  358. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  359. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  360. pixels+=line_size;\
  361. block +=line_size;\
  362. a= LD64(pixels );\
  363. b= LD64(pixels+1);\
  364. l0= (a&0x0303030303030303ULL)\
  365. + (b&0x0303030303030303ULL)\
  366. + 0x0202020202020202ULL;\
  367. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  368. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  369. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  370. pixels+=line_size;\
  371. block +=line_size;\
  372. }\
  373. }\
  374. \
  375. static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  376. {\
  377. int i;\
  378. const uint64_t a= LD64(pixels );\
  379. const uint64_t b= LD64(pixels+1);\
  380. uint64_t l0= (a&0x0303030303030303ULL)\
  381. + (b&0x0303030303030303ULL)\
  382. + 0x0101010101010101ULL;\
  383. uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  384. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  385. uint64_t l1,h1;\
  386. \
  387. pixels+=line_size;\
  388. for(i=0; i<h; i+=2){\
  389. uint64_t a= LD64(pixels );\
  390. uint64_t b= LD64(pixels+1);\
  391. l1= (a&0x0303030303030303ULL)\
  392. + (b&0x0303030303030303ULL);\
  393. h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  394. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  395. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  396. pixels+=line_size;\
  397. block +=line_size;\
  398. a= LD64(pixels );\
  399. b= LD64(pixels+1);\
  400. l0= (a&0x0303030303030303ULL)\
  401. + (b&0x0303030303030303ULL)\
  402. + 0x0101010101010101ULL;\
  403. h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
  404. + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
  405. OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
  406. pixels+=line_size;\
  407. block +=line_size;\
  408. }\
  409. }\
  410. \
  411. CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
  412. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
  413. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
  414. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
  415. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
  416. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
  417. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
  418. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
  419. #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){\
  422. int i;\
  423. for(i=0; i<h; i++){\
  424. OP(*((uint32_t*)(block )), LD32(pixels ));\
  425. OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
  426. pixels+=line_size;\
  427. block +=line_size;\
  428. }\
  429. }\
  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);\
  432. }\
  433. \
  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){\
  436. int i;\
  437. for(i=0; i<h; i++){\
  438. uint32_t a,b;\
  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));\
  445. }\
  446. }\
  447. \
  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){\
  450. int i;\
  451. for(i=0; i<h; i++){\
  452. uint32_t a,b;\
  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));\
  459. }\
  460. }\
  461. \
  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);\
  466. }\
  467. \
  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);\
  472. }\
  473. \
  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);\
  476. }\
  477. \
  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);\
  480. }\
  481. \
  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);\
  484. }\
  485. \
  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);\
  488. }\
  489. \
  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){\
  492. int i;\
  493. for(i=0; i<h; i++){\
  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)\
  500. + (b&0x03030303UL)\
  501. + 0x02020202UL;\
  502. h0= ((a&0xFCFCFCFCUL)>>2)\
  503. + ((b&0xFCFCFCFCUL)>>2);\
  504. l1= (c&0x03030303UL)\
  505. + (d&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)\
  514. + (b&0x03030303UL)\
  515. + 0x02020202UL;\
  516. h0= ((a&0xFCFCFCFCUL)>>2)\
  517. + ((b&0xFCFCFCFCUL)>>2);\
  518. l1= (c&0x03030303UL)\
  519. + (d&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));\
  523. }\
  524. }\
  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){\
  527. int i;\
  528. for(i=0; i<h; i++){\
  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)\
  535. + (b&0x03030303UL)\
  536. + 0x01010101UL;\
  537. h0= ((a&0xFCFCFCFCUL)>>2)\
  538. + ((b&0xFCFCFCFCUL)>>2);\
  539. l1= (c&0x03030303UL)\
  540. + (d&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)\
  549. + (b&0x03030303UL)\
  550. + 0x01010101UL;\
  551. h0= ((a&0xFCFCFCFCUL)>>2)\
  552. + ((b&0xFCFCFCFCUL)>>2);\
  553. l1= (c&0x03030303UL)\
  554. + (d&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));\
  558. }\
  559. }\
  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);\
  564. }\
  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);\
  569. }\
  570. \
  571. static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  572. {\
  573. int j;\
  574. for(j=0; j<2; j++){\
  575. int i;\
  576. const uint32_t a= LD32(pixels );\
  577. const uint32_t b= LD32(pixels+1);\
  578. uint32_t l0= (a&0x03030303UL)\
  579. + (b&0x03030303UL)\
  580. + 0x02020202UL;\
  581. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  582. + ((b&0xFCFCFCFCUL)>>2);\
  583. uint32_t l1,h1;\
  584. \
  585. pixels+=line_size;\
  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)\
  590. + (b&0x03030303UL);\
  591. h1= ((a&0xFCFCFCFCUL)>>2)\
  592. + ((b&0xFCFCFCFCUL)>>2);\
  593. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  594. pixels+=line_size;\
  595. block +=line_size;\
  596. a= LD32(pixels );\
  597. b= LD32(pixels+1);\
  598. l0= (a&0x03030303UL)\
  599. + (b&0x03030303UL)\
  600. + 0x02020202UL;\
  601. h0= ((a&0xFCFCFCFCUL)>>2)\
  602. + ((b&0xFCFCFCFCUL)>>2);\
  603. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  604. pixels+=line_size;\
  605. block +=line_size;\
  606. }\
  607. pixels+=4-line_size*(h+1);\
  608. block +=4-line_size*h;\
  609. }\
  610. }\
  611. \
  612. static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
  613. {\
  614. int j;\
  615. for(j=0; j<2; j++){\
  616. int i;\
  617. const uint32_t a= LD32(pixels );\
  618. const uint32_t b= LD32(pixels+1);\
  619. uint32_t l0= (a&0x03030303UL)\
  620. + (b&0x03030303UL)\
  621. + 0x01010101UL;\
  622. uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
  623. + ((b&0xFCFCFCFCUL)>>2);\
  624. uint32_t l1,h1;\
  625. \
  626. pixels+=line_size;\
  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)\
  631. + (b&0x03030303UL);\
  632. h1= ((a&0xFCFCFCFCUL)>>2)\
  633. + ((b&0xFCFCFCFCUL)>>2);\
  634. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  635. pixels+=line_size;\
  636. block +=line_size;\
  637. a= LD32(pixels );\
  638. b= LD32(pixels+1);\
  639. l0= (a&0x03030303UL)\
  640. + (b&0x03030303UL)\
  641. + 0x01010101UL;\
  642. h0= ((a&0xFCFCFCFCUL)>>2)\
  643. + ((b&0xFCFCFCFCUL)>>2);\
  644. OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
  645. pixels+=line_size;\
  646. block +=line_size;\
  647. }\
  648. pixels+=4-line_size*(h+1);\
  649. block +=4-line_size*h;\
  650. }\
  651. }\
  652. \
  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)\
  661. #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
  662. #endif
  663. #define op_put(a, b) a = b
  664. PIXOP2(avg, op_avg)
  665. PIXOP2(put, op_put)
  666. #undef op_avg
  667. #undef op_put
  668. #define avg2(a,b) ((a+b+1)>>1)
  669. #define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
  670. static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
  671. {
  672. const int A=(16-x16)*(16-y16);
  673. const int B=( x16)*(16-y16);
  674. const int C=(16-x16)*( y16);
  675. const int D=( x16)*( y16);
  676. int i;
  677. for(i=0; i<h; i++)
  678. {
  679. dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
  680. dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
  681. dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
  682. dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
  683. dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
  684. dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
  685. dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
  686. dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
  687. dst+= stride;
  688. src+= stride;
  689. }
  690. }
  691. static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
  692. int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
  693. {
  694. int y, vx, vy;
  695. const int s= 1<<shift;
  696. width--;
  697. height--;
  698. for(y=0; y<h; y++){
  699. int x;
  700. vx= ox;
  701. vy= oy;
  702. for(x=0; x<8; x++){ //XXX FIXME optimize
  703. int src_x, src_y, frac_x, frac_y, index;
  704. src_x= vx>>16;
  705. src_y= vy>>16;
  706. frac_x= src_x&(s-1);
  707. frac_y= src_y&(s-1);
  708. src_x>>=shift;
  709. src_y>>=shift;
  710. if((unsigned)src_x < width){
  711. if((unsigned)src_y < height){
  712. index= src_x + src_y*stride;
  713. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  714. + src[index +1]* frac_x )*(s-frac_y)
  715. + ( src[index+stride ]*(s-frac_x)
  716. + src[index+stride+1]* frac_x )* frac_y
  717. + r)>>(shift*2);
  718. }else{
  719. index= src_x + clip(src_y, 0, height)*stride;
  720. dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
  721. + src[index +1]* frac_x )*s
  722. + r)>>(shift*2);
  723. }
  724. }else{
  725. if((unsigned)src_y < height){
  726. index= clip(src_x, 0, width) + src_y*stride;
  727. dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
  728. + src[index+stride ]* frac_y )*s
  729. + r)>>(shift*2);
  730. }else{
  731. index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
  732. dst[y*stride + x]= src[index ];
  733. }
  734. }
  735. vx+= dxx;
  736. vy+= dyx;
  737. }
  738. ox += dxy;
  739. oy += dyy;
  740. }
  741. }
  742. static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  743. {
  744. int i;
  745. for(i=0; i<h; i++)
  746. {
  747. ST32(dst , LD32(src ));
  748. ST32(dst+4 , LD32(src+4 ));
  749. ST32(dst+8 , LD32(src+8 ));
  750. ST32(dst+12, LD32(src+12));
  751. dst[16]= src[16];
  752. dst+=dstStride;
  753. src+=srcStride;
  754. }
  755. }
  756. static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
  757. {
  758. int i;
  759. for(i=0; i<h; i++)
  760. {
  761. ST32(dst , LD32(src ));
  762. ST32(dst+4 , LD32(src+4 ));
  763. dst[8]= src[8];
  764. dst+=dstStride;
  765. src+=srcStride;
  766. }
  767. }
  768. #define QPEL_MC(r, OPNAME, RND, OP) \
  769. static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  770. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  771. int i;\
  772. for(i=0; i<h; i++)\
  773. {\
  774. OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
  775. OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
  776. OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
  777. OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
  778. OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
  779. OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
  780. OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
  781. OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
  782. dst+=dstStride;\
  783. src+=srcStride;\
  784. }\
  785. }\
  786. \
  787. static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  788. const int w=8;\
  789. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  790. int i;\
  791. for(i=0; i<w; i++)\
  792. {\
  793. const int src0= src[0*srcStride];\
  794. const int src1= src[1*srcStride];\
  795. const int src2= src[2*srcStride];\
  796. const int src3= src[3*srcStride];\
  797. const int src4= src[4*srcStride];\
  798. const int src5= src[5*srcStride];\
  799. const int src6= src[6*srcStride];\
  800. const int src7= src[7*srcStride];\
  801. const int src8= src[8*srcStride];\
  802. OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
  803. OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
  804. OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
  805. OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
  806. OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
  807. OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
  808. OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
  809. OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
  810. dst++;\
  811. src++;\
  812. }\
  813. }\
  814. \
  815. static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
  816. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  817. int i;\
  818. \
  819. for(i=0; i<h; i++)\
  820. {\
  821. OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
  822. OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
  823. OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
  824. OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
  825. OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
  826. OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
  827. OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
  828. OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
  829. OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
  830. OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
  831. OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
  832. OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
  833. OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
  834. OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
  835. OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
  836. OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
  837. dst+=dstStride;\
  838. src+=srcStride;\
  839. }\
  840. }\
  841. \
  842. static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
  843. uint8_t *cm = cropTbl + MAX_NEG_CROP;\
  844. int i;\
  845. const int w=16;\
  846. for(i=0; i<w; i++)\
  847. {\
  848. const int src0= src[0*srcStride];\
  849. const int src1= src[1*srcStride];\
  850. const int src2= src[2*srcStride];\
  851. const int src3= src[3*srcStride];\
  852. const int src4= src[4*srcStride];\
  853. const int src5= src[5*srcStride];\
  854. const int src6= src[6*srcStride];\
  855. const int src7= src[7*srcStride];\
  856. const int src8= src[8*srcStride];\
  857. const int src9= src[9*srcStride];\
  858. const int src10= src[10*srcStride];\
  859. const int src11= src[11*srcStride];\
  860. const int src12= src[12*srcStride];\
  861. const int src13= src[13*srcStride];\
  862. const int src14= src[14*srcStride];\
  863. const int src15= src[15*srcStride];\
  864. const int src16= src[16*srcStride];\
  865. OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
  866. OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
  867. OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
  868. OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
  869. OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
  870. OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
  871. OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
  872. OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
  873. OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
  874. OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
  875. OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
  876. OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
  877. OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
  878. OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
  879. OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
  880. OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
  881. dst++;\
  882. src++;\
  883. }\
  884. }\
  885. \
  886. static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  887. OPNAME ## pixels8_c(dst, src, stride, 8);\
  888. }\
  889. \
  890. static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  891. uint8_t half[64];\
  892. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  893. OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
  894. }\
  895. \
  896. static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  897. OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
  898. }\
  899. \
  900. static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  901. uint8_t half[64];\
  902. put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
  903. OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
  904. }\
  905. \
  906. static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  907. uint8_t full[16*9];\
  908. uint8_t half[64];\
  909. copy_block9(full, src, 16, stride, 9);\
  910. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  911. OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
  912. }\
  913. \
  914. static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  915. uint8_t full[16*9];\
  916. copy_block9(full, src, 16, stride, 9);\
  917. OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
  918. }\
  919. \
  920. static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  921. uint8_t full[16*9];\
  922. uint8_t half[64];\
  923. copy_block9(full, src, 16, stride, 9);\
  924. put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
  925. OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
  926. }\
  927. void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  928. uint8_t full[16*9];\
  929. uint8_t halfH[72];\
  930. uint8_t halfV[64];\
  931. uint8_t halfHV[64];\
  932. copy_block9(full, src, 16, stride, 9);\
  933. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  934. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  935. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  936. OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  937. }\
  938. static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  939. uint8_t full[16*9];\
  940. uint8_t halfH[72];\
  941. uint8_t halfHV[64];\
  942. copy_block9(full, src, 16, stride, 9);\
  943. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  944. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  945. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  946. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  947. }\
  948. void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  949. uint8_t full[16*9];\
  950. uint8_t halfH[72];\
  951. uint8_t halfV[64];\
  952. uint8_t halfHV[64];\
  953. copy_block9(full, src, 16, stride, 9);\
  954. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  955. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  956. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  957. OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  958. }\
  959. static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  960. uint8_t full[16*9];\
  961. uint8_t halfH[72];\
  962. uint8_t halfHV[64];\
  963. copy_block9(full, src, 16, stride, 9);\
  964. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  965. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  966. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  967. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  968. }\
  969. void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  970. uint8_t full[16*9];\
  971. uint8_t halfH[72];\
  972. uint8_t halfV[64];\
  973. uint8_t halfHV[64];\
  974. copy_block9(full, src, 16, stride, 9);\
  975. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  976. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  977. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  978. OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  979. }\
  980. static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  981. uint8_t full[16*9];\
  982. uint8_t halfH[72];\
  983. uint8_t halfHV[64];\
  984. copy_block9(full, src, 16, stride, 9);\
  985. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  986. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  987. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  988. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  989. }\
  990. void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  991. uint8_t full[16*9];\
  992. uint8_t halfH[72];\
  993. uint8_t halfV[64];\
  994. uint8_t halfHV[64];\
  995. copy_block9(full, src, 16, stride, 9);\
  996. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
  997. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  998. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  999. OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
  1000. }\
  1001. static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1002. uint8_t full[16*9];\
  1003. uint8_t halfH[72];\
  1004. uint8_t halfHV[64];\
  1005. copy_block9(full, src, 16, stride, 9);\
  1006. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1007. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1008. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1009. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1010. }\
  1011. static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1012. uint8_t halfH[72];\
  1013. uint8_t halfHV[64];\
  1014. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1015. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1016. OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
  1017. }\
  1018. static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1019. uint8_t halfH[72];\
  1020. uint8_t halfHV[64];\
  1021. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1022. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1023. OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
  1024. }\
  1025. void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1026. uint8_t full[16*9];\
  1027. uint8_t halfH[72];\
  1028. uint8_t halfV[64];\
  1029. uint8_t halfHV[64];\
  1030. copy_block9(full, src, 16, stride, 9);\
  1031. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1032. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
  1033. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1034. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1035. }\
  1036. static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1037. uint8_t full[16*9];\
  1038. uint8_t halfH[72];\
  1039. copy_block9(full, src, 16, stride, 9);\
  1040. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1041. put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
  1042. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1043. }\
  1044. void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1045. uint8_t full[16*9];\
  1046. uint8_t halfH[72];\
  1047. uint8_t halfV[64];\
  1048. uint8_t halfHV[64];\
  1049. copy_block9(full, src, 16, stride, 9);\
  1050. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1051. put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
  1052. put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
  1053. OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
  1054. }\
  1055. static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1056. uint8_t full[16*9];\
  1057. uint8_t halfH[72];\
  1058. copy_block9(full, src, 16, stride, 9);\
  1059. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
  1060. put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
  1061. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1062. }\
  1063. static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1064. uint8_t halfH[72];\
  1065. put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
  1066. OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
  1067. }\
  1068. static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
  1069. OPNAME ## pixels16_c(dst, src, stride, 16);\
  1070. }\
  1071. \
  1072. static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
  1073. uint8_t half[256];\
  1074. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1075. OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
  1076. }\
  1077. \
  1078. static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
  1079. OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
  1080. }\
  1081. \
  1082. static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
  1083. uint8_t half[256];\
  1084. put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
  1085. OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
  1086. }\
  1087. \
  1088. static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
  1089. uint8_t full[24*17];\
  1090. uint8_t half[256];\
  1091. copy_block17(full, src, 24, stride, 17);\
  1092. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1093. OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
  1094. }\
  1095. \
  1096. static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
  1097. uint8_t full[24*17];\
  1098. copy_block17(full, src, 24, stride, 17);\
  1099. OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
  1100. }\
  1101. \
  1102. static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
  1103. uint8_t full[24*17];\
  1104. uint8_t half[256];\
  1105. copy_block17(full, src, 24, stride, 17);\
  1106. put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
  1107. OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
  1108. }\
  1109. void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1110. uint8_t full[24*17];\
  1111. uint8_t halfH[272];\
  1112. uint8_t halfV[256];\
  1113. uint8_t halfHV[256];\
  1114. copy_block17(full, src, 24, stride, 17);\
  1115. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1116. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1117. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1118. OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1119. }\
  1120. static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
  1121. uint8_t full[24*17];\
  1122. uint8_t halfH[272];\
  1123. uint8_t halfHV[256];\
  1124. copy_block17(full, src, 24, stride, 17);\
  1125. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1126. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1127. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1128. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1129. }\
  1130. void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1131. uint8_t full[24*17];\
  1132. uint8_t halfH[272];\
  1133. uint8_t halfV[256];\
  1134. uint8_t halfHV[256];\
  1135. copy_block17(full, src, 24, stride, 17);\
  1136. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1137. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1138. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1139. OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1140. }\
  1141. static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
  1142. uint8_t full[24*17];\
  1143. uint8_t halfH[272];\
  1144. uint8_t halfHV[256];\
  1145. copy_block17(full, src, 24, stride, 17);\
  1146. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1147. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1148. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1149. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1150. }\
  1151. void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1152. uint8_t full[24*17];\
  1153. uint8_t halfH[272];\
  1154. uint8_t halfV[256];\
  1155. uint8_t halfHV[256];\
  1156. copy_block17(full, src, 24, stride, 17);\
  1157. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1158. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1159. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1160. OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1161. }\
  1162. static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
  1163. uint8_t full[24*17];\
  1164. uint8_t halfH[272];\
  1165. uint8_t halfHV[256];\
  1166. copy_block17(full, src, 24, stride, 17);\
  1167. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1168. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1169. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1170. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1171. }\
  1172. void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1173. uint8_t full[24*17];\
  1174. uint8_t halfH[272];\
  1175. uint8_t halfV[256];\
  1176. uint8_t halfHV[256];\
  1177. copy_block17(full, src, 24, stride, 17);\
  1178. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
  1179. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1180. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1181. OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
  1182. }\
  1183. static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
  1184. uint8_t full[24*17];\
  1185. uint8_t halfH[272];\
  1186. uint8_t halfHV[256];\
  1187. copy_block17(full, src, 24, stride, 17);\
  1188. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1189. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1190. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1191. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1192. }\
  1193. static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
  1194. uint8_t halfH[272];\
  1195. uint8_t halfHV[256];\
  1196. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1197. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1198. OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
  1199. }\
  1200. static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
  1201. uint8_t halfH[272];\
  1202. uint8_t halfHV[256];\
  1203. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1204. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1205. OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
  1206. }\
  1207. void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1208. uint8_t full[24*17];\
  1209. uint8_t halfH[272];\
  1210. uint8_t halfV[256];\
  1211. uint8_t halfHV[256];\
  1212. copy_block17(full, src, 24, stride, 17);\
  1213. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1214. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
  1215. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1216. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1217. }\
  1218. static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
  1219. uint8_t full[24*17];\
  1220. uint8_t halfH[272];\
  1221. copy_block17(full, src, 24, stride, 17);\
  1222. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1223. put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
  1224. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1225. }\
  1226. void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
  1227. uint8_t full[24*17];\
  1228. uint8_t halfH[272];\
  1229. uint8_t halfV[256];\
  1230. uint8_t halfHV[256];\
  1231. copy_block17(full, src, 24, stride, 17);\
  1232. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1233. put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
  1234. put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
  1235. OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
  1236. }\
  1237. static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
  1238. uint8_t full[24*17];\
  1239. uint8_t halfH[272];\
  1240. copy_block17(full, src, 24, stride, 17);\
  1241. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
  1242. put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
  1243. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1244. }\
  1245. static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
  1246. uint8_t halfH[272];\
  1247. put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
  1248. OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
  1249. }
  1250. #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
  1251. #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
  1252. #define op_put(a, b) a = cm[((b) + 16)>>5]
  1253. #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
  1254. QPEL_MC(0, put_ , _ , op_put)
  1255. QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
  1256. QPEL_MC(0, avg_ , _ , op_avg)
  1257. //QPEL_MC(1, avg_no_rnd , _ , op_avg)
  1258. #undef op_avg
  1259. #undef op_avg_no_rnd
  1260. #undef op_put
  1261. #undef op_put_no_rnd
  1262. static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
  1263. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  1264. int i;
  1265. for(i=0; i<h; i++){
  1266. dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
  1267. dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
  1268. dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
  1269. dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
  1270. dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
  1271. dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
  1272. dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
  1273. dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
  1274. dst+=dstStride;
  1275. src+=srcStride;
  1276. }
  1277. }
  1278. static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
  1279. uint8_t *cm = cropTbl + MAX_NEG_CROP;
  1280. int i;
  1281. for(i=0; i<w; i++){
  1282. const int src_1= src[ -srcStride];
  1283. const int src0 = src[0 ];
  1284. const int src1 = src[ srcStride];
  1285. const int src2 = src[2*srcStride];
  1286. const int src3 = src[3*srcStride];
  1287. const int src4 = src[4*srcStride];
  1288. const int src5 = src[5*srcStride];
  1289. const int src6 = src[6*srcStride];
  1290. const int src7 = src[7*srcStride];
  1291. const int src8 = src[8*srcStride];
  1292. const int src9 = src[9*srcStride];
  1293. dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
  1294. dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
  1295. dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
  1296. dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
  1297. dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
  1298. dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
  1299. dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
  1300. dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
  1301. src++;
  1302. dst++;
  1303. }
  1304. }
  1305. static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
  1306. put_pixels8_c(dst, src, stride, 8);
  1307. }
  1308. static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
  1309. uint8_t half[64];
  1310. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1311. put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
  1312. }
  1313. static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
  1314. wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
  1315. }
  1316. static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
  1317. uint8_t half[64];
  1318. wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
  1319. put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
  1320. }
  1321. static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
  1322. wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
  1323. }
  1324. static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
  1325. uint8_t halfH[88];
  1326. uint8_t halfV[64];
  1327. uint8_t halfHV[64];
  1328. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1329. wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
  1330. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1331. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  1332. }
  1333. static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
  1334. uint8_t halfH[88];
  1335. uint8_t halfV[64];
  1336. uint8_t halfHV[64];
  1337. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1338. wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
  1339. wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
  1340. put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
  1341. }
  1342. static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
  1343. uint8_t halfH[88];
  1344. wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
  1345. wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
  1346. }
  1347. static inline int pix_abs16x16_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1348. {
  1349. int s, i;
  1350. s = 0;
  1351. for(i=0;i<16;i++) {
  1352. s += abs(pix1[0] - pix2[0]);
  1353. s += abs(pix1[1] - pix2[1]);
  1354. s += abs(pix1[2] - pix2[2]);
  1355. s += abs(pix1[3] - pix2[3]);
  1356. s += abs(pix1[4] - pix2[4]);
  1357. s += abs(pix1[5] - pix2[5]);
  1358. s += abs(pix1[6] - pix2[6]);
  1359. s += abs(pix1[7] - pix2[7]);
  1360. s += abs(pix1[8] - pix2[8]);
  1361. s += abs(pix1[9] - pix2[9]);
  1362. s += abs(pix1[10] - pix2[10]);
  1363. s += abs(pix1[11] - pix2[11]);
  1364. s += abs(pix1[12] - pix2[12]);
  1365. s += abs(pix1[13] - pix2[13]);
  1366. s += abs(pix1[14] - pix2[14]);
  1367. s += abs(pix1[15] - pix2[15]);
  1368. pix1 += line_size;
  1369. pix2 += line_size;
  1370. }
  1371. return s;
  1372. }
  1373. static int pix_abs16x16_x2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1374. {
  1375. int s, i;
  1376. s = 0;
  1377. for(i=0;i<16;i++) {
  1378. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1379. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1380. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1381. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1382. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1383. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1384. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1385. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1386. s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
  1387. s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
  1388. s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
  1389. s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
  1390. s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
  1391. s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
  1392. s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
  1393. s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
  1394. pix1 += line_size;
  1395. pix2 += line_size;
  1396. }
  1397. return s;
  1398. }
  1399. static int pix_abs16x16_y2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1400. {
  1401. int s, i;
  1402. uint8_t *pix3 = pix2 + line_size;
  1403. s = 0;
  1404. for(i=0;i<16;i++) {
  1405. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1406. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1407. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1408. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1409. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1410. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1411. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1412. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1413. s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
  1414. s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
  1415. s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
  1416. s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
  1417. s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
  1418. s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
  1419. s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
  1420. s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
  1421. pix1 += line_size;
  1422. pix2 += line_size;
  1423. pix3 += line_size;
  1424. }
  1425. return s;
  1426. }
  1427. static int pix_abs16x16_xy2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1428. {
  1429. int s, i;
  1430. uint8_t *pix3 = pix2 + line_size;
  1431. s = 0;
  1432. for(i=0;i<16;i++) {
  1433. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1434. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1435. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1436. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1437. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1438. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1439. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1440. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1441. s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
  1442. s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
  1443. s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
  1444. s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
  1445. s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
  1446. s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
  1447. s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
  1448. s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
  1449. pix1 += line_size;
  1450. pix2 += line_size;
  1451. pix3 += line_size;
  1452. }
  1453. return s;
  1454. }
  1455. static inline int pix_abs8x8_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1456. {
  1457. int s, i;
  1458. s = 0;
  1459. for(i=0;i<8;i++) {
  1460. s += abs(pix1[0] - pix2[0]);
  1461. s += abs(pix1[1] - pix2[1]);
  1462. s += abs(pix1[2] - pix2[2]);
  1463. s += abs(pix1[3] - pix2[3]);
  1464. s += abs(pix1[4] - pix2[4]);
  1465. s += abs(pix1[5] - pix2[5]);
  1466. s += abs(pix1[6] - pix2[6]);
  1467. s += abs(pix1[7] - pix2[7]);
  1468. pix1 += line_size;
  1469. pix2 += line_size;
  1470. }
  1471. return s;
  1472. }
  1473. static int pix_abs8x8_x2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1474. {
  1475. int s, i;
  1476. s = 0;
  1477. for(i=0;i<8;i++) {
  1478. s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
  1479. s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
  1480. s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
  1481. s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
  1482. s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
  1483. s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
  1484. s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
  1485. s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
  1486. pix1 += line_size;
  1487. pix2 += line_size;
  1488. }
  1489. return s;
  1490. }
  1491. static int pix_abs8x8_y2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1492. {
  1493. int s, i;
  1494. uint8_t *pix3 = pix2 + line_size;
  1495. s = 0;
  1496. for(i=0;i<8;i++) {
  1497. s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
  1498. s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
  1499. s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
  1500. s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
  1501. s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
  1502. s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
  1503. s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
  1504. s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
  1505. pix1 += line_size;
  1506. pix2 += line_size;
  1507. pix3 += line_size;
  1508. }
  1509. return s;
  1510. }
  1511. static int pix_abs8x8_xy2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
  1512. {
  1513. int s, i;
  1514. uint8_t *pix3 = pix2 + line_size;
  1515. s = 0;
  1516. for(i=0;i<8;i++) {
  1517. s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
  1518. s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
  1519. s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
  1520. s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
  1521. s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
  1522. s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
  1523. s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
  1524. s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
  1525. pix1 += line_size;
  1526. pix2 += line_size;
  1527. pix3 += line_size;
  1528. }
  1529. return s;
  1530. }
  1531. static int sad16x16_c(void *s, uint8_t *a, uint8_t *b, int stride){
  1532. return pix_abs16x16_c(a,b,stride);
  1533. }
  1534. static int sad8x8_c(void *s, uint8_t *a, uint8_t *b, int stride){
  1535. return pix_abs8x8_c(a,b,stride);
  1536. }
  1537. void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
  1538. {
  1539. int i;
  1540. DCTELEM temp[64];
  1541. if(last<=0) return;
  1542. //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
  1543. for(i=0; i<=last; i++){
  1544. const int j= scantable[i];
  1545. temp[j]= block[j];
  1546. block[j]=0;
  1547. }
  1548. for(i=0; i<=last; i++){
  1549. const int j= scantable[i];
  1550. const int perm_j= permutation[j];
  1551. block[perm_j]= temp[j];
  1552. }
  1553. }
  1554. static void clear_blocks_c(DCTELEM *blocks)
  1555. {
  1556. memset(blocks, 0, sizeof(DCTELEM)*6*64);
  1557. }
  1558. static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
  1559. int i;
  1560. for(i=0; i+7<w; i+=8){
  1561. dst[i+0] += src[i+0];
  1562. dst[i+1] += src[i+1];
  1563. dst[i+2] += src[i+2];
  1564. dst[i+3] += src[i+3];
  1565. dst[i+4] += src[i+4];
  1566. dst[i+5] += src[i+5];
  1567. dst[i+6] += src[i+6];
  1568. dst[i+7] += src[i+7];
  1569. }
  1570. for(; i<w; i++)
  1571. dst[i+0] += src[i+0];
  1572. }
  1573. static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
  1574. int i;
  1575. for(i=0; i+7<w; i+=8){
  1576. dst[i+0] = src1[i+0]-src2[i+0];
  1577. dst[i+1] = src1[i+1]-src2[i+1];
  1578. dst[i+2] = src1[i+2]-src2[i+2];
  1579. dst[i+3] = src1[i+3]-src2[i+3];
  1580. dst[i+4] = src1[i+4]-src2[i+4];
  1581. dst[i+5] = src1[i+5]-src2[i+5];
  1582. dst[i+6] = src1[i+6]-src2[i+6];
  1583. dst[i+7] = src1[i+7]-src2[i+7];
  1584. }
  1585. for(; i<w; i++)
  1586. dst[i+0] = src1[i+0]-src2[i+0];
  1587. }
  1588. #define BUTTERFLY2(o1,o2,i1,i2) \
  1589. o1= (i1)+(i2);\
  1590. o2= (i1)-(i2);
  1591. #define BUTTERFLY1(x,y) \
  1592. {\
  1593. int a,b;\
  1594. a= x;\
  1595. b= y;\
  1596. x= a+b;\
  1597. y= a-b;\
  1598. }
  1599. #define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
  1600. static int hadamard8_diff_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride){
  1601. int i;
  1602. int temp[64];
  1603. int sum=0;
  1604. for(i=0; i<8; i++){
  1605. //FIXME try pointer walks
  1606. 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]);
  1607. 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]);
  1608. 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]);
  1609. 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]);
  1610. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1611. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1612. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1613. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1614. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1615. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1616. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1617. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1618. }
  1619. for(i=0; i<8; i++){
  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]);
  1624. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1625. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1626. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1627. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1628. sum +=
  1629. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1630. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1631. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1632. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1633. }
  1634. #if 0
  1635. static int maxi=0;
  1636. if(sum>maxi){
  1637. maxi=sum;
  1638. printf("MAX:%d\n", maxi);
  1639. }
  1640. #endif
  1641. return sum;
  1642. }
  1643. static int hadamard8_abs_c(uint8_t *src, int stride, int mean){
  1644. int i;
  1645. int temp[64];
  1646. int sum=0;
  1647. //FIXME OOOPS ignore 0 term instead of mean mess
  1648. for(i=0; i<8; i++){
  1649. //FIXME try pointer walks
  1650. BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-mean,src[stride*i+1]-mean);
  1651. BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-mean,src[stride*i+3]-mean);
  1652. BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-mean,src[stride*i+5]-mean);
  1653. BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-mean,src[stride*i+7]-mean);
  1654. BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
  1655. BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
  1656. BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
  1657. BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
  1658. BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
  1659. BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
  1660. BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
  1661. BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
  1662. }
  1663. for(i=0; i<8; i++){
  1664. BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
  1665. BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
  1666. BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
  1667. BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
  1668. BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
  1669. BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
  1670. BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
  1671. BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
  1672. sum +=
  1673. BUTTERFLYA(temp[8*0+i], temp[8*4+i])
  1674. +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
  1675. +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
  1676. +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
  1677. }
  1678. return sum;
  1679. }
  1680. static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1681. MpegEncContext * const s= (MpegEncContext *)c;
  1682. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  1683. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  1684. int sum=0, i;
  1685. s->dsp.diff_pixels(temp, src1, src2, stride);
  1686. s->fdct(temp);
  1687. for(i=0; i<64; i++)
  1688. sum+= ABS(temp[i]);
  1689. return sum;
  1690. }
  1691. void simple_idct(DCTELEM *block); //FIXME
  1692. static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1693. MpegEncContext * const s= (MpegEncContext *)c;
  1694. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8];
  1695. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  1696. DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
  1697. int sum=0, i;
  1698. s->mb_intra=0;
  1699. s->dsp.diff_pixels(temp, src1, src2, stride);
  1700. memcpy(bak, temp, 64*sizeof(DCTELEM));
  1701. s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1702. s->dct_unquantize(s, temp, 0, s->qscale);
  1703. simple_idct(temp); //FIXME
  1704. for(i=0; i<64; i++)
  1705. sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
  1706. return sum;
  1707. }
  1708. static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1709. MpegEncContext * const s= (MpegEncContext *)c;
  1710. const uint8_t *scantable= s->intra_scantable.permutated;
  1711. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  1712. uint64_t __align8 aligned_bak[stride];
  1713. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  1714. uint8_t * const bak= (uint8_t*)aligned_bak;
  1715. int i, last, run, bits, level, distoration, start_i;
  1716. const int esc_length= s->ac_esc_length;
  1717. uint8_t * length;
  1718. uint8_t * last_length;
  1719. for(i=0; i<8; i++){
  1720. ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
  1721. ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
  1722. }
  1723. s->dsp.diff_pixels(temp, src1, src2, stride);
  1724. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1725. bits=0;
  1726. if (s->mb_intra) {
  1727. start_i = 1;
  1728. length = s->intra_ac_vlc_length;
  1729. last_length= s->intra_ac_vlc_last_length;
  1730. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  1731. } else {
  1732. start_i = 0;
  1733. length = s->inter_ac_vlc_length;
  1734. last_length= s->inter_ac_vlc_last_length;
  1735. }
  1736. if(last>=start_i){
  1737. run=0;
  1738. for(i=start_i; i<last; i++){
  1739. int j= scantable[i];
  1740. level= temp[j];
  1741. if(level){
  1742. level+=64;
  1743. if((level&(~127)) == 0){
  1744. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  1745. }else
  1746. bits+= esc_length;
  1747. run=0;
  1748. }else
  1749. run++;
  1750. }
  1751. i= scantable[last];
  1752. level= temp[i] + 64;
  1753. assert(level - 64);
  1754. if((level&(~127)) == 0){
  1755. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  1756. }else
  1757. bits+= esc_length;
  1758. }
  1759. if(last>=0){
  1760. s->dct_unquantize(s, temp, 0, s->qscale);
  1761. }
  1762. s->idct_add(bak, stride, temp);
  1763. distoration= s->dsp.sse[1](NULL, bak, src1, stride);
  1764. return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
  1765. }
  1766. static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
  1767. MpegEncContext * const s= (MpegEncContext *)c;
  1768. const uint8_t *scantable= s->intra_scantable.permutated;
  1769. uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
  1770. DCTELEM * const temp= (DCTELEM*)aligned_temp;
  1771. int i, last, run, bits, level, start_i;
  1772. const int esc_length= s->ac_esc_length;
  1773. uint8_t * length;
  1774. uint8_t * last_length;
  1775. s->dsp.diff_pixels(temp, src1, src2, stride);
  1776. s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
  1777. bits=0;
  1778. if (s->mb_intra) {
  1779. start_i = 1;
  1780. length = s->intra_ac_vlc_length;
  1781. last_length= s->intra_ac_vlc_last_length;
  1782. bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
  1783. } else {
  1784. start_i = 0;
  1785. length = s->inter_ac_vlc_length;
  1786. last_length= s->inter_ac_vlc_last_length;
  1787. }
  1788. if(last>=start_i){
  1789. run=0;
  1790. for(i=start_i; i<last; i++){
  1791. int j= scantable[i];
  1792. level= temp[j];
  1793. if(level){
  1794. level+=64;
  1795. if((level&(~127)) == 0){
  1796. bits+= length[UNI_AC_ENC_INDEX(run, level)];
  1797. }else
  1798. bits+= esc_length;
  1799. run=0;
  1800. }else
  1801. run++;
  1802. }
  1803. i= scantable[last];
  1804. level= temp[i] + 64;
  1805. assert(level - 64);
  1806. if((level&(~127)) == 0){
  1807. bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
  1808. }else
  1809. bits+= esc_length;
  1810. }
  1811. return bits;
  1812. }
  1813. WARPER88_1616(hadamard8_diff_c, hadamard8_diff16_c)
  1814. WARPER88_1616(dct_sad8x8_c, dct_sad16x16_c)
  1815. WARPER88_1616(quant_psnr8x8_c, quant_psnr16x16_c)
  1816. WARPER88_1616(rd8x8_c, rd16x16_c)
  1817. WARPER88_1616(bit8x8_c, bit16x16_c)
  1818. void dsputil_init(DSPContext* c, unsigned mask)
  1819. {
  1820. static int init_done = 0;
  1821. int i;
  1822. if (!init_done) {
  1823. for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
  1824. for(i=0;i<MAX_NEG_CROP;i++) {
  1825. cropTbl[i] = 0;
  1826. cropTbl[i + MAX_NEG_CROP + 256] = 255;
  1827. }
  1828. for(i=0;i<512;i++) {
  1829. squareTbl[i] = (i - 256) * (i - 256);
  1830. }
  1831. for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
  1832. init_done = 1;
  1833. }
  1834. c->get_pixels = get_pixels_c;
  1835. c->diff_pixels = diff_pixels_c;
  1836. c->put_pixels_clamped = put_pixels_clamped_c;
  1837. c->add_pixels_clamped = add_pixels_clamped_c;
  1838. c->gmc1 = gmc1_c;
  1839. c->gmc = gmc_c;
  1840. c->clear_blocks = clear_blocks_c;
  1841. c->pix_sum = pix_sum_c;
  1842. c->pix_norm1 = pix_norm1_c;
  1843. c->sse[0]= sse16_c;
  1844. c->sse[1]= sse8_c;
  1845. /* TODO [0] 16 [1] 8 */
  1846. c->pix_abs16x16 = pix_abs16x16_c;
  1847. c->pix_abs16x16_x2 = pix_abs16x16_x2_c;
  1848. c->pix_abs16x16_y2 = pix_abs16x16_y2_c;
  1849. c->pix_abs16x16_xy2 = pix_abs16x16_xy2_c;
  1850. c->pix_abs8x8 = pix_abs8x8_c;
  1851. c->pix_abs8x8_x2 = pix_abs8x8_x2_c;
  1852. c->pix_abs8x8_y2 = pix_abs8x8_y2_c;
  1853. c->pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
  1854. #define dspfunc(PFX, IDX, NUM) \
  1855. c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
  1856. c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
  1857. c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
  1858. c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
  1859. dspfunc(put, 0, 16);
  1860. dspfunc(put_no_rnd, 0, 16);
  1861. dspfunc(put, 1, 8);
  1862. dspfunc(put_no_rnd, 1, 8);
  1863. dspfunc(avg, 0, 16);
  1864. dspfunc(avg_no_rnd, 0, 16);
  1865. dspfunc(avg, 1, 8);
  1866. dspfunc(avg_no_rnd, 1, 8);
  1867. #undef dspfunc
  1868. #define dspfunc(PFX, IDX, NUM) \
  1869. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  1870. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  1871. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  1872. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  1873. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  1874. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  1875. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  1876. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  1877. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  1878. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  1879. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  1880. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  1881. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  1882. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  1883. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  1884. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  1885. dspfunc(put_qpel, 0, 16);
  1886. dspfunc(put_no_rnd_qpel, 0, 16);
  1887. dspfunc(avg_qpel, 0, 16);
  1888. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  1889. dspfunc(put_qpel, 1, 8);
  1890. dspfunc(put_no_rnd_qpel, 1, 8);
  1891. dspfunc(avg_qpel, 1, 8);
  1892. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  1893. #undef dspfunc
  1894. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  1895. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  1896. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  1897. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  1898. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  1899. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  1900. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  1901. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  1902. c->hadamard8_diff[0]= hadamard8_diff16_c;
  1903. c->hadamard8_diff[1]= hadamard8_diff_c;
  1904. c->hadamard8_abs = hadamard8_abs_c;
  1905. c->dct_sad[0]= dct_sad16x16_c;
  1906. c->dct_sad[1]= dct_sad8x8_c;
  1907. c->sad[0]= sad16x16_c;
  1908. c->sad[1]= sad8x8_c;
  1909. c->quant_psnr[0]= quant_psnr16x16_c;
  1910. c->quant_psnr[1]= quant_psnr8x8_c;
  1911. c->rd[0]= rd16x16_c;
  1912. c->rd[1]= rd8x8_c;
  1913. c->bit[0]= bit16x16_c;
  1914. c->bit[1]= bit8x8_c;
  1915. c->add_bytes= add_bytes_c;
  1916. c->diff_bytes= diff_bytes_c;
  1917. #ifdef HAVE_MMX
  1918. dsputil_init_mmx(c, mask);
  1919. if (ff_bit_exact)
  1920. {
  1921. /* FIXME - AVCodec context should have flag for bitexact match */
  1922. /* fprintf(stderr, "\n\n\nff_bit_exact %d\n\n\n\n", ff_bit_exact); */
  1923. dsputil_set_bit_exact_mmx(c, mask);
  1924. }
  1925. #endif
  1926. #ifdef ARCH_ARMV4L
  1927. dsputil_init_armv4l(c, mask);
  1928. #endif
  1929. #ifdef HAVE_MLIB
  1930. dsputil_init_mlib(c, mask);
  1931. #endif
  1932. #ifdef ARCH_ALPHA
  1933. dsputil_init_alpha(c, mask);
  1934. #endif
  1935. #ifdef ARCH_POWERPC
  1936. dsputil_init_ppc(c, mask);
  1937. #endif
  1938. #ifdef HAVE_MMI
  1939. dsputil_init_mmi(c, mask);
  1940. #endif
  1941. }
  1942. /* remove any non bit exact operation (testing purpose) */
  1943. void avcodec_set_bit_exact(void)
  1944. {
  1945. ff_bit_exact=1;
  1946. #ifdef HAVE_MMX
  1947. // FIXME - better set_bit_exact
  1948. // dsputil_set_bit_exact_mmx();
  1949. #endif
  1950. }