xref: /aosp_15_r20/external/libaom/test/comp_mask_pred_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <cstdlib>
13*77c1e3ccSAndroid Build Coastguard Worker #include <new>
14*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_dsp_rtcd.h"
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_codec.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_integer.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/variance.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "aom_mem/aom_mem.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/aom_timer.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/mem.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/reconinter.h"
26*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/reconinter_enc.h"
27*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
28*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
29*77c1e3ccSAndroid Build Coastguard Worker #include "test/register_state_check.h"
30*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker namespace {
33*77c1e3ccSAndroid Build Coastguard Worker typedef void (*comp_mask_pred_func)(uint8_t *comp_pred, const uint8_t *pred,
34*77c1e3ccSAndroid Build Coastguard Worker                                     int width, int height, const uint8_t *ref,
35*77c1e3ccSAndroid Build Coastguard Worker                                     int ref_stride, const uint8_t *mask,
36*77c1e3ccSAndroid Build Coastguard Worker                                     int mask_stride, int invert_mask);
37*77c1e3ccSAndroid Build Coastguard Worker 
38*77c1e3ccSAndroid Build Coastguard Worker typedef void (*comp_avg_pred_func)(uint8_t *comp_pred, const uint8_t *pred,
39*77c1e3ccSAndroid Build Coastguard Worker                                    int width, int height, const uint8_t *ref,
40*77c1e3ccSAndroid Build Coastguard Worker                                    int ref_stride);
41*77c1e3ccSAndroid Build Coastguard Worker 
42*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSSE3 || HAVE_SSE2 || HAVE_AVX2 || HAVE_NEON
43*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE kCompMaskPredParams[] = {
44*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_8X8,   BLOCK_8X16, BLOCK_8X32,  BLOCK_16X8, BLOCK_16X16,
45*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_16X32, BLOCK_32X8, BLOCK_32X16, BLOCK_32X32
46*77c1e3ccSAndroid Build Coastguard Worker };
47*77c1e3ccSAndroid Build Coastguard Worker #endif
48*77c1e3ccSAndroid Build Coastguard Worker 
49*77c1e3ccSAndroid Build Coastguard Worker class AV1CompMaskPredBase : public ::testing::Test {
50*77c1e3ccSAndroid Build Coastguard Worker  public:
51*77c1e3ccSAndroid Build Coastguard Worker   ~AV1CompMaskPredBase() override;
52*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override;
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override;
55*77c1e3ccSAndroid Build Coastguard Worker 
56*77c1e3ccSAndroid Build Coastguard Worker  protected:
CheckResult(int width,int height)57*77c1e3ccSAndroid Build Coastguard Worker   bool CheckResult(int width, int height) {
58*77c1e3ccSAndroid Build Coastguard Worker     for (int y = 0; y < height; ++y) {
59*77c1e3ccSAndroid Build Coastguard Worker       for (int x = 0; x < width; ++x) {
60*77c1e3ccSAndroid Build Coastguard Worker         const int idx = y * width + x;
61*77c1e3ccSAndroid Build Coastguard Worker         if (comp_pred1_[idx] != comp_pred2_[idx]) {
62*77c1e3ccSAndroid Build Coastguard Worker           printf("%dx%d mismatch @%d(%d,%d) ", width, height, idx, y, x);
63*77c1e3ccSAndroid Build Coastguard Worker           printf("%d != %d ", comp_pred1_[idx], comp_pred2_[idx]);
64*77c1e3ccSAndroid Build Coastguard Worker           return false;
65*77c1e3ccSAndroid Build Coastguard Worker         }
66*77c1e3ccSAndroid Build Coastguard Worker       }
67*77c1e3ccSAndroid Build Coastguard Worker     }
68*77c1e3ccSAndroid Build Coastguard Worker     return true;
69*77c1e3ccSAndroid Build Coastguard Worker   }
70*77c1e3ccSAndroid Build Coastguard Worker 
71*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rnd_;
72*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *comp_pred1_;
73*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *comp_pred2_;
74*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *pred_;
75*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *ref_buffer_;
76*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *ref_;
77*77c1e3ccSAndroid Build Coastguard Worker };
78*77c1e3ccSAndroid Build Coastguard Worker 
79*77c1e3ccSAndroid Build Coastguard Worker AV1CompMaskPredBase::~AV1CompMaskPredBase() = default;
80*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()81*77c1e3ccSAndroid Build Coastguard Worker void AV1CompMaskPredBase::SetUp() {
82*77c1e3ccSAndroid Build Coastguard Worker   rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed());
83*77c1e3ccSAndroid Build Coastguard Worker   av1_init_wedge_masks();
84*77c1e3ccSAndroid Build Coastguard Worker   comp_pred1_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
85*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred1_, nullptr);
86*77c1e3ccSAndroid Build Coastguard Worker   comp_pred2_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
87*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred2_, nullptr);
88*77c1e3ccSAndroid Build Coastguard Worker   pred_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
89*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pred_, nullptr);
90*77c1e3ccSAndroid Build Coastguard Worker   // The biggest block size is MAX_SB_SQUARE(128*128), however for the
91*77c1e3ccSAndroid Build Coastguard Worker   // convolution we need to access 3 bytes before and 4 bytes after (for an
92*77c1e3ccSAndroid Build Coastguard Worker   // 8-tap filter), in both directions, so we need to allocate
93*77c1e3ccSAndroid Build Coastguard Worker   // (128 + 7) * (128 + 7) = MAX_SB_SQUARE + (14 * MAX_SB_SIZE) + 49
94*77c1e3ccSAndroid Build Coastguard Worker   ref_buffer_ =
95*77c1e3ccSAndroid Build Coastguard Worker       (uint8_t *)aom_memalign(16, MAX_SB_SQUARE + (14 * MAX_SB_SIZE) + 49);
96*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(ref_buffer_, nullptr);
97*77c1e3ccSAndroid Build Coastguard Worker   // Start of the actual block where the convolution will be computed
98*77c1e3ccSAndroid Build Coastguard Worker   ref_ = ref_buffer_ + (3 * MAX_SB_SIZE + 3);
99*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
100*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand8();
101*77c1e3ccSAndroid Build Coastguard Worker   }
102*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE + (14 * MAX_SB_SIZE) + 49; ++i) {
103*77c1e3ccSAndroid Build Coastguard Worker     ref_buffer_[i] = rnd_.Rand8();
104*77c1e3ccSAndroid Build Coastguard Worker   }
105*77c1e3ccSAndroid Build Coastguard Worker }
106*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()107*77c1e3ccSAndroid Build Coastguard Worker void AV1CompMaskPredBase::TearDown() {
108*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred1_);
109*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred2_);
110*77c1e3ccSAndroid Build Coastguard Worker   aom_free(pred_);
111*77c1e3ccSAndroid Build Coastguard Worker   aom_free(ref_buffer_);
112*77c1e3ccSAndroid Build Coastguard Worker }
113*77c1e3ccSAndroid Build Coastguard Worker 
114*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<comp_mask_pred_func, BLOCK_SIZE> CompMaskPredParam;
115*77c1e3ccSAndroid Build Coastguard Worker 
116*77c1e3ccSAndroid Build Coastguard Worker class AV1CompMaskPredTest
117*77c1e3ccSAndroid Build Coastguard Worker     : public AV1CompMaskPredBase,
118*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<CompMaskPredParam> {
119*77c1e3ccSAndroid Build Coastguard Worker  protected:
120*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(comp_mask_pred_func test_impl, BLOCK_SIZE bsize, int inv);
121*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(comp_mask_pred_func test_impl, BLOCK_SIZE bsize);
122*77c1e3ccSAndroid Build Coastguard Worker };
123*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(comp_mask_pred_func test_impl,BLOCK_SIZE bsize,int inv)124*77c1e3ccSAndroid Build Coastguard Worker void AV1CompMaskPredTest::RunCheckOutput(comp_mask_pred_func test_impl,
125*77c1e3ccSAndroid Build Coastguard Worker                                          BLOCK_SIZE bsize, int inv) {
126*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
127*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
128*77c1e3ccSAndroid Build Coastguard Worker   const int wedge_types = get_wedge_types_lookup(bsize);
129*77c1e3ccSAndroid Build Coastguard Worker   for (int wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
130*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *mask = av1_get_contiguous_soft_mask(wedge_index, 1, bsize);
131*77c1e3ccSAndroid Build Coastguard Worker 
132*77c1e3ccSAndroid Build Coastguard Worker     aom_comp_mask_pred_c(comp_pred1_, pred_, w, h, ref_, MAX_SB_SIZE, mask, w,
133*77c1e3ccSAndroid Build Coastguard Worker                          inv);
134*77c1e3ccSAndroid Build Coastguard Worker     test_impl(comp_pred2_, pred_, w, h, ref_, MAX_SB_SIZE, mask, w, inv);
135*77c1e3ccSAndroid Build Coastguard Worker 
136*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(CheckResult(w, h), true)
137*77c1e3ccSAndroid Build Coastguard Worker         << " wedge " << wedge_index << " inv " << inv;
138*77c1e3ccSAndroid Build Coastguard Worker   }
139*77c1e3ccSAndroid Build Coastguard Worker }
140*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(comp_mask_pred_func test_impl,BLOCK_SIZE bsize)141*77c1e3ccSAndroid Build Coastguard Worker void AV1CompMaskPredTest::RunSpeedTest(comp_mask_pred_func test_impl,
142*77c1e3ccSAndroid Build Coastguard Worker                                        BLOCK_SIZE bsize) {
143*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
144*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
145*77c1e3ccSAndroid Build Coastguard Worker   const int wedge_types = get_wedge_types_lookup(bsize);
146*77c1e3ccSAndroid Build Coastguard Worker   int wedge_index = wedge_types / 2;
147*77c1e3ccSAndroid Build Coastguard Worker   const uint8_t *mask = av1_get_contiguous_soft_mask(wedge_index, 1, bsize);
148*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
149*77c1e3ccSAndroid Build Coastguard Worker 
150*77c1e3ccSAndroid Build Coastguard Worker   comp_mask_pred_func funcs[2] = { aom_comp_mask_pred_c, test_impl };
151*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0 };
152*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
153*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
154*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
155*77c1e3ccSAndroid Build Coastguard Worker     comp_mask_pred_func func = funcs[i];
156*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
157*77c1e3ccSAndroid Build Coastguard Worker       func(comp_pred1_, pred_, w, h, ref_, MAX_SB_SIZE, mask, w, 0);
158*77c1e3ccSAndroid Build Coastguard Worker     }
159*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
160*77c1e3ccSAndroid Build Coastguard Worker     double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
161*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time / num_loops;
162*77c1e3ccSAndroid Build Coastguard Worker   }
163*77c1e3ccSAndroid Build Coastguard Worker   printf("compMask %3dx%-3d: %7.2f/%7.2fns", w, h, elapsed_time[0],
164*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[1]);
165*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
166*77c1e3ccSAndroid Build Coastguard Worker }
167*77c1e3ccSAndroid Build Coastguard Worker 
168*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1CompMaskPredTest);
169*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1CompMaskPredTest,CheckOutput)170*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1CompMaskPredTest, CheckOutput) {
171*77c1e3ccSAndroid Build Coastguard Worker   // inv = 0, 1
172*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1), 0);
173*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1), 1);
174*77c1e3ccSAndroid Build Coastguard Worker }
175*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1CompMaskPredTest,DISABLED_Speed)176*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1CompMaskPredTest, DISABLED_Speed) {
177*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1));
178*77c1e3ccSAndroid Build Coastguard Worker }
179*77c1e3ccSAndroid Build Coastguard Worker 
180*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSSE3
181*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
182*77c1e3ccSAndroid Build Coastguard Worker     SSSE3, AV1CompMaskPredTest,
183*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_comp_mask_pred_ssse3),
184*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams)));
185*77c1e3ccSAndroid Build Coastguard Worker #endif
186*77c1e3ccSAndroid Build Coastguard Worker 
187*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
188*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
189*77c1e3ccSAndroid Build Coastguard Worker     AVX2, AV1CompMaskPredTest,
190*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_comp_mask_pred_avx2),
191*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams)));
192*77c1e3ccSAndroid Build Coastguard Worker #endif
193*77c1e3ccSAndroid Build Coastguard Worker 
194*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
195*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
196*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1CompMaskPredTest,
197*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_comp_mask_pred_neon),
198*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams)));
199*77c1e3ccSAndroid Build Coastguard Worker #endif
200*77c1e3ccSAndroid Build Coastguard Worker 
201*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSSE3 || HAVE_SSE2 || HAVE_AVX2 || HAVE_NEON
202*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE kValidBlockSize[] = {
203*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_4X4,     BLOCK_8X8,   BLOCK_8X16,  BLOCK_8X32,   BLOCK_16X8,
204*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_16X16,   BLOCK_16X32, BLOCK_32X8,  BLOCK_32X16,  BLOCK_32X32,
205*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_32X64,   BLOCK_64X32, BLOCK_64X64, BLOCK_64X128, BLOCK_128X64,
206*77c1e3ccSAndroid Build Coastguard Worker   BLOCK_128X128, BLOCK_16X64, BLOCK_64X16
207*77c1e3ccSAndroid Build Coastguard Worker };
208*77c1e3ccSAndroid Build Coastguard Worker #endif
209*77c1e3ccSAndroid Build Coastguard Worker 
210*77c1e3ccSAndroid Build Coastguard Worker typedef void (*upsampled_pred_func)(MACROBLOCKD *xd, const AV1_COMMON *const cm,
211*77c1e3ccSAndroid Build Coastguard Worker                                     int mi_row, int mi_col, const MV *const mv,
212*77c1e3ccSAndroid Build Coastguard Worker                                     uint8_t *comp_pred, int width, int height,
213*77c1e3ccSAndroid Build Coastguard Worker                                     int subpel_x_q3, int subpel_y_q3,
214*77c1e3ccSAndroid Build Coastguard Worker                                     const uint8_t *ref, int ref_stride,
215*77c1e3ccSAndroid Build Coastguard Worker                                     int subpel_search);
216*77c1e3ccSAndroid Build Coastguard Worker 
217*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<upsampled_pred_func, BLOCK_SIZE> UpsampledPredParam;
218*77c1e3ccSAndroid Build Coastguard Worker 
219*77c1e3ccSAndroid Build Coastguard Worker class AV1UpsampledPredTest
220*77c1e3ccSAndroid Build Coastguard Worker     : public AV1CompMaskPredBase,
221*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<UpsampledPredParam> {
222*77c1e3ccSAndroid Build Coastguard Worker  protected:
223*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(upsampled_pred_func test_impl, BLOCK_SIZE bsize);
224*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(upsampled_pred_func test_impl, BLOCK_SIZE bsize,
225*77c1e3ccSAndroid Build Coastguard Worker                     int havSub);
226*77c1e3ccSAndroid Build Coastguard Worker };
227*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(upsampled_pred_func test_impl,BLOCK_SIZE bsize)228*77c1e3ccSAndroid Build Coastguard Worker void AV1UpsampledPredTest::RunCheckOutput(upsampled_pred_func test_impl,
229*77c1e3ccSAndroid Build Coastguard Worker                                           BLOCK_SIZE bsize) {
230*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
231*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
232*77c1e3ccSAndroid Build Coastguard Worker   for (int subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
233*77c1e3ccSAndroid Build Coastguard Worker        ++subpel_search) {
234*77c1e3ccSAndroid Build Coastguard Worker     // loop through subx and suby
235*77c1e3ccSAndroid Build Coastguard Worker     for (int sub = 0; sub < 8 * 8; ++sub) {
236*77c1e3ccSAndroid Build Coastguard Worker       int subx = sub & 0x7;
237*77c1e3ccSAndroid Build Coastguard Worker       int suby = (sub >> 3);
238*77c1e3ccSAndroid Build Coastguard Worker 
239*77c1e3ccSAndroid Build Coastguard Worker       aom_upsampled_pred_c(nullptr, nullptr, 0, 0, nullptr, comp_pred1_, w, h,
240*77c1e3ccSAndroid Build Coastguard Worker                            subx, suby, ref_, MAX_SB_SIZE, subpel_search);
241*77c1e3ccSAndroid Build Coastguard Worker 
242*77c1e3ccSAndroid Build Coastguard Worker       test_impl(nullptr, nullptr, 0, 0, nullptr, comp_pred2_, w, h, subx, suby,
243*77c1e3ccSAndroid Build Coastguard Worker                 ref_, MAX_SB_SIZE, subpel_search);
244*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(CheckResult(w, h), true)
245*77c1e3ccSAndroid Build Coastguard Worker           << "sub (" << subx << "," << suby << ")";
246*77c1e3ccSAndroid Build Coastguard Worker     }
247*77c1e3ccSAndroid Build Coastguard Worker   }
248*77c1e3ccSAndroid Build Coastguard Worker }
249*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(upsampled_pred_func test_impl,BLOCK_SIZE bsize,int havSub)250*77c1e3ccSAndroid Build Coastguard Worker void AV1UpsampledPredTest::RunSpeedTest(upsampled_pred_func test_impl,
251*77c1e3ccSAndroid Build Coastguard Worker                                         BLOCK_SIZE bsize, int havSub) {
252*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
253*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
254*77c1e3ccSAndroid Build Coastguard Worker   const int subx = havSub ? 3 : 0;
255*77c1e3ccSAndroid Build Coastguard Worker   const int suby = havSub ? 4 : 0;
256*77c1e3ccSAndroid Build Coastguard Worker 
257*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
258*77c1e3ccSAndroid Build Coastguard Worker   upsampled_pred_func funcs[2] = { aom_upsampled_pred_c, test_impl };
259*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0 };
260*77c1e3ccSAndroid Build Coastguard Worker   int subpel_search = USE_8_TAPS;  // set to USE_4_TAPS to test 4-tap filter.
261*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
262*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
263*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
264*77c1e3ccSAndroid Build Coastguard Worker     upsampled_pred_func func = funcs[i];
265*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
266*77c1e3ccSAndroid Build Coastguard Worker       func(nullptr, nullptr, 0, 0, nullptr, comp_pred1_, w, h, subx, suby, ref_,
267*77c1e3ccSAndroid Build Coastguard Worker            MAX_SB_SIZE, subpel_search);
268*77c1e3ccSAndroid Build Coastguard Worker     }
269*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
270*77c1e3ccSAndroid Build Coastguard Worker     double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
271*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time / num_loops;
272*77c1e3ccSAndroid Build Coastguard Worker   }
273*77c1e3ccSAndroid Build Coastguard Worker   printf("UpsampledPred[%d] %3dx%-3d:%7.2f/%7.2fns", havSub, w, h,
274*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[0], elapsed_time[1]);
275*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
276*77c1e3ccSAndroid Build Coastguard Worker }
277*77c1e3ccSAndroid Build Coastguard Worker 
278*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1UpsampledPredTest);
279*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1UpsampledPredTest,CheckOutput)280*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1UpsampledPredTest, CheckOutput) {
281*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1));
282*77c1e3ccSAndroid Build Coastguard Worker }
283*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1UpsampledPredTest,DISABLED_Speed)284*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1UpsampledPredTest, DISABLED_Speed) {
285*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1), 1);
286*77c1e3ccSAndroid Build Coastguard Worker }
287*77c1e3ccSAndroid Build Coastguard Worker 
288*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
289*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
290*77c1e3ccSAndroid Build Coastguard Worker     SSE2, AV1UpsampledPredTest,
291*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_upsampled_pred_sse2),
292*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize)));
293*77c1e3ccSAndroid Build Coastguard Worker #endif
294*77c1e3ccSAndroid Build Coastguard Worker 
295*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
296*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
297*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1UpsampledPredTest,
298*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_upsampled_pred_neon),
299*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize)));
300*77c1e3ccSAndroid Build Coastguard Worker #endif
301*77c1e3ccSAndroid Build Coastguard Worker 
302*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<comp_avg_pred_func, BLOCK_SIZE> CompAvgPredParam;
303*77c1e3ccSAndroid Build Coastguard Worker 
304*77c1e3ccSAndroid Build Coastguard Worker class AV1CompAvgPredTest : public ::testing::TestWithParam<CompAvgPredParam> {
305*77c1e3ccSAndroid Build Coastguard Worker  public:
306*77c1e3ccSAndroid Build Coastguard Worker   ~AV1CompAvgPredTest() override;
307*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override;
308*77c1e3ccSAndroid Build Coastguard Worker 
309*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override;
310*77c1e3ccSAndroid Build Coastguard Worker 
311*77c1e3ccSAndroid Build Coastguard Worker  protected:
312*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(comp_avg_pred_func test_impl, BLOCK_SIZE bsize);
313*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(comp_avg_pred_func test_impl, BLOCK_SIZE bsize);
CheckResult(int width,int height)314*77c1e3ccSAndroid Build Coastguard Worker   bool CheckResult(int width, int height) {
315*77c1e3ccSAndroid Build Coastguard Worker     for (int y = 0; y < height; ++y) {
316*77c1e3ccSAndroid Build Coastguard Worker       for (int x = 0; x < width; ++x) {
317*77c1e3ccSAndroid Build Coastguard Worker         const int idx = y * width + x;
318*77c1e3ccSAndroid Build Coastguard Worker         if (comp_pred1_[idx] != comp_pred2_[idx]) {
319*77c1e3ccSAndroid Build Coastguard Worker           printf("%dx%d mismatch @%d(%d,%d) ", width, height, idx, x, y);
320*77c1e3ccSAndroid Build Coastguard Worker           printf("%d != %d ", comp_pred1_[idx], comp_pred2_[idx]);
321*77c1e3ccSAndroid Build Coastguard Worker           return false;
322*77c1e3ccSAndroid Build Coastguard Worker         }
323*77c1e3ccSAndroid Build Coastguard Worker       }
324*77c1e3ccSAndroid Build Coastguard Worker     }
325*77c1e3ccSAndroid Build Coastguard Worker     return true;
326*77c1e3ccSAndroid Build Coastguard Worker   }
327*77c1e3ccSAndroid Build Coastguard Worker 
328*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rnd_;
329*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *comp_pred1_;
330*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *comp_pred2_;
331*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *pred_;
332*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *ref_;
333*77c1e3ccSAndroid Build Coastguard Worker };
334*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1CompAvgPredTest);
335*77c1e3ccSAndroid Build Coastguard Worker 
336*77c1e3ccSAndroid Build Coastguard Worker AV1CompAvgPredTest::~AV1CompAvgPredTest() = default;
337*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()338*77c1e3ccSAndroid Build Coastguard Worker void AV1CompAvgPredTest::SetUp() {
339*77c1e3ccSAndroid Build Coastguard Worker   rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed());
340*77c1e3ccSAndroid Build Coastguard Worker 
341*77c1e3ccSAndroid Build Coastguard Worker   comp_pred1_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
342*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred1_, nullptr);
343*77c1e3ccSAndroid Build Coastguard Worker   comp_pred2_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
344*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred2_, nullptr);
345*77c1e3ccSAndroid Build Coastguard Worker   pred_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
346*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pred_, nullptr);
347*77c1e3ccSAndroid Build Coastguard Worker   ref_ = (uint8_t *)aom_memalign(16, MAX_SB_SQUARE);
348*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(ref_, nullptr);
349*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
350*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand8();
351*77c1e3ccSAndroid Build Coastguard Worker   }
352*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
353*77c1e3ccSAndroid Build Coastguard Worker     ref_[i] = rnd_.Rand8();
354*77c1e3ccSAndroid Build Coastguard Worker   }
355*77c1e3ccSAndroid Build Coastguard Worker }
356*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()357*77c1e3ccSAndroid Build Coastguard Worker void AV1CompAvgPredTest::TearDown() {
358*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred1_);
359*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred2_);
360*77c1e3ccSAndroid Build Coastguard Worker   aom_free(pred_);
361*77c1e3ccSAndroid Build Coastguard Worker   aom_free(ref_);
362*77c1e3ccSAndroid Build Coastguard Worker }
363*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(comp_avg_pred_func test_impl,BLOCK_SIZE bsize)364*77c1e3ccSAndroid Build Coastguard Worker void AV1CompAvgPredTest::RunCheckOutput(comp_avg_pred_func test_impl,
365*77c1e3ccSAndroid Build Coastguard Worker                                         BLOCK_SIZE bsize) {
366*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
367*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
368*77c1e3ccSAndroid Build Coastguard Worker   aom_comp_avg_pred_c(comp_pred1_, pred_, w, h, ref_, MAX_SB_SIZE);
369*77c1e3ccSAndroid Build Coastguard Worker   test_impl(comp_pred2_, pred_, w, h, ref_, MAX_SB_SIZE);
370*77c1e3ccSAndroid Build Coastguard Worker 
371*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(CheckResult(w, h), true);
372*77c1e3ccSAndroid Build Coastguard Worker }
373*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(comp_avg_pred_func test_impl,BLOCK_SIZE bsize)374*77c1e3ccSAndroid Build Coastguard Worker void AV1CompAvgPredTest::RunSpeedTest(comp_avg_pred_func test_impl,
375*77c1e3ccSAndroid Build Coastguard Worker                                       BLOCK_SIZE bsize) {
376*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
377*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
378*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
379*77c1e3ccSAndroid Build Coastguard Worker 
380*77c1e3ccSAndroid Build Coastguard Worker   comp_avg_pred_func functions[2] = { aom_comp_avg_pred_c, test_impl };
381*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0.0 };
382*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
383*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
384*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
385*77c1e3ccSAndroid Build Coastguard Worker     comp_avg_pred_func func = functions[i];
386*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
387*77c1e3ccSAndroid Build Coastguard Worker       func(comp_pred1_, pred_, w, h, ref_, MAX_SB_SIZE);
388*77c1e3ccSAndroid Build Coastguard Worker     }
389*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
390*77c1e3ccSAndroid Build Coastguard Worker     const double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
391*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time;
392*77c1e3ccSAndroid Build Coastguard Worker   }
393*77c1e3ccSAndroid Build Coastguard Worker   printf("CompAvgPred %3dx%-3d: %7.2f/%7.2fns", w, h, elapsed_time[0],
394*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[1]);
395*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
396*77c1e3ccSAndroid Build Coastguard Worker }
397*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1CompAvgPredTest,CheckOutput)398*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1CompAvgPredTest, CheckOutput) {
399*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1));
400*77c1e3ccSAndroid Build Coastguard Worker }
401*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1CompAvgPredTest,DISABLED_Speed)402*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1CompAvgPredTest, DISABLED_Speed) {
403*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1));
404*77c1e3ccSAndroid Build Coastguard Worker }
405*77c1e3ccSAndroid Build Coastguard Worker 
406*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
407*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
408*77c1e3ccSAndroid Build Coastguard Worker     AVX2, AV1CompAvgPredTest,
409*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_comp_avg_pred_avx2),
410*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize)));
411*77c1e3ccSAndroid Build Coastguard Worker #endif
412*77c1e3ccSAndroid Build Coastguard Worker 
413*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
414*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
415*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1CompAvgPredTest,
416*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_comp_avg_pred_neon),
417*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize)));
418*77c1e3ccSAndroid Build Coastguard Worker #endif
419*77c1e3ccSAndroid Build Coastguard Worker 
420*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
421*77c1e3ccSAndroid Build Coastguard Worker class AV1HighbdCompMaskPredTestBase : public ::testing::Test {
422*77c1e3ccSAndroid Build Coastguard Worker  public:
423*77c1e3ccSAndroid Build Coastguard Worker   ~AV1HighbdCompMaskPredTestBase() override;
424*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override;
425*77c1e3ccSAndroid Build Coastguard Worker 
426*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override;
427*77c1e3ccSAndroid Build Coastguard Worker 
428*77c1e3ccSAndroid Build Coastguard Worker  protected:
CheckResult(int width,int height)429*77c1e3ccSAndroid Build Coastguard Worker   bool CheckResult(int width, int height) {
430*77c1e3ccSAndroid Build Coastguard Worker     for (int y = 0; y < height; ++y) {
431*77c1e3ccSAndroid Build Coastguard Worker       for (int x = 0; x < width; ++x) {
432*77c1e3ccSAndroid Build Coastguard Worker         const int idx = y * width + x;
433*77c1e3ccSAndroid Build Coastguard Worker         if (comp_pred1_[idx] != comp_pred2_[idx]) {
434*77c1e3ccSAndroid Build Coastguard Worker           printf("%dx%d mismatch @%d(%d,%d) ", width, height, idx, y, x);
435*77c1e3ccSAndroid Build Coastguard Worker           printf("%d != %d ", comp_pred1_[idx], comp_pred2_[idx]);
436*77c1e3ccSAndroid Build Coastguard Worker           return false;
437*77c1e3ccSAndroid Build Coastguard Worker         }
438*77c1e3ccSAndroid Build Coastguard Worker       }
439*77c1e3ccSAndroid Build Coastguard Worker     }
440*77c1e3ccSAndroid Build Coastguard Worker     return true;
441*77c1e3ccSAndroid Build Coastguard Worker   }
442*77c1e3ccSAndroid Build Coastguard Worker 
443*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rnd_;
444*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *comp_pred1_;
445*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *comp_pred2_;
446*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *pred_;
447*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *ref_buffer_;
448*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *ref_;
449*77c1e3ccSAndroid Build Coastguard Worker };
450*77c1e3ccSAndroid Build Coastguard Worker 
451*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdCompMaskPredTestBase::~AV1HighbdCompMaskPredTestBase() = default;
452*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()453*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompMaskPredTestBase::SetUp() {
454*77c1e3ccSAndroid Build Coastguard Worker   rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed());
455*77c1e3ccSAndroid Build Coastguard Worker   av1_init_wedge_masks();
456*77c1e3ccSAndroid Build Coastguard Worker 
457*77c1e3ccSAndroid Build Coastguard Worker   comp_pred1_ =
458*77c1e3ccSAndroid Build Coastguard Worker       (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*comp_pred1_));
459*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred1_, nullptr);
460*77c1e3ccSAndroid Build Coastguard Worker   comp_pred2_ =
461*77c1e3ccSAndroid Build Coastguard Worker       (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*comp_pred2_));
462*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred2_, nullptr);
463*77c1e3ccSAndroid Build Coastguard Worker   pred_ = (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*pred_));
464*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pred_, nullptr);
465*77c1e3ccSAndroid Build Coastguard Worker   // The biggest block size is MAX_SB_SQUARE(128*128), however for the
466*77c1e3ccSAndroid Build Coastguard Worker   // convolution we need to access 3 elements before and 4 elements after (for
467*77c1e3ccSAndroid Build Coastguard Worker   // an 8-tap filter), in both directions, so we need to allocate (128 + 7) *
468*77c1e3ccSAndroid Build Coastguard Worker   // (128 + 7) = (MAX_SB_SQUARE + (14 * MAX_SB_SIZE) + 49) *
469*77c1e3ccSAndroid Build Coastguard Worker   // sizeof(*ref_buffer_)
470*77c1e3ccSAndroid Build Coastguard Worker   ref_buffer_ = (uint16_t *)aom_memalign(
471*77c1e3ccSAndroid Build Coastguard Worker       16, (MAX_SB_SQUARE + (14 * MAX_SB_SIZE) + 49) * sizeof(*ref_buffer_));
472*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(ref_buffer_, nullptr);
473*77c1e3ccSAndroid Build Coastguard Worker   // Start of the actual block where the convolution will be computed
474*77c1e3ccSAndroid Build Coastguard Worker   ref_ = ref_buffer_ + (3 * MAX_SB_SIZE + 3);
475*77c1e3ccSAndroid Build Coastguard Worker }
476*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()477*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompMaskPredTestBase::TearDown() {
478*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred1_);
479*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred2_);
480*77c1e3ccSAndroid Build Coastguard Worker   aom_free(pred_);
481*77c1e3ccSAndroid Build Coastguard Worker   aom_free(ref_buffer_);
482*77c1e3ccSAndroid Build Coastguard Worker }
483*77c1e3ccSAndroid Build Coastguard Worker 
484*77c1e3ccSAndroid Build Coastguard Worker typedef void (*highbd_comp_mask_pred_func)(uint8_t *comp_pred8,
485*77c1e3ccSAndroid Build Coastguard Worker                                            const uint8_t *pred8, int width,
486*77c1e3ccSAndroid Build Coastguard Worker                                            int height, const uint8_t *ref8,
487*77c1e3ccSAndroid Build Coastguard Worker                                            int ref_stride, const uint8_t *mask,
488*77c1e3ccSAndroid Build Coastguard Worker                                            int mask_stride, int invert_mask);
489*77c1e3ccSAndroid Build Coastguard Worker 
490*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<highbd_comp_mask_pred_func, BLOCK_SIZE, int>
491*77c1e3ccSAndroid Build Coastguard Worker     HighbdCompMaskPredParam;
492*77c1e3ccSAndroid Build Coastguard Worker 
493*77c1e3ccSAndroid Build Coastguard Worker class AV1HighbdCompMaskPredTest
494*77c1e3ccSAndroid Build Coastguard Worker     : public AV1HighbdCompMaskPredTestBase,
495*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<HighbdCompMaskPredParam> {
496*77c1e3ccSAndroid Build Coastguard Worker  public:
497*77c1e3ccSAndroid Build Coastguard Worker   ~AV1HighbdCompMaskPredTest() override;
498*77c1e3ccSAndroid Build Coastguard Worker 
499*77c1e3ccSAndroid Build Coastguard Worker  protected:
500*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(comp_mask_pred_func test_impl, BLOCK_SIZE bsize, int inv);
501*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(comp_mask_pred_func test_impl, BLOCK_SIZE bsize);
502*77c1e3ccSAndroid Build Coastguard Worker };
503*77c1e3ccSAndroid Build Coastguard Worker 
504*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdCompMaskPredTest::~AV1HighbdCompMaskPredTest() = default;
505*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(highbd_comp_mask_pred_func test_impl,BLOCK_SIZE bsize,int inv)506*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompMaskPredTest::RunCheckOutput(
507*77c1e3ccSAndroid Build Coastguard Worker     highbd_comp_mask_pred_func test_impl, BLOCK_SIZE bsize, int inv) {
508*77c1e3ccSAndroid Build Coastguard Worker   int bd_ = GET_PARAM(2);
509*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
510*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
511*77c1e3ccSAndroid Build Coastguard Worker   const int wedge_types = get_wedge_types_lookup(bsize);
512*77c1e3ccSAndroid Build Coastguard Worker 
513*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
514*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
515*77c1e3ccSAndroid Build Coastguard Worker   }
516*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE + (8 * MAX_SB_SIZE); ++i) {
517*77c1e3ccSAndroid Build Coastguard Worker     ref_buffer_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
518*77c1e3ccSAndroid Build Coastguard Worker   }
519*77c1e3ccSAndroid Build Coastguard Worker 
520*77c1e3ccSAndroid Build Coastguard Worker   for (int wedge_index = 0; wedge_index < wedge_types; ++wedge_index) {
521*77c1e3ccSAndroid Build Coastguard Worker     const uint8_t *mask = av1_get_contiguous_soft_mask(wedge_index, 1, bsize);
522*77c1e3ccSAndroid Build Coastguard Worker 
523*77c1e3ccSAndroid Build Coastguard Worker     aom_highbd_comp_mask_pred_c(
524*77c1e3ccSAndroid Build Coastguard Worker         CONVERT_TO_BYTEPTR(comp_pred1_), CONVERT_TO_BYTEPTR(pred_), w, h,
525*77c1e3ccSAndroid Build Coastguard Worker         CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE, mask, w, inv);
526*77c1e3ccSAndroid Build Coastguard Worker 
527*77c1e3ccSAndroid Build Coastguard Worker     test_impl(CONVERT_TO_BYTEPTR(comp_pred2_), CONVERT_TO_BYTEPTR(pred_), w, h,
528*77c1e3ccSAndroid Build Coastguard Worker               CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE, mask, w, inv);
529*77c1e3ccSAndroid Build Coastguard Worker 
530*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(CheckResult(w, h), true)
531*77c1e3ccSAndroid Build Coastguard Worker         << " wedge " << wedge_index << " inv " << inv;
532*77c1e3ccSAndroid Build Coastguard Worker   }
533*77c1e3ccSAndroid Build Coastguard Worker }
534*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(highbd_comp_mask_pred_func test_impl,BLOCK_SIZE bsize)535*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompMaskPredTest::RunSpeedTest(
536*77c1e3ccSAndroid Build Coastguard Worker     highbd_comp_mask_pred_func test_impl, BLOCK_SIZE bsize) {
537*77c1e3ccSAndroid Build Coastguard Worker   int bd_ = GET_PARAM(2);
538*77c1e3ccSAndroid Build Coastguard Worker 
539*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
540*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
541*77c1e3ccSAndroid Build Coastguard Worker   const int wedge_types = get_wedge_types_lookup(bsize);
542*77c1e3ccSAndroid Build Coastguard Worker   int wedge_index = wedge_types / 2;
543*77c1e3ccSAndroid Build Coastguard Worker 
544*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
545*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
546*77c1e3ccSAndroid Build Coastguard Worker   }
547*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE + (8 * MAX_SB_SIZE); ++i) {
548*77c1e3ccSAndroid Build Coastguard Worker     ref_buffer_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
549*77c1e3ccSAndroid Build Coastguard Worker   }
550*77c1e3ccSAndroid Build Coastguard Worker 
551*77c1e3ccSAndroid Build Coastguard Worker   const uint8_t *mask = av1_get_contiguous_soft_mask(wedge_index, 1, bsize);
552*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
553*77c1e3ccSAndroid Build Coastguard Worker 
554*77c1e3ccSAndroid Build Coastguard Worker   highbd_comp_mask_pred_func funcs[2] = { aom_highbd_comp_mask_pred_c,
555*77c1e3ccSAndroid Build Coastguard Worker                                           test_impl };
556*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0 };
557*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
558*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
559*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
560*77c1e3ccSAndroid Build Coastguard Worker     highbd_comp_mask_pred_func func = funcs[i];
561*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
562*77c1e3ccSAndroid Build Coastguard Worker       func(CONVERT_TO_BYTEPTR(comp_pred1_), CONVERT_TO_BYTEPTR(pred_), w, h,
563*77c1e3ccSAndroid Build Coastguard Worker            CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE, mask, w, 0);
564*77c1e3ccSAndroid Build Coastguard Worker     }
565*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
566*77c1e3ccSAndroid Build Coastguard Worker     double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
567*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time / num_loops;
568*77c1e3ccSAndroid Build Coastguard Worker   }
569*77c1e3ccSAndroid Build Coastguard Worker   printf("compMask %3dx%-3d: %7.2f/%7.2fns", w, h, elapsed_time[0],
570*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[1]);
571*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
572*77c1e3ccSAndroid Build Coastguard Worker }
573*77c1e3ccSAndroid Build Coastguard Worker 
574*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HighbdCompMaskPredTest);
575*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdCompMaskPredTest,CheckOutput)576*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdCompMaskPredTest, CheckOutput) {
577*77c1e3ccSAndroid Build Coastguard Worker   // inv = 0, 1
578*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1), 0);
579*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1), 1);
580*77c1e3ccSAndroid Build Coastguard Worker }
581*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdCompMaskPredTest,DISABLED_Speed)582*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdCompMaskPredTest, DISABLED_Speed) {
583*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1));
584*77c1e3ccSAndroid Build Coastguard Worker }
585*77c1e3ccSAndroid Build Coastguard Worker 
586*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
587*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
588*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1HighbdCompMaskPredTest,
589*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_comp_mask_pred_neon),
590*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams),
591*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
592*77c1e3ccSAndroid Build Coastguard Worker #endif
593*77c1e3ccSAndroid Build Coastguard Worker 
594*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
595*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
596*77c1e3ccSAndroid Build Coastguard Worker     AVX2, AV1HighbdCompMaskPredTest,
597*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_comp_mask_pred_avx2),
598*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams),
599*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
600*77c1e3ccSAndroid Build Coastguard Worker #endif
601*77c1e3ccSAndroid Build Coastguard Worker 
602*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
603*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
604*77c1e3ccSAndroid Build Coastguard Worker     SSE2, AV1HighbdCompMaskPredTest,
605*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_comp_mask_pred_sse2),
606*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kCompMaskPredParams),
607*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
608*77c1e3ccSAndroid Build Coastguard Worker #endif
609*77c1e3ccSAndroid Build Coastguard Worker 
610*77c1e3ccSAndroid Build Coastguard Worker typedef void (*highbd_upsampled_pred_func)(
611*77c1e3ccSAndroid Build Coastguard Worker     MACROBLOCKD *xd, const struct AV1Common *const cm, int mi_row, int mi_col,
612*77c1e3ccSAndroid Build Coastguard Worker     const MV *const mv, uint8_t *comp_pred8, int width, int height,
613*77c1e3ccSAndroid Build Coastguard Worker     int subpel_x_q3, int subpel_y_q3, const uint8_t *ref8, int ref_stride,
614*77c1e3ccSAndroid Build Coastguard Worker     int bd, int subpel_search);
615*77c1e3ccSAndroid Build Coastguard Worker 
616*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<highbd_upsampled_pred_func, BLOCK_SIZE, int>
617*77c1e3ccSAndroid Build Coastguard Worker     HighbdUpsampledPredParam;
618*77c1e3ccSAndroid Build Coastguard Worker 
619*77c1e3ccSAndroid Build Coastguard Worker class AV1HighbdUpsampledPredTest
620*77c1e3ccSAndroid Build Coastguard Worker     : public AV1HighbdCompMaskPredTestBase,
621*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<HighbdUpsampledPredParam> {
622*77c1e3ccSAndroid Build Coastguard Worker  public:
623*77c1e3ccSAndroid Build Coastguard Worker   ~AV1HighbdUpsampledPredTest() override;
624*77c1e3ccSAndroid Build Coastguard Worker 
625*77c1e3ccSAndroid Build Coastguard Worker  protected:
626*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(highbd_upsampled_pred_func test_impl, BLOCK_SIZE bsize);
627*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(highbd_upsampled_pred_func test_impl, BLOCK_SIZE bsize,
628*77c1e3ccSAndroid Build Coastguard Worker                     int havSub);
629*77c1e3ccSAndroid Build Coastguard Worker };
630*77c1e3ccSAndroid Build Coastguard Worker 
631*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdUpsampledPredTest::~AV1HighbdUpsampledPredTest() = default;
632*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(highbd_upsampled_pred_func test_impl,BLOCK_SIZE bsize)633*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdUpsampledPredTest::RunCheckOutput(
634*77c1e3ccSAndroid Build Coastguard Worker     highbd_upsampled_pred_func test_impl, BLOCK_SIZE bsize) {
635*77c1e3ccSAndroid Build Coastguard Worker   int bd_ = GET_PARAM(2);
636*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
637*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
638*77c1e3ccSAndroid Build Coastguard Worker 
639*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
640*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
641*77c1e3ccSAndroid Build Coastguard Worker   }
642*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE + (8 * MAX_SB_SIZE); ++i) {
643*77c1e3ccSAndroid Build Coastguard Worker     ref_buffer_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
644*77c1e3ccSAndroid Build Coastguard Worker   }
645*77c1e3ccSAndroid Build Coastguard Worker 
646*77c1e3ccSAndroid Build Coastguard Worker   for (int subpel_search = 1; subpel_search <= 2; ++subpel_search) {
647*77c1e3ccSAndroid Build Coastguard Worker     // loop through subx and suby
648*77c1e3ccSAndroid Build Coastguard Worker     for (int sub = 0; sub < 8 * 8; ++sub) {
649*77c1e3ccSAndroid Build Coastguard Worker       int subx = sub & 0x7;
650*77c1e3ccSAndroid Build Coastguard Worker       int suby = (sub >> 3);
651*77c1e3ccSAndroid Build Coastguard Worker 
652*77c1e3ccSAndroid Build Coastguard Worker       aom_highbd_upsampled_pred_c(nullptr, nullptr, 0, 0, nullptr,
653*77c1e3ccSAndroid Build Coastguard Worker                                   CONVERT_TO_BYTEPTR(comp_pred1_), w, h, subx,
654*77c1e3ccSAndroid Build Coastguard Worker                                   suby, CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE,
655*77c1e3ccSAndroid Build Coastguard Worker                                   bd_, subpel_search);
656*77c1e3ccSAndroid Build Coastguard Worker 
657*77c1e3ccSAndroid Build Coastguard Worker       test_impl(nullptr, nullptr, 0, 0, nullptr,
658*77c1e3ccSAndroid Build Coastguard Worker                 CONVERT_TO_BYTEPTR(comp_pred2_), w, h, subx, suby,
659*77c1e3ccSAndroid Build Coastguard Worker                 CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE, bd_, subpel_search);
660*77c1e3ccSAndroid Build Coastguard Worker 
661*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(CheckResult(w, h), true)
662*77c1e3ccSAndroid Build Coastguard Worker           << "sub (" << subx << "," << suby << ")";
663*77c1e3ccSAndroid Build Coastguard Worker     }
664*77c1e3ccSAndroid Build Coastguard Worker   }
665*77c1e3ccSAndroid Build Coastguard Worker }
666*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(highbd_upsampled_pred_func test_impl,BLOCK_SIZE bsize,int havSub)667*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdUpsampledPredTest::RunSpeedTest(
668*77c1e3ccSAndroid Build Coastguard Worker     highbd_upsampled_pred_func test_impl, BLOCK_SIZE bsize, int havSub) {
669*77c1e3ccSAndroid Build Coastguard Worker   int bd_ = GET_PARAM(2);
670*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
671*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
672*77c1e3ccSAndroid Build Coastguard Worker   const int subx = havSub ? 3 : 0;
673*77c1e3ccSAndroid Build Coastguard Worker   const int suby = havSub ? 4 : 0;
674*77c1e3ccSAndroid Build Coastguard Worker 
675*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
676*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
677*77c1e3ccSAndroid Build Coastguard Worker   }
678*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE + (8 * MAX_SB_SIZE); ++i) {
679*77c1e3ccSAndroid Build Coastguard Worker     ref_buffer_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
680*77c1e3ccSAndroid Build Coastguard Worker   }
681*77c1e3ccSAndroid Build Coastguard Worker 
682*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
683*77c1e3ccSAndroid Build Coastguard Worker   highbd_upsampled_pred_func funcs[2] = { &aom_highbd_upsampled_pred_c,
684*77c1e3ccSAndroid Build Coastguard Worker                                           test_impl };
685*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0 };
686*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
687*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
688*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
689*77c1e3ccSAndroid Build Coastguard Worker     highbd_upsampled_pred_func func = funcs[i];
690*77c1e3ccSAndroid Build Coastguard Worker     int subpel_search = 2;  // set to 1 to test 4-tap filter.
691*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
692*77c1e3ccSAndroid Build Coastguard Worker       func(nullptr, nullptr, 0, 0, nullptr, CONVERT_TO_BYTEPTR(comp_pred1_), w,
693*77c1e3ccSAndroid Build Coastguard Worker            h, subx, suby, CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE, bd_,
694*77c1e3ccSAndroid Build Coastguard Worker            subpel_search);
695*77c1e3ccSAndroid Build Coastguard Worker     }
696*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
697*77c1e3ccSAndroid Build Coastguard Worker     double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
698*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time / num_loops;
699*77c1e3ccSAndroid Build Coastguard Worker   }
700*77c1e3ccSAndroid Build Coastguard Worker   printf("CompMaskUp[%d] %3dx%-3d:%7.2f/%7.2fns", havSub, w, h, elapsed_time[0],
701*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[1]);
702*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
703*77c1e3ccSAndroid Build Coastguard Worker }
704*77c1e3ccSAndroid Build Coastguard Worker 
705*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HighbdUpsampledPredTest);
706*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdUpsampledPredTest,CheckOutput)707*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdUpsampledPredTest, CheckOutput) {
708*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1));
709*77c1e3ccSAndroid Build Coastguard Worker }
710*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdUpsampledPredTest,DISABLED_Speed)711*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdUpsampledPredTest, DISABLED_Speed) {
712*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1), 1);
713*77c1e3ccSAndroid Build Coastguard Worker }
714*77c1e3ccSAndroid Build Coastguard Worker 
715*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
716*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
717*77c1e3ccSAndroid Build Coastguard Worker     SSE2, AV1HighbdUpsampledPredTest,
718*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_upsampled_pred_sse2),
719*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize),
720*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
721*77c1e3ccSAndroid Build Coastguard Worker #endif
722*77c1e3ccSAndroid Build Coastguard Worker 
723*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
724*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
725*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1HighbdUpsampledPredTest,
726*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_upsampled_pred_neon),
727*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize),
728*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
729*77c1e3ccSAndroid Build Coastguard Worker #endif
730*77c1e3ccSAndroid Build Coastguard Worker 
731*77c1e3ccSAndroid Build Coastguard Worker typedef void (*highbd_comp_avg_pred_func)(uint8_t *comp_pred,
732*77c1e3ccSAndroid Build Coastguard Worker                                           const uint8_t *pred, int width,
733*77c1e3ccSAndroid Build Coastguard Worker                                           int height, const uint8_t *ref,
734*77c1e3ccSAndroid Build Coastguard Worker                                           int ref_stride);
735*77c1e3ccSAndroid Build Coastguard Worker 
736*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<highbd_comp_avg_pred_func, BLOCK_SIZE, int>
737*77c1e3ccSAndroid Build Coastguard Worker     HighbdCompAvgPredParam;
738*77c1e3ccSAndroid Build Coastguard Worker 
739*77c1e3ccSAndroid Build Coastguard Worker class AV1HighbdCompAvgPredTest
740*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::TestWithParam<HighbdCompAvgPredParam> {
741*77c1e3ccSAndroid Build Coastguard Worker  public:
742*77c1e3ccSAndroid Build Coastguard Worker   ~AV1HighbdCompAvgPredTest() override;
743*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override;
744*77c1e3ccSAndroid Build Coastguard Worker 
745*77c1e3ccSAndroid Build Coastguard Worker  protected:
746*77c1e3ccSAndroid Build Coastguard Worker   void RunCheckOutput(highbd_comp_avg_pred_func test_impl, BLOCK_SIZE bsize);
747*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest(highbd_comp_avg_pred_func test_impl, BLOCK_SIZE bsize);
CheckResult(int width,int height) const748*77c1e3ccSAndroid Build Coastguard Worker   bool CheckResult(int width, int height) const {
749*77c1e3ccSAndroid Build Coastguard Worker     for (int y = 0; y < height; ++y) {
750*77c1e3ccSAndroid Build Coastguard Worker       for (int x = 0; x < width; ++x) {
751*77c1e3ccSAndroid Build Coastguard Worker         const int idx = y * width + x;
752*77c1e3ccSAndroid Build Coastguard Worker         if (comp_pred1_[idx] != comp_pred2_[idx]) {
753*77c1e3ccSAndroid Build Coastguard Worker           printf("%dx%d mismatch @%d(%d,%d) ", width, height, idx, x, y);
754*77c1e3ccSAndroid Build Coastguard Worker           printf("%d != %d ", comp_pred1_[idx], comp_pred2_[idx]);
755*77c1e3ccSAndroid Build Coastguard Worker           return false;
756*77c1e3ccSAndroid Build Coastguard Worker         }
757*77c1e3ccSAndroid Build Coastguard Worker       }
758*77c1e3ccSAndroid Build Coastguard Worker     }
759*77c1e3ccSAndroid Build Coastguard Worker     return true;
760*77c1e3ccSAndroid Build Coastguard Worker   }
761*77c1e3ccSAndroid Build Coastguard Worker 
762*77c1e3ccSAndroid Build Coastguard Worker   libaom_test::ACMRandom rnd_;
763*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *comp_pred1_;
764*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *comp_pred2_;
765*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *pred_;
766*77c1e3ccSAndroid Build Coastguard Worker   uint16_t *ref_;
767*77c1e3ccSAndroid Build Coastguard Worker };
768*77c1e3ccSAndroid Build Coastguard Worker 
~AV1HighbdCompAvgPredTest()769*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdCompAvgPredTest::~AV1HighbdCompAvgPredTest() {
770*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred1_);
771*77c1e3ccSAndroid Build Coastguard Worker   aom_free(comp_pred2_);
772*77c1e3ccSAndroid Build Coastguard Worker   aom_free(pred_);
773*77c1e3ccSAndroid Build Coastguard Worker   aom_free(ref_);
774*77c1e3ccSAndroid Build Coastguard Worker }
775*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()776*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompAvgPredTest::SetUp() {
777*77c1e3ccSAndroid Build Coastguard Worker   int bd_ = GET_PARAM(2);
778*77c1e3ccSAndroid Build Coastguard Worker   rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed());
779*77c1e3ccSAndroid Build Coastguard Worker 
780*77c1e3ccSAndroid Build Coastguard Worker   comp_pred1_ =
781*77c1e3ccSAndroid Build Coastguard Worker       (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*comp_pred1_));
782*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred1_, nullptr);
783*77c1e3ccSAndroid Build Coastguard Worker   comp_pred2_ =
784*77c1e3ccSAndroid Build Coastguard Worker       (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*comp_pred2_));
785*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(comp_pred2_, nullptr);
786*77c1e3ccSAndroid Build Coastguard Worker   pred_ = (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*pred_));
787*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(pred_, nullptr);
788*77c1e3ccSAndroid Build Coastguard Worker   ref_ = (uint16_t *)aom_memalign(16, MAX_SB_SQUARE * sizeof(*ref_));
789*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_NE(ref_, nullptr);
790*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
791*77c1e3ccSAndroid Build Coastguard Worker     pred_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
792*77c1e3ccSAndroid Build Coastguard Worker   }
793*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < MAX_SB_SQUARE; ++i) {
794*77c1e3ccSAndroid Build Coastguard Worker     ref_[i] = rnd_.Rand16() & ((1 << bd_) - 1);
795*77c1e3ccSAndroid Build Coastguard Worker   }
796*77c1e3ccSAndroid Build Coastguard Worker }
797*77c1e3ccSAndroid Build Coastguard Worker 
RunCheckOutput(highbd_comp_avg_pred_func test_impl,BLOCK_SIZE bsize)798*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompAvgPredTest::RunCheckOutput(
799*77c1e3ccSAndroid Build Coastguard Worker     highbd_comp_avg_pred_func test_impl, BLOCK_SIZE bsize) {
800*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
801*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
802*77c1e3ccSAndroid Build Coastguard Worker   aom_highbd_comp_avg_pred_c(CONVERT_TO_BYTEPTR(comp_pred1_),
803*77c1e3ccSAndroid Build Coastguard Worker                              CONVERT_TO_BYTEPTR(pred_), w, h,
804*77c1e3ccSAndroid Build Coastguard Worker                              CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE);
805*77c1e3ccSAndroid Build Coastguard Worker   test_impl(CONVERT_TO_BYTEPTR(comp_pred2_), CONVERT_TO_BYTEPTR(pred_), w, h,
806*77c1e3ccSAndroid Build Coastguard Worker             CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE);
807*77c1e3ccSAndroid Build Coastguard Worker 
808*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(CheckResult(w, h), true);
809*77c1e3ccSAndroid Build Coastguard Worker }
810*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest(highbd_comp_avg_pred_func test_impl,BLOCK_SIZE bsize)811*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdCompAvgPredTest::RunSpeedTest(highbd_comp_avg_pred_func test_impl,
812*77c1e3ccSAndroid Build Coastguard Worker                                             BLOCK_SIZE bsize) {
813*77c1e3ccSAndroid Build Coastguard Worker   const int w = block_size_wide[bsize];
814*77c1e3ccSAndroid Build Coastguard Worker   const int h = block_size_high[bsize];
815*77c1e3ccSAndroid Build Coastguard Worker   const int num_loops = 1000000000 / (w + h);
816*77c1e3ccSAndroid Build Coastguard Worker 
817*77c1e3ccSAndroid Build Coastguard Worker   highbd_comp_avg_pred_func functions[2] = { aom_highbd_comp_avg_pred_c,
818*77c1e3ccSAndroid Build Coastguard Worker                                              test_impl };
819*77c1e3ccSAndroid Build Coastguard Worker   double elapsed_time[2] = { 0.0 };
820*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < 2; ++i) {
821*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
822*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
823*77c1e3ccSAndroid Build Coastguard Worker     highbd_comp_avg_pred_func func = functions[i];
824*77c1e3ccSAndroid Build Coastguard Worker     for (int j = 0; j < num_loops; ++j) {
825*77c1e3ccSAndroid Build Coastguard Worker       func(CONVERT_TO_BYTEPTR(comp_pred1_), CONVERT_TO_BYTEPTR(pred_), w, h,
826*77c1e3ccSAndroid Build Coastguard Worker            CONVERT_TO_BYTEPTR(ref_), MAX_SB_SIZE);
827*77c1e3ccSAndroid Build Coastguard Worker     }
828*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
829*77c1e3ccSAndroid Build Coastguard Worker     const double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
830*77c1e3ccSAndroid Build Coastguard Worker     elapsed_time[i] = 1000.0 * time;
831*77c1e3ccSAndroid Build Coastguard Worker   }
832*77c1e3ccSAndroid Build Coastguard Worker   printf("HighbdCompAvg %3dx%-3d: %7.2f/%7.2fns", w, h, elapsed_time[0],
833*77c1e3ccSAndroid Build Coastguard Worker          elapsed_time[1]);
834*77c1e3ccSAndroid Build Coastguard Worker   printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
835*77c1e3ccSAndroid Build Coastguard Worker }
836*77c1e3ccSAndroid Build Coastguard Worker 
837*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HighbdCompAvgPredTest);
838*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdCompAvgPredTest,CheckOutput)839*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdCompAvgPredTest, CheckOutput) {
840*77c1e3ccSAndroid Build Coastguard Worker   RunCheckOutput(GET_PARAM(0), GET_PARAM(1));
841*77c1e3ccSAndroid Build Coastguard Worker }
842*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1HighbdCompAvgPredTest,DISABLED_Speed)843*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdCompAvgPredTest, DISABLED_Speed) {
844*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest(GET_PARAM(0), GET_PARAM(1));
845*77c1e3ccSAndroid Build Coastguard Worker }
846*77c1e3ccSAndroid Build Coastguard Worker 
847*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
848*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
849*77c1e3ccSAndroid Build Coastguard Worker     NEON, AV1HighbdCompAvgPredTest,
850*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Combine(::testing::Values(&aom_highbd_comp_avg_pred_neon),
851*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::ValuesIn(kValidBlockSize),
852*77c1e3ccSAndroid Build Coastguard Worker                        ::testing::Range(8, 13, 2)));
853*77c1e3ccSAndroid Build Coastguard Worker #endif
854*77c1e3ccSAndroid Build Coastguard Worker 
855*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
856*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
857