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.

271 lines
11KB

  1. /*
  2. * RV40 decoder motion compensation functions x86-optimised
  3. * Copyright (c) 2008 Konstantin Shishkov
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * RV40 decoder motion compensation functions x86-optimised
  24. * 2,0 and 0,2 have h264 equivalents.
  25. * 3,3 is bugged in the rv40 format and maps to _xy2 version
  26. */
  27. #include "libavcodec/rv34dsp.h"
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/mem.h"
  30. #include "libavutil/x86/cpu.h"
  31. #include "hpeldsp.h"
  32. #if HAVE_X86ASM
  33. void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src,
  34. ptrdiff_t stride, int h, int x, int y);
  35. void ff_avg_rv40_chroma_mc8_mmxext(uint8_t *dst, uint8_t *src,
  36. ptrdiff_t stride, int h, int x, int y);
  37. void ff_avg_rv40_chroma_mc8_3dnow(uint8_t *dst, uint8_t *src,
  38. ptrdiff_t stride, int h, int x, int y);
  39. void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  40. ptrdiff_t stride, int h, int x, int y);
  41. void ff_avg_rv40_chroma_mc4_mmxext(uint8_t *dst, uint8_t *src,
  42. ptrdiff_t stride, int h, int x, int y);
  43. void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src,
  44. ptrdiff_t stride, int h, int x, int y);
  45. #define DECLARE_WEIGHT(opt) \
  46. void ff_rv40_weight_func_rnd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  47. int w1, int w2, ptrdiff_t stride); \
  48. void ff_rv40_weight_func_rnd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  49. int w1, int w2, ptrdiff_t stride); \
  50. void ff_rv40_weight_func_nornd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  51. int w1, int w2, ptrdiff_t stride); \
  52. void ff_rv40_weight_func_nornd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  53. int w1, int w2, ptrdiff_t stride);
  54. DECLARE_WEIGHT(mmxext)
  55. DECLARE_WEIGHT(sse2)
  56. DECLARE_WEIGHT(ssse3)
  57. /** @{ */
  58. /**
  59. * Define one qpel function.
  60. * LOOPSIZE must be already set to the number of pixels processed per
  61. * iteration in the inner loop of the called functions.
  62. * COFF(x) must be already defined so as to provide the offset into any
  63. * array of coeffs used by the called function for the qpel position x.
  64. */
  65. #define QPEL_FUNC_DECL(OP, SIZE, PH, PV, OPT) \
  66. static void OP ## rv40_qpel ##SIZE ##_mc ##PH ##PV ##OPT(uint8_t *dst, \
  67. const uint8_t *src, \
  68. ptrdiff_t stride) \
  69. { \
  70. int i; \
  71. if (PH && PV) { \
  72. DECLARE_ALIGNED(16, uint8_t, tmp)[SIZE * (SIZE + 5)]; \
  73. uint8_t *tmpptr = tmp + SIZE * 2; \
  74. src -= stride * 2; \
  75. \
  76. for (i = 0; i < SIZE; i += LOOPSIZE) \
  77. ff_put_rv40_qpel_h ##OPT(tmp + i, SIZE, src + i, stride, \
  78. SIZE + 5, HCOFF(PH)); \
  79. for (i = 0; i < SIZE; i += LOOPSIZE) \
  80. ff_ ##OP ##rv40_qpel_v ##OPT(dst + i, stride, tmpptr + i, \
  81. SIZE, SIZE, VCOFF(PV)); \
  82. } else if (PV) { \
  83. for (i = 0; i < SIZE; i += LOOPSIZE) \
  84. ff_ ##OP ##rv40_qpel_v ## OPT(dst + i, stride, src + i, \
  85. stride, SIZE, VCOFF(PV)); \
  86. } else { \
  87. for (i = 0; i < SIZE; i += LOOPSIZE) \
  88. ff_ ##OP ##rv40_qpel_h ## OPT(dst + i, stride, src + i, \
  89. stride, SIZE, HCOFF(PH)); \
  90. } \
  91. }
  92. /** Declare functions for sizes 8 and 16 and given operations
  93. * and qpel position. */
  94. #define QPEL_FUNCS_DECL(OP, PH, PV, OPT) \
  95. QPEL_FUNC_DECL(OP, 8, PH, PV, OPT) \
  96. QPEL_FUNC_DECL(OP, 16, PH, PV, OPT)
  97. /** Declare all functions for all sizes and qpel positions */
  98. #define QPEL_MC_DECL(OP, OPT) \
  99. void ff_ ##OP ##rv40_qpel_h ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
  100. const uint8_t *src, \
  101. ptrdiff_t srcStride, \
  102. int len, int m); \
  103. void ff_ ##OP ##rv40_qpel_v ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
  104. const uint8_t *src, \
  105. ptrdiff_t srcStride, \
  106. int len, int m); \
  107. QPEL_FUNCS_DECL(OP, 0, 1, OPT) \
  108. QPEL_FUNCS_DECL(OP, 0, 3, OPT) \
  109. QPEL_FUNCS_DECL(OP, 1, 0, OPT) \
  110. QPEL_FUNCS_DECL(OP, 1, 1, OPT) \
  111. QPEL_FUNCS_DECL(OP, 1, 2, OPT) \
  112. QPEL_FUNCS_DECL(OP, 1, 3, OPT) \
  113. QPEL_FUNCS_DECL(OP, 2, 1, OPT) \
  114. QPEL_FUNCS_DECL(OP, 2, 2, OPT) \
  115. QPEL_FUNCS_DECL(OP, 2, 3, OPT) \
  116. QPEL_FUNCS_DECL(OP, 3, 0, OPT) \
  117. QPEL_FUNCS_DECL(OP, 3, 1, OPT) \
  118. QPEL_FUNCS_DECL(OP, 3, 2, OPT)
  119. /** @} */
  120. #define LOOPSIZE 8
  121. #define HCOFF(x) (32 * (x - 1))
  122. #define VCOFF(x) (32 * (x - 1))
  123. QPEL_MC_DECL(put_, _ssse3)
  124. QPEL_MC_DECL(avg_, _ssse3)
  125. #undef LOOPSIZE
  126. #undef HCOFF
  127. #undef VCOFF
  128. #define LOOPSIZE 8
  129. #define HCOFF(x) (64 * (x - 1))
  130. #define VCOFF(x) (64 * (x - 1))
  131. QPEL_MC_DECL(put_, _sse2)
  132. QPEL_MC_DECL(avg_, _sse2)
  133. #if ARCH_X86_32
  134. #undef LOOPSIZE
  135. #undef HCOFF
  136. #undef VCOFF
  137. #define LOOPSIZE 4
  138. #define HCOFF(x) (64 * (x - 1))
  139. #define VCOFF(x) (64 * (x - 1))
  140. QPEL_MC_DECL(put_, _mmx)
  141. #define ff_put_rv40_qpel_h_mmxext ff_put_rv40_qpel_h_mmx
  142. #define ff_put_rv40_qpel_v_mmxext ff_put_rv40_qpel_v_mmx
  143. QPEL_MC_DECL(avg_, _mmxext)
  144. #define ff_put_rv40_qpel_h_3dnow ff_put_rv40_qpel_h_mmx
  145. #define ff_put_rv40_qpel_v_3dnow ff_put_rv40_qpel_v_mmx
  146. QPEL_MC_DECL(avg_, _3dnow)
  147. #endif
  148. /** @{ */
  149. /** Set one function */
  150. #define QPEL_FUNC_SET(OP, SIZE, PH, PV, OPT) \
  151. c-> OP ## pixels_tab[2 - SIZE / 8][4 * PV + PH] = OP ## rv40_qpel ##SIZE ## _mc ##PH ##PV ##OPT;
  152. /** Set functions put and avg for sizes 8 and 16 and a given qpel position */
  153. #define QPEL_FUNCS_SET(OP, PH, PV, OPT) \
  154. QPEL_FUNC_SET(OP, 8, PH, PV, OPT) \
  155. QPEL_FUNC_SET(OP, 16, PH, PV, OPT)
  156. /** Set all functions for all sizes and qpel positions */
  157. #define QPEL_MC_SET(OP, OPT) \
  158. QPEL_FUNCS_SET (OP, 0, 1, OPT) \
  159. QPEL_FUNCS_SET (OP, 0, 3, OPT) \
  160. QPEL_FUNCS_SET (OP, 1, 0, OPT) \
  161. QPEL_FUNCS_SET (OP, 1, 1, OPT) \
  162. QPEL_FUNCS_SET (OP, 1, 2, OPT) \
  163. QPEL_FUNCS_SET (OP, 1, 3, OPT) \
  164. QPEL_FUNCS_SET (OP, 2, 1, OPT) \
  165. QPEL_FUNCS_SET (OP, 2, 2, OPT) \
  166. QPEL_FUNCS_SET (OP, 2, 3, OPT) \
  167. QPEL_FUNCS_SET (OP, 3, 0, OPT) \
  168. QPEL_FUNCS_SET (OP, 3, 1, OPT) \
  169. QPEL_FUNCS_SET (OP, 3, 2, OPT)
  170. /** @} */
  171. #endif /* HAVE_X86ASM */
  172. #if HAVE_MMX_INLINE
  173. static void put_rv40_qpel8_mc33_mmx(uint8_t *dst, const uint8_t *src,
  174. ptrdiff_t stride)
  175. {
  176. ff_put_pixels8_xy2_mmx(dst, src, stride, 8);
  177. }
  178. static void put_rv40_qpel16_mc33_mmx(uint8_t *dst, const uint8_t *src,
  179. ptrdiff_t stride)
  180. {
  181. ff_put_pixels16_xy2_mmx(dst, src, stride, 16);
  182. }
  183. static void avg_rv40_qpel8_mc33_mmx(uint8_t *dst, const uint8_t *src,
  184. ptrdiff_t stride)
  185. {
  186. ff_avg_pixels8_xy2_mmx(dst, src, stride, 8);
  187. }
  188. static void avg_rv40_qpel16_mc33_mmx(uint8_t *dst, const uint8_t *src,
  189. ptrdiff_t stride)
  190. {
  191. ff_avg_pixels16_xy2_mmx(dst, src, stride, 16);
  192. }
  193. #endif /* HAVE_MMX_INLINE */
  194. av_cold void ff_rv40dsp_init_x86(RV34DSPContext *c)
  195. {
  196. int cpu_flags = av_get_cpu_flags();
  197. #if HAVE_MMX_INLINE
  198. if (INLINE_MMX(cpu_flags)) {
  199. c->put_pixels_tab[0][15] = put_rv40_qpel16_mc33_mmx;
  200. c->put_pixels_tab[1][15] = put_rv40_qpel8_mc33_mmx;
  201. c->avg_pixels_tab[0][15] = avg_rv40_qpel16_mc33_mmx;
  202. c->avg_pixels_tab[1][15] = avg_rv40_qpel8_mc33_mmx;
  203. }
  204. #endif /* HAVE_MMX_INLINE */
  205. #if HAVE_X86ASM
  206. if (EXTERNAL_MMX(cpu_flags)) {
  207. c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx;
  208. c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx;
  209. #if ARCH_X86_32
  210. QPEL_MC_SET(put_, _mmx)
  211. #endif
  212. }
  213. if (EXTERNAL_AMD3DNOW(cpu_flags)) {
  214. c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow;
  215. c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow;
  216. #if ARCH_X86_32
  217. QPEL_MC_SET(avg_, _3dnow)
  218. #endif
  219. }
  220. if (EXTERNAL_MMXEXT(cpu_flags)) {
  221. c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmxext;
  222. c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmxext;
  223. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_mmxext;
  224. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_mmxext;
  225. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_mmxext;
  226. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_mmxext;
  227. #if ARCH_X86_32
  228. QPEL_MC_SET(avg_, _mmxext)
  229. #endif
  230. }
  231. if (EXTERNAL_SSE2(cpu_flags)) {
  232. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_sse2;
  233. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_sse2;
  234. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_sse2;
  235. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_sse2;
  236. QPEL_MC_SET(put_, _sse2)
  237. QPEL_MC_SET(avg_, _sse2)
  238. }
  239. if (EXTERNAL_SSSE3(cpu_flags)) {
  240. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_ssse3;
  241. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_ssse3;
  242. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_ssse3;
  243. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_ssse3;
  244. QPEL_MC_SET(put_, _ssse3)
  245. QPEL_MC_SET(avg_, _ssse3)
  246. }
  247. #endif /* HAVE_X86ASM */
  248. }