comp_avg_pred_test.cc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. ASSERT_TRUE(avg->TopLeftPixel() != NULL);
  25. ASSERT_TRUE(pred.TopLeftPixel() != NULL);
  26. ASSERT_TRUE(ref.TopLeftPixel() != NULL);
  27. for (int y = 0; y < height; ++y) {
  28. for (int x = 0; x < width; ++x) {
  29. avg->TopLeftPixel()[y * avg->stride() + x] =
  30. avg_with_rounding(pred.TopLeftPixel()[y * pred.stride() + x],
  31. ref.TopLeftPixel()[y * ref.stride() + x]);
  32. }
  33. }
  34. }
  35. class AvgPredTest : public ::testing::TestWithParam<AvgPredFunc> {
  36. public:
  37. virtual void SetUp() {
  38. avg_pred_func_ = GetParam();
  39. rnd_.Reset(ACMRandom::DeterministicSeed());
  40. }
  41. protected:
  42. AvgPredFunc avg_pred_func_;
  43. ACMRandom rnd_;
  44. };
  45. TEST_P(AvgPredTest, SizeCombinations) {
  46. // This is called as part of the sub pixel variance. As such it must be one of
  47. // the variance block sizes.
  48. for (int width_pow = 2; width_pow <= 6; ++width_pow) {
  49. for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
  50. ++height_pow) {
  51. // Don't test 4x2 or 64x128
  52. if (height_pow == 1 || height_pow == 7) continue;
  53. // The sse2 special-cases when ref width == stride, so make sure to test
  54. // it.
  55. for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
  56. const int width = 1 << width_pow;
  57. const int height = 1 << height_pow;
  58. // Only the reference buffer may have a stride not equal to width.
  59. Buffer<uint8_t> ref =
  60. Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
  61. ASSERT_TRUE(ref.Init());
  62. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  63. ASSERT_TRUE(pred.Init());
  64. Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
  65. ASSERT_TRUE(avg_ref.Init());
  66. Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
  67. ASSERT_TRUE(avg_chk.Init());
  68. ref.Set(&rnd_, &ACMRandom::Rand8);
  69. pred.Set(&rnd_, &ACMRandom::Rand8);
  70. reference_pred(pred, ref, width, height, &avg_ref);
  71. ASM_REGISTER_STATE_CHECK(
  72. avg_pred_func_(avg_chk.TopLeftPixel(), pred.TopLeftPixel(), width,
  73. height, ref.TopLeftPixel(), ref.stride()));
  74. EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
  75. if (HasFailure()) {
  76. printf("Width: %d Height: %d\n", width, height);
  77. avg_chk.PrintDifference(avg_ref);
  78. return;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. TEST_P(AvgPredTest, CompareReferenceRandom) {
  85. const int width = 64;
  86. const int height = 32;
  87. Buffer<uint8_t> ref = Buffer<uint8_t>(width, height, 8);
  88. ASSERT_TRUE(ref.Init());
  89. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  90. ASSERT_TRUE(pred.Init());
  91. Buffer<uint8_t> avg_ref = Buffer<uint8_t>(width, height, 0, 16);
  92. ASSERT_TRUE(avg_ref.Init());
  93. Buffer<uint8_t> avg_chk = Buffer<uint8_t>(width, height, 0, 16);
  94. ASSERT_TRUE(avg_chk.Init());
  95. for (int i = 0; i < 500; ++i) {
  96. ref.Set(&rnd_, &ACMRandom::Rand8);
  97. pred.Set(&rnd_, &ACMRandom::Rand8);
  98. reference_pred(pred, ref, width, height, &avg_ref);
  99. ASM_REGISTER_STATE_CHECK(avg_pred_func_(avg_chk.TopLeftPixel(),
  100. pred.TopLeftPixel(), width, height,
  101. ref.TopLeftPixel(), ref.stride()));
  102. EXPECT_TRUE(avg_chk.CheckValues(avg_ref));
  103. if (HasFailure()) {
  104. printf("Width: %d Height: %d\n", width, height);
  105. avg_chk.PrintDifference(avg_ref);
  106. return;
  107. }
  108. }
  109. }
  110. TEST_P(AvgPredTest, DISABLED_Speed) {
  111. for (int width_pow = 2; width_pow <= 6; ++width_pow) {
  112. for (int height_pow = width_pow - 1; height_pow <= width_pow + 1;
  113. ++height_pow) {
  114. // Don't test 4x2 or 64x128
  115. if (height_pow == 1 || height_pow == 7) continue;
  116. for (int ref_padding = 0; ref_padding < 2; ref_padding++) {
  117. const int width = 1 << width_pow;
  118. const int height = 1 << height_pow;
  119. Buffer<uint8_t> ref =
  120. Buffer<uint8_t>(width, height, ref_padding ? 8 : 0);
  121. ASSERT_TRUE(ref.Init());
  122. Buffer<uint8_t> pred = Buffer<uint8_t>(width, height, 0, 16);
  123. ASSERT_TRUE(pred.Init());
  124. Buffer<uint8_t> avg = Buffer<uint8_t>(width, height, 0, 16);
  125. ASSERT_TRUE(avg.Init());
  126. ref.Set(&rnd_, &ACMRandom::Rand8);
  127. pred.Set(&rnd_, &ACMRandom::Rand8);
  128. vpx_usec_timer timer;
  129. vpx_usec_timer_start(&timer);
  130. for (int i = 0; i < 10000000 / (width * height); ++i) {
  131. avg_pred_func_(avg.TopLeftPixel(), pred.TopLeftPixel(), width, height,
  132. ref.TopLeftPixel(), ref.stride());
  133. }
  134. vpx_usec_timer_mark(&timer);
  135. const int elapsed_time =
  136. static_cast<int>(vpx_usec_timer_elapsed(&timer));
  137. printf("Average Test (ref_padding: %d) %dx%d time: %5d us\n",
  138. ref_padding, width, height, elapsed_time);
  139. }
  140. }
  141. }
  142. }
  143. INSTANTIATE_TEST_CASE_P(C, AvgPredTest,
  144. ::testing::Values(&vpx_comp_avg_pred_c));
  145. #if HAVE_SSE2
  146. INSTANTIATE_TEST_CASE_P(SSE2, AvgPredTest,
  147. ::testing::Values(&vpx_comp_avg_pred_sse2));
  148. #endif // HAVE_SSE2
  149. #if HAVE_NEON
  150. INSTANTIATE_TEST_CASE_P(NEON, AvgPredTest,
  151. ::testing::Values(&vpx_comp_avg_pred_neon));
  152. #endif // HAVE_NEON
  153. #if HAVE_VSX
  154. INSTANTIATE_TEST_CASE_P(VSX, AvgPredTest,
  155. ::testing::Values(&vpx_comp_avg_pred_vsx));
  156. #endif // HAVE_VSX
  157. } // namespace