comp_avg_pred_test.cc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2017 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "third_party/googletest/src/include/gtest/gtest.h"
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "test/acm_random.h"
  13. #include "test/buffer.h"
  14. #include "test/register_state_check.h"
  15. #include "vpx_ports/vpx_timer.h"
  16. namespace {
  17. using ::libvpx_test::ACMRandom;
  18. using ::libvpx_test::Buffer;
  19. typedef void (*AvgPredFunc)(uint8_t *a, const uint8_t *b, int w, int h,
  20. const uint8_t *c, int c_stride);
  21. uint8_t avg_with_rounding(uint8_t a, uint8_t b) { return (a + b + 1) >> 1; }
  22. void reference_pred(const Buffer<uint8_t> &pred, const Buffer<uint8_t> &ref,
  23. int width, int height, Buffer<uint8_t> *avg) {
  24. for (int y = 0; y < height; ++y) {
  25. for (int x = 0; x < width; ++x) {
  26. avg->TopLeftPixel()[y * avg->stride() + x] =
  27. avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x],
  28. ref.TopLeftPixel()[y * ref.stride() + x]);
  29. }
  30. }
  31. }
  32. class AvgPredTest : public ::testing::TestWithParam<AvgPredFunc> {
  33. public:
  34. virtual void SetUp() {
  35. avg_pred_func_ = GetParam();
  36. rnd_.Reset(ACMRandom::DeterministicSeed());
  37. }
  38. protected:
  39. AvgPredFunc avg_pred_func_;
  40. ACMRandom rnd_;
  41. };
  42. TEST_P(AvgPredTest, SizeCombinations) {
  43. // This is called as part of the sub pixel variance. As such it must be one of
  44. // the variance block sizes.
  45. for (int width_pow = 2; width_pow <= 6; ++width_pow) {
  46. for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
  47. ++height_pow) {
  48. // Don't test 4x2 or 64x128
  49. if (height_pow == 1 || height_pow == 7) continue;
  50. // The sse2 special-cases when ref width == stride, so make sure to test
  51. // it.
  52. for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
  53. const int width = 1 << width_pow;
  54. const int height = 1 << height_pow;
  55. // Only the reference buffer may have a stride not equal to width.
  56. Buffer<uint8_t> ref =
  57. Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
  58. ASSERT_TRUE(ref.Init());
  59. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  60. ASSERT_TRUE(pred.Init());
  61. Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
  62. ASSERT_TRUE(avg_ref.Init());
  63. Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
  64. ASSERT_TRUE(avg_chk.Init());
  65. ref.Set(&rnd_, &ACMRandom::Rand8);
  66. pred.Set(&rnd_, &ACMRandom::Rand8);
  67. reference_pred(pred, ref, width, height, &avg_ref);
  68. ASM_REGISTER_STATE_CHECK(
  69. avg_pred_func_(avg_chk.TopLeftPixel(), pred.TopLeftPixel(), width,
  70. height, ref.TopLeftPixel(), ref.stride()));
  71. EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
  72. if (HasFailure()) {
  73. printf("Width: %d Height: %d\n", width, height);
  74. avg_chk.PrintDifference(avg_ref);
  75. return;
  76. }
  77. }
  78. }
  79. }
  80. }
  81. TEST_P(AvgPredTest, CompareReferenceRandom) {
  82. const int width = 64;
  83. const int height = 32;
  84. Buffer<uint8_t> ref = Buffer<uint8_t>(width, height, 8);
  85. ASSERT_TRUE(ref.Init());
  86. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  87. ASSERT_TRUE(pred.Init());
  88. Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
  89. ASSERT_TRUE(avg_ref.Init());
  90. Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
  91. ASSERT_TRUE(avg_chk.Init());
  92. for (int i = 0; i < 500; ++i) {
  93. ref.Set(&rnd_, &ACMRandom::Rand8);
  94. pred.Set(&rnd_, &ACMRandom::Rand8);
  95. reference_pred(pred, ref, width, height, &avg_ref);
  96. ASM_REGISTER_STATE_CHECK(avg_pred_func_(avg_chk.TopLeftPixel(),
  97. pred.TopLeftPixel(), width, height,
  98. ref.TopLeftPixel(), ref.stride()));
  99. EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
  100. if (HasFailure()) {
  101. printf("Width: %d Height: %d\n", width, height);
  102. avg_chk.PrintDifference(avg_ref);
  103. return;
  104. }
  105. }
  106. }
  107. TEST_P(AvgPredTest, DISABLED_Speed) {
  108. for (int width_pow = 2; width_pow <= 6; ++width_pow) {
  109. for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
  110. ++height_pow) {
  111. // Don't test 4x2 or 64x128
  112. if (height_pow == 1 || height_pow == 7) continue;
  113. for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
  114. const int width = 1 << width_pow;
  115. const int height = 1 << height_pow;
  116. Buffer<uint8_t> ref =
  117. Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
  118. ASSERT_TRUE(ref.Init());
  119. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  120. ASSERT_TRUE(pred.Init());
  121. Buffer<uint8_t> avg = Buffer<uint8_t>(width, height, 0, 16);
  122. ASSERT_TRUE(avg.Init());
  123. ref.Set(&rnd_, &ACMRandom::Rand8);
  124. pred.Set(&rnd_, &ACMRandom::Rand8);
  125. vpx_usec_timer timer;
  126. vpx_usec_timer_start(&timer);
  127. for (int i = 0; i < 10000000 / (width * height); ++i) {
  128. avg_pred_func_(avg.TopLeftPixel(), pred.TopLeftPixel(), width, height,
  129. ref.TopLeftPixel(), ref.stride());
  130. }
  131. vpx_usec_timer_mark(&timer);
  132. const int elapsed_time =
  133. static_cast<int>(vpx_usec_timer_elapsed(&timer));
  134. printf("Average Test (ref_padding: %d) %dx%d time: %5d us\n",
  135. ref_padding, width, height, elapsed_time);
  136. }
  137. }
  138. }
  139. }
  140. INSTANTIATE_TEST_CASE_P(C, AvgPredTest,
  141. ::testing::Values(&vpx_comp_avg_pred_c));
  142. #if HAVE_SSE2
  143. INSTANTIATE_TEST_CASE_P(SSE2, AvgPredTest,
  144. ::testing::Values(&vpx_comp_avg_pred_sse2));
  145. #endif // HAVE_SSE2
  146. #if HAVE_NEON
  147. INSTANTIATE_TEST_CASE_P(NEON, AvgPredTest,
  148. ::testing::Values(&vpx_comp_avg_pred_neon));
  149. #endif // HAVE_NEON
  150. #if HAVE_VSX
  151. INSTANTIATE_TEST_CASE_P(VSX, AvgPredTest,
  152. ::testing::Values(&vpx_comp_avg_pred_vsx));
  153. #endif // HAVE_VSX
  154. } // namespace