vp9dsp_init_aarch64.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright (c) 2016 Google Inc.
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdint.h>
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/internal.h"
  23. #include "libavutil/aarch64/cpu.h"
  24. #include "libavcodec/vp9dsp.h"
  25. #include "vp9dsp_init.h"
  26. #define declare_fpel(type, sz) \
  27. void ff_vp9_##type##sz##_neon(uint8_t *dst, ptrdiff_t dst_stride, \
  28. const uint8_t *src, ptrdiff_t src_stride, \
  29. int h, int mx, int my)
  30. #define declare_copy_avg(sz) \
  31. declare_fpel(copy, sz); \
  32. declare_fpel(avg , sz)
  33. #define decl_mc_func(op, filter, dir, sz) \
  34. void ff_vp9_##op##_##filter##sz##_##dir##_neon(uint8_t *dst, ptrdiff_t dst_stride, \
  35. const uint8_t *src, ptrdiff_t src_stride, \
  36. int h, int mx, int my)
  37. #define define_8tap_2d_fn(op, filter, sz) \
  38. static void op##_##filter##sz##_hv_neon(uint8_t *dst, ptrdiff_t dst_stride, \
  39. const uint8_t *src, ptrdiff_t src_stride, \
  40. int h, int mx, int my) \
  41. { \
  42. LOCAL_ALIGNED_16(uint8_t, temp, [((1 + (sz < 64)) * sz + 8) * sz]); \
  43. /* We only need h + 7 lines, but the horizontal filter assumes an \
  44. * even number of rows, so filter h + 8 lines here. */ \
  45. ff_vp9_put_##filter##sz##_h_neon(temp, sz, \
  46. src - 3 * src_stride, src_stride, \
  47. h + 8, mx, 0); \
  48. ff_vp9_##op##_##filter##sz##_v_neon(dst, dst_stride, \
  49. temp + 3 * sz, sz, \
  50. h, 0, my); \
  51. }
  52. #define decl_filter_funcs(op, dir, sz) \
  53. decl_mc_func(op, regular, dir, sz); \
  54. decl_mc_func(op, sharp, dir, sz); \
  55. decl_mc_func(op, smooth, dir, sz)
  56. #define decl_mc_funcs(sz) \
  57. decl_filter_funcs(put, h, sz); \
  58. decl_filter_funcs(avg, h, sz); \
  59. decl_filter_funcs(put, v, sz); \
  60. decl_filter_funcs(avg, v, sz); \
  61. decl_filter_funcs(put, hv, sz); \
  62. decl_filter_funcs(avg, hv, sz)
  63. #define ff_vp9_copy32_neon ff_vp9_copy32_aarch64
  64. #define ff_vp9_copy64_neon ff_vp9_copy64_aarch64
  65. declare_copy_avg(64);
  66. declare_copy_avg(32);
  67. declare_copy_avg(16);
  68. declare_copy_avg(8);
  69. declare_copy_avg(4);
  70. decl_mc_funcs(64);
  71. decl_mc_funcs(32);
  72. decl_mc_funcs(16);
  73. decl_mc_funcs(8);
  74. decl_mc_funcs(4);
  75. #define define_8tap_2d_funcs(sz) \
  76. define_8tap_2d_fn(put, regular, sz) \
  77. define_8tap_2d_fn(put, sharp, sz) \
  78. define_8tap_2d_fn(put, smooth, sz) \
  79. define_8tap_2d_fn(avg, regular, sz) \
  80. define_8tap_2d_fn(avg, sharp, sz) \
  81. define_8tap_2d_fn(avg, smooth, sz)
  82. define_8tap_2d_funcs(64)
  83. define_8tap_2d_funcs(32)
  84. define_8tap_2d_funcs(16)
  85. define_8tap_2d_funcs(8)
  86. define_8tap_2d_funcs(4)
  87. static av_cold void vp9dsp_mc_init_aarch64(VP9DSPContext *dsp)
  88. {
  89. int cpu_flags = av_get_cpu_flags();
  90. #define init_fpel(idx1, idx2, sz, type, suffix) \
  91. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
  92. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
  93. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
  94. dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_vp9_##type##sz##suffix
  95. #define init_copy(idx, sz, suffix) \
  96. init_fpel(idx, 0, sz, copy, suffix)
  97. #define init_avg(idx, sz, suffix) \
  98. init_fpel(idx, 1, sz, avg, suffix)
  99. #define init_copy_avg(idx, sz) \
  100. init_copy(idx, sz, _neon); \
  101. init_avg (idx, sz, _neon)
  102. if (have_armv8(cpu_flags)) {
  103. init_copy(0, 64, _aarch64);
  104. init_copy(1, 32, _aarch64);
  105. }
  106. if (have_neon(cpu_flags)) {
  107. #define init_mc_func(idx1, idx2, op, filter, fname, dir, mx, my, sz, pfx) \
  108. dsp->mc[idx1][filter][idx2][mx][my] = pfx##op##_##fname##sz##_##dir##_neon
  109. #define init_mc_funcs(idx, dir, mx, my, sz, pfx) \
  110. init_mc_func(idx, 0, put, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx); \
  111. init_mc_func(idx, 0, put, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx); \
  112. init_mc_func(idx, 0, put, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx); \
  113. init_mc_func(idx, 1, avg, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx); \
  114. init_mc_func(idx, 1, avg, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx); \
  115. init_mc_func(idx, 1, avg, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx)
  116. #define init_mc_funcs_dirs(idx, sz) \
  117. init_mc_funcs(idx, h, 1, 0, sz, ff_vp9_); \
  118. init_mc_funcs(idx, v, 0, 1, sz, ff_vp9_); \
  119. init_mc_funcs(idx, hv, 1, 1, sz,)
  120. init_avg(0, 64, _neon);
  121. init_avg(1, 32, _neon);
  122. init_copy_avg(2, 16);
  123. init_copy_avg(3, 8);
  124. init_copy_avg(4, 4);
  125. init_mc_funcs_dirs(0, 64);
  126. init_mc_funcs_dirs(1, 32);
  127. init_mc_funcs_dirs(2, 16);
  128. init_mc_funcs_dirs(3, 8);
  129. init_mc_funcs_dirs(4, 4);
  130. }
  131. }
  132. #define define_itxfm(type_a, type_b, sz) \
  133. void ff_vp9_##type_a##_##type_b##_##sz##x##sz##_add_neon(uint8_t *_dst, \
  134. ptrdiff_t stride, \
  135. int16_t *_block, int eob)
  136. #define define_itxfm_funcs(sz) \
  137. define_itxfm(idct, idct, sz); \
  138. define_itxfm(iadst, idct, sz); \
  139. define_itxfm(idct, iadst, sz); \
  140. define_itxfm(iadst, iadst, sz)
  141. define_itxfm_funcs(4);
  142. define_itxfm_funcs(8);
  143. define_itxfm_funcs(16);
  144. define_itxfm(idct, idct, 32);
  145. define_itxfm(iwht, iwht, 4);
  146. static av_cold void vp9dsp_itxfm_init_aarch64(VP9DSPContext *dsp)
  147. {
  148. int cpu_flags = av_get_cpu_flags();
  149. if (have_neon(cpu_flags)) {
  150. #define init_itxfm(tx, sz) \
  151. dsp->itxfm_add[tx][DCT_DCT] = ff_vp9_idct_idct_##sz##_add_neon; \
  152. dsp->itxfm_add[tx][DCT_ADST] = ff_vp9_iadst_idct_##sz##_add_neon; \
  153. dsp->itxfm_add[tx][ADST_DCT] = ff_vp9_idct_iadst_##sz##_add_neon; \
  154. dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_iadst_iadst_##sz##_add_neon
  155. #define init_idct(tx, nm) \
  156. dsp->itxfm_add[tx][DCT_DCT] = \
  157. dsp->itxfm_add[tx][ADST_DCT] = \
  158. dsp->itxfm_add[tx][DCT_ADST] = \
  159. dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_##nm##_add_neon
  160. init_itxfm(TX_4X4, 4x4);
  161. init_itxfm(TX_8X8, 8x8);
  162. init_itxfm(TX_16X16, 16x16);
  163. init_idct(TX_32X32, idct_idct_32x32);
  164. init_idct(4, iwht_iwht_4x4);
  165. }
  166. }
  167. #define define_loop_filter(dir, wd, len) \
  168. void ff_vp9_loop_filter_##dir##_##wd##_##len##_neon(uint8_t *dst, ptrdiff_t stride, int E, int I, int H)
  169. #define define_loop_filters(wd, len) \
  170. define_loop_filter(h, wd, len); \
  171. define_loop_filter(v, wd, len)
  172. define_loop_filters(4, 8);
  173. define_loop_filters(8, 8);
  174. define_loop_filters(16, 8);
  175. define_loop_filters(16, 16);
  176. define_loop_filters(44, 16);
  177. define_loop_filters(48, 16);
  178. define_loop_filters(84, 16);
  179. define_loop_filters(88, 16);
  180. static av_cold void vp9dsp_loopfilter_init_aarch64(VP9DSPContext *dsp)
  181. {
  182. int cpu_flags = av_get_cpu_flags();
  183. if (have_neon(cpu_flags)) {
  184. dsp->loop_filter_8[0][1] = ff_vp9_loop_filter_v_4_8_neon;
  185. dsp->loop_filter_8[0][0] = ff_vp9_loop_filter_h_4_8_neon;
  186. dsp->loop_filter_8[1][1] = ff_vp9_loop_filter_v_8_8_neon;
  187. dsp->loop_filter_8[1][0] = ff_vp9_loop_filter_h_8_8_neon;
  188. dsp->loop_filter_8[2][1] = ff_vp9_loop_filter_v_16_8_neon;
  189. dsp->loop_filter_8[2][0] = ff_vp9_loop_filter_h_16_8_neon;
  190. dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_neon;
  191. dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_neon;
  192. dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_neon;
  193. dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_neon;
  194. dsp->loop_filter_mix2[0][1][0] = ff_vp9_loop_filter_h_48_16_neon;
  195. dsp->loop_filter_mix2[0][1][1] = ff_vp9_loop_filter_v_48_16_neon;
  196. dsp->loop_filter_mix2[1][0][0] = ff_vp9_loop_filter_h_84_16_neon;
  197. dsp->loop_filter_mix2[1][0][1] = ff_vp9_loop_filter_v_84_16_neon;
  198. dsp->loop_filter_mix2[1][1][0] = ff_vp9_loop_filter_h_88_16_neon;
  199. dsp->loop_filter_mix2[1][1][1] = ff_vp9_loop_filter_v_88_16_neon;
  200. }
  201. }
  202. av_cold void ff_vp9dsp_init_aarch64(VP9DSPContext *dsp, int bpp)
  203. {
  204. if (bpp == 10) {
  205. ff_vp9dsp_init_10bpp_aarch64(dsp);
  206. return;
  207. } else if (bpp == 12) {
  208. ff_vp9dsp_init_12bpp_aarch64(dsp);
  209. return;
  210. } else if (bpp != 8)
  211. return;
  212. vp9dsp_mc_init_aarch64(dsp);
  213. vp9dsp_loopfilter_init_aarch64(dsp);
  214. vp9dsp_itxfm_init_aarch64(dsp);
  215. }