2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
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.
15 #include "third_party/googletest/src/include/gtest/gtest.h"
16 #include "test/acm_random.h"
17 #include "test/clear_system_state.h"
18 #include "test/register_state_check.h"
19 #include "test/util.h"
21 #include "./vp9_rtcd.h"
22 #include "./vpx_dsp_rtcd.h"
23 #include "vp9/common/vp9_blockd.h"
24 #include "vp9/common/vp9_scan.h"
25 #include "vpx/vpx_integer.h"
27 using libvpx_test::ACMRandom;
30 typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride);
31 typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride);
32 typedef std::tr1::tuple<FwdTxfmFunc,
35 TX_SIZE, int> PartialInvTxfmParam;
36 const int kMaxNumCoeffs = 1024;
37 class PartialIDctTest : public ::testing::TestWithParam<PartialInvTxfmParam> {
39 virtual ~PartialIDctTest() {}
40 virtual void SetUp() {
41 ftxfm_ = GET_PARAM(0);
42 full_itxfm_ = GET_PARAM(1);
43 partial_itxfm_ = GET_PARAM(2);
44 tx_size_ = GET_PARAM(3);
45 last_nonzero_ = GET_PARAM(4);
48 virtual void TearDown() { libvpx_test::ClearSystemState(); }
54 InvTxfmFunc full_itxfm_;
55 InvTxfmFunc partial_itxfm_;
58 TEST_P(PartialIDctTest, RunQuantCheck) {
59 ACMRandom rnd(ACMRandom::DeterministicSeed());
75 FAIL() << "Wrong Size!";
78 DECLARE_ALIGNED(16, tran_low_t, test_coef_block1[kMaxNumCoeffs]);
79 DECLARE_ALIGNED(16, tran_low_t, test_coef_block2[kMaxNumCoeffs]);
80 DECLARE_ALIGNED(16, uint8_t, dst1[kMaxNumCoeffs]);
81 DECLARE_ALIGNED(16, uint8_t, dst2[kMaxNumCoeffs]);
83 const int count_test_block = 1000;
84 const int block_size = size * size;
86 DECLARE_ALIGNED(16, int16_t, input_extreme_block[kMaxNumCoeffs]);
87 DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kMaxNumCoeffs]);
90 for (int i = 0; i < count_test_block; ++i) {
91 // clear out destination buffer
92 memset(dst1, 0, sizeof(*dst1) * block_size);
93 memset(dst2, 0, sizeof(*dst2) * block_size);
94 memset(test_coef_block1, 0, sizeof(*test_coef_block1) * block_size);
95 memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size);
97 ACMRandom rnd(ACMRandom::DeterministicSeed());
99 for (int i = 0; i < count_test_block; ++i) {
100 // Initialize a test block with input range [-255, 255].
102 for (int j = 0; j < block_size; ++j)
103 input_extreme_block[j] = 255;
105 for (int j = 0; j < block_size; ++j)
106 input_extreme_block[j] = -255;
108 for (int j = 0; j < block_size; ++j) {
109 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
113 ftxfm_(input_extreme_block, output_ref_block, size);
115 // quantization with maximum allowed step sizes
116 test_coef_block1[0] = (output_ref_block[0] / 1336) * 1336;
117 for (int j = 1; j < last_nonzero_; ++j)
118 test_coef_block1[vp9_default_scan_orders[tx_size_].scan[j]]
119 = (output_ref_block[j] / 1828) * 1828;
122 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size));
123 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block1, dst2, size));
125 for (int j = 0; j < block_size; ++j) {
126 const int diff = dst1[j] - dst2[j];
127 const int error = diff * diff;
128 if (max_error < error)
133 EXPECT_EQ(0, max_error)
134 << "Error: partial inverse transform produces different results";
137 TEST_P(PartialIDctTest, ResultsMatch) {
138 ACMRandom rnd(ACMRandom::DeterministicSeed());
154 FAIL() << "Wrong Size!";
157 DECLARE_ALIGNED(16, tran_low_t, test_coef_block1[kMaxNumCoeffs]);
158 DECLARE_ALIGNED(16, tran_low_t, test_coef_block2[kMaxNumCoeffs]);
159 DECLARE_ALIGNED(16, uint8_t, dst1[kMaxNumCoeffs]);
160 DECLARE_ALIGNED(16, uint8_t, dst2[kMaxNumCoeffs]);
161 const int count_test_block = 1000;
162 const int max_coeff = 32766 / 4;
163 const int block_size = size * size;
165 for (int i = 0; i < count_test_block; ++i) {
166 // clear out destination buffer
167 memset(dst1, 0, sizeof(*dst1) * block_size);
168 memset(dst2, 0, sizeof(*dst2) * block_size);
169 memset(test_coef_block1, 0, sizeof(*test_coef_block1) * block_size);
170 memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size);
171 int max_energy_leftover = max_coeff * max_coeff;
172 for (int j = 0; j < last_nonzero_; ++j) {
173 int16_t coef = static_cast<int16_t>(sqrt(1.0 * max_energy_leftover) *
174 (rnd.Rand16() - 32768) / 65536);
175 max_energy_leftover -= coef * coef;
176 if (max_energy_leftover < 0) {
177 max_energy_leftover = 0;
180 test_coef_block1[vp9_default_scan_orders[tx_size_].scan[j]] = coef;
183 memcpy(test_coef_block2, test_coef_block1,
184 sizeof(*test_coef_block2) * block_size);
186 ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size));
187 ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block2, dst2, size));
189 for (int j = 0; j < block_size; ++j) {
190 const int diff = dst1[j] - dst2[j];
191 const int error = diff * diff;
192 if (max_error < error)
197 EXPECT_EQ(0, max_error)
198 << "Error: partial inverse transform produces different results";
200 using std::tr1::make_tuple;
202 INSTANTIATE_TEST_CASE_P(
205 make_tuple(&vp9_fdct32x32_c,
206 &vp9_idct32x32_1024_add_c,
207 &vp9_idct32x32_34_add_c,
209 make_tuple(&vp9_fdct32x32_c,
210 &vp9_idct32x32_1024_add_c,
211 &vp9_idct32x32_1_add_c,
213 make_tuple(&vp9_fdct16x16_c,
214 &vp9_idct16x16_256_add_c,
215 &vp9_idct16x16_10_add_c,
217 make_tuple(&vp9_fdct16x16_c,
218 &vp9_idct16x16_256_add_c,
219 &vp9_idct16x16_1_add_c,
221 make_tuple(&vp9_fdct8x8_c,
222 &vp9_idct8x8_64_add_c,
223 &vp9_idct8x8_12_add_c,
225 make_tuple(&vp9_fdct8x8_c,
226 &vp9_idct8x8_64_add_c,
227 &vp9_idct8x8_1_add_c,
229 make_tuple(&vp9_fdct4x4_c,
230 &vp9_idct4x4_16_add_c,
231 &vp9_idct4x4_1_add_c,
234 #if HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
235 INSTANTIATE_TEST_CASE_P(
236 NEON, PartialIDctTest,
238 make_tuple(&vp9_fdct32x32_c,
239 &vp9_idct32x32_1024_add_c,
240 &vp9_idct32x32_1_add_neon,
242 make_tuple(&vp9_fdct16x16_c,
243 &vp9_idct16x16_256_add_c,
244 &vp9_idct16x16_10_add_neon,
246 make_tuple(&vp9_fdct16x16_c,
247 &vp9_idct16x16_256_add_c,
248 &vp9_idct16x16_1_add_neon,
250 make_tuple(&vp9_fdct8x8_c,
251 &vp9_idct8x8_64_add_c,
252 &vp9_idct8x8_12_add_neon,
254 make_tuple(&vp9_fdct8x8_c,
255 &vp9_idct8x8_64_add_c,
256 &vp9_idct8x8_1_add_neon,
258 make_tuple(&vp9_fdct4x4_c,
259 &vp9_idct4x4_16_add_c,
260 &vp9_idct4x4_1_add_neon,
262 #endif // HAVE_NEON && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
264 #if HAVE_SSE2 && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
265 INSTANTIATE_TEST_CASE_P(
266 SSE2, PartialIDctTest,
268 make_tuple(&vp9_fdct32x32_c,
269 &vp9_idct32x32_1024_add_c,
270 &vp9_idct32x32_34_add_sse2,
272 make_tuple(&vp9_fdct32x32_c,
273 &vp9_idct32x32_1024_add_c,
274 &vp9_idct32x32_1_add_sse2,
276 make_tuple(&vp9_fdct16x16_c,
277 &vp9_idct16x16_256_add_c,
278 &vp9_idct16x16_10_add_sse2,
280 make_tuple(&vp9_fdct16x16_c,
281 &vp9_idct16x16_256_add_c,
282 &vp9_idct16x16_1_add_sse2,
284 make_tuple(&vp9_fdct8x8_c,
285 &vp9_idct8x8_64_add_c,
286 &vp9_idct8x8_12_add_sse2,
288 make_tuple(&vp9_fdct8x8_c,
289 &vp9_idct8x8_64_add_c,
290 &vp9_idct8x8_1_add_sse2,
292 make_tuple(&vp9_fdct4x4_c,
293 &vp9_idct4x4_16_add_c,
294 &vp9_idct4x4_1_add_sse2,
298 #if HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64 && \
299 !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
300 INSTANTIATE_TEST_CASE_P(
301 SSSE3_64, PartialIDctTest,
303 make_tuple(&vp9_fdct8x8_c,
304 &vp9_idct8x8_64_add_c,
305 &vp9_idct8x8_12_add_ssse3,
309 #if HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
310 INSTANTIATE_TEST_CASE_P(
311 MSA, PartialIDctTest,
313 make_tuple(&vp9_fdct32x32_c,
314 &vp9_idct32x32_1024_add_c,
315 &vp9_idct32x32_34_add_msa,
317 make_tuple(&vp9_fdct32x32_c,
318 &vp9_idct32x32_1024_add_c,
319 &vp9_idct32x32_1_add_msa,
321 make_tuple(&vp9_fdct16x16_c,
322 &vp9_idct16x16_256_add_c,
323 &vp9_idct16x16_10_add_msa,
325 make_tuple(&vp9_fdct16x16_c,
326 &vp9_idct16x16_256_add_c,
327 &vp9_idct16x16_1_add_msa,
329 make_tuple(&vp9_fdct8x8_c,
330 &vp9_idct8x8_64_add_c,
331 &vp9_idct8x8_12_add_msa,
333 make_tuple(&vp9_fdct8x8_c,
334 &vp9_idct8x8_64_add_c,
335 &vp9_idct8x8_1_add_msa,
337 make_tuple(&vp9_fdct4x4_c,
338 &vp9_idct4x4_16_add_c,
339 &vp9_idct4x4_1_add_msa,
341 #endif // HAVE_MSA && !CONFIG_VP9_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE