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.

387 lines
13KB

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