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.

217 lines
10KB

  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. /*
  25. * MC functions
  26. */
  27. extern void ff_put_vp8_epel4_h4_mmxext(uint8_t *dst, int dststride,
  28. uint8_t *src, int srcstride,
  29. int height, int mx, int my);
  30. extern void ff_put_vp8_epel4_h6_mmxext(uint8_t *dst, int dststride,
  31. uint8_t *src, int srcstride,
  32. int height, int mx, int my);
  33. extern void ff_put_vp8_epel4_v4_mmxext(uint8_t *dst, int dststride,
  34. uint8_t *src, int srcstride,
  35. int height, int mx, int my);
  36. extern void ff_put_vp8_epel4_v6_mmxext(uint8_t *dst, int dststride,
  37. uint8_t *src, int srcstride,
  38. int height, int mx, int my);
  39. extern void ff_put_vp8_epel8_h4_sse2 (uint8_t *dst, int dststride,
  40. uint8_t *src, int srcstride,
  41. int height, int mx, int my);
  42. extern void ff_put_vp8_epel8_h6_sse2 (uint8_t *dst, int dststride,
  43. uint8_t *src, int srcstride,
  44. int height, int mx, int my);
  45. extern void ff_put_vp8_epel8_v4_sse2 (uint8_t *dst, int dststride,
  46. uint8_t *src, int srcstride,
  47. int height, int mx, int my);
  48. extern void ff_put_vp8_epel8_v6_sse2 (uint8_t *dst, int dststride,
  49. uint8_t *src, int srcstride,
  50. int height, int mx, int my);
  51. extern void ff_put_vp8_epel8_h4_ssse3 (uint8_t *dst, int dststride,
  52. uint8_t *src, int srcstride,
  53. int height, int mx, int my);
  54. extern void ff_put_vp8_epel8_h6_ssse3 (uint8_t *dst, int dststride,
  55. uint8_t *src, int srcstride,
  56. int height, int mx, int my);
  57. extern void ff_put_vp8_epel8_v4_ssse3 (uint8_t *dst, int dststride,
  58. uint8_t *src, int srcstride,
  59. int height, int mx, int my);
  60. extern void ff_put_vp8_epel8_v6_ssse3 (uint8_t *dst, int dststride,
  61. uint8_t *src, int srcstride,
  62. int height, int mx, int my);
  63. #define TAP_W16(OPT, TAPTYPE) \
  64. static void ff_put_vp8_epel16_ ## TAPTYPE ## _ ## OPT(uint8_t *dst, \
  65. int dststride, \
  66. uint8_t *src, \
  67. int srcstride, \
  68. int height, \
  69. int mx, int my) \
  70. { \
  71. ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(dst, dststride, \
  72. src, srcstride, \
  73. height, mx, my); \
  74. ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(dst + 8, dststride, \
  75. src + 8, srcstride, \
  76. height, mx, my); \
  77. }
  78. #define TAP_W8(OPT, TAPTYPE) \
  79. static void ff_put_vp8_epel8_ ## TAPTYPE ## _ ## OPT(uint8_t *dst, \
  80. int dststride, \
  81. uint8_t *src, \
  82. int srcstride, \
  83. int height, \
  84. int mx, int my) \
  85. { \
  86. ff_put_vp8_epel4_ ## TAPTYPE ## _ ## OPT(dst, dststride, \
  87. src, srcstride, \
  88. height, mx, my); \
  89. ff_put_vp8_epel4_ ## TAPTYPE ## _ ## OPT(dst + 4, dststride, \
  90. src + 4, srcstride, \
  91. height, mx, my); \
  92. }
  93. TAP_W8 (mmxext, h4)
  94. TAP_W8 (mmxext, h6)
  95. TAP_W16(mmxext, h6)
  96. TAP_W8 (mmxext, v4)
  97. TAP_W8 (mmxext, v6)
  98. TAP_W16(mmxext, v6)
  99. TAP_W16(sse2, h6)
  100. TAP_W16(sse2, v6)
  101. TAP_W16(ssse3, h6)
  102. TAP_W16(ssse3, v6)
  103. #define HVTAP(OPT, ALIGN, TAPNUMX, TAPNUMY, SIZE, MAXHEIGHT) \
  104. static void ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## v ## TAPNUMY ## _ ## OPT \
  105. (uint8_t *dst, int dststride, \
  106. uint8_t *src, int srcstride, \
  107. int height, int mx, int my) \
  108. { \
  109. DECLARE_ALIGNED(ALIGN, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \
  110. uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \
  111. src -= srcstride * (TAPNUMY / 2 - 1); \
  112. ff_put_vp8_epel ## SIZE ## _h ## TAPNUMX ## _ ## OPT(tmp, SIZE, \
  113. src, srcstride, \
  114. height + TAPNUMY - 1, \
  115. mx, my); \
  116. ff_put_vp8_epel ## SIZE ## _v ## TAPNUMY ## _ ## OPT(dst, dststride, \
  117. tmpptr, SIZE, \
  118. height, mx, my); \
  119. }
  120. #define HVTAPMMX(x, y) \
  121. HVTAP(mmxext, 8, x, y, 4, 8) \
  122. HVTAP(mmxext, 8, x, y, 8, 16)
  123. HVTAPMMX(4, 4)
  124. HVTAPMMX(4, 6)
  125. HVTAPMMX(6, 4)
  126. HVTAPMMX(6, 6)
  127. HVTAP(mmxext, 8, 6, 6, 16, 16)
  128. #define HVTAPSSE2(x, y, w) \
  129. HVTAP(sse2, 16, x, y, w, 16) \
  130. HVTAP(ssse3, 16, x, y, w, 16)
  131. HVTAPSSE2(4, 4, 8)
  132. HVTAPSSE2(4, 6, 8)
  133. HVTAPSSE2(6, 4, 8)
  134. HVTAPSSE2(6, 6, 8)
  135. HVTAPSSE2(6, 6, 16)
  136. extern void ff_vp8_idct_dc_add_mmx(uint8_t *dst, DCTELEM block[16], int stride);
  137. extern void ff_vp8_idct_dc_add_sse4(uint8_t *dst, DCTELEM block[16], int stride);
  138. av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c)
  139. {
  140. mm_flags = mm_support();
  141. if (mm_flags & FF_MM_MMX) {
  142. c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx;
  143. }
  144. /* note that 4-tap width=16 functions are missing because w=16
  145. * is only used for luma, and luma is always a copy or sixtap. */
  146. if (mm_flags & FF_MM_MMXEXT) {
  147. c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_mmxext;
  148. c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_mmxext;
  149. c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_mmxext;
  150. c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_mmxext;
  151. c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_mmxext;
  152. c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_mmxext;
  153. c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_mmxext;
  154. c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_mmxext;
  155. c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_mmxext;
  156. c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_mmxext;
  157. c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_mmxext;
  158. c->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_mmxext;
  159. c->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_mmxext;
  160. c->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_mmxext;
  161. c->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_mmxext;
  162. c->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_mmxext;
  163. c->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_mmxext;
  164. c->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_mmxext;
  165. c->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_mmxext;
  166. }
  167. if (mm_flags & FF_MM_SSE2) {
  168. c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_sse2;
  169. c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_sse2;
  170. c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_sse2;
  171. c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_sse2;
  172. c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_sse2;
  173. c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_sse2;
  174. c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_sse2;
  175. c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_sse2;
  176. c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_sse2;
  177. c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_sse2;
  178. c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_sse2;
  179. }
  180. if (mm_flags & FF_MM_SSSE3) {
  181. c->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_ssse3;
  182. c->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_ssse3;
  183. c->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_ssse3;
  184. c->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_ssse3;
  185. c->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_ssse3;
  186. c->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_ssse3;
  187. c->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_ssse3;
  188. c->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_ssse3;
  189. c->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_ssse3;
  190. c->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_ssse3;
  191. c->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_ssse3;
  192. }
  193. if (mm_flags & FF_MM_SSE4) {
  194. c->vp8_idct_dc_add = ff_vp8_idct_dc_add_sse4;
  195. }
  196. }