convolve_test.cc 26.4 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2010 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
#include <string.h>
James Zern's avatar
James Zern committed
12 13 14 15
#include "test/acm_random.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
John Koleszar's avatar
John Koleszar committed
16 17 18

#include "./vpx_config.h"
#include "./vp9_rtcd.h"
19
#include "vp9/common/vp9_filter.h"
20
#include "vpx_mem/vpx_mem.h"
21
#include "vpx_ports/mem.h"
John Koleszar's avatar
John Koleszar committed
22 23

namespace {
24 25
typedef void (*convolve_fn_t)(const uint8_t *src, ptrdiff_t src_stride,
                              uint8_t *dst, ptrdiff_t dst_stride,
John Koleszar's avatar
John Koleszar committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
                              const int16_t *filter_x, int filter_x_stride,
                              const int16_t *filter_y, int filter_y_stride,
                              int w, int h);

struct ConvolveFunctions {
  ConvolveFunctions(convolve_fn_t h8, convolve_fn_t h8_avg,
                    convolve_fn_t v8, convolve_fn_t v8_avg,
                    convolve_fn_t hv8, convolve_fn_t hv8_avg)
      : h8_(h8), v8_(v8), hv8_(hv8), h8_avg_(h8_avg), v8_avg_(v8_avg),
        hv8_avg_(hv8_avg) {}

  convolve_fn_t h8_;
  convolve_fn_t v8_;
  convolve_fn_t hv8_;
  convolve_fn_t h8_avg_;
  convolve_fn_t v8_avg_;
  convolve_fn_t hv8_avg_;
};

45 46
typedef std::tr1::tuple<int, int, const ConvolveFunctions*> convolve_param_t;

John Koleszar's avatar
John Koleszar committed
47 48 49
// Reference 8-tap subpixel filter, slightly modified to fit into this test.
#define VP9_FILTER_WEIGHT 128
#define VP9_FILTER_SHIFT 7
James Zern's avatar
James Zern committed
50
uint8_t clip_pixel(int x) {
John Koleszar's avatar
John Koleszar committed
51 52 53 54 55
  return x < 0 ? 0 :
         x > 255 ? 255 :
         x;
}

James Zern's avatar
James Zern committed
56 57 58 59 60 61 62 63
void filter_block2d_8_c(const uint8_t *src_ptr,
                        const unsigned int src_stride,
                        const int16_t *HFilter,
                        const int16_t *VFilter,
                        uint8_t *dst_ptr,
                        unsigned int dst_stride,
                        unsigned int output_width,
                        unsigned int output_height) {
John Koleszar's avatar
John Koleszar committed
64 65 66 67 68 69
  // Between passes, we use an intermediate buffer whose height is extended to
  // have enough horizontally filtered values as input for the vertical pass.
  // This buffer is allocated to be big enough for the largest block type we
  // support.
  const int kInterp_Extend = 4;
  const unsigned int intermediate_height =
James Zern's avatar
James Zern committed
70
      (kInterp_Extend - 1) + output_height + kInterp_Extend;
John Koleszar's avatar
John Koleszar committed
71 72 73 74 75 76 77 78

  /* Size of intermediate_buffer is max_intermediate_height * filter_max_width,
   * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
   *                                 + kInterp_Extend
   *                               = 3 + 16 + 4
   *                               = 23
   * and filter_max_width = 16
   */
79
  uint8_t intermediate_buffer[71 * 64];
John Koleszar's avatar
John Koleszar committed
80 81 82 83 84 85 86 87 88 89 90
  const int intermediate_next_stride = 1 - intermediate_height * output_width;

  // Horizontal pass (src -> transposed intermediate).
  {
    uint8_t *output_ptr = intermediate_buffer;
    const int src_next_row_stride = src_stride - output_width;
    unsigned int i, j;
    src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
    for (i = 0; i < intermediate_height; ++i) {
      for (j = 0; j < output_width; ++j) {
        // Apply filter...
James Zern's avatar
James Zern committed
91 92 93 94 95 96 97 98 99
        const int temp = (src_ptr[0] * HFilter[0]) +
                         (src_ptr[1] * HFilter[1]) +
                         (src_ptr[2] * HFilter[2]) +
                         (src_ptr[3] * HFilter[3]) +
                         (src_ptr[4] * HFilter[4]) +
                         (src_ptr[5] * HFilter[5]) +
                         (src_ptr[6] * HFilter[6]) +
                         (src_ptr[7] * HFilter[7]) +
                         (VP9_FILTER_WEIGHT >> 1);  // Rounding
John Koleszar's avatar
John Koleszar committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

        // Normalize back to 0-255...
        *output_ptr = clip_pixel(temp >> VP9_FILTER_SHIFT);
        ++src_ptr;
        output_ptr += intermediate_height;
      }
      src_ptr += src_next_row_stride;
      output_ptr += intermediate_next_stride;
    }
  }

  // Vertical pass (transposed intermediate -> dst).
  {
    uint8_t *src_ptr = intermediate_buffer;
    const int dst_next_row_stride = dst_stride - output_width;
    unsigned int i, j;
    for (i = 0; i < output_height; ++i) {
      for (j = 0; j < output_width; ++j) {
        // Apply filter...
James Zern's avatar
James Zern committed
119 120 121 122 123 124 125 126 127
        const int temp = (src_ptr[0] * VFilter[0]) +
                         (src_ptr[1] * VFilter[1]) +
                         (src_ptr[2] * VFilter[2]) +
                         (src_ptr[3] * VFilter[3]) +
                         (src_ptr[4] * VFilter[4]) +
                         (src_ptr[5] * VFilter[5]) +
                         (src_ptr[6] * VFilter[6]) +
                         (src_ptr[7] * VFilter[7]) +
                         (VP9_FILTER_WEIGHT >> 1);  // Rounding
John Koleszar's avatar
John Koleszar committed
128 129 130 131 132 133 134 135 136 137 138

        // Normalize back to 0-255...
        *dst_ptr++ = clip_pixel(temp >> VP9_FILTER_SHIFT);
        src_ptr += intermediate_height;
      }
      src_ptr += intermediate_next_stride;
      dst_ptr += dst_next_row_stride;
    }
  }
}

James Zern's avatar
James Zern committed
139 140 141 142 143 144
void block2d_average_c(uint8_t *src,
                       unsigned int src_stride,
                       uint8_t *output_ptr,
                       unsigned int output_stride,
                       unsigned int output_width,
                       unsigned int output_height) {
John Koleszar's avatar
John Koleszar committed
145 146 147 148 149 150 151 152 153
  unsigned int i, j;
  for (i = 0; i < output_height; ++i) {
    for (j = 0; j < output_width; ++j) {
      output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
    }
    output_ptr += output_stride;
  }
}

James Zern's avatar
James Zern committed
154 155 156 157 158 159 160 161 162
void filter_average_block2d_8_c(const uint8_t *src_ptr,
                                const unsigned int src_stride,
                                const int16_t *HFilter,
                                const int16_t *VFilter,
                                uint8_t *dst_ptr,
                                unsigned int dst_stride,
                                unsigned int output_width,
                                unsigned int output_height) {
  uint8_t tmp[64 * 64];
John Koleszar's avatar
John Koleszar committed
163

164 165 166
  assert(output_width <= 64);
  assert(output_height <= 64);
  filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, 64,
John Koleszar's avatar
John Koleszar committed
167
                     output_width, output_height);
168
  block2d_average_c(tmp, 64, dst_ptr, dst_stride,
John Koleszar's avatar
John Koleszar committed
169 170 171
                    output_width, output_height);
}

172
class ConvolveTest : public ::testing::TestWithParam<convolve_param_t> {
173 174 175 176
 public:
  static void SetUpTestCase() {
    // Force input_ to be unaligned, output to be 16 byte aligned.
    input_ = reinterpret_cast<uint8_t*>(
177
        vpx_memalign(kDataAlignment, kInputBufferSize + 1)) + 1;
178
    output_ = reinterpret_cast<uint8_t*>(
179
        vpx_memalign(kDataAlignment, kOutputBufferSize));
180 181 182 183 184 185 186 187 188
  }

  static void TearDownTestCase() {
    vpx_free(input_ - 1);
    input_ = NULL;
    vpx_free(output_);
    output_ = NULL;
  }

James Zern's avatar
James Zern committed
189 190
 protected:
  static const int kDataAlignment = 16;
191
  static const int kOuterBlockSize = 256;
James Zern's avatar
James Zern committed
192 193 194 195 196 197 198 199 200 201 202 203 204
  static const int kInputStride = kOuterBlockSize;
  static const int kOutputStride = kOuterBlockSize;
  static const int kMaxDimension = 64;
  static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;
  static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;

  int Width() const { return GET_PARAM(0); }
  int Height() const { return GET_PARAM(1); }
  int BorderLeft() const {
    const int center = (kOuterBlockSize - Width()) / 2;
    return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);
  }
  int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }
John Koleszar's avatar
John Koleszar committed
205

James Zern's avatar
James Zern committed
206 207 208 209 210 211
  bool IsIndexInBorder(int i) {
    return (i < BorderTop() * kOuterBlockSize ||
            i >= (BorderTop() + Height()) * kOuterBlockSize ||
            i % kOuterBlockSize < BorderLeft() ||
            i % kOuterBlockSize >= (BorderLeft() + Width()));
  }
John Koleszar's avatar
John Koleszar committed
212

James Zern's avatar
James Zern committed
213 214
  virtual void SetUp() {
    UUT_ = GET_PARAM(2);
Johann's avatar
Johann committed
215
    /* Set up guard blocks for an inner block centered in the outer block */
James Zern's avatar
James Zern committed
216 217 218 219 220
    for (int i = 0; i < kOutputBufferSize; ++i) {
      if (IsIndexInBorder(i))
        output_[i] = 255;
      else
        output_[i] = 0;
John Koleszar's avatar
John Koleszar committed
221 222
    }

James Zern's avatar
James Zern committed
223
    ::libvpx_test::ACMRandom prng;
224 225 226 227 228 229
    for (int i = 0; i < kInputBufferSize; ++i) {
      if (i & 1)
        input_[i] = 255;
      else
        input_[i] = prng.Rand8Extremes();
    }
James Zern's avatar
James Zern committed
230
  }
John Koleszar's avatar
John Koleszar committed
231

232 233 234 235
  void SetConstantInput(int value) {
    memset(input_, value, kInputBufferSize);
  }

James Zern's avatar
James Zern committed
236 237 238 239
  void CheckGuardBlocks() {
    for (int i = 0; i < kOutputBufferSize; ++i) {
      if (IsIndexInBorder(i))
        EXPECT_EQ(255, output_[i]);
John Koleszar's avatar
John Koleszar committed
240
    }
James Zern's avatar
James Zern committed
241
  }
John Koleszar's avatar
John Koleszar committed
242

James Zern's avatar
James Zern committed
243 244 245
  uint8_t* input() const {
    return input_ + BorderTop() * kOuterBlockSize + BorderLeft();
  }
John Koleszar's avatar
John Koleszar committed
246

James Zern's avatar
James Zern committed
247 248 249 250 251 252 253
  uint8_t* output() const {
    return output_ + BorderTop() * kOuterBlockSize + BorderLeft();
  }

  const ConvolveFunctions* UUT_;
  static uint8_t* input_;
  static uint8_t* output_;
John Koleszar's avatar
John Koleszar committed
254
};
255 256
uint8_t* ConvolveTest::input_ = NULL;
uint8_t* ConvolveTest::output_ = NULL;
John Koleszar's avatar
John Koleszar committed
257 258 259 260 261 262 263 264

TEST_P(ConvolveTest, GuardBlocks) {
  CheckGuardBlocks();
}

TEST_P(ConvolveTest, CopyHoriz) {
  uint8_t* const in = input();
  uint8_t* const out = output();
265
  DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar's avatar
John Koleszar committed
266

267
  ASM_REGISTER_STATE_CHECK(
John Koleszar's avatar
John Koleszar committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281
      UUT_->h8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
                Width(), Height()));

  CheckGuardBlocks();

  for (int y = 0; y < Height(); ++y)
    for (int x = 0; x < Width(); ++x)
      ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
          << "(" << x << "," << y << ")";
}

TEST_P(ConvolveTest, CopyVert) {
  uint8_t* const in = input();
  uint8_t* const out = output();
282
  DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar's avatar
John Koleszar committed
283

284
  ASM_REGISTER_STATE_CHECK(
John Koleszar's avatar
John Koleszar committed
285 286 287 288 289 290 291 292 293 294 295 296 297 298
      UUT_->v8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
                Width(), Height()));

  CheckGuardBlocks();

  for (int y = 0; y < Height(); ++y)
    for (int x = 0; x < Width(); ++x)
      ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
          << "(" << x << "," << y << ")";
}

TEST_P(ConvolveTest, Copy2D) {
  uint8_t* const in = input();
  uint8_t* const out = output();
299
  DECLARE_ALIGNED(256, const int16_t, filter8[8]) = {0, 0, 0, 128, 0, 0, 0, 0};
John Koleszar's avatar
John Koleszar committed
300

301
  ASM_REGISTER_STATE_CHECK(
John Koleszar's avatar
John Koleszar committed
302 303 304 305 306 307 308 309 310 311 312
      UUT_->hv8_(in, kInputStride, out, kOutputStride, filter8, 16, filter8, 16,
                 Width(), Height()));

  CheckGuardBlocks();

  for (int y = 0; y < Height(); ++y)
    for (int x = 0; x < Width(); ++x)
      ASSERT_EQ(out[y * kOutputStride + x], in[y * kInputStride + x])
          << "(" << x << "," << y << ")";
}

313
const int kNumFilterBanks = 4;
314 315 316 317
const int kNumFilters = 16;

TEST(ConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
  for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
318 319
    const InterpKernel *filters =
        vp9_get_interp_kernel(static_cast<INTERP_FILTER>(filter_bank));
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    for (int i = 0; i < kNumFilters; i++) {
      const int p0 = filters[i][0] + filters[i][1];
      const int p1 = filters[i][2] + filters[i][3];
      const int p2 = filters[i][4] + filters[i][5];
      const int p3 = filters[i][6] + filters[i][7];
      EXPECT_LE(p0, 128);
      EXPECT_LE(p1, 128);
      EXPECT_LE(p2, 128);
      EXPECT_LE(p3, 128);
      EXPECT_LE(p0 + p3, 128);
      EXPECT_LE(p0 + p3 + p1, 128);
      EXPECT_LE(p0 + p3 + p1 + p2, 128);
      EXPECT_EQ(p0 + p1 + p2 + p3, 128);
    }
  }
}
336

337 338
const int16_t kInvalidFilter[8] = { 0 };

John Koleszar's avatar
John Koleszar committed
339 340 341 342 343
TEST_P(ConvolveTest, MatchesReferenceSubpixelFilter) {
  uint8_t* const in = input();
  uint8_t* const out = output();
  uint8_t ref[kOutputStride * kMaxDimension];

344 345

  for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
346 347
    const InterpKernel *filters =
        vp9_get_interp_kernel(static_cast<INTERP_FILTER>(filter_bank));
348 349 350
    const InterpKernel *const eighttap_smooth =
        vp9_get_interp_kernel(EIGHTTAP_SMOOTH);

351 352 353 354 355 356 357
    for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
      for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
        filter_block2d_8_c(in, kInputStride,
                           filters[filter_x], filters[filter_y],
                           ref, kOutputStride,
                           Width(), Height());

358
        if (filters == eighttap_smooth || (filter_x && filter_y))
359
          ASM_REGISTER_STATE_CHECK(
360 361 362 363
              UUT_->hv8_(in, kInputStride, out, kOutputStride,
                         filters[filter_x], 16, filters[filter_y], 16,
                         Width(), Height()));
        else if (filter_y)
364
          ASM_REGISTER_STATE_CHECK(
365
              UUT_->v8_(in, kInputStride, out, kOutputStride,
366
                        kInvalidFilter, 16, filters[filter_y], 16,
367 368
                        Width(), Height()));
        else
369
          ASM_REGISTER_STATE_CHECK(
370
              UUT_->h8_(in, kInputStride, out, kOutputStride,
371
                        filters[filter_x], 16, kInvalidFilter, 16,
372 373 374 375 376 377 378 379 380 381 382
                        Width(), Height()));

        CheckGuardBlocks();

        for (int y = 0; y < Height(); ++y)
          for (int x = 0; x < Width(); ++x)
            ASSERT_EQ(ref[y * kOutputStride + x], out[y * kOutputStride + x])
                << "mismatch at (" << x << "," << y << "), "
                << "filters (" << filter_bank << ","
                << filter_x << "," << filter_y << ")";
      }
John Koleszar's avatar
John Koleszar committed
383 384 385 386 387 388 389 390 391 392 393 394 395
    }
  }
}

TEST_P(ConvolveTest, MatchesReferenceAveragingSubpixelFilter) {
  uint8_t* const in = input();
  uint8_t* const out = output();
  uint8_t ref[kOutputStride * kMaxDimension];

  // Populate ref and out with some random data
  ::libvpx_test::ACMRandom prng;
  for (int y = 0; y < Height(); ++y) {
    for (int x = 0; x < Width(); ++x) {
396
      const uint8_t r = prng.Rand8Extremes();
John Koleszar's avatar
John Koleszar committed
397 398 399 400 401 402

      out[y * kOutputStride + x] = r;
      ref[y * kOutputStride + x] = r;
    }
  }

403
  for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
404 405
    const InterpKernel *filters =
        vp9_get_interp_kernel(static_cast<INTERP_FILTER>(filter_bank));
406 407
    const InterpKernel *const eighttap_smooth =
        vp9_get_interp_kernel(EIGHTTAP_SMOOTH);
408 409 410 411 412 413 414 415

    for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
      for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
        filter_average_block2d_8_c(in, kInputStride,
                                   filters[filter_x], filters[filter_y],
                                   ref, kOutputStride,
                                   Width(), Height());

416
        if (filters == eighttap_smooth || (filter_x && filter_y))
417
          ASM_REGISTER_STATE_CHECK(
418 419 420 421
              UUT_->hv8_avg_(in, kInputStride, out, kOutputStride,
                             filters[filter_x], 16, filters[filter_y], 16,
                             Width(), Height()));
        else if (filter_y)
422
          ASM_REGISTER_STATE_CHECK(
423 424 425 426
              UUT_->v8_avg_(in, kInputStride, out, kOutputStride,
                            filters[filter_x], 16, filters[filter_y], 16,
                            Width(), Height()));
        else
427
          ASM_REGISTER_STATE_CHECK(
428 429 430 431 432 433 434 435 436 437 438 439 440
              UUT_->h8_avg_(in, kInputStride, out, kOutputStride,
                            filters[filter_x], 16, filters[filter_y], 16,
                            Width(), Height()));

        CheckGuardBlocks();

        for (int y = 0; y < Height(); ++y)
          for (int x = 0; x < Width(); ++x)
            ASSERT_EQ(ref[y * kOutputStride + x], out[y * kOutputStride + x])
                << "mismatch at (" << x << "," << y << "), "
                << "filters (" << filter_bank << ","
                << filter_x << "," << filter_y << ")";
      }
John Koleszar's avatar
John Koleszar committed
441 442 443 444
    }
  }
}

445
DECLARE_ALIGNED(256, const int16_t, kChangeFilters[16][8]) = {
John Koleszar's avatar
John Koleszar committed
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    { 0,   0,   0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0, 128},
    { 0,   0,   0, 128},
    { 0,   0, 128},
    { 0, 128},
    { 128},
    { 0,   0,   0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0,   0, 128},
    { 0,   0,   0,   0, 128},
    { 0,   0,   0, 128},
    { 0,   0, 128},
    { 0, 128},
461 462 463
    { 128}
};

464
/* This test exercises the horizontal and vertical filter functions. */
465 466 467
TEST_P(ConvolveTest, ChangeFilterWorks) {
  uint8_t* const in = input();
  uint8_t* const out = output();
468 469 470 471 472 473 474 475 476 477 478

  /* Assume that the first input sample is at the 8/16th position. */
  const int kInitialSubPelOffset = 8;

  /* Filters are 8-tap, so the first filter tap will be applied to the pixel
   * at position -3 with respect to the current filtering position. Since
   * kInitialSubPelOffset is set to 8, we first select sub-pixel filter 8,
   * which is non-zero only in the last tap. So, applying the filter at the
   * current input position will result in an output equal to the pixel at
   * offset +4 (-3 + 7) with respect to the current filtering position.
   */
479
  const int kPixelSelected = 4;
John Koleszar's avatar
John Koleszar committed
480

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  /* Assume that each output pixel requires us to step on by 17/16th pixels in
   * the input.
   */
  const int kInputPixelStep = 17;

  /* The filters are setup in such a way that the expected output produces
   * sets of 8 identical output samples. As the filter position moves to the
   * next 1/16th pixel position the only active (=128) filter tap moves one
   * position to the left, resulting in the same input pixel being replicated
   * in to the output for 8 consecutive samples. After each set of 8 positions
   * the filters select a different input pixel. kFilterPeriodAdjust below
   * computes which input pixel is written to the output for a specified
   * x or y position.
   */

  /* Test the horizontal filter. */
497 498 499 500
  ASM_REGISTER_STATE_CHECK(
      UUT_->h8_(in, kInputStride, out, kOutputStride,
                kChangeFilters[kInitialSubPelOffset],
                kInputPixelStep, NULL, 0, Width(), Height()));
John Koleszar's avatar
John Koleszar committed
501

502
  for (int x = 0; x < Width(); ++x) {
503
    const int kFilterPeriodAdjust = (x >> 3) << 3;
504 505 506 507 508
    const int ref_x =
        kPixelSelected + ((kInitialSubPelOffset
            + kFilterPeriodAdjust * kInputPixelStep)
                          >> SUBPEL_BITS);
    ASSERT_EQ(in[ref_x], out[x]) << "x == " << x << "width = " << Width();
John Koleszar's avatar
John Koleszar committed
509 510
  }

511
  /* Test the vertical filter. */
512 513 514 515
  ASM_REGISTER_STATE_CHECK(
      UUT_->v8_(in, kInputStride, out, kOutputStride,
                NULL, 0, kChangeFilters[kInitialSubPelOffset],
                kInputPixelStep, Width(), Height()));
John Koleszar's avatar
John Koleszar committed
516

517
  for (int y = 0; y < Height(); ++y) {
518
    const int kFilterPeriodAdjust = (y >> 3) << 3;
519 520 521 522
    const int ref_y =
        kPixelSelected + ((kInitialSubPelOffset
            + kFilterPeriodAdjust * kInputPixelStep)
                          >> SUBPEL_BITS);
523
    ASSERT_EQ(in[ref_y * kInputStride], out[y * kInputStride]) << "y == " << y;
John Koleszar's avatar
John Koleszar committed
524 525
  }

526
  /* Test the horizontal and vertical filters in combination. */
527 528 529 530 531
  ASM_REGISTER_STATE_CHECK(
      UUT_->hv8_(in, kInputStride, out, kOutputStride,
                 kChangeFilters[kInitialSubPelOffset], kInputPixelStep,
                 kChangeFilters[kInitialSubPelOffset], kInputPixelStep,
                 Width(), Height()));
John Koleszar's avatar
John Koleszar committed
532

533
  for (int y = 0; y < Height(); ++y) {
534
    const int kFilterPeriodAdjustY = (y >> 3) << 3;
535 536 537 538
    const int ref_y =
        kPixelSelected + ((kInitialSubPelOffset
            + kFilterPeriodAdjustY * kInputPixelStep)
                          >> SUBPEL_BITS);
539
    for (int x = 0; x < Width(); ++x) {
540
      const int kFilterPeriodAdjustX = (x >> 3) << 3;
541 542 543 544
      const int ref_x =
          kPixelSelected + ((kInitialSubPelOffset
              + kFilterPeriodAdjustX * kInputPixelStep)
                            >> SUBPEL_BITS);
545 546

      ASSERT_EQ(in[ref_y * kInputStride + ref_x], out[y * kOutputStride + x])
John Koleszar's avatar
John Koleszar committed
547 548 549 550 551
          << "x == " << x << ", y == " << y;
    }
  }
}

552 553 554 555 556
/* This test exercises that enough rows and columns are filtered with every
   possible initial fractional positions and scaling steps. */
TEST_P(ConvolveTest, CheckScalingFiltering) {
  uint8_t* const in = input();
  uint8_t* const out = output();
557
  const InterpKernel *const eighttap = vp9_get_interp_kernel(EIGHTTAP);
558 559 560 561 562 563

  SetConstantInput(127);

  for (int frac = 0; frac < 16; ++frac) {
    for (int step = 1; step <= 32; ++step) {
      /* Test the horizontal and vertical filters in combination. */
564 565 566 567
      ASM_REGISTER_STATE_CHECK(UUT_->hv8_(in, kInputStride, out, kOutputStride,
                                          eighttap[frac], step,
                                          eighttap[frac], step,
                                          Width(), Height()));
568 569 570 571 572 573 574 575 576 577 578 579 580 581

      CheckGuardBlocks();

      for (int y = 0; y < Height(); ++y) {
        for (int x = 0; x < Width(); ++x) {
          ASSERT_EQ(in[y * kInputStride + x], out[y * kOutputStride + x])
              << "x == " << x << ", y == " << y
              << ", frac == " << frac << ", step == " << step;
        }
      }
    }
  }
}

John Koleszar's avatar
John Koleszar committed
582 583 584 585 586 587 588 589 590 591
using std::tr1::make_tuple;

const ConvolveFunctions convolve8_c(
    vp9_convolve8_horiz_c, vp9_convolve8_avg_horiz_c,
    vp9_convolve8_vert_c, vp9_convolve8_avg_vert_c,
    vp9_convolve8_c, vp9_convolve8_avg_c);

INSTANTIATE_TEST_CASE_P(C, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_c),
    make_tuple(8, 4, &convolve8_c),
592
    make_tuple(4, 8, &convolve8_c),
John Koleszar's avatar
John Koleszar committed
593
    make_tuple(8, 8, &convolve8_c),
594
    make_tuple(16, 8, &convolve8_c),
595 596 597 598 599 600 601 602
    make_tuple(8, 16, &convolve8_c),
    make_tuple(16, 16, &convolve8_c),
    make_tuple(32, 16, &convolve8_c),
    make_tuple(16, 32, &convolve8_c),
    make_tuple(32, 32, &convolve8_c),
    make_tuple(64, 32, &convolve8_c),
    make_tuple(32, 64, &convolve8_c),
    make_tuple(64, 64, &convolve8_c)));
603

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
#if HAVE_SSE2
const ConvolveFunctions convolve8_sse2(
    vp9_convolve8_horiz_sse2, vp9_convolve8_avg_horiz_sse2,
    vp9_convolve8_vert_sse2, vp9_convolve8_avg_vert_sse2,
    vp9_convolve8_sse2, vp9_convolve8_avg_sse2);

INSTANTIATE_TEST_CASE_P(SSE2, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_sse2),
    make_tuple(8, 4, &convolve8_sse2),
    make_tuple(4, 8, &convolve8_sse2),
    make_tuple(8, 8, &convolve8_sse2),
    make_tuple(16, 8, &convolve8_sse2),
    make_tuple(8, 16, &convolve8_sse2),
    make_tuple(16, 16, &convolve8_sse2),
    make_tuple(32, 16, &convolve8_sse2),
    make_tuple(16, 32, &convolve8_sse2),
    make_tuple(32, 32, &convolve8_sse2),
    make_tuple(64, 32, &convolve8_sse2),
    make_tuple(32, 64, &convolve8_sse2),
    make_tuple(64, 64, &convolve8_sse2)));
#endif

626 627
#if HAVE_SSSE3
const ConvolveFunctions convolve8_ssse3(
628 629 630
    vp9_convolve8_horiz_ssse3, vp9_convolve8_avg_horiz_ssse3,
    vp9_convolve8_vert_ssse3, vp9_convolve8_avg_vert_ssse3,
    vp9_convolve8_ssse3, vp9_convolve8_avg_ssse3);
631 632 633 634

INSTANTIATE_TEST_CASE_P(SSSE3, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_ssse3),
    make_tuple(8, 4, &convolve8_ssse3),
635
    make_tuple(4, 8, &convolve8_ssse3),
636
    make_tuple(8, 8, &convolve8_ssse3),
637
    make_tuple(16, 8, &convolve8_ssse3),
638 639 640 641 642 643 644 645
    make_tuple(8, 16, &convolve8_ssse3),
    make_tuple(16, 16, &convolve8_ssse3),
    make_tuple(32, 16, &convolve8_ssse3),
    make_tuple(16, 32, &convolve8_ssse3),
    make_tuple(32, 32, &convolve8_ssse3),
    make_tuple(64, 32, &convolve8_ssse3),
    make_tuple(32, 64, &convolve8_ssse3),
    make_tuple(64, 64, &convolve8_ssse3)));
646
#endif
Johann's avatar
Johann committed
647

648
#if HAVE_AVX2
James Zern's avatar
James Zern committed
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
// TODO(jzern): these prototypes can be removed after the avx2 versions are
// reenabled in vp9_rtcd_defs.pl.
extern "C" {
void vp9_convolve8_vert_avx2(const uint8_t *src, ptrdiff_t src_stride,
                             uint8_t *dst, ptrdiff_t dst_stride,
                             const int16_t *filter_x, int x_step_q4,
                             const int16_t *filter_y, int y_step_q4,
                             int w, int h);
void vp9_convolve8_horiz_avx2(const uint8_t *src, ptrdiff_t src_stride,
                              uint8_t *dst, ptrdiff_t dst_stride,
                              const int16_t *filter_x, int x_step_q4,
                              const int16_t *filter_y, int y_step_q4,
                              int w, int h);
void vp9_convolve8_avx2(const uint8_t *src, ptrdiff_t src_stride,
                        uint8_t *dst, ptrdiff_t dst_stride,
                        const int16_t *filter_x, int x_step_q4,
                        const int16_t *filter_y, int y_step_q4,
                        int w, int h);
}

669 670 671 672 673 674 675 676 677 678
const ConvolveFunctions convolve8_avx2(
    vp9_convolve8_horiz_avx2, vp9_convolve8_avg_horiz_ssse3,
    vp9_convolve8_vert_avx2, vp9_convolve8_avg_vert_ssse3,
    vp9_convolve8_avx2, vp9_convolve8_avg_ssse3);

INSTANTIATE_TEST_CASE_P(AVX2, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_avx2),
    make_tuple(8, 4, &convolve8_avx2),
    make_tuple(4, 8, &convolve8_avx2),
    make_tuple(8, 8, &convolve8_avx2),
James Zern's avatar
James Zern committed
679 680 681
    make_tuple(8, 16, &convolve8_avx2)));

INSTANTIATE_TEST_CASE_P(DISABLED_AVX2, ConvolveTest, ::testing::Values(
682 683 684 685 686 687 688 689 690 691
    make_tuple(16, 8, &convolve8_avx2),
    make_tuple(16, 16, &convolve8_avx2),
    make_tuple(32, 16, &convolve8_avx2),
    make_tuple(16, 32, &convolve8_avx2),
    make_tuple(32, 32, &convolve8_avx2),
    make_tuple(64, 32, &convolve8_avx2),
    make_tuple(32, 64, &convolve8_avx2),
    make_tuple(64, 64, &convolve8_avx2)));
#endif

692
#if HAVE_NEON_ASM
Johann's avatar
Johann committed
693
const ConvolveFunctions convolve8_neon(
Johann's avatar
Johann committed
694 695
    vp9_convolve8_horiz_neon, vp9_convolve8_avg_horiz_neon,
    vp9_convolve8_vert_neon, vp9_convolve8_avg_vert_neon,
Johann's avatar
Johann committed
696
    vp9_convolve8_neon, vp9_convolve8_avg_neon);
Johann's avatar
Johann committed
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712

INSTANTIATE_TEST_CASE_P(NEON, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_neon),
    make_tuple(8, 4, &convolve8_neon),
    make_tuple(4, 8, &convolve8_neon),
    make_tuple(8, 8, &convolve8_neon),
    make_tuple(16, 8, &convolve8_neon),
    make_tuple(8, 16, &convolve8_neon),
    make_tuple(16, 16, &convolve8_neon),
    make_tuple(32, 16, &convolve8_neon),
    make_tuple(16, 32, &convolve8_neon),
    make_tuple(32, 32, &convolve8_neon),
    make_tuple(64, 32, &convolve8_neon),
    make_tuple(32, 64, &convolve8_neon),
    make_tuple(64, 64, &convolve8_neon)));
#endif
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734

#if HAVE_DSPR2
const ConvolveFunctions convolve8_dspr2(
    vp9_convolve8_horiz_dspr2, vp9_convolve8_avg_horiz_dspr2,
    vp9_convolve8_vert_dspr2, vp9_convolve8_avg_vert_dspr2,
    vp9_convolve8_dspr2, vp9_convolve8_avg_dspr2);

INSTANTIATE_TEST_CASE_P(DSPR2, ConvolveTest, ::testing::Values(
    make_tuple(4, 4, &convolve8_dspr2),
    make_tuple(8, 4, &convolve8_dspr2),
    make_tuple(4, 8, &convolve8_dspr2),
    make_tuple(8, 8, &convolve8_dspr2),
    make_tuple(16, 8, &convolve8_dspr2),
    make_tuple(8, 16, &convolve8_dspr2),
    make_tuple(16, 16, &convolve8_dspr2),
    make_tuple(32, 16, &convolve8_dspr2),
    make_tuple(16, 32, &convolve8_dspr2),
    make_tuple(32, 32, &convolve8_dspr2),
    make_tuple(64, 32, &convolve8_dspr2),
    make_tuple(32, 64, &convolve8_dspr2),
    make_tuple(64, 64, &convolve8_dspr2)));
#endif
James Zern's avatar
James Zern committed
735
}  // namespace