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.

215 lines
7.2KB

  1. /*
  2. * VP9 SIMD optimizations
  3. *
  4. * Copyright (c) 2013 Ronald S. Bultje <rsbultje 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/cpu.h"
  23. #include "libavutil/mem.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavcodec/vp9dsp.h"
  26. #if HAVE_YASM
  27. #define fpel_func(avg, sz, opt) \
  28. void ff_##avg##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
  29. const uint8_t *src, ptrdiff_t src_stride, \
  30. int h, int mx, int my)
  31. fpel_func(put, 4, mmx);
  32. fpel_func(put, 8, mmx);
  33. fpel_func(put, 16, sse);
  34. fpel_func(put, 32, sse);
  35. fpel_func(put, 64, sse);
  36. fpel_func(avg, 4, sse);
  37. fpel_func(avg, 8, sse);
  38. fpel_func(avg, 16, sse2);
  39. fpel_func(avg, 32, sse2);
  40. fpel_func(avg, 64, sse2);
  41. #undef fpel_func
  42. #define mc_func(avg, sz, dir, opt) \
  43. void ff_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
  44. const uint8_t *src, ptrdiff_t src_stride, \
  45. int h, const int8_t (*filter)[16])
  46. #define mc_funcs(sz) \
  47. mc_func(put, sz, h, ssse3); \
  48. mc_func(avg, sz, h, ssse3); \
  49. mc_func(put, sz, v, ssse3); \
  50. mc_func(avg, sz, v, ssse3)
  51. mc_funcs(4);
  52. mc_funcs(8);
  53. #undef mc_funcs
  54. #undef mc_func
  55. #define mc_rep_func(avg, sz, hsz, dir, opt) \
  56. static av_always_inline void \
  57. ff_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
  58. const uint8_t *src, ptrdiff_t src_stride, \
  59. int h, const int8_t (*filter)[16]) \
  60. { \
  61. ff_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst, dst_stride, src, \
  62. src_stride, h, filter); \
  63. ff_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst + hsz, dst_stride, src + hsz, \
  64. src_stride, h, filter); \
  65. }
  66. #define mc_rep_funcs(sz, hsz) \
  67. mc_rep_func(put, sz, hsz, h, ssse3); \
  68. mc_rep_func(avg, sz, hsz, h, ssse3); \
  69. mc_rep_func(put, sz, hsz, v, ssse3); \
  70. mc_rep_func(avg, sz, hsz, v, ssse3)
  71. mc_rep_funcs(16, 8);
  72. mc_rep_funcs(32, 16);
  73. mc_rep_funcs(64, 32);
  74. #undef mc_rep_funcs
  75. #undef mc_rep_func
  76. extern const int8_t ff_filters_ssse3[3][15][4][16];
  77. #define filter_8tap_2d_fn(op, sz, f, fname) \
  78. static void op##_8tap_##fname##_##sz##hv_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
  79. const uint8_t *src, ptrdiff_t src_stride, \
  80. int h, int mx, int my) \
  81. { \
  82. LOCAL_ALIGNED_16(uint8_t, temp, [71 * 64]); \
  83. ff_put_8tap_1d_h_##sz##_ssse3(temp, 64, src - 3 * src_stride, src_stride, \
  84. h + 7, ff_filters_ssse3[f][mx - 1]); \
  85. ff_##op##_8tap_1d_v_##sz##_ssse3(dst, dst_stride, temp + 3 * 64, 64, \
  86. h, ff_filters_ssse3[f][my - 1]); \
  87. }
  88. #define filters_8tap_2d_fn(op, sz) \
  89. filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, regular) \
  90. filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP, sharp) \
  91. filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth)
  92. #define filters_8tap_2d_fn2(op) \
  93. filters_8tap_2d_fn(op, 64) \
  94. filters_8tap_2d_fn(op, 32) \
  95. filters_8tap_2d_fn(op, 16) \
  96. filters_8tap_2d_fn(op, 8) \
  97. filters_8tap_2d_fn(op, 4)
  98. filters_8tap_2d_fn2(put)
  99. filters_8tap_2d_fn2(avg)
  100. #undef filters_8tap_2d_fn2
  101. #undef filters_8tap_2d_fn
  102. #undef filter_8tap_2d_fn
  103. #define filter_8tap_1d_fn(op, sz, f, fname, dir, dvar) \
  104. static void op##_8tap_##fname##_##sz##dir##_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
  105. const uint8_t *src, ptrdiff_t src_stride, \
  106. int h, int mx, int my) \
  107. { \
  108. ff_##op##_8tap_1d_##dir##_##sz##_ssse3(dst, dst_stride, src, src_stride, \
  109. h, ff_filters_ssse3[f][dvar - 1]); \
  110. }
  111. #define filters_8tap_1d_fn(op, sz, dir, dvar) \
  112. filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, regular, dir, dvar) \
  113. filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP, sharp, dir, dvar) \
  114. filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth, dir, dvar)
  115. #define filters_8tap_1d_fn2(op, sz) \
  116. filters_8tap_1d_fn(op, sz, h, mx) \
  117. filters_8tap_1d_fn(op, sz, v, my)
  118. #define filters_8tap_1d_fn3(op) \
  119. filters_8tap_1d_fn2(op, 64) \
  120. filters_8tap_1d_fn2(op, 32) \
  121. filters_8tap_1d_fn2(op, 16) \
  122. filters_8tap_1d_fn2(op, 8) \
  123. filters_8tap_1d_fn2(op, 4)
  124. filters_8tap_1d_fn3(put)
  125. filters_8tap_1d_fn3(avg)
  126. #undef filters_8tap_1d_fn
  127. #undef filters_8tap_1d_fn2
  128. #undef filters_8tap_1d_fn3
  129. #undef filter_8tap_1d_fn
  130. #endif /* HAVE_YASM */
  131. av_cold void ff_vp9dsp_init_x86(VP9DSPContext *dsp)
  132. {
  133. #if HAVE_YASM
  134. int cpu_flags = av_get_cpu_flags();
  135. #define init_fpel(idx1, idx2, sz, type, opt) \
  136. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
  137. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
  138. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
  139. dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_##type##sz##_##opt
  140. #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type, opt) \
  141. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_##opt; \
  142. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_##opt; \
  143. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_##opt
  144. #define init_subpel2(idx, idxh, idxv, dir, type, opt) \
  145. init_subpel1(0, idx, idxh, idxv, 64, dir, type, opt); \
  146. init_subpel1(1, idx, idxh, idxv, 32, dir, type, opt); \
  147. init_subpel1(2, idx, idxh, idxv, 16, dir, type, opt); \
  148. init_subpel1(3, idx, idxh, idxv, 8, dir, type, opt); \
  149. init_subpel1(4, idx, idxh, idxv, 4, dir, type, opt)
  150. #define init_subpel3(idx, type, opt) \
  151. init_subpel2(idx, 1, 1, hv, type, opt); \
  152. init_subpel2(idx, 0, 1, v, type, opt); \
  153. init_subpel2(idx, 1, 0, h, type, opt)
  154. if (cpu_flags & AV_CPU_FLAG_MMX) {
  155. init_fpel(4, 0, 4, put, mmx);
  156. init_fpel(3, 0, 8, put, mmx);
  157. }
  158. if (cpu_flags & AV_CPU_FLAG_SSE) {
  159. init_fpel(2, 0, 16, put, sse);
  160. init_fpel(1, 0, 32, put, sse);
  161. init_fpel(0, 0, 64, put, sse);
  162. init_fpel(4, 1, 4, avg, sse);
  163. init_fpel(3, 1, 8, avg, sse);
  164. }
  165. if (cpu_flags & AV_CPU_FLAG_SSE2) {
  166. init_fpel(2, 1, 16, avg, sse2);
  167. init_fpel(1, 1, 32, avg, sse2);
  168. init_fpel(0, 1, 64, avg, sse2);
  169. }
  170. if (cpu_flags & AV_CPU_FLAG_SSSE3) {
  171. init_subpel3(0, put, ssse3);
  172. init_subpel3(1, avg, ssse3);
  173. }
  174. #undef init_fpel
  175. #undef init_subpel1
  176. #undef init_subpel2
  177. #undef init_subpel3
  178. #endif /* HAVE_YASM */
  179. }