exrdsp.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2017 James Almer
  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/defs.h"
  23. #include "libavcodec/exrdsp.h"
  24. #include "libavutil/intreadwrite.h"
  25. #include "libavutil/mem_internal.h"
  26. #define BUF_SIZE 5120
  27. #define PADDED_BUF_SIZE BUF_SIZE+AV_INPUT_BUFFER_PADDING_SIZE*2
  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(src + i, r); \
  34. } \
  35. } while (0)
  36. static void check_reorder_pixels(void) {
  37. LOCAL_ALIGNED_32(uint8_t, src, [PADDED_BUF_SIZE]);
  38. LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
  39. LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
  40. declare_func(void, uint8_t *dst, const uint8_t *src, ptrdiff_t size);
  41. memset(src, 0, PADDED_BUF_SIZE);
  42. memset(dst_ref, 0, PADDED_BUF_SIZE);
  43. memset(dst_new, 0, PADDED_BUF_SIZE);
  44. randomize_buffers();
  45. call_ref(dst_ref, src, BUF_SIZE);
  46. call_new(dst_new, src, BUF_SIZE);
  47. if (memcmp(dst_ref, dst_new, BUF_SIZE))
  48. fail();
  49. bench_new(dst_new, src, BUF_SIZE);
  50. }
  51. static void check_predictor(void) {
  52. LOCAL_ALIGNED_32(uint8_t, src, [PADDED_BUF_SIZE]);
  53. LOCAL_ALIGNED_32(uint8_t, dst_ref, [PADDED_BUF_SIZE]);
  54. LOCAL_ALIGNED_32(uint8_t, dst_new, [PADDED_BUF_SIZE]);
  55. declare_func(void, uint8_t *src, ptrdiff_t size);
  56. memset(src, 0, PADDED_BUF_SIZE);
  57. randomize_buffers();
  58. memcpy(dst_ref, src, PADDED_BUF_SIZE);
  59. memcpy(dst_new, src, PADDED_BUF_SIZE);
  60. call_ref(dst_ref, BUF_SIZE);
  61. call_new(dst_new, BUF_SIZE);
  62. if (memcmp(dst_ref, dst_new, BUF_SIZE))
  63. fail();
  64. bench_new(dst_new, BUF_SIZE);
  65. }
  66. void checkasm_check_exrdsp(void)
  67. {
  68. ExrDSPContext h;
  69. ff_exrdsp_init(&h);
  70. if (check_func(h.reorder_pixels, "reorder_pixels"))
  71. check_reorder_pixels();
  72. report("reorder_pixels");
  73. if (check_func(h.predictor, "predictor"))
  74. check_predictor();
  75. report("predictor");
  76. }