1 /*
2 * Copyright (c) 2016, 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 <array>
13 #include <cstdlib>
14 #include <iostream>
15 #include <string>
16 #include <tuple>
17
18 #include "gtest/gtest.h"
19
20 #include "config/aom_config.h"
21 #include "config/av1_rtcd.h"
22
23 #include "aom_ports/aom_timer.h"
24 #include "av1/common/cdef_block.h"
25 #include "test/acm_random.h"
26 #include "test/register_state_check.h"
27 #include "test/util.h"
28
29 using libaom_test::ACMRandom;
30
31 namespace {
32
33 using CdefFilterBlockFunctions = std::array<cdef_filter_block_func, 4>;
34
35 typedef std::tuple<CdefFilterBlockFunctions, CdefFilterBlockFunctions,
36 BLOCK_SIZE, int, int>
37 cdef_dir_param_t;
38
39 class CDEFBlockTest : public ::testing::TestWithParam<cdef_dir_param_t> {
40 public:
41 ~CDEFBlockTest() override = default;
SetUp()42 void SetUp() override {
43 cdef = GET_PARAM(0);
44 ref_cdef = GET_PARAM(1);
45 bsize = GET_PARAM(2);
46 boundary = GET_PARAM(3);
47 depth = GET_PARAM(4);
48 }
49
50 protected:
51 BLOCK_SIZE bsize;
52 int boundary;
53 int depth;
54 CdefFilterBlockFunctions cdef;
55 CdefFilterBlockFunctions ref_cdef;
56 };
57 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFBlockTest);
58
59 typedef CDEFBlockTest CDEFBlockHighbdTest;
60 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFBlockHighbdTest);
61
62 typedef CDEFBlockTest CDEFSpeedTest;
63 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFSpeedTest);
64
65 typedef CDEFBlockTest CDEFSpeedHighbdTest;
66 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFSpeedHighbdTest);
67
test_cdef(BLOCK_SIZE bsize,int iterations,CdefFilterBlockFunctions cdef,CdefFilterBlockFunctions ref_cdef,int boundary,int depth)68 int64_t test_cdef(BLOCK_SIZE bsize, int iterations,
69 CdefFilterBlockFunctions cdef,
70 CdefFilterBlockFunctions ref_cdef, int boundary, int depth) {
71 aom_usec_timer ref_timer;
72 int64_t ref_elapsed_time = 0;
73 const int size = 8;
74 const int ysize = size + 2 * CDEF_VBORDER;
75 ACMRandom rnd(ACMRandom::DeterministicSeed());
76 DECLARE_ALIGNED(16, uint16_t, s[ysize * CDEF_BSTRIDE]);
77 DECLARE_ALIGNED(16, static uint16_t, d[size * size]);
78 DECLARE_ALIGNED(16, static uint16_t, ref_d[size * size]);
79 memset(ref_d, 0, sizeof(ref_d));
80 memset(d, 0, sizeof(d));
81
82 int error = 0, pristrength = 0, secstrength, dir;
83 int pridamping, secdamping, bits, level, count,
84 errdepth = 0, errpristrength = 0, errsecstrength = 0, errboundary = 0,
85 errpridamping = 0, errsecdamping = 0;
86 unsigned int pos = 0;
87
88 const int block_width =
89 ((bsize == BLOCK_8X8) || (bsize == BLOCK_8X4)) ? 8 : 4;
90 const int block_height =
91 ((bsize == BLOCK_8X8) || (bsize == BLOCK_4X8)) ? 8 : 4;
92 const unsigned int max_pos = size * size >> static_cast<int>(depth == 8);
93 for (pridamping = 3 + depth - 8; pridamping < 7 - 3 * !!boundary + depth - 8;
94 pridamping++) {
95 for (secdamping = 3 + depth - 8;
96 secdamping < 7 - 3 * !!boundary + depth - 8; secdamping++) {
97 for (count = 0; count < iterations; count++) {
98 for (level = 0; level < (1 << depth) && !error;
99 level += (2 + 6 * !!boundary) << (depth - 8)) {
100 for (bits = 1; bits <= depth && !error; bits += 1 + 3 * !!boundary) {
101 for (unsigned int i = 0; i < sizeof(s) / sizeof(*s); i++)
102 s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0,
103 (1 << depth) - 1);
104 if (boundary) {
105 if (boundary & 1) { // Left
106 for (int i = 0; i < ysize; i++)
107 for (int j = 0; j < CDEF_HBORDER; j++)
108 s[i * CDEF_BSTRIDE + j] = CDEF_VERY_LARGE;
109 }
110 if (boundary & 2) { // Right
111 for (int i = 0; i < ysize; i++)
112 for (int j = CDEF_HBORDER + size; j < CDEF_BSTRIDE; j++)
113 s[i * CDEF_BSTRIDE + j] = CDEF_VERY_LARGE;
114 }
115 if (boundary & 4) { // Above
116 for (int i = 0; i < CDEF_VBORDER; i++)
117 for (int j = 0; j < CDEF_BSTRIDE; j++)
118 s[i * CDEF_BSTRIDE + j] = CDEF_VERY_LARGE;
119 }
120 if (boundary & 8) { // Below
121 for (int i = CDEF_VBORDER + size; i < ysize; i++)
122 for (int j = 0; j < CDEF_BSTRIDE; j++)
123 s[i * CDEF_BSTRIDE + j] = CDEF_VERY_LARGE;
124 }
125 }
126 for (dir = 0; dir < 8; dir++) {
127 for (pristrength = 0; pristrength <= 19 << (depth - 8) && !error;
128 pristrength += (1 + 4 * !!boundary) << (depth - 8)) {
129 if (pristrength == 16) pristrength = 19;
130 for (secstrength = 0; secstrength <= 4 << (depth - 8) && !error;
131 secstrength += 1 << (depth - 8)) {
132 if (secstrength == 3 << (depth - 8)) continue;
133
134 const int strength_index =
135 (secstrength == 0) | ((pristrength == 0) << 1);
136
137 aom_usec_timer_start(&ref_timer);
138 ref_cdef[strength_index](
139 ref_d, size,
140 s + CDEF_HBORDER + CDEF_VBORDER * CDEF_BSTRIDE,
141 pristrength, secstrength, dir, pridamping, secdamping,
142 depth - 8, block_width, block_height);
143 aom_usec_timer_mark(&ref_timer);
144 ref_elapsed_time += aom_usec_timer_elapsed(&ref_timer);
145 // If cdef and ref_cdef are the same, we're just testing
146 // speed
147 if (cdef[0] != ref_cdef[0])
148 API_REGISTER_STATE_CHECK(cdef[strength_index](
149 d, size, s + CDEF_HBORDER + CDEF_VBORDER * CDEF_BSTRIDE,
150 pristrength, secstrength, dir, pridamping, secdamping,
151 depth - 8, block_width, block_height));
152 if (ref_cdef[0] != cdef[0]) {
153 for (pos = 0; pos < max_pos && !error; pos++) {
154 error = ref_d[pos] != d[pos];
155 errdepth = depth;
156 errpristrength = pristrength;
157 errsecstrength = secstrength;
158 errboundary = boundary;
159 errpridamping = pridamping;
160 errsecdamping = secdamping;
161 }
162 }
163 }
164 }
165 }
166 }
167 }
168 }
169 }
170 }
171
172 pos--;
173 EXPECT_EQ(0, error) << "Error: CDEFBlockTest, SIMD and C mismatch."
174 << std::endl
175 << "First error at " << pos % size << "," << pos / size
176 << " (" << (int16_t)ref_d[pos] << " : " << (int16_t)d[pos]
177 << ") " << std::endl
178 << "pristrength: " << errpristrength << std::endl
179 << "pridamping: " << errpridamping << std::endl
180 << "secstrength: " << errsecstrength << std::endl
181 << "secdamping: " << errsecdamping << std::endl
182 << "depth: " << errdepth << std::endl
183 << "size: " << bsize << std::endl
184 << "boundary: " << errboundary << std::endl
185 << std::endl;
186
187 return ref_elapsed_time;
188 }
189
test_cdef_speed(BLOCK_SIZE bsize,int iterations,CdefFilterBlockFunctions cdef,CdefFilterBlockFunctions ref_cdef,int boundary,int depth)190 void test_cdef_speed(BLOCK_SIZE bsize, int iterations,
191 CdefFilterBlockFunctions cdef,
192 CdefFilterBlockFunctions ref_cdef, int boundary,
193 int depth) {
194 int64_t ref_elapsed_time =
195 test_cdef(bsize, iterations, ref_cdef, ref_cdef, boundary, depth);
196
197 int64_t elapsed_time =
198 test_cdef(bsize, iterations, cdef, cdef, boundary, depth);
199
200 std::cout << "C time: " << ref_elapsed_time << " us" << std::endl
201 << "SIMD time: " << elapsed_time << " us" << std::endl;
202
203 EXPECT_GT(ref_elapsed_time, elapsed_time)
204 << "Error: CDEFSpeedTest, SIMD slower than C." << std::endl
205 << "C time: " << ref_elapsed_time << " us" << std::endl
206 << "SIMD time: " << elapsed_time << " us" << std::endl;
207 }
208
209 typedef int (*find_dir_t)(const uint16_t *img, int stride, int32_t *var,
210 int coeff_shift);
211
212 typedef std::tuple<find_dir_t, find_dir_t> find_dir_param_t;
213
214 class CDEFFindDirTest : public ::testing::TestWithParam<find_dir_param_t> {
215 public:
216 ~CDEFFindDirTest() override = default;
SetUp()217 void SetUp() override {
218 finddir = GET_PARAM(0);
219 ref_finddir = GET_PARAM(1);
220 }
221
222 protected:
223 find_dir_t finddir;
224 find_dir_t ref_finddir;
225 };
226 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFFindDirTest);
227
228 typedef CDEFFindDirTest CDEFFindDirSpeedTest;
229 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFFindDirSpeedTest);
230
test_finddir(int (* finddir)(const uint16_t * img,int stride,int32_t * var,int coeff_shift),int (* ref_finddir)(const uint16_t * img,int stride,int32_t * var,int coeff_shift))231 void test_finddir(int (*finddir)(const uint16_t *img, int stride, int32_t *var,
232 int coeff_shift),
233 int (*ref_finddir)(const uint16_t *img, int stride,
234 int32_t *var, int coeff_shift)) {
235 const int size = 8;
236 ACMRandom rnd(ACMRandom::DeterministicSeed());
237 DECLARE_ALIGNED(16, uint16_t, s[size * size]);
238
239 int error = 0;
240 int depth, bits, level, count, errdepth = 0;
241 int ref_res = 0, res = 0;
242 int32_t ref_var = 0, var = 0;
243
244 for (depth = 8; depth <= 12 && !error; depth += 2) {
245 for (count = 0; count < 512 && !error; count++) {
246 for (level = 0; level < (1 << depth) && !error;
247 level += 1 << (depth - 8)) {
248 for (bits = 1; bits <= depth && !error; bits++) {
249 for (unsigned int i = 0; i < sizeof(s) / sizeof(*s); i++)
250 s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0,
251 (1 << depth) - 1);
252 for (int c = 0; c < 1 + 9 * (finddir == ref_finddir); c++)
253 ref_res = ref_finddir(s, size, &ref_var, depth - 8);
254 if (finddir != ref_finddir)
255 API_REGISTER_STATE_CHECK(res = finddir(s, size, &var, depth - 8));
256 if (ref_finddir != finddir) {
257 if (res != ref_res || var != ref_var) error = 1;
258 errdepth = depth;
259 }
260 }
261 }
262 }
263 }
264
265 EXPECT_EQ(0, error) << "Error: CDEFFindDirTest, SIMD and C mismatch."
266 << std::endl
267 << "return: " << res << " : " << ref_res << std::endl
268 << "var: " << var << " : " << ref_var << std::endl
269 << "depth: " << errdepth << std::endl
270 << std::endl;
271 }
272
test_finddir_speed(int (* finddir)(const uint16_t * img,int stride,int32_t * var,int coeff_shift),int (* ref_finddir)(const uint16_t * img,int stride,int32_t * var,int coeff_shift))273 void test_finddir_speed(int (*finddir)(const uint16_t *img, int stride,
274 int32_t *var, int coeff_shift),
275 int (*ref_finddir)(const uint16_t *img, int stride,
276 int32_t *var, int coeff_shift)) {
277 aom_usec_timer ref_timer;
278 aom_usec_timer timer;
279
280 aom_usec_timer_start(&ref_timer);
281 test_finddir(ref_finddir, ref_finddir);
282 aom_usec_timer_mark(&ref_timer);
283 int64_t ref_elapsed_time = aom_usec_timer_elapsed(&ref_timer);
284
285 aom_usec_timer_start(&timer);
286 test_finddir(finddir, finddir);
287 aom_usec_timer_mark(&timer);
288 int64_t elapsed_time = aom_usec_timer_elapsed(&timer);
289
290 EXPECT_GT(ref_elapsed_time, elapsed_time)
291 << "Error: CDEFFindDirSpeedTest, SIMD slower than C." << std::endl
292 << "C time: " << ref_elapsed_time << " us" << std::endl
293 << "SIMD time: " << elapsed_time << " us" << std::endl;
294 }
295
296 typedef void (*find_dir_dual_t)(const uint16_t *img1, const uint16_t *img2,
297 int stride, int32_t *var1, int32_t *var2,
298 int coeff_shift, int *out1, int *out2);
299
300 typedef std::tuple<find_dir_dual_t, find_dir_dual_t> find_dir_dual_param_t;
301
302 class CDEFFindDirDualTest
303 : public ::testing::TestWithParam<find_dir_dual_param_t> {
304 public:
305 ~CDEFFindDirDualTest() override = default;
SetUp()306 void SetUp() override {
307 finddir = GET_PARAM(0);
308 ref_finddir = GET_PARAM(1);
309 }
310
311 protected:
312 find_dir_dual_t finddir;
313 find_dir_dual_t ref_finddir;
314 };
315 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFFindDirDualTest);
316
317 typedef CDEFFindDirDualTest CDEFFindDirDualSpeedTest;
318 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFFindDirDualSpeedTest);
319
test_finddir_dual(void (* finddir)(const uint16_t * img1,const uint16_t * img2,int stride,int32_t * var1,int32_t * var2,int coeff_shift,int * out1,int * out2),void (* ref_finddir)(const uint16_t * img1,const uint16_t * img2,int stride,int32_t * var1,int32_t * var2,int coeff_shift,int * out1,int * out2))320 void test_finddir_dual(
321 void (*finddir)(const uint16_t *img1, const uint16_t *img2, int stride,
322 int32_t *var1, int32_t *var2, int coeff_shift, int *out1,
323 int *out2),
324 void (*ref_finddir)(const uint16_t *img1, const uint16_t *img2, int stride,
325 int32_t *var1, int32_t *var2, int coeff_shift,
326 int *out1, int *out2)) {
327 const int size_wd = 16;
328 const int size_ht = 8;
329 ACMRandom rnd(ACMRandom::DeterministicSeed());
330 DECLARE_ALIGNED(16, uint16_t, s[size_ht * size_wd]);
331
332 int error = 0, errdepth = 0;
333 int32_t ref_var[2] = { 0 };
334 int ref_dir[2] = { 0 };
335 int32_t var[2] = { 0 };
336 int dir[2] = { 0 };
337
338 for (int depth = 8; depth <= 12 && !error; depth += 2) {
339 for (int count = 0; count < 512 && !error; count++) {
340 for (int level = 0; level < (1 << depth) && !error;
341 level += 1 << (depth - 8)) {
342 for (int bits = 1; bits <= depth && !error; bits++) {
343 for (unsigned int i = 0; i < sizeof(s) / sizeof(*s); i++)
344 s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0,
345 (1 << depth) - 1);
346 for (int c = 0; c < 1 + 9 * (finddir == ref_finddir); c++)
347 ref_finddir(s, s + 8, size_wd, &ref_var[0], &ref_var[1], depth - 8,
348 &ref_dir[0], &ref_dir[1]);
349 if (finddir != ref_finddir)
350 API_REGISTER_STATE_CHECK(finddir(s, s + 8, size_wd, &var[0],
351 &var[1], depth - 8, &dir[0],
352 &dir[1]));
353 if (ref_finddir != finddir) {
354 for (int j = 0; j < 2; j++) {
355 if (ref_dir[j] != dir[j] || ref_var[j] != var[j]) error = 1;
356 }
357 errdepth = depth;
358 }
359 }
360 }
361 }
362 }
363
364 for (int j = 0; j < 2; j++) {
365 EXPECT_EQ(0, error) << "Error: CDEFFindDirTest, SIMD and C mismatch."
366 << std::endl
367 << "direction: " << dir[j] << " : " << ref_dir[j]
368 << std::endl
369 << "variance: " << var[j] << " : " << ref_var[j]
370 << std::endl
371 << "depth: " << errdepth << std::endl
372 << std::endl;
373 }
374 }
375
test_finddir_dual_speed(void (* finddir)(const uint16_t * img1,const uint16_t * img2,int stride,int32_t * var1,int32_t * var2,int coeff_shift,int * out1,int * out2),void (* ref_finddir)(const uint16_t * img1,const uint16_t * img2,int stride,int32_t * var1,int32_t * var2,int coeff_shift,int * out1,int * out2))376 void test_finddir_dual_speed(
377 void (*finddir)(const uint16_t *img1, const uint16_t *img2, int stride,
378 int32_t *var1, int32_t *var2, int coeff_shift, int *out1,
379 int *out2),
380 void (*ref_finddir)(const uint16_t *img1, const uint16_t *img2, int stride,
381 int32_t *var1, int32_t *var2, int coeff_shift,
382 int *out1, int *out2)) {
383 aom_usec_timer ref_timer;
384 aom_usec_timer timer;
385
386 aom_usec_timer_start(&ref_timer);
387 test_finddir_dual(ref_finddir, ref_finddir);
388 aom_usec_timer_mark(&ref_timer);
389 const double ref_elapsed_time =
390 static_cast<double>(aom_usec_timer_elapsed(&ref_timer));
391
392 aom_usec_timer_start(&timer);
393 test_finddir_dual(finddir, finddir);
394 aom_usec_timer_mark(&timer);
395 const double elapsed_time =
396 static_cast<double>(aom_usec_timer_elapsed(&timer));
397
398 printf(
399 "ref_time=%lf \t simd_time=%lf \t "
400 "gain=%lf \n",
401 ref_elapsed_time, elapsed_time, ref_elapsed_time / elapsed_time);
402 }
403
404 #define MAX_CDEF_BLOCK 256
405
406 constexpr int kIterations = 100;
407
408 using CDEFCopyRect8To16 = void (*)(uint16_t *dst, int dstride,
409 const uint8_t *src, int sstride, int width,
410 int height);
411
412 using CDEFCopyRect8To16Param = std::tuple<CDEFCopyRect8To16, CDEFCopyRect8To16>;
413
414 class CDEFCopyRect8to16Test
415 : public ::testing::TestWithParam<CDEFCopyRect8To16Param> {
416 public:
CDEFCopyRect8to16Test()417 CDEFCopyRect8to16Test()
418 : rnd_(libaom_test::ACMRandom::DeterministicSeed()),
419 test_func_(GET_PARAM(0)), ref_func_(GET_PARAM(1)) {}
420 ~CDEFCopyRect8to16Test() override = default;
SetUp()421 void SetUp() override {
422 src_ = reinterpret_cast<uint8_t *>(
423 aom_memalign(8, sizeof(uint8_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
424 ASSERT_NE(src_, nullptr);
425 ref_dst_ = reinterpret_cast<uint16_t *>(
426 aom_memalign(16, sizeof(uint16_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
427 ASSERT_NE(ref_dst_, nullptr);
428 test_dst_ = reinterpret_cast<uint16_t *>(
429 aom_memalign(16, sizeof(uint16_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
430 ASSERT_NE(test_dst_, nullptr);
431 }
432
TearDown()433 void TearDown() override {
434 aom_free(src_);
435 aom_free(ref_dst_);
436 aom_free(test_dst_);
437 }
438
test_copy_rect_8_to_16(CDEFCopyRect8To16 test_func,CDEFCopyRect8To16 ref_func)439 void test_copy_rect_8_to_16(CDEFCopyRect8To16 test_func,
440 CDEFCopyRect8To16 ref_func) {
441 constexpr int stride = MAX_CDEF_BLOCK;
442 int error = 0;
443 for (int k = 0; k < kIterations && !error; k++) {
444 // This function operates on values of width that are either 4 or a
445 // multiple of 8. For height, generate a random value between 1 and 256,
446 // making sure it is even.
447 const int width = k == 0 ? 4 : (rnd_.Rand8() % 32 + 1) * 8;
448 const int height = k == 0 ? 4 : (rnd_.Rand8() % 128 + 1) * 2;
449 for (int i = 0; i < height; i++) {
450 for (int j = 0; j < width; j++) {
451 src_[i * stride + j] = rnd_.Rand8();
452 }
453 }
454
455 ref_func(ref_dst_, stride, src_, stride, width, height);
456 test_func(test_dst_, stride, src_, stride, width, height);
457
458 int i, j;
459 for (i = 0; i < height; i++) {
460 for (j = 0; j < width; j++) {
461 if (test_dst_[i * stride + j] != ref_dst_[i * stride + j]) {
462 error = 1;
463 break;
464 }
465 }
466 if (error) {
467 break;
468 }
469 }
470 EXPECT_EQ(0, error)
471 << "Error: CDEFCopyRect8to16Test, SIMD and C mismatch." << std::endl
472 << "First error at " << i << "," << j << " ("
473 << ref_dst_[i * stride + j] << " : " << test_dst_[i * stride + j]
474 << ") " << std::endl
475 << "width: " << width << std::endl
476 << "height: " << height << std::endl
477 << std::endl;
478 }
479 }
480
481 protected:
482 libaom_test::ACMRandom rnd_;
483 uint8_t *src_;
484 uint16_t *ref_dst_;
485 uint16_t *test_dst_;
486 CDEFCopyRect8To16 test_func_;
487 CDEFCopyRect8To16 ref_func_;
488 };
489 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFCopyRect8to16Test);
490
491 #if CONFIG_AV1_HIGHBITDEPTH
492 using CDEFCopyRect16To16 = void (*)(uint16_t *dst, int dstride,
493 const uint16_t *src, int sstride, int width,
494 int height);
495
496 using CDEFCopyRect16To16Param =
497 std::tuple<CDEFCopyRect16To16, CDEFCopyRect16To16>;
498
499 class CDEFCopyRect16to16Test
500 : public ::testing::TestWithParam<CDEFCopyRect16To16Param> {
501 public:
CDEFCopyRect16to16Test()502 CDEFCopyRect16to16Test()
503 : rnd_(libaom_test::ACMRandom::DeterministicSeed()),
504 test_func_(GET_PARAM(0)), ref_func_(GET_PARAM(1)) {}
505 ~CDEFCopyRect16to16Test() override = default;
SetUp()506 void SetUp() override {
507 src_ = reinterpret_cast<uint16_t *>(
508 aom_memalign(16, sizeof(uint16_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
509 ASSERT_NE(src_, nullptr);
510 ref_dst_ = reinterpret_cast<uint16_t *>(
511 aom_memalign(16, sizeof(uint16_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
512 ASSERT_NE(ref_dst_, nullptr);
513 test_dst_ = reinterpret_cast<uint16_t *>(
514 aom_memalign(16, sizeof(uint16_t) * MAX_CDEF_BLOCK * MAX_CDEF_BLOCK));
515 ASSERT_NE(test_dst_, nullptr);
516 }
517
TearDown()518 void TearDown() override {
519 aom_free(src_);
520 aom_free(ref_dst_);
521 aom_free(test_dst_);
522 }
523
test_copy_rect_16_to_16(CDEFCopyRect16To16 test_func,CDEFCopyRect16To16 ref_func)524 void test_copy_rect_16_to_16(CDEFCopyRect16To16 test_func,
525 CDEFCopyRect16To16 ref_func) {
526 constexpr int stride = MAX_CDEF_BLOCK;
527 int error = 0;
528 for (int k = 0; k < kIterations && !error; k++) {
529 // This function operates on values of width that are either 4 or a
530 // multiple of 8. For height, generate a random value between 1 and 256,
531 // making sure it is even.
532 const int width = k == 0 ? 4 : (rnd_.Rand8() % 32 + 1) * 8;
533 const int height = k == 0 ? 4 : (rnd_.Rand8() % 128 + 1) * 2;
534 for (int i = 0; i < height; i++) {
535 for (int j = 0; j < width; j++) {
536 src_[i * stride + j] = rnd_.Rand16();
537 }
538 }
539
540 ref_func(ref_dst_, stride, src_, stride, width, height);
541 test_func(test_dst_, stride, src_, stride, width, height);
542
543 int i, j;
544 for (i = 0; i < height; i++) {
545 for (j = 0; j < width; j++) {
546 if (test_dst_[i * stride + j] != ref_dst_[i * stride + j]) {
547 error = 1;
548 break;
549 }
550 }
551 if (error) {
552 break;
553 }
554 }
555 EXPECT_EQ(0, error)
556 << "Error: CDEFCopyRect16to16Test, SIMD and C mismatch." << std::endl
557 << "First error at " << i << "," << j << " ("
558 << ref_dst_[i * stride + j] << " : " << test_dst_[i * stride + j]
559 << ") " << std::endl
560 << "width: " << width << std::endl
561 << "height: " << height << std::endl
562 << std::endl;
563 }
564 }
565
566 protected:
567 libaom_test::ACMRandom rnd_;
568 uint16_t *src_;
569 uint16_t *ref_dst_;
570 uint16_t *test_dst_;
571 CDEFCopyRect16To16 test_func_;
572 CDEFCopyRect16To16 ref_func_;
573 };
574 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(CDEFCopyRect16to16Test);
575 #endif // CONFIG_AV1_HIGHBITDEPTH
576
TEST_P(CDEFBlockTest,TestSIMDNoMismatch)577 TEST_P(CDEFBlockTest, TestSIMDNoMismatch) {
578 test_cdef(bsize, 1, cdef, ref_cdef, boundary, depth);
579 }
580
TEST_P(CDEFBlockHighbdTest,TestSIMDHighbdNoMismatch)581 TEST_P(CDEFBlockHighbdTest, TestSIMDHighbdNoMismatch) {
582 test_cdef(bsize, 1, cdef, ref_cdef, boundary, depth);
583 }
584
TEST_P(CDEFSpeedTest,DISABLED_TestSpeed)585 TEST_P(CDEFSpeedTest, DISABLED_TestSpeed) {
586 test_cdef_speed(bsize, 4, cdef, ref_cdef, boundary, depth);
587 }
588
TEST_P(CDEFSpeedHighbdTest,DISABLED_TestSpeed)589 TEST_P(CDEFSpeedHighbdTest, DISABLED_TestSpeed) {
590 test_cdef_speed(bsize, 4, cdef, ref_cdef, boundary, depth);
591 }
592
TEST_P(CDEFFindDirTest,TestSIMDNoMismatch)593 TEST_P(CDEFFindDirTest, TestSIMDNoMismatch) {
594 test_finddir(finddir, ref_finddir);
595 }
596
TEST_P(CDEFFindDirSpeedTest,DISABLED_TestSpeed)597 TEST_P(CDEFFindDirSpeedTest, DISABLED_TestSpeed) {
598 test_finddir_speed(finddir, ref_finddir);
599 }
600
TEST_P(CDEFFindDirDualTest,TestSIMDNoMismatch)601 TEST_P(CDEFFindDirDualTest, TestSIMDNoMismatch) {
602 test_finddir_dual(finddir, ref_finddir);
603 }
604
TEST_P(CDEFFindDirDualSpeedTest,DISABLED_TestSpeed)605 TEST_P(CDEFFindDirDualSpeedTest, DISABLED_TestSpeed) {
606 test_finddir_dual_speed(finddir, ref_finddir);
607 }
608
TEST_P(CDEFCopyRect8to16Test,TestSIMDNoMismatch)609 TEST_P(CDEFCopyRect8to16Test, TestSIMDNoMismatch) {
610 test_copy_rect_8_to_16(test_func_, ref_func_);
611 }
612
613 #if CONFIG_AV1_HIGHBITDEPTH
TEST_P(CDEFCopyRect16to16Test,TestSIMDNoMismatch)614 TEST_P(CDEFCopyRect16to16Test, TestSIMDNoMismatch) {
615 test_copy_rect_16_to_16(test_func_, ref_func_);
616 }
617 #endif // CONFIG_AV1_HIGHBITDEPTH
618
619 using std::make_tuple;
620
621 #if ((AOM_ARCH_X86 && HAVE_SSSE3) || HAVE_SSE4_1 || HAVE_AVX2 || HAVE_NEON)
622 static const CdefFilterBlockFunctions kCdefFilterFuncC[] = {
623 { &cdef_filter_8_0_c, &cdef_filter_8_1_c, &cdef_filter_8_2_c,
624 &cdef_filter_8_3_c }
625 };
626
627 static const CdefFilterBlockFunctions kCdefFilterHighbdFuncC[] = {
628 { &cdef_filter_16_0_c, &cdef_filter_16_0_c, &cdef_filter_16_0_c,
629 &cdef_filter_16_0_c }
630 };
631 #endif
632
633 #if AOM_ARCH_X86 && HAVE_SSSE3
634 static const CdefFilterBlockFunctions kCdefFilterFuncSsse3[] = {
635 { &cdef_filter_8_0_ssse3, &cdef_filter_8_1_ssse3, &cdef_filter_8_2_ssse3,
636 &cdef_filter_8_3_ssse3 }
637 };
638
639 static const CdefFilterBlockFunctions kCdefFilterHighbdFuncSsse3[] = {
640 { &cdef_filter_16_0_ssse3, &cdef_filter_16_1_ssse3, &cdef_filter_16_2_ssse3,
641 &cdef_filter_16_3_ssse3 }
642 };
643
644 INSTANTIATE_TEST_SUITE_P(
645 SSSE3, CDEFBlockTest,
646 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncSsse3),
647 ::testing::ValuesIn(kCdefFilterFuncC),
648 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
649 BLOCK_8X8),
650 ::testing::Range(0, 16), ::testing::Values(8)));
651 INSTANTIATE_TEST_SUITE_P(
652 SSSE3, CDEFBlockHighbdTest,
653 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncSsse3),
654 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
655 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
656 BLOCK_8X8),
657 ::testing::Range(0, 16), ::testing::Range(10, 13, 2)));
658 INSTANTIATE_TEST_SUITE_P(SSSE3, CDEFFindDirTest,
659 ::testing::Values(make_tuple(&cdef_find_dir_ssse3,
660 &cdef_find_dir_c)));
661 INSTANTIATE_TEST_SUITE_P(SSSE3, CDEFFindDirDualTest,
662 ::testing::Values(make_tuple(&cdef_find_dir_dual_ssse3,
663 &cdef_find_dir_dual_c)));
664
665 INSTANTIATE_TEST_SUITE_P(
666 SSSE3, CDEFCopyRect8to16Test,
667 ::testing::Values(make_tuple(&cdef_copy_rect8_8bit_to_16bit_c,
668 &cdef_copy_rect8_8bit_to_16bit_ssse3)));
669
670 #if CONFIG_AV1_HIGHBITDEPTH
671 INSTANTIATE_TEST_SUITE_P(
672 SSSE3, CDEFCopyRect16to16Test,
673 ::testing::Values(make_tuple(&cdef_copy_rect8_16bit_to_16bit_c,
674 &cdef_copy_rect8_16bit_to_16bit_ssse3)));
675 #endif // CONFIG_AV1_HIGHBITDEPTH
676 #endif
677
678 #if HAVE_SSE4_1
679 static const CdefFilterBlockFunctions kCdefFilterFuncSse4_1[] = {
680 { &cdef_filter_8_0_sse4_1, &cdef_filter_8_1_sse4_1, &cdef_filter_8_2_sse4_1,
681 &cdef_filter_8_3_sse4_1 }
682 };
683
684 static const CdefFilterBlockFunctions kCdefFilterHighbdFuncSse4_1[] = {
685 { &cdef_filter_16_0_sse4_1, &cdef_filter_16_1_sse4_1,
686 &cdef_filter_16_2_sse4_1, &cdef_filter_16_3_sse4_1 }
687 };
688
689 INSTANTIATE_TEST_SUITE_P(
690 SSE4_1, CDEFBlockTest,
691 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncSse4_1),
692 ::testing::ValuesIn(kCdefFilterFuncC),
693 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
694 BLOCK_8X8),
695 ::testing::Range(0, 16), ::testing::Values(8)));
696 INSTANTIATE_TEST_SUITE_P(
697 SSE4_1, CDEFBlockHighbdTest,
698 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncSse4_1),
699 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
700 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
701 BLOCK_8X8),
702 ::testing::Range(0, 16), ::testing::Range(10, 13, 2)));
703 INSTANTIATE_TEST_SUITE_P(SSE4_1, CDEFFindDirTest,
704 ::testing::Values(make_tuple(&cdef_find_dir_sse4_1,
705 &cdef_find_dir_c)));
706 INSTANTIATE_TEST_SUITE_P(
707 SSE4_1, CDEFFindDirDualTest,
708 ::testing::Values(make_tuple(&cdef_find_dir_dual_sse4_1,
709 &cdef_find_dir_dual_c)));
710
711 INSTANTIATE_TEST_SUITE_P(
712 SSE4_1, CDEFCopyRect8to16Test,
713 ::testing::Values(make_tuple(&cdef_copy_rect8_8bit_to_16bit_c,
714 &cdef_copy_rect8_8bit_to_16bit_sse4_1)));
715
716 #if CONFIG_AV1_HIGHBITDEPTH
717 INSTANTIATE_TEST_SUITE_P(
718 SSE4_1, CDEFCopyRect16to16Test,
719 ::testing::Values(make_tuple(&cdef_copy_rect8_16bit_to_16bit_c,
720 &cdef_copy_rect8_16bit_to_16bit_sse4_1)));
721 #endif // CONFIG_AV1_HIGHBITDEPTH
722 #endif
723
724 #if HAVE_AVX2
725 static const CdefFilterBlockFunctions kCdefFilterFuncAvx2[] = {
726 { &cdef_filter_8_0_avx2, &cdef_filter_8_1_avx2, &cdef_filter_8_2_avx2,
727 &cdef_filter_8_3_avx2 }
728 };
729
730 static const CdefFilterBlockFunctions kCdefFilterHighbdFuncAvx2[] = {
731 { &cdef_filter_16_0_avx2, &cdef_filter_16_1_avx2, &cdef_filter_16_2_avx2,
732 &cdef_filter_16_3_avx2 }
733 };
734
735 INSTANTIATE_TEST_SUITE_P(
736 AVX2, CDEFBlockTest,
737 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncAvx2),
738 ::testing::ValuesIn(kCdefFilterFuncC),
739 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
740 BLOCK_8X8),
741 ::testing::Range(0, 16), ::testing::Values(8)));
742 INSTANTIATE_TEST_SUITE_P(
743 AVX2, CDEFBlockHighbdTest,
744 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncAvx2),
745 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
746 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
747 BLOCK_8X8),
748 ::testing::Range(0, 16), ::testing::Range(10, 13, 2)));
749 INSTANTIATE_TEST_SUITE_P(AVX2, CDEFFindDirTest,
750 ::testing::Values(make_tuple(&cdef_find_dir_avx2,
751 &cdef_find_dir_c)));
752 INSTANTIATE_TEST_SUITE_P(AVX2, CDEFFindDirDualTest,
753 ::testing::Values(make_tuple(&cdef_find_dir_dual_avx2,
754 &cdef_find_dir_dual_c)));
755
756 INSTANTIATE_TEST_SUITE_P(
757 AVX2, CDEFCopyRect8to16Test,
758 ::testing::Values(make_tuple(&cdef_copy_rect8_8bit_to_16bit_c,
759 &cdef_copy_rect8_8bit_to_16bit_avx2)));
760
761 #if CONFIG_AV1_HIGHBITDEPTH
762 INSTANTIATE_TEST_SUITE_P(
763 AVX2, CDEFCopyRect16to16Test,
764 ::testing::Values(make_tuple(&cdef_copy_rect8_16bit_to_16bit_c,
765 &cdef_copy_rect8_16bit_to_16bit_avx2)));
766 #endif // CONFIG_AV1_HIGHBITDEPTH
767 #endif
768
769 #if HAVE_NEON
770 static const CdefFilterBlockFunctions kCdefFilterFuncNeon[] = {
771 { &cdef_filter_8_0_neon, &cdef_filter_8_1_neon, &cdef_filter_8_2_neon,
772 &cdef_filter_8_3_neon }
773 };
774
775 static const CdefFilterBlockFunctions kCdefFilterHighbdFuncNeon[] = {
776 { &cdef_filter_16_0_neon, &cdef_filter_16_1_neon, &cdef_filter_16_2_neon,
777 &cdef_filter_16_3_neon }
778 };
779
780 INSTANTIATE_TEST_SUITE_P(
781 NEON, CDEFBlockTest,
782 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncNeon),
783 ::testing::ValuesIn(kCdefFilterFuncC),
784 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
785 BLOCK_8X8),
786 ::testing::Range(0, 16), ::testing::Values(8)));
787 INSTANTIATE_TEST_SUITE_P(
788 NEON, CDEFBlockHighbdTest,
789 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncNeon),
790 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
791 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
792 BLOCK_8X8),
793 ::testing::Range(0, 16), ::testing::Range(10, 13, 2)));
794 INSTANTIATE_TEST_SUITE_P(NEON, CDEFFindDirTest,
795 ::testing::Values(make_tuple(&cdef_find_dir_neon,
796 &cdef_find_dir_c)));
797 INSTANTIATE_TEST_SUITE_P(NEON, CDEFFindDirDualTest,
798 ::testing::Values(make_tuple(&cdef_find_dir_dual_neon,
799 &cdef_find_dir_dual_c)));
800
801 INSTANTIATE_TEST_SUITE_P(
802 NEON, CDEFCopyRect8to16Test,
803 ::testing::Values(make_tuple(&cdef_copy_rect8_8bit_to_16bit_c,
804 &cdef_copy_rect8_8bit_to_16bit_neon)));
805
806 #if CONFIG_AV1_HIGHBITDEPTH
807 INSTANTIATE_TEST_SUITE_P(
808 NEON, CDEFCopyRect16to16Test,
809 ::testing::Values(make_tuple(&cdef_copy_rect8_16bit_to_16bit_c,
810 &cdef_copy_rect8_16bit_to_16bit_neon)));
811 #endif // CONFIG_AV1_HIGHBITDEPTH
812 #endif
813
814 // Test speed for all supported architectures
815 #if AOM_ARCH_X86 && HAVE_SSSE3
816 INSTANTIATE_TEST_SUITE_P(
817 SSSE3, CDEFSpeedTest,
818 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncSsse3),
819 ::testing::ValuesIn(kCdefFilterFuncC),
820 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
821 BLOCK_8X8),
822 ::testing::Range(0, 16), ::testing::Values(8)));
823 INSTANTIATE_TEST_SUITE_P(
824 SSSE3, CDEFSpeedHighbdTest,
825 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncSsse3),
826 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
827 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
828 BLOCK_8X8),
829 ::testing::Range(0, 16), ::testing::Values(10)));
830 INSTANTIATE_TEST_SUITE_P(SSSE3, CDEFFindDirSpeedTest,
831 ::testing::Values(make_tuple(&cdef_find_dir_ssse3,
832 &cdef_find_dir_c)));
833 INSTANTIATE_TEST_SUITE_P(SSSE3, CDEFFindDirDualSpeedTest,
834 ::testing::Values(make_tuple(&cdef_find_dir_dual_ssse3,
835 &cdef_find_dir_dual_c)));
836 #endif
837
838 #if HAVE_SSE4_1
839 INSTANTIATE_TEST_SUITE_P(
840 SSE4_1, CDEFSpeedTest,
841 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncSse4_1),
842 ::testing::ValuesIn(kCdefFilterFuncC),
843 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
844 BLOCK_8X8),
845 ::testing::Range(0, 16), ::testing::Values(8)));
846 INSTANTIATE_TEST_SUITE_P(
847 SSE4_1, CDEFSpeedHighbdTest,
848 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncSse4_1),
849 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
850 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
851 BLOCK_8X8),
852 ::testing::Range(0, 16), ::testing::Values(10)));
853 INSTANTIATE_TEST_SUITE_P(SSE4_1, CDEFFindDirSpeedTest,
854 ::testing::Values(make_tuple(&cdef_find_dir_sse4_1,
855 &cdef_find_dir_c)));
856 INSTANTIATE_TEST_SUITE_P(
857 SSE4_1, CDEFFindDirDualSpeedTest,
858 ::testing::Values(make_tuple(&cdef_find_dir_dual_sse4_1,
859 &cdef_find_dir_dual_c)));
860 #endif
861
862 #if HAVE_AVX2
863 INSTANTIATE_TEST_SUITE_P(
864 AVX2, CDEFSpeedTest,
865 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncAvx2),
866 ::testing::ValuesIn(kCdefFilterFuncC),
867 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
868 BLOCK_8X8),
869 ::testing::Range(0, 16), ::testing::Values(8)));
870 INSTANTIATE_TEST_SUITE_P(
871 AVX2, CDEFSpeedHighbdTest,
872 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncAvx2),
873 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
874 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
875 BLOCK_8X8),
876 ::testing::Range(0, 16), ::testing::Values(10)));
877 INSTANTIATE_TEST_SUITE_P(AVX2, CDEFFindDirSpeedTest,
878 ::testing::Values(make_tuple(&cdef_find_dir_avx2,
879 &cdef_find_dir_c)));
880 INSTANTIATE_TEST_SUITE_P(AVX2, CDEFFindDirDualSpeedTest,
881 ::testing::Values(make_tuple(&cdef_find_dir_dual_avx2,
882 &cdef_find_dir_dual_c)));
883 #endif
884
885 #if HAVE_NEON
886 INSTANTIATE_TEST_SUITE_P(
887 NEON, CDEFSpeedTest,
888 ::testing::Combine(::testing::ValuesIn(kCdefFilterFuncNeon),
889 ::testing::ValuesIn(kCdefFilterFuncC),
890 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
891 BLOCK_8X8),
892 ::testing::Range(0, 16), ::testing::Values(8)));
893 INSTANTIATE_TEST_SUITE_P(
894 NEON, CDEFSpeedHighbdTest,
895 ::testing::Combine(::testing::ValuesIn(kCdefFilterHighbdFuncNeon),
896 ::testing::ValuesIn(kCdefFilterHighbdFuncC),
897 ::testing::Values(BLOCK_4X4, BLOCK_4X8, BLOCK_8X4,
898 BLOCK_8X8),
899 ::testing::Range(0, 16), ::testing::Values(10)));
900 INSTANTIATE_TEST_SUITE_P(NEON, CDEFFindDirSpeedTest,
901 ::testing::Values(make_tuple(&cdef_find_dir_neon,
902 &cdef_find_dir_c)));
903 INSTANTIATE_TEST_SUITE_P(NEON, CDEFFindDirDualSpeedTest,
904 ::testing::Values(make_tuple(&cdef_find_dir_dual_neon,
905 &cdef_find_dir_dual_c)));
906 #endif
907
908 } // namespace
909