vp9_cx_iface: set default cpu_used=5 w/CONFIG_REALTIME_ONLY
[platform/upstream/libvpx.git] / test / vp8_fdct4x4_test.cc
1 /*
2  *  Copyright (c) 2013 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 <stddef.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <sys/types.h>
17
18 #include "third_party/googletest/src/include/gtest/gtest.h"
19
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"
25
26 namespace {
27
28 typedef void (*FdctFunc)(int16_t *a, int16_t *b, int a_stride);
29
30 const int cospi8sqrt2minus1 = 20091;
31 const int sinpi8sqrt2 = 35468;
32
33 void reference_idct4x4(const int16_t *input, int16_t *output) {
34   const int16_t *ip = input;
35   int16_t *op = output;
36
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;
46     op[0] = a1 + d1;
47     op[12] = a1 - d1;
48     op[4] = b1 + c1;
49     op[8] = b1 - c1;
50     ++ip;
51     ++op;
52   }
53   ip = output;
54   op = output;
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;
68     ip += 4;
69     op += 4;
70   }
71 }
72
73 using libvpx_test::ACMRandom;
74
75 class FdctTest : public ::testing::TestWithParam<FdctFunc> {
76  public:
77   virtual void SetUp() {
78     fdct_func_ = GetParam();
79     rnd_.Reset(ACMRandom::DeterministicSeed());
80   }
81
82  protected:
83   FdctFunc fdct_func_;
84   ACMRandom rnd_;
85 };
86
87 TEST_P(FdctTest, SignBiasCheck) {
88   int16_t test_input_block[16];
89   DECLARE_ALIGNED(16, int16_t, test_output_block[16]);
90   const int pitch = 8;
91   int count_sign_block[16][2];
92   const int count_test_block = 1000000;
93
94   memset(count_sign_block, 0, sizeof(count_sign_block));
95
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();
100     }
101
102     fdct_func_(test_input_block, test_output_block, pitch);
103
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];
109       }
110     }
111   }
112
113   bool bias_acceptable = true;
114   for (int j = 0; j < 16; ++j) {
115     bias_acceptable =
116         bias_acceptable &&
117         (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 10000);
118   }
119
120   EXPECT_EQ(true, bias_acceptable)
121       << "Error: 4x4 FDCT has a sign bias > 1% for input range [-255, 255]";
122
123   memset(count_sign_block, 0, sizeof(count_sign_block));
124
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);
129     }
130
131     fdct_func_(test_input_block, test_output_block, pitch);
132
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];
138       }
139     }
140   }
141
142   bias_acceptable = true;
143   for (int j = 0; j < 16; ++j) {
144     bias_acceptable =
145         bias_acceptable &&
146         (abs(count_sign_block[j][0] - count_sign_block[j][1]) < 100000);
147   }
148
149   EXPECT_EQ(true, bias_acceptable)
150       << "Error: 4x4 FDCT has a sign bias > 10% for input range [-15, 15]";
151 }
152
153 TEST_P(FdctTest, RoundTripErrorCheck) {
154   int max_error = 0;
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]);
161
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();
165     }
166
167     const int pitch = 8;
168     fdct_func_(test_input_block, test_temp_block, pitch);
169     reference_idct4x4(test_temp_block, test_output_block);
170
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;
176     }
177   }
178
179   EXPECT_GE(1, max_error)
180       << "Error: FDCT/IDCT has an individual roundtrip error > 1";
181
182   EXPECT_GE(count_test_block, total_error)
183       << "Error: FDCT/IDCT has average roundtrip error > 1 per block";
184 }
185
186 INSTANTIATE_TEST_SUITE_P(C, FdctTest, ::testing::Values(vp8_short_fdct4x4_c));
187
188 #if HAVE_NEON
189 INSTANTIATE_TEST_SUITE_P(NEON, FdctTest,
190                          ::testing::Values(vp8_short_fdct4x4_neon));
191 #endif  // HAVE_NEON
192
193 #if HAVE_SSE2
194 INSTANTIATE_TEST_SUITE_P(SSE2, FdctTest,
195                          ::testing::Values(vp8_short_fdct4x4_sse2));
196 #endif  // HAVE_SSE2
197
198 #if HAVE_MSA
199 INSTANTIATE_TEST_SUITE_P(MSA, FdctTest,
200                          ::testing::Values(vp8_short_fdct4x4_msa));
201 #endif  // HAVE_MSA
202 #if HAVE_MMI
203 INSTANTIATE_TEST_SUITE_P(MMI, FdctTest,
204                          ::testing::Values(vp8_short_fdct4x4_mmi));
205 #endif  // HAVE_MMI
206
207 #if HAVE_LSX
208 INSTANTIATE_TEST_SUITE_P(LSX, FdctTest,
209                          ::testing::Values(vp8_short_fdct4x4_lsx));
210 #endif  // HAVE_LSX
211 }  // namespace