vp9_subtract_test.cc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 2012 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 "./vp9_rtcd.h"
  12. #include "./vpx_config.h"
  13. #include "./vpx_dsp_rtcd.h"
  14. #include "test/acm_random.h"
  15. #include "test/bench.h"
  16. #include "test/clear_system_state.h"
  17. #include "test/register_state_check.h"
  18. #include "vp9/common/vp9_blockd.h"
  19. #include "vpx_ports/msvc.h"
  20. #include "vpx_mem/vpx_mem.h"
  21. typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
  22. ptrdiff_t diff_stride, const uint8_t *src_ptr,
  23. ptrdiff_t src_stride, const uint8_t *pred_ptr,
  24. ptrdiff_t pred_stride);
  25. namespace vp9 {
  26. class VP9SubtractBlockTest : public AbstractBench,
  27. public ::testing::TestWithParam<SubtractFunc> {
  28. public:
  29. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  30. protected:
  31. virtual void Run() {
  32. GetParam()(block_height_, block_width_, diff_, block_width_, src_,
  33. block_width_, pred_, block_width_);
  34. }
  35. void SetupBlocks(BLOCK_SIZE bsize) {
  36. block_width_ = 4 * num_4x4_blocks_wide_lookup[bsize];
  37. block_height_ = 4 * num_4x4_blocks_high_lookup[bsize];
  38. diff_ = reinterpret_cast<int16_t *>(
  39. vpx_memalign(16, sizeof(*diff_) * block_width_ * block_height_ * 2));
  40. pred_ = reinterpret_cast<uint8_t *>(
  41. vpx_memalign(16, block_width_ * block_height_ * 2));
  42. src_ = reinterpret_cast<uint8_t *>(
  43. vpx_memalign(16, block_width_ * block_height_ * 2));
  44. }
  45. int block_width_;
  46. int block_height_;
  47. int16_t *diff_;
  48. uint8_t *pred_;
  49. uint8_t *src_;
  50. };
  51. using libvpx_test::ACMRandom;
  52. TEST_P(VP9SubtractBlockTest, DISABLED_Speed) {
  53. ACMRandom rnd(ACMRandom::DeterministicSeed());
  54. for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
  55. bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
  56. SetupBlocks(bsize);
  57. RunNTimes(100000000 / (block_height_ * block_width_));
  58. char block_size[16];
  59. snprintf(block_size, sizeof(block_size), "%dx%d", block_height_,
  60. block_width_);
  61. char title[100];
  62. snprintf(title, sizeof(title), "%8s ", block_size);
  63. PrintMedian(title);
  64. vpx_free(diff_);
  65. vpx_free(pred_);
  66. vpx_free(src_);
  67. }
  68. }
  69. TEST_P(VP9SubtractBlockTest, SimpleSubtract) {
  70. ACMRandom rnd(ACMRandom::DeterministicSeed());
  71. for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
  72. bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
  73. SetupBlocks(bsize);
  74. for (int n = 0; n < 100; n++) {
  75. for (int r = 0; r < block_height_; ++r) {
  76. for (int c = 0; c < block_width_ * 2; ++c) {
  77. src_[r * block_width_ * 2 + c] = rnd.Rand8();
  78. pred_[r * block_width_ * 2 + c] = rnd.Rand8();
  79. }
  80. }
  81. GetParam()(block_height_, block_width_, diff_, block_width_, src_,
  82. block_width_, pred_, block_width_);
  83. for (int r = 0; r < block_height_; ++r) {
  84. for (int c = 0; c < block_width_; ++c) {
  85. EXPECT_EQ(diff_[r * block_width_ + c],
  86. (src_[r * block_width_ + c] - pred_[r * block_width_ + c]))
  87. << "r = " << r << ", c = " << c
  88. << ", bs = " << static_cast<int>(bsize);
  89. }
  90. }
  91. GetParam()(block_height_, block_width_, diff_, block_width_ * 2, src_,
  92. block_width_ * 2, pred_, block_width_ * 2);
  93. for (int r = 0; r < block_height_; ++r) {
  94. for (int c = 0; c < block_width_; ++c) {
  95. EXPECT_EQ(diff_[r * block_width_ * 2 + c],
  96. (src_[r * block_width_ * 2 + c] -
  97. pred_[r * block_width_ * 2 + c]))
  98. << "r = " << r << ", c = " << c
  99. << ", bs = " << static_cast<int>(bsize);
  100. }
  101. }
  102. }
  103. vpx_free(diff_);
  104. vpx_free(pred_);
  105. vpx_free(src_);
  106. }
  107. }
  108. INSTANTIATE_TEST_CASE_P(C, VP9SubtractBlockTest,
  109. ::testing::Values(vpx_subtract_block_c));
  110. #if HAVE_SSE2
  111. INSTANTIATE_TEST_CASE_P(SSE2, VP9SubtractBlockTest,
  112. ::testing::Values(vpx_subtract_block_sse2));
  113. #endif
  114. #if HAVE_NEON
  115. INSTANTIATE_TEST_CASE_P(NEON, VP9SubtractBlockTest,
  116. ::testing::Values(vpx_subtract_block_neon));
  117. #endif
  118. #if HAVE_MSA
  119. INSTANTIATE_TEST_CASE_P(MSA, VP9SubtractBlockTest,
  120. ::testing::Values(vpx_subtract_block_msa));
  121. #endif
  122. #if HAVE_MMI
  123. INSTANTIATE_TEST_CASE_P(MMI, VP9SubtractBlockTest,
  124. ::testing::Values(vpx_subtract_block_mmi));
  125. #endif
  126. #if HAVE_VSX
  127. INSTANTIATE_TEST_CASE_P(VSX, VP9SubtractBlockTest,
  128. ::testing::Values(vpx_subtract_block_vsx));
  129. #endif
  130. } // namespace vp9