subtract_test.cc 3.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *  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.
 */

#include "third_party/googletest/src/include/gtest/gtest.h"
#include "test/acm_random.h"
13
#include "test/clear_system_state.h"
14
#include "test/register_state_check.h"
Yaowu Xu's avatar
Yaowu Xu committed
15 16
#include "./vpx_config.h"
#include "./vp8_rtcd.h"
17 18 19 20
#include "vp8/common/blockd.h"
#include "vp8/encoder/block.h"
#include "vpx_mem/vpx_mem.h"

21
typedef void (*SubtractBlockFunc)(BLOCK *be, BLOCKD *bd, int pitch);
22 23 24

namespace {

25
class SubtractBlockTest : public ::testing::TestWithParam<SubtractBlockFunc> {
26 27 28 29 30
 public:
  virtual void TearDown() {
    libvpx_test::ClearSystemState();
  }
};
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

using libvpx_test::ACMRandom;

TEST_P(SubtractBlockTest, SimpleSubtract) {
  ACMRandom rnd(ACMRandom::DeterministicSeed());
  BLOCK be;
  BLOCKD bd;
  // in libvpx, this stride is always 16
  const int kDiffPredStride = 16;
  const int kSrcStride[] = {32, 16, 8, 4, 0};
  const int kBlockWidth = 4;
  const int kBlockHeight = 4;

  // Allocate... align to 16 for mmx/sse tests
  uint8_t *source = reinterpret_cast<uint8_t*>(
      vpx_memalign(16, kBlockHeight * kSrcStride[0] * sizeof(*source)));
  be.src_diff = reinterpret_cast<int16_t*>(
      vpx_memalign(16, kBlockHeight * kDiffPredStride * sizeof(*be.src_diff)));
  bd.predictor = reinterpret_cast<unsigned char*>(
      vpx_memalign(16, kBlockHeight * kDiffPredStride * sizeof(*bd.predictor)));

Yaowu Xu's avatar
Yaowu Xu committed
52
  for (int i = 0; kSrcStride[i] > 0; ++i) {
53 54 55 56 57 58 59 60 61
    // start at block0
    be.src = 0;
    be.base_src = &source;
    be.src_stride = kSrcStride[i];

    // set difference
    int16_t *src_diff = be.src_diff;
    for (int r = 0; r < kBlockHeight; ++r) {
      for (int c = 0; c < kBlockWidth; ++c) {
James Zern's avatar
James Zern committed
62
        src_diff[c] = static_cast<int16_t>(0xa5a5u);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
      }
      src_diff += kDiffPredStride;
    }

    // set destination
    uint8_t *base_src = *be.base_src;
    for (int r = 0; r < kBlockHeight; ++r) {
      for (int c = 0; c < kBlockWidth; ++c) {
        base_src[c] = rnd.Rand8();
      }
      base_src += be.src_stride;
    }

    // set predictor
    uint8_t *predictor = bd.predictor;
    for (int r = 0; r < kBlockHeight; ++r) {
      for (int c = 0; c < kBlockWidth; ++c) {
        predictor[c] = rnd.Rand8();
      }
      predictor += kDiffPredStride;
    }

85
    ASM_REGISTER_STATE_CHECK(GetParam()(&be, &bd, kDiffPredStride));
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    base_src = *be.base_src;
    src_diff = be.src_diff;
    predictor = bd.predictor;
    for (int r = 0; r < kBlockHeight; ++r) {
      for (int c = 0; c < kBlockWidth; ++c) {
        EXPECT_EQ(base_src[c], (src_diff[c] + predictor[c])) << "r = " << r
                                                             << ", c = " << c;
      }
      src_diff += kDiffPredStride;
      predictor += kDiffPredStride;
      base_src += be.src_stride;
    }
  }
  vpx_free(be.src_diff);
  vpx_free(source);
  vpx_free(bd.predictor);
}

INSTANTIATE_TEST_CASE_P(C, SubtractBlockTest,
                        ::testing::Values(vp8_subtract_b_c));

108
#if HAVE_NEON_ASM
James Zern's avatar
James Zern committed
109 110 111 112
INSTANTIATE_TEST_CASE_P(NEON, SubtractBlockTest,
                        ::testing::Values(vp8_subtract_b_neon));
#endif

113 114 115 116 117 118 119 120 121 122 123
#if HAVE_MMX
INSTANTIATE_TEST_CASE_P(MMX, SubtractBlockTest,
                        ::testing::Values(vp8_subtract_b_mmx));
#endif

#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(SSE2, SubtractBlockTest,
                        ::testing::Values(vp8_subtract_b_sse2));
#endif

}  // namespace