dct_partial_test.cc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 <math.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <limits>
  14. #include "third_party/googletest/src/include/gtest/gtest.h"
  15. #include "./vpx_dsp_rtcd.h"
  16. #include "test/acm_random.h"
  17. #include "test/buffer.h"
  18. #include "test/clear_system_state.h"
  19. #include "test/register_state_check.h"
  20. #include "test/util.h"
  21. #include "vpx/vpx_codec.h"
  22. #include "vpx/vpx_integer.h"
  23. #include "vpx_dsp/vpx_dsp_common.h"
  24. using libvpx_test::ACMRandom;
  25. using libvpx_test::Buffer;
  26. using std::tr1::tuple;
  27. using std::tr1::make_tuple;
  28. namespace {
  29. typedef void (*PartialFdctFunc)(const int16_t *in, tran_low_t *out, int stride);
  30. typedef tuple<PartialFdctFunc, int /* size */, vpx_bit_depth_t>
  31. PartialFdctParam;
  32. tran_low_t partial_fdct_ref(const Buffer<int16_t> &in, int size) {
  33. int64_t sum = 0;
  34. for (int y = 0; y < size; ++y) {
  35. for (int x = 0; x < size; ++x) {
  36. sum += in.TopLeftPixel()[y * in.stride() + x];
  37. }
  38. }
  39. switch (size) {
  40. case 4: sum *= 2; break;
  41. case 8: /*sum = sum;*/ break;
  42. case 16: sum >>= 1; break;
  43. case 32: sum >>= 3; break;
  44. }
  45. return static_cast<tran_low_t>(sum);
  46. }
  47. class PartialFdctTest : public ::testing::TestWithParam<PartialFdctParam> {
  48. public:
  49. PartialFdctTest() {
  50. fwd_txfm_ = GET_PARAM(0);
  51. size_ = GET_PARAM(1);
  52. bit_depth_ = GET_PARAM(2);
  53. }
  54. virtual void TearDown() { libvpx_test::ClearSystemState(); }
  55. protected:
  56. void RunTest() {
  57. ACMRandom rnd(ACMRandom::DeterministicSeed());
  58. const int16_t maxvalue =
  59. clip_pixel_highbd(std::numeric_limits<int16_t>::max(), bit_depth_);
  60. const int16_t minvalue = -maxvalue;
  61. Buffer<int16_t> input_block =
  62. Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
  63. ASSERT_TRUE(input_block.Init());
  64. Buffer<tran_low_t> output_block = Buffer<tran_low_t>(size_, size_, 0, 16);
  65. ASSERT_TRUE(output_block.Init());
  66. for (int i = 0; i < 100; ++i) {
  67. if (i == 0) {
  68. input_block.Set(maxvalue);
  69. } else if (i == 1) {
  70. input_block.Set(minvalue);
  71. } else {
  72. input_block.Set(&rnd, minvalue, maxvalue);
  73. }
  74. ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block.TopLeftPixel(),
  75. output_block.TopLeftPixel(),
  76. input_block.stride()));
  77. EXPECT_EQ(partial_fdct_ref(input_block, size_),
  78. output_block.TopLeftPixel()[0]);
  79. }
  80. }
  81. PartialFdctFunc fwd_txfm_;
  82. vpx_bit_depth_t bit_depth_;
  83. int size_;
  84. };
  85. TEST_P(PartialFdctTest, PartialFdctTest) { RunTest(); }
  86. #if CONFIG_VP9_HIGHBITDEPTH
  87. INSTANTIATE_TEST_CASE_P(
  88. C, PartialFdctTest,
  89. ::testing::Values(make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_12),
  90. make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_10),
  91. make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
  92. make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_12),
  93. make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_10),
  94. make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
  95. make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_12),
  96. make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_10),
  97. make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
  98. make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
  99. #else
  100. INSTANTIATE_TEST_CASE_P(
  101. C, PartialFdctTest,
  102. ::testing::Values(make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
  103. make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
  104. make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
  105. make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
  106. #endif // CONFIG_VP9_HIGHBITDEPTH
  107. #if HAVE_SSE2
  108. INSTANTIATE_TEST_CASE_P(
  109. SSE2, PartialFdctTest,
  110. ::testing::Values(make_tuple(&vpx_fdct32x32_1_sse2, 32, VPX_BITS_8),
  111. make_tuple(&vpx_fdct16x16_1_sse2, 16, VPX_BITS_8),
  112. make_tuple(&vpx_fdct8x8_1_sse2, 8, VPX_BITS_8),
  113. make_tuple(&vpx_fdct4x4_1_sse2, 4, VPX_BITS_8)));
  114. #endif // HAVE_SSE2
  115. #if HAVE_NEON
  116. #if CONFIG_VP9_HIGHBITDEPTH
  117. INSTANTIATE_TEST_CASE_P(
  118. NEON, PartialFdctTest,
  119. ::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
  120. make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
  121. make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_12),
  122. make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_10),
  123. make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
  124. make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
  125. #else
  126. INSTANTIATE_TEST_CASE_P(
  127. NEON, PartialFdctTest,
  128. ::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
  129. make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
  130. make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
  131. make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
  132. #endif // CONFIG_VP9_HIGHBITDEPTH
  133. #endif // HAVE_NEON
  134. #if HAVE_MSA
  135. #if CONFIG_VP9_HIGHBITDEPTH
  136. INSTANTIATE_TEST_CASE_P(MSA, PartialFdctTest,
  137. ::testing::Values(make_tuple(&vpx_fdct8x8_1_msa, 8,
  138. VPX_BITS_8)));
  139. #else // !CONFIG_VP9_HIGHBITDEPTH
  140. INSTANTIATE_TEST_CASE_P(
  141. MSA, PartialFdctTest,
  142. ::testing::Values(make_tuple(&vpx_fdct32x32_1_msa, 32, VPX_BITS_8),
  143. make_tuple(&vpx_fdct16x16_1_msa, 16, VPX_BITS_8),
  144. make_tuple(&vpx_fdct8x8_1_msa, 8, VPX_BITS_8)));
  145. #endif // CONFIG_VP9_HIGHBITDEPTH
  146. #endif // HAVE_MSA
  147. } // namespace