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.

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