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