hevc_add_res.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2016 Alexandra Hájková
  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 "libavutil/intreadwrite.h"
  22. #include "libavutil/mem_internal.h"
  23. #include "libavcodec/hevcdsp.h"
  24. #include "checkasm.h"
  25. #define randomize_buffers(buf, size) \
  26. do { \
  27. int j; \
  28. for (j = 0; j < size; j++) { \
  29. int16_t r = rnd(); \
  30. AV_WN16A(buf + j, r >> 3); \
  31. } \
  32. } while (0)
  33. #define randomize_buffers2(buf, size, mask) \
  34. do { \
  35. int j; \
  36. for (j = 0; j < size; j++) \
  37. AV_WN16A(buf + j * 2, rnd() & mask); \
  38. } while (0)
  39. static void compare_add_res(int size, ptrdiff_t stride, int overflow_test, int mask)
  40. {
  41. LOCAL_ALIGNED_32(int16_t, res0, [32 * 32]);
  42. LOCAL_ALIGNED_32(int16_t, res1, [32 * 32]);
  43. LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
  44. LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
  45. declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *dst, int16_t *res, ptrdiff_t stride);
  46. randomize_buffers(res0, size);
  47. randomize_buffers2(dst0, size, mask);
  48. if (overflow_test)
  49. res0[0] = 0x8000;
  50. memcpy(res1, res0, sizeof(*res0) * size);
  51. memcpy(dst1, dst0, sizeof(int16_t) * size);
  52. call_ref(dst0, res0, stride);
  53. call_new(dst1, res1, stride);
  54. if (memcmp(dst0, dst1, size))
  55. fail();
  56. bench_new(dst1, res1, stride);
  57. }
  58. static void check_add_res(HEVCDSPContext *h, int bit_depth)
  59. {
  60. int i;
  61. int mask = bit_depth == 8 ? 0xFFFF : bit_depth == 10 ? 0x03FF : 0x07FF;
  62. for (i = 2; i <= 5; i++) {
  63. int block_size = 1 << i;
  64. int size = block_size * block_size;
  65. ptrdiff_t stride = block_size << (bit_depth > 8);
  66. if (check_func(h->add_residual[i - 2], "hevc_add_res_%dx%d_%d", block_size, block_size, bit_depth)) {
  67. compare_add_res(size, stride, 0, mask);
  68. // overflow test for res = -32768
  69. compare_add_res(size, stride, 1, mask);
  70. }
  71. }
  72. }
  73. void checkasm_check_hevc_add_res(void)
  74. {
  75. int bit_depth;
  76. for (bit_depth = 8; bit_depth <= 12; bit_depth++) {
  77. HEVCDSPContext h;
  78. ff_hevc_dsp_init(&h, bit_depth);
  79. check_add_res(&h, bit_depth);
  80. }
  81. report("add_residual");
  82. }