variance_test.cc 90.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

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

14
#include "test/acm_random.h"
15
#include "test/clear_system_state.h"
16
#include "test/register_state_check.h"
17
#include "third_party/googletest/src/include/gtest/gtest.h"
18

Yaowu Xu's avatar
Yaowu Xu committed
19
#include "./vpx_config.h"
20 21
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
22
#include "vpx_mem/vpx_mem.h"
23
#include "vpx_ports/mem.h"
James Zern's avatar
James Zern committed
24
#if CONFIG_VP9_ENCODER
Yaowu Xu's avatar
Yaowu Xu committed
25
# include "./vp9_rtcd.h"
26
# include "vp9/encoder/vp9_variance.h"
Johann's avatar
Johann committed
27 28
#endif  // CONFIG_VP9_ENCODER
#include "./vpx_dsp_rtcd.h"
29 30 31

namespace {

Johann's avatar
Johann committed
32 33 34
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
35
typedef unsigned int (*Get4x4SseFunc)(const uint8_t *a, int a_stride,
Johann's avatar
Johann committed
36 37 38
                                      const uint8_t *b, int b_stride);


39 40 41
using ::std::tr1::get;
using ::std::tr1::make_tuple;
using ::std::tr1::tuple;
42 43
using libvpx_test::ACMRandom;

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
// 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) {
    case VPX_BITS_12:
      *sse = (*sse + 128) >> 8;
      *se = (*se + 8) >> 4;
      break;
    case VPX_BITS_10:
      *sse = (*sse + 8) >> 4;
      *se = (*se + 2) >> 2;
      break;
    case VPX_BITS_8:
    default:
      break;
  }
}

63 64 65 66 67 68 69 70
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;
}

Johann's avatar
Johann committed
71 72 73 74 75
static uint32_t variance_ref(const uint8_t *src, const uint8_t *ref,
                             int l2w, int l2h, int src_stride_coeff,
                             int ref_stride_coeff, uint32_t *sse_ptr,
                             bool use_high_bit_depth_,
                             vpx_bit_depth_t bit_depth) {
76 77 78 79 80 81 82 83 84 85 86 87
  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;
Johann's avatar
Johann committed
88
#if CONFIG_VP9_HIGHBITDEPTH
89 90 91 92 93
      } 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;
Johann's avatar
Johann committed
94
#endif  // CONFIG_VP9_HIGHBITDEPTH
95 96 97
      }
    }
  }
98
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
99 100 101 102
  *sse_ptr = static_cast<uint32_t>(sse);
  return static_cast<uint32_t>(sse -
                               ((static_cast<int64_t>(se) * se) >>
                                (l2w + l2h)));
103 104
}

Johann's avatar
Johann committed
105 106 107 108 109
static uint32_t subpel_variance_ref(const uint8_t *ref, const uint8_t *src,
                                    int l2w, int l2h, int xoff, int yoff,
                                    uint32_t *sse_ptr,
                                    bool use_high_bit_depth_,
                                    vpx_bit_depth_t bit_depth) {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  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++) {
      // 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;
Johann's avatar
Johann committed
128
#if CONFIG_VP9_HIGHBITDEPTH
129 130 131 132 133 134 135 136 137 138 139 140 141
      } 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;
Johann's avatar
Johann committed
142
#endif  // CONFIG_VP9_HIGHBITDEPTH
143 144 145
      }
    }
  }
146
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
147 148 149 150
  *sse_ptr = static_cast<uint32_t>(sse);
  return static_cast<uint32_t>(sse -
                               ((static_cast<int64_t>(se) * se) >>
                                (l2w + l2h)));
151
}
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 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
typedef unsigned int (*SumOfSquaresFunction)(const int16_t *src);

class SumOfSquaresTest : public ::testing::TestWithParam<SumOfSquaresFunction> {
 public:
  SumOfSquaresTest() : func_(GetParam()) {}

  virtual ~SumOfSquaresTest() {
    libvpx_test::ClearSystemState();
  }

 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);
  }
}

James Zern's avatar
James Zern committed
197
template<typename VarianceFunctionType>
Yaowu Xu's avatar
Yaowu Xu committed
198
class VarianceTest
199 200
    : public ::testing::TestWithParam<tuple<int, int,
                                            VarianceFunctionType, int> > {
201 202
 public:
  virtual void SetUp() {
203
    const tuple<int, int, VarianceFunctionType, int>& params = this->GetParam();
204 205 206 207
    log2width_  = get<0>(params);
    width_ = 1 << log2width_;
    log2height_ = get<1>(params);
    height_ = 1 << log2height_;
208
    variance_ = get<2>(params);
209 210 211 212 213 214 215 216
    if (get<3>(params)) {
      bit_depth_ = static_cast<vpx_bit_depth_t>(get<3>(params));
      use_high_bit_depth_ = true;
    } else {
      bit_depth_ = VPX_BITS_8;
      use_high_bit_depth_ = false;
    }
    mask_ = (1 << bit_depth_) - 1;
217

218
    rnd_.Reset(ACMRandom::DeterministicSeed());
219
    block_size_ = width_ * height_;
220 221 222
    if (!use_high_bit_depth_) {
      src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_ * 2));
      ref_ = new uint8_t[block_size_ * 2];
Johann's avatar
Johann committed
223
#if CONFIG_VP9_HIGHBITDEPTH
224 225 226 227
    } else {
      src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
          vpx_memalign(16, block_size_ * 2 * sizeof(uint16_t))));
      ref_ = CONVERT_TO_BYTEPTR(new uint16_t[block_size_ * 2]);
Johann's avatar
Johann committed
228
#endif  // CONFIG_VP9_HIGHBITDEPTH
229
    }
230 231 232 233 234
    ASSERT_TRUE(src_ != NULL);
    ASSERT_TRUE(ref_ != NULL);
  }

  virtual void TearDown() {
235 236 237
    if (!use_high_bit_depth_) {
      vpx_free(src_);
      delete[] ref_;
Johann's avatar
Johann committed
238
#if CONFIG_VP9_HIGHBITDEPTH
239 240 241
    } else {
      vpx_free(CONVERT_TO_SHORTPTR(src_));
      delete[] CONVERT_TO_SHORTPTR(ref_);
Johann's avatar
Johann committed
242
#endif  // CONFIG_VP9_HIGHBITDEPTH
243
    }
244
    libvpx_test::ClearSystemState();
245 246 247
  }

 protected:
James Zern's avatar
James Zern committed
248
  void ZeroTest();
249
  void RefTest();
250
  void RefStrideTest();
James Zern's avatar
James Zern committed
251 252
  void OneQuarterTest();

253
  ACMRandom rnd_;
254 255
  uint8_t *src_;
  uint8_t *ref_;
256 257
  int width_, log2width_;
  int height_, log2height_;
258 259 260
  vpx_bit_depth_t bit_depth_;
  int mask_;
  bool use_high_bit_depth_;
261
  int block_size_;
James Zern's avatar
James Zern committed
262
  VarianceFunctionType variance_;
263 264
};

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

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

template<typename VarianceFunctionType>
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();
Johann's avatar
Johann committed
333
#if CONFIG_VP9_HIGHBITDEPTH
334 335 336
      } else {
        CONVERT_TO_SHORTPTR(src_)[src_ind] = rnd_.Rand16() && mask_;
        CONVERT_TO_SHORTPTR(ref_)[ref_ind] = rnd_.Rand16() && mask_;
Johann's avatar
Johann committed
337
#endif  // CONFIG_VP9_HIGHBITDEPTH
338 339 340 341 342 343 344 345 346 347 348 349
      }
    }
    unsigned int sse1, sse2;
    unsigned int var1;

    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_);
350 351 352 353 354
    EXPECT_EQ(sse1, sse2);
    EXPECT_EQ(var1, var2);
  }
}

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

377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
template<typename MseFunctionType>
class MseTest
    : public ::testing::TestWithParam<tuple<int, int, MseFunctionType> > {
 public:
  virtual void SetUp() {
    const tuple<int, int, MseFunctionType>& params = this->GetParam();
    log2width_  = get<0>(params);
    width_ = 1 << log2width_;
    log2height_ = get<1>(params);
    height_ = 1 << log2height_;
    mse_ = get<2>(params);

    rnd(ACMRandom::DeterministicSeed());
    block_size_ = width_ * height_;
    src_ = reinterpret_cast<uint8_t *>(vpx_memalign(16, block_size_));
    ref_ = new uint8_t[block_size_];
    ASSERT_TRUE(src_ != NULL);
    ASSERT_TRUE(ref_ != NULL);
  }

  virtual void TearDown() {
    vpx_free(src_);
    delete[] ref_;
    libvpx_test::ClearSystemState();
  }

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

  ACMRandom rnd;
  uint8_t* src_;
  uint8_t* ref_;
  int width_, log2width_;
  int height_, log2height_;
  int block_size_;
  MseFunctionType mse_;
};

template<typename MseFunctionType>
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;
426
    const int stride_coeff = 1;
427
    ASM_REGISTER_STATE_CHECK(mse_(src_, width_, ref_, width_, &sse1));
428 429
    variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
                 stride_coeff, &sse2, false, VPX_BITS_8);
430 431 432 433 434 435 436 437 438 439 440 441 442
    EXPECT_EQ(sse1, sse2);
  }
}

template<typename MseFunctionType>
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;
443 444 445 446
    const int stride_coeff = 1;
    ASM_REGISTER_STATE_CHECK(var1 = mse_(src_, width_, ref_, width_));
    variance_ref(src_, ref_, log2width_, log2height_, stride_coeff,
                 stride_coeff, &sse2, false, VPX_BITS_8);
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
    EXPECT_EQ(var1, sse2);
  }
}

template<typename MseFunctionType>
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);
}

template<typename MseFunctionType>
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);
}

Johann's avatar
Johann committed
471 472 473 474 475 476 477 478
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,
                                        uint32_t *sse_ptr,
                                        bool use_high_bit_depth,
                                        vpx_bit_depth_t bit_depth) {
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  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++) {
      // 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 + second_pred[w * y + x] + 1) >> 1) - src[w * y + x];
        se += diff;
        sse += diff * diff;
Johann's avatar
Johann committed
497
#if CONFIG_VP9_HIGHBITDEPTH
498 499 500 501 502 503 504 505 506 507 508 509 510 511
      } else {
        uint16_t *ref16 = CONVERT_TO_SHORTPTR(ref);
        uint16_t *src16 = CONVERT_TO_SHORTPTR(src);
        uint16_t *sec16   = CONVERT_TO_SHORTPTR(second_pred);
        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;
Johann's avatar
Johann committed
512
#endif  // CONFIG_VP9_HIGHBITDEPTH
513 514 515
      }
    }
  }
516
  RoundHighBitDepth(bit_depth, &se, &sse);
Johann's avatar
Johann committed
517 518 519 520
  *sse_ptr = static_cast<uint32_t>(sse);
  return static_cast<uint32_t>(sse -
                               ((static_cast<int64_t>(se) * se) >>
                                (l2w + l2h)));
James Zern's avatar
James Zern committed
521 522
}

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

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

  virtual void TearDown() {
569 570 571 572
    if (!use_high_bit_depth_) {
      vpx_free(src_);
      delete[] ref_;
      vpx_free(sec_);
Johann's avatar
Johann committed
573
#if CONFIG_VP9_HIGHBITDEPTH
574 575 576 577
    } else {
      vpx_free(CONVERT_TO_SHORTPTR(src_));
      delete[] CONVERT_TO_SHORTPTR(ref_);
      vpx_free(CONVERT_TO_SHORTPTR(sec_));
Johann's avatar
Johann committed
578
#endif  // CONFIG_VP9_HIGHBITDEPTH
579
    }
580
    libvpx_test::ClearSystemState();
581 582 583 584
  }

 protected:
  void RefTest();
585
  void ExtremeRefTest();
586

587
  ACMRandom rnd_;
588 589 590
  uint8_t *src_;
  uint8_t *ref_;
  uint8_t *sec_;
591 592
  bool use_high_bit_depth_;
  vpx_bit_depth_t bit_depth_;
593 594
  int width_, log2width_;
  int height_, log2height_;
595
  int block_size_,  mask_;
596 597 598 599 600 601 602
  SubpelVarianceFunctionType subpel_variance_;
};

template<typename SubpelVarianceFunctionType>
void SubpelVarianceTest<SubpelVarianceFunctionType>::RefTest() {
  for (int x = 0; x < 16; ++x) {
    for (int y = 0; y < 16; ++y) {
603 604 605 606 607 608 609
      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();
        }
Johann's avatar
Johann committed
610
#if CONFIG_VP9_HIGHBITDEPTH
611 612 613 614 615 616 617 618
      } 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_;
        }
#endif  // CONFIG_VP9_HIGHBITDEPTH
Johann's avatar
Johann committed
619
      }
620
      unsigned int sse1, sse2;
621
      unsigned int var1;
622 623
      ASM_REGISTER_STATE_CHECK(var1 = subpel_variance_(ref_, width_ + 1, x, y,
                                                       src_, width_, &sse1));
624
      const unsigned int var2 = subpel_variance_ref(ref_, src_, log2width_,
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
                                                    log2height_, x, y, &sse2,
                                                    use_high_bit_depth_,
                                                    bit_depth_);
      EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
      EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
    }
  }
}

template<typename SubpelVarianceFunctionType>
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.
  for (int x = 0; x < 16; ++x) {
    for (int y = 0; y < 16; ++y) {
      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);
Johann's avatar
Johann committed
647
#if CONFIG_VP9_HIGHBITDEPTH
648 649 650 651 652 653 654
      } else {
        vpx_memset16(CONVERT_TO_SHORTPTR(src_), mask_, half);
        vpx_memset16(CONVERT_TO_SHORTPTR(src_) + half, 0, half);
        vpx_memset16(CONVERT_TO_SHORTPTR(ref_), 0, half);
        vpx_memset16(CONVERT_TO_SHORTPTR(ref_) + half, mask_,
                     half + width_ + height_ + 1);
#endif  // CONFIG_VP9_HIGHBITDEPTH
Johann's avatar
Johann committed
655
      }
656 657 658 659 660 661 662
      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 =
          subpel_variance_ref(ref_, src_, log2width_, log2height_, x, y, &sse2,
                              use_high_bit_depth_, bit_depth_);
663 664 665 666 667 668
      EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
      EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
    }
  }
}

Johann's avatar
Johann committed
669
#if CONFIG_VP9_ENCODER
670 671 672 673
template<>
void SubpelVarianceTest<vp9_subp_avg_variance_fn_t>::RefTest() {
  for (int x = 0; x < 16; ++x) {
    for (int y = 0; y < 16; ++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();
        }
Johann's avatar
Johann committed
682
#if CONFIG_VP9_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_;
        }
Johann's avatar
Johann committed
691
#endif  // CONFIG_VP9_HIGHBITDEPTH
692
      }
693
      unsigned int sse1, sse2;
694
      unsigned int var1;
695 696 697
      ASM_REGISTER_STATE_CHECK(
          var1 = subpel_variance_(ref_, width_ + 1, x, y,
                                  src_, width_, &sse1, sec_));
698 699
      const unsigned int var2 = subpel_avg_variance_ref(ref_, src_, sec_,
                                                        log2width_, log2height_,
700 701 702
                                                        x, y, &sse2,
                                                        use_high_bit_depth_,
                                                        bit_depth_);
703 704 705 706 707
      EXPECT_EQ(sse1, sse2) << "at position " << x << ", " << y;
      EXPECT_EQ(var1, var2) << "at position " << x << ", " << y;
    }
  }
}
James Zern's avatar
James Zern committed
708 709
#endif  // CONFIG_VP9_ENCODER

Johann's avatar
Johann committed
710
typedef MseTest<Get4x4SseFunc> VpxSseTest;
Johann's avatar
Johann committed
711 712 713 714 715 716 717 718 719 720 721 722 723
typedef MseTest<VarianceMxNFunc> VpxMseTest;
typedef VarianceTest<VarianceMxNFunc> VpxVarianceTest;

TEST_P(VpxSseTest, Ref_sse) { RefTest_sse(); }
TEST_P(VpxSseTest, Max_sse) { MaxTest_sse(); }
TEST_P(VpxMseTest, Ref_mse) { RefTest_mse(); }
TEST_P(VpxMseTest, Max_mse) { MaxTest_mse(); }
TEST_P(VpxVarianceTest, Zero) { ZeroTest(); }
TEST_P(VpxVarianceTest, Ref) { RefTest(); }
TEST_P(VpxVarianceTest, RefStride) { RefStrideTest(); }
TEST_P(VpxVarianceTest, OneQuarter) { OneQuarterTest(); }
TEST_P(SumOfSquaresTest, Const) { ConstTest(); }
TEST_P(SumOfSquaresTest, Ref) { RefTest(); }
James Zern's avatar
James Zern committed
724

Johann's avatar
Johann committed
725 726 727
INSTANTIATE_TEST_CASE_P(C, SumOfSquaresTest,
                        ::testing::Values(vpx_get_mb_ss_c));

Johann's avatar
Johann committed
728
const Get4x4SseFunc get4x4sse_cs_c = vpx_get4x4sse_cs_c;
Johann's avatar
Johann committed
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
INSTANTIATE_TEST_CASE_P(C, VpxSseTest,
                        ::testing::Values(make_tuple(2, 2, get4x4sse_cs_c)));

const VarianceMxNFunc mse16x16_c = vpx_mse16x16_c;
const VarianceMxNFunc mse16x8_c = vpx_mse16x8_c;
const VarianceMxNFunc mse8x16_c = vpx_mse8x16_c;
const VarianceMxNFunc mse8x8_c = vpx_mse8x8_c;
INSTANTIATE_TEST_CASE_P(C, VpxMseTest,
                        ::testing::Values(make_tuple(4, 4, mse16x16_c),
                                          make_tuple(4, 3, mse16x8_c),
                                          make_tuple(3, 4, mse8x16_c),
                                          make_tuple(3, 3, mse8x8_c)));

const VarianceMxNFunc variance64x64_c = vpx_variance64x64_c;
const VarianceMxNFunc variance64x32_c = vpx_variance64x32_c;
const VarianceMxNFunc variance32x64_c = vpx_variance32x64_c;
const VarianceMxNFunc variance32x32_c = vpx_variance32x32_c;
const VarianceMxNFunc variance32x16_c = vpx_variance32x16_c;
const VarianceMxNFunc variance16x32_c = vpx_variance16x32_c;
const VarianceMxNFunc variance16x16_c = vpx_variance16x16_c;
const VarianceMxNFunc variance16x8_c = vpx_variance16x8_c;
const VarianceMxNFunc variance8x16_c = vpx_variance8x16_c;
const VarianceMxNFunc variance8x8_c = vpx_variance8x8_c;
const VarianceMxNFunc variance8x4_c = vpx_variance8x4_c;
const VarianceMxNFunc variance4x8_c = vpx_variance4x8_c;
const VarianceMxNFunc variance4x4_c = vpx_variance4x4_c;
755 756

INSTANTIATE_TEST_CASE_P(
Johann's avatar
Johann committed
757 758 759 760 761 762 763 764
    C, VpxVarianceTest,
    ::testing::Values(make_tuple(6, 6, variance64x64_c, 0),
                      make_tuple(6, 5, variance64x32_c, 0),
                      make_tuple(5, 6, variance32x64_c, 0),
                      make_tuple(5, 5, variance32x32_c, 0),
                      make_tuple(5, 4, variance32x16_c, 0),
                      make_tuple(4, 5, variance16x32_c, 0),
                      make_tuple(4, 4, variance16x16_c, 0),
765
                      make_tuple(4, 3, variance16x8_c, 0),
Johann's avatar
Johann committed
766 767 768 769 770
                      make_tuple(3, 4, variance8x16_c, 0),
                      make_tuple(3, 3, variance8x8_c, 0),
                      make_tuple(3, 2, variance8x4_c, 0),
                      make_tuple(2, 3, variance4x8_c, 0),
                      make_tuple(2, 2, variance4x4_c, 0)));
James Zern's avatar
James Zern committed
771

Johann's avatar
Johann committed
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
#if CONFIG_VP9_HIGHBITDEPTH
typedef MseTest<VarianceMxNFunc> VpxHBDMseTest;
typedef VarianceTest<VarianceMxNFunc> VpxHBDVarianceTest;

TEST_P(VpxHBDMseTest, Ref_mse) { RefTest_mse(); }
TEST_P(VpxHBDMseTest, Max_mse) { MaxTest_mse(); }
TEST_P(VpxHBDVarianceTest, Zero) { ZeroTest(); }
TEST_P(VpxHBDVarianceTest, Ref) { RefTest(); }
TEST_P(VpxHBDVarianceTest, RefStride) { RefStrideTest(); }
TEST_P(VpxHBDVarianceTest, OneQuarter) { OneQuarterTest(); }

/* TODO(debargha): This test does not support the highbd version
const VarianceMxNFunc highbd_12_mse16x16_c = vpx_highbd_12_mse16x16_c;
const VarianceMxNFunc highbd_12_mse16x8_c = vpx_highbd_12_mse16x8_c;
const VarianceMxNFunc highbd_12_mse8x16_c = vpx_highbd_12_mse8x16_c;
const VarianceMxNFunc highbd_12_mse8x8_c = vpx_highbd_12_mse8x8_c;

const VarianceMxNFunc highbd_10_mse16x16_c = vpx_highbd_10_mse16x16_c;
const VarianceMxNFunc highbd_10_mse16x8_c = vpx_highbd_10_mse16x8_c;
const VarianceMxNFunc highbd_10_mse8x16_c = vpx_highbd_10_mse8x16_c;
const VarianceMxNFunc highbd_10_mse8x8_c = vpx_highbd_10_mse8x8_c;

const VarianceMxNFunc highbd_8_mse16x16_c = vpx_highbd_8_mse16x16_c;
const VarianceMxNFunc highbd_8_mse16x8_c = vpx_highbd_8_mse16x8_c;
const VarianceMxNFunc highbd_8_mse8x16_c = vpx_highbd_8_mse8x16_c;
const VarianceMxNFunc highbd_8_mse8x8_c = vpx_highbd_8_mse8x8_c;
798 799

INSTANTIATE_TEST_CASE_P(
Johann's avatar
Johann committed
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 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
    C, VpxHBDMseTest, ::testing::Values(make_tuple(4, 4, highbd_12_mse16x16_c),
                                        make_tuple(4, 4, highbd_12_mse16x8_c),
                                        make_tuple(4, 4, highbd_12_mse8x16_c),
                                        make_tuple(4, 4, highbd_12_mse8x8_c),
                                        make_tuple(4, 4, highbd_10_mse16x16_c),
                                        make_tuple(4, 4, highbd_10_mse16x8_c),
                                        make_tuple(4, 4, highbd_10_mse8x16_c),
                                        make_tuple(4, 4, highbd_10_mse8x8_c),
                                        make_tuple(4, 4, highbd_8_mse16x16_c),
                                        make_tuple(4, 4, highbd_8_mse16x8_c),
                                        make_tuple(4, 4, highbd_8_mse8x16_c),
                                        make_tuple(4, 4, highbd_8_mse8x8_c)));
*/


const VarianceMxNFunc highbd_12_variance64x64_c = vpx_highbd_12_variance64x64_c;
const VarianceMxNFunc highbd_12_variance64x32_c = vpx_highbd_12_variance64x32_c;
const VarianceMxNFunc highbd_12_variance32x64_c = vpx_highbd_12_variance32x64_c;
const VarianceMxNFunc highbd_12_variance32x32_c = vpx_highbd_12_variance32x32_c;
const VarianceMxNFunc highbd_12_variance32x16_c = vpx_highbd_12_variance32x16_c;
const VarianceMxNFunc highbd_12_variance16x32_c = vpx_highbd_12_variance16x32_c;
const VarianceMxNFunc highbd_12_variance16x16_c = vpx_highbd_12_variance16x16_c;
const VarianceMxNFunc highbd_12_variance16x8_c = vpx_highbd_12_variance16x8_c;
const VarianceMxNFunc highbd_12_variance8x16_c = vpx_highbd_12_variance8x16_c;
const VarianceMxNFunc highbd_12_variance8x8_c = vpx_highbd_12_variance8x8_c;
const VarianceMxNFunc highbd_12_variance8x4_c = vpx_highbd_12_variance8x4_c;
const VarianceMxNFunc highbd_12_variance4x8_c = vpx_highbd_12_variance4x8_c;
const VarianceMxNFunc highbd_12_variance4x4_c = vpx_highbd_12_variance4x4_c;

const VarianceMxNFunc highbd_10_variance64x64_c = vpx_highbd_10_variance64x64_c;
const VarianceMxNFunc highbd_10_variance64x32_c = vpx_highbd_10_variance64x32_c;
const VarianceMxNFunc highbd_10_variance32x64_c = vpx_highbd_10_variance32x64_c;
const VarianceMxNFunc highbd_10_variance32x32_c = vpx_highbd_10_variance32x32_c;
const VarianceMxNFunc highbd_10_variance32x16_c = vpx_highbd_10_variance32x16_c;
const VarianceMxNFunc highbd_10_variance16x32_c = vpx_highbd_10_variance16x32_c;
const VarianceMxNFunc highbd_10_variance16x16_c = vpx_highbd_10_variance16x16_c;
const VarianceMxNFunc highbd_10_variance16x8_c = vpx_highbd_10_variance16x8_c;
const VarianceMxNFunc highbd_10_variance8x16_c = vpx_highbd_10_variance8x16_c;
const VarianceMxNFunc highbd_10_variance8x8_c = vpx_highbd_10_variance8x8_c;
const VarianceMxNFunc highbd_10_variance8x4_c = vpx_highbd_10_variance8x4_c;
const VarianceMxNFunc highbd_10_variance4x8_c = vpx_highbd_10_variance4x8_c;
const VarianceMxNFunc highbd_10_variance4x4_c = vpx_highbd_10_variance4x4_c;

const VarianceMxNFunc highbd_8_variance64x64_c = vpx_highbd_8_variance64x64_c;
const VarianceMxNFunc highbd_8_variance64x32_c = vpx_highbd_8_variance64x32_c;
const VarianceMxNFunc highbd_8_variance32x64_c = vpx_highbd_8_variance32x64_c;
const VarianceMxNFunc highbd_8_variance32x32_c = vpx_highbd_8_variance32x32_c;
const VarianceMxNFunc highbd_8_variance32x16_c = vpx_highbd_8_variance32x16_c;
const VarianceMxNFunc highbd_8_variance16x32_c = vpx_highbd_8_variance16x32_c;
const VarianceMxNFunc highbd_8_variance16x16_c = vpx_highbd_8_variance16x16_c;
const VarianceMxNFunc highbd_8_variance16x8_c = vpx_highbd_8_variance16x8_c;
const VarianceMxNFunc highbd_8_variance8x16_c = vpx_highbd_8_variance8x16_c;
const VarianceMxNFunc highbd_8_variance8x8_c = vpx_highbd_8_variance8x8_c;
const VarianceMxNFunc highbd_8_variance8x4_c = vpx_highbd_8_variance8x4_c;
const VarianceMxNFunc highbd_8_variance4x8_c = vpx_highbd_8_variance4x8_c;
const VarianceMxNFunc highbd_8_variance4x4_c = vpx_highbd_8_variance4x4_c;
James Zern's avatar
James Zern committed
856
INSTANTIATE_TEST_CASE_P(
Johann's avatar
Johann committed
857 858 859 860 861 862 863 864 865 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
    C, VpxHBDVarianceTest,
    ::testing::Values(make_tuple(6, 6, highbd_12_variance64x64_c, 12),
                      make_tuple(6, 5, highbd_12_variance64x32_c, 12),
                      make_tuple(5, 6, highbd_12_variance32x64_c, 12),
                      make_tuple(5, 5, highbd_12_variance32x32_c, 12),
                      make_tuple(5, 4, highbd_12_variance32x16_c, 12),
                      make_tuple(4, 5, highbd_12_variance16x32_c, 12),
                      make_tuple(4, 4, highbd_12_variance16x16_c, 12),
                      make_tuple(4, 3, highbd_12_variance16x8_c, 12),
                      make_tuple(3, 4, highbd_12_variance8x16_c, 12),
                      make_tuple(3, 3, highbd_12_variance8x8_c, 12),
                      make_tuple(3, 2, highbd_12_variance8x4_c, 12),
                      make_tuple(2, 3, highbd_12_variance4x8_c, 12),
                      make_tuple(2, 2, highbd_12_variance4x4_c, 12),
                      make_tuple(6, 6, highbd_10_variance64x64_c, 10),
                      make_tuple(6, 5, highbd_10_variance64x32_c, 10),
                      make_tuple(5, 6, highbd_10_variance32x64_c, 10),
                      make_tuple(5, 5, highbd_10_variance32x32_c, 10),
                      make_tuple(5, 4, highbd_10_variance32x16_c, 10),
                      make_tuple(4, 5, highbd_10_variance16x32_c, 10),
                      make_tuple(4, 4, highbd_10_variance16x16_c, 10),
                      make_tuple(4, 3, highbd_10_variance16x8_c, 10),
                      make_tuple(3, 4, highbd_10_variance8x16_c, 10),
                      make_tuple(3, 3, highbd_10_variance8x8_c, 10),
                      make_tuple(3, 2, highbd_10_variance8x4_c, 10),
                      make_tuple(2, 3, highbd_10_variance4x8_c, 10),
                      make_tuple(2, 2, highbd_10_variance4x4_c, 10),
                      make_tuple(6, 6, highbd_8_variance64x64_c, 8),
                      make_tuple(6, 5, highbd_8_variance64x32_c, 8),
                      make_tuple(5, 6, highbd_8_variance32x64_c, 8),
                      make_tuple(5, 5, highbd_8_variance32x32_c, 8),
                      make_tuple(5, 4, highbd_8_variance32x16_c, 8),
                      make_tuple(4, 5, highbd_8_variance16x32_c, 8),
                      make_tuple(4, 4, highbd_8_variance16x16_c, 8),
                      make_tuple(4, 3, highbd_8_variance16x8_c, 8),
                      make_tuple(3, 4, highbd_8_variance8x16_c, 8),
                      make_tuple(3, 3, highbd_8_variance8x8_c, 8),
                      make_tuple(3, 2, highbd_8_variance8x4_c, 8),
                      make_tuple(2, 3, highbd_8_variance4x8_c, 8),
                      make_tuple(2, 2, highbd_8_variance4x4_c, 8)));
#endif  // CONFIG_VP9_HIGHBITDEPTH
James Zern's avatar
James Zern committed
898

James Zern's avatar
James Zern committed
899
#if HAVE_MMX
Johann's avatar
Johann committed
900 901 902 903 904 905 906 907 908 909 910 911
const VarianceMxNFunc mse16x16_mmx = vpx_mse16x16_mmx;
INSTANTIATE_TEST_CASE_P(MMX, VpxMseTest,
                        ::testing::Values(make_tuple(4, 4, mse16x16_mmx)));

INSTANTIATE_TEST_CASE_P(MMX, SumOfSquaresTest,
                        ::testing::Values(vpx_get_mb_ss_mmx));

const VarianceMxNFunc variance16x16_mmx = vpx_variance16x16_mmx;
const VarianceMxNFunc variance16x8_mmx = vpx_variance16x8_mmx;
const VarianceMxNFunc variance8x16_mmx = vpx_variance8x16_mmx;
const VarianceMxNFunc variance8x8_mmx = vpx_variance8x8_mmx;
const VarianceMxNFunc variance4x4_mmx = vpx_variance4x4_mmx;
James Zern's avatar
James Zern committed
912
INSTANTIATE_TEST_CASE_P(
Johann's avatar
Johann committed
913 914
    MMX, VpxVarianceTest,
    ::testing::Values(make_tuple(4, 4, variance16x16_mmx, 0),
915
                      make_tuple(4, 3, variance16x8_mmx, 0),
Johann's avatar
Johann committed
916 917 918 919
                      make_tuple(3, 4, variance8x16_mmx, 0),
                      make_tuple(3, 3, variance8x8_mmx, 0),
                      make_tuple(2, 2, variance4x4_mmx, 0)));
#endif  // HAVE_MMX
James Zern's avatar
James Zern committed
920 921

#if HAVE_SSE2
Johann's avatar
Johann committed
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
INSTANTIATE_TEST_CASE_P(SSE2, SumOfSquaresTest,
                        ::testing::Values(vpx_get_mb_ss_sse2));

const VarianceMxNFunc mse16x16_sse2 = vpx_mse16x16_sse2;
const VarianceMxNFunc mse16x8_sse2 = vpx_mse16x8_sse2;
const VarianceMxNFunc mse8x16_sse2 = vpx_mse8x16_sse2;
const VarianceMxNFunc mse8x8_sse2 = vpx_mse8x8_sse2;
INSTANTIATE_TEST_CASE_P(SSE2, VpxMseTest,
                        ::testing::Values(make_tuple(4, 4, mse16x16_sse2),
                                          make_tuple(4, 3, mse16x8_sse2),
                                          make_tuple(3, 4, mse8x16_sse2),
                                          make_tuple(3, 3, mse8x8_sse2)));

const VarianceMxNFunc variance64x64_sse2 = vpx_variance64x64_sse2;
const VarianceMxNFunc variance64x32_sse2 = vpx_variance64x32_sse2;
const VarianceMxNFunc variance32x64_sse2 = vpx_variance32x64_sse2;
const VarianceMxNFunc variance32x32_sse2 = vpx_variance32x32_sse2;
const VarianceMxNFunc variance32x16_sse2 = vpx_variance32x16_sse2;
const VarianceMxNFunc variance16x32_sse2 = vpx_variance16x32_sse2;
const VarianceMxNFunc variance16x16_sse2 = vpx_variance16x16_sse2;
const VarianceMxNFunc variance16x8_sse2 = vpx_variance16x8_sse2;
const VarianceMxNFunc variance8x16_sse2 = vpx_variance8x16_sse2;
const VarianceMxNFunc variance8x8_sse2 = vpx_variance8x8_sse2;
const VarianceMxNFunc variance8x4_sse2 = vpx_variance8x4_sse2;
const VarianceMxNFunc variance4x8_sse2 = vpx_variance4x8_sse2;
const VarianceMxNFunc variance4x4_sse2 = vpx_variance4x4_sse2;
James Zern's avatar
James Zern committed
948
INSTANTIATE_TEST_CASE_P(
Johann's avatar
Johann committed
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
    SSE2, VpxVarianceTest,
    ::testing::Values(make_tuple(6, 6, variance64x64_sse2, 0),
                      make_tuple(6, 5, variance64x32_sse2, 0),
                      make_tuple(5, 6, variance32x64_sse2, 0),
                      make_tuple(5, 5, variance32x32_sse2, 0),
                      make_tuple(5, 4, variance32x16_sse2, 0),
                      make_tuple(4, 5, variance16x32_sse2, 0),
                      make_tuple(4, 4, variance16x16_sse2, 0),
                      make_tuple(4, 3, variance16x8_sse2, 0),
                      make_tuple(3, 4, variance8x16_sse2, 0),
                      make_tuple(3, 3, variance8x8_sse2, 0),
                      make_tuple(3, 2, variance8x4_sse2, 0),
                      make_tuple(2, 3, variance4x8_sse2, 0),
                      make_tuple(2, 2, variance4x4_sse2, 0)));
#if CONFIG_VP9_HIGHBITDEPTH
/* TODO(debargha): This test does not support the highbd version
const VarianceMxNFunc highbd_12_mse16x16_sse2 = vpx_highbd_12_mse16x16_sse2;
const VarianceMxNFunc highbd_12_mse16x8_sse2 = vpx_highbd_12_mse16x8_sse2;
const VarianceMxNFunc highbd_12_mse8x16_sse2 = vpx_highbd_12_mse8x16_sse2;
const VarianceMxNFunc highbd_12_mse8x8_sse2 = vpx_highbd_12_mse8x8_sse2;

const VarianceMxNFunc highbd_10_mse16x16_sse2 = vpx_highbd_10_mse16x16_sse2;
const VarianceMxNFunc highbd_10_mse16x8_sse2 = vpx_highbd_10_mse16x8_sse2;
const VarianceMxNFunc highbd_10_mse8x16_sse2 = vpx_highbd_10_mse8x16_sse2;
const VarianceMxNFunc highbd_10_mse8x8_sse2 = vpx_highbd_10_mse8x8_sse2;

const VarianceMxNFunc highbd_8_mse16x16_sse2 = vpx_highbd_8_mse16x16_sse2;
const VarianceMxNFunc highbd_8_mse16x8_sse2 = vpx_highbd_8_mse16x8_sse2;
const VarianceMxNFunc highbd_8_mse8x16_sse2 = vpx_highbd_8_mse8x16_sse2;
const VarianceMxNFunc highbd_8_mse8x8_sse2 = vpx_highbd_8_mse8x8_sse2;
James Zern's avatar
James Zern committed
979

Johann's avatar
Johann committed
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
INSTANTIATE_TEST_CASE_P(
    SSE2, VpxHBDMseTest, ::testing::Values(make_tuple(4, 4, highbd_12_mse16x16_sse2),
                                           make_tuple(4, 3, highbd_12_mse16x8_sse2),
                                           make_tuple(3, 4, highbd_12_mse8x16_sse2),
                                           make_tuple(3, 3, highbd_12_mse8x8_sse2),
                                           make_tuple(4, 4, highbd_10_mse16x16_sse2),
                                           make_tuple(4, 3, highbd_10_mse16x8_sse2),
                                           make_tuple(3, 4, highbd_10_mse8x16_sse2),
                                           make_tuple(3, 3, highbd_10_mse8x8_sse2),
                                           make_tuple(4, 4, highbd_8_mse16x16_sse2),
                                           make_tuple(4, 3, highbd_8_mse16x8_sse2),
                                           make_tuple(3, 4, highbd_8_mse8x16_sse2),
                                           make_tuple(3, 3, highbd_8_mse8x8_sse2)));
*/

const VarianceMxNFunc highbd_12_variance64x64_sse2 =
    vpx_highbd_12_variance64x64_sse2;
const VarianceMxNFunc highbd_12_variance64x32_sse2 =
    vpx_highbd_12_variance64x32_sse2;
const VarianceMxNFunc highbd_12_variance32x64_sse2 =
    vpx_highbd_12_variance32x64_sse2;
const VarianceMxNFunc highbd_12_variance32x32_sse2 =
    vpx_highbd_12_variance32x32_sse2;
const VarianceMxNFunc highbd_12_variance32x16_sse2 =
    vpx_highbd_12_variance32x16_sse2;
const VarianceMxNFunc highbd_12_variance16x32_sse2 =
    vpx_highbd_12_variance16x32_sse2;
const VarianceMxNFunc highbd_12_variance16x16_sse2 =
    vpx_highbd_12_variance16x16_sse2;
const VarianceMxNFunc highbd_12_variance16x8_sse2 =
    vpx_highbd_12_variance16x8_sse2;
const VarianceMxNFunc highbd_12_variance8x16_sse2 =
    vpx_highbd_12_variance8x16_sse2;
const VarianceMxNFunc highbd_12_variance8x8_sse2 =
    vpx_highbd_12_variance8x8_sse2;
const VarianceMxNFunc highbd_10_variance64x64_sse2 =
    vpx_highbd_10_variance64x64_sse2;
const VarianceMxNFunc highbd_10_variance64x32_sse2 =
    vpx_highbd_10_variance64x32_sse2;
const VarianceMxNFunc highbd_10_variance32x64_sse2 =
    vpx_highbd_10_variance32x64_sse2;
const VarianceMxNFunc highbd_10_variance32x32_sse2 =
    vpx_highbd_10_variance32x32_sse2;
const VarianceMxNFunc highbd_10_variance32x16_sse2 =
    vpx_highbd_10_variance32x16_sse2;
const VarianceMxNFunc highbd_10_variance16x32_sse2 =
    vpx_highbd_10_variance16x32_sse2;
const VarianceMxNFunc highbd_10_variance16x16_sse2 =
    vpx_highbd_10_variance16x16_sse2;
const VarianceMxNFunc highbd_10_variance16x8_sse2 =
    vpx_highbd_10_variance16x8_sse2;
const VarianceMxNFunc highbd_10_variance8x16_sse2 =
    vpx_highbd_10_variance8x16_sse2;
const VarianceMxNFunc highbd_10_variance8x8_sse2 =
    vpx_highbd_10_variance8x8_sse2;
const VarianceMxNFunc highbd_8_variance64x64_sse2 =
    vpx_highbd_8_variance64x64_sse2;
const VarianceMxNFunc highbd_8_variance64x32_sse2 =
    vpx_highbd_8_variance64x32_sse2;
const VarianceMxNFunc highbd_8_variance32x64_sse2 =
    vpx_highbd_8_variance32x64_sse2;
const VarianceMxNFunc highbd_8_variance32x32_sse2 =
    vpx_highbd_8_variance32x32_sse2;
const VarianceMxNFunc highbd_8_variance32x16_sse2 =
    vpx_highbd_8_variance32x16_sse2;
const VarianceMxNFunc highbd_8_variance16x32_sse2 =
    vpx_highbd_8_variance16x32_sse2;
const VarianceMxNFunc highbd_8_variance16x16_sse2 =
    vpx_highbd_8_variance16x16_sse2;
const VarianceMxNFunc highbd_8_variance16x8_sse2 =
    vpx_highbd_8_variance16x8_sse2;
const VarianceMxNFunc highbd_8_variance8x16_sse2 =
    vpx_highbd_8_variance8x16_sse2;
const VarianceMxNFunc highbd_8_variance8x8_sse2 =
    vpx_highbd_8_variance8x8_sse2;
James Zern's avatar
James Zern committed
1055

Johann's avatar
Johann committed
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
INSTANTIATE_TEST_CASE_P(
    SSE2, VpxHBDVarianceTest,
    ::testing::Values(make_tuple(6, 6, highbd_12_variance64x64_sse2, 12),
                      make_tuple(6, 5, highbd_12_variance64x32_sse2, 12),
                      make_tuple(5, 6, highbd_12_variance32x64_sse2, 12),
                      make_tuple(5, 5, highbd_12_variance32x32_sse2, 12),
                      make_tuple(5, 4, highbd_12_variance32x16_sse2, 12),
                      make_tuple(4, 5, highbd_12_variance16x32_sse2, 12),
                      make_tuple(4, 4, highbd_12_variance16x16_sse2, 12),
                      make_tuple(4, 3, highbd_12_variance16x8_sse2, 12),
                      make_tuple(3, 4, highbd_12_variance8x16_sse2, 12),
                      make_tuple(3, 3, highbd_12_variance8x8_sse2, 12),
                      make_tuple(6, 6, highbd_10_variance64x64_sse2, 10),
                      make_tuple(6, 5, highbd_10_variance64x32_sse2, 10),
                      make_tuple(5, 6, highbd_10_variance32x64_sse2, 10),
                      make_tuple(5, 5, highbd_10_variance32x32_sse2, 10),
                      make_tuple(5, 4, highbd_10_variance32x16_sse2, 10),
                      make_tuple(4, 5, highbd_10_variance16x32_sse2, 10),
                      make_tuple(4, 4, highbd_10_variance16x16_sse2, 10),
                      make_tuple(4, 3, highbd_10_variance16x8_sse2, 10),
                      make_tuple(3, 4, highbd_10_variance8x16_sse2, 10),
                      make_tuple(3, 3, highbd_10_variance8x8_sse2, 10),
                      make_tuple(6, 6, highbd_8_variance64x64_sse2, 8),
                      make_tuple(6, 5, highbd_8_variance64x32_sse2, 8),
                      make_tuple(5, 6, highbd_8_variance32x64_sse2, 8),
                      make_tuple(5, 5, highbd_8_variance32x32_sse2, 8),
                      make_tuple(5, 4, highbd_8_variance32x16_sse2, 8),
                      make_tuple(4, 5, highbd_8_variance16x32_sse2, 8),
                      make_tuple(4, 4, highbd_8_variance16x16_sse2, 8),
                      make_tuple(4, 3, highbd_8_variance16x8_sse2, 8),
                      make_tuple(3, 4, highbd_8_variance8x16_sse2, 8),
                      make_tuple(3, 3, highbd_8_variance8x8_sse2, 8)));
#endif  // CONFIG_VP9_HIGHBITDEPTH
#endif  // HAVE_SSE2
James Zern's avatar
James Zern committed
1090 1091

#if CONFIG_VP9_ENCODER
1092
typedef SubpelVarianceTest<vp9_subpixvariance_fn_t> VP9SubpelVarianceTest;
1093
typedef SubpelVarianceTest<vp9_subp_avg_variance_fn_t> VP9SubpelAvgVarianceTest;
James Zern's avatar
James Zern committed
1094

1095
TEST_P(VP9SubpelVarianceTest, Ref) { RefTest(); }
1096
TEST_P(VP9SubpelVarianceTest, ExtremeRef) { ExtremeRefTest(); }
1097
TEST_P(VP9SubpelAvgVarianceTest, Ref) { RefTest(); }
James Zern's avatar
James Zern committed
1098

1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
#if CONFIG_VP9_HIGHBITDEPTH
typedef SubpelVarianceTest<vp9_subpixvariance_fn_t> VP9SubpelVarianceHighTest;
typedef SubpelVarianceTest<vp9_subp_avg_variance_fn_t>
    VP9SubpelAvgVarianceHighTest;

TEST_P(VP9SubpelVarianceHighTest, Ref) { RefTest(); }
TEST_P(VP9SubpelVarianceHighTest, ExtremeRef) { ExtremeRefTest(); }
TEST_P(VP9SubpelAvgVarianceHighTest, Ref) { RefTest(); }
#endif  // CONFIG_VP9_HIGHBITDEPTH

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
const vp9_subpixvariance_fn_t subpel_variance4x4_c =
    vp9_sub_pixel_variance4x4_c;
const vp9_subpixvariance_fn_t subpel_variance4x8_c =
    vp9_sub_pixel_variance4x8_c;
const vp9_subpixvariance_fn_t subpel_variance8x4_c =
    vp9_sub_pixel_variance8x4_c;
const vp9_subpixvariance_fn_t subpel_variance8x8_c =
    vp9_sub_pixel_variance8x8_c;
const vp9_subpixvariance_fn_t subpel_variance8x16_c =
    vp9_sub_pixel_variance8x16_c;
const vp9_subpixvariance_fn_t subpel_variance16x8_c =
    vp9_sub_pixel_variance16x8_c;
const vp9_subpixvariance_fn_t subpel_variance16x16_c =
    vp9_sub_pixel_variance16x16_c;
const vp9_subpixvariance_fn_t subpel_variance16x32_c =
    vp9_sub_pixel_variance16x32_c;
const vp9_subpixvariance_fn_t subpel_variance32x16_c =
    vp9_sub_pixel_variance32x16_c;
const vp9_subpixvariance_fn_t subpel_variance32x32_c =
    vp9_sub_pixel_variance32x32_c;
const vp9_subpixvariance_fn_t subpel_variance32x64_c =
    vp9_sub_pixel_variance32x64_c;
const vp9_subpixvariance_fn_t subpel_variance64x32_c =
    vp9_sub_pixel_variance64x32_c;
const vp9_subpixvariance_fn_t subpel_variance64x64_c =
    vp9_sub_pixel_variance64x64_c;
1135 1136
INSTANTIATE_TEST_CASE_P(
    C, VP9SubpelVarianceTest,
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
    ::testing::Values(make_tuple(2, 2, subpel_variance4x4_c, 0),
                      make_tuple(2, 3, subpel_variance4x8_c, 0),
                      make_tuple(3, 2, subpel_variance8x4_c, 0),
                      make_tuple(3, 3, subpel_variance8x8_c, 0),
                      make_tuple(3, 4, subpel_variance8x16_c, 0),
                      make_tuple(4, 3, subpel_variance16x8_c, 0),
                      make_tuple(4, 4, subpel_variance16x16_c, 0),
                      make_tuple(4, 5, subpel_variance16x32_c, 0),
                      make_tuple(5, 4, subpel_variance32x16_c, 0),
                      make_tuple(5, 5, subpel_variance32x32_c, 0),
                      make_tuple(5, 6, subpel_variance32x64_c, 0),
                      make_tuple(6, 5, subpel_variance64x32_c, 0),
                      make_tuple(6, 6, subpel_variance64x64_c, 0)));
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
const vp9_subp_avg_variance_fn_t subpel_avg_variance4x4_c =
    vp9_sub_pixel_avg_variance4x4_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance4x8_c =
    vp9_sub_pixel_avg_variance4x8_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance8x4_c =
    vp9_sub_pixel_avg_variance8x4_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance8x8_c =
    vp9_sub_pixel_avg_variance8x8_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance8x16_c =
    vp9_sub_pixel_avg_variance8x16_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance16x8_c =
    vp9_sub_pixel_avg_variance16x8_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance16x16_c =
    vp9_sub_pixel_avg_variance16x16_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance16x32_c =
    vp9_sub_pixel_avg_variance16x32_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance32x16_c =
    vp9_sub_pixel_avg_variance32x16_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance32x32_c =
    vp9_sub_pixel_avg_variance32x32_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance32x64_c =
    vp9_sub_pixel_avg_variance32x64_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance64x32_c =
    vp9_sub_pixel_avg_variance64x32_c;
const vp9_subp_avg_variance_fn_t subpel_avg_variance64x64_c =
    vp9_sub_pixel_avg_variance64x64_c;
1176