pixblockdsp.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2015 Tiancheng "Timothy" Gu
  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/pixblockdsp.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/mem_internal.h"
  27. #define BUF_UNITS 8
  28. #define BUF_SIZE (BUF_UNITS * 128 + 8 * BUF_UNITS)
  29. #define randomize_buffers() \
  30. do { \
  31. int i; \
  32. for (i = 0; i < BUF_SIZE; i += 4) { \
  33. uint32_t r = rnd(); \
  34. AV_WN32A(src10 + i, r); \
  35. AV_WN32A(src11 + i, r); \
  36. r = rnd(); \
  37. AV_WN32A(src20 + i, r); \
  38. AV_WN32A(src21 + i, r); \
  39. r = rnd(); \
  40. AV_WN32A(dst0_ + i, r); \
  41. AV_WN32A(dst1_ + i, r); \
  42. } \
  43. } while (0)
  44. #define check_get_pixels(type, aligned) \
  45. do { \
  46. int i; \
  47. declare_func(void, int16_t *block, const uint8_t *pixels, ptrdiff_t line_size); \
  48. \
  49. for (i = 0; i < BUF_UNITS; i++) { \
  50. int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \
  51. int dst_offset = i * 64; /* dst must be aligned */ \
  52. randomize_buffers(); \
  53. call_ref(dst0 + dst_offset, src10 + src_offset, 8); \
  54. call_new(dst1 + dst_offset, src11 + src_offset, 8); \
  55. if (memcmp(src10, src11, BUF_SIZE)|| memcmp(dst0, dst1, BUF_SIZE)) \
  56. fail(); \
  57. bench_new(dst1 + dst_offset, src11 + src_offset, 8); \
  58. } \
  59. } while (0)
  60. #define check_diff_pixels(type, aligned) \
  61. do { \
  62. int i; \
  63. declare_func(void, int16_t *restrict block, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride); \
  64. \
  65. for (i = 0; i < BUF_UNITS; i++) { \
  66. int src_offset = i * 64 * sizeof(type) + (aligned ? 8 : 1) * i; \
  67. int dst_offset = i * 64; /* dst must be aligned */ \
  68. randomize_buffers(); \
  69. call_ref(dst0 + dst_offset, src10 + src_offset, src20 + src_offset, 8); \
  70. call_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \
  71. if (memcmp(src10, src11, BUF_SIZE) || memcmp(src20, src21, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \
  72. fail(); \
  73. bench_new(dst1 + dst_offset, src11 + src_offset, src21 + src_offset, 8); \
  74. } \
  75. } while (0)
  76. void checkasm_check_pixblockdsp(void)
  77. {
  78. LOCAL_ALIGNED_16(uint8_t, src10, [BUF_SIZE]);
  79. LOCAL_ALIGNED_16(uint8_t, src11, [BUF_SIZE]);
  80. LOCAL_ALIGNED_16(uint8_t, src20, [BUF_SIZE]);
  81. LOCAL_ALIGNED_16(uint8_t, src21, [BUF_SIZE]);
  82. LOCAL_ALIGNED_16(uint8_t, dst0_, [BUF_SIZE]);
  83. LOCAL_ALIGNED_16(uint8_t, dst1_, [BUF_SIZE]);
  84. uint16_t *dst0 = (uint16_t *)dst0_;
  85. uint16_t *dst1 = (uint16_t *)dst1_;
  86. PixblockDSPContext h;
  87. AVCodecContext avctx = {
  88. .bits_per_raw_sample = 8,
  89. };
  90. ff_pixblockdsp_init(&h, &avctx);
  91. if (check_func(h.get_pixels, "get_pixels"))
  92. check_get_pixels(uint8_t, 1);
  93. if (check_func(h.get_pixels_unaligned, "get_pixels_unaligned"))
  94. check_get_pixels(uint8_t, 0);
  95. report("get_pixels");
  96. if (check_func(h.diff_pixels, "diff_pixels"))
  97. check_diff_pixels(uint8_t, 1);
  98. if (check_func(h.diff_pixels_unaligned, "diff_pixels_unaligned"))
  99. check_diff_pixels(uint8_t, 0);
  100. report("diff_pixels");
  101. }