videodsp.c 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #define randomize_buffers(w, h) \
  26. do { \
  27. int i; \
  28. for (i = 0; i < w * h * sizeof(*src0); i += 4) \
  29. AV_WN32A(((uint8_t *) src0) + i, rnd()); \
  30. } while (0)
  31. #define iter_1d(type, fix, fix_val, var, var_start, var_end) \
  32. for (fix = fix_val, var = var_start; var <= var_end; var++) { \
  33. call_ref((type *) dst0, (const type *) (src0 + y * pw + x), \
  34. bw * sizeof(type), pw * sizeof(type), \
  35. bw, bh, x, y, pw, ph); \
  36. call_new((type *) dst1, (const type *) (src1 + y * pw + x), \
  37. bw * sizeof(type), pw * sizeof(type), \
  38. bw, bh, x, y, pw, ph); \
  39. if (memcmp(dst0, dst1, bw * bh * sizeof(type))) \
  40. fail(); \
  41. bench_new((type *) dst1, (const type *) (src1 + y * pw + x),\
  42. bw * sizeof(type), pw * sizeof(type), \
  43. bw, bh, x, y, pw, ph); \
  44. }
  45. #define check_emu_edge_size(type, src_w, src_h, dst_w, dst_h) \
  46. do { \
  47. LOCAL_ALIGNED_16(type, src0, [src_w * src_h]); \
  48. LOCAL_ALIGNED_16(type, src1, [src_w * src_h]); \
  49. int bw = dst_w, bh = dst_h; \
  50. int pw = src_w, ph = src_h; \
  51. int y, x; \
  52. randomize_buffers(src_w, src_h); \
  53. memcpy(src1, src0, pw * ph * sizeof(type)); \
  54. iter_1d(type, y, 0 - src_h, x, 0 - src_w, src_w - 0); \
  55. iter_1d(type, x, src_w - 0, y, 0 - src_h, src_h - 0); \
  56. iter_1d(type, y, src_h - 0, x, 0 - src_w, src_w - 0); \
  57. iter_1d(type, x, 0 - src_w, y, 0 - src_h, src_h - 0); \
  58. } while (0)
  59. #define check_emu_edge(type) \
  60. do { \
  61. LOCAL_ALIGNED_16(type, dst0, [64 * 64]); \
  62. LOCAL_ALIGNED_16(type, dst1, [64 * 64]); \
  63. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, \
  64. void, type *dst, const type *src, \
  65. ptrdiff_t dst_linesize, \
  66. ptrdiff_t src_linesize, \
  67. int block_w, int block_h, \
  68. int src_x, int src_y, \
  69. int src_w, int src_h); \
  70. check_emu_edge_size(type, 16, 1, 64, 64); \
  71. check_emu_edge_size(type, 16, 16, 64, 64); \
  72. check_emu_edge_size(type, 64, 64, 64, 64); \
  73. } while (0)
  74. void checkasm_check_videodsp(void)
  75. {
  76. VideoDSPContext vdsp;
  77. ff_videodsp_init(&vdsp, 8);
  78. if (check_func(vdsp.emulated_edge_mc, "emulated_edge_mc_8"))
  79. check_emu_edge(uint8_t);
  80. report("emulated_edge_mc");
  81. }