pixblockdsp.c 5.2 KB

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