videodsp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2016 Ronald S. Bultje <rsbultje@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <string.h>
  21. #include "checkasm.h"
  22. #include "libavcodec/videodsp.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/mem_internal.h"
  26. #define randomize_buffers(w, h) \
  27. do { \
  28. int i; \
  29. for (i = 0; i < w * h * sizeof(*src0); i += 4) \
  30. AV_WN32A(((uint8_t *) src0) + i, rnd()); \
  31. } while (0)
  32. #define iter_1d(type, fix, fix_val, var, var_start, var_end) \
  33. for (fix = fix_val, var = var_start; var <= var_end; var++) { \
  34. call_ref((type *) dst0, (const type *) (src0 + y * pw + x), \
  35. bw * sizeof(type), pw * sizeof(type), \
  36. bw, bh, x, y, pw, ph); \
  37. call_new((type *) dst1, (const type *) (src1 + y * pw + x), \
  38. bw * sizeof(type), pw * sizeof(type), \
  39. bw, bh, x, y, pw, ph); \
  40. if (memcmp(dst0, dst1, bw * bh * sizeof(type))) \
  41. fail(); \
  42. bench_new((type *) dst1, (const type *) (src1 + y * pw + x),\
  43. bw * sizeof(type), pw * sizeof(type), \
  44. bw, bh, x, y, pw, ph); \
  45. }
  46. #define check_emu_edge_size(type, src_w, src_h, dst_w, dst_h) \
  47. do { \
  48. LOCAL_ALIGNED_16(type, src0, [src_w * src_h]); \
  49. LOCAL_ALIGNED_16(type, src1, [src_w * src_h]); \
  50. int bw = dst_w, bh = dst_h; \
  51. int pw = src_w, ph = src_h; \
  52. int y, x; \
  53. randomize_buffers(src_w, src_h); \
  54. memcpy(src1, src0, pw * ph * sizeof(type)); \
  55. iter_1d(type, y, 0 - src_h, x, 0 - src_w, src_w - 0); \
  56. iter_1d(type, x, src_w - 0, y, 0 - src_h, src_h - 0); \
  57. iter_1d(type, y, src_h - 0, x, 0 - src_w, src_w - 0); \
  58. iter_1d(type, x, 0 - src_w, y, 0 - src_h, src_h - 0); \
  59. } while (0)
  60. #define check_emu_edge(type) \
  61. do { \
  62. LOCAL_ALIGNED_16(type, dst0, [64 * 64]); \
  63. LOCAL_ALIGNED_16(type, dst1, [64 * 64]); \
  64. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, \
  65. void, type *dst, const type *src, \
  66. ptrdiff_t dst_linesize, \
  67. ptrdiff_t src_linesize, \
  68. int block_w, int block_h, \
  69. int src_x, int src_y, \
  70. int src_w, int src_h); \
  71. check_emu_edge_size(type, 16, 1, 64, 64); \
  72. check_emu_edge_size(type, 16, 16, 64, 64); \
  73. check_emu_edge_size(type, 64, 64, 64, 64); \
  74. } while (0)
  75. void checkasm_check_videodsp(void)
  76. {
  77. VideoDSPContext vdsp;
  78. ff_videodsp_init(&vdsp, 8);
  79. if (check_func(vdsp.emulated_edge_mc, "emulated_edge_mc_8"))
  80. check_emu_edge(uint8_t);
  81. report("emulated_edge_mc");
  82. }