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.

172 lines
5.9KB

  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 mc_func(avg, sz, dir, opt) \
  28. void ff_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
  29. const uint8_t *src, ptrdiff_t src_stride, \
  30. int h, const int8_t (*filter)[16])
  31. #define mc_funcs(sz) \
  32. mc_func(put, sz, h, ssse3); \
  33. mc_func(avg, sz, h, ssse3); \
  34. mc_func(put, sz, v, ssse3); \
  35. mc_func(avg, sz, v, ssse3)
  36. mc_funcs(4);
  37. mc_funcs(8);
  38. #undef mc_funcs
  39. #undef mc_func
  40. #define mc_rep_func(avg, sz, hsz, dir, opt) \
  41. static av_always_inline void \
  42. ff_##avg##_8tap_1d_##dir##_##sz##_##opt(uint8_t *dst, ptrdiff_t dst_stride, \
  43. const uint8_t *src, ptrdiff_t src_stride, \
  44. int h, const int8_t (*filter)[16]) \
  45. { \
  46. ff_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst, dst_stride, src, \
  47. src_stride, h, filter); \
  48. ff_##avg##_8tap_1d_##dir##_##hsz##_##opt(dst + hsz, dst_stride, src + hsz, \
  49. src_stride, h, filter); \
  50. }
  51. #define mc_rep_funcs(sz, hsz) \
  52. mc_rep_func(put, sz, hsz, h, ssse3); \
  53. mc_rep_func(avg, sz, hsz, h, ssse3); \
  54. mc_rep_func(put, sz, hsz, v, ssse3); \
  55. mc_rep_func(avg, sz, hsz, v, ssse3)
  56. mc_rep_funcs(16, 8);
  57. mc_rep_funcs(32, 16);
  58. mc_rep_funcs(64, 32);
  59. #undef mc_rep_funcs
  60. #undef mc_rep_func
  61. extern const int8_t ff_filters_ssse3[3][15][4][16];
  62. #define filter_8tap_2d_fn(op, sz, f, fname) \
  63. static void op##_8tap_##fname##_##sz##hv_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
  64. const uint8_t *src, ptrdiff_t src_stride, \
  65. int h, int mx, int my) \
  66. { \
  67. LOCAL_ALIGNED_16(uint8_t, temp, [71 * 64]); \
  68. ff_put_8tap_1d_h_##sz##_ssse3(temp, 64, src - 3 * src_stride, src_stride, \
  69. h + 7, ff_filters_ssse3[f][mx - 1]); \
  70. ff_##op##_8tap_1d_v_##sz##_ssse3(dst, dst_stride, temp + 3 * 64, 64, \
  71. h, ff_filters_ssse3[f][my - 1]); \
  72. }
  73. #define filters_8tap_2d_fn(op, sz) \
  74. filter_8tap_2d_fn(op, sz, FILTER_8TAP_REGULAR, regular) \
  75. filter_8tap_2d_fn(op, sz, FILTER_8TAP_SHARP, sharp) \
  76. filter_8tap_2d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth)
  77. #define filters_8tap_2d_fn2(op) \
  78. filters_8tap_2d_fn(op, 64) \
  79. filters_8tap_2d_fn(op, 32) \
  80. filters_8tap_2d_fn(op, 16) \
  81. filters_8tap_2d_fn(op, 8) \
  82. filters_8tap_2d_fn(op, 4)
  83. filters_8tap_2d_fn2(put)
  84. filters_8tap_2d_fn2(avg)
  85. #undef filters_8tap_2d_fn2
  86. #undef filters_8tap_2d_fn
  87. #undef filter_8tap_2d_fn
  88. #define filter_8tap_1d_fn(op, sz, f, fname, dir, dvar) \
  89. static void op##_8tap_##fname##_##sz##dir##_ssse3(uint8_t *dst, ptrdiff_t dst_stride, \
  90. const uint8_t *src, ptrdiff_t src_stride, \
  91. int h, int mx, int my) \
  92. { \
  93. ff_##op##_8tap_1d_##dir##_##sz##_ssse3(dst, dst_stride, src, src_stride, \
  94. h, ff_filters_ssse3[f][dvar - 1]); \
  95. }
  96. #define filters_8tap_1d_fn(op, sz, dir, dvar) \
  97. filter_8tap_1d_fn(op, sz, FILTER_8TAP_REGULAR, regular, dir, dvar) \
  98. filter_8tap_1d_fn(op, sz, FILTER_8TAP_SHARP, sharp, dir, dvar) \
  99. filter_8tap_1d_fn(op, sz, FILTER_8TAP_SMOOTH, smooth, dir, dvar)
  100. #define filters_8tap_1d_fn2(op, sz) \
  101. filters_8tap_1d_fn(op, sz, h, mx) \
  102. filters_8tap_1d_fn(op, sz, v, my)
  103. #define filters_8tap_1d_fn3(op) \
  104. filters_8tap_1d_fn2(op, 64) \
  105. filters_8tap_1d_fn2(op, 32) \
  106. filters_8tap_1d_fn2(op, 16) \
  107. filters_8tap_1d_fn2(op, 8) \
  108. filters_8tap_1d_fn2(op, 4)
  109. filters_8tap_1d_fn3(put)
  110. filters_8tap_1d_fn3(avg)
  111. #undef filters_8tap_1d_fn
  112. #undef filters_8tap_1d_fn2
  113. #undef filters_8tap_1d_fn3
  114. #undef filter_8tap_1d_fn
  115. #endif /* HAVE_YASM */
  116. av_cold void ff_vp9dsp_init_x86(VP9DSPContext *dsp)
  117. {
  118. #if HAVE_YASM
  119. int cpu_flags = av_get_cpu_flags();
  120. #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type, opt) \
  121. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_##opt; \
  122. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_##opt; \
  123. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_##opt
  124. #define init_subpel2(idx, idxh, idxv, dir, type, opt) \
  125. init_subpel1(0, idx, idxh, idxv, 64, dir, type, opt); \
  126. init_subpel1(1, idx, idxh, idxv, 32, dir, type, opt); \
  127. init_subpel1(2, idx, idxh, idxv, 16, dir, type, opt); \
  128. init_subpel1(3, idx, idxh, idxv, 8, dir, type, opt); \
  129. init_subpel1(4, idx, idxh, idxv, 4, dir, type, opt)
  130. #define init_subpel3(idx, type, opt) \
  131. init_subpel2(idx, 1, 1, hv, type, opt); \
  132. init_subpel2(idx, 0, 1, v, type, opt); \
  133. init_subpel2(idx, 1, 0, h, type, opt)
  134. if (cpu_flags & AV_CPU_FLAG_SSSE3) {
  135. init_subpel3(0, put, ssse3);
  136. init_subpel3(1, avg, ssse3);
  137. }
  138. #undef init_subpel1
  139. #undef init_subpel2
  140. #undef init_subpel3
  141. #endif /* HAVE_YASM */
  142. }