obmc_sad_test.cc 7.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 *  Copyright (c) 2016 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"

#include "test/function_equivalence_test.h"

#include "./vpx_config.h"
#include "./vpx_dsp_rtcd.h"
#include "vpx/vpx_integer.h"

#define MAX_SB_SQUARE (MAX_SB_SIZE * MAX_SB_SIZE)

using std::tr1::make_tuple;

using libvpx_test::ACMRandom;
using libvpx_test::FunctionEquivalenceTest;

namespace {

static const int kIterations = 1000;
static const int kMaskMax = 64;

32
typedef unsigned int (*ObmcSadF)(const uint8_t *pre, int pre_stride,
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
                                 const int32_t *wsrc, const int32_t *mask);

////////////////////////////////////////////////////////////////////////////////
// 8 bit
////////////////////////////////////////////////////////////////////////////////

class ObmcSadTest : public FunctionEquivalenceTest<ObmcSadF> {
 public:
  ObmcSadTest() : rng_(ACMRandom::DeterministicSeed()) {}

 protected:
  ACMRandom rng_;
};

TEST_P(ObmcSadTest, RandomValues) {
48
  DECLARE_ALIGNED(32, uint8_t, pre[MAX_SB_SQUARE]);
49 50 51 52
  DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);

  for (int iter = 0 ; iter < kIterations && !HasFatalFailure() ; ++iter) {
53
    const int pre_stride = rng_(MAX_SB_SIZE + 1);
54 55

    for (int i = 0 ; i < MAX_SB_SQUARE ; ++i) {
56
      pre[i] = rng_.Rand8();
57 58 59 60
      wsrc[i] = rng_.Rand8() * rng_(kMaskMax * kMaskMax + 1);
      mask[i] = rng_(kMaskMax * kMaskMax + 1);
    }

61 62
    const unsigned int ref_res = ref_func_(pre, pre_stride, wsrc, mask);
    const unsigned int tst_res = tst_func_(pre, pre_stride, wsrc, mask);
63 64 65 66 67 68

    ASSERT_EQ(ref_res, tst_res);
  }
}

TEST_P(ObmcSadTest, ExtremeValues) {
69
  DECLARE_ALIGNED(32, uint8_t, pre[MAX_SB_SQUARE]);
70 71 72 73
  DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);

  for (int iter = 0 ; iter < MAX_SB_SIZE && !HasFatalFailure() ; ++iter) {
74
    const int pre_stride = iter;
75 76

    for (int i = 0 ; i < MAX_SB_SQUARE ; ++i) {
77
      pre[i] = UINT8_MAX;
78 79 80 81
      wsrc[i] = UINT8_MAX * kMaskMax * kMaskMax;
      mask[i] = kMaskMax * kMaskMax;
    }

82 83
    const unsigned int ref_res = ref_func_(pre, pre_stride, wsrc, mask);
    const unsigned int tst_res = tst_func_(pre, pre_stride, wsrc, mask);
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

    ASSERT_EQ(ref_res, tst_res);
  }
}

#if HAVE_SSE4_1
const ObmcSadTest::ParamType sse4_functions[] = {
#if CONFIG_EXT_PARTITION
  make_tuple(vpx_obmc_sad128x128_c, vpx_obmc_sad128x128_sse4_1),
  make_tuple(vpx_obmc_sad128x64_c, vpx_obmc_sad128x64_sse4_1),
  make_tuple(vpx_obmc_sad64x128_c, vpx_obmc_sad64x128_sse4_1),
#endif  // CONFIG_EXT_PARTITION
  make_tuple(vpx_obmc_sad64x64_c, vpx_obmc_sad64x64_sse4_1),
  make_tuple(vpx_obmc_sad64x32_c, vpx_obmc_sad64x32_sse4_1),
  make_tuple(vpx_obmc_sad32x64_c, vpx_obmc_sad32x64_sse4_1),
  make_tuple(vpx_obmc_sad32x32_c, vpx_obmc_sad32x32_sse4_1),
  make_tuple(vpx_obmc_sad32x16_c, vpx_obmc_sad32x16_sse4_1),
  make_tuple(vpx_obmc_sad16x32_c, vpx_obmc_sad16x32_sse4_1),
  make_tuple(vpx_obmc_sad16x16_c, vpx_obmc_sad16x16_sse4_1),
  make_tuple(vpx_obmc_sad16x8_c, vpx_obmc_sad16x8_sse4_1),
  make_tuple(vpx_obmc_sad8x16_c, vpx_obmc_sad8x16_sse4_1),
  make_tuple(vpx_obmc_sad8x8_c, vpx_obmc_sad8x8_sse4_1),
  make_tuple(vpx_obmc_sad8x4_c, vpx_obmc_sad8x4_sse4_1),
  make_tuple(vpx_obmc_sad4x8_c, vpx_obmc_sad4x8_sse4_1),
  make_tuple(vpx_obmc_sad4x4_c, vpx_obmc_sad4x4_sse4_1)
};

INSTANTIATE_TEST_CASE_P(SSE4_1_C_COMPARE, ObmcSadTest,
                        ::testing::ValuesIn(sse4_functions));
#endif  // HAVE_SSE4_1

////////////////////////////////////////////////////////////////////////////////
// High bit-depth
////////////////////////////////////////////////////////////////////////////////

#if CONFIG_VP9_HIGHBITDEPTH
class ObmcSadHBDTest : public FunctionEquivalenceTest<ObmcSadF> {
 public:
  ObmcSadHBDTest() : rng_(ACMRandom::DeterministicSeed()) {}

 protected:
  ACMRandom rng_;
};

TEST_P(ObmcSadHBDTest, RandomValues) {
129
  DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
130 131 132 133
  DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);

  for (int iter = 0 ; iter < kIterations && !HasFatalFailure() ; ++iter) {
134
    const int pre_stride = rng_(MAX_SB_SIZE + 1);
135 136

    for (int i = 0 ; i < MAX_SB_SQUARE ; ++i) {
137
      pre[i] = rng_(1<<12);
138 139 140 141
      wsrc[i] = rng_(1<<12) * rng_(kMaskMax * kMaskMax + 1);
      mask[i] = rng_(kMaskMax * kMaskMax + 1);
    }

142
    const unsigned int ref_res = ref_func_(CONVERT_TO_BYTEPTR(pre), pre_stride,
143
                                           wsrc, mask);
144
    const unsigned int tst_res = tst_func_(CONVERT_TO_BYTEPTR(pre), pre_stride,
145 146 147 148 149 150 151
                                           wsrc, mask);

    ASSERT_EQ(ref_res, tst_res);
  }
}

TEST_P(ObmcSadHBDTest, ExtremeValues) {
152
  DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
153 154 155 156
  DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
  DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);

  for (int iter = 0 ; iter < MAX_SB_SIZE && !HasFatalFailure() ; ++iter) {
157
    const int pre_stride = iter;
158 159

    for (int i = 0 ; i < MAX_SB_SQUARE ; ++i) {
160
      pre[i] = (1 << 12) - 1;
161 162 163 164
      wsrc[i] = ((1 << 12) - 1) * kMaskMax * kMaskMax;
      mask[i] = kMaskMax * kMaskMax;
    }

165
    const unsigned int ref_res = ref_func_(CONVERT_TO_BYTEPTR(pre), pre_stride,
166
                                           wsrc, mask);
167
    const unsigned int tst_res = tst_func_(CONVERT_TO_BYTEPTR(pre), pre_stride,
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                                           wsrc, mask);

    ASSERT_EQ(ref_res, tst_res);
  }
}

#if HAVE_SSE4_1
ObmcSadHBDTest::ParamType sse4_functions_hbd[] = {
#if CONFIG_EXT_PARTITION
  make_tuple(vpx_highbd_obmc_sad128x128_c, vpx_highbd_obmc_sad128x128_sse4_1),
  make_tuple(vpx_highbd_obmc_sad128x64_c, vpx_highbd_obmc_sad128x64_sse4_1),
  make_tuple(vpx_highbd_obmc_sad64x128_c, vpx_highbd_obmc_sad64x128_sse4_1),
#endif  // CONFIG_EXT_PARTITION
  make_tuple(vpx_highbd_obmc_sad64x64_c, vpx_highbd_obmc_sad64x64_sse4_1),
  make_tuple(vpx_highbd_obmc_sad64x32_c, vpx_highbd_obmc_sad64x32_sse4_1),
  make_tuple(vpx_highbd_obmc_sad32x64_c, vpx_highbd_obmc_sad32x64_sse4_1),
  make_tuple(vpx_highbd_obmc_sad32x32_c, vpx_highbd_obmc_sad32x32_sse4_1),
  make_tuple(vpx_highbd_obmc_sad32x16_c, vpx_highbd_obmc_sad32x16_sse4_1),
  make_tuple(vpx_highbd_obmc_sad16x32_c, vpx_highbd_obmc_sad16x32_sse4_1),
  make_tuple(vpx_highbd_obmc_sad16x16_c, vpx_highbd_obmc_sad16x16_sse4_1),
  make_tuple(vpx_highbd_obmc_sad16x8_c, vpx_highbd_obmc_sad16x8_sse4_1),
  make_tuple(vpx_highbd_obmc_sad8x16_c, vpx_highbd_obmc_sad8x16_sse4_1),
  make_tuple(vpx_highbd_obmc_sad8x8_c, vpx_highbd_obmc_sad8x8_sse4_1),
  make_tuple(vpx_highbd_obmc_sad8x4_c, vpx_highbd_obmc_sad8x4_sse4_1),
  make_tuple(vpx_highbd_obmc_sad4x8_c, vpx_highbd_obmc_sad4x8_sse4_1),
  make_tuple(vpx_highbd_obmc_sad4x4_c, vpx_highbd_obmc_sad4x4_sse4_1)
};

INSTANTIATE_TEST_CASE_P(SSE4_1_C_COMPARE, ObmcSadHBDTest,
                        ::testing::ValuesIn(sse4_functions_hbd));
#endif  // HAVE_SSE4_1
#endif  // CONFIG_VP9_HIGHBITDEPTH
}  // namespace