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.

299 lines
9.7KB

  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 put_pixels8_c ff_put_rnd_pixels8_o
  219. #define put_pixels16_c ff_put_rnd_pixels16_o
  220. #define avg_pixels8_c ff_avg_rnd_pixels8_o
  221. #define avg_pixels16_c ff_avg_rnd_pixels16_o
  222. #define put_no_rnd_pixels8_c ff_put_rnd_pixels8_o
  223. #define put_no_rnd_pixels16_c ff_put_rnd_pixels16_o
  224. #define avg_no_rnd_pixels16_c ff_avg_rnd_pixels16_o
  225. #if CONFIG_HPELDSP
  226. #include "qpel.c"
  227. #endif
  228. av_cold void ff_dsputil_init_align(DSPContext *c, AVCodecContext *avctx)
  229. {
  230. #if CONFIG_HPELDSP
  231. #define dspfunc(PFX, IDX, NUM) \
  232. c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_sh4; \
  233. c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_sh4; \
  234. c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_sh4; \
  235. c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_sh4; \
  236. c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_sh4; \
  237. c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_sh4; \
  238. c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_sh4; \
  239. c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_sh4; \
  240. c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_sh4; \
  241. c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_sh4; \
  242. c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_sh4; \
  243. c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_sh4; \
  244. c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_sh4; \
  245. c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_sh4; \
  246. c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_sh4; \
  247. c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_sh4
  248. dspfunc(put_qpel, 0, 16);
  249. dspfunc(put_no_rnd_qpel, 0, 16);
  250. dspfunc(avg_qpel, 0, 16);
  251. /* dspfunc(avg_no_rnd_qpel, 0, 16); */
  252. dspfunc(put_qpel, 1, 8);
  253. dspfunc(put_no_rnd_qpel, 1, 8);
  254. dspfunc(avg_qpel, 1, 8);
  255. /* dspfunc(avg_no_rnd_qpel, 1, 8); */
  256. #undef dspfunc
  257. c->put_mspel_pixels_tab[0]= put_mspel8_mc00_sh4;
  258. c->put_mspel_pixels_tab[1]= put_mspel8_mc10_sh4;
  259. c->put_mspel_pixels_tab[2]= put_mspel8_mc20_sh4;
  260. c->put_mspel_pixels_tab[3]= put_mspel8_mc30_sh4;
  261. c->put_mspel_pixels_tab[4]= put_mspel8_mc02_sh4;
  262. c->put_mspel_pixels_tab[5]= put_mspel8_mc12_sh4;
  263. c->put_mspel_pixels_tab[6]= put_mspel8_mc22_sh4;
  264. c->put_mspel_pixels_tab[7]= put_mspel8_mc32_sh4;
  265. c->gmc1 = gmc1_c;
  266. #endif
  267. }