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.

128 lines
5.0KB

  1. /*
  2. * Copyright (c) 2015 Ronald S. Bultje <rsbultje@gmail.com>
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; 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/common.h"
  22. #include "libavutil/internal.h"
  23. #include "libavutil/intreadwrite.h"
  24. #include "libavcodec/vp9.h"
  25. #include "checkasm.h"
  26. static const uint32_t pixel_mask[3] = { 0xffffffff, 0x03ff03ff, 0x0fff0fff };
  27. #define BIT_DEPTH 8
  28. #define SIZEOF_PIXEL ((BIT_DEPTH + 7) / 8)
  29. #define DST_BUF_SIZE (size * size * SIZEOF_PIXEL)
  30. #define SRC_BUF_STRIDE 72
  31. #define SRC_BUF_SIZE ((size + 7) * SRC_BUF_STRIDE * SIZEOF_PIXEL)
  32. #define src (buf + 3 * SIZEOF_PIXEL * (SRC_BUF_STRIDE + 1))
  33. #define randomize_buffers() \
  34. do { \
  35. uint32_t mask = pixel_mask[(BIT_DEPTH - 8) >> 1]; \
  36. int k; \
  37. for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
  38. uint32_t r = rnd() & mask; \
  39. AV_WN32A(buf + k, r); \
  40. } \
  41. if (op == 1) { \
  42. for (k = 0; k < DST_BUF_SIZE; k += 4) { \
  43. uint32_t r = rnd() & mask; \
  44. AV_WN32A(dst0 + k, r); \
  45. AV_WN32A(dst1 + k, r); \
  46. } \
  47. } \
  48. } while (0)
  49. static void check_mc(void)
  50. {
  51. static const char *const filter_names[4] = {
  52. "8tap_smooth", "8tap_regular", "8tap_sharp", "bilin"
  53. };
  54. static const char *const subpel_names[2][2] = { { "", "h" }, { "v", "hv" } };
  55. static const char *const op_names[2] = { "put", "avg" };
  56. LOCAL_ALIGNED_32(uint8_t, buf, [72 * 72 * 2]);
  57. LOCAL_ALIGNED_32(uint8_t, dst0, [64 * 64 * 2]);
  58. LOCAL_ALIGNED_32(uint8_t, dst1, [64 * 64 * 2]);
  59. char str[256];
  60. VP9DSPContext dsp;
  61. int op, hsize, filter, dx, dy;
  62. declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT,
  63. void, uint8_t *dst, const uint8_t *ref,
  64. ptrdiff_t dst_stride, ptrdiff_t ref_stride,
  65. int h, int mx, int my);
  66. for (op = 0; op < 2; op++) {
  67. ff_vp9dsp_init(&dsp);
  68. for (hsize = 0; hsize < 5; hsize++) {
  69. int size = 64 >> hsize;
  70. for (filter = 0; filter < 4; filter++) {
  71. for (dx = 0; dx < 2; dx++) {
  72. for (dy = 0; dy < 2; dy++) {
  73. if (dx || dy) {
  74. snprintf(str, sizeof(str), "%s_%s_%d%s", op_names[op],
  75. filter_names[filter], size,
  76. subpel_names[dy][dx]);
  77. } else {
  78. snprintf(str, sizeof(str), "%s%d", op_names[op], size);
  79. }
  80. if (check_func(dsp.mc[hsize][filter][op][dx][dy],
  81. "vp9_%s", str)) {
  82. int mx = dx ? 1 + (rnd() % 14) : 0;
  83. int my = dy ? 1 + (rnd() % 14) : 0;
  84. randomize_buffers();
  85. call_ref(dst0, src,
  86. size * SIZEOF_PIXEL,
  87. SRC_BUF_STRIDE * SIZEOF_PIXEL,
  88. size, mx, my);
  89. call_new(dst1, src,
  90. size * SIZEOF_PIXEL,
  91. SRC_BUF_STRIDE * SIZEOF_PIXEL,
  92. size, mx, my);
  93. if (memcmp(dst0, dst1, DST_BUF_SIZE))
  94. fail();
  95. // SIMD implementations for each filter of subpel
  96. // functions are identical
  97. if (filter >= 1 && filter <= 2) continue;
  98. bench_new(dst1, src, size * SIZEOF_PIXEL,
  99. SRC_BUF_STRIDE * SIZEOF_PIXEL,
  100. size, mx, my);
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. report("mc");
  108. }
  109. void checkasm_check_vp9dsp(void)
  110. {
  111. check_mc();
  112. }