blob: 5a8fff43bce358636a4121e5e7e33b1c723a96bd [file] [log] [blame]
Joe Young1124db22018-02-05 16:19:17 -08001/*
2 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#include <math.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17#include "test/register_state_check.h"
18#include "test/function_equivalence_test.h"
19
20#include "./aom_config.h"
21#include "./aom_dsp_rtcd.h"
22#include "aom/aom_integer.h"
23
24#include "./av1_rtcd.h"
25
26#include "av1/common/enums.h"
27
28using libaom_test::FunctionEquivalenceTest;
29
30namespace {
31
32template <typename F, typename T>
33class UpsampleTest : public FunctionEquivalenceTest<F> {
34 protected:
Yaowu Xu974a19e2018-02-17 21:17:07 -080035 static const int kIterations = 1000000;
Joe Young1124db22018-02-05 16:19:17 -080036 static const int kMinEdge = 4;
37 static const int kMaxEdge = 24;
38 static const int kBufSize = 2 * 64 + 32;
39 static const int kOffset = 16;
40
41 virtual ~UpsampleTest() {}
42
43 virtual void Execute(T *edge_tst) = 0;
44
45 void Common() {
46 edge_ref_ = &edge_ref_data_[kOffset];
47 edge_tst_ = &edge_tst_data_[kOffset];
48
49 Execute(edge_tst_);
50
51 const int max_idx = (size_ - 1) * 2;
52 for (int r = -2; r <= max_idx; ++r) {
53 ASSERT_EQ(edge_ref_[r], edge_tst_[r]);
54 }
55 }
56
57 T edge_ref_data_[kBufSize];
58 T edge_tst_data_[kBufSize];
59
60 T *edge_ref_;
61 T *edge_tst_;
62
63 int size_;
64};
65
66//////////////////////////////////////////////////////////////////////////////
67// 8 bit version
68//////////////////////////////////////////////////////////////////////////////
69
70typedef void (*UP8B)(uint8_t *p, int size);
71typedef libaom_test::FuncParam<UP8B> TestFuncs;
72
73class UpsampleTest8B : public UpsampleTest<UP8B, uint8_t> {
74 protected:
75 void Execute(uint8_t *edge_tst) {
76 params_.ref_func(edge_ref_, size_);
77 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst, size_));
78 }
79};
80
81TEST_P(UpsampleTest8B, RandomValues) {
82 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
83 size_ = 4 * (this->rng_(4) + 1);
84
85 int i, pix = 0;
86 for (i = 0; i < kOffset + size_; ++i) {
87 pix = rng_.Rand8();
88 edge_ref_data_[i] = pix;
89 edge_tst_data_[i] = edge_ref_data_[i];
90 }
91
92 // Extend final sample
93 while (i < kBufSize) {
94 edge_ref_data_[i] = pix;
95 edge_tst_data_[i] = pix;
96 i++;
97 }
98
99 Common();
100 }
101}
102
103#if HAVE_SSE4_1
104INSTANTIATE_TEST_CASE_P(
105 SSE4_1, UpsampleTest8B,
106 ::testing::Values(TestFuncs(av1_upsample_intra_edge_c,
107 av1_upsample_intra_edge_sse4_1)));
108#endif // HAVE_SSE4_1
109
110//////////////////////////////////////////////////////////////////////////////
111// High bit-depth version
112//////////////////////////////////////////////////////////////////////////////
113
114typedef void (*UPHB)(uint16_t *p, int size, int bd);
115typedef libaom_test::FuncParam<UPHB> TestFuncsHBD;
116
117class UpsampleTestHB : public UpsampleTest<UPHB, uint16_t> {
118 protected:
119 void Execute(uint16_t *edge_tst) {
120 params_.ref_func(edge_ref_, size_, bit_depth_);
121 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst, size_, bit_depth_));
122 }
123 int bit_depth_;
124};
125
126TEST_P(UpsampleTestHB, RandomValues) {
127 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
128 switch (rng_(3)) {
129 case 0: bit_depth_ = 8; break;
130 case 1: bit_depth_ = 10; break;
131 default: bit_depth_ = 12; break;
132 }
133 const int hi = 1 << bit_depth_;
134
135 size_ = 4 * (this->rng_(4) + 1);
136
137 int i, pix = 0;
138 for (i = 0; i < kOffset + size_; ++i) {
139 pix = rng_(hi);
140 edge_ref_data_[i] = pix;
141 edge_tst_data_[i] = pix;
142 }
143
144 // Extend final sample
145 while (i < kBufSize) {
146 edge_ref_data_[i] = pix;
147 edge_tst_data_[i] = pix;
148 i++;
149 }
150
151 Common();
152 }
153}
154
155#if HAVE_SSE4_1
156INSTANTIATE_TEST_CASE_P(
157 SSE4_1, UpsampleTestHB,
158 ::testing::Values(TestFuncsHBD(av1_upsample_intra_edge_high_c,
159 av1_upsample_intra_edge_high_sse4_1)));
160#endif // HAVE_SSE4_1
161
162template <typename F, typename T>
163class FilterEdgeTest : public FunctionEquivalenceTest<F> {
164 protected:
Yaowu Xu974a19e2018-02-17 21:17:07 -0800165 static const int kIterations = 1000000;
Joe Young1124db22018-02-05 16:19:17 -0800166 static const int kMaxEdge = 2 * 64;
167 static const int kBufSize = kMaxEdge + 32;
168 static const int kOffset = 15;
169
170 virtual ~FilterEdgeTest() {}
171
172 virtual void Execute(T *edge_tst) = 0;
173
174 void Common() {
175 edge_ref_ = &edge_ref_data_[kOffset];
176 edge_tst_ = &edge_tst_data_[kOffset];
177
178 Execute(edge_tst_);
179
180 for (int r = 0; r < size_; ++r) {
181 ASSERT_EQ(edge_ref_[r], edge_tst_[r]);
182 }
183 }
184
185 T edge_ref_data_[kBufSize];
186 T edge_tst_data_[kBufSize];
187
188 T *edge_ref_;
189 T *edge_tst_;
190
191 int size_;
192 int strength_;
193};
194
195//////////////////////////////////////////////////////////////////////////////
196// 8 bit version
197//////////////////////////////////////////////////////////////////////////////
198
199typedef void (*FE8B)(uint8_t *p, int size, int strength);
200typedef libaom_test::FuncParam<FE8B> FilterEdgeTestFuncs;
201
202class FilterEdgeTest8B : public FilterEdgeTest<FE8B, uint8_t> {
203 protected:
204 void Execute(uint8_t *edge_tst) {
205 params_.ref_func(edge_ref_, size_, strength_);
206 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst, size_, strength_));
207 }
208};
209
210TEST_P(FilterEdgeTest8B, RandomValues) {
211 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
212 strength_ = this->rng_(4);
213 size_ = 4 * (this->rng_(128 / 4) + 1) + 1;
214
215 int i, pix = 0;
216 for (i = 0; i < kOffset + size_; ++i) {
217 pix = rng_.Rand8();
218 edge_ref_data_[i] = pix;
219 edge_tst_data_[i] = pix;
220 }
221
222 Common();
223 }
224}
225
226#if HAVE_SSE4_1
227INSTANTIATE_TEST_CASE_P(
228 SSE4_1, FilterEdgeTest8B,
229 ::testing::Values(FilterEdgeTestFuncs(av1_filter_intra_edge_c,
230 av1_filter_intra_edge_sse4_1)));
231#endif // HAVE_SSE4_1
232
233//////////////////////////////////////////////////////////////////////////////
234// High bit-depth version
235//////////////////////////////////////////////////////////////////////////////
236
237typedef void (*FEHB)(uint16_t *p, int size, int strength);
238typedef libaom_test::FuncParam<FEHB> FilterEdgeTestFuncsHBD;
239
240class FilterEdgeTestHB : public FilterEdgeTest<FEHB, uint16_t> {
241 protected:
242 void Execute(uint16_t *edge_tst) {
243 params_.ref_func(edge_ref_, size_, strength_);
244 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst, size_, strength_));
245 }
246 int bit_depth_;
247};
248
249TEST_P(FilterEdgeTestHB, RandomValues) {
250 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
251 switch (rng_(3)) {
252 case 0: bit_depth_ = 8; break;
253 case 1: bit_depth_ = 10; break;
254 default: bit_depth_ = 12; break;
255 }
256 const int hi = 1 << bit_depth_;
257 strength_ = this->rng_(4);
258 size_ = 4 * (this->rng_(128 / 4) + 1) + 1;
259
260 int i, pix = 0;
261 for (i = 0; i < kOffset + size_; ++i) {
262 pix = rng_(hi);
263 edge_ref_data_[i] = pix;
264 edge_tst_data_[i] = pix;
265 }
266
267 Common();
268 }
269}
270
271#if HAVE_SSE4_1
272INSTANTIATE_TEST_CASE_P(SSE4_1, FilterEdgeTestHB,
273 ::testing::Values(FilterEdgeTestFuncsHBD(
274 av1_filter_intra_edge_high_c,
275 av1_filter_intra_edge_high_sse4_1)));
276#endif // HAVE_SSE4_1
277
278// Speed tests
279
280TEST_P(UpsampleTest8B, DISABLED_Speed) {
Yaowu Xu974a19e2018-02-17 21:17:07 -0800281 const int test_count = 10000000;
Joe Young1124db22018-02-05 16:19:17 -0800282 size_ = kMaxEdge;
283 for (int i = 0; i < kOffset + size_; ++i) {
284 edge_tst_data_[i] = rng_.Rand8();
285 }
286 edge_tst_ = &edge_tst_data_[kOffset];
287 for (int iter = 0; iter < test_count; ++iter) {
288 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst_, size_));
289 }
290}
291
292TEST_P(UpsampleTestHB, DISABLED_Speed) {
Yaowu Xu974a19e2018-02-17 21:17:07 -0800293 const int test_count = 10000000;
Joe Young1124db22018-02-05 16:19:17 -0800294 size_ = kMaxEdge;
295 bit_depth_ = 12;
296 const int hi = 1 << bit_depth_;
297 for (int i = 0; i < kOffset + size_; ++i) {
298 edge_tst_data_[i] = rng_(hi);
299 }
300 edge_tst_ = &edge_tst_data_[kOffset];
301 for (int iter = 0; iter < test_count; ++iter) {
302 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst_, size_, bit_depth_));
303 }
304}
305
306TEST_P(FilterEdgeTest8B, DISABLED_Speed) {
Yaowu Xu974a19e2018-02-17 21:17:07 -0800307 const int test_count = 10000000;
Joe Young1124db22018-02-05 16:19:17 -0800308 size_ = kMaxEdge;
309 strength_ = 1;
310 for (int i = 0; i < kOffset + size_; ++i) {
311 edge_tst_data_[i] = rng_.Rand8();
312 }
313 edge_tst_ = &edge_tst_data_[kOffset];
314 for (int iter = 0; iter < test_count; ++iter) {
315 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst_, size_, strength_));
316 // iterate over filter strengths (1,2,3)
317 strength_ = (strength_ == 3) ? 1 : strength_ + 1;
318 }
319}
320
321TEST_P(FilterEdgeTestHB, DISABLED_Speed) {
Yaowu Xu974a19e2018-02-17 21:17:07 -0800322 const int test_count = 10000000;
Joe Young1124db22018-02-05 16:19:17 -0800323 size_ = kMaxEdge;
324 strength_ = 1;
325 bit_depth_ = 12;
326 const int hi = 1 << bit_depth_;
327 for (int i = 0; i < kOffset + size_; ++i) {
328 edge_tst_data_[i] = rng_(hi);
329 }
330 edge_tst_ = &edge_tst_data_[kOffset];
331 for (int iter = 0; iter < test_count; ++iter) {
332 ASM_REGISTER_STATE_CHECK(params_.tst_func(edge_tst_, size_, strength_));
333 // iterate over filter strengths (1,2,3)
334 strength_ = (strength_ == 3) ? 1 : strength_ + 1;
335 }
336}
337
338} // namespace