2 * Copyright (c) 2012 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 "vp9/common/vp9_entropy.h"
23 #include "vpx/vpx_integer.h"
26 void vp9_idct4x4_16_add_c(const int16_t *input, uint8_t *output, int pitch);
29 using libvpx_test::ACMRandom;
32 const int kNumCoeffs = 16;
33 typedef void (*FdctFunc)(const int16_t *in, int16_t *out, int stride);
34 typedef void (*IdctFunc)(const int16_t *in, uint8_t *out, int stride);
35 typedef void (*FhtFunc)(const int16_t *in, int16_t *out, int stride,
37 typedef void (*IhtFunc)(const int16_t *in, uint8_t *out, int stride,
40 typedef std::tr1::tuple<FdctFunc, IdctFunc, int> Dct4x4Param;
41 typedef std::tr1::tuple<FhtFunc, IhtFunc, int> Ht4x4Param;
43 void fdct4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
44 vp9_fdct4x4_c(in, out, stride);
47 void fht4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
48 vp9_fht4x4_c(in, out, stride, tx_type);
51 void fwht4x4_ref(const int16_t *in, int16_t *out, int stride, int tx_type) {
52 vp9_fwht4x4_c(in, out, stride);
55 class Trans4x4TestBase {
57 virtual ~Trans4x4TestBase() {}
60 virtual void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) = 0;
62 virtual void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) = 0;
64 void RunAccuracyCheck(int limit) {
65 ACMRandom rnd(ACMRandom::DeterministicSeed());
66 uint32_t max_error = 0;
67 int64_t total_error = 0;
68 const int count_test_block = 10000;
69 for (int i = 0; i < count_test_block; ++i) {
70 DECLARE_ALIGNED_ARRAY(16, int16_t, test_input_block, kNumCoeffs);
71 DECLARE_ALIGNED_ARRAY(16, int16_t, test_temp_block, kNumCoeffs);
72 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
73 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
75 // Initialize a test block with input range [-255, 255].
76 for (int j = 0; j < kNumCoeffs; ++j) {
79 test_input_block[j] = src[j] - dst[j];
82 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(test_input_block,
83 test_temp_block, pitch_));
84 ASM_REGISTER_STATE_CHECK(RunInvTxfm(test_temp_block, dst, pitch_));
86 for (int j = 0; j < kNumCoeffs; ++j) {
87 const uint32_t diff = dst[j] - src[j];
88 const uint32_t error = diff * diff;
89 if (max_error < error)
95 EXPECT_GE(static_cast<uint32_t>(limit), max_error)
96 << "Error: 4x4 FHT/IHT has an individual round trip error > "
99 EXPECT_GE(count_test_block * limit, total_error)
100 << "Error: 4x4 FHT/IHT has average round trip error > " << limit
104 void RunCoeffCheck() {
105 ACMRandom rnd(ACMRandom::DeterministicSeed());
106 const int count_test_block = 5000;
107 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
108 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
109 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
111 for (int i = 0; i < count_test_block; ++i) {
112 // Initialize a test block with input range [-255, 255].
113 for (int j = 0; j < kNumCoeffs; ++j)
114 input_block[j] = rnd.Rand8() - rnd.Rand8();
116 fwd_txfm_ref(input_block, output_ref_block, pitch_, tx_type_);
117 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_block, output_block, pitch_));
119 // The minimum quant value is 4.
120 for (int j = 0; j < kNumCoeffs; ++j)
121 EXPECT_EQ(output_block[j], output_ref_block[j]);
126 ACMRandom rnd(ACMRandom::DeterministicSeed());
127 const int count_test_block = 5000;
128 DECLARE_ALIGNED_ARRAY(16, int16_t, input_block, kNumCoeffs);
129 DECLARE_ALIGNED_ARRAY(16, int16_t, input_extreme_block, kNumCoeffs);
130 DECLARE_ALIGNED_ARRAY(16, int16_t, output_ref_block, kNumCoeffs);
131 DECLARE_ALIGNED_ARRAY(16, int16_t, output_block, kNumCoeffs);
133 for (int i = 0; i < count_test_block; ++i) {
134 // Initialize a test block with input range [-255, 255].
135 for (int j = 0; j < kNumCoeffs; ++j) {
136 input_block[j] = rnd.Rand8() - rnd.Rand8();
137 input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255;
140 for (int j = 0; j < kNumCoeffs; ++j)
141 input_extreme_block[j] = 255;
143 for (int j = 0; j < kNumCoeffs; ++j)
144 input_extreme_block[j] = -255;
147 fwd_txfm_ref(input_extreme_block, output_ref_block, pitch_, tx_type_);
148 ASM_REGISTER_STATE_CHECK(RunFwdTxfm(input_extreme_block,
149 output_block, pitch_));
151 // The minimum quant value is 4.
152 for (int j = 0; j < kNumCoeffs; ++j) {
153 EXPECT_EQ(output_block[j], output_ref_block[j]);
154 EXPECT_GE(4 * DCT_MAX_VALUE, abs(output_block[j]))
155 << "Error: 16x16 FDCT has coefficient larger than 4*DCT_MAX_VALUE";
160 void RunInvAccuracyCheck(int limit) {
161 ACMRandom rnd(ACMRandom::DeterministicSeed());
162 const int count_test_block = 1000;
163 DECLARE_ALIGNED_ARRAY(16, int16_t, in, kNumCoeffs);
164 DECLARE_ALIGNED_ARRAY(16, int16_t, coeff, kNumCoeffs);
165 DECLARE_ALIGNED_ARRAY(16, uint8_t, dst, kNumCoeffs);
166 DECLARE_ALIGNED_ARRAY(16, uint8_t, src, kNumCoeffs);
168 for (int i = 0; i < count_test_block; ++i) {
169 // Initialize a test block with input range [-255, 255].
170 for (int j = 0; j < kNumCoeffs; ++j) {
171 src[j] = rnd.Rand8();
172 dst[j] = rnd.Rand8();
173 in[j] = src[j] - dst[j];
176 fwd_txfm_ref(in, coeff, pitch_, tx_type_);
178 ASM_REGISTER_STATE_CHECK(RunInvTxfm(coeff, dst, pitch_));
180 for (int j = 0; j < kNumCoeffs; ++j) {
181 const uint32_t diff = dst[j] - src[j];
182 const uint32_t error = diff * diff;
183 EXPECT_GE(static_cast<uint32_t>(limit), error)
184 << "Error: 4x4 IDCT has error " << error
185 << " at index " << j;
192 FhtFunc fwd_txfm_ref;
196 : public Trans4x4TestBase,
197 public ::testing::TestWithParam<Dct4x4Param> {
199 virtual ~Trans4x4DCT() {}
201 virtual void SetUp() {
202 fwd_txfm_ = GET_PARAM(0);
203 inv_txfm_ = GET_PARAM(1);
204 tx_type_ = GET_PARAM(2);
206 fwd_txfm_ref = fdct4x4_ref;
208 virtual void TearDown() { libvpx_test::ClearSystemState(); }
211 void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
212 fwd_txfm_(in, out, stride);
214 void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
215 inv_txfm_(out, dst, stride);
222 TEST_P(Trans4x4DCT, AccuracyCheck) {
226 TEST_P(Trans4x4DCT, CoeffCheck) {
230 TEST_P(Trans4x4DCT, MemCheck) {
234 TEST_P(Trans4x4DCT, InvAccuracyCheck) {
235 RunInvAccuracyCheck(1);
239 : public Trans4x4TestBase,
240 public ::testing::TestWithParam<Ht4x4Param> {
242 virtual ~Trans4x4HT() {}
244 virtual void SetUp() {
245 fwd_txfm_ = GET_PARAM(0);
246 inv_txfm_ = GET_PARAM(1);
247 tx_type_ = GET_PARAM(2);
249 fwd_txfm_ref = fht4x4_ref;
251 virtual void TearDown() { libvpx_test::ClearSystemState(); }
254 void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
255 fwd_txfm_(in, out, stride, tx_type_);
258 void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
259 inv_txfm_(out, dst, stride, tx_type_);
266 TEST_P(Trans4x4HT, AccuracyCheck) {
270 TEST_P(Trans4x4HT, CoeffCheck) {
274 TEST_P(Trans4x4HT, MemCheck) {
278 TEST_P(Trans4x4HT, InvAccuracyCheck) {
279 RunInvAccuracyCheck(1);
283 : public Trans4x4TestBase,
284 public ::testing::TestWithParam<Dct4x4Param> {
286 virtual ~Trans4x4WHT() {}
288 virtual void SetUp() {
289 fwd_txfm_ = GET_PARAM(0);
290 inv_txfm_ = GET_PARAM(1);
291 tx_type_ = GET_PARAM(2);
293 fwd_txfm_ref = fwht4x4_ref;
295 virtual void TearDown() { libvpx_test::ClearSystemState(); }
298 void RunFwdTxfm(const int16_t *in, int16_t *out, int stride) {
299 fwd_txfm_(in, out, stride);
301 void RunInvTxfm(const int16_t *out, uint8_t *dst, int stride) {
302 inv_txfm_(out, dst, stride);
309 TEST_P(Trans4x4WHT, AccuracyCheck) {
313 TEST_P(Trans4x4WHT, CoeffCheck) {
317 TEST_P(Trans4x4WHT, MemCheck) {
321 TEST_P(Trans4x4WHT, InvAccuracyCheck) {
322 RunInvAccuracyCheck(0);
324 using std::tr1::make_tuple;
326 INSTANTIATE_TEST_CASE_P(
329 make_tuple(&vp9_fdct4x4_c, &vp9_idct4x4_16_add_c, 0)));
330 INSTANTIATE_TEST_CASE_P(
333 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 0),
334 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 1),
335 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 2),
336 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_c, 3)));
337 INSTANTIATE_TEST_CASE_P(
340 make_tuple(&vp9_fwht4x4_c, &vp9_iwht4x4_16_add_c, 0)));
343 INSTANTIATE_TEST_CASE_P(
346 make_tuple(&vp9_fdct4x4_c,
347 &vp9_idct4x4_16_add_neon, 0)));
348 INSTANTIATE_TEST_CASE_P(
349 DISABLED_NEON, Trans4x4HT,
351 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 0),
352 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 1),
353 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 2),
354 make_tuple(&vp9_fht4x4_c, &vp9_iht4x4_16_add_neon, 3)));
357 #if CONFIG_USE_X86INC && HAVE_MMX
358 INSTANTIATE_TEST_CASE_P(
361 make_tuple(&vp9_fwht4x4_mmx, &vp9_iwht4x4_16_add_c, 0)));
365 INSTANTIATE_TEST_CASE_P(
368 make_tuple(&vp9_fdct4x4_sse2,
369 &vp9_idct4x4_16_add_sse2, 0)));
370 INSTANTIATE_TEST_CASE_P(
373 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 0),
374 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 1),
375 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 2),
376 make_tuple(&vp9_fht4x4_sse2, &vp9_iht4x4_16_add_sse2, 3)));
380 INSTANTIATE_TEST_CASE_P(
383 make_tuple(&vp9_fdct4x4_avx2,
384 &vp9_idct4x4_16_add_c, 0)));
385 INSTANTIATE_TEST_CASE_P(
388 make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 0),
389 make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 1),
390 make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 2),
391 make_tuple(&vp9_fht4x4_avx2, &vp9_iht4x4_16_add_c, 3)));