error_block_test.cc 7.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *  Copyright (c) 2014 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 <cmath>
#include <cstdlib>
#include <string>

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

17
#include "./vpx_config.h"
Yaowu Xu's avatar
Yaowu Xu committed
18
#include "./av1_rtcd.h"
19 20 21 22
#include "test/acm_random.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
Yaowu Xu's avatar
Yaowu Xu committed
23
#include "av1/common/entropy.h"
Yaowu Xu's avatar
Yaowu Xu committed
24 25
#include "aom/vpx_codec.h"
#include "aom/vpx_integer.h"
26

Yaowu Xu's avatar
Yaowu Xu committed
27
using libaom_test::ACMRandom;
28 29

namespace {
30
#if CONFIG_VPX_HIGHBITDEPTH
31 32 33 34
const int kNumIterations = 1000;

typedef int64_t (*ErrorBlockFunc)(const tran_low_t *coeff,
                                  const tran_low_t *dqcoeff,
clang-format's avatar
clang-format committed
35
                                  intptr_t block_size, int64_t *ssz, int bps);
36 37

typedef std::tr1::tuple<ErrorBlockFunc, ErrorBlockFunc, vpx_bit_depth_t>
clang-format's avatar
clang-format committed
38
    ErrorBlockParam;
39

clang-format's avatar
clang-format committed
40
class ErrorBlockTest : public ::testing::TestWithParam<ErrorBlockParam> {
41 42 43
 public:
  virtual ~ErrorBlockTest() {}
  virtual void SetUp() {
clang-format's avatar
clang-format committed
44
    error_block_op_ = GET_PARAM(0);
45
    ref_error_block_op_ = GET_PARAM(1);
clang-format's avatar
clang-format committed
46
    bit_depth_ = GET_PARAM(2);
47 48
  }

Yaowu Xu's avatar
Yaowu Xu committed
49
  virtual void TearDown() { libaom_test::ClearSystemState(); }
50 51 52 53 54 55 56 57 58

 protected:
  vpx_bit_depth_t bit_depth_;
  ErrorBlockFunc error_block_op_;
  ErrorBlockFunc ref_error_block_op_;
};

TEST_P(ErrorBlockTest, OperationCheck) {
  ACMRandom rnd(ACMRandom::DeterministicSeed());
59 60
  DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
61 62 63 64 65 66 67
  int err_count_total = 0;
  int first_failure = -1;
  intptr_t block_size;
  int64_t ssz;
  int64_t ret;
  int64_t ref_ssz;
  int64_t ref_ret;
68
  const int msb = bit_depth_ + 8 - 1;
69 70 71 72
  for (int i = 0; i < kNumIterations; ++i) {
    int err_count = 0;
    block_size = 16 << (i % 9);  // All block sizes from 4x4, 8x4 ..64x64
    for (int j = 0; j < block_size; j++) {
73 74 75 76
      // coeff and dqcoeff will always have at least the same sign, and this
      // can be used for optimization, so generate test input precisely.
      if (rnd(2)) {
        // Positive number
clang-format's avatar
clang-format committed
77
        coeff[j] = rnd(1 << msb);
78 79 80
        dqcoeff[j] = rnd(1 << msb);
      } else {
        // Negative number
clang-format's avatar
clang-format committed
81
        coeff[j] = -rnd(1 << msb);
82 83
        dqcoeff[j] = -rnd(1 << msb);
      }
84
    }
clang-format's avatar
clang-format committed
85 86 87 88
    ref_ret =
        ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
    ASM_REGISTER_STATE_CHECK(
        ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
89 90 91 92 93 94 95
    err_count += (ref_ret != ret) | (ref_ssz != ssz);
    if (err_count && !err_count_total) {
      first_failure = i;
    }
    err_count_total += err_count;
  }
  EXPECT_EQ(0, err_count_total)
96
      << "Error: Error Block Test, C output doesn't match optimized output. "
97 98 99 100 101
      << "First failed at test case " << first_failure;
}

TEST_P(ErrorBlockTest, ExtremeValues) {
  ACMRandom rnd(ACMRandom::DeterministicSeed());
102 103
  DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
104 105 106 107 108 109 110
  int err_count_total = 0;
  int first_failure = -1;
  intptr_t block_size;
  int64_t ssz;
  int64_t ret;
  int64_t ref_ssz;
  int64_t ref_ret;
111 112
  const int msb = bit_depth_ + 8 - 1;
  int max_val = ((1 << msb) - 1);
113 114
  for (int i = 0; i < kNumIterations; ++i) {
    int err_count = 0;
115
    int k = (i / 9) % 9;
116 117

    // Change the maximum coeff value, to test different bit boundaries
clang-format's avatar
clang-format committed
118
    if (k == 8 && (i % 9) == 0) {
119 120 121 122
      max_val >>= 1;
    }
    block_size = 16 << (i % 9);  // All block sizes from 4x4, 8x4 ..64x64
    for (int j = 0; j < block_size; j++) {
123 124
      if (k < 4) {
        // Test at positive maximum values
clang-format's avatar
clang-format committed
125
        coeff[j] = k % 2 ? max_val : 0;
126 127 128
        dqcoeff[j] = (k >> 1) % 2 ? max_val : 0;
      } else if (k < 8) {
        // Test at negative maximum values
clang-format's avatar
clang-format committed
129
        coeff[j] = k % 2 ? -max_val : 0;
130
        dqcoeff[j] = (k >> 1) % 2 ? -max_val : 0;
131
      } else {
132 133
        if (rnd(2)) {
          // Positive number
clang-format's avatar
clang-format committed
134
          coeff[j] = rnd(1 << 14);
135 136 137
          dqcoeff[j] = rnd(1 << 14);
        } else {
          // Negative number
clang-format's avatar
clang-format committed
138
          coeff[j] = -rnd(1 << 14);
139 140
          dqcoeff[j] = -rnd(1 << 14);
        }
141 142
      }
    }
clang-format's avatar
clang-format committed
143 144 145 146
    ref_ret =
        ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
    ASM_REGISTER_STATE_CHECK(
        ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
147 148 149 150 151 152 153
    err_count += (ref_ret != ret) | (ref_ssz != ssz);
    if (err_count && !err_count_total) {
      first_failure = i;
    }
    err_count_total += err_count;
  }
  EXPECT_EQ(0, err_count_total)
154
      << "Error: Error Block Test, C output doesn't match optimized output. "
155 156 157 158 159
      << "First failed at test case " << first_failure;
}

using std::tr1::make_tuple;

160
#if CONFIG_USE_X86INC
161
int64_t wrap_vp10_highbd_block_error_8bit_c(const tran_low_t *coeff,
clang-format's avatar
clang-format committed
162 163 164
                                            const tran_low_t *dqcoeff,
                                            intptr_t block_size, int64_t *ssz,
                                            int bps) {
165
  assert(bps == 8);
166
  return vp10_highbd_block_error_8bit_c(coeff, dqcoeff, block_size, ssz);
167 168
}

169
#if HAVE_SSE2
170
int64_t wrap_vp10_highbd_block_error_8bit_sse2(const tran_low_t *coeff,
clang-format's avatar
clang-format committed
171 172 173
                                               const tran_low_t *dqcoeff,
                                               intptr_t block_size,
                                               int64_t *ssz, int bps) {
174
  assert(bps == 8);
175
  return vp10_highbd_block_error_8bit_sse2(coeff, dqcoeff, block_size, ssz);
176 177
}

178 179
INSTANTIATE_TEST_CASE_P(
    SSE2, ErrorBlockTest,
clang-format's avatar
clang-format committed
180 181 182 183 184 185 186 187 188
    ::testing::Values(make_tuple(&vp10_highbd_block_error_sse2,
                                 &vp10_highbd_block_error_c, VPX_BITS_10),
                      make_tuple(&vp10_highbd_block_error_sse2,
                                 &vp10_highbd_block_error_c, VPX_BITS_12),
                      make_tuple(&vp10_highbd_block_error_sse2,
                                 &vp10_highbd_block_error_c, VPX_BITS_8),
                      make_tuple(&wrap_vp10_highbd_block_error_8bit_sse2,
                                 &wrap_vp10_highbd_block_error_8bit_c,
                                 VPX_BITS_8)));
189
#endif  // HAVE_SSE2
190 191

#if HAVE_AVX
192
int64_t wrap_vp10_highbd_block_error_8bit_avx(const tran_low_t *coeff,
193
                                              const tran_low_t *dqcoeff,
clang-format's avatar
clang-format committed
194 195
                                              intptr_t block_size, int64_t *ssz,
                                              int bps) {
196
  assert(bps == 8);
197
  return vp10_highbd_block_error_8bit_avx(coeff, dqcoeff, block_size, ssz);
198 199
}

clang-format's avatar
clang-format committed
200 201 202 203
INSTANTIATE_TEST_CASE_P(AVX, ErrorBlockTest,
                        ::testing::Values(make_tuple(
                            &wrap_vp10_highbd_block_error_8bit_avx,
                            &wrap_vp10_highbd_block_error_8bit_c, VPX_BITS_8)));
204 205 206
#endif  // HAVE_AVX

#endif  // CONFIG_USE_X86INC
207
#endif  // CONFIG_VPX_HIGHBITDEPTH
208
}  // namespace