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.
16 #include <sys/types.h>
18 #include "third_party/googletest/src/include/gtest/gtest.h"
20 #include "./vpx_config.h"
21 #include "./vp8_rtcd.h"
22 #include "test/acm_random.h"
23 #include "vpx/vpx_integer.h"
24 #include "vpx_ports/mem.h"
28 typedef void (*FdctFunc)(int16_t *a, int16_t *b, int a_stride);
30 const int cospi8sqrt2minus1 = 20091;
31 const int sinpi8sqrt2 = 35468;
33 void reference_idct4x4(const int16_t *input, int16_t *output) {
34 const int16_t *ip = input;
37 for (int i = 0; i < 4; ++i) {
38 const int a1 = ip[0] + ip[8];
39 const int b1 = ip[0] - ip[8];
40 const int temp1 = (ip[4] * sinpi8sqrt2) >> 16;
41 const int temp2 = ip[12] + ((ip[12] * cospi8sqrt2minus1) >> 16);
42 const int c1 = temp1 - temp2;
43 const int temp3 = ip[4] + ((ip[4] * cospi8sqrt2minus1) >> 16);
44 const int temp4 = (ip[12] * sinpi8sqrt2) >> 16;
45 const int d1 = temp3 + temp4;
55 for (int i = 0; i < 4; ++i) {
56 const int a1 = ip[0] + ip[2];
57 const int b1 = ip[0] - ip[2];
58 const int temp1 = (ip[1] * sinpi8sqrt2) >> 16;
59 const int temp2 = ip[3] + ((ip[3] * cospi8sqrt2minus1) >> 16);
60 const int c1 = temp1 - temp2;
61 const int temp3 = ip[1] + ((ip[1] * cospi8sqrt2minus1) >> 16);
62 const int temp4 = (ip[3] * sinpi8sqrt2) >> 16;
63 const int d1 = temp3 + temp4;
64 op[0] = (a1 + d1 + 4) >> 3;
65 op[3] = (a1 - d1 + 4) >> 3;
66 op[1] = (b1 + c1 + 4) >> 3;
67 op[2] = (b1 - c1 + 4) >> 3;
73 using libvpx_test::ACMRandom;
75 class FdctTest : public ::testing::TestWithParam<FdctFunc> {
77 virtual void SetUp() {
78 fdct_func_ = GetParam();
79 rnd_.Reset(ACMRandom::DeterministicSeed());
87 TEST_P(FdctTest, SignBiasCheck) {
88 int16_t test_input_block[16];
89 DECLARE_ALIGNED(16, int16_t, test_output_block[16]);
91 int count_sign_block[16][2];
92 const int count_test_block = 1000000;
94 memset(count_sign_block, 0, sizeof(count_sign_block));
96 for (int i = 0; i < count_test_block; ++i) {
97 // Initialize a test block with input range [-255, 255].
98 for (int j = 0; j < 16; ++j) {
99 test_input_block[j] = rnd_.Rand8() - rnd_.Rand8();
102 fdct_func_(test_input_block, test_output_block, pitch);
104 for (int j = 0; j < 16; ++j) {
105 if (test_output_block[j] < 0) {
106 ++count_sign_block[j][0];
107 } else if (test_output_block[j] > 0) {
108 ++count_sign_block[j][1];
113 bool bias_acceptable = true;
114 for (int j = 0; j < 16; ++j) {
117 (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 10000);
120 EXPECT_EQ(true, bias_acceptable)
121 << "Error: 4x4 FDCT has a sign bias > 1% for input range [-255, 255]";
123 memset(count_sign_block, 0, sizeof(count_sign_block));
125 for (int i = 0; i < count_test_block; ++i) {
126 // Initialize a test block with input range [-15, 15].
127 for (int j = 0; j < 16; ++j) {
128 test_input_block[j] = (rnd_.Rand8() >> 4) - (rnd_.Rand8() >> 4);
131 fdct_func_(test_input_block, test_output_block, pitch);
133 for (int j = 0; j < 16; ++j) {
134 if (test_output_block[j] < 0) {
135 ++count_sign_block[j][0];
136 } else if (test_output_block[j] > 0) {
137 ++count_sign_block[j][1];
142 bias_acceptable = true;
143 for (int j = 0; j < 16; ++j) {
146 (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 100000);
149 EXPECT_EQ(true, bias_acceptable)
150 << "Error: 4x4 FDCT has a sign bias > 10% for input range [-15, 15]";
153 TEST_P(FdctTest, RoundTripErrorCheck) {
155 double total_error = 0;
156 const int count_test_block = 1000000;
157 for (int i = 0; i < count_test_block; ++i) {
158 int16_t test_input_block[16];
159 int16_t test_output_block[16];
160 DECLARE_ALIGNED(16, int16_t, test_temp_block[16]);
162 // Initialize a test block with input range [-255, 255].
163 for (int j = 0; j < 16; ++j) {
164 test_input_block[j] = rnd_.Rand8() - rnd_.Rand8();
168 fdct_func_(test_input_block, test_temp_block, pitch);
169 reference_idct4x4(test_temp_block, test_output_block);
171 for (int j = 0; j < 16; ++j) {
172 const int diff = test_input_block[j] - test_output_block[j];
173 const int error = diff * diff;
174 if (max_error < error) max_error = error;
175 total_error += error;
179 EXPECT_GE(1, max_error)
180 << "Error: FDCT/IDCT has an individual roundtrip error > 1";
182 EXPECT_GE(count_test_block, total_error)
183 << "Error: FDCT/IDCT has average roundtrip error > 1 per block";
186 INSTANTIATE_TEST_SUITE_P(C, FdctTest, ::testing::Values(vp8_short_fdct4x4_c));
189 INSTANTIATE_TEST_SUITE_P(NEON, FdctTest,
190 ::testing::Values(vp8_short_fdct4x4_neon));
194 INSTANTIATE_TEST_SUITE_P(SSE2, FdctTest,
195 ::testing::Values(vp8_short_fdct4x4_sse2));
199 INSTANTIATE_TEST_SUITE_P(MSA, FdctTest,
200 ::testing::Values(vp8_short_fdct4x4_msa));
203 INSTANTIATE_TEST_SUITE_P(MMI, FdctTest,
204 ::testing::Values(vp8_short_fdct4x4_mmi));