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.

276 lines
12KB

  1. /*
  2. * VP8 DSP functions x86-optimized
  3. * Copyright (c) 2010 Ronald S. Bultje <rsbultje@gmail.com>
  4. * Copyright (c) 2010 Jason Garrett-Glaser <darkshikari@gmail.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavutil/x86_cpu.h"
  23. #include "libavcodec/vp8dsp.h"
  24. #if HAVE_YASM
  25. /*
  26. * MC functions
  27. */
  28. extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, int dststride,
  29. uint8_t *src, int srcstride,
  30. int height, int mx, int my);
  31. extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, int dststride,
  32. uint8_t *src, int srcstride,
  33. int height, int mx, int my);
  34. extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, int dststride,
  35. uint8_t *src, int srcstride,
  36. int height, int mx, int my);
  37. extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, int dststride,
  38. uint8_t *src, int srcstride,
  39. int height, int mx, int my);
  40. extern void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, int dststride,
  41. uint8_t *src, int srcstride,
  42. int height, int mx, int my);
  43. extern void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, int dststride,
  44. uint8_t *src, int srcstride,
  45. int height, int mx, int my);
  46. extern void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, int dststride,
  47. uint8_t *src, int srcstride,
  48. int height, int mx, int my);
  49. extern void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, int dststride,
  50. uint8_t *src, int srcstride,
  51. int height, int mx, int my);
  52. extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, int dststride,
  53. uint8_t *src, int srcstride,
  54. int height, int mx, int my);
  55. extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, int dststride,
  56. uint8_t *src, int srcstride,
  57. int height, int mx, int my);
  58. extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, int dststride,
  59. uint8_t *src, int srcstride,
  60. int height, int mx, int my);
  61. extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, int dststride,
  62. uint8_t *src, int srcstride,
  63. int height, int mx, int my);
  64. extern void ff_put_vp8_bilinear4_h_mmxext(uint8_t *dst, int dststride,
  65. uint8_t *src, int srcstride,
  66. int height, int mx, int my);
  67. extern void ff_put_vp8_bilinear8_h_sse2 (uint8_t *dst, int dststride,
  68. uint8_t *src, int srcstride,
  69. int height, int mx, int my);
  70. extern void ff_put_vp8_bilinear4_v_mmxext(uint8_t *dst, int dststride,
  71. uint8_t *src, int srcstride,
  72. int height, int mx, int my);
  73. extern void ff_put_vp8_bilinear8_v_sse2 (uint8_t *dst, int dststride,
  74. uint8_t *src, int srcstride,
  75. int height, int mx, int my);
  76. extern void ff_put_vp8_bilinear8_v_ssse3 (uint8_t *dst, int dststride,
  77. uint8_t *src, int srcstride,
  78. int height, int mx, int my);
  79. extern void ff_put_vp8_bilinear8_h_ssse3 (uint8_t *dst, int dststride,
  80. uint8_t *src, int srcstride,
  81. int height, int mx, int my);
  82. extern void ff_put_vp8_pixels8_mmx (uint8_t *dst, int dststride,
  83. uint8_t *src, int srcstride,
  84. int height, int mx, int my);
  85. extern void ff_put_vp8_pixels16_mmx(uint8_t *dst, int dststride,
  86. uint8_t *src, int srcstride,
  87. int height, int mx, int my);
  88. extern void ff_put_vp8_pixels16_sse(uint8_t *dst, int dststride,
  89. uint8_t *src, int srcstride,
  90. int height, int mx, int my);
  91. #define TAP_W16(OPT, FILTERTYPE, TAPTYPE) \
  92. static void ff_put_vp8_ ## FILTERTYPE ## 16_ ## TAPTYPE ## _ ## OPT( \
  93. uint8_t *dst, int dststride, uint8_t *src, \
  94. int srcstride, int height, int mx, int my) \
  95. { \
  96. ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
  97. dst, dststride, src, srcstride, height, mx, my); \
  98. ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
  99. dst + 8, dststride, src + 8, srcstride, height, mx, my); \
  100. }
  101. #define TAP_W8(OPT, FILTERTYPE, TAPTYPE) \
  102. static void ff_put_vp8_ ## FILTERTYPE ## 8_ ## TAPTYPE ## _ ## OPT( \
  103. uint8_t *dst, int dststride, uint8_t *src, \
  104. int srcstride, int height, int mx, int my) \
  105. { \
  106. ff_put_vp8_ ## FILTERTYPE ## 4_ ## TAPTYPE ## _ ## OPT( \
  107. dst, dststride, src, srcstride, height, mx, my); \
  108. ff_put_vp8_ ## FILTERTYPE ## 4_ ## TAPTYPE ## _ ## OPT( \
  109. dst + 4, dststride, src + 4, srcstride, height, mx, my); \
  110. }
  111. TAP_W8 (mmxext, epel, h4)
  112. TAP_W8 (mmxext, epel, h6)
  113. TAP_W16(mmxext, epel, h6)
  114. TAP_W8 (mmxext, epel, v4)
  115. TAP_W8 (mmxext, epel, v6)
  116. TAP_W16(mmxext, epel, v6)
  117. TAP_W8 (mmxext, bilinear, h)
  118. TAP_W16(mmxext, bilinear, h)
  119. TAP_W8 (mmxext, bilinear, v)
  120. TAP_W16(mmxext, bilinear, v)
  121. TAP_W16(sse2, epel, h6)
  122. TAP_W16(sse2, epel, v6)
  123. TAP_W16(sse2, bilinear, h)
  124. TAP_W16(sse2, bilinear, v)
  125. TAP_W16(ssse3, epel, h6)
  126. TAP_W16(ssse3, epel, v6)
  127. TAP_W16(ssse3, bilinear, h)
  128. TAP_W16(ssse3, bilinear, v)
  129. #define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
  130. static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT( \
  131. uint8_t *dst, int dststride, uint8_t *src, \
  132. int srcstride, int height, int mx, int my) \
  133. { \
  134. DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
  135. uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
  136. src -= srcstride * (TAPNUMY / 2 - 1); \
  137. ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## _ ## OPT( \
  138. tmp, SIZE, src, srcstride, height + TAPNUMY - 1, mx, my); \
  139. ff_put_vp8_epel ## SIZE ## _v ## TAPNUMY ## _ ## OPT( \
  140. dst, dststride, tmpptr, SIZE, height, mx, my); \
  141. }
  142. #define HVTAPMMX(x, y) \
  143. HVTAP(mmxext, 8, x, y, 4, 8) \
  144. HVTAP(mmxext, 8, x, y, 8, 16)
  145. HVTAPMMX(4, 4)
  146. HVTAPMMX(4, 6)
  147. HVTAPMMX(6, 4)
  148. HVTAPMMX(6, 6)
  149. HVTAP(mmxext, 8, 6, 6, 16, 16)
  150. #define HVTAPSSE2(x, y, w) \
  151. HVTAP(sse2, 16, x, y, w, 16) \
  152. HVTAP(ssse3, 16, x, y, w, 16)
  153. HVTAPSSE2(4, 4, 8)
  154. HVTAPSSE2(4, 6, 8)
  155. HVTAPSSE2(6, 4, 8)
  156. HVTAPSSE2(6, 6, 8)
  157. HVTAPSSE2(6, 6, 16)
  158. #define HVBILIN(OPT, ALIGN, SIZE, MAXHEIGHT) \
  159. static void ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT( \
  160. uint8_t *dst, int dststride, uint8_t *src, \
  161. int srcstride, int height, int mx, int my) \
  162. { \
  163. DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + 2)]; \
  164. ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT( \
  165. tmp, SIZE, src, srcstride, height + 1, mx, my); \
  166. ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT( \
  167. dst, dststride, tmp, SIZE, height, mx, my); \
  168. }
  169. HVBILIN(mmxext, 8, 4, 8)
  170. HVBILIN(mmxext, 8, 8, 16)
  171. HVBILIN(mmxext, 8, 16, 16)
  172. HVBILIN(sse2, 8, 8, 16)
  173. HVBILIN(sse2, 8, 16, 16)
  174. HVBILIN(ssse3, 8, 8, 16)
  175. HVBILIN(ssse3, 8, 16, 16)
  176. extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
  177. extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16], int stride);
  178. extern void ff_vp8_luma_dc_wht_mmxext(DCTELEM block[4][4][16], DCTELEM dc[16]);
  179. extern void ff_vp8_idct_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
  180. #endif
  181. #define VP8_LUMA_MC_FUNC(IDX, SIZE, OPT) \
  182. c->put_vp8_epel_pixels_tab[IDX][0][2] = ff_put_vp8_epel ## SIZE ## _h6_ ## OPT; \
  183. c->put_vp8_epel_pixels_tab[IDX][2][0] = ff_put_vp8_epel ## SIZE ## _v6_ ## OPT; \
  184. c->put_vp8_epel_pixels_tab[IDX][2][2] = ff_put_vp8_epel ## SIZE ## _h6v6_ ## OPT
  185. #define VP8_MC_FUNC(IDX, SIZE, OPT) \
  186. c->put_vp8_epel_pixels_tab[IDX][0][1] = ff_put_vp8_epel ## SIZE ## _h4_ ## OPT; \
  187. c->put_vp8_epel_pixels_tab[IDX][1][0] = ff_put_vp8_epel ## SIZE ## _v4_ ## OPT; \
  188. c->put_vp8_epel_pixels_tab[IDX][1][1] = ff_put_vp8_epel ## SIZE ## _h4v4_ ## OPT; \
  189. c->put_vp8_epel_pixels_tab[IDX][1][2] = ff_put_vp8_epel ## SIZE ## _h6v4_ ## OPT; \
  190. c->put_vp8_epel_pixels_tab[IDX][2][1] = ff_put_vp8_epel ## SIZE ## _h4v6_ ## OPT; \
  191. VP8_LUMA_MC_FUNC(IDX, SIZE, OPT)
  192. #define VP8_BILINEAR_MC_FUNC(IDX, SIZE, OPT) \
  193. c->put_vp8_bilinear_pixels_tab[IDX][0][1] = ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT; \
  194. c->put_vp8_bilinear_pixels_tab[IDX][0][2] = ff_put_vp8_bilinear ## SIZE ## _h_ ## OPT; \
  195. c->put_vp8_bilinear_pixels_tab[IDX][1][0] = ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT; \
  196. c->put_vp8_bilinear_pixels_tab[IDX][1][1] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
  197. c->put_vp8_bilinear_pixels_tab[IDX][1][2] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
  198. c->put_vp8_bilinear_pixels_tab[IDX][2][0] = ff_put_vp8_bilinear ## SIZE ## _v_ ## OPT; \
  199. c->put_vp8_bilinear_pixels_tab[IDX][2][1] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT; \
  200. c->put_vp8_bilinear_pixels_tab[IDX][2][2] = ff_put_vp8_bilinear ## SIZE ## _hv_ ## OPT
  201. av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
  202. {
  203. mm_flags = mm_support();
  204. #if HAVE_YASM
  205. if (mm_flags & FF_MM_MMX) {
  206. c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx;
  207. c->vp8_idct_add = ff_vp8_idct_add_mmx;
  208. c->put_vp8_epel_pixels_tab[0][0][0] =
  209. c->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_mmx;
  210. c->put_vp8_epel_pixels_tab[1][0][0] =
  211. c->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_mmx;
  212. }
  213. /* note that 4-tap width=16 functions are missing because w=16
  214. * is only used for luma, and luma is always a copy or sixtap. */
  215. if (mm_flags & FF_MM_MMX2) {
  216. c->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_mmxext;
  217. VP8_LUMA_MC_FUNC(0, 16, mmxext);
  218. VP8_MC_FUNC(1, 8, mmxext);
  219. VP8_MC_FUNC(2, 4, mmxext);
  220. VP8_BILINEAR_MC_FUNC(0, 16, mmxext);
  221. VP8_BILINEAR_MC_FUNC(1, 8, mmxext);
  222. VP8_BILINEAR_MC_FUNC(2, 4, mmxext);
  223. }
  224. if (mm_flags & FF_MM_SSE) {
  225. c->put_vp8_epel_pixels_tab[0][0][0] =
  226. c->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_sse;
  227. }
  228. if (mm_flags & FF_MM_SSE2) {
  229. VP8_LUMA_MC_FUNC(0, 16, sse2);
  230. VP8_MC_FUNC(1, 8, sse2);
  231. VP8_BILINEAR_MC_FUNC(0, 16, sse2);
  232. VP8_BILINEAR_MC_FUNC(1, 8, sse2);
  233. }
  234. if (mm_flags & FF_MM_SSSE3) {
  235. VP8_LUMA_MC_FUNC(0, 16, ssse3);
  236. VP8_MC_FUNC(1, 8, ssse3);
  237. VP8_BILINEAR_MC_FUNC(0, 16, ssse3);
  238. VP8_BILINEAR_MC_FUNC(1, 8, ssse3);
  239. }
  240. if (mm_flags & FF_MM_SSE4) {
  241. c->vp8_idct_dc_add = ff_vp8_idct_dc_add_sse4;
  242. }
  243. #endif
  244. }