blockdsp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2015 Henrik Gramner
  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/blockdsp.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #include "libavutil/mem_internal.h"
  27. #define randomize_buffers(size) \
  28. do { \
  29. int i; \
  30. for (i = 0; i < size; i++) { \
  31. uint16_t r = rnd(); \
  32. AV_WN16A(buf0 + i, r); \
  33. AV_WN16A(buf1 + i, r); \
  34. } \
  35. } while (0)
  36. #define check_clear(func, size) \
  37. do { \
  38. if (check_func(h.func, "blockdsp." #func)) { \
  39. declare_func(void, int16_t *block); \
  40. randomize_buffers(size); \
  41. call_ref(buf0); \
  42. call_new(buf1); \
  43. if (memcmp(buf0, buf1, sizeof(*buf0) * size)) \
  44. fail(); \
  45. bench_new(buf0); \
  46. } \
  47. } while (0)
  48. static void check_fill(BlockDSPContext *h){
  49. LOCAL_ALIGNED_16(uint8_t, buf0_16, [16 * 16]);
  50. LOCAL_ALIGNED_16(uint8_t, buf1_16, [16 * 16]);
  51. for (int t = 0; t < 2; ++t) {
  52. uint8_t *buf0 = buf0_16 + t * /* force 8 byte alignment */ 8;
  53. uint8_t *buf1 = buf1_16 + t * /* force 8 byte alignment */ 8;
  54. int n = 16 - 8 * t;
  55. declare_func(void, uint8_t *block, uint8_t value,
  56. ptrdiff_t line_size, int h);
  57. if (check_func(h->fill_block_tab[t], "blockdsp.fill_block_tab[%d]", t)) {
  58. uint8_t value = rnd();
  59. memset(buf0, 0, sizeof(*buf0) * n * n);
  60. memset(buf1, 0, sizeof(*buf1) * n * n);
  61. call_ref(buf0, value, n, n);
  62. call_new(buf1, value, n, n);
  63. if (memcmp(buf0, buf1, sizeof(*buf0) * n * n))
  64. fail();
  65. bench_new(buf0, value, n, n);
  66. }
  67. }
  68. }
  69. void checkasm_check_blockdsp(void)
  70. {
  71. LOCAL_ALIGNED_32(uint16_t, buf0, [6 * 8 * 8]);
  72. LOCAL_ALIGNED_32(uint16_t, buf1, [6 * 8 * 8]);
  73. BlockDSPContext h;
  74. ff_blockdsp_init(&h);
  75. check_clear(clear_block, 8 * 8);
  76. check_clear(clear_blocks, 8 * 8 * 6);
  77. check_fill(&h);
  78. report("blockdsp");
  79. }