bswapdsp.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/bswapdsp.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. #define BUF_SIZE 512
  27. #define randomize_buffers() \
  28. do { \
  29. int i; \
  30. for (i = 0; i < BUF_SIZE; i += 4) { \
  31. uint32_t r = rnd(); \
  32. AV_WN32A(src0 + i, r); \
  33. AV_WN32A(src1 + i, r); \
  34. r = rnd(); \
  35. AV_WN32A(dst0 + i, r); \
  36. AV_WN32A(dst1 + i, r); \
  37. } \
  38. } while (0)
  39. #define check_bswap(type) \
  40. do { \
  41. int w; \
  42. declare_func(void, type *dst, const type *src, int w); \
  43. \
  44. for (w = 0; w < BUF_SIZE / sizeof(type); w++) { \
  45. int offset = (BUF_SIZE / sizeof(type) - w) & 15; /* Test various alignments */ \
  46. randomize_buffers(); \
  47. call_ref((type *)dst0 + offset, (type *)src0 + offset, w); \
  48. call_new((type *)dst1 + offset, (type *)src1 + offset, w); \
  49. if (memcmp(src0, src1, BUF_SIZE) || memcmp(dst0, dst1, BUF_SIZE)) \
  50. fail(); \
  51. bench_new((type *)dst1 + offset, (type *)src1 + offset, w); \
  52. } \
  53. } while (0)
  54. void checkasm_check_bswapdsp(void)
  55. {
  56. LOCAL_ALIGNED_16(uint8_t, src0, [BUF_SIZE]);
  57. LOCAL_ALIGNED_16(uint8_t, src1, [BUF_SIZE]);
  58. LOCAL_ALIGNED_16(uint8_t, dst0, [BUF_SIZE]);
  59. LOCAL_ALIGNED_16(uint8_t, dst1, [BUF_SIZE]);
  60. BswapDSPContext h;
  61. ff_bswapdsp_init(&h);
  62. if (check_func(h.bswap_buf, "bswap_buf"))
  63. check_bswap(uint32_t);
  64. if (check_func(h.bswap16_buf, "bswap16_buf"))
  65. check_bswap(uint16_t);
  66. report("bswap");
  67. }