Merge "remove mmx variance functions"
[aom.git] / test / hadamard_test.cc
blob0bf6f4af79aa94eeff7bc211c6504199d3154658
1 /*
2 * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
11 #include <algorithm>
13 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "./vpx_dsp_rtcd.h"
17 #include "test/acm_random.h"
18 #include "test/register_state_check.h"
20 namespace {
22 using ::libvpx_test::ACMRandom;
24 typedef void (*Hadamard8x8Func)(const int16_t *a, int a_stride,
25 int16_t *b);
27 class HadamardTest : public ::testing::TestWithParam<Hadamard8x8Func> {
28 public:
29 virtual void SetUp() {
30 h_func_ = GetParam();
31 rnd_.Reset(ACMRandom::DeterministicSeed());
34 protected:
35 Hadamard8x8Func h_func_;
36 ACMRandom rnd_;
39 void hadamard_loop(const int16_t *a, int a_stride, int16_t *out) {
40 int16_t b[8];
41 for (int i = 0; i < 8; i += 2) {
42 b[i + 0] = a[i * a_stride] + a[(i + 1) * a_stride];
43 b[i + 1] = a[i * a_stride] - a[(i + 1) * a_stride];
45 int16_t c[8];
46 for (int i = 0; i < 8; i += 4) {
47 c[i + 0] = b[i + 0] + b[i + 2];
48 c[i + 1] = b[i + 1] + b[i + 3];
49 c[i + 2] = b[i + 0] - b[i + 2];
50 c[i + 3] = b[i + 1] - b[i + 3];
52 out[0] = c[0] + c[4];
53 out[7] = c[1] + c[5];
54 out[3] = c[2] + c[6];
55 out[4] = c[3] + c[7];
56 out[2] = c[0] - c[4];
57 out[6] = c[1] - c[5];
58 out[1] = c[2] - c[6];
59 out[5] = c[3] - c[7];
62 void reference_hadamard(const int16_t *a, int a_stride, int16_t *b) {
63 int16_t buf[64];
64 for (int i = 0; i < 8; i++) {
65 hadamard_loop(a + i, a_stride, buf + i * 8);
68 for (int i = 0; i < 8; i++) {
69 hadamard_loop(buf + i, 8, b + i * 8);
73 TEST_P(HadamardTest, CompareReferenceRandom) {
74 DECLARE_ALIGNED(16, int16_t, a[64]);
75 DECLARE_ALIGNED(16, int16_t, b[64]);
76 int16_t b_ref[64];
77 for (int i = 0; i < 64; i++) {
78 a[i] = rnd_.Rand9Signed();
80 memset(b, 0, sizeof(b));
81 memset(b_ref, 0, sizeof(b_ref));
83 reference_hadamard(a, 8, b_ref);
84 ASM_REGISTER_STATE_CHECK(h_func_(a, 8, b));
86 // The order of the output is not important. Sort before checking.
87 std::sort(b, b + 64);
88 std::sort(b_ref, b_ref + 64);
89 EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
92 TEST_P(HadamardTest, VaryStride) {
93 DECLARE_ALIGNED(16, int16_t, a[64 * 8]);
94 DECLARE_ALIGNED(16, int16_t, b[64]);
95 int16_t b_ref[64];
96 for (int i = 0; i < 64 * 8; i++) {
97 a[i] = rnd_.Rand9Signed();
100 for (int i = 8; i < 64; i += 8) {
101 memset(b, 0, sizeof(b));
102 memset(b_ref, 0, sizeof(b_ref));
104 reference_hadamard(a, i, b_ref);
105 ASM_REGISTER_STATE_CHECK(h_func_(a, i, b));
107 // The order of the output is not important. Sort before checking.
108 std::sort(b, b + 64);
109 std::sort(b_ref, b_ref + 64);
110 EXPECT_EQ(0, memcmp(b, b_ref, sizeof(b)));
114 INSTANTIATE_TEST_CASE_P(C, HadamardTest,
115 ::testing::Values(&vpx_hadamard_8x8_c));
117 #if HAVE_SSE2
118 INSTANTIATE_TEST_CASE_P(SSE2, HadamardTest,
119 ::testing::Values(&vpx_hadamard_8x8_sse2));
120 #endif // HAVE_SSE2
122 #if HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64
123 INSTANTIATE_TEST_CASE_P(SSSE3, HadamardTest,
124 ::testing::Values(&vpx_hadamard_8x8_ssse3));
125 #endif // HAVE_SSSE3 && CONFIG_USE_X86INC && ARCH_X86_64
126 } // namespace