dct_partial_test.cc 6.1 KB

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