idctdsp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2022 Ben Avison
  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/avcodec.h"
  23. #include "libavcodec/idctdsp.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/internal.h"
  26. #include "libavutil/intreadwrite.h"
  27. #include "libavutil/mem_internal.h"
  28. #define IDCTDSP_TEST(func) { #func, offsetof(IDCTDSPContext, func) },
  29. typedef struct {
  30. const char *name;
  31. size_t offset;
  32. } test;
  33. #define RANDOMIZE_BUFFER16(name, size) \
  34. do { \
  35. int i; \
  36. for (i = 0; i < size; ++i) { \
  37. uint16_t r = rnd() % 0x201 - 0x100; \
  38. AV_WN16A(name##0 + i, r); \
  39. AV_WN16A(name##1 + i, r); \
  40. } \
  41. } while (0)
  42. #define RANDOMIZE_BUFFER8(name, size) \
  43. do { \
  44. int i; \
  45. for (i = 0; i < size; ++i) { \
  46. uint8_t r = rnd(); \
  47. name##0[i] = r; \
  48. name##1[i] = r; \
  49. } \
  50. } while (0)
  51. static void check_add_put_clamped(void)
  52. {
  53. /* Source buffers are only as big as needed, since any over-read won't affect results */
  54. LOCAL_ALIGNED_16(int16_t, src0, [64]);
  55. LOCAL_ALIGNED_16(int16_t, src1, [64]);
  56. /* Destination buffers have borders of one row above/below and 8 columns left/right to catch overflows */
  57. LOCAL_ALIGNED_8(uint8_t, dst0, [10 * 24]);
  58. LOCAL_ALIGNED_8(uint8_t, dst1, [10 * 24]);
  59. AVCodecContext avctx = { 0 };
  60. IDCTDSPContext h;
  61. const test tests[] = {
  62. IDCTDSP_TEST(add_pixels_clamped)
  63. IDCTDSP_TEST(put_pixels_clamped)
  64. IDCTDSP_TEST(put_signed_pixels_clamped)
  65. };
  66. ff_idctdsp_init(&h, &avctx);
  67. for (size_t t = 0; t < FF_ARRAY_ELEMS(tests); ++t) {
  68. void (*func)(const int16_t *, uint8_t * ptrdiff_t) = *(void **)((intptr_t) &h + tests[t].offset);
  69. if (check_func(func, "idctdsp.%s", tests[t].name)) {
  70. declare_func(void, const int16_t *, uint8_t *, ptrdiff_t);
  71. RANDOMIZE_BUFFER16(src, 64);
  72. RANDOMIZE_BUFFER8(dst, 10 * 24);
  73. call_ref(src0, dst0 + 24 + 8, 24);
  74. call_new(src1, dst1 + 24 + 8, 24);
  75. if (memcmp(dst0, dst1, 10 * 24))
  76. fail();
  77. bench_new(src1, dst1 + 24 + 8, 24);
  78. }
  79. }
  80. }
  81. void checkasm_check_idctdsp(void)
  82. {
  83. check_add_put_clamped();
  84. report("idctdsp");
  85. }