dct_partial_test.cc 5.9 KB
Newer Older
Johann's avatar
Johann committed
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
/*
 *  Copyright (c) 2017 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 <math.h>
#include <stdlib.h>
#include <string.h>

#include <limits>

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

#include "./vpx_dsp_rtcd.h"
#include "test/acm_random.h"
#include "test/buffer.h"
#include "test/clear_system_state.h"
#include "test/register_state_check.h"
#include "test/util.h"
#include "vpx/vpx_codec.h"
#include "vpx/vpx_integer.h"
#include "vpx_dsp/vpx_dsp_common.h"

using libvpx_test::ACMRandom;
using libvpx_test::Buffer;
using std::tr1::tuple;
using std::tr1::make_tuple;

namespace {
typedef void (*PartialFdctFunc)(const int16_t *in, tran_low_t *out, int stride);

typedef tuple<PartialFdctFunc, int /* size */, vpx_bit_depth_t>
    PartialFdctParam;

tran_low_t partial_fdct_ref(const Buffer<int16_t> &in, int size) {
  int64_t sum = 0;
  for (int y = 0; y < size; ++y) {
    for (int x = 0; x < size; ++x) {
      sum += in.TopLeftPixel()[y * in.stride() + x];
    }
  }

  switch (size) {
49
    case 4: sum *= 2; break;
Johann's avatar
Johann committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    case 8: /*sum = sum;*/ break;
    case 16: sum >>= 1; break;
    case 32: sum >>= 3; break;
  }

  return static_cast<tran_low_t>(sum);
}

class PartialFdctTest : public ::testing::TestWithParam<PartialFdctParam> {
 public:
  PartialFdctTest() {
    fwd_txfm_ = GET_PARAM(0);
    size_ = GET_PARAM(1);
    bit_depth_ = GET_PARAM(2);
  }

  virtual void TearDown() { libvpx_test::ClearSystemState(); }

 protected:
  void RunTest() {
    ACMRandom rnd(ACMRandom::DeterministicSeed());
    const int16_t maxvalue =
        clip_pixel_highbd(std::numeric_limits<int16_t>::max(), bit_depth_);
    const int16_t minvalue = -maxvalue;
    Buffer<int16_t> input_block =
        Buffer<int16_t>(size_, size_, 8, size_ == 4 ? 0 : 16);
    ASSERT_TRUE(input_block.Init());
    Buffer<tran_low_t> output_block = Buffer<tran_low_t>(size_, size_, 0, 16);
    ASSERT_TRUE(output_block.Init());

    for (int i = 0; i < 100; ++i) {
      if (i == 0) {
        input_block.Set(maxvalue);
      } else if (i == 1) {
        input_block.Set(minvalue);
      } else {
86
        input_block.Set(&rnd, minvalue, maxvalue);
Johann's avatar
Johann committed
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 129 130 131 132 133 134 135 136
      }

      ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block.TopLeftPixel(),
                                         output_block.TopLeftPixel(),
                                         input_block.stride()));

      EXPECT_EQ(partial_fdct_ref(input_block, size_),
                output_block.TopLeftPixel()[0]);
    }
  }

  PartialFdctFunc fwd_txfm_;
  vpx_bit_depth_t bit_depth_;
  int size_;
};

TEST_P(PartialFdctTest, PartialFdctTest) { RunTest(); }

#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
    C, PartialFdctTest,
    ::testing::Values(make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_12),
                      make_tuple(&vpx_highbd_fdct32x32_1_c, 32, VPX_BITS_10),
                      make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
                      make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_12),
                      make_tuple(&vpx_highbd_fdct16x16_1_c, 16, VPX_BITS_10),
                      make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
                      make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_12),
                      make_tuple(&vpx_highbd_fdct8x8_1_c, 8, VPX_BITS_10),
                      make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
                      make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
#else
INSTANTIATE_TEST_CASE_P(
    C, PartialFdctTest,
    ::testing::Values(make_tuple(&vpx_fdct32x32_1_c, 32, VPX_BITS_8),
                      make_tuple(&vpx_fdct16x16_1_c, 16, VPX_BITS_8),
                      make_tuple(&vpx_fdct8x8_1_c, 8, VPX_BITS_8),
                      make_tuple(&vpx_fdct4x4_1_c, 4, VPX_BITS_8)));
#endif  // CONFIG_VP9_HIGHBITDEPTH

#if HAVE_SSE2
INSTANTIATE_TEST_CASE_P(
    SSE2, PartialFdctTest,
    ::testing::Values(make_tuple(&vpx_fdct32x32_1_sse2, 32, VPX_BITS_8),
                      make_tuple(&vpx_fdct16x16_1_sse2, 16, VPX_BITS_8),
                      make_tuple(&vpx_fdct8x8_1_sse2, 8, VPX_BITS_8),
                      make_tuple(&vpx_fdct4x4_1_sse2, 4, VPX_BITS_8)));
#endif  // HAVE_SSE2

#if HAVE_NEON
137 138 139
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(
    NEON, PartialFdctTest,
Johann's avatar
Johann committed
140 141
    ::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
                      make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
Johann's avatar
Johann committed
142
                      make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_12),
143
                      make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_10),
Johann's avatar
Johann committed
144 145
                      make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
                      make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
146
#else
Johann's avatar
Johann committed
147 148
INSTANTIATE_TEST_CASE_P(
    NEON, PartialFdctTest,
Johann's avatar
Johann committed
149 150
    ::testing::Values(make_tuple(&vpx_fdct32x32_1_neon, 32, VPX_BITS_8),
                      make_tuple(&vpx_fdct16x16_1_neon, 16, VPX_BITS_8),
Johann's avatar
Johann committed
151
                      make_tuple(&vpx_fdct8x8_1_neon, 8, VPX_BITS_8),
Johann's avatar
Johann committed
152
                      make_tuple(&vpx_fdct4x4_1_neon, 4, VPX_BITS_8)));
153
#endif  // CONFIG_VP9_HIGHBITDEPTH
Johann's avatar
Johann committed
154 155
#endif  // HAVE_NEON

156 157 158 159 160 161
#if HAVE_MSA
#if CONFIG_VP9_HIGHBITDEPTH
INSTANTIATE_TEST_CASE_P(MSA, PartialFdctTest,
                        ::testing::Values(make_tuple(&vpx_fdct8x8_1_msa, 8,
                                                     VPX_BITS_8)));
#else   // !CONFIG_VP9_HIGHBITDEPTH
Johann's avatar
Johann committed
162 163 164 165 166
INSTANTIATE_TEST_CASE_P(
    MSA, PartialFdctTest,
    ::testing::Values(make_tuple(&vpx_fdct32x32_1_msa, 32, VPX_BITS_8),
                      make_tuple(&vpx_fdct16x16_1_msa, 16, VPX_BITS_8),
                      make_tuple(&vpx_fdct8x8_1_msa, 8, VPX_BITS_8)));
167 168
#endif  // CONFIG_VP9_HIGHBITDEPTH
#endif  // HAVE_MSA
Johann's avatar
Johann committed
169
}  // namespace