xref: /aosp_15_r20/external/libaom/test/avg_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2019, 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 <stdlib.h>
13*77c1e3ccSAndroid Build Coastguard Worker #include <ostream>
14*77c1e3ccSAndroid Build Coastguard Worker #include <string>
15*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
16*77c1e3ccSAndroid Build Coastguard Worker 
17*77c1e3ccSAndroid Build Coastguard Worker #include "gtest/gtest.h"
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_dsp_rtcd.h"
21*77c1e3ccSAndroid Build Coastguard Worker 
22*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/aom_timer.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/mem.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "test/register_state_check.h"
26*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
27*77c1e3ccSAndroid Build Coastguard Worker 
28*77c1e3ccSAndroid Build Coastguard Worker namespace {
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom;
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker template <typename Pixel>
33*77c1e3ccSAndroid Build Coastguard Worker class AverageTestBase : public ::testing::Test {
34*77c1e3ccSAndroid Build Coastguard Worker  public:
AverageTestBase(int width,int height,int bit_depth=8)35*77c1e3ccSAndroid Build Coastguard Worker   AverageTestBase(int width, int height, int bit_depth = 8)
36*77c1e3ccSAndroid Build Coastguard Worker       : width_(width), height_(height), source_data_(nullptr),
37*77c1e3ccSAndroid Build Coastguard Worker         source_stride_(0), bit_depth_(bit_depth) {}
38*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()39*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
40*77c1e3ccSAndroid Build Coastguard Worker     aom_free(source_data_);
41*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = nullptr;
42*77c1e3ccSAndroid Build Coastguard Worker   }
43*77c1e3ccSAndroid Build Coastguard Worker 
44*77c1e3ccSAndroid Build Coastguard Worker  protected:
45*77c1e3ccSAndroid Build Coastguard Worker   // Handle blocks up to 4 blocks 64x64 with stride up to 128
46*77c1e3ccSAndroid Build Coastguard Worker   static const int kDataAlignment = 16;
47*77c1e3ccSAndroid Build Coastguard Worker   static const int kDataBlockWidth = 128;
48*77c1e3ccSAndroid Build Coastguard Worker   static const int kDataBlockHeight = 128;
49*77c1e3ccSAndroid Build Coastguard Worker   static const int kDataBlockSize = kDataBlockWidth * kDataBlockHeight;
50*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()51*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
52*77c1e3ccSAndroid Build Coastguard Worker     const testing::TestInfo *const test_info =
53*77c1e3ccSAndroid Build Coastguard Worker         testing::UnitTest::GetInstance()->current_test_info();
54*77c1e3ccSAndroid Build Coastguard Worker     // Skip the speed test for C code as the baseline uses the same function.
55*77c1e3ccSAndroid Build Coastguard Worker     if (std::string(test_info->test_suite_name()).find("C/") == 0 &&
56*77c1e3ccSAndroid Build Coastguard Worker         std::string(test_info->name()).find("DISABLED_Speed") !=
57*77c1e3ccSAndroid Build Coastguard Worker             std::string::npos) {
58*77c1e3ccSAndroid Build Coastguard Worker       GTEST_SKIP();
59*77c1e3ccSAndroid Build Coastguard Worker     }
60*77c1e3ccSAndroid Build Coastguard Worker 
61*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = static_cast<Pixel *>(
62*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, kDataBlockSize * sizeof(source_data_[0])));
63*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(source_data_, nullptr);
64*77c1e3ccSAndroid Build Coastguard Worker     memset(source_data_, 0, kDataBlockSize * sizeof(source_data_[0]));
65*77c1e3ccSAndroid Build Coastguard Worker     source_stride_ = (width_ + 31) & ~31;
66*77c1e3ccSAndroid Build Coastguard Worker     bit_depth_ = 8;
67*77c1e3ccSAndroid Build Coastguard Worker     rnd_.Reset(ACMRandom::DeterministicSeed());
68*77c1e3ccSAndroid Build Coastguard Worker   }
69*77c1e3ccSAndroid Build Coastguard Worker 
70*77c1e3ccSAndroid Build Coastguard Worker   // Sum Pixels
ReferenceAverage8x8(const Pixel * source,int pitch)71*77c1e3ccSAndroid Build Coastguard Worker   static unsigned int ReferenceAverage8x8(const Pixel *source, int pitch) {
72*77c1e3ccSAndroid Build Coastguard Worker     unsigned int average = 0;
73*77c1e3ccSAndroid Build Coastguard Worker     for (int h = 0; h < 8; ++h) {
74*77c1e3ccSAndroid Build Coastguard Worker       for (int w = 0; w < 8; ++w) average += source[h * pitch + w];
75*77c1e3ccSAndroid Build Coastguard Worker     }
76*77c1e3ccSAndroid Build Coastguard Worker     return (average + 32) >> 6;
77*77c1e3ccSAndroid Build Coastguard Worker   }
78*77c1e3ccSAndroid Build Coastguard Worker 
ReferenceAverage8x8_quad(const uint8_t * source,int pitch,int x16_idx,int y16_idx,int * avg)79*77c1e3ccSAndroid Build Coastguard Worker   static void ReferenceAverage8x8_quad(const uint8_t *source, int pitch,
80*77c1e3ccSAndroid Build Coastguard Worker                                        int x16_idx, int y16_idx, int *avg) {
81*77c1e3ccSAndroid Build Coastguard Worker     for (int k = 0; k < 4; k++) {
82*77c1e3ccSAndroid Build Coastguard Worker       int average = 0;
83*77c1e3ccSAndroid Build Coastguard Worker       int x8_idx = x16_idx + ((k & 1) << 3);
84*77c1e3ccSAndroid Build Coastguard Worker       int y8_idx = y16_idx + ((k >> 1) << 3);
85*77c1e3ccSAndroid Build Coastguard Worker       for (int h = 0; h < 8; ++h) {
86*77c1e3ccSAndroid Build Coastguard Worker         for (int w = 0; w < 8; ++w)
87*77c1e3ccSAndroid Build Coastguard Worker           average += source[(h + y8_idx) * pitch + w + x8_idx];
88*77c1e3ccSAndroid Build Coastguard Worker       }
89*77c1e3ccSAndroid Build Coastguard Worker       avg[k] = (average + 32) >> 6;
90*77c1e3ccSAndroid Build Coastguard Worker     }
91*77c1e3ccSAndroid Build Coastguard Worker   }
92*77c1e3ccSAndroid Build Coastguard Worker 
ReferenceAverage4x4(const Pixel * source,int pitch)93*77c1e3ccSAndroid Build Coastguard Worker   static unsigned int ReferenceAverage4x4(const Pixel *source, int pitch) {
94*77c1e3ccSAndroid Build Coastguard Worker     unsigned int average = 0;
95*77c1e3ccSAndroid Build Coastguard Worker     for (int h = 0; h < 4; ++h) {
96*77c1e3ccSAndroid Build Coastguard Worker       for (int w = 0; w < 4; ++w) average += source[h * pitch + w];
97*77c1e3ccSAndroid Build Coastguard Worker     }
98*77c1e3ccSAndroid Build Coastguard Worker     return (average + 8) >> 4;
99*77c1e3ccSAndroid Build Coastguard Worker   }
100*77c1e3ccSAndroid Build Coastguard Worker 
FillConstant(Pixel fill_constant)101*77c1e3ccSAndroid Build Coastguard Worker   void FillConstant(Pixel fill_constant) {
102*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < width_ * height_; ++i) {
103*77c1e3ccSAndroid Build Coastguard Worker       source_data_[i] = fill_constant;
104*77c1e3ccSAndroid Build Coastguard Worker     }
105*77c1e3ccSAndroid Build Coastguard Worker   }
106*77c1e3ccSAndroid Build Coastguard Worker 
FillRandom()107*77c1e3ccSAndroid Build Coastguard Worker   void FillRandom() {
108*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < width_ * height_; ++i) {
109*77c1e3ccSAndroid Build Coastguard Worker       source_data_[i] = rnd_.Rand16() & ((1 << bit_depth_) - 1);
110*77c1e3ccSAndroid Build Coastguard Worker     }
111*77c1e3ccSAndroid Build Coastguard Worker   }
112*77c1e3ccSAndroid Build Coastguard Worker 
113*77c1e3ccSAndroid Build Coastguard Worker   int width_, height_;
114*77c1e3ccSAndroid Build Coastguard Worker   Pixel *source_data_;
115*77c1e3ccSAndroid Build Coastguard Worker   int source_stride_;
116*77c1e3ccSAndroid Build Coastguard Worker   int bit_depth_;
117*77c1e3ccSAndroid Build Coastguard Worker 
118*77c1e3ccSAndroid Build Coastguard Worker   ACMRandom rnd_;
119*77c1e3ccSAndroid Build Coastguard Worker };
120*77c1e3ccSAndroid Build Coastguard Worker typedef unsigned int (*AverageFunction)(const uint8_t *s, int pitch);
121*77c1e3ccSAndroid Build Coastguard Worker 
122*77c1e3ccSAndroid Build Coastguard Worker // Arguments: width, height, bit_depth, buffer start offset, block size, avg
123*77c1e3ccSAndroid Build Coastguard Worker // function.
124*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<int, int, int, int, int, AverageFunction> AvgFunc;
125*77c1e3ccSAndroid Build Coastguard Worker 
126*77c1e3ccSAndroid Build Coastguard Worker template <typename Pixel>
127*77c1e3ccSAndroid Build Coastguard Worker class AverageTest : public AverageTestBase<Pixel>,
128*77c1e3ccSAndroid Build Coastguard Worker                     public ::testing::WithParamInterface<AvgFunc> {
129*77c1e3ccSAndroid Build Coastguard Worker  public:
AverageTest()130*77c1e3ccSAndroid Build Coastguard Worker   AverageTest()
131*77c1e3ccSAndroid Build Coastguard Worker       : AverageTestBase<Pixel>(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2)) {}
132*77c1e3ccSAndroid Build Coastguard Worker 
133*77c1e3ccSAndroid Build Coastguard Worker  protected:
134*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::source_data_;
135*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::source_stride_;
136*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::ReferenceAverage8x8;
137*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::ReferenceAverage4x4;
138*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::FillConstant;
139*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::FillRandom;
140*77c1e3ccSAndroid Build Coastguard Worker 
CheckAverages()141*77c1e3ccSAndroid Build Coastguard Worker   void CheckAverages() {
142*77c1e3ccSAndroid Build Coastguard Worker     const int block_size = GET_PARAM(4);
143*77c1e3ccSAndroid Build Coastguard Worker     unsigned int expected = 0;
144*77c1e3ccSAndroid Build Coastguard Worker 
145*77c1e3ccSAndroid Build Coastguard Worker     // The reference frame, but not the source frame, may be unaligned for
146*77c1e3ccSAndroid Build Coastguard Worker     // certain types of searches.
147*77c1e3ccSAndroid Build Coastguard Worker     const Pixel *const src = source_data_ + GET_PARAM(3);
148*77c1e3ccSAndroid Build Coastguard Worker     if (block_size == 8) {
149*77c1e3ccSAndroid Build Coastguard Worker       expected = ReferenceAverage8x8(src, source_stride_);
150*77c1e3ccSAndroid Build Coastguard Worker     } else if (block_size == 4) {
151*77c1e3ccSAndroid Build Coastguard Worker       expected = ReferenceAverage4x4(src, source_stride_);
152*77c1e3ccSAndroid Build Coastguard Worker     }
153*77c1e3ccSAndroid Build Coastguard Worker 
154*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
155*77c1e3ccSAndroid Build Coastguard Worker     unsigned int actual;
156*77c1e3ccSAndroid Build Coastguard Worker     if (sizeof(Pixel) == 2) {
157*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
158*77c1e3ccSAndroid Build Coastguard Worker       AverageFunction avg_c =
159*77c1e3ccSAndroid Build Coastguard Worker           (block_size == 8) ? aom_highbd_avg_8x8_c : aom_highbd_avg_4x4_c;
160*77c1e3ccSAndroid Build Coastguard Worker       // To avoid differences in optimization with the local Reference*()
161*77c1e3ccSAndroid Build Coastguard Worker       // functions the C implementation is used as a baseline.
162*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_start(&timer);
163*77c1e3ccSAndroid Build Coastguard Worker       avg_c(CONVERT_TO_BYTEPTR(src), source_stride_);
164*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_mark(&timer);
165*77c1e3ccSAndroid Build Coastguard Worker       ref_elapsed_time_ += aom_usec_timer_elapsed(&timer);
166*77c1e3ccSAndroid Build Coastguard Worker 
167*77c1e3ccSAndroid Build Coastguard Worker       AverageFunction avg_opt = GET_PARAM(5);
168*77c1e3ccSAndroid Build Coastguard Worker       API_REGISTER_STATE_CHECK(
169*77c1e3ccSAndroid Build Coastguard Worker           aom_usec_timer_start(&timer);
170*77c1e3ccSAndroid Build Coastguard Worker           actual = avg_opt(CONVERT_TO_BYTEPTR(src), source_stride_);
171*77c1e3ccSAndroid Build Coastguard Worker           aom_usec_timer_mark(&timer));
172*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
173*77c1e3ccSAndroid Build Coastguard Worker     } else {
174*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_EQ(sizeof(Pixel), 1u);
175*77c1e3ccSAndroid Build Coastguard Worker 
176*77c1e3ccSAndroid Build Coastguard Worker       AverageFunction avg_c = (block_size == 8) ? aom_avg_8x8_c : aom_avg_4x4_c;
177*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_start(&timer);
178*77c1e3ccSAndroid Build Coastguard Worker       avg_c(reinterpret_cast<const uint8_t *>(src), source_stride_);
179*77c1e3ccSAndroid Build Coastguard Worker       aom_usec_timer_mark(&timer);
180*77c1e3ccSAndroid Build Coastguard Worker       ref_elapsed_time_ += aom_usec_timer_elapsed(&timer);
181*77c1e3ccSAndroid Build Coastguard Worker 
182*77c1e3ccSAndroid Build Coastguard Worker       AverageFunction avg_opt = GET_PARAM(5);
183*77c1e3ccSAndroid Build Coastguard Worker       API_REGISTER_STATE_CHECK(
184*77c1e3ccSAndroid Build Coastguard Worker           aom_usec_timer_start(&timer);
185*77c1e3ccSAndroid Build Coastguard Worker           actual =
186*77c1e3ccSAndroid Build Coastguard Worker               avg_opt(reinterpret_cast<const uint8_t *>(src), source_stride_);
187*77c1e3ccSAndroid Build Coastguard Worker           aom_usec_timer_mark(&timer));
188*77c1e3ccSAndroid Build Coastguard Worker     }
189*77c1e3ccSAndroid Build Coastguard Worker     opt_elapsed_time_ += aom_usec_timer_elapsed(&timer);
190*77c1e3ccSAndroid Build Coastguard Worker 
191*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(expected, actual);
192*77c1e3ccSAndroid Build Coastguard Worker   }
193*77c1e3ccSAndroid Build Coastguard Worker 
TestConstantValue(Pixel value)194*77c1e3ccSAndroid Build Coastguard Worker   void TestConstantValue(Pixel value) {
195*77c1e3ccSAndroid Build Coastguard Worker     FillConstant(value);
196*77c1e3ccSAndroid Build Coastguard Worker     CheckAverages();
197*77c1e3ccSAndroid Build Coastguard Worker   }
198*77c1e3ccSAndroid Build Coastguard Worker 
TestRandom(int iterations=1000)199*77c1e3ccSAndroid Build Coastguard Worker   void TestRandom(int iterations = 1000) {
200*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < iterations; i++) {
201*77c1e3ccSAndroid Build Coastguard Worker       FillRandom();
202*77c1e3ccSAndroid Build Coastguard Worker       CheckAverages();
203*77c1e3ccSAndroid Build Coastguard Worker     }
204*77c1e3ccSAndroid Build Coastguard Worker   }
205*77c1e3ccSAndroid Build Coastguard Worker 
PrintTimingStats() const206*77c1e3ccSAndroid Build Coastguard Worker   void PrintTimingStats() const {
207*77c1e3ccSAndroid Build Coastguard Worker     printf(
208*77c1e3ccSAndroid Build Coastguard Worker         "block_size = %d \t ref_time = %d \t simd_time = %d \t Gain = %4.2f\n",
209*77c1e3ccSAndroid Build Coastguard Worker         GET_PARAM(4), static_cast<int>(ref_elapsed_time_),
210*77c1e3ccSAndroid Build Coastguard Worker         static_cast<int>(opt_elapsed_time_),
211*77c1e3ccSAndroid Build Coastguard Worker         (static_cast<float>(ref_elapsed_time_) /
212*77c1e3ccSAndroid Build Coastguard Worker          static_cast<float>(opt_elapsed_time_)));
213*77c1e3ccSAndroid Build Coastguard Worker   }
214*77c1e3ccSAndroid Build Coastguard Worker 
215*77c1e3ccSAndroid Build Coastguard Worker   int64_t ref_elapsed_time_ = 0;
216*77c1e3ccSAndroid Build Coastguard Worker   int64_t opt_elapsed_time_ = 0;
217*77c1e3ccSAndroid Build Coastguard Worker };
218*77c1e3ccSAndroid Build Coastguard Worker 
219*77c1e3ccSAndroid Build Coastguard Worker typedef void (*AverageFunction_8x8_quad)(const uint8_t *s, int pitch, int x_idx,
220*77c1e3ccSAndroid Build Coastguard Worker                                          int y_idx, int *avg);
221*77c1e3ccSAndroid Build Coastguard Worker 
222*77c1e3ccSAndroid Build Coastguard Worker // Arguments: width, height, bit_depth, buffer start offset, block size, avg
223*77c1e3ccSAndroid Build Coastguard Worker // function.
224*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<int, int, int, int, int, AverageFunction_8x8_quad>
225*77c1e3ccSAndroid Build Coastguard Worker     AvgFunc_8x8_quad;
226*77c1e3ccSAndroid Build Coastguard Worker 
227*77c1e3ccSAndroid Build Coastguard Worker template <typename Pixel>
228*77c1e3ccSAndroid Build Coastguard Worker class AverageTest_8x8_quad
229*77c1e3ccSAndroid Build Coastguard Worker     : public AverageTestBase<Pixel>,
230*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<AvgFunc_8x8_quad> {
231*77c1e3ccSAndroid Build Coastguard Worker  public:
AverageTest_8x8_quad()232*77c1e3ccSAndroid Build Coastguard Worker   AverageTest_8x8_quad()
233*77c1e3ccSAndroid Build Coastguard Worker       : AverageTestBase<Pixel>(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2)) {}
234*77c1e3ccSAndroid Build Coastguard Worker 
235*77c1e3ccSAndroid Build Coastguard Worker  protected:
236*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::source_data_;
237*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::source_stride_;
238*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::ReferenceAverage8x8_quad;
239*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::FillConstant;
240*77c1e3ccSAndroid Build Coastguard Worker   using AverageTestBase<Pixel>::FillRandom;
241*77c1e3ccSAndroid Build Coastguard Worker 
CheckAveragesAt(int iterations,int x16_idx,int y16_idx)242*77c1e3ccSAndroid Build Coastguard Worker   void CheckAveragesAt(int iterations, int x16_idx, int y16_idx) {
243*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(sizeof(Pixel), 1u);
244*77c1e3ccSAndroid Build Coastguard Worker     const int block_size = GET_PARAM(4);
245*77c1e3ccSAndroid Build Coastguard Worker     (void)block_size;
246*77c1e3ccSAndroid Build Coastguard Worker     int expected[4] = { 0 };
247*77c1e3ccSAndroid Build Coastguard Worker 
248*77c1e3ccSAndroid Build Coastguard Worker     // The reference frame, but not the source frame, may be unaligned for
249*77c1e3ccSAndroid Build Coastguard Worker     // certain types of searches.
250*77c1e3ccSAndroid Build Coastguard Worker     const Pixel *const src = source_data_ + GET_PARAM(3);
251*77c1e3ccSAndroid Build Coastguard Worker     ReferenceAverage8x8_quad(src, source_stride_, x16_idx, y16_idx, expected);
252*77c1e3ccSAndroid Build Coastguard Worker 
253*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
254*77c1e3ccSAndroid Build Coastguard Worker     int expected_c[4] = { 0 };
255*77c1e3ccSAndroid Build Coastguard Worker     int actual[4] = { 0 };
256*77c1e3ccSAndroid Build Coastguard Worker     AverageFunction_8x8_quad avg_c = aom_avg_8x8_quad_c;
257*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
258*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < iterations; i++) {
259*77c1e3ccSAndroid Build Coastguard Worker       avg_c(reinterpret_cast<const uint8_t *>(src), source_stride_, x16_idx,
260*77c1e3ccSAndroid Build Coastguard Worker             y16_idx, expected_c);
261*77c1e3ccSAndroid Build Coastguard Worker     }
262*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
263*77c1e3ccSAndroid Build Coastguard Worker     ref_elapsed_time_ += aom_usec_timer_elapsed(&timer);
264*77c1e3ccSAndroid Build Coastguard Worker 
265*77c1e3ccSAndroid Build Coastguard Worker     AverageFunction_8x8_quad avg_opt = GET_PARAM(5);
266*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
267*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < iterations; i++) {
268*77c1e3ccSAndroid Build Coastguard Worker       avg_opt(reinterpret_cast<const uint8_t *>(src), source_stride_, x16_idx,
269*77c1e3ccSAndroid Build Coastguard Worker               y16_idx, actual);
270*77c1e3ccSAndroid Build Coastguard Worker     }
271*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
272*77c1e3ccSAndroid Build Coastguard Worker     opt_elapsed_time_ += aom_usec_timer_elapsed(&timer);
273*77c1e3ccSAndroid Build Coastguard Worker 
274*77c1e3ccSAndroid Build Coastguard Worker     for (int k = 0; k < 4; k++) {
275*77c1e3ccSAndroid Build Coastguard Worker       EXPECT_EQ(expected[k], actual[k]);
276*77c1e3ccSAndroid Build Coastguard Worker       EXPECT_EQ(expected_c[k], actual[k]);
277*77c1e3ccSAndroid Build Coastguard Worker     }
278*77c1e3ccSAndroid Build Coastguard Worker 
279*77c1e3ccSAndroid Build Coastguard Worker     // Print scaling information only when Speed test is called.
280*77c1e3ccSAndroid Build Coastguard Worker     if (iterations > 1) {
281*77c1e3ccSAndroid Build Coastguard Worker       printf("ref_time = %d \t simd_time = %d \t Gain = %4.2f\n",
282*77c1e3ccSAndroid Build Coastguard Worker              static_cast<int>(ref_elapsed_time_),
283*77c1e3ccSAndroid Build Coastguard Worker              static_cast<int>(opt_elapsed_time_),
284*77c1e3ccSAndroid Build Coastguard Worker              (static_cast<float>(ref_elapsed_time_) /
285*77c1e3ccSAndroid Build Coastguard Worker               static_cast<float>(opt_elapsed_time_)));
286*77c1e3ccSAndroid Build Coastguard Worker     }
287*77c1e3ccSAndroid Build Coastguard Worker   }
288*77c1e3ccSAndroid Build Coastguard Worker 
CheckAverages()289*77c1e3ccSAndroid Build Coastguard Worker   void CheckAverages() {
290*77c1e3ccSAndroid Build Coastguard Worker     for (int x16_idx = 0; x16_idx < this->kDataBlockWidth / 8; x16_idx += 2)
291*77c1e3ccSAndroid Build Coastguard Worker       for (int y16_idx = 0; y16_idx < this->kDataBlockHeight / 8; y16_idx += 2)
292*77c1e3ccSAndroid Build Coastguard Worker         CheckAveragesAt(1, x16_idx, y16_idx);
293*77c1e3ccSAndroid Build Coastguard Worker   }
294*77c1e3ccSAndroid Build Coastguard Worker 
TestConstantValue(Pixel value)295*77c1e3ccSAndroid Build Coastguard Worker   void TestConstantValue(Pixel value) {
296*77c1e3ccSAndroid Build Coastguard Worker     FillConstant(value);
297*77c1e3ccSAndroid Build Coastguard Worker     CheckAverages();
298*77c1e3ccSAndroid Build Coastguard Worker   }
299*77c1e3ccSAndroid Build Coastguard Worker 
TestRandom()300*77c1e3ccSAndroid Build Coastguard Worker   void TestRandom() {
301*77c1e3ccSAndroid Build Coastguard Worker     FillRandom();
302*77c1e3ccSAndroid Build Coastguard Worker     CheckAverages();
303*77c1e3ccSAndroid Build Coastguard Worker   }
304*77c1e3ccSAndroid Build Coastguard Worker 
TestSpeed()305*77c1e3ccSAndroid Build Coastguard Worker   void TestSpeed() {
306*77c1e3ccSAndroid Build Coastguard Worker     FillRandom();
307*77c1e3ccSAndroid Build Coastguard Worker     CheckAveragesAt(1000000, 0, 0);
308*77c1e3ccSAndroid Build Coastguard Worker   }
309*77c1e3ccSAndroid Build Coastguard Worker 
310*77c1e3ccSAndroid Build Coastguard Worker   int64_t ref_elapsed_time_ = 0;
311*77c1e3ccSAndroid Build Coastguard Worker   int64_t opt_elapsed_time_ = 0;
312*77c1e3ccSAndroid Build Coastguard Worker };
313*77c1e3ccSAndroid Build Coastguard Worker 
314*77c1e3ccSAndroid Build Coastguard Worker using AverageTest8bpp = AverageTest<uint8_t>;
315*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTest8bpp,MinValue)316*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTest8bpp, MinValue) { TestConstantValue(0); }
317*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTest8bpp,MaxValue)318*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTest8bpp, MaxValue) { TestConstantValue(255); }
319*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTest8bpp,Random)320*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTest8bpp, Random) { TestRandom(); }
321*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTest8bpp,DISABLED_Speed)322*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTest8bpp, DISABLED_Speed) {
323*77c1e3ccSAndroid Build Coastguard Worker   TestRandom(1000000);
324*77c1e3ccSAndroid Build Coastguard Worker   PrintTimingStats();
325*77c1e3ccSAndroid Build Coastguard Worker }
326*77c1e3ccSAndroid Build Coastguard Worker 
327*77c1e3ccSAndroid Build Coastguard Worker using AvgTest8bpp_avg_8x8_quad = AverageTest_8x8_quad<uint8_t>;
328*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AvgTest8bpp_avg_8x8_quad,MinValue)329*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AvgTest8bpp_avg_8x8_quad, MinValue) { TestConstantValue(0); }
330*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AvgTest8bpp_avg_8x8_quad,MaxValue)331*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AvgTest8bpp_avg_8x8_quad, MaxValue) { TestConstantValue(255); }
332*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AvgTest8bpp_avg_8x8_quad,Random)333*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AvgTest8bpp_avg_8x8_quad, Random) { TestRandom(); }
334*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AvgTest8bpp_avg_8x8_quad,DISABLED_Speed)335*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AvgTest8bpp_avg_8x8_quad, DISABLED_Speed) { TestSpeed(); }
336*77c1e3ccSAndroid Build Coastguard Worker 
337*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
338*77c1e3ccSAndroid Build Coastguard Worker using AverageTestHbd = AverageTest<uint16_t>;
339*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTestHbd,MinValue)340*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTestHbd, MinValue) { TestConstantValue(0); }
341*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTestHbd,MaxValue10bit)342*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTestHbd, MaxValue10bit) { TestConstantValue(1023); }
TEST_P(AverageTestHbd,MaxValue12bit)343*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTestHbd, MaxValue12bit) { TestConstantValue(4095); }
344*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTestHbd,Random)345*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTestHbd, Random) { TestRandom(); }
346*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AverageTestHbd,DISABLED_Speed)347*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AverageTestHbd, DISABLED_Speed) {
348*77c1e3ccSAndroid Build Coastguard Worker   TestRandom(1000000);
349*77c1e3ccSAndroid Build Coastguard Worker   PrintTimingStats();
350*77c1e3ccSAndroid Build Coastguard Worker }
351*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
352*77c1e3ccSAndroid Build Coastguard Worker 
353*77c1e3ccSAndroid Build Coastguard Worker typedef void (*IntProRowFunc)(int16_t *hbuf, uint8_t const *ref,
354*77c1e3ccSAndroid Build Coastguard Worker                               const int ref_stride, const int width,
355*77c1e3ccSAndroid Build Coastguard Worker                               const int height, int norm_factor);
356*77c1e3ccSAndroid Build Coastguard Worker 
357*77c1e3ccSAndroid Build Coastguard Worker // Params: width, height, asm function, c function.
358*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<int, int, IntProRowFunc, IntProRowFunc> IntProRowParam;
359*77c1e3ccSAndroid Build Coastguard Worker 
360*77c1e3ccSAndroid Build Coastguard Worker class IntProRowTest : public AverageTestBase<uint8_t>,
361*77c1e3ccSAndroid Build Coastguard Worker                       public ::testing::WithParamInterface<IntProRowParam> {
362*77c1e3ccSAndroid Build Coastguard Worker  public:
IntProRowTest()363*77c1e3ccSAndroid Build Coastguard Worker   IntProRowTest()
364*77c1e3ccSAndroid Build Coastguard Worker       : AverageTestBase(GET_PARAM(0), GET_PARAM(1)), hbuf_asm_(nullptr),
365*77c1e3ccSAndroid Build Coastguard Worker         hbuf_c_(nullptr) {
366*77c1e3ccSAndroid Build Coastguard Worker     asm_func_ = GET_PARAM(2);
367*77c1e3ccSAndroid Build Coastguard Worker     c_func_ = GET_PARAM(3);
368*77c1e3ccSAndroid Build Coastguard Worker   }
369*77c1e3ccSAndroid Build Coastguard Worker 
set_norm_factor()370*77c1e3ccSAndroid Build Coastguard Worker   void set_norm_factor() {
371*77c1e3ccSAndroid Build Coastguard Worker     if (height_ == 128)
372*77c1e3ccSAndroid Build Coastguard Worker       norm_factor_ = 6;
373*77c1e3ccSAndroid Build Coastguard Worker     else if (height_ == 64)
374*77c1e3ccSAndroid Build Coastguard Worker       norm_factor_ = 5;
375*77c1e3ccSAndroid Build Coastguard Worker     else if (height_ == 32)
376*77c1e3ccSAndroid Build Coastguard Worker       norm_factor_ = 4;
377*77c1e3ccSAndroid Build Coastguard Worker     else if (height_ == 16)
378*77c1e3ccSAndroid Build Coastguard Worker       norm_factor_ = 3;
379*77c1e3ccSAndroid Build Coastguard Worker   }
380*77c1e3ccSAndroid Build Coastguard Worker 
381*77c1e3ccSAndroid Build Coastguard Worker  protected:
SetUp()382*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
383*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = static_cast<uint8_t *>(
384*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, kDataBlockSize * sizeof(source_data_[0])));
385*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(source_data_, nullptr);
386*77c1e3ccSAndroid Build Coastguard Worker 
387*77c1e3ccSAndroid Build Coastguard Worker     hbuf_asm_ = static_cast<int16_t *>(
388*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, sizeof(*hbuf_asm_) * width_));
389*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(hbuf_asm_, nullptr);
390*77c1e3ccSAndroid Build Coastguard Worker     hbuf_c_ = static_cast<int16_t *>(
391*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, sizeof(*hbuf_c_) * width_));
392*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(hbuf_c_, nullptr);
393*77c1e3ccSAndroid Build Coastguard Worker   }
394*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()395*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
396*77c1e3ccSAndroid Build Coastguard Worker     aom_free(source_data_);
397*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = nullptr;
398*77c1e3ccSAndroid Build Coastguard Worker     aom_free(hbuf_c_);
399*77c1e3ccSAndroid Build Coastguard Worker     hbuf_c_ = nullptr;
400*77c1e3ccSAndroid Build Coastguard Worker     aom_free(hbuf_asm_);
401*77c1e3ccSAndroid Build Coastguard Worker     hbuf_asm_ = nullptr;
402*77c1e3ccSAndroid Build Coastguard Worker   }
403*77c1e3ccSAndroid Build Coastguard Worker 
RunComparison()404*77c1e3ccSAndroid Build Coastguard Worker   void RunComparison() {
405*77c1e3ccSAndroid Build Coastguard Worker     set_norm_factor();
406*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(
407*77c1e3ccSAndroid Build Coastguard Worker         c_func_(hbuf_c_, source_data_, width_, width_, height_, norm_factor_));
408*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(asm_func_(hbuf_asm_, source_data_, width_, width_,
409*77c1e3ccSAndroid Build Coastguard Worker                                        height_, norm_factor_));
410*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * width_))
411*77c1e3ccSAndroid Build Coastguard Worker         << "Output mismatch\n";
412*77c1e3ccSAndroid Build Coastguard Worker   }
413*77c1e3ccSAndroid Build Coastguard Worker 
RunSpeedTest()414*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest() {
415*77c1e3ccSAndroid Build Coastguard Worker     const int numIter = 5000000;
416*77c1e3ccSAndroid Build Coastguard Worker     set_norm_factor();
417*77c1e3ccSAndroid Build Coastguard Worker     printf("Blk_Size=%dx%d: number of iteration is %d \n", width_, height_,
418*77c1e3ccSAndroid Build Coastguard Worker            numIter);
419*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer c_timer_;
420*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&c_timer_);
421*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
422*77c1e3ccSAndroid Build Coastguard Worker       c_func_(hbuf_c_, source_data_, width_, width_, height_, norm_factor_);
423*77c1e3ccSAndroid Build Coastguard Worker     }
424*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&c_timer_);
425*77c1e3ccSAndroid Build Coastguard Worker 
426*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer asm_timer_;
427*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&asm_timer_);
428*77c1e3ccSAndroid Build Coastguard Worker 
429*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
430*77c1e3ccSAndroid Build Coastguard Worker       asm_func_(hbuf_asm_, source_data_, width_, width_, height_, norm_factor_);
431*77c1e3ccSAndroid Build Coastguard Worker     }
432*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&asm_timer_);
433*77c1e3ccSAndroid Build Coastguard Worker 
434*77c1e3ccSAndroid Build Coastguard Worker     const int c_sum_time = static_cast<int>(aom_usec_timer_elapsed(&c_timer_));
435*77c1e3ccSAndroid Build Coastguard Worker     const int asm_sum_time =
436*77c1e3ccSAndroid Build Coastguard Worker         static_cast<int>(aom_usec_timer_elapsed(&asm_timer_));
437*77c1e3ccSAndroid Build Coastguard Worker 
438*77c1e3ccSAndroid Build Coastguard Worker     printf("c_time = %d \t simd_time = %d \t Gain = %4.2f \n", c_sum_time,
439*77c1e3ccSAndroid Build Coastguard Worker            asm_sum_time,
440*77c1e3ccSAndroid Build Coastguard Worker            (static_cast<float>(c_sum_time) / static_cast<float>(asm_sum_time)));
441*77c1e3ccSAndroid Build Coastguard Worker 
442*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * width_))
443*77c1e3ccSAndroid Build Coastguard Worker         << "Output mismatch\n";
444*77c1e3ccSAndroid Build Coastguard Worker   }
445*77c1e3ccSAndroid Build Coastguard Worker 
446*77c1e3ccSAndroid Build Coastguard Worker  private:
447*77c1e3ccSAndroid Build Coastguard Worker   IntProRowFunc asm_func_;
448*77c1e3ccSAndroid Build Coastguard Worker   IntProRowFunc c_func_;
449*77c1e3ccSAndroid Build Coastguard Worker   int16_t *hbuf_asm_;
450*77c1e3ccSAndroid Build Coastguard Worker   int16_t *hbuf_c_;
451*77c1e3ccSAndroid Build Coastguard Worker   int norm_factor_;
452*77c1e3ccSAndroid Build Coastguard Worker };
453*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IntProRowTest);
454*77c1e3ccSAndroid Build Coastguard Worker 
455*77c1e3ccSAndroid Build Coastguard Worker typedef void (*IntProColFunc)(int16_t *vbuf, uint8_t const *ref,
456*77c1e3ccSAndroid Build Coastguard Worker                               const int ref_stride, const int width,
457*77c1e3ccSAndroid Build Coastguard Worker                               const int height, int norm_factor);
458*77c1e3ccSAndroid Build Coastguard Worker 
459*77c1e3ccSAndroid Build Coastguard Worker // Params: width, height, asm function, c function.
460*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<int, int, IntProColFunc, IntProColFunc> IntProColParam;
461*77c1e3ccSAndroid Build Coastguard Worker 
462*77c1e3ccSAndroid Build Coastguard Worker class IntProColTest : public AverageTestBase<uint8_t>,
463*77c1e3ccSAndroid Build Coastguard Worker                       public ::testing::WithParamInterface<IntProColParam> {
464*77c1e3ccSAndroid Build Coastguard Worker  public:
IntProColTest()465*77c1e3ccSAndroid Build Coastguard Worker   IntProColTest()
466*77c1e3ccSAndroid Build Coastguard Worker       : AverageTestBase(GET_PARAM(0), GET_PARAM(1)), vbuf_asm_(nullptr),
467*77c1e3ccSAndroid Build Coastguard Worker         vbuf_c_(nullptr) {
468*77c1e3ccSAndroid Build Coastguard Worker     asm_func_ = GET_PARAM(2);
469*77c1e3ccSAndroid Build Coastguard Worker     c_func_ = GET_PARAM(3);
470*77c1e3ccSAndroid Build Coastguard Worker   }
471*77c1e3ccSAndroid Build Coastguard Worker 
472*77c1e3ccSAndroid Build Coastguard Worker  protected:
SetUp()473*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
474*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = static_cast<uint8_t *>(
475*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, kDataBlockSize * sizeof(source_data_[0])));
476*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(source_data_, nullptr);
477*77c1e3ccSAndroid Build Coastguard Worker 
478*77c1e3ccSAndroid Build Coastguard Worker     vbuf_asm_ = static_cast<int16_t *>(
479*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, sizeof(*vbuf_asm_) * width_));
480*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(vbuf_asm_, nullptr);
481*77c1e3ccSAndroid Build Coastguard Worker     vbuf_c_ = static_cast<int16_t *>(
482*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, sizeof(*vbuf_c_) * width_));
483*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(vbuf_c_, nullptr);
484*77c1e3ccSAndroid Build Coastguard Worker   }
485*77c1e3ccSAndroid Build Coastguard Worker 
TearDown()486*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
487*77c1e3ccSAndroid Build Coastguard Worker     aom_free(source_data_);
488*77c1e3ccSAndroid Build Coastguard Worker     source_data_ = nullptr;
489*77c1e3ccSAndroid Build Coastguard Worker     aom_free(vbuf_c_);
490*77c1e3ccSAndroid Build Coastguard Worker     vbuf_c_ = nullptr;
491*77c1e3ccSAndroid Build Coastguard Worker     aom_free(vbuf_asm_);
492*77c1e3ccSAndroid Build Coastguard Worker     vbuf_asm_ = nullptr;
493*77c1e3ccSAndroid Build Coastguard Worker   }
494*77c1e3ccSAndroid Build Coastguard Worker 
RunComparison()495*77c1e3ccSAndroid Build Coastguard Worker   void RunComparison() {
496*77c1e3ccSAndroid Build Coastguard Worker     int norm_factor_ = 3 + (width_ >> 5);
497*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(
498*77c1e3ccSAndroid Build Coastguard Worker         c_func_(vbuf_c_, source_data_, width_, width_, height_, norm_factor_));
499*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(asm_func_(vbuf_asm_, source_data_, width_, width_,
500*77c1e3ccSAndroid Build Coastguard Worker                                        height_, norm_factor_));
501*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(0, memcmp(vbuf_c_, vbuf_asm_, sizeof(*vbuf_c_) * height_))
502*77c1e3ccSAndroid Build Coastguard Worker         << "Output mismatch\n";
503*77c1e3ccSAndroid Build Coastguard Worker   }
RunSpeedTest()504*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest() {
505*77c1e3ccSAndroid Build Coastguard Worker     const int numIter = 5000000;
506*77c1e3ccSAndroid Build Coastguard Worker     printf("Blk_Size=%dx%d: number of iteration is %d \n", width_, height_,
507*77c1e3ccSAndroid Build Coastguard Worker            numIter);
508*77c1e3ccSAndroid Build Coastguard Worker     int norm_factor_ = 3 + (width_ >> 5);
509*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer c_timer_;
510*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&c_timer_);
511*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
512*77c1e3ccSAndroid Build Coastguard Worker       c_func_(vbuf_c_, source_data_, width_, width_, height_, norm_factor_);
513*77c1e3ccSAndroid Build Coastguard Worker     }
514*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&c_timer_);
515*77c1e3ccSAndroid Build Coastguard Worker 
516*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer asm_timer_;
517*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&asm_timer_);
518*77c1e3ccSAndroid Build Coastguard Worker 
519*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
520*77c1e3ccSAndroid Build Coastguard Worker       asm_func_(vbuf_asm_, source_data_, width_, width_, height_, norm_factor_);
521*77c1e3ccSAndroid Build Coastguard Worker     }
522*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&asm_timer_);
523*77c1e3ccSAndroid Build Coastguard Worker 
524*77c1e3ccSAndroid Build Coastguard Worker     const int c_sum_time = static_cast<int>(aom_usec_timer_elapsed(&c_timer_));
525*77c1e3ccSAndroid Build Coastguard Worker     const int asm_sum_time =
526*77c1e3ccSAndroid Build Coastguard Worker         static_cast<int>(aom_usec_timer_elapsed(&asm_timer_));
527*77c1e3ccSAndroid Build Coastguard Worker 
528*77c1e3ccSAndroid Build Coastguard Worker     printf("c_time = %d \t simd_time = %d \t Gain = %4.2f \n", c_sum_time,
529*77c1e3ccSAndroid Build Coastguard Worker            asm_sum_time,
530*77c1e3ccSAndroid Build Coastguard Worker            (static_cast<float>(c_sum_time) / static_cast<float>(asm_sum_time)));
531*77c1e3ccSAndroid Build Coastguard Worker 
532*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(0, memcmp(vbuf_c_, vbuf_asm_, sizeof(*vbuf_c_) * height_))
533*77c1e3ccSAndroid Build Coastguard Worker         << "Output mismatch\n";
534*77c1e3ccSAndroid Build Coastguard Worker   }
535*77c1e3ccSAndroid Build Coastguard Worker 
536*77c1e3ccSAndroid Build Coastguard Worker  private:
537*77c1e3ccSAndroid Build Coastguard Worker   IntProColFunc asm_func_;
538*77c1e3ccSAndroid Build Coastguard Worker   IntProColFunc c_func_;
539*77c1e3ccSAndroid Build Coastguard Worker   int16_t *vbuf_asm_;
540*77c1e3ccSAndroid Build Coastguard Worker   int16_t *vbuf_c_;
541*77c1e3ccSAndroid Build Coastguard Worker };
542*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(IntProColTest);
543*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProRowTest,MinValue)544*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProRowTest, MinValue) {
545*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(0);
546*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
547*77c1e3ccSAndroid Build Coastguard Worker }
548*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProRowTest,MaxValue)549*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProRowTest, MaxValue) {
550*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(255);
551*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
552*77c1e3ccSAndroid Build Coastguard Worker }
553*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProRowTest,Random)554*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProRowTest, Random) {
555*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
556*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
557*77c1e3ccSAndroid Build Coastguard Worker }
558*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProRowTest,DISABLED_Speed)559*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProRowTest, DISABLED_Speed) {
560*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
561*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest();
562*77c1e3ccSAndroid Build Coastguard Worker }
563*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProColTest,MinValue)564*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProColTest, MinValue) {
565*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(0);
566*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
567*77c1e3ccSAndroid Build Coastguard Worker }
568*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProColTest,MaxValue)569*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProColTest, MaxValue) {
570*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(255);
571*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
572*77c1e3ccSAndroid Build Coastguard Worker }
573*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProColTest,Random)574*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProColTest, Random) {
575*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
576*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
577*77c1e3ccSAndroid Build Coastguard Worker }
578*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(IntProColTest,DISABLED_Speed)579*77c1e3ccSAndroid Build Coastguard Worker TEST_P(IntProColTest, DISABLED_Speed) {
580*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
581*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest();
582*77c1e3ccSAndroid Build Coastguard Worker }
583*77c1e3ccSAndroid Build Coastguard Worker class VectorVarTestBase : public ::testing::Test {
584*77c1e3ccSAndroid Build Coastguard Worker  public:
VectorVarTestBase(int bwl)585*77c1e3ccSAndroid Build Coastguard Worker   explicit VectorVarTestBase(int bwl) { m_bwl = bwl; }
586*77c1e3ccSAndroid Build Coastguard Worker   VectorVarTestBase() = default;
587*77c1e3ccSAndroid Build Coastguard Worker   ~VectorVarTestBase() override = default;
588*77c1e3ccSAndroid Build Coastguard Worker 
589*77c1e3ccSAndroid Build Coastguard Worker  protected:
590*77c1e3ccSAndroid Build Coastguard Worker   static const int kDataAlignment = 16;
591*77c1e3ccSAndroid Build Coastguard Worker 
SetUp()592*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
593*77c1e3ccSAndroid Build Coastguard Worker     width = 4 << m_bwl;
594*77c1e3ccSAndroid Build Coastguard Worker 
595*77c1e3ccSAndroid Build Coastguard Worker     ref_vector = static_cast<int16_t *>(
596*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, width * sizeof(ref_vector[0])));
597*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(ref_vector, nullptr);
598*77c1e3ccSAndroid Build Coastguard Worker     src_vector = static_cast<int16_t *>(
599*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(kDataAlignment, width * sizeof(src_vector[0])));
600*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(src_vector, nullptr);
601*77c1e3ccSAndroid Build Coastguard Worker 
602*77c1e3ccSAndroid Build Coastguard Worker     rnd_.Reset(ACMRandom::DeterministicSeed());
603*77c1e3ccSAndroid Build Coastguard Worker   }
TearDown()604*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override {
605*77c1e3ccSAndroid Build Coastguard Worker     aom_free(ref_vector);
606*77c1e3ccSAndroid Build Coastguard Worker     ref_vector = nullptr;
607*77c1e3ccSAndroid Build Coastguard Worker     aom_free(src_vector);
608*77c1e3ccSAndroid Build Coastguard Worker     src_vector = nullptr;
609*77c1e3ccSAndroid Build Coastguard Worker   }
610*77c1e3ccSAndroid Build Coastguard Worker 
FillConstant(int16_t fill_constant_ref,int16_t fill_constant_src)611*77c1e3ccSAndroid Build Coastguard Worker   void FillConstant(int16_t fill_constant_ref, int16_t fill_constant_src) {
612*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < width; ++i) {
613*77c1e3ccSAndroid Build Coastguard Worker       ref_vector[i] = fill_constant_ref;
614*77c1e3ccSAndroid Build Coastguard Worker       src_vector[i] = fill_constant_src;
615*77c1e3ccSAndroid Build Coastguard Worker     }
616*77c1e3ccSAndroid Build Coastguard Worker   }
617*77c1e3ccSAndroid Build Coastguard Worker 
FillRandom()618*77c1e3ccSAndroid Build Coastguard Worker   void FillRandom() {
619*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < width; ++i) {
620*77c1e3ccSAndroid Build Coastguard Worker       ref_vector[i] =
621*77c1e3ccSAndroid Build Coastguard Worker           rnd_.Rand16() % max_range;  // acc. aom_vector_var_c brief.
622*77c1e3ccSAndroid Build Coastguard Worker       src_vector[i] = rnd_.Rand16() % max_range;
623*77c1e3ccSAndroid Build Coastguard Worker     }
624*77c1e3ccSAndroid Build Coastguard Worker   }
625*77c1e3ccSAndroid Build Coastguard Worker 
626*77c1e3ccSAndroid Build Coastguard Worker   int width;
627*77c1e3ccSAndroid Build Coastguard Worker   int m_bwl;
628*77c1e3ccSAndroid Build Coastguard Worker   int16_t *ref_vector;
629*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_vector;
630*77c1e3ccSAndroid Build Coastguard Worker   ACMRandom rnd_;
631*77c1e3ccSAndroid Build Coastguard Worker 
632*77c1e3ccSAndroid Build Coastguard Worker   static const int max_range = 510;
633*77c1e3ccSAndroid Build Coastguard Worker   static const int num_random_cmp = 50;
634*77c1e3ccSAndroid Build Coastguard Worker };
635*77c1e3ccSAndroid Build Coastguard Worker 
636*77c1e3ccSAndroid Build Coastguard Worker typedef int (*VectorVarFunc)(const int16_t *ref, const int16_t *src,
637*77c1e3ccSAndroid Build Coastguard Worker                              const int bwl);
638*77c1e3ccSAndroid Build Coastguard Worker 
639*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<int, VectorVarFunc, VectorVarFunc> VecVarFunc;
640*77c1e3ccSAndroid Build Coastguard Worker 
641*77c1e3ccSAndroid Build Coastguard Worker class VectorVarTest : public VectorVarTestBase,
642*77c1e3ccSAndroid Build Coastguard Worker                       public ::testing::WithParamInterface<VecVarFunc> {
643*77c1e3ccSAndroid Build Coastguard Worker  public:
VectorVarTest()644*77c1e3ccSAndroid Build Coastguard Worker   VectorVarTest()
645*77c1e3ccSAndroid Build Coastguard Worker       : VectorVarTestBase(GET_PARAM(0)), c_func(GET_PARAM(1)),
646*77c1e3ccSAndroid Build Coastguard Worker         simd_func(GET_PARAM(2)) {}
647*77c1e3ccSAndroid Build Coastguard Worker 
648*77c1e3ccSAndroid Build Coastguard Worker  protected:
calcVarC()649*77c1e3ccSAndroid Build Coastguard Worker   int calcVarC() { return c_func(ref_vector, src_vector, m_bwl); }
calcVarSIMD()650*77c1e3ccSAndroid Build Coastguard Worker   int calcVarSIMD() { return simd_func(ref_vector, src_vector, m_bwl); }
651*77c1e3ccSAndroid Build Coastguard Worker 
652*77c1e3ccSAndroid Build Coastguard Worker   VectorVarFunc c_func;
653*77c1e3ccSAndroid Build Coastguard Worker   VectorVarFunc simd_func;
654*77c1e3ccSAndroid Build Coastguard Worker };
655*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VectorVarTest);
656*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(VectorVarTest,MaxVar)657*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, MaxVar) {
658*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(0, max_range);
659*77c1e3ccSAndroid Build Coastguard Worker   int c_var = calcVarC();
660*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = calcVarSIMD();
661*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(c_var, simd_var);
662*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,MaxVarRev)663*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, MaxVarRev) {
664*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(max_range, 0);
665*77c1e3ccSAndroid Build Coastguard Worker   int c_var = calcVarC();
666*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = calcVarSIMD();
667*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(c_var, simd_var);
668*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,ZeroDiff)669*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, ZeroDiff) {
670*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(0, 0);
671*77c1e3ccSAndroid Build Coastguard Worker   int c_var = calcVarC();
672*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = calcVarSIMD();
673*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(c_var, simd_var);
674*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,ZeroDiff2)675*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, ZeroDiff2) {
676*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(max_range, max_range);
677*77c1e3ccSAndroid Build Coastguard Worker   int c_var = calcVarC();
678*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = calcVarSIMD();
679*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(c_var, simd_var);
680*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,Constant)681*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, Constant) {
682*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(30, 90);
683*77c1e3ccSAndroid Build Coastguard Worker   int c_var = calcVarC();
684*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = calcVarSIMD();
685*77c1e3ccSAndroid Build Coastguard Worker   ASSERT_EQ(c_var, simd_var);
686*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,Random)687*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, Random) {
688*77c1e3ccSAndroid Build Coastguard Worker   for (size_t i = 0; i < num_random_cmp; i++) {
689*77c1e3ccSAndroid Build Coastguard Worker     FillRandom();
690*77c1e3ccSAndroid Build Coastguard Worker     int c_var = calcVarC();
691*77c1e3ccSAndroid Build Coastguard Worker     int simd_var = calcVarSIMD();
692*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_EQ(c_var, simd_var);
693*77c1e3ccSAndroid Build Coastguard Worker   }
694*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(VectorVarTest,DISABLED_Speed)695*77c1e3ccSAndroid Build Coastguard Worker TEST_P(VectorVarTest, DISABLED_Speed) {
696*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
697*77c1e3ccSAndroid Build Coastguard Worker   const int numIter = 5000000;
698*77c1e3ccSAndroid Build Coastguard Worker   printf("Width = %d number of iteration is %d \n", width, numIter);
699*77c1e3ccSAndroid Build Coastguard Worker 
700*77c1e3ccSAndroid Build Coastguard Worker   int sum_c_var = 0;
701*77c1e3ccSAndroid Build Coastguard Worker   int c_var = 0;
702*77c1e3ccSAndroid Build Coastguard Worker 
703*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer c_timer_;
704*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer_start(&c_timer_);
705*77c1e3ccSAndroid Build Coastguard Worker   for (size_t i = 0; i < numIter; i++) {
706*77c1e3ccSAndroid Build Coastguard Worker     c_var = calcVarC();
707*77c1e3ccSAndroid Build Coastguard Worker     sum_c_var += c_var;
708*77c1e3ccSAndroid Build Coastguard Worker   }
709*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer_mark(&c_timer_);
710*77c1e3ccSAndroid Build Coastguard Worker 
711*77c1e3ccSAndroid Build Coastguard Worker   int simd_var = 0;
712*77c1e3ccSAndroid Build Coastguard Worker   int sum_simd_var = 0;
713*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer simd_timer_;
714*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer_start(&simd_timer_);
715*77c1e3ccSAndroid Build Coastguard Worker   for (size_t i = 0; i < numIter; i++) {
716*77c1e3ccSAndroid Build Coastguard Worker     simd_var = calcVarSIMD();
717*77c1e3ccSAndroid Build Coastguard Worker     sum_simd_var += simd_var;
718*77c1e3ccSAndroid Build Coastguard Worker   }
719*77c1e3ccSAndroid Build Coastguard Worker   aom_usec_timer_mark(&simd_timer_);
720*77c1e3ccSAndroid Build Coastguard Worker 
721*77c1e3ccSAndroid Build Coastguard Worker   const int c_sum_time = static_cast<int>(aom_usec_timer_elapsed(&c_timer_));
722*77c1e3ccSAndroid Build Coastguard Worker   const int simd_sum_time =
723*77c1e3ccSAndroid Build Coastguard Worker       static_cast<int>(aom_usec_timer_elapsed(&simd_timer_));
724*77c1e3ccSAndroid Build Coastguard Worker 
725*77c1e3ccSAndroid Build Coastguard Worker   printf("c_time = %d \t simd_time = %d \t Gain = %4.2f \n", c_sum_time,
726*77c1e3ccSAndroid Build Coastguard Worker          simd_sum_time,
727*77c1e3ccSAndroid Build Coastguard Worker          (static_cast<float>(c_sum_time) / static_cast<float>(simd_sum_time)));
728*77c1e3ccSAndroid Build Coastguard Worker 
729*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(c_var, simd_var) << "Output mismatch \n";
730*77c1e3ccSAndroid Build Coastguard Worker   EXPECT_EQ(sum_c_var, sum_simd_var) << "Output mismatch \n";
731*77c1e3ccSAndroid Build Coastguard Worker }
732*77c1e3ccSAndroid Build Coastguard Worker 
733*77c1e3ccSAndroid Build Coastguard Worker using std::make_tuple;
734*77c1e3ccSAndroid Build Coastguard Worker 
735*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
736*77c1e3ccSAndroid Build Coastguard Worker     C, AverageTest8bpp,
737*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 1, 8, &aom_avg_8x8_c),
738*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 1, 4, &aom_avg_4x4_c)));
739*77c1e3ccSAndroid Build Coastguard Worker 
740*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
741*77c1e3ccSAndroid Build Coastguard Worker     C, AvgTest8bpp_avg_8x8_quad,
742*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 16, &aom_avg_8x8_quad_c),
743*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 16, 16, &aom_avg_8x8_quad_c),
744*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 8, 16, &aom_avg_8x8_quad_c)));
745*77c1e3ccSAndroid Build Coastguard Worker 
746*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
747*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
748*77c1e3ccSAndroid Build Coastguard Worker     SSE2, AverageTest8bpp,
749*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 8, &aom_avg_8x8_sse2),
750*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 5, 8, &aom_avg_8x8_sse2),
751*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 15, 8, &aom_avg_8x8_sse2),
752*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 0, 4, &aom_avg_4x4_sse2),
753*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 5, 4, &aom_avg_4x4_sse2),
754*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 15, 4, &aom_avg_4x4_sse2)));
755*77c1e3ccSAndroid Build Coastguard Worker 
756*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
757*77c1e3ccSAndroid Build Coastguard Worker     SSE2, AvgTest8bpp_avg_8x8_quad,
758*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 16, &aom_avg_8x8_quad_sse2),
759*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 16, 16, &aom_avg_8x8_quad_sse2),
760*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 8, 16, &aom_avg_8x8_quad_sse2)));
761*77c1e3ccSAndroid Build Coastguard Worker 
762*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
763*77c1e3ccSAndroid Build Coastguard Worker     SSE2, IntProRowTest,
764*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
765*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_row_sse2, &aom_int_pro_row_c),
766*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_row_sse2, &aom_int_pro_row_c),
767*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_row_sse2, &aom_int_pro_row_c),
768*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_row_sse2, &aom_int_pro_row_c)));
769*77c1e3ccSAndroid Build Coastguard Worker 
770*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
771*77c1e3ccSAndroid Build Coastguard Worker     SSE2, IntProColTest,
772*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
773*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_col_sse2, &aom_int_pro_col_c),
774*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_col_sse2, &aom_int_pro_col_c),
775*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_col_sse2, &aom_int_pro_col_c),
776*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_col_sse2, &aom_int_pro_col_c)));
777*77c1e3ccSAndroid Build Coastguard Worker #endif
778*77c1e3ccSAndroid Build Coastguard Worker 
779*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
780*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
781*77c1e3ccSAndroid Build Coastguard Worker     AVX2, AvgTest8bpp_avg_8x8_quad,
782*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 16, &aom_avg_8x8_quad_avx2),
783*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 16, 16, &aom_avg_8x8_quad_avx2),
784*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 8, 16, &aom_avg_8x8_quad_avx2)));
785*77c1e3ccSAndroid Build Coastguard Worker 
786*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
787*77c1e3ccSAndroid Build Coastguard Worker     AVX2, IntProRowTest,
788*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
789*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_row_avx2, &aom_int_pro_row_c),
790*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_row_avx2, &aom_int_pro_row_c),
791*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_row_avx2, &aom_int_pro_row_c),
792*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_row_avx2, &aom_int_pro_row_c)));
793*77c1e3ccSAndroid Build Coastguard Worker 
794*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
795*77c1e3ccSAndroid Build Coastguard Worker     AVX2, IntProColTest,
796*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
797*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_col_avx2, &aom_int_pro_col_c),
798*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_col_avx2, &aom_int_pro_col_c),
799*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_col_avx2, &aom_int_pro_col_c),
800*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_col_avx2, &aom_int_pro_col_c)));
801*77c1e3ccSAndroid Build Coastguard Worker #endif
802*77c1e3ccSAndroid Build Coastguard Worker 
803*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
804*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
805*77c1e3ccSAndroid Build Coastguard Worker     NEON, AverageTest8bpp,
806*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 8, &aom_avg_8x8_neon),
807*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 5, 8, &aom_avg_8x8_neon),
808*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 15, 8, &aom_avg_8x8_neon),
809*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 0, 4, &aom_avg_4x4_neon),
810*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 8, 5, 4, &aom_avg_4x4_neon),
811*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 15, 4, &aom_avg_4x4_neon)));
812*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
813*77c1e3ccSAndroid Build Coastguard Worker     NEON, IntProRowTest,
814*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
815*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_row_neon, &aom_int_pro_row_c),
816*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_row_neon, &aom_int_pro_row_c),
817*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_row_neon, &aom_int_pro_row_c),
818*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_row_neon, &aom_int_pro_row_c)));
819*77c1e3ccSAndroid Build Coastguard Worker 
820*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
821*77c1e3ccSAndroid Build Coastguard Worker     NEON, IntProColTest,
822*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
823*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(16, 16, &aom_int_pro_col_neon, &aom_int_pro_col_c),
824*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(32, 32, &aom_int_pro_col_neon, &aom_int_pro_col_c),
825*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(64, 64, &aom_int_pro_col_neon, &aom_int_pro_col_c),
826*77c1e3ccSAndroid Build Coastguard Worker         make_tuple(128, 128, &aom_int_pro_col_neon, &aom_int_pro_col_c)));
827*77c1e3ccSAndroid Build Coastguard Worker 
828*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
829*77c1e3ccSAndroid Build Coastguard Worker     NEON, AvgTest8bpp_avg_8x8_quad,
830*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 8, 0, 16, &aom_avg_8x8_quad_neon),
831*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 16, 16, &aom_avg_8x8_quad_neon),
832*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 8, 8, 16, &aom_avg_8x8_quad_neon)));
833*77c1e3ccSAndroid Build Coastguard Worker #endif
834*77c1e3ccSAndroid Build Coastguard Worker 
835*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
836*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
837*77c1e3ccSAndroid Build Coastguard Worker     C, AverageTestHbd,
838*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 10, 1, 8, &aom_highbd_avg_8x8_c),
839*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 10, 1, 4, &aom_highbd_avg_4x4_c),
840*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 1, 8, &aom_highbd_avg_8x8_c),
841*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 1, 4, &aom_highbd_avg_4x4_c)));
842*77c1e3ccSAndroid Build Coastguard Worker 
843*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
844*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
845*77c1e3ccSAndroid Build Coastguard Worker     NEON, AverageTestHbd,
846*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(16, 16, 10, 0, 4, &aom_highbd_avg_4x4_neon),
847*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 10, 5, 4, &aom_highbd_avg_4x4_neon),
848*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 10, 15, 4, &aom_highbd_avg_4x4_neon),
849*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 0, 4, &aom_highbd_avg_4x4_neon),
850*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 5, 4, &aom_highbd_avg_4x4_neon),
851*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 12, 15, 4, &aom_highbd_avg_4x4_neon),
852*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 10, 0, 8, &aom_highbd_avg_8x8_neon),
853*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 10, 5, 8, &aom_highbd_avg_8x8_neon),
854*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 10, 15, 8, &aom_highbd_avg_8x8_neon),
855*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 0, 8, &aom_highbd_avg_8x8_neon),
856*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(16, 16, 12, 5, 8, &aom_highbd_avg_8x8_neon),
857*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(32, 32, 12, 15, 8, &aom_highbd_avg_8x8_neon)));
858*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_NEON
859*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
860*77c1e3ccSAndroid Build Coastguard Worker 
861*77c1e3ccSAndroid Build Coastguard Worker typedef int (*SatdFunc)(const tran_low_t *coeffs, int length);
862*77c1e3ccSAndroid Build Coastguard Worker typedef int (*SatdLpFunc)(const int16_t *coeffs, int length);
863*77c1e3ccSAndroid Build Coastguard Worker 
864*77c1e3ccSAndroid Build Coastguard Worker template <typename SatdFuncType>
865*77c1e3ccSAndroid Build Coastguard Worker struct SatdTestParam {
SatdTestParam__anon9f9f480a0111::SatdTestParam866*77c1e3ccSAndroid Build Coastguard Worker   SatdTestParam(int s, SatdFuncType f1, SatdFuncType f2)
867*77c1e3ccSAndroid Build Coastguard Worker       : satd_size(s), func_ref(f1), func_simd(f2) {}
operator <<(std::ostream & os,const SatdTestParam<SatdFuncType> & param)868*77c1e3ccSAndroid Build Coastguard Worker   friend std::ostream &operator<<(std::ostream &os,
869*77c1e3ccSAndroid Build Coastguard Worker                                   const SatdTestParam<SatdFuncType> &param) {
870*77c1e3ccSAndroid Build Coastguard Worker     return os << "satd_size: " << param.satd_size;
871*77c1e3ccSAndroid Build Coastguard Worker   }
872*77c1e3ccSAndroid Build Coastguard Worker   int satd_size;
873*77c1e3ccSAndroid Build Coastguard Worker   SatdFuncType func_ref;
874*77c1e3ccSAndroid Build Coastguard Worker   SatdFuncType func_simd;
875*77c1e3ccSAndroid Build Coastguard Worker };
876*77c1e3ccSAndroid Build Coastguard Worker 
877*77c1e3ccSAndroid Build Coastguard Worker template <typename CoeffType, typename SatdFuncType>
878*77c1e3ccSAndroid Build Coastguard Worker class SatdTestBase
879*77c1e3ccSAndroid Build Coastguard Worker     : public ::testing::Test,
880*77c1e3ccSAndroid Build Coastguard Worker       public ::testing::WithParamInterface<SatdTestParam<SatdFuncType>> {
881*77c1e3ccSAndroid Build Coastguard Worker  protected:
SatdTestBase(const SatdTestParam<SatdFuncType> & func_param)882*77c1e3ccSAndroid Build Coastguard Worker   explicit SatdTestBase(const SatdTestParam<SatdFuncType> &func_param) {
883*77c1e3ccSAndroid Build Coastguard Worker     satd_size_ = func_param.satd_size;
884*77c1e3ccSAndroid Build Coastguard Worker     satd_func_ref_ = func_param.func_ref;
885*77c1e3ccSAndroid Build Coastguard Worker     satd_func_simd_ = func_param.func_simd;
886*77c1e3ccSAndroid Build Coastguard Worker   }
SetUp()887*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
888*77c1e3ccSAndroid Build Coastguard Worker     rnd_.Reset(ACMRandom::DeterministicSeed());
889*77c1e3ccSAndroid Build Coastguard Worker     src_ = reinterpret_cast<CoeffType *>(
890*77c1e3ccSAndroid Build Coastguard Worker         aom_memalign(32, sizeof(*src_) * satd_size_));
891*77c1e3ccSAndroid Build Coastguard Worker     ASSERT_NE(src_, nullptr);
892*77c1e3ccSAndroid Build Coastguard Worker   }
TearDown()893*77c1e3ccSAndroid Build Coastguard Worker   void TearDown() override { aom_free(src_); }
FillConstant(const CoeffType val)894*77c1e3ccSAndroid Build Coastguard Worker   void FillConstant(const CoeffType val) {
895*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < satd_size_; ++i) src_[i] = val;
896*77c1e3ccSAndroid Build Coastguard Worker   }
FillRandom()897*77c1e3ccSAndroid Build Coastguard Worker   void FillRandom() {
898*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < satd_size_; ++i) {
899*77c1e3ccSAndroid Build Coastguard Worker       src_[i] = static_cast<int16_t>(rnd_.Rand16());
900*77c1e3ccSAndroid Build Coastguard Worker     }
901*77c1e3ccSAndroid Build Coastguard Worker   }
Check(int expected)902*77c1e3ccSAndroid Build Coastguard Worker   void Check(int expected) {
903*77c1e3ccSAndroid Build Coastguard Worker     int total_ref;
904*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(total_ref = satd_func_ref_(src_, satd_size_));
905*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(expected, total_ref);
906*77c1e3ccSAndroid Build Coastguard Worker 
907*77c1e3ccSAndroid Build Coastguard Worker     int total_simd;
908*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(total_simd = satd_func_simd_(src_, satd_size_));
909*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(expected, total_simd);
910*77c1e3ccSAndroid Build Coastguard Worker   }
RunComparison()911*77c1e3ccSAndroid Build Coastguard Worker   void RunComparison() {
912*77c1e3ccSAndroid Build Coastguard Worker     int total_ref;
913*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(total_ref = satd_func_ref_(src_, satd_size_));
914*77c1e3ccSAndroid Build Coastguard Worker 
915*77c1e3ccSAndroid Build Coastguard Worker     int total_simd;
916*77c1e3ccSAndroid Build Coastguard Worker     API_REGISTER_STATE_CHECK(total_simd = satd_func_simd_(src_, satd_size_));
917*77c1e3ccSAndroid Build Coastguard Worker 
918*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(total_ref, total_simd);
919*77c1e3ccSAndroid Build Coastguard Worker   }
RunSpeedTest()920*77c1e3ccSAndroid Build Coastguard Worker   void RunSpeedTest() {
921*77c1e3ccSAndroid Build Coastguard Worker     const int numIter = 500000;
922*77c1e3ccSAndroid Build Coastguard Worker     printf("size = %d number of iteration is %d \n", satd_size_, numIter);
923*77c1e3ccSAndroid Build Coastguard Worker 
924*77c1e3ccSAndroid Build Coastguard Worker     int total_ref;
925*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer c_timer_;
926*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&c_timer_);
927*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
928*77c1e3ccSAndroid Build Coastguard Worker       total_ref = satd_func_ref_(src_, satd_size_);
929*77c1e3ccSAndroid Build Coastguard Worker     }
930*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&c_timer_);
931*77c1e3ccSAndroid Build Coastguard Worker 
932*77c1e3ccSAndroid Build Coastguard Worker     int total_simd;
933*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer simd_timer_;
934*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&simd_timer_);
935*77c1e3ccSAndroid Build Coastguard Worker 
936*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < numIter; i++) {
937*77c1e3ccSAndroid Build Coastguard Worker       total_simd = satd_func_simd_(src_, satd_size_);
938*77c1e3ccSAndroid Build Coastguard Worker     }
939*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&simd_timer_);
940*77c1e3ccSAndroid Build Coastguard Worker 
941*77c1e3ccSAndroid Build Coastguard Worker     const int c_sum_time = static_cast<int>(aom_usec_timer_elapsed(&c_timer_));
942*77c1e3ccSAndroid Build Coastguard Worker     const int simd_sum_time =
943*77c1e3ccSAndroid Build Coastguard Worker         static_cast<int>(aom_usec_timer_elapsed(&simd_timer_));
944*77c1e3ccSAndroid Build Coastguard Worker 
945*77c1e3ccSAndroid Build Coastguard Worker     printf(
946*77c1e3ccSAndroid Build Coastguard Worker         "c_time = %d \t simd_time = %d \t Gain = %4.2f \n", c_sum_time,
947*77c1e3ccSAndroid Build Coastguard Worker         simd_sum_time,
948*77c1e3ccSAndroid Build Coastguard Worker         (static_cast<float>(c_sum_time) / static_cast<float>(simd_sum_time)));
949*77c1e3ccSAndroid Build Coastguard Worker 
950*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_EQ(total_ref, total_simd) << "Output mismatch \n";
951*77c1e3ccSAndroid Build Coastguard Worker   }
952*77c1e3ccSAndroid Build Coastguard Worker   int satd_size_;
953*77c1e3ccSAndroid Build Coastguard Worker 
954*77c1e3ccSAndroid Build Coastguard Worker  private:
955*77c1e3ccSAndroid Build Coastguard Worker   CoeffType *src_;
956*77c1e3ccSAndroid Build Coastguard Worker   SatdFuncType satd_func_ref_;
957*77c1e3ccSAndroid Build Coastguard Worker   SatdFuncType satd_func_simd_;
958*77c1e3ccSAndroid Build Coastguard Worker   ACMRandom rnd_;
959*77c1e3ccSAndroid Build Coastguard Worker };
960*77c1e3ccSAndroid Build Coastguard Worker 
961*77c1e3ccSAndroid Build Coastguard Worker class SatdTest : public SatdTestBase<tran_low_t, SatdFunc> {
962*77c1e3ccSAndroid Build Coastguard Worker  public:
SatdTest()963*77c1e3ccSAndroid Build Coastguard Worker   SatdTest() : SatdTestBase(GetParam()) {}
964*77c1e3ccSAndroid Build Coastguard Worker };
965*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(SatdTest,MinValue)966*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdTest, MinValue) {
967*77c1e3ccSAndroid Build Coastguard Worker   const int kMin = -524287;
968*77c1e3ccSAndroid Build Coastguard Worker   const int expected = -kMin * satd_size_;
969*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(kMin);
970*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
971*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdTest,MaxValue)972*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdTest, MaxValue) {
973*77c1e3ccSAndroid Build Coastguard Worker   const int kMax = 524287;
974*77c1e3ccSAndroid Build Coastguard Worker   const int expected = kMax * satd_size_;
975*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(kMax);
976*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
977*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdTest,Random)978*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdTest, Random) {
979*77c1e3ccSAndroid Build Coastguard Worker   int expected;
980*77c1e3ccSAndroid Build Coastguard Worker   switch (satd_size_) {
981*77c1e3ccSAndroid Build Coastguard Worker     case 16: expected = 205298; break;
982*77c1e3ccSAndroid Build Coastguard Worker     case 64: expected = 1113950; break;
983*77c1e3ccSAndroid Build Coastguard Worker     case 256: expected = 4268415; break;
984*77c1e3ccSAndroid Build Coastguard Worker     case 1024: expected = 16954082; break;
985*77c1e3ccSAndroid Build Coastguard Worker     default:
986*77c1e3ccSAndroid Build Coastguard Worker       FAIL() << "Invalid satd size (" << satd_size_
987*77c1e3ccSAndroid Build Coastguard Worker              << ") valid: 16/64/256/1024";
988*77c1e3ccSAndroid Build Coastguard Worker   }
989*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
990*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
991*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdTest,Match)992*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdTest, Match) {
993*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
994*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
995*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdTest,DISABLED_Speed)996*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdTest, DISABLED_Speed) {
997*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
998*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest();
999*77c1e3ccSAndroid Build Coastguard Worker }
1000*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SatdTest);
1001*77c1e3ccSAndroid Build Coastguard Worker 
1002*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1003*77c1e3ccSAndroid Build Coastguard Worker     C, SatdTest,
1004*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(SatdTestParam<SatdFunc>(16, &aom_satd_c, &aom_satd_c),
1005*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(64, &aom_satd_c, &aom_satd_c),
1006*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(256, &aom_satd_c, &aom_satd_c),
1007*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(1024, &aom_satd_c, &aom_satd_c)));
1008*77c1e3ccSAndroid Build Coastguard Worker 
1009*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
1010*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1011*77c1e3ccSAndroid Build Coastguard Worker     NEON, SatdTest,
1012*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(SatdTestParam<SatdFunc>(16, &aom_satd_c, &aom_satd_neon),
1013*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(64, &aom_satd_c, &aom_satd_neon),
1014*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(256, &aom_satd_c, &aom_satd_neon),
1015*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(1024, &aom_satd_c,
1016*77c1e3ccSAndroid Build Coastguard Worker                                               &aom_satd_neon)));
1017*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1018*77c1e3ccSAndroid Build Coastguard Worker     NEON, VectorVarTest,
1019*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(2, &aom_vector_var_c, &aom_vector_var_neon),
1020*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(3, &aom_vector_var_c, &aom_vector_var_neon),
1021*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(4, &aom_vector_var_c, &aom_vector_var_neon),
1022*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(5, &aom_vector_var_c, &aom_vector_var_neon)));
1023*77c1e3ccSAndroid Build Coastguard Worker #endif
1024*77c1e3ccSAndroid Build Coastguard Worker 
1025*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SVE
1026*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1027*77c1e3ccSAndroid Build Coastguard Worker     SVE, VectorVarTest,
1028*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(2, &aom_vector_var_c, &aom_vector_var_sve),
1029*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(3, &aom_vector_var_c, &aom_vector_var_sve),
1030*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(4, &aom_vector_var_c, &aom_vector_var_sve),
1031*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(5, &aom_vector_var_c, &aom_vector_var_sve)));
1032*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SVE
1033*77c1e3ccSAndroid Build Coastguard Worker 
1034*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE4_1
1035*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1036*77c1e3ccSAndroid Build Coastguard Worker     SSE4_1, VectorVarTest,
1037*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(2, &aom_vector_var_c, &aom_vector_var_sse4_1),
1038*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(3, &aom_vector_var_c, &aom_vector_var_sse4_1),
1039*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(4, &aom_vector_var_c, &aom_vector_var_sse4_1),
1040*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(5, &aom_vector_var_c,
1041*77c1e3ccSAndroid Build Coastguard Worker                                  &aom_vector_var_sse4_1)));
1042*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SSE4_1
1043*77c1e3ccSAndroid Build Coastguard Worker 
1044*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
1045*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1046*77c1e3ccSAndroid Build Coastguard Worker     AVX2, SatdTest,
1047*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(SatdTestParam<SatdFunc>(16, &aom_satd_c, &aom_satd_avx2),
1048*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(64, &aom_satd_c, &aom_satd_avx2),
1049*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(256, &aom_satd_c, &aom_satd_avx2),
1050*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(1024, &aom_satd_c,
1051*77c1e3ccSAndroid Build Coastguard Worker                                               &aom_satd_avx2)));
1052*77c1e3ccSAndroid Build Coastguard Worker 
1053*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1054*77c1e3ccSAndroid Build Coastguard Worker     AVX2, VectorVarTest,
1055*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(make_tuple(2, &aom_vector_var_c, &aom_vector_var_avx2),
1056*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(3, &aom_vector_var_c, &aom_vector_var_avx2),
1057*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(4, &aom_vector_var_c, &aom_vector_var_avx2),
1058*77c1e3ccSAndroid Build Coastguard Worker                       make_tuple(5, &aom_vector_var_c, &aom_vector_var_avx2)));
1059*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_AVX2
1060*77c1e3ccSAndroid Build Coastguard Worker 
1061*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
1062*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1063*77c1e3ccSAndroid Build Coastguard Worker     SSE2, SatdTest,
1064*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(SatdTestParam<SatdFunc>(16, &aom_satd_c, &aom_satd_sse2),
1065*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(64, &aom_satd_c, &aom_satd_sse2),
1066*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(256, &aom_satd_c, &aom_satd_sse2),
1067*77c1e3ccSAndroid Build Coastguard Worker                       SatdTestParam<SatdFunc>(1024, &aom_satd_c,
1068*77c1e3ccSAndroid Build Coastguard Worker                                               &aom_satd_sse2)));
1069*77c1e3ccSAndroid Build Coastguard Worker #endif
1070*77c1e3ccSAndroid Build Coastguard Worker 
1071*77c1e3ccSAndroid Build Coastguard Worker class SatdLpTest : public SatdTestBase<int16_t, SatdLpFunc> {
1072*77c1e3ccSAndroid Build Coastguard Worker  public:
SatdLpTest()1073*77c1e3ccSAndroid Build Coastguard Worker   SatdLpTest() : SatdTestBase(GetParam()) {}
1074*77c1e3ccSAndroid Build Coastguard Worker };
1075*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(SatdLpTest,MinValue)1076*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdLpTest, MinValue) {
1077*77c1e3ccSAndroid Build Coastguard Worker   const int kMin = -32640;
1078*77c1e3ccSAndroid Build Coastguard Worker   const int expected = -kMin * satd_size_;
1079*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(kMin);
1080*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
1081*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdLpTest,MaxValue)1082*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdLpTest, MaxValue) {
1083*77c1e3ccSAndroid Build Coastguard Worker   const int kMax = 32640;
1084*77c1e3ccSAndroid Build Coastguard Worker   const int expected = kMax * satd_size_;
1085*77c1e3ccSAndroid Build Coastguard Worker   FillConstant(kMax);
1086*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
1087*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdLpTest,Random)1088*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdLpTest, Random) {
1089*77c1e3ccSAndroid Build Coastguard Worker   int expected;
1090*77c1e3ccSAndroid Build Coastguard Worker   switch (satd_size_) {
1091*77c1e3ccSAndroid Build Coastguard Worker     case 16: expected = 205298; break;
1092*77c1e3ccSAndroid Build Coastguard Worker     case 64: expected = 1113950; break;
1093*77c1e3ccSAndroid Build Coastguard Worker     case 256: expected = 4268415; break;
1094*77c1e3ccSAndroid Build Coastguard Worker     case 1024: expected = 16954082; break;
1095*77c1e3ccSAndroid Build Coastguard Worker     default:
1096*77c1e3ccSAndroid Build Coastguard Worker       FAIL() << "Invalid satd size (" << satd_size_
1097*77c1e3ccSAndroid Build Coastguard Worker              << ") valid: 16/64/256/1024";
1098*77c1e3ccSAndroid Build Coastguard Worker   }
1099*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
1100*77c1e3ccSAndroid Build Coastguard Worker   Check(expected);
1101*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdLpTest,Match)1102*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdLpTest, Match) {
1103*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
1104*77c1e3ccSAndroid Build Coastguard Worker   RunComparison();
1105*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(SatdLpTest,DISABLED_Speed)1106*77c1e3ccSAndroid Build Coastguard Worker TEST_P(SatdLpTest, DISABLED_Speed) {
1107*77c1e3ccSAndroid Build Coastguard Worker   FillRandom();
1108*77c1e3ccSAndroid Build Coastguard Worker   RunSpeedTest();
1109*77c1e3ccSAndroid Build Coastguard Worker }
1110*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SatdLpTest);
1111*77c1e3ccSAndroid Build Coastguard Worker 
1112*77c1e3ccSAndroid Build Coastguard Worker // Add the following c test to avoid gtest uninitialized warning.
1113*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1114*77c1e3ccSAndroid Build Coastguard Worker     C, SatdLpTest,
1115*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
1116*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(16, &aom_satd_lp_c, &aom_satd_lp_c),
1117*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(64, &aom_satd_lp_c, &aom_satd_lp_c),
1118*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(256, &aom_satd_lp_c, &aom_satd_lp_c),
1119*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(1024, &aom_satd_lp_c, &aom_satd_lp_c)));
1120*77c1e3ccSAndroid Build Coastguard Worker 
1121*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
1122*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1123*77c1e3ccSAndroid Build Coastguard Worker     NEON, SatdLpTest,
1124*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
1125*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(16, &aom_satd_lp_c, &aom_satd_lp_neon),
1126*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(64, &aom_satd_lp_c, &aom_satd_lp_neon),
1127*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(256, &aom_satd_lp_c, &aom_satd_lp_neon),
1128*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(1024, &aom_satd_lp_c, &aom_satd_lp_neon)));
1129*77c1e3ccSAndroid Build Coastguard Worker #endif
1130*77c1e3ccSAndroid Build Coastguard Worker 
1131*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
1132*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1133*77c1e3ccSAndroid Build Coastguard Worker     AVX2, SatdLpTest,
1134*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
1135*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(16, &aom_satd_lp_c, &aom_satd_lp_avx2),
1136*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(64, &aom_satd_lp_c, &aom_satd_lp_avx2),
1137*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(256, &aom_satd_lp_c, &aom_satd_lp_avx2),
1138*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(1024, &aom_satd_lp_c, &aom_satd_lp_avx2)));
1139*77c1e3ccSAndroid Build Coastguard Worker #endif
1140*77c1e3ccSAndroid Build Coastguard Worker 
1141*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE2
1142*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(
1143*77c1e3ccSAndroid Build Coastguard Worker     SSE2, SatdLpTest,
1144*77c1e3ccSAndroid Build Coastguard Worker     ::testing::Values(
1145*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(16, &aom_satd_lp_c, &aom_satd_lp_sse2),
1146*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(64, &aom_satd_lp_c, &aom_satd_lp_sse2),
1147*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(256, &aom_satd_lp_c, &aom_satd_lp_sse2),
1148*77c1e3ccSAndroid Build Coastguard Worker         SatdTestParam<SatdLpFunc>(1024, &aom_satd_lp_c, &aom_satd_lp_sse2)));
1149*77c1e3ccSAndroid Build Coastguard Worker #endif
1150*77c1e3ccSAndroid Build Coastguard Worker 
1151*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
1152