vp9dsp_init_16bpp_template.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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_X86ASM
  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. decl_itxfm_func(iwht, iwht, 4, BPC, mmxext);
  108. #if BPC == 10
  109. decl_itxfm_func(idct, idct, 4, BPC, mmxext);
  110. decl_itxfm_funcs(4, BPC, ssse3);
  111. #else
  112. decl_itxfm_func(idct, idct, 4, BPC, sse2);
  113. #endif
  114. decl_itxfm_func(idct, iadst, 4, BPC, sse2);
  115. decl_itxfm_func(iadst, idct, 4, BPC, sse2);
  116. decl_itxfm_func(iadst, iadst, 4, BPC, sse2);
  117. decl_itxfm_funcs(8, BPC, sse2);
  118. decl_itxfm_funcs(16, BPC, sse2);
  119. decl_itxfm_func(idct, idct, 32, BPC, sse2);
  120. #endif /* HAVE_X86ASM */
  121. av_cold void INIT_FUNC(VP9DSPContext *dsp, int bitexact)
  122. {
  123. #if HAVE_X86ASM
  124. int cpu_flags = av_get_cpu_flags();
  125. #define init_lpf_8_func(idx1, idx2, dir, wd, bpp, opt) \
  126. dsp->loop_filter_8[idx1][idx2] = ff_vp9_loop_filter_##dir##_##wd##_##bpp##_##opt
  127. #define init_lpf_16_func(idx, dir, bpp, opt) \
  128. dsp->loop_filter_16[idx] = loop_filter_##dir##_16_##bpp##_##opt
  129. #define init_lpf_mix2_func(idx1, idx2, idx3, dir, wd1, wd2, bpp, opt) \
  130. dsp->loop_filter_mix2[idx1][idx2][idx3] = loop_filter_##dir##_##wd1##wd2##_##bpp##_##opt
  131. #define init_lpf_funcs(bpp, opt) \
  132. init_lpf_8_func(0, 0, h, 4, bpp, opt); \
  133. init_lpf_8_func(0, 1, v, 4, bpp, opt); \
  134. init_lpf_8_func(1, 0, h, 8, bpp, opt); \
  135. init_lpf_8_func(1, 1, v, 8, bpp, opt); \
  136. init_lpf_8_func(2, 0, h, 16, bpp, opt); \
  137. init_lpf_8_func(2, 1, v, 16, bpp, opt); \
  138. init_lpf_16_func(0, h, bpp, opt); \
  139. init_lpf_16_func(1, v, bpp, opt); \
  140. init_lpf_mix2_func(0, 0, 0, h, 4, 4, bpp, opt); \
  141. init_lpf_mix2_func(0, 1, 0, h, 4, 8, bpp, opt); \
  142. init_lpf_mix2_func(1, 0, 0, h, 8, 4, bpp, opt); \
  143. init_lpf_mix2_func(1, 1, 0, h, 8, 8, bpp, opt); \
  144. init_lpf_mix2_func(0, 0, 1, v, 4, 4, bpp, opt); \
  145. init_lpf_mix2_func(0, 1, 1, v, 4, 8, bpp, opt); \
  146. init_lpf_mix2_func(1, 0, 1, v, 8, 4, bpp, opt); \
  147. init_lpf_mix2_func(1, 1, 1, v, 8, 8, bpp, opt)
  148. #define init_itx_func(idxa, idxb, typea, typeb, size, bpp, opt) \
  149. dsp->itxfm_add[idxa][idxb] = \
  150. cat(ff_vp9_##typea##_##typeb##_##size##x##size##_add_, bpp, _##opt);
  151. #define init_itx_func_one(idx, typea, typeb, size, bpp, opt) \
  152. init_itx_func(idx, DCT_DCT, typea, typeb, size, bpp, opt); \
  153. init_itx_func(idx, ADST_DCT, typea, typeb, size, bpp, opt); \
  154. init_itx_func(idx, DCT_ADST, typea, typeb, size, bpp, opt); \
  155. init_itx_func(idx, ADST_ADST, typea, typeb, size, bpp, opt)
  156. #define init_itx_funcs(idx, size, bpp, opt) \
  157. init_itx_func(idx, DCT_DCT, idct, idct, size, bpp, opt); \
  158. init_itx_func(idx, ADST_DCT, idct, iadst, size, bpp, opt); \
  159. init_itx_func(idx, DCT_ADST, iadst, idct, size, bpp, opt); \
  160. init_itx_func(idx, ADST_ADST, iadst, iadst, size, bpp, opt); \
  161. if (EXTERNAL_MMXEXT(cpu_flags)) {
  162. init_ipred_func(tm, TM_VP8, 4, BPC, mmxext);
  163. if (!bitexact) {
  164. init_itx_func_one(4 /* lossless */, iwht, iwht, 4, BPC, mmxext);
  165. #if BPC == 10
  166. init_itx_func(TX_4X4, DCT_DCT, idct, idct, 4, 10, mmxext);
  167. #endif
  168. }
  169. }
  170. if (EXTERNAL_SSE2(cpu_flags)) {
  171. init_subpel3(0, put, BPC, sse2);
  172. init_subpel3(1, avg, BPC, sse2);
  173. init_lpf_funcs(BPC, sse2);
  174. init_8_16_32_ipred_funcs(tm, TM_VP8, BPC, sse2);
  175. #if BPC == 10
  176. if (!bitexact) {
  177. init_itx_func(TX_4X4, ADST_DCT, idct, iadst, 4, 10, sse2);
  178. init_itx_func(TX_4X4, DCT_ADST, iadst, idct, 4, 10, sse2);
  179. init_itx_func(TX_4X4, ADST_ADST, iadst, iadst, 4, 10, sse2);
  180. }
  181. #else
  182. init_itx_funcs(TX_4X4, 4, 12, sse2);
  183. #endif
  184. init_itx_funcs(TX_8X8, 8, BPC, sse2);
  185. init_itx_funcs(TX_16X16, 16, BPC, sse2);
  186. init_itx_func_one(TX_32X32, idct, idct, 32, BPC, sse2);
  187. }
  188. if (EXTERNAL_SSSE3(cpu_flags)) {
  189. init_lpf_funcs(BPC, ssse3);
  190. #if BPC == 10
  191. if (!bitexact) {
  192. init_itx_funcs(TX_4X4, 4, BPC, ssse3);
  193. }
  194. #endif
  195. }
  196. if (EXTERNAL_AVX(cpu_flags)) {
  197. init_lpf_funcs(BPC, avx);
  198. }
  199. if (EXTERNAL_AVX2_FAST(cpu_flags)) {
  200. #if HAVE_AVX2_EXTERNAL
  201. init_subpel3_32_64(0, put, BPC, avx2);
  202. init_subpel3_32_64(1, avg, BPC, avx2);
  203. init_subpel2(2, 0, 16, put, BPC, avx2);
  204. init_subpel2(2, 1, 16, avg, BPC, avx2);
  205. #endif
  206. }
  207. #endif /* HAVE_X86ASM */
  208. ff_vp9dsp_init_16bpp_x86(dsp);
  209. }