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