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.
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"
22 using ::libvpx_test::ACMRandom
;
24 typedef void (*Hadamard8x8Func
)(const int16_t *a
, int a_stride
,
27 class HadamardTest
: public ::testing::TestWithParam
<Hadamard8x8Func
> {
29 virtual void SetUp() {
31 rnd_
.Reset(ACMRandom::DeterministicSeed());
35 Hadamard8x8Func h_func_
;
39 void hadamard_loop(const int16_t *a
, int a_stride
, int16_t *out
) {
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
];
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];
62 void reference_hadamard(const int16_t *a
, int a_stride
, int16_t *b
) {
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]);
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.
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]);
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
));
118 INSTANTIATE_TEST_CASE_P(SSE2
, HadamardTest
,
119 ::testing::Values(&vpx_hadamard_8x8_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