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.

243 lines
10KB

  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/mem.h"
  29. #include "libavutil/x86/cpu.h"
  30. #include "dsputil_mmx.h"
  31. #if HAVE_YASM
  32. void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src,
  33. int stride, int h, int x, int y);
  34. void ff_avg_rv40_chroma_mc8_mmx2 (uint8_t *dst, uint8_t *src,
  35. int stride, int h, int x, int y);
  36. void ff_avg_rv40_chroma_mc8_3dnow(uint8_t *dst, uint8_t *src,
  37. int stride, int h, int x, int y);
  38. void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src,
  39. int stride, int h, int x, int y);
  40. void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src,
  41. int stride, int h, int x, int y);
  42. void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src,
  43. int stride, int h, int x, int y);
  44. #define DECLARE_WEIGHT(opt) \
  45. void ff_rv40_weight_func_rnd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  46. int w1, int w2, ptrdiff_t stride); \
  47. void ff_rv40_weight_func_rnd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  48. int w1, int w2, ptrdiff_t stride); \
  49. void ff_rv40_weight_func_nornd_16_##opt(uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  50. int w1, int w2, ptrdiff_t stride); \
  51. void ff_rv40_weight_func_nornd_8_##opt (uint8_t *dst, uint8_t *src1, uint8_t *src2, \
  52. int w1, int w2, ptrdiff_t stride);
  53. DECLARE_WEIGHT(mmx2)
  54. DECLARE_WEIGHT(sse2)
  55. DECLARE_WEIGHT(ssse3)
  56. /** @{ */
  57. /**
  58. * Define one qpel function.
  59. * LOOPSIZE must be already set to the number of pixels processed per
  60. * iteration in the inner loop of the called functions.
  61. * COFF(x) must be already defined so as to provide the offset into any
  62. * array of coeffs used by the called function for the qpel position x.
  63. */
  64. #define QPEL_FUNC_DECL(OP, SIZE, PH, PV, OPT) \
  65. static void OP ## rv40_qpel ##SIZE ##_mc ##PH ##PV ##OPT(uint8_t *dst, \
  66. uint8_t *src, \
  67. int stride) \
  68. { \
  69. int i; \
  70. if (PH && PV) { \
  71. DECLARE_ALIGNED(16, uint8_t, tmp)[SIZE * (SIZE + 5)]; \
  72. uint8_t *tmpptr = tmp + SIZE * 2; \
  73. src -= stride * 2; \
  74. \
  75. for (i = 0; i < SIZE; i += LOOPSIZE) \
  76. ff_put_rv40_qpel_h ##OPT(tmp + i, SIZE, src + i, stride, \
  77. SIZE + 5, HCOFF(PH)); \
  78. for (i = 0; i < SIZE; i += LOOPSIZE) \
  79. ff_ ##OP ##rv40_qpel_v ##OPT(dst + i, stride, tmpptr + i, \
  80. SIZE, SIZE, VCOFF(PV)); \
  81. } else if (PV) { \
  82. for (i = 0; i < SIZE; i += LOOPSIZE) \
  83. ff_ ##OP ##rv40_qpel_v ## OPT(dst + i, stride, src + i, \
  84. stride, SIZE, VCOFF(PV)); \
  85. } else { \
  86. for (i = 0; i < SIZE; i += LOOPSIZE) \
  87. ff_ ##OP ##rv40_qpel_h ## OPT(dst + i, stride, src + i, \
  88. stride, SIZE, HCOFF(PH)); \
  89. } \
  90. };
  91. /** Declare functions for sizes 8 and 16 and given operations
  92. * and qpel position. */
  93. #define QPEL_FUNCS_DECL(OP, PH, PV, OPT) \
  94. QPEL_FUNC_DECL(OP, 8, PH, PV, OPT) \
  95. QPEL_FUNC_DECL(OP, 16, PH, PV, OPT)
  96. /** Declare all functions for all sizes and qpel positions */
  97. #define QPEL_MC_DECL(OP, OPT) \
  98. void ff_ ##OP ##rv40_qpel_h ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
  99. const uint8_t *src, \
  100. ptrdiff_t srcStride, \
  101. int len, int m); \
  102. void ff_ ##OP ##rv40_qpel_v ##OPT(uint8_t *dst, ptrdiff_t dstStride, \
  103. const uint8_t *src, \
  104. ptrdiff_t srcStride, \
  105. int len, int m); \
  106. QPEL_FUNCS_DECL(OP, 0, 1, OPT) \
  107. QPEL_FUNCS_DECL(OP, 0, 3, OPT) \
  108. QPEL_FUNCS_DECL(OP, 1, 0, OPT) \
  109. QPEL_FUNCS_DECL(OP, 1, 1, OPT) \
  110. QPEL_FUNCS_DECL(OP, 1, 2, OPT) \
  111. QPEL_FUNCS_DECL(OP, 1, 3, OPT) \
  112. QPEL_FUNCS_DECL(OP, 2, 1, OPT) \
  113. QPEL_FUNCS_DECL(OP, 2, 2, OPT) \
  114. QPEL_FUNCS_DECL(OP, 2, 3, OPT) \
  115. QPEL_FUNCS_DECL(OP, 3, 0, OPT) \
  116. QPEL_FUNCS_DECL(OP, 3, 1, OPT) \
  117. QPEL_FUNCS_DECL(OP, 3, 2, OPT)
  118. /** @} */
  119. #define LOOPSIZE 8
  120. #define HCOFF(x) (32 * (x - 1))
  121. #define VCOFF(x) (32 * (x - 1))
  122. QPEL_MC_DECL(put_, _ssse3)
  123. QPEL_MC_DECL(avg_, _ssse3)
  124. #undef LOOPSIZE
  125. #undef HCOFF
  126. #undef VCOFF
  127. #define LOOPSIZE 8
  128. #define HCOFF(x) (64 * (x - 1))
  129. #define VCOFF(x) (64 * (x - 1))
  130. QPEL_MC_DECL(put_, _sse2)
  131. QPEL_MC_DECL(avg_, _sse2)
  132. #if ARCH_X86_32
  133. #undef LOOPSIZE
  134. #undef HCOFF
  135. #undef VCOFF
  136. #define LOOPSIZE 4
  137. #define HCOFF(x) (64 * (x - 1))
  138. #define VCOFF(x) (64 * (x - 1))
  139. QPEL_MC_DECL(put_, _mmx)
  140. #define ff_put_rv40_qpel_h_mmx2 ff_put_rv40_qpel_h_mmx
  141. #define ff_put_rv40_qpel_v_mmx2 ff_put_rv40_qpel_v_mmx
  142. QPEL_MC_DECL(avg_, _mmx2)
  143. #define ff_put_rv40_qpel_h_3dnow ff_put_rv40_qpel_h_mmx
  144. #define ff_put_rv40_qpel_v_3dnow ff_put_rv40_qpel_v_mmx
  145. QPEL_MC_DECL(avg_, _3dnow)
  146. #endif
  147. /** @{ */
  148. /** Set one function */
  149. #define QPEL_FUNC_SET(OP, SIZE, PH, PV, OPT) \
  150. c-> OP ## pixels_tab[2 - SIZE / 8][4 * PV + PH] = OP ## rv40_qpel ##SIZE ## _mc ##PH ##PV ##OPT;
  151. /** Set functions put and avg for sizes 8 and 16 and a given qpel position */
  152. #define QPEL_FUNCS_SET(OP, PH, PV, OPT) \
  153. QPEL_FUNC_SET(OP, 8, PH, PV, OPT) \
  154. QPEL_FUNC_SET(OP, 16, PH, PV, OPT)
  155. /** Set all functions for all sizes and qpel positions */
  156. #define QPEL_MC_SET(OP, OPT) \
  157. QPEL_FUNCS_SET (OP, 0, 1, OPT) \
  158. QPEL_FUNCS_SET (OP, 0, 3, OPT) \
  159. QPEL_FUNCS_SET (OP, 1, 0, OPT) \
  160. QPEL_FUNCS_SET (OP, 1, 1, OPT) \
  161. QPEL_FUNCS_SET (OP, 1, 2, OPT) \
  162. QPEL_FUNCS_SET (OP, 1, 3, OPT) \
  163. QPEL_FUNCS_SET (OP, 2, 1, OPT) \
  164. QPEL_FUNCS_SET (OP, 2, 2, OPT) \
  165. QPEL_FUNCS_SET (OP, 2, 3, OPT) \
  166. QPEL_FUNCS_SET (OP, 3, 0, OPT) \
  167. QPEL_FUNCS_SET (OP, 3, 1, OPT) \
  168. QPEL_FUNCS_SET (OP, 3, 2, OPT)
  169. /** @} */
  170. #endif /* HAVE_YASM */
  171. void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp)
  172. {
  173. #if HAVE_YASM
  174. int mm_flags = av_get_cpu_flags();
  175. if (EXTERNAL_MMX(mm_flags)) {
  176. c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx;
  177. c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx;
  178. #if HAVE_MMX_INLINE
  179. c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_mmx;
  180. c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_mmx;
  181. c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_mmx;
  182. c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_mmx;
  183. #endif /* HAVE_MMX_INLINE */
  184. #if ARCH_X86_32
  185. QPEL_MC_SET(put_, _mmx)
  186. #endif
  187. }
  188. if (EXTERNAL_MMXEXT(mm_flags)) {
  189. c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2;
  190. c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmx2;
  191. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_mmx2;
  192. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_mmx2;
  193. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_mmx2;
  194. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_mmx2;
  195. #if ARCH_X86_32
  196. QPEL_MC_SET(avg_, _mmx2)
  197. #endif
  198. } else if (EXTERNAL_AMD3DNOW(mm_flags)) {
  199. c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow;
  200. c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow;
  201. #if ARCH_X86_32
  202. QPEL_MC_SET(avg_, _3dnow)
  203. #endif
  204. }
  205. if (EXTERNAL_SSE2(mm_flags)) {
  206. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_sse2;
  207. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_sse2;
  208. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_sse2;
  209. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_sse2;
  210. QPEL_MC_SET(put_, _sse2)
  211. QPEL_MC_SET(avg_, _sse2)
  212. }
  213. if (EXTERNAL_SSSE3(mm_flags)) {
  214. c->rv40_weight_pixels_tab[0][0] = ff_rv40_weight_func_rnd_16_ssse3;
  215. c->rv40_weight_pixels_tab[0][1] = ff_rv40_weight_func_rnd_8_ssse3;
  216. c->rv40_weight_pixels_tab[1][0] = ff_rv40_weight_func_nornd_16_ssse3;
  217. c->rv40_weight_pixels_tab[1][1] = ff_rv40_weight_func_nornd_8_ssse3;
  218. QPEL_MC_SET(put_, _ssse3)
  219. QPEL_MC_SET(avg_, _ssse3)
  220. }
  221. #endif /* HAVE_YASM */
  222. }