You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.9KB

  1. /*
  2. * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
  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/vp9dsp.h"
  23. #include "libavutil/common.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/intreadwrite.h"
  26. static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
  27. #define SIZEOF_PIXEL ((bit_depth + 7) / 8)
  28. #define randomize_buffers() \
  29. do { \
  30. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  31. int k; \
  32. for (k = -4; k < SIZEOF_PIXEL * FFMAX(8, size); k += 4) { \
  33. uint32_t r = rnd() & mask; \
  34. AV_WN32A(a + k, r); \
  35. } \
  36. for (k = 0; k < size * SIZEOF_PIXEL; k += 4) { \
  37. uint32_t r = rnd() & mask; \
  38. AV_WN32A(l + k, r); \
  39. } \
  40. } while (0)
  41. static void check_ipred(void)
  42. {
  43. LOCAL_ALIGNED_32(uint8_t, a_buf, [64 * 2]);
  44. uint8_t *a = &a_buf[32 * 2];
  45. LOCAL_ALIGNED_32(uint8_t, l, [32 * 2]);
  46. LOCAL_ALIGNED_32(uint8_t, dst0, [32 * 32 * 2]);
  47. LOCAL_ALIGNED_32(uint8_t, dst1, [32 * 32 * 2]);
  48. VP9DSPContext dsp;
  49. int tx, mode, bit_depth;
  50. declare_func(void, uint8_t *dst, ptrdiff_t stride,
  51. const uint8_t *left, const uint8_t *top);
  52. static const char *const mode_names[N_INTRA_PRED_MODES] = {
  53. [VERT_PRED] = "vert",
  54. [HOR_PRED] = "hor",
  55. [DC_PRED] = "dc",
  56. [DIAG_DOWN_LEFT_PRED] = "diag_downleft",
  57. [DIAG_DOWN_RIGHT_PRED] = "diag_downright",
  58. [VERT_RIGHT_PRED] = "vert_right",
  59. [HOR_DOWN_PRED] = "hor_down",
  60. [VERT_LEFT_PRED] = "vert_left",
  61. [HOR_UP_PRED] = "hor_up",
  62. [TM_VP8_PRED] = "tm",
  63. [LEFT_DC_PRED] = "dc_left",
  64. [TOP_DC_PRED] = "dc_top",
  65. [DC_128_PRED] = "dc_128",
  66. [DC_127_PRED] = "dc_127",
  67. [DC_129_PRED] = "dc_129",
  68. };
  69. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  70. ff_vp9dsp_init(&dsp, bit_depth, 0);
  71. for (tx = 0; tx < 4; tx++) {
  72. int size = 4 << tx;
  73. for (mode = 0; mode < N_INTRA_PRED_MODES; mode++) {
  74. if (check_func(dsp.intra_pred[tx][mode], "vp9_%s_%dx%d_%dbpp",
  75. mode_names[mode], size, size, bit_depth)) {
  76. randomize_buffers();
  77. call_ref(dst0, size * SIZEOF_PIXEL, l, a);
  78. call_new(dst1, size * SIZEOF_PIXEL, l, a);
  79. if (memcmp(dst0, dst1, size * size * SIZEOF_PIXEL))
  80. fail();
  81. bench_new(dst1, size * SIZEOF_PIXEL,l, a);
  82. }
  83. }
  84. }
  85. }
  86. report("ipred");
  87. }
  88. #undef randomize_buffers
  89. #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
  90. #define SRC_BUF_STRIDE 72
  91. #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
  92. #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
  93. #define randomize_buffers() \
  94. do { \
  95. uint32_t mask = pixel_mask[(bit_depth - 8) >> 1]; \
  96. int k; \
  97. for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
  98. uint32_t r = rnd() & mask; \
  99. AV_WN32A(buf + k, r); \
  100. } \
  101. if (op == 1) { \
  102. for (k = 0; k < DST_BUF_SIZE; k += 4) { \
  103. uint32_t r = rnd() & mask; \
  104. AV_WN32A(dst0 + k, r); \
  105. AV_WN32A(dst1 + k, r); \
  106. } \
  107. } \
  108. } while (0)
  109. static void check_mc(void)
  110. {
  111. LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
  112. LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
  113. LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
  114. VP9DSPContext dsp;
  115. int op, hsize, bit_depth, filter, dx, dy;
  116. declare_func(void, uint8_t *dst, ptrdiff_t dst_stride,
  117. const uint8_t *ref, ptrdiff_t ref_stride,
  118. int h, int mx, int my);
  119. static const char *const filter_names[4] = {
  120. "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
  121. };
  122. static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
  123. static const char *const op_names[2] = { "put", "avg" };
  124. char str[256];
  125. for (op = 0; op < 2; op++) {
  126. for (bit_depth = 8; bit_depth <= 12; bit_depth += 2) {
  127. ff_vp9dsp_init(&dsp, bit_depth, 0);
  128. for (hsize = 0; hsize < 5; hsize++) {
  129. int size = 64 >> hsize;
  130. for (filter = 0; filter < 4; filter++) {
  131. for (dx = 0; dx < 2; dx++) {
  132. for (dy = 0; dy < 2; dy++) {
  133. if (dx || dy) {
  134. sprintf(str, "%s_%s_%d%s", op_names[op],
  135. filter_names[filter], size,
  136. subpel_names[dy][dx]);
  137. } else {
  138. sprintf(str, "%s%d", op_names[op], size);
  139. }
  140. if (check_func(dsp.mc[hsize][filter][op][dx][dy],
  141. "vp9_%s_%dbpp", str, bit_depth)) {
  142. int mx = dx ? 1 + (rnd() % 14) : 0;
  143. int my = dy ? 1 + (rnd() % 14) : 0;
  144. randomize_buffers();
  145. call_ref(dst0, size * SIZEOF_PIXEL,
  146. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  147. size, mx, my);
  148. call_new(dst1, size * SIZEOF_PIXEL,
  149. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  150. size, mx, my);
  151. if (memcmp(dst0, dst1, DST_BUF_SIZE))
  152. fail();
  153. // simd implementations for each filter of subpel
  154. // functions are identical
  155. if (filter >= 1 && filter <= 2) continue;
  156. // 10/12 bpp for bilin are identical
  157. if (bit_depth == 12 && filter == 3) continue;
  158. bench_new(dst1, size * SIZEOF_PIXEL,
  159. src, SRC_BUF_STRIDE * SIZEOF_PIXEL,
  160. size, mx, my);
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. report("mc");
  169. }
  170. void checkasm_check_vp9dsp(void)
  171. {
  172. check_ipred();
  173. check_mc();
  174. }