diracdsp.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2024 Kyosuke Kawakami
  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 "checkasm.h"
  21. #include "libavcodec/diracdsp.h"
  22. #include "libavutil/intreadwrite.h"
  23. #include "libavutil/mem_internal.h"
  24. #define RANDOMIZE_DESTS(name, size) \
  25. do { \
  26. int i; \
  27. for (i = 0; i < size; ++i) { \
  28. uint16_t r = rnd(); \
  29. AV_WN16A(name##0 + i, r); \
  30. AV_WN16A(name##1 + i, r); \
  31. } \
  32. } while (0)
  33. #define RANDOMIZE_BUFFER8(name, size) \
  34. do { \
  35. int i; \
  36. for (i = 0; i < size; ++i) { \
  37. uint8_t r = rnd(); \
  38. name[i] = r; \
  39. } \
  40. } while (0)
  41. #define OBMC_STRIDE 32
  42. #define XBLEN_MAX 32
  43. #define YBLEN_MAX 64
  44. static void check_add_obmc(size_t func_index, int xblen)
  45. {
  46. LOCAL_ALIGNED_16(uint8_t, src, [XBLEN_MAX * YBLEN_MAX]);
  47. LOCAL_ALIGNED_16(uint16_t, _dst0, [XBLEN_MAX * YBLEN_MAX + 4]);
  48. LOCAL_ALIGNED_16(uint16_t, _dst1, [XBLEN_MAX * YBLEN_MAX + 4]);
  49. LOCAL_ALIGNED_16(uint8_t, obmc_weight, [XBLEN_MAX * YBLEN_MAX]);
  50. // Ensure that they accept unaligned buffer.
  51. // Not using LOCAL_ALIGNED_8 because it might make 16 byte aligned buffer.
  52. uint16_t *dst0 = _dst0 + 4;
  53. uint16_t *dst1 = _dst1 + 4;
  54. int yblen;
  55. DiracDSPContext h;
  56. ff_diracdsp_init(&h);
  57. if (check_func(h.add_dirac_obmc[func_index], "diracdsp.add_dirac_obmc_%d", xblen)) {
  58. declare_func(void, uint16_t*, const uint8_t*, int, const uint8_t *, int);
  59. RANDOMIZE_BUFFER8(src, YBLEN_MAX * xblen);
  60. RANDOMIZE_DESTS(dst, YBLEN_MAX * xblen);
  61. RANDOMIZE_BUFFER8(obmc_weight, YBLEN_MAX * OBMC_STRIDE);
  62. yblen = 1 + (rnd() % YBLEN_MAX);
  63. call_ref(dst0, src, xblen, obmc_weight, yblen);
  64. call_new(dst1, src, xblen, obmc_weight, yblen);
  65. if (memcmp(dst0, dst1, yblen * xblen))
  66. fail();
  67. bench_new(dst1, src, xblen, obmc_weight, YBLEN_MAX);
  68. }
  69. }
  70. void checkasm_check_diracdsp(void)
  71. {
  72. check_add_obmc(0, 8);
  73. check_add_obmc(1, 16);
  74. check_add_obmc(2, 32);
  75. report("diracdsp");
  76. }