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.

429 lines
12KB

  1. /*
  2. * aligned/packed access motion
  3. *
  4. * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include "../avcodec.h"
  21. #include "../dsputil.h"
  22. #define LP(p) *(uint32_t*)(p)
  23. #define UNPACK(ph,pl,tt0,tt1) do { \
  24. uint32_t t0,t1; t0=tt0;t1=tt1; \
  25. ph = ( (t0 & ~BYTE_VEC32(0x03))>>2) + ( (t1 & ~BYTE_VEC32(0x03))>>2); \
  26. pl = (t0 & BYTE_VEC32(0x03)) + (t1 & BYTE_VEC32(0x03)); } while(0)
  27. #define rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x02))>>2) & BYTE_VEC32(0x03))
  28. #define no_rnd_PACK(ph,pl,nph,npl) ph + nph + (((pl + npl + BYTE_VEC32(0x01))>>2) & BYTE_VEC32(0x03))
  29. /* little endian */
  30. #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)>>(8*ofs))|((b)<<(32-8*ofs)) )
  31. #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)>>(8*(ofs+1)))|((b)<<(32-8*(ofs+1))) )
  32. /* big
  33. #define MERGE1(a,b,ofs) (ofs==0)?a:( ((a)<<(8*ofs))|((b)>>(32-8*ofs)) )
  34. #define MERGE2(a,b,ofs) (ofs==3)?b:( ((a)<<(8+8*ofs))|((b)>>(32-8-8*ofs)) )
  35. */
  36. #define put(d,s) d = s
  37. #define avg(d,s) d = rnd_avg32(s,d)
  38. #define OP_C4(ofs) \
  39. ref-=ofs; \
  40. do { \
  41. OP(LP(dest),MERGE1(LP(ref),LP(ref+4),ofs)); \
  42. ref+=stride; \
  43. dest+=stride; \
  44. } while(--height)
  45. #define OP_C40() \
  46. do { \
  47. OP(LP(dest),LP(ref)); \
  48. ref+=stride; \
  49. dest+=stride; \
  50. } while(--height)
  51. #define OP put
  52. static void put_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
  53. {
  54. switch((int)ref&3){
  55. case 0: OP_C40(); return;
  56. case 1: OP_C4(1); return;
  57. case 2: OP_C4(2); return;
  58. case 3: OP_C4(3); return;
  59. }
  60. }
  61. #undef OP
  62. #define OP avg
  63. static void avg_pixels4_c(uint8_t *dest,const uint8_t *ref, const int stride,int height)
  64. {
  65. switch((int)ref&3){
  66. case 0: OP_C40(); return;
  67. case 1: OP_C4(1); return;
  68. case 2: OP_C4(2); return;
  69. case 3: OP_C4(3); return;
  70. }
  71. }
  72. #undef OP
  73. #define OP_C(ofs,sz,avg2) \
  74. { \
  75. ref-=ofs; \
  76. do { \
  77. uint32_t t0,t1; \
  78. t0 = LP(ref+0); \
  79. t1 = LP(ref+4); \
  80. OP(LP(dest+0), MERGE1(t0,t1,ofs)); \
  81. t0 = LP(ref+8); \
  82. OP(LP(dest+4), MERGE1(t1,t0,ofs)); \
  83. if (sz==16) { \
  84. t1 = LP(ref+12); \
  85. OP(LP(dest+8), MERGE1(t0,t1,ofs)); \
  86. t0 = LP(ref+16); \
  87. OP(LP(dest+12), MERGE1(t1,t0,ofs)); \
  88. } \
  89. ref+=stride; \
  90. dest+= stride; \
  91. } while(--height); \
  92. }
  93. /* aligned */
  94. #define OP_C0(sz,avg2) \
  95. { \
  96. do { \
  97. OP(LP(dest+0), LP(ref+0)); \
  98. OP(LP(dest+4), LP(ref+4)); \
  99. if (sz==16) { \
  100. OP(LP(dest+8), LP(ref+8)); \
  101. OP(LP(dest+12), LP(ref+12)); \
  102. } \
  103. ref+=stride; \
  104. dest+= stride; \
  105. } while(--height); \
  106. }
  107. #define OP_X(ofs,sz,avg2) \
  108. { \
  109. ref-=ofs; \
  110. do { \
  111. uint32_t t0,t1; \
  112. t0 = LP(ref+0); \
  113. t1 = LP(ref+4); \
  114. OP(LP(dest+0), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
  115. t0 = LP(ref+8); \
  116. OP(LP(dest+4), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
  117. if (sz==16) { \
  118. t1 = LP(ref+12); \
  119. OP(LP(dest+8), avg2(MERGE1(t0,t1,ofs),MERGE2(t0,t1,ofs))); \
  120. t0 = LP(ref+16); \
  121. OP(LP(dest+12), avg2(MERGE1(t1,t0,ofs),MERGE2(t1,t0,ofs))); \
  122. } \
  123. ref+=stride; \
  124. dest+= stride; \
  125. } while(--height); \
  126. }
  127. /* aligned */
  128. #define OP_Y0(sz,avg2) \
  129. { \
  130. uint32_t t0,t1,t2,t3,t; \
  131. \
  132. t0 = LP(ref+0); \
  133. t1 = LP(ref+4); \
  134. if (sz==16) { \
  135. t2 = LP(ref+8); \
  136. t3 = LP(ref+12); \
  137. } \
  138. do { \
  139. ref += stride; \
  140. \
  141. t = LP(ref+0); \
  142. OP(LP(dest+0), avg2(t0,t)); t0 = t; \
  143. t = LP(ref+4); \
  144. OP(LP(dest+4), avg2(t1,t)); t1 = t; \
  145. if (sz==16) { \
  146. t = LP(ref+8); \
  147. OP(LP(dest+8), avg2(t2,t)); t2 = t; \
  148. t = LP(ref+12); \
  149. OP(LP(dest+12), avg2(t3,t)); t3 = t; \
  150. } \
  151. dest+= stride; \
  152. } while(--height); \
  153. }
  154. #define OP_Y(ofs,sz,avg2) \
  155. { \
  156. uint32_t t0,t1,t2,t3,t,w0,w1; \
  157. \
  158. ref-=ofs; \
  159. w0 = LP(ref+0); \
  160. w1 = LP(ref+4); \
  161. t0 = MERGE1(w0,w1,ofs); \
  162. w0 = LP(ref+8); \
  163. t1 = MERGE1(w1,w0,ofs); \
  164. if (sz==16) { \
  165. w1 = LP(ref+12); \
  166. t2 = MERGE1(w0,w1,ofs); \
  167. w0 = LP(ref+16); \
  168. t3 = MERGE1(w1,w0,ofs); \
  169. } \
  170. do { \
  171. ref += stride; \
  172. \
  173. w0 = LP(ref+0); \
  174. w1 = LP(ref+4); \
  175. t = MERGE1(w0,w1,ofs); \
  176. OP(LP(dest+0), avg2(t0,t)); t0 = t; \
  177. w0 = LP(ref+8); \
  178. t = MERGE1(w1,w0,ofs); \
  179. OP(LP(dest+4), avg2(t1,t)); t1 = t; \
  180. if (sz==16) { \
  181. w1 = LP(ref+12); \
  182. t = MERGE1(w0,w1,ofs); \
  183. OP(LP(dest+8), avg2(t2,t)); t2 = t; \
  184. w0 = LP(ref+16); \
  185. t = MERGE1(w1,w0,ofs); \
  186. OP(LP(dest+12), avg2(t3,t)); t3 = t; \
  187. } \
  188. dest+=stride; \
  189. } while(--height); \
  190. }
  191. #define OP_X0(sz,avg2) OP_X(0,sz,avg2)
  192. #define OP_XY0(sz,PACK) OP_XY(0,sz,PACK)
  193. #define OP_XY(ofs,sz,PACK) \
  194. { \
  195. uint32_t t2,t3,w0,w1; \
  196. uint32_t a0,a1,a2,a3,a4,a5,a6,a7; \
  197. \
  198. ref -= ofs; \
  199. w0 = LP(ref+0); \
  200. w1 = LP(ref+4); \
  201. UNPACK(a0,a1,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
  202. w0 = LP(ref+8); \
  203. UNPACK(a2,a3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
  204. if (sz==16) { \
  205. w1 = LP(ref+12); \
  206. UNPACK(a4,a5,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
  207. w0 = LP(ref+16); \
  208. UNPACK(a6,a7,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
  209. } \
  210. do { \
  211. ref+=stride; \
  212. w0 = LP(ref+0); \
  213. w1 = LP(ref+4); \
  214. UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
  215. OP(LP(dest+0),PACK(a0,a1,t2,t3)); \
  216. a0 = t2; a1 = t3; \
  217. w0 = LP(ref+8); \
  218. UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
  219. OP(LP(dest+4),PACK(a2,a3,t2,t3)); \
  220. a2 = t2; a3 = t3; \
  221. if (sz==16) { \
  222. w1 = LP(ref+12); \
  223. UNPACK(t2,t3,MERGE1(w0,w1,ofs),MERGE2(w0,w1,ofs)); \
  224. OP(LP(dest+8),PACK(a4,a5,t2,t3)); \
  225. a4 = t2; a5 = t3; \
  226. w0 = LP(ref+16); \
  227. UNPACK(t2,t3,MERGE1(w1,w0,ofs),MERGE2(w1,w0,ofs)); \
  228. OP(LP(dest+12),PACK(a6,a7,t2,t3)); \
  229. a6 = t2; a7 = t3; \
  230. } \
  231. dest+=stride; \
  232. } while(--height); \
  233. }
  234. #define DEFFUNC(op,rnd,xy,sz,OP_N,avgfunc) \
  235. static void op##_##rnd##_pixels##sz##_##xy (uint8_t * dest, const uint8_t * ref, \
  236. const int stride, int height) \
  237. { \
  238. switch((int)ref&3) { \
  239. case 0:OP_N##0(sz,rnd##_##avgfunc); return; \
  240. case 1:OP_N(1,sz,rnd##_##avgfunc); return; \
  241. case 2:OP_N(2,sz,rnd##_##avgfunc); return; \
  242. case 3:OP_N(3,sz,rnd##_##avgfunc); return; \
  243. } \
  244. }
  245. #define OP put
  246. DEFFUNC(put, rnd,o,8,OP_C,avg2)
  247. DEFFUNC(put, rnd,x,8,OP_X,avg2)
  248. DEFFUNC(put,no_rnd,x,8,OP_X,avg2)
  249. DEFFUNC(put, rnd,y,8,OP_Y,avg2)
  250. DEFFUNC(put,no_rnd,y,8,OP_Y,avg2)
  251. DEFFUNC(put, rnd,xy,8,OP_XY,PACK)
  252. DEFFUNC(put,no_rnd,xy,8,OP_XY,PACK)
  253. DEFFUNC(put, rnd,o,16,OP_C,avg2)
  254. DEFFUNC(put, rnd,x,16,OP_X,avg2)
  255. DEFFUNC(put,no_rnd,x,16,OP_X,avg2)
  256. DEFFUNC(put, rnd,y,16,OP_Y,avg2)
  257. DEFFUNC(put,no_rnd,y,16,OP_Y,avg2)
  258. DEFFUNC(put, rnd,xy,16,OP_XY,PACK)
  259. DEFFUNC(put,no_rnd,xy,16,OP_XY,PACK)
  260. #undef OP
  261. #define OP avg
  262. DEFFUNC(avg, rnd,o,8,OP_C,avg2)
  263. DEFFUNC(avg, rnd,x,8,OP_X,avg2)
  264. DEFFUNC(avg,no_rnd,x,8,OP_X,avg2)
  265. DEFFUNC(avg, rnd,y,8,OP_Y,avg2)
  266. DEFFUNC(avg,no_rnd,y,8,OP_Y,avg2)
  267. DEFFUNC(avg, rnd,xy,8,OP_XY,PACK)
  268. DEFFUNC(avg,no_rnd,xy,8,OP_XY,PACK)
  269. DEFFUNC(avg, rnd,o,16,OP_C,avg2)
  270. DEFFUNC(avg, rnd,x,16,OP_X,avg2)
  271. DEFFUNC(avg,no_rnd,x,16,OP_X,avg2)
  272. DEFFUNC(avg, rnd,y,16,OP_Y,avg2)
  273. DEFFUNC(avg,no_rnd,y,16,OP_Y,avg2)
  274. DEFFUNC(avg, rnd,xy,16,OP_XY,PACK)
  275. DEFFUNC(avg,no_rnd,xy,16,OP_XY,PACK)
  276. #undef OP
  277. #define put_no_rnd_pixels8_o put_rnd_pixels8_o
  278. #define put_no_rnd_pixels16_o put_rnd_pixels16_o
  279. #define avg_no_rnd_pixels8_o avg_rnd_pixels8_o
  280. #define avg_no_rnd_pixels16_o avg_rnd_pixels16_o
  281. #define put_pixels8_c put_rnd_pixels8_o
  282. #define put_pixels16_c put_rnd_pixels16_o
  283. #define avg_pixels8_c avg_rnd_pixels8_o
  284. #define avg_pixels16_c avg_rnd_pixels16_o
  285. #define put_no_rnd_pixels8_c put_rnd_pixels8_o
  286. #define put_no_rnd_pixels16_c put_rnd_pixels16_o
  287. #define avg_no_rnd_pixels8_c avg_rnd_pixels8_o
  288. #define avg_no_rnd_pixels16_c avg_rnd_pixels16_o
  289. #define QPEL
  290. #ifdef QPEL
  291. #include "qpel.c"
  292. #endif
  293. void dsputil_init_align(DSPContext* c, AVCodecContext *avctx)
  294. {
  295. c->put_pixels_tab[0][0] = put_rnd_pixels16_o;
  296. c->put_pixels_tab[0][1] = put_rnd_pixels16_x;
  297. c->put_pixels_tab[0][2] = put_rnd_pixels16_y;
  298. c->put_pixels_tab[0][3] = put_rnd_pixels16_xy;
  299. c->put_pixels_tab[1][0] = put_rnd_pixels8_o;
  300. c->put_pixels_tab[1][1] = put_rnd_pixels8_x;
  301. c->put_pixels_tab[1][2] = put_rnd_pixels8_y;
  302. c->put_pixels_tab[1][3] = put_rnd_pixels8_xy;
  303. c->put_no_rnd_pixels_tab[0][0] = put_no_rnd_pixels16_o;
  304. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x;
  305. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y;
  306. c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy;
  307. c->put_no_rnd_pixels_tab[1][0] = put_no_rnd_pixels8_o;
  308. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x;
  309. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y;
  310. c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy;
  311. c->avg_pixels_tab[0][0] = avg_rnd_pixels16_o;
  312. c->avg_pixels_tab[0][1] = avg_rnd_pixels16_x;
  313. c->avg_pixels_tab[0][2] = avg_rnd_pixels16_y;
  314. c->avg_pixels_tab[0][3] = avg_rnd_pixels16_xy;
  315. c->avg_pixels_tab[1][0] = avg_rnd_pixels8_o;
  316. c->avg_pixels_tab[1][1] = avg_rnd_pixels8_x;
  317. c->avg_pixels_tab[1][2] = avg_rnd_pixels8_y;
  318. c->avg_pixels_tab[1][3] = avg_rnd_pixels8_xy;
  319. c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_o;
  320. c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x;
  321. c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y;
  322. c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy;
  323. c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_o;
  324. c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x;
  325. c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y;
  326. c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy;
  327. #ifdef QPEL
  328. #define dspfunc(PFX, IDX, NUM) \
  329. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
  330. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
  331. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
  332. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
  333. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
  334. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
  335. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
  336. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
  337. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
  338. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
  339. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
  340. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
  341. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
  342. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
  343. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
  344. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
  345. dspfunc(put_qpel, 0, 16);
  346. dspfunc(put_no_rnd_qpel, 0, 16);
  347. dspfunc(avg_qpel, 0, 16);
  348. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  349. dspfunc(put_qpel, 1, 8);
  350. dspfunc(put_no_rnd_qpel, 1, 8);
  351. dspfunc(avg_qpel, 1, 8);
  352. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  353. dspfunc(put_h264_qpel, 0, 16);
  354. dspfunc(put_h264_qpel, 1, 8);
  355. dspfunc(put_h264_qpel, 2, 4);
  356. dspfunc(avg_h264_qpel, 0, 16);
  357. dspfunc(avg_h264_qpel, 1, 8);
  358. dspfunc(avg_h264_qpel, 2, 4);
  359. #undef dspfunc
  360. c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
  361. c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
  362. c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
  363. c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
  364. c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
  365. c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
  366. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
  367. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
  368. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
  369. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
  370. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
  371. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
  372. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
  373. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
  374. c->gmc1 = gmc1_c;
  375. c->gmc = gmc_c;
  376. #endif
  377. }