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.

247 lines
10.0KB

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