variance_test.cc 58.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
 *
4
5
6
7
8
9
10
11
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/

12
13
#include <cstdlib>
#include <new>
14

15
#include "third_party/googletest/src/include/gtest/gtest.h"
16

Adrian Grange's avatar
Adrian Grange committed
17
18
#include "./aom_config.h"
#include "./aom_dsp_rtcd.h"
19
20
21
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
Adrian Grange's avatar
Adrian Grange committed
22
23
24
#include "aom/aom_codec.h"
#include "aom/aom_integer.h"
#include "aom_mem/aom_mem.h"
Yaowu Xu's avatar
Yaowu Xu committed
25
#include "aom_ports/mem.h"
26
27
28

namespace {

Johann's avatar
Johann committed
29
30
31
typedef unsigned int (*VarianceMxNFunc)(const uint8_t *a, int a_stride,
                                        const uint8_t *b, int b_stride,
                                        unsigned int *sse);
Johann's avatar
Johann committed
32
33
34
35
typedef unsigned int (*SubpixVarMxNFunc)(const uint8_t *a, int a_stride,
                                         int xoffset, int yoffset,
                                         const uint8_t *b, int b_stride,
                                         unsigned int *sse);
Johann's avatar
Johann committed
36
37
38
39
40
typedef unsigned int (*SubpixAvgVarMxNFunc)(const uint8_t *a, int a_stride,
                                            int xoffset, int yoffset,
                                            const uint8_t *b, int b_stride,
                                            uint32_t *sse,
                                            const uint8_t *second_pred);
Johann's avatar
Johann committed
41
typedef unsigned int (*Get4x4SseFunc)(const uint8_t *a, int a_stride,
Johann's avatar
Johann committed
42
                                      const uint8_t *b, int b_stride);
Johann's avatar
Johann committed
43
44
typedef unsigned int (*SumOfSquaresFunction)(const int16_t *src);

45
46
47
using ::std::tr1::get;
using ::std::tr1::make_tuple;
using ::std::tr1::tuple;
Yaowu Xu's avatar
Yaowu Xu committed
48
using libaom_test::ACMRandom;
49

50
51
52
53
54
// Truncate high bit depth results by downshifting (with rounding) by:
// 2 * (bit_depth - 8) for sse
// (bit_depth - 8) for se
static void RoundHighBitDepth(int bit_depth, int64_t *se, uint64_t *sse) {
  switch (bit_depth) {
Adrian Grange's avatar
Adrian Grange committed
55
    case AOM_BITS_12:
56
      *sse = (*sse + 128) >> 8;
57
      *se = (*se + 8) >> 4;
58
      break;
Adrian Grange's avatar
Adrian Grange committed
59
    case AOM_BITS_10:
60
      *sse = (*sse + 8) >> 4;
61
      *se = (*se + 2) >> 2;
62
      break;
Adrian Grange's avatar
Adrian Grange committed
63
    case AOM_BITS_8:
clang-format's avatar
clang-format committed
64
    default: break;
65
66
67
  }
}

68
69
70
71
72
73
74
75
static unsigned int mb_ss_ref(const int16_t *src) {
  unsigned int res = 0;
  for (int i = 0; i < 256; ++i) {
    res += src[i] * src[i];
  }
  return res;
}

clang-format's avatar
clang-format committed
76
77
static uint32_t variance_ref(const uint8_t *src, const uint8_t *ref, int l2w,
                             int l2h, int src_stride_coeff,
Johann's avatar
Johann committed
78
79
                             int ref_stride_coeff, uint32_t *sse_ptr,
                             bool use_high_bit_depth_,
Adrian Grange's avatar
Adrian Grange committed
80
                             aom_bit_depth_t bit_depth) {
81
82
83
84
85
86
87
88
89
90
91
92
  int64_t se = 0;
  uint64_t sse = 0;
  const int w = 1 << l2w;
  const int h = 1 << l2h;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      int diff;
      if (!use_high_bit_depth_) {
        diff = ref[w * y * ref_stride_coeff + x] -
               src[w * y * src_stride_coeff + x];
        se += diff;
        sse += diff * diff;
93
#if CONFIG_AOM_HIGHBITDEPTH
94
95
96
97
98
      } else {
        diff = CONVERT_TO_SHORTPTR(ref)[w * y * ref_stride_coeff + x] -
               CONVERT_TO_SHORTPTR(src)[w * y * src_stride_coeff + x];
        se += diff;
        sse += diff * diff;
99
#endif  // CONFIG_AOM_HIGHBITDEPTH
100
101
102
      }
    }
  }
103
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
104
  *sse_ptr = static_cast<uint32_t>(sse);
Urvang Joshi's avatar
Urvang Joshi committed
105
  return static_cast<uint32_t>(sse - ((se * se) >> (l2w + l2h)));
106
107
}

Johann's avatar
Johann committed
108
109
110
111
/* The subpel reference functions differ from the codec version in one aspect:
 * they calculate the bilinear factors directly instead of using a lookup table
 * and therefore upshift xoff and yoff by 1. Only every other calculated value
 * is used so the codec version shrinks the table to save space and maintain
Adrian Grange's avatar
Adrian Grange committed
112
 * compatibility with aom.
Johann's avatar
Johann committed
113
 */
Johann's avatar
Johann committed
114
115
static uint32_t subpel_variance_ref(const uint8_t *ref, const uint8_t *src,
                                    int l2w, int l2h, int xoff, int yoff,
clang-format's avatar
clang-format committed
116
                                    uint32_t *sse_ptr, bool use_high_bit_depth_,
Adrian Grange's avatar
Adrian Grange committed
117
                                    aom_bit_depth_t bit_depth) {
118
119
120
121
  int64_t se = 0;
  uint64_t sse = 0;
  const int w = 1 << l2w;
  const int h = 1 << l2h;
Johann's avatar
Johann committed
122
123
124
125

  xoff <<= 1;
  yoff <<= 1;

126
127
128
129
130
131
132
133
134
135
136
137
138
139
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      // Bilinear interpolation at a 16th pel step.
      if (!use_high_bit_depth_) {
        const int a1 = ref[(w + 1) * (y + 0) + x + 0];
        const int a2 = ref[(w + 1) * (y + 0) + x + 1];
        const int b1 = ref[(w + 1) * (y + 1) + x + 0];
        const int b2 = ref[(w + 1) * (y + 1) + x + 1];
        const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
        const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
        const int r = a + (((b - a) * yoff + 8) >> 4);
        const int diff = r - src[w * y + x];
        se += diff;
        sse += diff * diff;
140
#if CONFIG_AOM_HIGHBITDEPTH
141
142
143
144
145
146
147
148
149
150
151
152
153
      } else {
        uint16_t *ref16 = CONVERT_TO_SHORTPTR(ref);
        uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
        const int a1 = ref16[(w + 1) * (y + 0) + x + 0];
        const int a2 = ref16[(w + 1) * (y + 0) + x + 1];
        const int b1 = ref16[(w + 1) * (y + 1) + x + 0];
        const int b2 = ref16[(w + 1) * (y + 1) + x + 1];
        const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
        const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
        const int r = a + (((b - a) * yoff + 8) >> 4);
        const int diff = r - src16[w * y + x];
        se += diff;
        sse += diff * diff;
154
#endif  // CONFIG_AOM_HIGHBITDEPTH
155
156
157
      }
    }
  }
158
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
159
  *sse_ptr = static_cast<uint32_t>(sse);
Urvang Joshi's avatar
Urvang Joshi committed
160
  return static_cast<uint32_t>(sse - ((se * se) >> (l2w + l2h)));
161
}
162

163
164
165
166
class SumOfSquaresTest : public ::testing::TestWithParam<SumOfSquaresFunction> {
 public:
  SumOfSquaresTest() : func_(GetParam()) {}

Yaowu Xu's avatar
Yaowu Xu committed
167
  virtual ~SumOfSquaresTest() { libaom_test::ClearSystemState(); }
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

 protected:
  void ConstTest();
  void RefTest();

  SumOfSquaresFunction func_;
  ACMRandom rnd_;
};

void SumOfSquaresTest::ConstTest() {
  int16_t mem[256];
  unsigned int res;
  for (int v = 0; v < 256; ++v) {
    for (int i = 0; i < 256; ++i) {
      mem[i] = v;
    }
    ASM_REGISTER_STATE_CHECK(res = func_(mem));
    EXPECT_EQ(256u * (v * v), res);
  }
}

void SumOfSquaresTest::RefTest() {
  int16_t mem[256];
  for (int i = 0; i < 100; ++i) {
    for (int j = 0; j < 256; ++j) {
      mem[j] = rnd_.Rand8() - rnd_.Rand8();
    }

    const unsigned int expected = mb_ss_ref(mem);
    unsigned int res;
    ASM_REGISTER_STATE_CHECK(res = func_(mem));
    EXPECT_EQ(expected, res);
  }
}

clang-format's avatar
clang-format committed
203
204
205
template <typename VarianceFunctionType>
class VarianceTest : public ::testing::TestWithParam<
                         tuple<int, int, VarianceFunctionType, int> > {
206
207
 public:
  virtual void SetUp() {
clang-format's avatar
clang-format committed
208
209
    const tuple<int, int, VarianceFunctionType, int> &params = this->GetParam();
    log2width_ = get<0>(params);
210
211
212
    width_ = 1 << log2width_;
    log2height_ = get<1>(params);
    height_ = 1 << log2height_;
213
    variance_ = get<2>(params);
214
    if (get<3>(params)) {
Adrian Grange's avatar
Adrian Grange committed
215
      bit_depth_ = static_cast<aom_bit_depth_t>(get<3>(params));
216
217
      use_high_bit_depth_ = true;
    } else {
Adrian Grange's avatar
Adrian Grange committed
218
      bit_depth_ = AOM_BITS_8;
219
220
221
      use_high_bit_depth_ = false;
    }
    mask_ = (1 << bit_depth_) - 1;
222

223
    rnd_.Reset(ACMRandom::DeterministicSeed());
224
    block_size_ = width_ * height_;
225
    if (!use_high_bit_depth_) {
Adrian Grange's avatar
Adrian Grange committed
226
      src_ = reinterpret_cast<uint8_t *>(aom_memalign(16, block_size_ * 2));
227
      ref_ = new uint8_t[block_size_ * 2];
228
#if CONFIG_AOM_HIGHBITDEPTH
229
230
    } else {
      src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Adrian Grange's avatar
Adrian Grange committed
231
          aom_memalign(16, block_size_ * 2 * sizeof(uint16_t))));
232
      ref_ = CONVERT_TO_BYTEPTR(new uint16_t[block_size_ * 2]);
233
#endif  // CONFIG_AOM_HIGHBITDEPTH
234
    }
235
236
237
238
239
    ASSERT_TRUE(src_ != NULL);
    ASSERT_TRUE(ref_ != NULL);
  }

  virtual void TearDown() {
240
    if (!use_high_bit_depth_) {
Adrian Grange's avatar
Adrian Grange committed
241
      aom_free(src_);
242
      delete[] ref_;
243
#if CONFIG_AOM_HIGHBITDEPTH
244
    } else {
Adrian Grange's avatar
Adrian Grange committed
245
      aom_free(CONVERT_TO_SHORTPTR(src_));
246
      delete[] CONVERT_TO_SHORTPTR(ref_);
247
#endif  // CONFIG_AOM_HIGHBITDEPTH
248
    }
Yaowu Xu's avatar
Yaowu Xu committed
249
    libaom_test::ClearSystemState();
250
251
252
  }

 protected:
James Zern's avatar
James Zern committed
253
  void ZeroTest();
254
  void RefTest();
255
  void RefStrideTest();
James Zern's avatar
James Zern committed
256
257
  void OneQuarterTest();

258
  ACMRandom rnd_;
259
260
  uint8_t *src_;
  uint8_t *ref_;
261
262
  int width_, log2width_;
  int height_, log2height_;
Adrian Grange's avatar
Adrian Grange committed
263
  aom_bit_depth_t bit_depth_;
264
265
  int mask_;
  bool use_high_bit_depth_;
266
  int block_size_;
James Zern's avatar
James Zern committed
267
  VarianceFunctionType variance_;
268
269
};

clang-format's avatar
clang-format committed
270
template <typename VarianceFunctionType>
James Zern's avatar
James Zern committed
271
void VarianceTest<VarianceFunctionType>::ZeroTest() {
272
  for (int i = 0; i <= 255; ++i) {
273
274
    if (!use_high_bit_depth_) {
      memset(src_, i, block_size_);
275
#if CONFIG_AOM_HIGHBITDEPTH
276
    } else {
Adrian Grange's avatar
Adrian Grange committed
277
      aom_memset16(CONVERT_TO_SHORTPTR(src_), i << (bit_depth_ - 8),
278
                   block_size_);
279
#endif  // CONFIG_AOM_HIGHBITDEPTH
280
    }
281
    for (int j = 0; j <= 255; ++j) {
282
283
      if (!use_high_bit_depth_) {
        memset(ref_, j, block_size_);
284
#if CONFIG_AOM_HIGHBITDEPTH
285
      } else {
Adrian Grange's avatar
Adrian Grange committed
286
        aom_memset16(CONVERT_TO_SHORTPTR(ref_), j << (bit_depth_ - 8),
287
                     block_size_);
288
#endif  // CONFIG_AOM_HIGHBITDEPTH
289
      }
290
      unsigned int sse;
291
      unsigned int var;
clang-format's avatar
clang-format committed
292
293
      ASM_REGISTER_STATE_CHECK(var =
                                   variance_(src_, width_, ref_, width_, &sse));
294
      EXPECT_EQ(0u, var) << "src values: " << i << " ref values: " << j;
295
296
297
298
    }
  }
}

clang-format's avatar
clang-format committed
299
template <typename VarianceFunctionType>
300
301
302
void VarianceTest<VarianceFunctionType>::RefTest() {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < block_size_; j++) {
clang-format's avatar
clang-format committed
303
304
305
      if (!use_high_bit_depth_) {
        src_[j] = rnd_.Rand8();
        ref_[j] = rnd_.Rand8();
306
#if CONFIG_AOM_HIGHBITDEPTH
clang-format's avatar
clang-format committed
307
308
309
      } else {
        CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() && mask_;
        CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() && mask_;
310
#endif  // CONFIG_AOM_HIGHBITDEPTH
clang-format's avatar
clang-format committed
311
      }
312
313
    }
    unsigned int sse1, sse2;
314
    unsigned int var1;
315
    const int stride_coeff = 1;
clang-format's avatar
clang-format committed
316
317
318
319
320
    ASM_REGISTER_STATE_CHECK(var1 =
                                 variance_(src_, width_, ref_, width_, &sse1));
    const unsigned int var2 =
        variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
                     stride_coeff, &sse2, use_high_bit_depth_, bit_depth_);
321
322
323
324
325
    EXPECT_EQ(sse1, sse2);
    EXPECT_EQ(var1, var2);
  }
}

clang-format's avatar
clang-format committed
326
template <typename VarianceFunctionType>
327
328
329
330
331
332
333
334
335
336
void VarianceTest<VarianceFunctionType>::RefStrideTest() {
  for (int i = 0; i < 10; ++i) {
    int ref_stride_coeff = i % 2;
    int src_stride_coeff = (i >> 1) % 2;
    for (int j = 0; j < block_size_; j++) {
      int ref_ind = (j / width_) * ref_stride_coeff * width_ + j % width_;
      int src_ind = (j / width_) * src_stride_coeff * width_ + j % width_;
      if (!use_high_bit_depth_) {
        src_[src_ind] = rnd_.Rand8();
        ref_[ref_ind] = rnd_.Rand8();
337
#if CONFIG_AOM_HIGHBITDEPTH
338
339
340
      } else {
        CONVERT_TO_SHORTPTR(src_)[src_ind] = rnd_.Rand16() && mask_;
        CONVERT_TO_SHORTPTR(ref_)[ref_ind] = rnd_.Rand16() && mask_;
341
#endif  // CONFIG_AOM_HIGHBITDEPTH
342
343
344
345
346
      }
    }
    unsigned int sse1, sse2;
    unsigned int var1;

clang-format's avatar
clang-format committed
347
348
349
350
351
352
    ASM_REGISTER_STATE_CHECK(var1 = variance_(src_, width_ * src_stride_coeff,
                                              ref_, width_ * ref_stride_coeff,
                                              &sse1));
    const unsigned int var2 =
        variance_ref(src_, ref_, log2width_, log2height_, src_stride_coeff,
                     ref_stride_coeff, &sse2, use_high_bit_depth_, bit_depth_);
353
354
355
356
357
    EXPECT_EQ(sse1, sse2);
    EXPECT_EQ(var1, var2);
  }
}

clang-format's avatar
clang-format committed
358
template <typename VarianceFunctionType>
James Zern's avatar
James Zern committed
359
void VarianceTest<VarianceFunctionType>::OneQuarterTest() {
360
  const int half = block_size_ / 2;
361
362
363
364
  if (!use_high_bit_depth_) {
    memset(src_, 255, block_size_);
    memset(ref_, 255, half);
    memset(ref_ + half, 0, half);
365
#if CONFIG_AOM_HIGHBITDEPTH
366
  } else {
Adrian Grange's avatar
Adrian Grange committed
367
    aom_memset16(CONVERT_TO_SHORTPTR(src_), 255 << (bit_depth_ - 8),
368
                 block_size_);
Adrian Grange's avatar
Adrian Grange committed
369
370
    aom_memset16(CONVERT_TO_SHORTPTR(ref_), 255 << (bit_depth_ - 8), half);
    aom_memset16(CONVERT_TO_SHORTPTR(ref_) + half, 0, half);
371
#endif  // CONFIG_AOM_HIGHBITDEPTH
372
  }
373
  unsigned int sse;
374
  unsigned int var;
375
  ASM_REGISTER_STATE_CHECK(var = variance_(src_, width_, ref_, width_, &sse));
376
377
378
379
  const unsigned int expected = block_size_ * 255 * 255 / 4;
  EXPECT_EQ(expected, var);
}

clang-format's avatar
clang-format committed
380
template <typename MseFunctionType>
381
382
383
384
class MseTest
    : public ::testing::TestWithParam<tuple<int, int, MseFunctionType> > {
 public:
  virtual void SetUp() {
clang-format's avatar
clang-format committed
385
386
    const tuple<int, int, MseFunctionType> &params = this->GetParam();
    log2width_ = get<0>(params);
387
388
389
390
391
392
393
    width_ = 1 << log2width_;
    log2height_ = get<1>(params);
    height_ = 1 << log2height_;
    mse_ = get<2>(params);

    rnd(ACMRandom::DeterministicSeed());
    block_size_ = width_ * height_;
Adrian Grange's avatar
Adrian Grange committed
394
    src_ = reinterpret_cast<uint8_t *>(aom_memalign(16, block_size_));
395
396
397
398
399
400
    ref_ = new uint8_t[block_size_];
    ASSERT_TRUE(src_ != NULL);
    ASSERT_TRUE(ref_ != NULL);
  }

  virtual void TearDown() {
Adrian Grange's avatar
Adrian Grange committed
401
    aom_free(src_);
402
    delete[] ref_;
Yaowu Xu's avatar
Yaowu Xu committed
403
    libaom_test::ClearSystemState();
404
405
406
407
408
409
410
411
412
  }

 protected:
  void RefTest_mse();
  void RefTest_sse();
  void MaxTest_mse();
  void MaxTest_sse();

  ACMRandom rnd;
clang-format's avatar
clang-format committed
413
414
  uint8_t *src_;
  uint8_t *ref_;
415
416
417
418
419
420
  int width_, log2width_;
  int height_, log2height_;
  int block_size_;
  MseFunctionType mse_;
};

clang-format's avatar
clang-format committed
421
template <typename MseFunctionType>
422
423
424
425
426
427
428
void MseTest<MseFunctionType>::RefTest_mse() {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < block_size_; j++) {
      src_[j] = rnd.Rand8();
      ref_[j] = rnd.Rand8();
    }
    unsigned int sse1, sse2;
429
    const int stride_coeff = 1;
430
    ASM_REGISTER_STATE_CHECK(mse_(src_, width_, ref_, width_, &sse1));
431
    variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
Adrian Grange's avatar
Adrian Grange committed
432
                 stride_coeff, &sse2, false, AOM_BITS_8);
433
434
435
436
    EXPECT_EQ(sse1, sse2);
  }
}

clang-format's avatar
clang-format committed
437
template <typename MseFunctionType>
438
439
440
441
442
443
444
445
void MseTest<MseFunctionType>::RefTest_sse() {
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < block_size_; j++) {
      src_[j] = rnd.Rand8();
      ref_[j] = rnd.Rand8();
    }
    unsigned int sse2;
    unsigned int var1;
446
447
448
    const int stride_coeff = 1;
    ASM_REGISTER_STATE_CHECK(var1 = mse_(src_, width_, ref_, width_));
    variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
Adrian Grange's avatar
Adrian Grange committed
449
                 stride_coeff, &sse2, false, AOM_BITS_8);
450
451
452
453
    EXPECT_EQ(var1, sse2);
  }
}

clang-format's avatar
clang-format committed
454
template <typename MseFunctionType>
455
456
457
458
459
460
461
462
463
void MseTest<MseFunctionType>::MaxTest_mse() {
  memset(src_, 255, block_size_);
  memset(ref_, 0, block_size_);
  unsigned int sse;
  ASM_REGISTER_STATE_CHECK(mse_(src_, width_, ref_, width_, &sse));
  const unsigned int expected = block_size_ * 255 * 255;
  EXPECT_EQ(expected, sse);
}

clang-format's avatar
clang-format committed
464
template <typename MseFunctionType>
465
466
467
468
469
470
471
472
473
void MseTest<MseFunctionType>::MaxTest_sse() {
  memset(src_, 255, block_size_);
  memset(ref_, 0, block_size_);
  unsigned int var;
  ASM_REGISTER_STATE_CHECK(var = mse_(src_, width_, ref_, width_));
  const unsigned int expected = block_size_ * 255 * 255;
  EXPECT_EQ(expected, var);
}

clang-format's avatar
clang-format committed
474
475
476
static uint32_t subpel_avg_variance_ref(const uint8_t *ref, const uint8_t *src,
                                        const uint8_t *second_pred, int l2w,
                                        int l2h, int xoff, int yoff,
Johann's avatar
Johann committed
477
478
                                        uint32_t *sse_ptr,
                                        bool use_high_bit_depth,
Adrian Grange's avatar
Adrian Grange committed
479
                                        aom_bit_depth_t bit_depth) {
480
481
482
483
  int64_t se = 0;
  uint64_t sse = 0;
  const int w = 1 << l2w;
  const int h = 1 << l2h;
Johann's avatar
Johann committed
484
485
486
487

  xoff <<= 1;
  yoff <<= 1;

488
489
490
491
492
493
494
495
496
497
498
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      // bilinear interpolation at a 16th pel step
      if (!use_high_bit_depth) {
        const int a1 = ref[(w + 1) * (y + 0) + x + 0];
        const int a2 = ref[(w + 1) * (y + 0) + x + 1];
        const int b1 = ref[(w + 1) * (y + 1) + x + 0];
        const int b2 = ref[(w + 1) * (y + 1) + x + 1];
        const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
        const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
        const int r = a + (((b - a) * yoff + 8) >> 4);
clang-format's avatar
clang-format committed
499
500
        const int diff =
            ((r + second_pred[w * y + x] + 1) >> 1) - src[w * y + x];
501
502
        se += diff;
        sse += diff * diff;
503
#if CONFIG_AOM_HIGHBITDEPTH
504
505
506
      } else {
        uint16_t *ref16 = CONVERT_TO_SHORTPTR(ref);
        uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
clang-format's avatar
clang-format committed
507
        uint16_t *sec16 = CONVERT_TO_SHORTPTR(second_pred);
508
509
510
511
512
513
514
515
516
517
        const int a1 = ref16[(w + 1) * (y + 0) + x + 0];
        const int a2 = ref16[(w + 1) * (y + 0) + x + 1];
        const int b1 = ref16[(w + 1) * (y + 1) + x + 0];
        const int b2 = ref16[(w + 1) * (y + 1) + x + 1];
        const int a = a1 + (((a2 - a1) * xoff + 8) >> 4);
        const int b = b1 + (((b2 - b1) * xoff + 8) >> 4);
        const int r = a + (((b - a) * yoff + 8) >> 4);
        const int diff = ((r + sec16[w * y + x] + 1) >> 1) - src16[w * y + x];
        se += diff;
        sse += diff * diff;
518
#endif  // CONFIG_AOM_HIGHBITDEPTH
519
520
521
      }
    }
  }
522
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
523
  *sse_ptr = static_cast<uint32_t>(sse);
Urvang Joshi's avatar
Urvang Joshi committed
524
  return static_cast<uint32_t>(sse - ((se * se) >> (l2w + l2h)));
James Zern's avatar
James Zern committed
525
526
}

clang-format's avatar
clang-format committed
527
template <typename SubpelVarianceFunctionType>
Yaowu Xu's avatar
Yaowu Xu committed
528
class SubpelVarianceTest
clang-format's avatar
clang-format committed
529
530
    : public ::testing::TestWithParam<
          tuple<int, int, SubpelVarianceFunctionType, int> > {
531
532
 public:
  virtual void SetUp() {
clang-format's avatar
clang-format committed
533
    const tuple<int, int, SubpelVarianceFunctionType, int> &params =
534
        this->GetParam();
clang-format's avatar
clang-format committed
535
    log2width_ = get<0>(params);
536
537
538
539
    width_ = 1 << log2width_;
    log2height_ = get<1>(params);
    height_ = 1 << log2height_;
    subpel_variance_ = get<2>(params);
540
    if (get<3>(params)) {
Adrian Grange's avatar
Adrian Grange committed
541
      bit_depth_ = (aom_bit_depth_t)get<3>(params);
542
543
      use_high_bit_depth_ = true;
    } else {
Adrian Grange's avatar
Adrian Grange committed
544
      bit_depth_ = AOM_BITS_8;
545
546
      use_high_bit_depth_ = false;
    }
clang-format's avatar
clang-format committed
547
    mask_ = (1 << bit_depth_) - 1;
548

549
    rnd_.Reset(ACMRandom::DeterministicSeed());
550
    block_size_ = width_ * height_;
551
    if (!use_high_bit_depth_) {
Adrian Grange's avatar
Adrian Grange committed
552
553
      src_ = reinterpret_cast<uint8_t *>(aom_memalign(16, block_size_));
      sec_ = reinterpret_cast<uint8_t *>(aom_memalign(16, block_size_));
554
      ref_ = new uint8_t[block_size_ + width_ + height_ + 1];
555
#if CONFIG_AOM_HIGHBITDEPTH
556
    } else {
clang-format's avatar
clang-format committed
557
      src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Adrian Grange's avatar
Adrian Grange committed
558
          aom_memalign(16, block_size_ * sizeof(uint16_t))));
clang-format's avatar
clang-format committed
559
      sec_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Adrian Grange's avatar
Adrian Grange committed
560
          aom_memalign(16, block_size_ * sizeof(uint16_t))));
clang-format's avatar
clang-format committed
561
562
      ref_ =
          CONVERT_TO_BYTEPTR(new uint16_t[block_size_ + width_ + height_ + 1]);
563
#endif  // CONFIG_AOM_HIGHBITDEPTH
Johann's avatar
Johann committed
564
    }
565
    ASSERT_TRUE(src_ != NULL);
566
    ASSERT_TRUE(sec_ != NULL);
567
568
569
570
    ASSERT_TRUE(ref_ != NULL);
  }

  virtual void TearDown() {
571
    if (!use_high_bit_depth_) {
Adrian Grange's avatar
Adrian Grange committed
572
      aom_free(src_);
573
      delete[] ref_;
Adrian Grange's avatar
Adrian Grange committed
574
      aom_free(sec_);
575
#if CONFIG_AOM_HIGHBITDEPTH
576
    } else {
Adrian Grange's avatar
Adrian Grange committed
577
      aom_free(CONVERT_TO_SHORTPTR(src_));
578
      delete[] CONVERT_TO_SHORTPTR(ref_);
Adrian Grange's avatar
Adrian Grange committed
579
      aom_free(CONVERT_TO_SHORTPTR(sec_));
580
#endif  // CONFIG_AOM_HIGHBITDEPTH
581
    }
Yaowu Xu's avatar
Yaowu Xu committed
582
    libaom_test::ClearSystemState();
583
584
585
586
  }

 protected:
  void RefTest();
587
  void ExtremeRefTest();
588

589
  ACMRandom rnd_;
590
591
592
  uint8_t *src_;
  uint8_t *ref_;
  uint8_t *sec_;
593
  bool use_high_bit_depth_;
Adrian Grange's avatar
Adrian Grange committed
594
  aom_bit_depth_t bit_depth_;
595
596
  int width_, log2width_;
  int height_, log2height_;
clang-format's avatar
clang-format committed
597
  int block_size_, mask_;
598
599
600
  SubpelVarianceFunctionType subpel_variance_;
};

clang-format's avatar
clang-format committed
601
template <typename SubpelVarianceFunctionType>
602
void SubpelVarianceTest<SubpelVarianceFunctionType>::RefTest() {
Johann's avatar
Johann committed
603
604
  for (int x = 0; x < 8; ++x) {
    for (int y = 0; y < 8; ++y) {
605
606
607
608
609
610
611
      if (!use_high_bit_depth_) {
        for (int j = 0; j < block_size_; j++) {
          src_[j] = rnd_.Rand8();
        }
        for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
          ref_[j] = rnd_.Rand8();
        }
612
#if CONFIG_AOM_HIGHBITDEPTH
613
614
615
616
617
618
619
      } else {
        for (int j = 0; j < block_size_; j++) {
          CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask_;
        }
        for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
          CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() & mask_;
        }
620
#endif  // CONFIG_AOM_HIGHBITDEPTH
Johann's avatar
Johann committed
621
      }
622
      unsigned int sse1, sse2;
623
      unsigned int var1;
clang-format's avatar
clang-format committed
624
625
626
627
628
      ASM_REGISTER_STATE_CHECK(
          var1 = subpel_variance_(ref_, width_ + 1, x, y, src_, width_, &sse1));
      const unsigned int var2 =
          subpel_variance_ref(ref_, src_, log2width_, log2height_, x, y, &sse2,
                              use_high_bit_depth_, bit_depth_);
629
630
631
632
633
634
      EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
      EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
    }
  }
}

clang-format's avatar
clang-format committed
635
template <typename SubpelVarianceFunctionType>
636
637
638
639
void SubpelVarianceTest<SubpelVarianceFunctionType>::ExtremeRefTest() {
  // Compare against reference.
  // Src: Set the first half of values to 0, the second half to the maximum.
  // Ref: Set the first half of values to the maximum, the second half to 0.
Johann's avatar
Johann committed
640
641
  for (int x = 0; x < 8; ++x) {
    for (int y = 0; y < 8; ++y) {
642
643
644
645
646
647
      const int half = block_size_ / 2;
      if (!use_high_bit_depth_) {
        memset(src_, 0, half);
        memset(src_ + half, 255, half);
        memset(ref_, 255, half);
        memset(ref_ + half, 0, half + width_ + height_ + 1);
648
#if CONFIG_AOM_HIGHBITDEPTH
649
      } else {
Adrian Grange's avatar
Adrian Grange committed
650
651
652
653
        aom_memset16(CONVERT_TO_SHORTPTR(src_), mask_, half);
        aom_memset16(CONVERT_TO_SHORTPTR(src_) + half, 0, half);
        aom_memset16(CONVERT_TO_SHORTPTR(ref_), 0, half);
        aom_memset16(CONVERT_TO_SHORTPTR(ref_) + half, mask_,
654
                     half + width_ + height_ + 1);
655
#endif  // CONFIG_AOM_HIGHBITDEPTH
Johann's avatar
Johann committed
656
      }
657
658
659
660
661
      unsigned int sse1, sse2;
      unsigned int var1;
      ASM_REGISTER_STATE_CHECK(
          var1 = subpel_variance_(ref_, width_ + 1, x, y, src_, width_, &sse1));
      const unsigned int var2 =
clang-format's avatar
clang-format committed
662
663
          subpel_variance_ref(ref_, src_, log2width_, log2height_, x, y, &sse2,
                              use_high_bit_depth_, bit_depth_);
Johann's avatar
Johann committed
664
665
      EXPECT_EQ(sse1, sse2) << "for xoffset " << x << " and yoffset " << y;
      EXPECT_EQ(var1, var2) << "for xoffset " << x << " and yoffset " << y;
666
667
668
669
    }
  }
}

clang-format's avatar
clang-format committed
670
template <>
Johann's avatar
Johann committed
671
void SubpelVarianceTest<SubpixAvgVarMxNFunc>::RefTest() {
Johann's avatar
Johann committed
672
673
  for (int x = 0; x < 8; ++x) {
    for (int y = 0; y < 8; ++y) {
674
675
676
677
678
679
680
681
      if (!use_high_bit_depth_) {
        for (int j = 0; j < block_size_; j++) {
          src_[j] = rnd_.Rand8();
          sec_[j] = rnd_.Rand8();
        }
        for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
          ref_[j] = rnd_.Rand8();
        }
682
#if CONFIG_AOM_HIGHBITDEPTH
683
684
685
686
687
688
689
690
      } else {
        for (int j = 0; j < block_size_; j++) {
          CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask_;
          CONVERT_TO_SHORTPTR(sec_)[j] = rnd_.Rand16() & mask_;
        }
        for (int j = 0; j < block_size_ + width_ + height_ + 1; j++) {
          CONVERT_TO_SHORTPTR(ref_)[j] = rnd_.Rand16() & mask_;
        }
691
#endif  // CONFIG_AOM_HIGHBITDEPTH
692
      }
693
      unsigned int sse1, sse2;
694
      unsigned int var1;
clang-format's avatar
clang-format committed
695
696
697
698
699
700
      ASM_REGISTER_STATE_CHECK(var1 =
                                   subpel_variance_(ref_, width_ + 1, x, y,
                                                    src_, width_, &sse1, sec_));
      const unsigned int var2 =
          subpel_avg_variance_ref(ref_, src_, sec_, log2width_, log2height_, x,
                                  y, &sse2, use_high_bit_depth_, bit_depth_);
701
702
703
704
705
      EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
      EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
    }
  }
}
James Zern's avatar
James Zern committed
706

Adrian Grange's avatar
Adrian Grange committed
707
708
709
710
711
712
713
714
715
716
717
718
719
720
typedef MseTest<Get4x4SseFunc> AvxSseTest;
typedef MseTest<VarianceMxNFunc> AvxMseTest;
typedef VarianceTest<VarianceMxNFunc> AvxVarianceTest;
typedef SubpelVarianceTest<SubpixVarMxNFunc> AvxSubpelVarianceTest;
typedef SubpelVarianceTest<SubpixAvgVarMxNFunc> AvxSubpelAvgVarianceTest;

TEST_P(AvxSseTest, Ref_sse) { RefTest_sse(); }
TEST_P(AvxSseTest, Max_sse) { MaxTest_sse(); }
TEST_P(AvxMseTest, Ref_mse) { RefTest_mse(); }
TEST_P(AvxMseTest, Max_mse) { MaxTest_mse(); }
TEST_P(AvxVarianceTest, Zero) { ZeroTest(); }
TEST_P(AvxVarianceTest, Ref) { RefTest(); }
TEST_P(AvxVarianceTest, RefStride) { RefStrideTest(); }
TEST_P(AvxVarianceTest, OneQuarter) { OneQuarterTest(); }
Johann's avatar
Johann committed
721
722
TEST_P(SumOfSquaresTest, Const) { ConstTest(); }
TEST_P(SumOfSquaresTest, Ref) { RefTest(); }
Adrian Grange's avatar
Adrian Grange committed
723
724
725
TEST_P(AvxSubpelVarianceTest, Ref) { RefTest(); }
TEST_P(AvxSubpelVarianceTest, ExtremeRef) { ExtremeRefTest(); }
TEST_P(AvxSubpelAvgVarianceTest, Ref) { RefTest(); }
James Zern's avatar
James Zern committed
726

Johann's avatar
Johann committed
727
INSTANTIATE_TEST_CASE_P(C, SumOfSquaresTest,
Adrian Grange's avatar
Adrian Grange committed
728
                        ::testing::Values(aom_get_mb_ss_c));
Johann's avatar
Johann committed
729

Adrian Grange's avatar
Adrian Grange committed
730
INSTANTIATE_TEST_CASE_P(C, AvxSseTest,
731
                        ::testing::Values(make_tuple(2, 2,
Adrian Grange's avatar
Adrian Grange committed
732
                                                     &aom_get4x4sse_cs_c)));
Johann's avatar
Johann committed
733

Adrian Grange's avatar
Adrian Grange committed
734
INSTANTIATE_TEST_CASE_P(C, AvxMseTest,
Adrian Grange's avatar
Adrian Grange committed
735
736
737
738
                        ::testing::Values(make_tuple(4, 4, &aom_mse16x16_c),
                                          make_tuple(4, 3, &aom_mse16x8_c),
                                          make_tuple(3, 4, &aom_mse8x16_c),
                                          make_tuple(3, 3, &aom_mse8x8_c)));
739

740
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
741
    C, AvxVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
742
743
744
745
746
747
748
749
750
751
752
753
754
    ::testing::Values(make_tuple(6, 6, &aom_variance64x64_c, 0),
                      make_tuple(6, 5, &aom_variance64x32_c, 0),
                      make_tuple(5, 6, &aom_variance32x64_c, 0),
                      make_tuple(5, 5, &aom_variance32x32_c, 0),
                      make_tuple(5, 4, &aom_variance32x16_c, 0),
                      make_tuple(4, 5, &aom_variance16x32_c, 0),
                      make_tuple(4, 4, &aom_variance16x16_c, 0),
                      make_tuple(4, 3, &aom_variance16x8_c, 0),
                      make_tuple(3, 4, &aom_variance8x16_c, 0),
                      make_tuple(3, 3, &aom_variance8x8_c, 0),
                      make_tuple(3, 2, &aom_variance8x4_c, 0),
                      make_tuple(2, 3, &aom_variance4x8_c, 0),
                      make_tuple(2, 2, &aom_variance4x4_c, 0)));
755

Johann's avatar
Johann committed
756
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
757
    C, AvxSubpelVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
758
759
760
761
762
763
764
765
766
767
768
769
770
    ::testing::Values(make_tuple(6, 6, &aom_sub_pixel_variance64x64_c, 0),
                      make_tuple(6, 5, &aom_sub_pixel_variance64x32_c, 0),
                      make_tuple(5, 6, &aom_sub_pixel_variance32x64_c, 0),
                      make_tuple(5, 5, &aom_sub_pixel_variance32x32_c, 0),
                      make_tuple(5, 4, &aom_sub_pixel_variance32x16_c, 0),
                      make_tuple(4, 5, &aom_sub_pixel_variance16x32_c, 0),
                      make_tuple(4, 4, &aom_sub_pixel_variance16x16_c, 0),
                      make_tuple(4, 3, &aom_sub_pixel_variance16x8_c, 0),
                      make_tuple(3, 4, &aom_sub_pixel_variance8x16_c, 0),
                      make_tuple(3, 3, &aom_sub_pixel_variance8x8_c, 0),
                      make_tuple(3, 2, &aom_sub_pixel_variance8x4_c, 0),
                      make_tuple(2, 3, &aom_sub_pixel_variance4x8_c, 0),
                      make_tuple(2, 2, &aom_sub_pixel_variance4x4_c, 0)));
771

Johann's avatar
Johann committed
772
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
773
    C, AvxSubpelAvgVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
774
775
776
777
778
779
780
781
782
783
784
785
786
    ::testing::Values(make_tuple(6, 6, &aom_sub_pixel_avg_variance64x64_c, 0),
                      make_tuple(6, 5, &aom_sub_pixel_avg_variance64x32_c, 0),
                      make_tuple(5, 6, &aom_sub_pixel_avg_variance32x64_c, 0),
                      make_tuple(5, 5, &aom_sub_pixel_avg_variance32x32_c, 0),
                      make_tuple(5, 4, &aom_sub_pixel_avg_variance32x16_c, 0),
                      make_tuple(4, 5, &aom_sub_pixel_avg_variance16x32_c, 0),
                      make_tuple(4, 4, &aom_sub_pixel_avg_variance16x16_c, 0),
                      make_tuple(4, 3, &aom_sub_pixel_avg_variance16x8_c, 0),
                      make_tuple(3, 4, &aom_sub_pixel_avg_variance8x16_c, 0),
                      make_tuple(3, 3, &aom_sub_pixel_avg_variance8x8_c, 0),
                      make_tuple(3, 2, &aom_sub_pixel_avg_variance8x4_c, 0),
                      make_tuple(2, 3, &aom_sub_pixel_avg_variance4x8_c, 0),
                      make_tuple(2, 2, &aom_sub_pixel_avg_variance4x4_c, 0)));
Johann's avatar
Johann committed
787

788
#if CONFIG_AOM_HIGHBITDEPTH
Adrian Grange's avatar
Adrian Grange committed
789
790
791
792
793
794
795
796
797
798
799
800
801
802
typedef MseTest<VarianceMxNFunc> AvxHBDMseTest;
typedef VarianceTest<VarianceMxNFunc> AvxHBDVarianceTest;
typedef SubpelVarianceTest<SubpixVarMxNFunc> AvxHBDSubpelVarianceTest;
typedef SubpelVarianceTest<SubpixAvgVarMxNFunc> AvxHBDSubpelAvgVarianceTest;

TEST_P(AvxHBDMseTest, Ref_mse) { RefTest_mse(); }
TEST_P(AvxHBDMseTest, Max_mse) { MaxTest_mse(); }
TEST_P(AvxHBDVarianceTest, Zero) { ZeroTest(); }
TEST_P(AvxHBDVarianceTest, Ref) { RefTest(); }
TEST_P(AvxHBDVarianceTest, RefStride) { RefStrideTest(); }
TEST_P(AvxHBDVarianceTest, OneQuarter) { OneQuarterTest(); }
TEST_P(AvxHBDSubpelVarianceTest, Ref) { RefTest(); }
TEST_P(AvxHBDSubpelVarianceTest, ExtremeRef) { ExtremeRefTest(); }
TEST_P(AvxHBDSubpelAvgVarianceTest, Ref) { RefTest(); }
Johann's avatar
Johann committed
803
804

/* TODO(debargha): This test does not support the highbd version
805
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
806
    C, AvxHBDMseTest,
Adrian Grange's avatar
Adrian Grange committed
807
808
809
810
811
812
813
814
815
816
817
818
    ::testing::Values(make_tuple(4, 4, &aom_highbd_12_mse16x16_c),
                      make_tuple(4, 4, &aom_highbd_12_mse16x8_c),
                      make_tuple(4, 4, &aom_highbd_12_mse8x16_c),
                      make_tuple(4, 4, &aom_highbd_12_mse8x8_c),
                      make_tuple(4, 4, &aom_highbd_10_mse16x16_c),
                      make_tuple(4, 4, &aom_highbd_10_mse16x8_c),
                      make_tuple(4, 4, &aom_highbd_10_mse8x16_c),
                      make_tuple(4, 4, &aom_highbd_10_mse8x8_c),
                      make_tuple(4, 4, &aom_highbd_8_mse16x16_c),
                      make_tuple(4, 4, &aom_highbd_8_mse16x8_c),
                      make_tuple(4, 4, &aom_highbd_8_mse8x16_c),
                      make_tuple(4, 4, &aom_highbd_8_mse8x8_c)));
Johann's avatar
Johann committed
819
820
*/

James Zern's avatar
James Zern committed
821
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
822
    C, AvxHBDVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
    ::testing::Values(make_tuple(6, 6, &aom_highbd_12_variance64x64_c, 12),
                      make_tuple(6, 5, &aom_highbd_12_variance64x32_c, 12),
                      make_tuple(5, 6, &aom_highbd_12_variance32x64_c, 12),
                      make_tuple(5, 5, &aom_highbd_12_variance32x32_c, 12),
                      make_tuple(5, 4, &aom_highbd_12_variance32x16_c, 12),
                      make_tuple(4, 5, &aom_highbd_12_variance16x32_c, 12),
                      make_tuple(4, 4, &aom_highbd_12_variance16x16_c, 12),
                      make_tuple(4, 3, &aom_highbd_12_variance16x8_c, 12),
                      make_tuple(3, 4, &aom_highbd_12_variance8x16_c, 12),
                      make_tuple(3, 3, &aom_highbd_12_variance8x8_c, 12),
                      make_tuple(3, 2, &aom_highbd_12_variance8x4_c, 12),
                      make_tuple(2, 3, &aom_highbd_12_variance4x8_c, 12),
                      make_tuple(2, 2, &aom_highbd_12_variance4x4_c, 12),
                      make_tuple(6, 6, &aom_highbd_10_variance64x64_c, 10),
                      make_tuple(6, 5, &aom_highbd_10_variance64x32_c, 10),
                      make_tuple(5, 6, &aom_highbd_10_variance32x64_c, 10),
                      make_tuple(5, 5, &aom_highbd_10_variance32x32_c, 10),
                      make_tuple(5, 4, &aom_highbd_10_variance32x16_c, 10),
                      make_tuple(4, 5, &aom_highbd_10_variance16x32_c, 10),
                      make_tuple(4, 4, &aom_highbd_10_variance16x16_c, 10),
                      make_tuple(4, 3, &aom_highbd_10_variance16x8_c, 10),
                      make_tuple(3, 4, &aom_highbd_10_variance8x16_c, 10),
                      make_tuple(3, 3, &aom_highbd_10_variance8x8_c, 10),
                      make_tuple(3, 2, &aom_highbd_10_variance8x4_c, 10),
                      make_tuple(2, 3, &aom_highbd_10_variance4x8_c, 10),
                      make_tuple(2, 2, &aom_highbd_10_variance4x4_c, 10),
                      make_tuple(6, 6, &aom_highbd_8_variance64x64_c, 8),
                      make_tuple(6, 5, &aom_highbd_8_variance64x32_c, 8),
                      make_tuple(5, 6, &aom_highbd_8_variance32x64_c, 8),
                      make_tuple(5, 5, &aom_highbd_8_variance32x32_c, 8),
                      make_tuple(5, 4, &aom_highbd_8_variance32x16_c, 8),
                      make_tuple(4, 5, &aom_highbd_8_variance16x32_c, 8),
                      make_tuple(4, 4, &aom_highbd_8_variance16x16_c, 8),
                      make_tuple(4, 3, &aom_highbd_8_variance16x8_c, 8),
                      make_tuple(3, 4, &aom_highbd_8_variance8x16_c, 8),
                      make_tuple(3, 3, &aom_highbd_8_variance8x8_c, 8),
                      make_tuple(3, 2, &aom_highbd_8_variance8x4_c, 8),
                      make_tuple(2, 3, &aom_highbd_8_variance4x8_c, 8),
                      make_tuple(2, 2, &aom_highbd_8_variance4x4_c, 8)));
862

Johann's avatar
Johann committed
863
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
864
    C, AvxHBDSubpelVarianceTest,
865
    ::testing::Values(
Adrian Grange's avatar
Adrian Grange committed
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
        make_tuple(6, 6, &aom_highbd_8_sub_pixel_variance64x64_c, 8),
        make_tuple(6, 5, &aom_highbd_8_sub_pixel_variance64x32_c, 8),
        make_tuple(5, 6, &aom_highbd_8_sub_pixel_variance32x64_c, 8),
        make_tuple(5, 5, &aom_highbd_8_sub_pixel_variance32x32_c, 8),
        make_tuple(5, 4, &aom_highbd_8_sub_pixel_variance32x16_c, 8),
        make_tuple(4, 5, &aom_highbd_8_sub_pixel_variance16x32_c, 8),
        make_tuple(4, 4, &aom_highbd_8_sub_pixel_variance16x16_c, 8),
        make_tuple(4, 3, &aom_highbd_8_sub_pixel_variance16x8_c, 8),
        make_tuple(3, 4, &aom_highbd_8_sub_pixel_variance8x16_c, 8),
        make_tuple(3, 3, &aom_highbd_8_sub_pixel_variance8x8_c, 8),
        make_tuple(3, 2, &aom_highbd_8_sub_pixel_variance8x4_c, 8),
        make_tuple(2, 3, &aom_highbd_8_sub_pixel_variance4x8_c, 8),
        make_tuple(2, 2, &aom_highbd_8_sub_pixel_variance4x4_c, 8),
        make_tuple(6, 6, &aom_highbd_10_sub_pixel_variance64x64_c, 10),
        make_tuple(6, 5, &aom_highbd_10_sub_pixel_variance64x32_c, 10),
        make_tuple(5, 6, &aom_highbd_10_sub_pixel_variance32x64_c, 10),
        make_tuple(5, 5, &aom_highbd_10_sub_pixel_variance32x32_c, 10),
        make_tuple(5, 4, &aom_highbd_10_sub_pixel_variance32x16_c, 10),
        make_tuple(4, 5, &aom_highbd_10_sub_pixel_variance16x32_c, 10),
        make_tuple(4, 4, &aom_highbd_10_sub_pixel_variance16x16_c, 10),
        make_tuple(4, 3, &aom_highbd_10_sub_pixel_variance16x8_c, 10),
        make_tuple(3, 4, &aom_highbd_10_sub_pixel_variance8x16_c, 10),
        make_tuple(3, 3, &aom_highbd_10_sub_pixel_variance8x8_c, 10),
        make_tuple(3, 2, &aom_highbd_10_sub_pixel_variance8x4_c, 10),
        make_tuple(2, 3, &aom_highbd_10_sub_pixel_variance4x8_c, 10),
        make_tuple(2, 2, &aom_highbd_10_sub_pixel_variance4x4_c, 10),
        make_tuple(6, 6, &aom_highbd_12_sub_pixel_variance64x64_c, 12),
        make_tuple(6, 5, &aom_highbd_12_sub_pixel_variance64x32_c, 12),
        make_tuple(5, 6, &aom_highbd_12_sub_pixel_variance32x64_c, 12),
        make_tuple(5, 5, &aom_highbd_12_sub_pixel_variance32x32_c, 12),
        make_tuple(5, 4, &aom_highbd_12_sub_pixel_variance32x16_c, 12),
        make_tuple(4, 5, &aom_highbd_12_sub_pixel_variance16x32_c, 12),
        make_tuple(4, 4, &aom_highbd_12_sub_pixel_variance16x16_c, 12),
        make_tuple(4, 3, &aom_highbd_12_sub_pixel_variance16x8_c, 12),
        make_tuple(3, 4, &aom_highbd_12_sub_pixel_variance8x16_c, 12),
        make_tuple(3, 3, &aom_highbd_12_sub_pixel_variance8x8_c, 12),
        make_tuple(3, 2, &aom_highbd_12_sub_pixel_variance8x4_c, 12),
        make_tuple(2, 3, &aom_highbd_12_sub_pixel_variance4x8_c, 12),
        make_tuple(2, 2, &aom_highbd_12_sub_pixel_variance4x4_c, 12)));
905

Johann's avatar
Johann committed
906
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
907
    C, AvxHBDSubpelAvgVarianceTest,
Johann's avatar
Johann committed
908
    ::testing::Values(
Adrian Grange's avatar
Adrian Grange committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
        make_tuple(6, 6, &aom_highbd_8_sub_pixel_avg_variance64x64_c, 8),
        make_tuple(6, 5, &aom_highbd_8_sub_pixel_avg_variance64x32_c, 8),
        make_tuple(5, 6, &aom_highbd_8_sub_pixel_avg_variance32x64_c, 8),
        make_tuple(5, 5, &aom_highbd_8_sub_pixel_avg_variance32x32_c, 8),
        make_tuple(5, 4, &aom_highbd_8_sub_pixel_avg_variance32x16_c, 8),
        make_tuple(4, 5, &aom_highbd_8_sub_pixel_avg_variance16x32_c, 8),
        make_tuple(4, 4, &aom_highbd_8_sub_pixel_avg_variance16x16_c, 8),
        make_tuple(4, 3, &aom_highbd_8_sub_pixel_avg_variance16x8_c, 8),
        make_tuple(3, 4, &aom_highbd_8_sub_pixel_avg_variance8x16_c, 8),
        make_tuple(3, 3, &aom_highbd_8_sub_pixel_avg_variance8x8_c, 8),
        make_tuple(3, 2, &aom_highbd_8_sub_pixel_avg_variance8x4_c, 8),
        make_tuple(2, 3, &aom_highbd_8_sub_pixel_avg_variance4x8_c, 8),
        make_tuple(2, 2, &aom_highbd_8_sub_pixel_avg_variance4x4_c, 8),
        make_tuple(6, 6, &aom_highbd_10_sub_pixel_avg_variance64x64_c, 10),
        make_tuple(6, 5, &aom_highbd_10_sub_pixel_avg_variance64x32_c, 10),
        make_tuple(5, 6, &aom_highbd_10_sub_pixel_avg_variance32x64_c, 10),
        make_tuple(5, 5, &aom_highbd_10_sub_pixel_avg_variance32x32_c, 10),
        make_tuple(5, 4, &aom_highbd_10_sub_pixel_avg_variance32x16_c, 10),
        make_tuple(4, 5, &aom_highbd_10_sub_pixel_avg_variance16x32_c, 10),
        make_tuple(4, 4, &aom_highbd_10_sub_pixel_avg_variance16x16_c, 10),
        make_tuple(4, 3, &aom_highbd_10_sub_pixel_avg_variance16x8_c, 10),
        make_tuple(3, 4, &aom_highbd_10_sub_pixel_avg_variance8x16_c, 10),
        make_tuple(3, 3, &aom_highbd_10_sub_pixel_avg_variance8x8_c, 10),
        make_tuple(3, 2, &aom_highbd_10_sub_pixel_avg_variance8x4_c, 10),
        make_tuple(2, 3, &aom_highbd_10_sub_pixel_avg_variance4x8_c, 10),
        make_tuple(2, 2, &aom_highbd_10_sub_pixel_avg_variance4x4_c, 10),
        make_tuple(6, 6, &aom_highbd_12_sub_pixel_avg_variance64x64_c, 12),
        make_tuple(6, 5, &aom_highbd_12_sub_pixel_avg_variance64x32_c, 12),
        make_tuple(5, 6, &aom_highbd_12_sub_pixel_avg_variance32x64_c, 12),
        make_tuple(5, 5, &aom_highbd_12_sub_pixel_avg_variance32x32_c, 12),
        make_tuple(5, 4, &aom_highbd_12_sub_pixel_avg_variance32x16_c, 12),
        make_tuple(4, 5, &aom_highbd_12_sub_pixel_avg_variance16x32_c, 12),
        make_tuple(4, 4, &aom_highbd_12_sub_pixel_avg_variance16x16_c, 12),
        make_tuple(4, 3, &aom_highbd_12_sub_pixel_avg_variance16x8_c, 12),
        make_tuple(3, 4, &aom_highbd_12_sub_pixel_avg_variance8x16_c, 12),
        make_tuple(3, 3, &aom_highbd_12_sub_pixel_avg_variance8x8_c, 12),
        make_tuple(3, 2, &aom_highbd_12_sub_pixel_avg_variance8x4_c, 12),
        make_tuple(2, 3, &aom_highbd_12_sub_pixel_avg_variance4x8_c, 12),
        make_tuple(2, 2, &aom_highbd_12_sub_pixel_avg_variance4x4_c, 12)));
948
#endif  // CONFIG_AOM_HIGHBITDEPTH
James Zern's avatar
James Zern committed
949

James Zern's avatar
James Zern committed
950
#if HAVE_SSE2
Johann's avatar
Johann committed
951
INSTANTIATE_TEST_CASE_P(SSE2, SumOfSquaresTest,
Adrian Grange's avatar
Adrian Grange committed
952
                        ::testing::Values(aom_get_mb_ss_sse2));
Johann's avatar
Johann committed
953

Adrian Grange's avatar
Adrian Grange committed
954
INSTANTIATE_TEST_CASE_P(SSE2, AvxMseTest,
Adrian Grange's avatar
Adrian Grange committed
955
956
957
958
                        ::testing::Values(make_tuple(4, 4, &aom_mse16x16_sse2),
                                          make_tuple(4, 3, &aom_mse16x8_sse2),
                                          make_tuple(3, 4, &aom_mse8x16_sse2),
                                          make_tuple(3, 3, &aom_mse8x8_sse2)));
959

James Zern's avatar
James Zern committed
960
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
961
    SSE2, AvxVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
962
963
964
965
966
967
968
969
970
971
972
973
974
    ::testing::Values(make_tuple(6, 6, &aom_variance64x64_sse2, 0),
                      make_tuple(6, 5, &aom_variance64x32_sse2, 0),
                      make_tuple(5, 6, &aom_variance32x64_sse2, 0),
                      make_tuple(5, 5, &aom_variance32x32_sse2, 0),
                      make_tuple(5, 4, &aom_variance32x16_sse2, 0),
                      make_tuple(4, 5, &aom_variance16x32_sse2, 0),
                      make_tuple(4, 4, &aom_variance16x16_sse2, 0),
                      make_tuple(4, 3, &aom_variance16x8_sse2, 0),
                      make_tuple(3, 4, &aom_variance8x16_sse2, 0),
                      make_tuple(3, 3, &aom_variance8x8_sse2, 0),
                      make_tuple(3, 2, &aom_variance8x4_sse2, 0),
                      make_tuple(2, 3, &aom_variance4x8_sse2, 0),
                      make_tuple(2, 2, &aom_variance4x4_sse2, 0)));
Johann's avatar
Johann committed
975
976
977

#if CONFIG_USE_X86INC
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
978
    SSE2, AvxSubpelVarianceTest,
Adrian Grange's avatar
Adrian Grange committed
979
980
981
982
983
984
985
986
987
988
989
990
991
    ::testing::Values(make_tuple(6, 6, &aom_sub_pixel_variance64x64_sse2, 0),
                      make_tuple(6, 5, &aom_sub_pixel_variance64x32_sse2, 0),
                      make_tuple(5, 6, &aom_sub_pixel_variance32x64_sse2, 0),
                      make_tuple(5, 5, &aom_sub_pixel_variance32x32_sse2, 0),
                      make_tuple(5, 4, &aom_sub_pixel_variance32x16_sse2, 0),
                      make_tuple(4, 5, &aom_sub_pixel_variance16x32_sse2, 0),
                      make_tuple(4, 4, &aom_sub_pixel_variance16x16_sse2, 0),
                      make_tuple(4, 3, &aom_sub_pixel_variance16x8_sse2, 0),
                      make_tuple(3, 4, &aom_sub_pixel_variance8x16_sse2, 0),
                      make_tuple(3, 3, &aom_sub_pixel_variance8x8_sse2, 0),
                      make_tuple(3, 2, &aom_sub_pixel_variance8x4_sse2, 0),
                      make_tuple(2, 3, &aom_sub_pixel_variance4x8_sse, 0),
                      make_tuple(2, 2, &aom_sub_pixel_variance4x4_sse, 0)));
992

Johann's avatar
Johann committed
993
INSTANTIATE_TEST_CASE_P(
Adrian Grange's avatar
Adrian Grange committed
994
    SSE2, AvxSubpelAvgVarianceTest,
Johann's avatar
Johann committed
995
    ::testing::Values(
Adrian Grange's avatar
Adrian Grange committed
996
997
998
999
1000
        make_tuple(6, 6, &aom_sub_pixel_avg_variance64x64_sse2, 0),
        make_tuple(6, 5, &aom_sub_pixel_avg_variance64x32_sse2, 0),
        make_tuple(5, 6, &aom_sub_pixel_avg_variance32x64_sse2, 0),
        make_tuple(5, 5, &aom_sub_pixel_avg_variance32x32_sse2, 0),
        make_tuple(5, 4, &aom_sub_pixel_avg_variance32x16_sse2, 0),
For faster browsing, not all history is shown. View entire blame