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