From 8c02a36953e575b4c8bc79c9be3d94ef2ec6ec81 Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 15 Apr 2016 11:35:56 -0700 Subject: [PATCH] hadamard 8x8 test The order of the output structure is not currently important. BUG=https://bugs.chromium.org/p/webm/issues/detail?id=1021 Change-Id: Ibc0006d569675db6c5060c4529f5d9e73f2e96a6 --- test/acm_random.h | 6 +++ test/hadamard_test.cc | 122 ++++++++++++++++++++++++++++++++++++++++++ test/test.mk | 1 + vpx_dsp/avg.c | 2 + 4 files changed, 131 insertions(+) create mode 100644 test/hadamard_test.cc diff --git a/test/acm_random.h b/test/acm_random.h index ff5c93ea1..a29ced2f7 100644 --- a/test/acm_random.h +++ b/test/acm_random.h @@ -32,6 +32,12 @@ class ACMRandom { return (value >> 15) & 0xffff; } + int16_t Rand9Signed(void) { + // Use 9 bits: values between 255 (0x0FF) and -256 (0x100). + const uint32_t value = random_.Generate(512); + return static_cast(value - 256); + } + uint8_t Rand8(void) { const uint32_t value = random_.Generate(testing::internal::Random::kMaxRange); diff --git a/test/hadamard_test.cc b/test/hadamard_test.cc new file mode 100644 index 000000000..6a428ffca --- /dev/null +++ b/test/hadamard_test.cc @@ -0,0 +1,122 @@ +/* + * 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 + +#include "third_party/googletest/src/include/gtest/gtest.h" + +#include "./vpx_dsp_rtcd.h" + +#include "test/acm_random.h" +#include "test/register_state_check.h" + +namespace { + +using ::libvpx_test::ACMRandom; + +typedef void (*Hadamard8x8Func)(const int16_t *a, int a_stride, + int16_t *b); + +class HadamardTest : public ::testing::TestWithParam { + public: + virtual void SetUp() { + h_func_ = GetParam(); + rnd_.Reset(ACMRandom::DeterministicSeed()); + } + + protected: + Hadamard8x8Func h_func_; + ACMRandom rnd_; +}; + +void hadamard_loop(const int16_t *a, int a_stride, int16_t *out) { + int16_t b[8]; + for (int i = 0; i < 8; i += 2) { + b[i + 0] = a[i * a_stride] + a[(i + 1) * a_stride]; + b[i + 1] = a[i * a_stride] - a[(i + 1) * a_stride]; + } + int16_t c[8]; + for (int i = 0; i < 8; i += 4) { + c[i + 0] = b[i + 0] + b[i + 2]; + c[i + 1] = b[i + 1] + b[i + 3]; + c[i + 2] = b[i + 0] - b[i + 2]; + c[i + 3] = b[i + 1] - b[i + 3]; + } + out[0] = c[0] + c[4]; + out[7] = c[1] + c[5]; + out[3] = c[2] + c[6]; + out[4] = c[3] + c[7]; + out[2] = c[0] - c[4]; + out[6] = c[1] - c[5]; + out[1] = c[2] - c[6]; + out[5] = c[3] - c[7]; +} + +void reference_hadamard(const int16_t *a, int a_stride, int16_t *b) { + int16_t buf[64]; + for (int i = 0; i < 8; i++) { + hadamard_loop(a + i, a_stride, buf + i * 8); + } + + for (int i = 0; i < 8; i++) { + hadamard_loop(buf + i, 8, b + i * 8); + } +} + +TEST_P(HadamardTest, CompareReferenceRandom) { + int16_t a[64], b[64], b_ref[64]; + for (int i = 0; i < 64; i++) { + a[i] = rnd_.Rand9Signed(); + } + memset(b, 0, sizeof(b)); + memset(b_ref, 0, sizeof(b_ref)); + + reference_hadamard(a, 8, b_ref); + ASM_REGISTER_STATE_CHECK(h_func_(a, 8, b)); + + // The order of the output is not important. Sort before checking. + std::sort(b, b + 64); + std::sort(b_ref, b_ref + 64); + EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b))); +} + +TEST_P(HadamardTest, VaryStride) { + int16_t a[64 * 8], b[64], b_ref[64]; + for (int i = 0; i < 64 * 8; i++) { + a[i] = rnd_.Rand9Signed(); + } + + for (int i = 8; i < 64; i += 8) { + memset(b, 0, sizeof(b)); + memset(b_ref, 0, sizeof(b_ref)); + + reference_hadamard(a, i, b_ref); + ASM_REGISTER_STATE_CHECK(h_func_(a, i, b)); + + // The order of the output is not important. Sort before checking. + std::sort(b, b + 64); + std::sort(b_ref, b_ref + 64); + EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b))); + } +} + +INSTANTIATE_TEST_CASE_P(C, HadamardTest, + ::testing::Values(&vpx_hadamard_8x8_c)); + +#if HAVE_SSE2 +INSTANTIATE_TEST_CASE_P(SSE2, HadamardTest, + ::testing::Values(&vpx_hadamard_8x8_sse2)); +#endif // HAVE_SSE2 + +#if HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64 +INSTANTIATE_TEST_CASE_P(SSSE3, HadamardTest, + ::testing::Values(&vpx_hadamard_8x8_ssse3)); +#endif // HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64 +} // namespace diff --git a/test/test.mk b/test/test.mk index 693185362..d28ab114b 100644 --- a/test/test.mk +++ b/test/test.mk @@ -143,6 +143,7 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += dct16x16_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += dct32x32_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += fdct4x4_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += fdct8x8_test.cc +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += hadamard_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += variance_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_error_block_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_quantize_test.cc diff --git a/vpx_dsp/avg.c b/vpx_dsp/avg.c index a44c52e8d..a8c996663 100644 --- a/vpx_dsp/avg.c +++ b/vpx_dsp/avg.c @@ -62,6 +62,8 @@ static void hadamard_col8(const int16_t *src_diff, int src_stride, coeff[5] = c3 - c7; } +// The order of the output coeff of the hadamard is not important. For +// optimization purposes the final transpose may be skipped. void vpx_hadamard_8x8_c(const int16_t *src_diff, int src_stride, int16_t *coeff) { int idx; -- GitLab