chromium/third_party/libaom/source/libaom/test/hadamard_test.cc

/*
 * Copyright (c) 2019, Alliance for Open Media. All rights reserved.
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include <algorithm>
#include <ostream>

#include "gtest/gtest.h"

#include "config/aom_dsp_rtcd.h"

#include "test/acm_random.h"
#include "test/register_state_check.h"
#include "test/util.h"

namespace {

ACMRandom;

HadamardFunc;
// Low precision version of Hadamard Transform
HadamardLPFunc;
// Low precision version of Hadamard Transform 8x8 - Dual
HadamardLP8x8DualFunc;

template <typename OutputType>
void Hadamard4x4(const OutputType *a, OutputType *out) {}

template <typename OutputType>
void ReferenceHadamard4x4(const int16_t *a, int a_stride, OutputType *b) {}

template <typename OutputType>
void HadamardLoop(const OutputType *a, OutputType *out) {}

template <typename OutputType>
void ReferenceHadamard8x8(const int16_t *a, int a_stride, OutputType *b) {}

template <typename OutputType>
void ReferenceHadamard8x8Dual(const int16_t *a, int a_stride, OutputType *b) {}

template <typename OutputType>
void ReferenceHadamard16x16(const int16_t *a, int a_stride, OutputType *b,
                            bool shift) {}

template <typename OutputType>
void ReferenceHadamard32x32(const int16_t *a, int a_stride, OutputType *b,
                            bool shift) {}

template <typename OutputType>
void ReferenceHadamard(const int16_t *a, int a_stride, OutputType *b, int bw,
                       int bh, bool shift) {}

template <typename HadamardFuncType>
struct FuncWithSize {};

HadamardFuncWithSize;
HadamardLPFuncWithSize;
HadamardLP8x8DualFuncWithSize;

template <typename OutputType, typename HadamardFuncType>
class HadamardTestBase
    : public ::testing::TestWithParam<FuncWithSize<HadamardFuncType>> {};

class HadamardLowbdTest : public HadamardTestBase<tran_low_t, HadamardFunc> {};

TEST_P(HadamardLowbdTest, CompareReferenceRandom) {}

TEST_P(HadamardLowbdTest, CompareReferenceExtreme) {}

TEST_P(HadamardLowbdTest, VaryStride) {}

TEST_P(HadamardLowbdTest, DISABLED_SpeedTest) {}

INSTANTIATE_TEST_SUITE_P();

#if HAVE_SSE2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_SSE2

#if HAVE_AVX2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_AVX2

// TODO(aomedia:3314): Disable NEON unit test for now, since hadamard 16x16 NEON
// need modifications to match C/AVX2 behavior.
#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(
    NEON, HadamardLowbdTest,
    ::testing::Values(HadamardFuncWithSize(&aom_hadamard_4x4_neon, 4, 4),
                      HadamardFuncWithSize(&aom_hadamard_8x8_neon, 8, 8),
                      HadamardFuncWithSize(&aom_hadamard_16x16_neon, 16, 16),
                      HadamardFuncWithSize(&aom_hadamard_32x32_neon, 32, 32)));
#endif  // HAVE_NEON

#if CONFIG_AV1_HIGHBITDEPTH
class HadamardHighbdTest : public HadamardTestBase<tran_low_t, HadamardFunc> {
 protected:
  HadamardHighbdTest() : HadamardTestBase(GetParam(), /*do_shift=*/true) {}
  // Use values between -4095 (0xF001) and 4095 (0x0FFF)
  int16_t Rand() override {
    int16_t src = rnd_.Rand12();
    int16_t pred = rnd_.Rand12();
    return src - pred;
  }
};

TEST_P(HadamardHighbdTest, CompareReferenceRandom) { CompareReferenceRandom(); }

TEST_P(HadamardHighbdTest, VaryStride) { VaryStride(); }

TEST_P(HadamardHighbdTest, DISABLED_Speed) {
  SpeedTest(10);
  SpeedTest(10000);
  SpeedTest(10000000);
}

INSTANTIATE_TEST_SUITE_P(
    C, HadamardHighbdTest,
    ::testing::Values(
        HadamardFuncWithSize(&aom_highbd_hadamard_8x8_c, 8, 8),
        HadamardFuncWithSize(&aom_highbd_hadamard_16x16_c, 16, 16),
        HadamardFuncWithSize(&aom_highbd_hadamard_32x32_c, 32, 32)));

#if HAVE_AVX2
INSTANTIATE_TEST_SUITE_P(
    AVX2, HadamardHighbdTest,
    ::testing::Values(
        HadamardFuncWithSize(&aom_highbd_hadamard_8x8_avx2, 8, 8),
        HadamardFuncWithSize(&aom_highbd_hadamard_16x16_avx2, 16, 16),
        HadamardFuncWithSize(&aom_highbd_hadamard_32x32_avx2, 32, 32)));
#endif  // HAVE_AVX2

#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(
    NEON, HadamardHighbdTest,
    ::testing::Values(
        HadamardFuncWithSize(&aom_highbd_hadamard_8x8_neon, 8, 8),
        HadamardFuncWithSize(&aom_highbd_hadamard_16x16_neon, 16, 16),
        HadamardFuncWithSize(&aom_highbd_hadamard_32x32_neon, 32, 32)));
#endif  // HAVE_NEON

#endif  // CONFIG_AV1_HIGHBITDEPTH

// Tests for low precision
class HadamardLowbdLPTest : public HadamardTestBase<int16_t, HadamardLPFunc> {};

TEST_P(HadamardLowbdLPTest, CompareReferenceRandom) {}

TEST_P(HadamardLowbdLPTest, VaryStride) {}

TEST_P(HadamardLowbdLPTest, DISABLED_SpeedTest) {}

INSTANTIATE_TEST_SUITE_P();

#if HAVE_SSE2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_SSE2

#if HAVE_AVX2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_AVX2

#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(
    NEON, HadamardLowbdLPTest,
    ::testing::Values(HadamardLPFuncWithSize(&aom_hadamard_lp_8x8_neon, 8, 8),
                      HadamardLPFuncWithSize(&aom_hadamard_lp_16x16_neon, 16,
                                             16)));
#endif  // HAVE_NEON

// Tests for 8x8 dual low precision
class HadamardLowbdLP8x8DualTest
    : public HadamardTestBase<int16_t, HadamardLP8x8DualFunc> {};

TEST_P(HadamardLowbdLP8x8DualTest, CompareReferenceRandom) {}

TEST_P(HadamardLowbdLP8x8DualTest, VaryStride) {}

TEST_P(HadamardLowbdLP8x8DualTest, DISABLED_SpeedTest) {}

INSTANTIATE_TEST_SUITE_P();

#if HAVE_SSE2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_SSE2

#if HAVE_AVX2
INSTANTIATE_TEST_SUITE_P();
#endif  // HAVE_AVX2

#if HAVE_NEON
INSTANTIATE_TEST_SUITE_P(NEON, HadamardLowbdLP8x8DualTest,
                         ::testing::Values(HadamardLP8x8DualFuncWithSize(
                             &aom_hadamard_lp_8x8_dual_neon, 8, 16)));
#endif  // HAVE_NEON

}  // namespace