• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 std::tuple<distwtdcompavg_func, BLOCK_SIZE> DISTWTDCOMPAVGParam;
44 
45 typedef std::tuple<distwtdcompavgupsampled_func, BLOCK_SIZE>
46     DISTWTDCOMPAVGUPSAMPLEDParam;
47 
48 #if CONFIG_AV1_HIGHBITDEPTH
49 typedef void (*highbddistwtdcompavgupsampled_func)(
50     MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
51     const MV *const mv, uint8_t *comp_pred8, const uint8_t *pred8, int width,
52     int height, int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8,
53     int ref_stride, int bd, const DIST_WTD_COMP_PARAMS *jcp_param,
54     int subpel_search);
55 
56 typedef std::tuple<int, highbddistwtdcompavgupsampled_func, BLOCK_SIZE>
57     HighbdDISTWTDCOMPAVGUPSAMPLEDParam;
58 
59 typedef std::tuple<int, distwtdcompavg_func, BLOCK_SIZE>
60     HighbdDISTWTDCOMPAVGParam;
61 
BuildParams(distwtdcompavg_func filter,int is_hbd)62 ::testing::internal::ParamGenerator<HighbdDISTWTDCOMPAVGParam> BuildParams(
63     distwtdcompavg_func filter, int is_hbd) {
64   (void)is_hbd;
65   return ::testing::Combine(::testing::Range(8, 13, 2),
66                             ::testing::Values(filter),
67                             ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
68 }
69 
70 ::testing::internal::ParamGenerator<HighbdDISTWTDCOMPAVGUPSAMPLEDParam>
BuildParams(highbddistwtdcompavgupsampled_func filter)71 BuildParams(highbddistwtdcompavgupsampled_func filter) {
72   return ::testing::Combine(::testing::Range(8, 13, 2),
73                             ::testing::Values(filter),
74                             ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
75 }
76 #endif  // CONFIG_AV1_HIGHBITDEPTH
77 
BuildParams(distwtdcompavg_func filter)78 ::testing::internal::ParamGenerator<DISTWTDCOMPAVGParam> BuildParams(
79     distwtdcompavg_func filter) {
80   return ::testing::Combine(::testing::Values(filter),
81                             ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
82 }
83 
BuildParams(distwtdcompavgupsampled_func filter)84 ::testing::internal::ParamGenerator<DISTWTDCOMPAVGUPSAMPLEDParam> BuildParams(
85     distwtdcompavgupsampled_func filter) {
86   return ::testing::Combine(::testing::Values(filter),
87                             ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
88 }
89 
90 class AV1DISTWTDCOMPAVGTest
91     : public ::testing::TestWithParam<DISTWTDCOMPAVGParam> {
92  public:
~AV1DISTWTDCOMPAVGTest()93   ~AV1DISTWTDCOMPAVGTest() {}
SetUp()94   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
95 
96  protected:
RunCheckOutput(distwtdcompavg_func test_impl)97   void RunCheckOutput(distwtdcompavg_func test_impl) {
98     const int w = kMaxSize, h = kMaxSize;
99     const int block_idx = GET_PARAM(1);
100 
101     uint8_t pred8[kMaxSize * kMaxSize];
102     uint8_t ref8[kMaxSize * kMaxSize];
103     uint8_t output[kMaxSize * kMaxSize];
104     uint8_t output2[kMaxSize * kMaxSize];
105 
106     for (int i = 0; i < h; ++i)
107       for (int j = 0; j < w; ++j) {
108         pred8[i * w + j] = rnd_.Rand8();
109         ref8[i * w + j] = rnd_.Rand8();
110       }
111     const int in_w = block_size_wide[block_idx];
112     const int in_h = block_size_high[block_idx];
113 
114     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
115     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
116 
117     for (int ii = 0; ii < 2; ii++) {
118       for (int jj = 0; jj < 4; jj++) {
119         dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
120         dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[jj][1 - ii];
121 
122         const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
123         const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
124         aom_dist_wtd_comp_avg_pred_c(output, pred8 + offset_r * w + offset_c,
125                                      in_w, in_h, ref8 + offset_r * w + offset_c,
126                                      in_w, &dist_wtd_comp_params);
127         test_impl(output2, pred8 + offset_r * w + offset_c, in_w, in_h,
128                   ref8 + offset_r * w + offset_c, in_w, &dist_wtd_comp_params);
129 
130         for (int i = 0; i < in_h; ++i) {
131           for (int j = 0; j < in_w; ++j) {
132             int idx = i * in_w + j;
133             ASSERT_EQ(output[idx], output2[idx])
134                 << "Mismatch at unit tests for AV1DISTWTDCOMPAVGTest\n"
135                 << in_w << "x" << in_h << " Pixel mismatch at index " << idx
136                 << " = (" << i << ", " << j << ")";
137           }
138         }
139       }
140     }
141   }
RunSpeedTest(distwtdcompavg_func test_impl)142   void RunSpeedTest(distwtdcompavg_func test_impl) {
143     const int w = kMaxSize, h = kMaxSize;
144     const int block_idx = GET_PARAM(1);
145 
146     uint8_t pred8[kMaxSize * kMaxSize];
147     uint8_t ref8[kMaxSize * kMaxSize];
148     uint8_t output[kMaxSize * kMaxSize];
149     uint8_t output2[kMaxSize * kMaxSize];
150 
151     for (int i = 0; i < h; ++i)
152       for (int j = 0; j < w; ++j) {
153         pred8[i * w + j] = rnd_.Rand8();
154         ref8[i * w + j] = rnd_.Rand8();
155       }
156     const int in_w = block_size_wide[block_idx];
157     const int in_h = block_size_high[block_idx];
158 
159     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
160     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
161 
162     dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
163     dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
164 
165     const int num_loops = 1000000000 / (in_w + in_h);
166     aom_usec_timer timer;
167     aom_usec_timer_start(&timer);
168 
169     for (int i = 0; i < num_loops; ++i)
170       aom_dist_wtd_comp_avg_pred_c(output, pred8, in_w, in_h, ref8, in_w,
171                                    &dist_wtd_comp_params);
172 
173     aom_usec_timer_mark(&timer);
174     const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
175     printf("distwtdcompavg c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
176            1000.0 * elapsed_time / num_loops);
177 
178     aom_usec_timer timer1;
179     aom_usec_timer_start(&timer1);
180 
181     for (int i = 0; i < num_loops; ++i)
182       test_impl(output2, pred8, in_w, in_h, ref8, in_w, &dist_wtd_comp_params);
183 
184     aom_usec_timer_mark(&timer1);
185     const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
186     printf("distwtdcompavg test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
187            1000.0 * elapsed_time1 / num_loops);
188   }
189 
190   libaom_test::ACMRandom rnd_;
191 };  // class AV1DISTWTDCOMPAVGTest
192 
193 class AV1DISTWTDCOMPAVGUPSAMPLEDTest
194     : public ::testing::TestWithParam<DISTWTDCOMPAVGUPSAMPLEDParam> {
195  public:
~AV1DISTWTDCOMPAVGUPSAMPLEDTest()196   ~AV1DISTWTDCOMPAVGUPSAMPLEDTest() {}
SetUp()197   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
198 
199  protected:
RunCheckOutput(distwtdcompavgupsampled_func test_impl)200   void RunCheckOutput(distwtdcompavgupsampled_func test_impl) {
201     const int w = kMaxSize, h = kMaxSize;
202     const int block_idx = GET_PARAM(1);
203 
204     uint8_t pred8[kMaxSize * kMaxSize];
205     uint8_t ref8[kMaxSize * kMaxSize];
206     DECLARE_ALIGNED(16, uint8_t, output[MAX_SB_SQUARE]);
207     DECLARE_ALIGNED(16, uint8_t, output2[MAX_SB_SQUARE]);
208 
209     for (int i = 0; i < h; ++i)
210       for (int j = 0; j < w; ++j) {
211         pred8[i * w + j] = rnd_.Rand8();
212         ref8[i * w + j] = rnd_.Rand8();
213       }
214     const int in_w = block_size_wide[block_idx];
215     const int in_h = block_size_high[block_idx];
216 
217     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
218     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
219     int sub_x_q3, sub_y_q3;
220     int subpel_search;
221     for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
222          ++subpel_search) {
223       for (sub_x_q3 = 0; sub_x_q3 < 8; ++sub_x_q3) {
224         for (sub_y_q3 = 0; sub_y_q3 < 8; ++sub_y_q3) {
225           for (int ii = 0; ii < 2; ii++) {
226             for (int jj = 0; jj < 4; jj++) {
227               dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
228               dist_wtd_comp_params.bck_offset =
229                   quant_dist_lookup_table[jj][1 - ii];
230 
231               const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
232               const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
233 
234               aom_dist_wtd_comp_avg_upsampled_pred_c(
235                   NULL, NULL, 0, 0, NULL, output,
236                   pred8 + offset_r * w + offset_c, in_w, in_h, sub_x_q3,
237                   sub_y_q3, ref8 + offset_r * w + offset_c, in_w,
238                   &dist_wtd_comp_params, subpel_search);
239               test_impl(NULL, NULL, 0, 0, NULL, output2,
240                         pred8 + offset_r * w + offset_c, in_w, in_h, sub_x_q3,
241                         sub_y_q3, ref8 + offset_r * w + offset_c, in_w,
242                         &dist_wtd_comp_params, subpel_search);
243 
244               for (int i = 0; i < in_h; ++i) {
245                 for (int j = 0; j < in_w; ++j) {
246                   int idx = i * in_w + j;
247                   ASSERT_EQ(output[idx], output2[idx])
248                       << "Mismatch at unit tests for "
249                          "AV1DISTWTDCOMPAVGUPSAMPLEDTest\n"
250                       << in_w << "x" << in_h << " Pixel mismatch at index "
251                       << idx << " = (" << i << ", " << j
252                       << "), sub pixel offset = (" << sub_y_q3 << ", "
253                       << sub_x_q3 << ")";
254                 }
255               }
256             }
257           }
258         }
259       }
260     }
261   }
RunSpeedTest(distwtdcompavgupsampled_func test_impl)262   void RunSpeedTest(distwtdcompavgupsampled_func test_impl) {
263     const int w = kMaxSize, h = kMaxSize;
264     const int block_idx = GET_PARAM(1);
265 
266     uint8_t pred8[kMaxSize * kMaxSize];
267     uint8_t ref8[kMaxSize * kMaxSize];
268     DECLARE_ALIGNED(16, uint8_t, output[MAX_SB_SQUARE]);
269     DECLARE_ALIGNED(16, uint8_t, output2[MAX_SB_SQUARE]);
270 
271     for (int i = 0; i < h; ++i)
272       for (int j = 0; j < w; ++j) {
273         pred8[i * w + j] = rnd_.Rand8();
274         ref8[i * w + j] = rnd_.Rand8();
275       }
276     const int in_w = block_size_wide[block_idx];
277     const int in_h = block_size_high[block_idx];
278 
279     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
280     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
281 
282     dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
283     dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
284 
285     int sub_x_q3 = 0;
286     int sub_y_q3 = 0;
287 
288     const int num_loops = 1000000000 / (in_w + in_h);
289     aom_usec_timer timer;
290     aom_usec_timer_start(&timer);
291     int subpel_search = USE_8_TAPS;  // set to USE_4_TAPS to test 4-tap filter.
292 
293     for (int i = 0; i < num_loops; ++i)
294       aom_dist_wtd_comp_avg_upsampled_pred_c(
295           NULL, NULL, 0, 0, NULL, output, pred8, in_w, in_h, sub_x_q3, sub_y_q3,
296           ref8, in_w, &dist_wtd_comp_params, subpel_search);
297 
298     aom_usec_timer_mark(&timer);
299     const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
300     printf("distwtdcompavgupsampled c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
301            1000.0 * elapsed_time / num_loops);
302 
303     aom_usec_timer timer1;
304     aom_usec_timer_start(&timer1);
305 
306     for (int i = 0; i < num_loops; ++i)
307       test_impl(NULL, NULL, 0, 0, NULL, output2, pred8, in_w, in_h, sub_x_q3,
308                 sub_y_q3, ref8, in_w, &dist_wtd_comp_params, subpel_search);
309 
310     aom_usec_timer_mark(&timer1);
311     const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
312     printf("distwtdcompavgupsampled test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
313            1000.0 * elapsed_time1 / num_loops);
314   }
315 
316   libaom_test::ACMRandom rnd_;
317 };  // class AV1DISTWTDCOMPAVGUPSAMPLEDTest
318 
319 #if CONFIG_AV1_HIGHBITDEPTH
320 class AV1HighBDDISTWTDCOMPAVGTest
321     : public ::testing::TestWithParam<HighbdDISTWTDCOMPAVGParam> {
322  public:
~AV1HighBDDISTWTDCOMPAVGTest()323   ~AV1HighBDDISTWTDCOMPAVGTest() {}
SetUp()324   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
325 
326  protected:
RunCheckOutput(distwtdcompavg_func test_impl)327   void RunCheckOutput(distwtdcompavg_func test_impl) {
328     const int w = kMaxSize, h = kMaxSize;
329     const int block_idx = GET_PARAM(2);
330     const int bd = GET_PARAM(0);
331     uint16_t pred8[kMaxSize * kMaxSize];
332     uint16_t ref8[kMaxSize * kMaxSize];
333     uint16_t output[kMaxSize * kMaxSize];
334     uint16_t output2[kMaxSize * kMaxSize];
335 
336     for (int i = 0; i < h; ++i)
337       for (int j = 0; j < w; ++j) {
338         pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
339         ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
340       }
341     const int in_w = block_size_wide[block_idx];
342     const int in_h = block_size_high[block_idx];
343 
344     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
345     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
346 
347     for (int ii = 0; ii < 2; ii++) {
348       for (int jj = 0; jj < 4; jj++) {
349         dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
350         dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[jj][1 - ii];
351 
352         const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
353         const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
354         aom_highbd_dist_wtd_comp_avg_pred_c(
355             CONVERT_TO_BYTEPTR(output),
356             CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w, in_h,
357             CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c, in_w,
358             &dist_wtd_comp_params);
359         test_impl(CONVERT_TO_BYTEPTR(output2),
360                   CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w,
361                   in_h, CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c,
362                   in_w, &dist_wtd_comp_params);
363 
364         for (int i = 0; i < in_h; ++i) {
365           for (int j = 0; j < in_w; ++j) {
366             int idx = i * in_w + j;
367             ASSERT_EQ(output[idx], output2[idx])
368                 << "Mismatch at unit tests for AV1HighBDDISTWTDCOMPAVGTest\n"
369                 << in_w << "x" << in_h << " Pixel mismatch at index " << idx
370                 << " = (" << i << ", " << j << ")";
371           }
372         }
373       }
374     }
375   }
RunSpeedTest(distwtdcompavg_func test_impl)376   void RunSpeedTest(distwtdcompavg_func test_impl) {
377     const int w = kMaxSize, h = kMaxSize;
378     const int block_idx = GET_PARAM(2);
379     const int bd = GET_PARAM(0);
380     uint16_t pred8[kMaxSize * kMaxSize];
381     uint16_t ref8[kMaxSize * kMaxSize];
382     uint16_t output[kMaxSize * kMaxSize];
383     uint16_t output2[kMaxSize * kMaxSize];
384 
385     for (int i = 0; i < h; ++i)
386       for (int j = 0; j < w; ++j) {
387         pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
388         ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
389       }
390     const int in_w = block_size_wide[block_idx];
391     const int in_h = block_size_high[block_idx];
392 
393     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
394     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
395 
396     dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
397     dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
398 
399     const int num_loops = 1000000000 / (in_w + in_h);
400     aom_usec_timer timer;
401     aom_usec_timer_start(&timer);
402 
403     for (int i = 0; i < num_loops; ++i)
404       aom_highbd_dist_wtd_comp_avg_pred_c(
405           CONVERT_TO_BYTEPTR(output), CONVERT_TO_BYTEPTR(pred8), in_w, in_h,
406           CONVERT_TO_BYTEPTR(ref8), in_w, &dist_wtd_comp_params);
407 
408     aom_usec_timer_mark(&timer);
409     const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
410     printf("highbddistwtdcompavg c_code %3dx%-3d: %7.2f us\n", in_w, in_h,
411            1000.0 * elapsed_time / num_loops);
412 
413     aom_usec_timer timer1;
414     aom_usec_timer_start(&timer1);
415 
416     for (int i = 0; i < num_loops; ++i)
417       test_impl(CONVERT_TO_BYTEPTR(output2), CONVERT_TO_BYTEPTR(pred8), in_w,
418                 in_h, CONVERT_TO_BYTEPTR(ref8), in_w, &dist_wtd_comp_params);
419 
420     aom_usec_timer_mark(&timer1);
421     const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
422     printf("highbddistwtdcompavg test_code %3dx%-3d: %7.2f us\n", in_w, in_h,
423            1000.0 * elapsed_time1 / num_loops);
424   }
425 
426   libaom_test::ACMRandom rnd_;
427 };  // class AV1HighBDDISTWTDCOMPAVGTest
428 
429 class AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest
430     : public ::testing::TestWithParam<HighbdDISTWTDCOMPAVGUPSAMPLEDParam> {
431  public:
~AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest()432   ~AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest() {}
SetUp()433   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
434 
435  protected:
RunCheckOutput(highbddistwtdcompavgupsampled_func test_impl)436   void RunCheckOutput(highbddistwtdcompavgupsampled_func test_impl) {
437     const int w = kMaxSize, h = kMaxSize;
438     const int block_idx = GET_PARAM(2);
439     const int bd = GET_PARAM(0);
440     uint16_t pred8[kMaxSize * kMaxSize];
441     uint16_t ref8[kMaxSize * kMaxSize];
442     DECLARE_ALIGNED(16, uint16_t, output[kMaxSize * kMaxSize]);
443     DECLARE_ALIGNED(16, uint16_t, output2[kMaxSize * kMaxSize]);
444 
445     for (int i = 0; i < h; ++i)
446       for (int j = 0; j < w; ++j) {
447         pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
448         ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
449       }
450     const int in_w = block_size_wide[block_idx];
451     const int in_h = block_size_high[block_idx];
452 
453     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
454     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
455     int sub_x_q3, sub_y_q3;
456     int subpel_search;
457     for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
458          ++subpel_search) {
459       for (sub_x_q3 = 0; sub_x_q3 < 8; ++sub_x_q3) {
460         for (sub_y_q3 = 0; sub_y_q3 < 8; ++sub_y_q3) {
461           for (int ii = 0; ii < 2; ii++) {
462             for (int jj = 0; jj < 4; jj++) {
463               dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[jj][ii];
464               dist_wtd_comp_params.bck_offset =
465                   quant_dist_lookup_table[jj][1 - ii];
466 
467               const int offset_r = 3 + rnd_.PseudoUniform(h - in_h - 7);
468               const int offset_c = 3 + rnd_.PseudoUniform(w - in_w - 7);
469 
470               aom_highbd_dist_wtd_comp_avg_upsampled_pred_c(
471                   NULL, NULL, 0, 0, NULL, CONVERT_TO_BYTEPTR(output),
472                   CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c, in_w,
473                   in_h, sub_x_q3, sub_y_q3,
474                   CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c, in_w, bd,
475                   &dist_wtd_comp_params, subpel_search);
476               test_impl(NULL, NULL, 0, 0, NULL, CONVERT_TO_BYTEPTR(output2),
477                         CONVERT_TO_BYTEPTR(pred8) + offset_r * w + offset_c,
478                         in_w, in_h, sub_x_q3, sub_y_q3,
479                         CONVERT_TO_BYTEPTR(ref8) + offset_r * w + offset_c,
480                         in_w, bd, &dist_wtd_comp_params, subpel_search);
481 
482               for (int i = 0; i < in_h; ++i) {
483                 for (int j = 0; j < in_w; ++j) {
484                   int idx = i * in_w + j;
485                   ASSERT_EQ(output[idx], output2[idx])
486                       << "Mismatch at unit tests for "
487                          "AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest\n"
488                       << in_w << "x" << in_h << " Pixel mismatch at index "
489                       << idx << " = (" << i << ", " << j
490                       << "), sub pixel offset = (" << sub_y_q3 << ", "
491                       << sub_x_q3 << ")";
492                 }
493               }
494             }
495           }
496         }
497       }
498     }
499   }
RunSpeedTest(highbddistwtdcompavgupsampled_func test_impl)500   void RunSpeedTest(highbddistwtdcompavgupsampled_func test_impl) {
501     const int w = kMaxSize, h = kMaxSize;
502     const int block_idx = GET_PARAM(2);
503     const int bd = GET_PARAM(0);
504     uint16_t pred8[kMaxSize * kMaxSize];
505     uint16_t ref8[kMaxSize * kMaxSize];
506     DECLARE_ALIGNED(16, uint16_t, output[kMaxSize * kMaxSize]);
507     DECLARE_ALIGNED(16, uint16_t, output2[kMaxSize * kMaxSize]);
508 
509     for (int i = 0; i < h; ++i)
510       for (int j = 0; j < w; ++j) {
511         pred8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
512         ref8[i * w + j] = rnd_.Rand16() & ((1 << bd) - 1);
513       }
514     const int in_w = block_size_wide[block_idx];
515     const int in_h = block_size_high[block_idx];
516 
517     DIST_WTD_COMP_PARAMS dist_wtd_comp_params;
518     dist_wtd_comp_params.use_dist_wtd_comp_avg = 1;
519 
520     dist_wtd_comp_params.fwd_offset = quant_dist_lookup_table[0][0];
521     dist_wtd_comp_params.bck_offset = quant_dist_lookup_table[0][1];
522     int sub_x_q3 = 0;
523     int sub_y_q3 = 0;
524     const int num_loops = 1000000000 / (in_w + in_h);
525     aom_usec_timer timer;
526     aom_usec_timer_start(&timer);
527     int subpel_search = USE_8_TAPS;  // set to USE_4_TAPS to test 4-tap filter.
528     for (int i = 0; i < num_loops; ++i)
529       aom_highbd_dist_wtd_comp_avg_upsampled_pred_c(
530           NULL, NULL, 0, 0, NULL, CONVERT_TO_BYTEPTR(output),
531           CONVERT_TO_BYTEPTR(pred8), in_w, in_h, sub_x_q3, sub_y_q3,
532           CONVERT_TO_BYTEPTR(ref8), in_w, bd, &dist_wtd_comp_params,
533           subpel_search);
534 
535     aom_usec_timer_mark(&timer);
536     const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
537     printf("highbddistwtdcompavgupsampled c_code %3dx%-3d: %7.2f us\n", in_w,
538            in_h, 1000.0 * elapsed_time / num_loops);
539 
540     aom_usec_timer timer1;
541     aom_usec_timer_start(&timer1);
542 
543     for (int i = 0; i < num_loops; ++i)
544       test_impl(NULL, NULL, 0, 0, NULL, CONVERT_TO_BYTEPTR(output2),
545                 CONVERT_TO_BYTEPTR(pred8), in_w, in_h, sub_x_q3, sub_y_q3,
546                 CONVERT_TO_BYTEPTR(ref8), in_w, bd, &dist_wtd_comp_params,
547                 subpel_search);
548 
549     aom_usec_timer_mark(&timer1);
550     const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
551     printf("highbddistwtdcompavgupsampled test_code %3dx%-3d: %7.2f us\n", in_w,
552            in_h, 1000.0 * elapsed_time1 / num_loops);
553   }
554 
555   libaom_test::ACMRandom rnd_;
556 };      // class AV1HighBDDISTWTDCOMPAVGUPSAMPLEDTest
557 #endif  // CONFIG_AV1_HIGHBITDEPTH
558 
559 }  // namespace AV1DISTWTDCOMPAVG
560 }  // namespace libaom_test
561 
562 #endif  // AOM_TEST_COMP_AVG_PRED_TEST_H_
563