vp9_block_error_test.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Copyright (c) 2014 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 <cmath>
  11. #include <cstdlib>
  12. #include <string>
  13. #include <tuple>
  14. #include "third_party/googletest/src/include/gtest/gtest.h"
  15. #include "./vpx_config.h"
  16. #include "./vp9_rtcd.h"
  17. #include "test/acm_random.h"
  18. #include "test/clear_system_state.h"
  19. #include "test/register_state_check.h"
  20. #include "test/util.h"
  21. #include "vp9/common/vp9_entropy.h"
  22. #include "vpx/vpx_codec.h"
  23. #include "vpx/vpx_integer.h"
  24. #include "vpx_dsp/vpx_dsp_common.h"
  25. using libvpx_test::ACMRandom;
  26. namespace {
  27. const int kNumIterations = 1000;
  28. typedef int64_t (*HBDBlockErrorFunc)(const tran_low_t *coeff,
  29. const tran_low_t *dqcoeff,
  30. intptr_t block_size, int64_t *ssz,
  31. int bps);
  32. typedef std::tuple<HBDBlockErrorFunc, HBDBlockErrorFunc, vpx_bit_depth_t>
  33. BlockErrorParam;
  34. typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff,
  35. const tran_low_t *dqcoeff,
  36. intptr_t block_size, int64_t *ssz);
  37. template <BlockErrorFunc fn>
  38. int64_t BlockError8BitWrapper(const tran_low_t *coeff,
  39. const tran_low_t *dqcoeff, intptr_t block_size,
  40. int64_t *ssz, int bps) {
  41. EXPECT_EQ(bps, 8);
  42. return fn(coeff, dqcoeff, block_size, ssz);
  43. }
  44. class BlockErrorTest : public ::testing::TestWithParam<BlockErrorParam> {
  45. public:
  46. virtual ~BlockErrorTest() {}
  47. virtual void SetUp() {
  48. error_block_op_ = GET_PARAM(0);
  49. ref_error_block_op_ = GET_PARAM(1);
  50. bit_depth_ = GET_PARAM(2);
  51. }
  52. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  53. protected:
  54. vpx_bit_depth_t bit_depth_;
  55. HBDBlockErrorFunc error_block_op_;
  56. HBDBlockErrorFunc ref_error_block_op_;
  57. };
  58. TEST_P(BlockErrorTest, OperationCheck) {
  59. ACMRandom rnd(ACMRandom::DeterministicSeed());
  60. DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  61. DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
  62. int err_count_total = 0;
  63. int first_failure = -1;
  64. intptr_t block_size;
  65. int64_t ssz;
  66. int64_t ret;
  67. int64_t ref_ssz;
  68. int64_t ref_ret;
  69. const int msb = bit_depth_ + 8 - 1;
  70. for (int i = 0; i < kNumIterations; ++i) {
  71. int err_count = 0;
  72. block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
  73. for (int j = 0; j < block_size; j++) {
  74. // coeff and dqcoeff will always have at least the same sign, and this
  75. // can be used for optimization, so generate test input precisely.
  76. if (rnd(2)) {
  77. // Positive number
  78. coeff[j] = rnd(1 << msb);
  79. dqcoeff[j] = rnd(1 << msb);
  80. } else {
  81. // Negative number
  82. coeff[j] = -rnd(1 << msb);
  83. dqcoeff[j] = -rnd(1 << msb);
  84. }
  85. }
  86. ref_ret =
  87. ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
  88. ASM_REGISTER_STATE_CHECK(
  89. ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
  90. err_count += (ref_ret != ret) | (ref_ssz != ssz);
  91. if (err_count && !err_count_total) {
  92. first_failure = i;
  93. }
  94. err_count_total += err_count;
  95. }
  96. EXPECT_EQ(0, err_count_total)
  97. << "Error: Error Block Test, C output doesn't match optimized output. "
  98. << "First failed at test case " << first_failure;
  99. }
  100. TEST_P(BlockErrorTest, ExtremeValues) {
  101. ACMRandom rnd(ACMRandom::DeterministicSeed());
  102. DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  103. DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
  104. int err_count_total = 0;
  105. int first_failure = -1;
  106. intptr_t block_size;
  107. int64_t ssz;
  108. int64_t ret;
  109. int64_t ref_ssz;
  110. int64_t ref_ret;
  111. const int msb = bit_depth_ + 8 - 1;
  112. int max_val = ((1 << msb) - 1);
  113. for (int i = 0; i < kNumIterations; ++i) {
  114. int err_count = 0;
  115. int k = (i / 9) % 9;
  116. // Change the maximum coeff value, to test different bit boundaries
  117. if (k == 8 && (i % 9) == 0) {
  118. max_val >>= 1;
  119. }
  120. block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
  121. for (int j = 0; j < block_size; j++) {
  122. if (k < 4) {
  123. // Test at positive maximum values
  124. coeff[j] = k % 2 ? max_val : 0;
  125. dqcoeff[j] = (k >> 1) % 2 ? max_val : 0;
  126. } else if (k < 8) {
  127. // Test at negative maximum values
  128. coeff[j] = k % 2 ? -max_val : 0;
  129. dqcoeff[j] = (k >> 1) % 2 ? -max_val : 0;
  130. } else {
  131. if (rnd(2)) {
  132. // Positive number
  133. coeff[j] = rnd(1 << 14);
  134. dqcoeff[j] = rnd(1 << 14);
  135. } else {
  136. // Negative number
  137. coeff[j] = -rnd(1 << 14);
  138. dqcoeff[j] = -rnd(1 << 14);
  139. }
  140. }
  141. }
  142. ref_ret =
  143. ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
  144. ASM_REGISTER_STATE_CHECK(
  145. ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
  146. err_count += (ref_ret != ret) | (ref_ssz != ssz);
  147. if (err_count && !err_count_total) {
  148. first_failure = i;
  149. }
  150. err_count_total += err_count;
  151. }
  152. EXPECT_EQ(0, err_count_total)
  153. << "Error: Error Block Test, C output doesn't match optimized output. "
  154. << "First failed at test case " << first_failure;
  155. }
  156. using std::make_tuple;
  157. #if HAVE_SSE2
  158. const BlockErrorParam sse2_block_error_tests[] = {
  159. #if CONFIG_VP9_HIGHBITDEPTH
  160. make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
  161. VPX_BITS_10),
  162. make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
  163. VPX_BITS_12),
  164. make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
  165. VPX_BITS_8),
  166. #endif // CONFIG_VP9_HIGHBITDEPTH
  167. make_tuple(&BlockError8BitWrapper<vp9_block_error_sse2>,
  168. &BlockError8BitWrapper<vp9_block_error_c>, VPX_BITS_8)
  169. };
  170. INSTANTIATE_TEST_CASE_P(SSE2, BlockErrorTest,
  171. ::testing::ValuesIn(sse2_block_error_tests));
  172. #endif // HAVE_SSE2
  173. #if HAVE_AVX2
  174. INSTANTIATE_TEST_CASE_P(
  175. AVX2, BlockErrorTest,
  176. ::testing::Values(make_tuple(&BlockError8BitWrapper<vp9_block_error_avx2>,
  177. &BlockError8BitWrapper<vp9_block_error_c>,
  178. VPX_BITS_8)));
  179. #endif // HAVE_AVX2
  180. } // namespace