hevc_idct.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/hevc/dsp.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); \
  31. } \
  32. } while (0)
  33. static void check_idct(HEVCDSPContext *h, int bit_depth)
  34. {
  35. int i;
  36. LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
  37. LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
  38. for (i = 2; i <= 5; i++) {
  39. int block_size = 1 << i;
  40. int size = block_size * block_size;
  41. int col_limit = block_size;
  42. declare_func(void, int16_t *coeffs, int col_limit);
  43. randomize_buffers(coeffs0, size);
  44. memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
  45. if (check_func(h->idct[i - 2], "hevc_idct_%dx%d_%d", block_size, block_size, bit_depth)) {
  46. call_ref(coeffs0, col_limit);
  47. call_new(coeffs1, col_limit);
  48. if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
  49. fail();
  50. bench_new(coeffs1, col_limit);
  51. }
  52. }
  53. }
  54. static void check_idct_dc(HEVCDSPContext *h, int bit_depth)
  55. {
  56. int i;
  57. LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
  58. LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
  59. for (i = 2; i <= 5; i++) {
  60. int block_size = 1 << i;
  61. int size = block_size * block_size;
  62. declare_func_emms(AV_CPU_FLAG_MMXEXT, void, int16_t *coeffs);
  63. randomize_buffers(coeffs0, size);
  64. memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
  65. if (check_func(h->idct_dc[i - 2], "hevc_idct_%dx%d_dc_%d", block_size, block_size, bit_depth)) {
  66. call_ref(coeffs0);
  67. call_new(coeffs1);
  68. if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
  69. fail();
  70. bench_new(coeffs1);
  71. }
  72. }
  73. }
  74. static void check_transform_luma(HEVCDSPContext *h, int bit_depth)
  75. {
  76. LOCAL_ALIGNED(32, int16_t, coeffs0, [32 * 32]);
  77. LOCAL_ALIGNED(32, int16_t, coeffs1, [32 * 32]);
  78. int block_size = 4;
  79. int size = block_size * block_size;
  80. declare_func(void, int16_t *coeffs);
  81. randomize_buffers(coeffs0, size);
  82. memcpy(coeffs1, coeffs0, sizeof(*coeffs0) * size);
  83. if (check_func(h->transform_4x4_luma, "hevc_transform_luma_4x4_%d", bit_depth)) {
  84. call_ref(coeffs0);
  85. call_new(coeffs1);
  86. if (memcmp(coeffs0, coeffs1, sizeof(*coeffs0) * size))
  87. fail();
  88. bench_new(coeffs1);
  89. }
  90. }
  91. void checkasm_check_hevc_idct(void)
  92. {
  93. int bit_depth;
  94. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  95. HEVCDSPContext h;
  96. ff_hevc_dsp_init(&h, bit_depth);
  97. check_idct_dc(&h, bit_depth);
  98. }
  99. report("idct_dc");
  100. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  101. HEVCDSPContext h;
  102. ff_hevc_dsp_init(&h, bit_depth);
  103. check_idct(&h, bit_depth);
  104. }
  105. report("idct");
  106. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  107. HEVCDSPContext h;
  108. ff_hevc_dsp_init(&h, bit_depth);
  109. check_transform_luma(&h, bit_depth);
  110. }
  111. report("transform_luma");
  112. }