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.

190 lines
6.5KB

  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/attributes.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/mem.h"
  25. #include "libavutil/x86/cpu.h"
  26. #include "libavcodec/vp9dsp.h"
  27. #include "libavcodec/x86/vp9dsp_init.h"
  28. #if HAVE_YASM
  29. extern const int16_t ff_filters_16bpp[3][15][4][16];
  30. decl_mc_funcs(4, sse2, int16_t, 16, BPC);
  31. decl_mc_funcs(8, sse2, int16_t, 16, BPC);
  32. decl_mc_funcs(16, avx2, int16_t, 16, BPC);
  33. mc_rep_funcs(16, 8, 16, sse2, int16_t, 16, BPC);
  34. mc_rep_funcs(32, 16, 32, sse2, int16_t, 16, BPC);
  35. mc_rep_funcs(64, 32, 64, sse2, int16_t, 16, BPC);
  36. #if HAVE_AVX2_EXTERNAL
  37. mc_rep_funcs(32, 16, 32, avx2, int16_t, 16, BPC);
  38. mc_rep_funcs(64, 32, 64, avx2, int16_t, 16, BPC);
  39. #endif
  40. filters_8tap_2d_fn2(put, 16, BPC, 2, sse2, sse2, 16bpp)
  41. filters_8tap_2d_fn2(avg, 16, BPC, 2, sse2, sse2, 16bpp)
  42. #if HAVE_AVX2_EXTERNAL
  43. filters_8tap_2d_fn(put, 64, 32, BPC, 2, avx2, 16bpp)
  44. filters_8tap_2d_fn(avg, 64, 32, BPC, 2, avx2, 16bpp)
  45. filters_8tap_2d_fn(put, 32, 32, BPC, 2, avx2, 16bpp)
  46. filters_8tap_2d_fn(avg, 32, 32, BPC, 2, avx2, 16bpp)
  47. filters_8tap_2d_fn(put, 16, 32, BPC, 2, avx2, 16bpp)
  48. filters_8tap_2d_fn(avg, 16, 32, BPC, 2, avx2, 16bpp)
  49. #endif
  50. filters_8tap_1d_fn3(put, BPC, sse2, sse2, 16bpp)
  51. filters_8tap_1d_fn3(avg, BPC, sse2, sse2, 16bpp)
  52. #if HAVE_AVX2_EXTERNAL
  53. filters_8tap_1d_fn2(put, 64, BPC, avx2, 16bpp)
  54. filters_8tap_1d_fn2(avg, 64, BPC, avx2, 16bpp)
  55. filters_8tap_1d_fn2(put, 32, BPC, avx2, 16bpp)
  56. filters_8tap_1d_fn2(avg, 32, BPC, avx2, 16bpp)
  57. filters_8tap_1d_fn2(put, 16, BPC, avx2, 16bpp)
  58. filters_8tap_1d_fn2(avg, 16, BPC, avx2, 16bpp)
  59. #endif
  60. #define decl_lpf_func(dir, wd, bpp, opt) \
  61. void ff_vp9_loop_filter_##dir##_##wd##_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \
  62. int E, int I, int H)
  63. #define decl_lpf_funcs(dir, wd, bpp) \
  64. decl_lpf_func(dir, wd, bpp, sse2); \
  65. decl_lpf_func(dir, wd, bpp, ssse3); \
  66. decl_lpf_func(dir, wd, bpp, avx)
  67. #define decl_lpf_funcs_wd(dir) \
  68. decl_lpf_funcs(dir, 4, BPC); \
  69. decl_lpf_funcs(dir, 8, BPC); \
  70. decl_lpf_funcs(dir, 16, BPC)
  71. decl_lpf_funcs_wd(h);
  72. decl_lpf_funcs_wd(v);
  73. #define lpf_16_wrapper(dir, off, bpp, opt) \
  74. static void loop_filter_##dir##_16_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \
  75. int E, int I, int H) \
  76. { \
  77. ff_vp9_loop_filter_##dir##_16_##bpp##_##opt(dst, stride, E, I, H); \
  78. ff_vp9_loop_filter_##dir##_16_##bpp##_##opt(dst + off, stride, E, I, H); \
  79. }
  80. #define lpf_16_wrappers(bpp, opt) \
  81. lpf_16_wrapper(h, 8 * stride, bpp, opt); \
  82. lpf_16_wrapper(v, 16, bpp, opt)
  83. lpf_16_wrappers(BPC, sse2);
  84. lpf_16_wrappers(BPC, ssse3);
  85. lpf_16_wrappers(BPC, avx);
  86. #define lpf_mix2_wrapper(dir, off, wd1, wd2, bpp, opt) \
  87. static void loop_filter_##dir##_##wd1##wd2##_##bpp##_##opt(uint8_t *dst, ptrdiff_t stride, \
  88. int E, int I, int H) \
  89. { \
  90. ff_vp9_loop_filter_##dir##_##wd1##_##bpp##_##opt(dst, stride, \
  91. E & 0xff, I & 0xff, H & 0xff); \
  92. ff_vp9_loop_filter_##dir##_##wd2##_##bpp##_##opt(dst + off, stride, \
  93. E >> 8, I >> 8, H >> 8); \
  94. }
  95. #define lpf_mix2_wrappers(wd1, wd2, bpp, opt) \
  96. lpf_mix2_wrapper(h, 8 * stride, wd1, wd2, bpp, opt); \
  97. lpf_mix2_wrapper(v, 16, wd1, wd2, bpp, opt)
  98. #define lpf_mix2_wrappers_set(bpp, opt) \
  99. lpf_mix2_wrappers(4, 4, bpp, opt); \
  100. lpf_mix2_wrappers(4, 8, bpp, opt); \
  101. lpf_mix2_wrappers(8, 4, bpp, opt); \
  102. lpf_mix2_wrappers(8, 8, bpp, opt); \
  103. lpf_mix2_wrappers_set(BPC, sse2);
  104. lpf_mix2_wrappers_set(BPC, ssse3);
  105. lpf_mix2_wrappers_set(BPC, avx);
  106. decl_ipred_fns(tm, BPC, mmxext, sse2);
  107. #endif /* HAVE_YASM */
  108. av_cold void INIT_FUNC(VP9DSPContext *dsp)
  109. {
  110. #if HAVE_YASM
  111. int cpu_flags = av_get_cpu_flags();
  112. #define init_lpf_8_func(idx1, idx2, dir, wd, bpp, opt) \
  113. dsp->loop_filter_8[idx1][idx2] = ff_vp9_loop_filter_##dir##_##wd##_##bpp##_##opt
  114. #define init_lpf_16_func(idx, dir, bpp, opt) \
  115. dsp->loop_filter_16[idx] = loop_filter_##dir##_16_##bpp##_##opt
  116. #define init_lpf_mix2_func(idx1, idx2, idx3, dir, wd1, wd2, bpp, opt) \
  117. dsp->loop_filter_mix2[idx1][idx2][idx3] = loop_filter_##dir##_##wd1##wd2##_##bpp##_##opt
  118. #define init_lpf_funcs(bpp, opt) \
  119. init_lpf_8_func(0, 0, h, 4, bpp, opt); \
  120. init_lpf_8_func(0, 1, v, 4, bpp, opt); \
  121. init_lpf_8_func(1, 0, h, 8, bpp, opt); \
  122. init_lpf_8_func(1, 1, v, 8, bpp, opt); \
  123. init_lpf_8_func(2, 0, h, 16, bpp, opt); \
  124. init_lpf_8_func(2, 1, v, 16, bpp, opt); \
  125. init_lpf_16_func(0, h, bpp, opt); \
  126. init_lpf_16_func(1, v, bpp, opt); \
  127. init_lpf_mix2_func(0, 0, 0, h, 4, 4, bpp, opt); \
  128. init_lpf_mix2_func(0, 1, 0, h, 4, 8, bpp, opt); \
  129. init_lpf_mix2_func(1, 0, 0, h, 8, 4, bpp, opt); \
  130. init_lpf_mix2_func(1, 1, 0, h, 8, 8, bpp, opt); \
  131. init_lpf_mix2_func(0, 0, 1, v, 4, 4, bpp, opt); \
  132. init_lpf_mix2_func(0, 1, 1, v, 4, 8, bpp, opt); \
  133. init_lpf_mix2_func(1, 0, 1, v, 8, 4, bpp, opt); \
  134. init_lpf_mix2_func(1, 1, 1, v, 8, 8, bpp, opt)
  135. if (EXTERNAL_MMXEXT(cpu_flags)) {
  136. init_ipred_func(tm, TM_VP8, 4, BPC, mmxext);
  137. }
  138. if (EXTERNAL_SSE2(cpu_flags)) {
  139. init_subpel3(0, put, BPC, sse2);
  140. init_subpel3(1, avg, BPC, sse2);
  141. init_lpf_funcs(BPC, sse2);
  142. init_8_16_32_ipred_funcs(tm, TM_VP8, BPC, sse2);
  143. }
  144. if (EXTERNAL_SSSE3(cpu_flags)) {
  145. init_lpf_funcs(BPC, ssse3);
  146. }
  147. if (EXTERNAL_AVX(cpu_flags)) {
  148. init_lpf_funcs(BPC, avx);
  149. }
  150. if (EXTERNAL_AVX2(cpu_flags)) {
  151. #if HAVE_AVX2_EXTERNAL
  152. init_subpel3_32_64(0, put, BPC, avx2);
  153. init_subpel3_32_64(1, avg, BPC, avx2);
  154. init_subpel2(2, 0, 16, put, BPC, avx2);
  155. init_subpel2(2, 1, 16, avg, BPC, avx2);
  156. #endif
  157. }
  158. #endif /* HAVE_YASM */
  159. ff_vp9dsp_init_16bpp_x86(dsp);
  160. }