1 /*
2 * Copyright (c) 2018, 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 #ifndef AOM_TEST_COMP_AVG_PRED_TEST_H_
13 #define AOM_TEST_COMP_AVG_PRED_TEST_H_
14
15 #include <tuple>
16
17 #include "config/aom_dsp_rtcd.h"
18 #include "config/av1_rtcd.h"
19
20 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
21 #include "test/acm_random.h"
22 #include "test/util.h"
23 #include "test/register_state_check.h"
24 #include "av1/common/common_data.h"
25 #include "aom_ports/aom_timer.h"
26
27 namespace libaom_test {
28 const int kMaxSize = 128 + 32; // padding
29
30 namespace AV1DISTWTDCOMPAVG {
31
32 typedef void (*distwtdcompavg_func)(uint8_t *comp_pred, const uint8_t *pred,
33 int width, int height, const uint8_t *ref,
34 int ref_stride,
35 const DIST_WTD_COMP_PARAMS *jcp_param);
36
37 typedef void (*distwtdcompavgupsampled_func)(
38 MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
39 const MV *const mv, uint8_t *comp_pred, const uint8_t *pred, int width,
40 int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref,
41 int ref_stride, const DIST_WTD_COMP_PARAMS *jcp_param, int subpel_search);
42
43 typedef void (*DistWtdCompAvgFunc)(uint8_t *comp_pred, const uint8_t *pred,
44 int width, int height, const uint8_t *ref,
45 int ref_stride,
46 const DIST_WTD_COMP_PARAMS *jcp_param);
47
48 typedef std::tuple<distwtdcompavg_func, BLOCK_SIZE> DISTWTDCOMPAVGParam;
49
50 typedef std::tuple<distwtdcompavgupsampled_func, BLOCK_SIZE>
51 DISTWTDCOMPAVGUPSAMPLEDParam;
52
53 typedef std::tuple<int, int, DistWtdCompAvgFunc, int> DistWtdCompAvgParam;
54
55 #if CONFIG_AV1_HIGHBITDEPTH
56 typedef void (*highbddistwtdcompavgupsampled_func)(
57 MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
58 const MV *const mv, uint8_t *comp_pred8, const uint8_t *pred8, int width,
59 int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8,
60 int ref_stride, int bd, const DIST_WTD_COMP_PARAMS *jcp_param,
61 int subpel_search);
62
63 typedef std::tuple<int, highbddistwtdcompavgupsampled_func, BLOCK_SIZE>
64 HighbdDISTWTDCOMPAVGUPSAMPLEDParam;
65
66 typedef std::tuple<int, distwtdcompavg_func, BLOCK_SIZE>
67 HighbdDISTWTDCOMPAVGParam;
68
BuildParams(distwtdcompavg_func filter,int is_hbd)69 ::testing::internal::ParamGenerator<HighbdDISTWTDCOMPAVGParam> BuildParams(
70 distwtdcompavg_func filter, int is_hbd) {
71 (void)is_hbd;
72 return ::testing::Combine(::testing::Range(8, 13, 2),
73 ::testing::Values(filter),
74 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
75 }
76
77 ::testing::internal::ParamGenerator<HighbdDISTWTDCOMPAVGUPSAMPLEDParam>
BuildParams(highbddistwtdcompavgupsampled_func filter)78 BuildParams(highbddistwtdcompavgupsampled_func filter) {
79 return ::testing::Combine(::testing::Range(8, 13, 2),
80 ::testing::Values(filter),
81 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
82 }
83 #endif // CONFIG_AV1_HIGHBITDEPTH
84
BuildParams(distwtdcompavg_func filter)85 ::testing::internal::ParamGenerator<DISTWTDCOMPAVGParam> BuildParams(
86 distwtdcompavg_func filter) {
87 return ::testing::Combine(::testing::Values(filter),
88 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
89 }
90
BuildParams(distwtdcompavgupsampled_func filter)91 ::testing::internal::ParamGenerator<DISTWTDCOMPAVGUPSAMPLEDParam> BuildParams(
92 distwtdcompavgupsampled_func filter) {
93 return ::testing::Combine(::testing::Values(filter),
94 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
95 }
96
97 class AV1DISTWTDCOMPAVGTest
98 : public ::testing::TestWithParam<DISTWTDCOMPAVGParam> {
99 public:
100 ~AV1DISTWTDCOMPAVGTest() override = default;
SetUp()101 void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); }
102
103 protected:
RunCheckOutput(distwtdcompavg_func test_impl)104 void RunCheckOutput(distwtdcompavg_func test_impl) {
105 const int w = kMaxSize, h = kMaxSize;
106 const int block_idx = GET_PARAM(1);
107
108 uint8_t pred8[kMaxSize * kMaxSize];
109 uint8_t ref8[kMaxSize * kMaxSize];
110 uint8_t output[kMaxSize * kMaxSize];
111 uint8_t output2[kMaxSize * kMaxSize];
112
113 for (int i = 0; i < h; ++i)
114 for (int j = 0; j < w; ++j) {
115 pred8[i * w + j] = rnd_.Rand8();
116 ref8[i * w + j] = rnd_.Rand8();
117 }
118 const int in_w = block_size_wide[block_idx];
119 const int in_h = block_size_high[block_idx];
120
121 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
122 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
123
124 for (int ii = 0; ii < 2; ii++) {
125 for (int jj = 0; jj < 4; jj++) {
126 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
127 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[jj][1 - ii];
128
129 const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
130 const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
131 aom_dist_wtd_comp_avg_pred_c(output, pred8 + offset_r * w + offset_c,
132 in_w, in_h, ref8 + offset_r * w + offset_c,
133 in_w, &dist_wtd_comp_params);
134 test_impl(output2, pred8 + offset_r * w + offset_c, in_w, in_h,
135 ref8 + offset_r * w + offset_c, in_w, &dist_wtd_comp_params);
136
137 for (int i = 0; i < in_h; ++i) {
138 for (int j = 0; j < in_w; ++j) {
139 int idx = i * in_w + j;
140 ASSERT_EQ(output[idx], output2[idx])
141 << "Mismatch at unit tests for AV1DISTWTDCOMPAVGTest\n"
142 << in_w << "x" << in_h << " Pixel mismatch at index " << idx
143 << " = (" << i << ", " << j << ")";
144 }
145 }
146 }
147 }
148 }
RunSpeedTest(distwtdcompavg_func test_impl)149 void RunSpeedTest(distwtdcompavg_func test_impl) {
150 const int w = kMaxSize, h = kMaxSize;
151 const int block_idx = GET_PARAM(1);
152
153 uint8_t pred8[kMaxSize * kMaxSize];
154 uint8_t ref8[kMaxSize * kMaxSize];
155 uint8_t output[kMaxSize * kMaxSize];
156 uint8_t output2[kMaxSize * kMaxSize];
157
158 for (int i = 0; i < h; ++i)
159 for (int j = 0; j < w; ++j) {
160 pred8[i * w + j] = rnd_.Rand8();
161 ref8[i * w + j] = rnd_.Rand8();
162 }
163 const int in_w = block_size_wide[block_idx];
164 const int in_h = block_size_high[block_idx];
165
166 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
167 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
168
169 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
170 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
171
172 const int num_loops = 1000000000 / (in_w + in_h);
173 aom_usec_timer timer;
174 aom_usec_timer_start(&timer);
175
176 for (int i = 0; i < num_loops; ++i)
177 aom_dist_wtd_comp_avg_pred_c(output, pred8, in_w, in_h, ref8, in_w,
178 &dist_wtd_comp_params);
179
180 aom_usec_timer_mark(&timer);
181 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
182 printf("distwtdcompavg c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
183 1000.0 * elapsed_time / num_loops);
184
185 aom_usec_timer timer1;
186 aom_usec_timer_start(&timer1);
187
188 for (int i = 0; i < num_loops; ++i)
189 test_impl(output2, pred8, in_w, in_h, ref8, in_w, &dist_wtd_comp_params);
190
191 aom_usec_timer_mark(&timer1);
192 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
193 printf("distwtdcompavg test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
194 1000.0 * elapsed_time1 / num_loops);
195 }
196
197 libaom_test::ACMRandom rnd_;
198 }; // class AV1DISTWTDCOMPAVGTest
199
200 class AV1DISTWTDCOMPAVGUPSAMPLEDTest
201 : public ::testing::TestWithParam<DISTWTDCOMPAVGUPSAMPLEDParam> {
202 public:
203 ~AV1DISTWTDCOMPAVGUPSAMPLEDTest() override = default;
SetUp()204 void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); }
205
206 protected:
RunCheckOutput(distwtdcompavgupsampled_func test_impl)207 void RunCheckOutput(distwtdcompavgupsampled_func test_impl) {
208 const int w = kMaxSize, h = kMaxSize;
209 const int block_idx = GET_PARAM(1);
210
211 uint8_t pred8[kMaxSize * kMaxSize];
212 uint8_t ref8[kMaxSize * kMaxSize];
213 DECLARE_ALIGNED(16, uint8_t, output[MAX_SB_SQUARE]);
214 DECLARE_ALIGNED(16, uint8_t, output2[MAX_SB_SQUARE]);
215
216 for (int i = 0; i < h; ++i)
217 for (int j = 0; j < w; ++j) {
218 pred8[i * w + j] = rnd_.Rand8();
219 ref8[i * w + j] = rnd_.Rand8();
220 }
221 const int in_w = block_size_wide[block_idx];
222 const int in_h = block_size_high[block_idx];
223
224 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
225 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
226 int sub_x_q3, sub_y_q3;
227 int subpel_search;
228 for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
229 ++subpel_search) {
230 for (sub_x_q3 = 0; sub_x_q3 < 8; ++sub_x_q3) {
231 for (sub_y_q3 = 0; sub_y_q3 < 8; ++sub_y_q3) {
232 for (int ii = 0; ii < 2; ii++) {
233 for (int jj = 0; jj < 4; jj++) {
234 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
235 dist_wtd_comp_params.bck_offset =
236 quant_dist_lookup_table[jj][1 - ii];
237
238 const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
239 const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
240
241 aom_dist_wtd_comp_avg_upsampled_pred_c(
242 nullptr, nullptr, 0, 0, nullptr, output,
243 pred8 + offset_r * w + offset_c, in_w, in_h, sub_x_q3,
244 sub_y_q3, ref8 + offset_r * w + offset_c, in_w,
245 &dist_wtd_comp_params, subpel_search);
246 test_impl(nullptr, nullptr, 0, 0, nullptr, output2,
247 pred8 + offset_r * w + offset_c, in_w, in_h, sub_x_q3,
248 sub_y_q3, ref8 + offset_r * w + offset_c, in_w,
249 &dist_wtd_comp_params, subpel_search);
250
251 for (int i = 0; i < in_h; ++i) {
252 for (int j = 0; j < in_w; ++j) {
253 int idx = i * in_w + j;
254 ASSERT_EQ(output[idx], output2[idx])
255 << "Mismatch at unit tests for "
256 "AV1DISTWTDCOMPAVGUPSAMPLEDTest\n"
257 << in_w << "x" << in_h << " Pixel mismatch at index "
258 << idx << " = (" << i << ", " << j
259 << "), sub pixel offset = (" << sub_y_q3 << ", "
260 << sub_x_q3 << ")";
261 }
262 }
263 }
264 }
265 }
266 }
267 }
268 }
RunSpeedTest(distwtdcompavgupsampled_func test_impl)269 void RunSpeedTest(distwtdcompavgupsampled_func test_impl) {
270 const int w = kMaxSize, h = kMaxSize;
271 const int block_idx = GET_PARAM(1);
272
273 uint8_t pred8[kMaxSize * kMaxSize];
274 uint8_t ref8[kMaxSize * kMaxSize];
275 DECLARE_ALIGNED(16, uint8_t, output[MAX_SB_SQUARE]);
276 DECLARE_ALIGNED(16, uint8_t, output2[MAX_SB_SQUARE]);
277
278 for (int i = 0; i < h; ++i)
279 for (int j = 0; j < w; ++j) {
280 pred8[i * w + j] = rnd_.Rand8();
281 ref8[i * w + j] = rnd_.Rand8();
282 }
283 const int in_w = block_size_wide[block_idx];
284 const int in_h = block_size_high[block_idx];
285
286 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
287 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
288
289 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
290 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
291
292 int sub_x_q3 = 0;
293 int sub_y_q3 = 0;
294
295 const int num_loops = 1000000000 / (in_w + in_h);
296 aom_usec_timer timer;
297 aom_usec_timer_start(&timer);
298 int subpel_search = USE_8_TAPS; // set to USE_4_TAPS to test 4-tap filter.
299
300 for (int i = 0; i < num_loops; ++i)
301 aom_dist_wtd_comp_avg_upsampled_pred_c(
302 nullptr, nullptr, 0, 0, nullptr, output, pred8, in_w, in_h, sub_x_q3,
303 sub_y_q3, ref8, in_w, &dist_wtd_comp_params, subpel_search);
304
305 aom_usec_timer_mark(&timer);
306 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
307 printf("distwtdcompavgupsampled c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
308 1000.0 * elapsed_time / num_loops);
309
310 aom_usec_timer timer1;
311 aom_usec_timer_start(&timer1);
312
313 for (int i = 0; i < num_loops; ++i)
314 test_impl(nullptr, nullptr, 0, 0, nullptr, output2, pred8, in_w, in_h,
315 sub_x_q3, sub_y_q3, ref8, in_w, &dist_wtd_comp_params,
316 subpel_search);
317
318 aom_usec_timer_mark(&timer1);
319 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
320 printf("distwtdcompavgupsampled test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
321 1000.0 * elapsed_time1 / num_loops);
322 }
323
324 libaom_test::ACMRandom rnd_;
325 }; // class AV1DISTWTDCOMPAVGUPSAMPLEDTest
326
327 class DistWtdCompAvgTest
328 : public ::testing::WithParamInterface<DistWtdCompAvgParam>,
329 public ::testing::Test {
330 public:
DistWtdCompAvgTest()331 DistWtdCompAvgTest()
332 : width_(GET_PARAM(0)), height_(GET_PARAM(1)), bd_(GET_PARAM(3)) {}
333
SetUpTestSuite()334 static void SetUpTestSuite() {
335 reference_data8_ = reinterpret_cast<uint8_t *>(
336 aom_memalign(kDataAlignment, kDataBufferSize));
337 ASSERT_NE(reference_data8_, nullptr);
338 second_pred8_ =
339 reinterpret_cast<uint8_t *>(aom_memalign(kDataAlignment, 128 * 128));
340 ASSERT_NE(second_pred8_, nullptr);
341 comp_pred8_ =
342 reinterpret_cast<uint8_t *>(aom_memalign(kDataAlignment, 128 * 128));
343 ASSERT_NE(comp_pred8_, nullptr);
344 comp_pred8_test_ =
345 reinterpret_cast<uint8_t *>(aom_memalign(kDataAlignment, 128 * 128));
346 ASSERT_NE(comp_pred8_test_, nullptr);
347 reference_data16_ = reinterpret_cast<uint16_t *>(
348 aom_memalign(kDataAlignment, kDataBufferSize * sizeof(uint16_t)));
349 ASSERT_NE(reference_data16_, nullptr);
350 second_pred16_ = reinterpret_cast<uint16_t *>(
351 aom_memalign(kDataAlignment, 128 * 128 * sizeof(uint16_t)));
352 ASSERT_NE(second_pred16_, nullptr);
353 comp_pred16_ = reinterpret_cast<uint16_t *>(
354 aom_memalign(kDataAlignment, 128 * 128 * sizeof(uint16_t)));
355 ASSERT_NE(comp_pred16_, nullptr);
356 comp_pred16_test_ = reinterpret_cast<uint16_t *>(
357 aom_memalign(kDataAlignment, 128 * 128 * sizeof(uint16_t)));
358 ASSERT_NE(comp_pred16_test_, nullptr);
359 }
360
TearDownTestSuite()361 static void TearDownTestSuite() {
362 aom_free(reference_data8_);
363 reference_data8_ = nullptr;
364 aom_free(second_pred8_);
365 second_pred8_ = nullptr;
366 aom_free(comp_pred8_);
367 comp_pred8_ = nullptr;
368 aom_free(comp_pred8_test_);
369 comp_pred8_test_ = nullptr;
370 aom_free(reference_data16_);
371 reference_data16_ = nullptr;
372 aom_free(second_pred16_);
373 second_pred16_ = nullptr;
374 aom_free(comp_pred16_);
375 comp_pred16_ = nullptr;
376 aom_free(comp_pred16_test_);
377 comp_pred16_test_ = nullptr;
378 }
379
380 protected:
381 // Handle up to 4 128x128 blocks, with stride up to 256
382 static const int kDataAlignment = 16;
383 static const int kDataBlockSize = 128 * 256;
384 static const int kDataBufferSize = 4 * kDataBlockSize;
385
SetUp()386 void SetUp() override {
387 if (bd_ == -1) {
388 use_high_bit_depth_ = false;
389 bit_depth_ = AOM_BITS_8;
390 reference_data_ = reference_data8_;
391 second_pred_ = second_pred8_;
392 comp_pred_ = comp_pred8_;
393 comp_pred_test_ = comp_pred8_test_;
394 } else {
395 use_high_bit_depth_ = true;
396 bit_depth_ = static_cast<aom_bit_depth_t>(bd_);
397 reference_data_ = CONVERT_TO_BYTEPTR(reference_data16_);
398 second_pred_ = CONVERT_TO_BYTEPTR(second_pred16_);
399 comp_pred_ = CONVERT_TO_BYTEPTR(comp_pred16_);
400 comp_pred_test_ = CONVERT_TO_BYTEPTR(comp_pred16_test_);
401 }
402 mask_ = (1 << bit_depth_) - 1;
403 reference_stride_ = width_ * 2;
404 rnd_.Reset(ACMRandom::DeterministicSeed());
405 }
406
GetReference(int block_idx)407 virtual uint8_t *GetReference(int block_idx) {
408 if (use_high_bit_depth_)
409 return CONVERT_TO_BYTEPTR(CONVERT_TO_SHORTPTR(reference_data_) +
410 block_idx * kDataBlockSize);
411 return reference_data_ + block_idx * kDataBlockSize;
412 }
413
ReferenceDistWtdCompAvg(int block_idx)414 void ReferenceDistWtdCompAvg(int block_idx) {
415 const uint8_t *const reference8 = GetReference(block_idx);
416 const uint8_t *const second_pred8 = second_pred_;
417 uint8_t *const comp_pred8 = comp_pred_;
418 const uint16_t *const reference16 =
419 CONVERT_TO_SHORTPTR(GetReference(block_idx));
420 const uint16_t *const second_pred16 = CONVERT_TO_SHORTPTR(second_pred_);
421 uint16_t *const comp_pred16 = CONVERT_TO_SHORTPTR(comp_pred_);
422 for (int h = 0; h < height_; ++h) {
423 for (int w = 0; w < width_; ++w) {
424 if (!use_high_bit_depth_) {
425 const int tmp =
426 second_pred8[h * width_ + w] * jcp_param_.bck_offset +
427 reference8[h * reference_stride_ + w] * jcp_param_.fwd_offset;
428 comp_pred8[h * width_ + w] = ROUND_POWER_OF_TWO(tmp, 4);
429 } else {
430 const int tmp =
431 second_pred16[h * width_ + w] * jcp_param_.bck_offset +
432 reference16[h * reference_stride_ + w] * jcp_param_.fwd_offset;
433 comp_pred16[h * width_ + w] = ROUND_POWER_OF_TWO(tmp, 4);
434 }
435 }
436 }
437 }
438
FillConstant(uint8_t * data,int stride,uint16_t fill_constant)439 void FillConstant(uint8_t *data, int stride, uint16_t fill_constant) {
440 uint8_t *data8 = data;
441 uint16_t *data16 = CONVERT_TO_SHORTPTR(data);
442 for (int h = 0; h < height_; ++h) {
443 for (int w = 0; w < width_; ++w) {
444 if (!use_high_bit_depth_) {
445 data8[h * stride + w] = static_cast<uint8_t>(fill_constant);
446 } else {
447 data16[h * stride + w] = fill_constant;
448 }
449 }
450 }
451 }
452
FillRandom(uint8_t * data,int stride)453 void FillRandom(uint8_t *data, int stride) {
454 uint8_t *data8 = data;
455 uint16_t *data16 = CONVERT_TO_SHORTPTR(data);
456 for (int h = 0; h < height_; ++h) {
457 for (int w = 0; w < width_; ++w) {
458 if (!use_high_bit_depth_) {
459 data8[h * stride + w] = rnd_.Rand8();
460 } else {
461 data16[h * stride + w] = rnd_.Rand16() & mask_;
462 }
463 }
464 }
465 }
466
dist_wtd_comp_avg(int block_idx)467 void dist_wtd_comp_avg(int block_idx) {
468 const uint8_t *const reference = GetReference(block_idx);
469
470 API_REGISTER_STATE_CHECK(GET_PARAM(2)(comp_pred_test_, second_pred_, width_,
471 height_, reference, reference_stride_,
472 &jcp_param_));
473 }
474
CheckCompAvg()475 void CheckCompAvg() {
476 for (int j = 0; j < 2; ++j) {
477 for (int i = 0; i < 4; ++i) {
478 jcp_param_.fwd_offset = quant_dist_lookup_table[i][j];
479 jcp_param_.bck_offset = quant_dist_lookup_table[i][1 - j];
480
481 ReferenceDistWtdCompAvg(0);
482 dist_wtd_comp_avg(0);
483
484 for (int y = 0; y < height_; ++y)
485 for (int x = 0; x < width_; ++x)
486 ASSERT_EQ(comp_pred_[y * width_ + x],
487 comp_pred_test_[y * width_ + x]);
488 }
489 }
490 }
491
492 int width_, height_, mask_, bd_;
493 aom_bit_depth_t bit_depth_;
494 static uint8_t *reference_data_;
495 static uint8_t *second_pred_;
496 bool use_high_bit_depth_;
497 static uint8_t *reference_data8_;
498 static uint8_t *second_pred8_;
499 static uint16_t *reference_data16_;
500 static uint16_t *second_pred16_;
501 int reference_stride_;
502 static uint8_t *comp_pred_;
503 static uint8_t *comp_pred8_;
504 static uint16_t *comp_pred16_;
505 static uint8_t *comp_pred_test_;
506 static uint8_t *comp_pred8_test_;
507 static uint16_t *comp_pred16_test_;
508 DIST_WTD_COMP_PARAMS jcp_param_;
509
510 ACMRandom rnd_;
511 };
512
513 #if CONFIG_AV1_HIGHBITDEPTH
514 class AV1HighBDDISTWTDCOMPAVGTest
515 : public ::testing::TestWithParam<HighbdDISTWTDCOMPAVGParam> {
516 public:
517 ~AV1HighBDDISTWTDCOMPAVGTest() override = default;
SetUp()518 void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); }
519
520 protected:
RunCheckOutput(distwtdcompavg_func test_impl)521 void RunCheckOutput(distwtdcompavg_func test_impl) {
522 const int w = kMaxSize, h = kMaxSize;
523 const int block_idx = GET_PARAM(2);
524 const int bd = GET_PARAM(0);
525 uint16_t pred8[kMaxSize * kMaxSize];
526 uint16_t ref8[kMaxSize * kMaxSize];
527 uint16_t output[kMaxSize * kMaxSize];
528 uint16_t output2[kMaxSize * kMaxSize];
529
530 for (int i = 0; i < h; ++i)
531 for (int j = 0; j < w; ++j) {
532 pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
533 ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
534 }
535 const int in_w = block_size_wide[block_idx];
536 const int in_h = block_size_high[block_idx];
537
538 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
539 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
540
541 for (int ii = 0; ii < 2; ii++) {
542 for (int jj = 0; jj < 4; jj++) {
543 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
544 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[jj][1 - ii];
545
546 const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
547 const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
548 aom_highbd_dist_wtd_comp_avg_pred_c(
549 CONVERT_TO_BYTEPTR(output),
550 CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w, in_h,
551 CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c, in_w,
552 &dist_wtd_comp_params);
553 test_impl(CONVERT_TO_BYTEPTR(output2),
554 CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w,
555 in_h, CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c,
556 in_w, &dist_wtd_comp_params);
557
558 for (int i = 0; i < in_h; ++i) {
559 for (int j = 0; j < in_w; ++j) {
560 int idx = i * in_w + j;
561 ASSERT_EQ(output[idx], output2[idx])
562 << "Mismatch at unit tests for AV1HighBDDISTWTDCOMPAVGTest\n"
563 << in_w << "x" << in_h << " Pixel mismatch at index " << idx
564 << " = (" << i << ", " << j << ")";
565 }
566 }
567 }
568 }
569 }
RunSpeedTest(distwtdcompavg_func test_impl)570 void RunSpeedTest(distwtdcompavg_func test_impl) {
571 const int w = kMaxSize, h = kMaxSize;
572 const int block_idx = GET_PARAM(2);
573 const int bd = GET_PARAM(0);
574 uint16_t pred8[kMaxSize * kMaxSize];
575 uint16_t ref8[kMaxSize * kMaxSize];
576 uint16_t output[kMaxSize * kMaxSize];
577 uint16_t output2[kMaxSize * kMaxSize];
578
579 for (int i = 0; i < h; ++i)
580 for (int j = 0; j < w; ++j) {
581 pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
582 ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
583 }
584 const int in_w = block_size_wide[block_idx];
585 const int in_h = block_size_high[block_idx];
586
587 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
588 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
589
590 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
591 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
592
593 const int num_loops = 1000000000 / (in_w + in_h);
594 aom_usec_timer timer;
595 aom_usec_timer_start(&timer);
596
597 for (int i = 0; i < num_loops; ++i)
598 aom_highbd_dist_wtd_comp_avg_pred_c(
599 CONVERT_TO_BYTEPTR(output), CONVERT_TO_BYTEPTR(pred8), in_w, in_h,
600 CONVERT_TO_BYTEPTR(ref8), in_w, &dist_wtd_comp_params);
601
602 aom_usec_timer_mark(&timer);
603 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
604 printf("highbddistwtdcompavg c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
605 1000.0 * elapsed_time / num_loops);
606
607 aom_usec_timer timer1;
608 aom_usec_timer_start(&timer1);
609
610 for (int i = 0; i < num_loops; ++i)
611 test_impl(CONVERT_TO_BYTEPTR(output2), CONVERT_TO_BYTEPTR(pred8), in_w,
612 in_h, CONVERT_TO_BYTEPTR(ref8), in_w, &dist_wtd_comp_params);
613
614 aom_usec_timer_mark(&timer1);
615 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
616 printf("highbddistwtdcompavg test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
617 1000.0 * elapsed_time1 / num_loops);
618 }
619
620 libaom_test::ACMRandom rnd_;
621 }; // class AV1HighBDDISTWTDCOMPAVGTest
622
623 class AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest
624 : public ::testing::TestWithParam<HighbdDISTWTDCOMPAVGUPSAMPLEDParam> {
625 public:
626 ~AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest() override = default;
SetUp()627 void SetUp() override { rnd_.Reset(ACMRandom::DeterministicSeed()); }
628
629 protected:
RunCheckOutput(highbddistwtdcompavgupsampled_func test_impl)630 void RunCheckOutput(highbddistwtdcompavgupsampled_func test_impl) {
631 const int w = kMaxSize, h = kMaxSize;
632 const int block_idx = GET_PARAM(2);
633 const int bd = GET_PARAM(0);
634 uint16_t pred8[kMaxSize * kMaxSize];
635 uint16_t ref8[kMaxSize * kMaxSize];
636 DECLARE_ALIGNED(16, uint16_t, output[kMaxSize * kMaxSize]);
637 DECLARE_ALIGNED(16, uint16_t, output2[kMaxSize * kMaxSize]);
638
639 for (int i = 0; i < h; ++i)
640 for (int j = 0; j < w; ++j) {
641 pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
642 ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
643 }
644 const int in_w = block_size_wide[block_idx];
645 const int in_h = block_size_high[block_idx];
646
647 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
648 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
649 int sub_x_q3, sub_y_q3;
650 int subpel_search;
651 for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
652 ++subpel_search) {
653 for (sub_x_q3 = 0; sub_x_q3 < 8; ++sub_x_q3) {
654 for (sub_y_q3 = 0; sub_y_q3 < 8; ++sub_y_q3) {
655 for (int ii = 0; ii < 2; ii++) {
656 for (int jj = 0; jj < 4; jj++) {
657 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
658 dist_wtd_comp_params.bck_offset =
659 quant_dist_lookup_table[jj][1 - ii];
660
661 const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
662 const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
663
664 aom_highbd_dist_wtd_comp_avg_upsampled_pred_c(
665 nullptr, nullptr, 0, 0, nullptr, CONVERT_TO_BYTEPTR(output),
666 CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w,
667 in_h, sub_x_q3, sub_y_q3,
668 CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c, in_w, bd,
669 &dist_wtd_comp_params, subpel_search);
670 test_impl(nullptr, nullptr, 0, 0, nullptr,
671 CONVERT_TO_BYTEPTR(output2),
672 CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c,
673 in_w, in_h, sub_x_q3, sub_y_q3,
674 CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c,
675 in_w, bd, &dist_wtd_comp_params, subpel_search);
676
677 for (int i = 0; i < in_h; ++i) {
678 for (int j = 0; j < in_w; ++j) {
679 int idx = i * in_w + j;
680 ASSERT_EQ(output[idx], output2[idx])
681 << "Mismatch at unit tests for "
682 "AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest\n"
683 << in_w << "x" << in_h << " Pixel mismatch at index "
684 << idx << " = (" << i << ", " << j
685 << "), sub pixel offset = (" << sub_y_q3 << ", "
686 << sub_x_q3 << ")";
687 }
688 }
689 }
690 }
691 }
692 }
693 }
694 }
RunSpeedTest(highbddistwtdcompavgupsampled_func test_impl)695 void RunSpeedTest(highbddistwtdcompavgupsampled_func test_impl) {
696 const int w = kMaxSize, h = kMaxSize;
697 const int block_idx = GET_PARAM(2);
698 const int bd = GET_PARAM(0);
699 uint16_t pred8[kMaxSize * kMaxSize];
700 uint16_t ref8[kMaxSize * kMaxSize];
701 DECLARE_ALIGNED(16, uint16_t, output[kMaxSize * kMaxSize]);
702 DECLARE_ALIGNED(16, uint16_t, output2[kMaxSize * kMaxSize]);
703
704 for (int i = 0; i < h; ++i)
705 for (int j = 0; j < w; ++j) {
706 pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
707 ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
708 }
709 const int in_w = block_size_wide[block_idx];
710 const int in_h = block_size_high[block_idx];
711
712 DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
713 dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
714
715 dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
716 dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
717 int sub_x_q3 = 0;
718 int sub_y_q3 = 0;
719 const int num_loops = 1000000000 / (in_w + in_h);
720 aom_usec_timer timer;
721 aom_usec_timer_start(&timer);
722 int subpel_search = USE_8_TAPS; // set to USE_4_TAPS to test 4-tap filter.
723 for (int i = 0; i < num_loops; ++i)
724 aom_highbd_dist_wtd_comp_avg_upsampled_pred_c(
725 nullptr, nullptr, 0, 0, nullptr, CONVERT_TO_BYTEPTR(output),
726 CONVERT_TO_BYTEPTR(pred8), in_w, in_h, sub_x_q3, sub_y_q3,
727 CONVERT_TO_BYTEPTR(ref8), in_w, bd, &dist_wtd_comp_params,
728 subpel_search);
729
730 aom_usec_timer_mark(&timer);
731 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
732 printf("highbddistwtdcompavgupsampled c_code %3dx%-3d: %7.2f us\n", in_w,
733 in_h, 1000.0 * elapsed_time / num_loops);
734
735 aom_usec_timer timer1;
736 aom_usec_timer_start(&timer1);
737
738 for (int i = 0; i < num_loops; ++i)
739 test_impl(nullptr, nullptr, 0, 0, nullptr, CONVERT_TO_BYTEPTR(output2),
740 CONVERT_TO_BYTEPTR(pred8), in_w, in_h, sub_x_q3, sub_y_q3,
741 CONVERT_TO_BYTEPTR(ref8), in_w, bd, &dist_wtd_comp_params,
742 subpel_search);
743
744 aom_usec_timer_mark(&timer1);
745 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
746 printf("highbddistwtdcompavgupsampled test_code %3dx%-3d: %7.2f us\n", in_w,
747 in_h, 1000.0 * elapsed_time1 / num_loops);
748 }
749
750 libaom_test::ACMRandom rnd_;
751 }; // class AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest
752 #endif // CONFIG_AV1_HIGHBITDEPTH
753
754 } // namespace AV1DISTWTDCOMPAVG
755 } // namespace libaom_test
756
757 #endif // AOM_TEST_COMP_AVG_PRED_TEST_H_
758