vp9dsp_init_arm.c 9.9 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/arm/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. declare_copy_avg(64);
  64. declare_copy_avg(32);
  65. declare_copy_avg(16);
  66. declare_copy_avg(8);
  67. declare_copy_avg(4);
  68. decl_mc_funcs(64);
  69. decl_mc_funcs(32);
  70. decl_mc_funcs(16);
  71. decl_mc_funcs(8);
  72. decl_mc_funcs(4);
  73. #define define_8tap_2d_funcs(sz) \
  74. define_8tap_2d_fn(put, regular, sz) \
  75. define_8tap_2d_fn(put, sharp, sz) \
  76. define_8tap_2d_fn(put, smooth, sz) \
  77. define_8tap_2d_fn(avg, regular, sz) \
  78. define_8tap_2d_fn(avg, sharp, sz) \
  79. define_8tap_2d_fn(avg, smooth, sz)
  80. define_8tap_2d_funcs(64)
  81. define_8tap_2d_funcs(32)
  82. define_8tap_2d_funcs(16)
  83. define_8tap_2d_funcs(8)
  84. define_8tap_2d_funcs(4)
  85. static av_cold void vp9dsp_mc_init_arm(VP9DSPContext *dsp)
  86. {
  87. int cpu_flags = av_get_cpu_flags();
  88. if (have_neon(cpu_flags)) {
  89. #define init_fpel(idx1, idx2, sz, type) \
  90. dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \
  91. dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \
  92. dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \
  93. dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_vp9_##type##sz##_neon
  94. #define init_copy_avg(idx, sz) \
  95. init_fpel(idx, 0, sz, copy); \
  96. init_fpel(idx, 1, sz, avg)
  97. #define init_mc_func(idx1, idx2, op, filter, fname, dir, mx, my, sz, pfx) \
  98. dsp->mc[idx1][filter][idx2][mx][my] = pfx##op##_##fname##sz##_##dir##_neon
  99. #define init_mc_funcs(idx, dir, mx, my, sz, pfx) \
  100. init_mc_func(idx, 0, put, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx); \
  101. init_mc_func(idx, 0, put, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx); \
  102. init_mc_func(idx, 0, put, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx); \
  103. init_mc_func(idx, 1, avg, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx); \
  104. init_mc_func(idx, 1, avg, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx); \
  105. init_mc_func(idx, 1, avg, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx)
  106. #define init_mc_funcs_dirs(idx, sz) \
  107. init_mc_funcs(idx, h, 1, 0, sz, ff_vp9_); \
  108. init_mc_funcs(idx, v, 0, 1, sz, ff_vp9_); \
  109. init_mc_funcs(idx, hv, 1, 1, sz,)
  110. init_copy_avg(0, 64);
  111. init_copy_avg(1, 32);
  112. init_copy_avg(2, 16);
  113. init_copy_avg(3, 8);
  114. init_copy_avg(4, 4);
  115. init_mc_funcs_dirs(0, 64);
  116. init_mc_funcs_dirs(1, 32);
  117. init_mc_funcs_dirs(2, 16);
  118. init_mc_funcs_dirs(3, 8);
  119. init_mc_funcs_dirs(4, 4);
  120. }
  121. }
  122. #define define_itxfm(type_a, type_b, sz) \
  123. void ff_vp9_##type_a##_##type_b##_##sz##x##sz##_add_neon(uint8_t *_dst, \
  124. ptrdiff_t stride, \
  125. int16_t *_block, int eob)
  126. #define define_itxfm_funcs(sz) \
  127. define_itxfm(idct, idct, sz); \
  128. define_itxfm(iadst, idct, sz); \
  129. define_itxfm(idct, iadst, sz); \
  130. define_itxfm(iadst, iadst, sz)
  131. define_itxfm_funcs(4);
  132. define_itxfm_funcs(8);
  133. define_itxfm_funcs(16);
  134. define_itxfm(idct, idct, 32);
  135. define_itxfm(iwht, iwht, 4);
  136. static av_cold void vp9dsp_itxfm_init_arm(VP9DSPContext *dsp)
  137. {
  138. int cpu_flags = av_get_cpu_flags();
  139. if (have_neon(cpu_flags)) {
  140. #define init_itxfm(tx, sz) \
  141. dsp->itxfm_add[tx][DCT_DCT] = ff_vp9_idct_idct_##sz##_add_neon; \
  142. dsp->itxfm_add[tx][DCT_ADST] = ff_vp9_iadst_idct_##sz##_add_neon; \
  143. dsp->itxfm_add[tx][ADST_DCT] = ff_vp9_idct_iadst_##sz##_add_neon; \
  144. dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_iadst_iadst_##sz##_add_neon
  145. #define init_idct(tx, nm) \
  146. dsp->itxfm_add[tx][DCT_DCT] = \
  147. dsp->itxfm_add[tx][ADST_DCT] = \
  148. dsp->itxfm_add[tx][DCT_ADST] = \
  149. dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_##nm##_add_neon
  150. init_itxfm(TX_4X4, 4x4);
  151. init_itxfm(TX_8X8, 8x8);
  152. init_itxfm(TX_16X16, 16x16);
  153. init_idct(TX_32X32, idct_idct_32x32);
  154. init_idct(4, iwht_iwht_4x4);
  155. }
  156. }
  157. #define define_loop_filter(dir, wd, size) \
  158. void ff_vp9_loop_filter_##dir##_##wd##_##size##_neon(uint8_t *dst, ptrdiff_t stride, int E, int I, int H)
  159. #define define_loop_filters(wd, size) \
  160. define_loop_filter(h, wd, size); \
  161. define_loop_filter(v, wd, size)
  162. define_loop_filters(4, 8);
  163. define_loop_filters(8, 8);
  164. define_loop_filters(16, 8);
  165. define_loop_filters(16, 16);
  166. define_loop_filters(44, 16);
  167. #define lf_mix_fn(dir, wd1, wd2, stridea) \
  168. static void loop_filter_##dir##_##wd1##wd2##_16_neon(uint8_t *dst, \
  169. ptrdiff_t stride, \
  170. int E, int I, int H) \
  171. { \
  172. ff_vp9_loop_filter_##dir##_##wd1##_8_neon(dst, stride, E & 0xff, I & 0xff, H & 0xff); \
  173. ff_vp9_loop_filter_##dir##_##wd2##_8_neon(dst + 8 * stridea, stride, E >> 8, I >> 8, H >> 8); \
  174. }
  175. #define lf_mix_fns(wd1, wd2) \
  176. lf_mix_fn(h, wd1, wd2, stride) \
  177. lf_mix_fn(v, wd1, wd2, sizeof(uint8_t))
  178. lf_mix_fns(4, 8)
  179. lf_mix_fns(8, 4)
  180. lf_mix_fns(8, 8)
  181. static av_cold void vp9dsp_loopfilter_init_arm(VP9DSPContext *dsp)
  182. {
  183. int cpu_flags = av_get_cpu_flags();
  184. if (have_neon(cpu_flags)) {
  185. dsp->loop_filter_8[0][1] = ff_vp9_loop_filter_v_4_8_neon;
  186. dsp->loop_filter_8[0][0] = ff_vp9_loop_filter_h_4_8_neon;
  187. dsp->loop_filter_8[1][1] = ff_vp9_loop_filter_v_8_8_neon;
  188. dsp->loop_filter_8[1][0] = ff_vp9_loop_filter_h_8_8_neon;
  189. dsp->loop_filter_8[2][1] = ff_vp9_loop_filter_v_16_8_neon;
  190. dsp->loop_filter_8[2][0] = ff_vp9_loop_filter_h_16_8_neon;
  191. dsp->loop_filter_16[0] = ff_vp9_loop_filter_h_16_16_neon;
  192. dsp->loop_filter_16[1] = ff_vp9_loop_filter_v_16_16_neon;
  193. dsp->loop_filter_mix2[0][0][0] = ff_vp9_loop_filter_h_44_16_neon;
  194. dsp->loop_filter_mix2[0][0][1] = ff_vp9_loop_filter_v_44_16_neon;
  195. dsp->loop_filter_mix2[0][1][0] = loop_filter_h_48_16_neon;
  196. dsp->loop_filter_mix2[0][1][1] = loop_filter_v_48_16_neon;
  197. dsp->loop_filter_mix2[1][0][0] = loop_filter_h_84_16_neon;
  198. dsp->loop_filter_mix2[1][0][1] = loop_filter_v_84_16_neon;
  199. dsp->loop_filter_mix2[1][1][0] = loop_filter_h_88_16_neon;
  200. dsp->loop_filter_mix2[1][1][1] = loop_filter_v_88_16_neon;
  201. }
  202. }
  203. av_cold void ff_vp9dsp_init_arm(VP9DSPContext *dsp, int bpp)
  204. {
  205. if (bpp == 10) {
  206. ff_vp9dsp_init_10bpp_arm(dsp);
  207. return;
  208. } else if (bpp == 12) {
  209. ff_vp9dsp_init_12bpp_arm(dsp);
  210. return;
  211. } else if (bpp != 8)
  212. return;
  213. vp9dsp_mc_init_arm(dsp);
  214. vp9dsp_loopfilter_init_arm(dsp);
  215. vp9dsp_itxfm_init_arm(dsp);
  216. }