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.

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