blob: b6824284910687555715f100e15ec9dd824d9abf [file] [log] [blame]
Jim Bankoski0ce51d82014-10-07 16:36:14 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jim Bankoski0ce51d82014-10-07 16:36:14 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Johann123e8a62017-12-28 14:40:49 -080010 */
Jim Bankoski0ce51d82014-10-07 16:36:14 -070011
Jim Bankoski0ce51d82014-10-07 16:36:14 -070012#include <limits.h>
13#include <stdio.h>
Jingning Han097d59c2015-07-29 14:51:36 -070014#include <string.h>
15
Tom Finegan7a07ece2017-02-07 17:14:05 -080016#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jim Bankoski0ce51d82014-10-07 16:36:14 -070017
Yaowu Xuf883b422016-08-30 14:01:10 -070018#include "./aom_config.h"
19#include "./aom_dsp_rtcd.h"
Jim Bankoski0ce51d82014-10-07 16:36:14 -070020
21#include "test/acm_random.h"
22#include "test/clear_system_state.h"
23#include "test/register_state_check.h"
24#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070025#include "aom_mem/aom_mem.h"
Jim Bankoski0ce51d82014-10-07 16:36:14 -070026
Yaowu Xuc27fc142016-08-22 16:08:15 -070027using libaom_test::ACMRandom;
Jim Bankoski0ce51d82014-10-07 16:36:14 -070028
29namespace {
30class AverageTestBase : public ::testing::Test {
31 public:
32 AverageTestBase(int width, int height) : width_(width), height_(height) {}
33
34 static void SetUpTestCase() {
clang-format3a826f12016-08-11 17:46:05 -070035 source_data_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070036 aom_memalign(kDataAlignment, kDataBlockSize));
Jim Bankoski0ce51d82014-10-07 16:36:14 -070037 }
38
39 static void TearDownTestCase() {
Yaowu Xuf883b422016-08-30 14:01:10 -070040 aom_free(source_data_);
Jim Bankoski0ce51d82014-10-07 16:36:14 -070041 source_data_ = NULL;
42 }
43
Yaowu Xuc27fc142016-08-22 16:08:15 -070044 virtual void TearDown() { libaom_test::ClearSystemState(); }
Jim Bankoski0ce51d82014-10-07 16:36:14 -070045
46 protected:
47 // Handle blocks up to 4 blocks 64x64 with stride up to 128
48 static const int kDataAlignment = 16;
49 static const int kDataBlockSize = 64 * 128;
50
51 virtual void SetUp() {
52 source_stride_ = (width_ + 31) & ~31;
53 rnd_.Reset(ACMRandom::DeterministicSeed());
54 }
55
Jim Bankoski0ce51d82014-10-07 16:36:14 -070056 void FillConstant(uint8_t fill_constant) {
57 for (int i = 0; i < width_ * height_; ++i) {
clang-format3a826f12016-08-11 17:46:05 -070058 source_data_[i] = fill_constant;
Jim Bankoski0ce51d82014-10-07 16:36:14 -070059 }
60 }
61
62 void FillRandom() {
63 for (int i = 0; i < width_ * height_; ++i) {
clang-format3a826f12016-08-11 17:46:05 -070064 source_data_[i] = rnd_.Rand8();
Jim Bankoski0ce51d82014-10-07 16:36:14 -070065 }
66 }
67
68 int width_, height_;
clang-format3a826f12016-08-11 17:46:05 -070069 static uint8_t *source_data_;
Jim Bankoski0ce51d82014-10-07 16:36:14 -070070 int source_stride_;
71
72 ACMRandom rnd_;
73};
Jim Bankoski0ce51d82014-10-07 16:36:14 -070074
Frank Galligan1395b562015-06-19 08:59:42 -070075typedef void (*IntProRowFunc)(int16_t hbuf[16], uint8_t const *ref,
76 const int ref_stride, const int height);
77
78typedef std::tr1::tuple<int, IntProRowFunc, IntProRowFunc> IntProRowParam;
79
clang-format3a826f12016-08-11 17:46:05 -070080class IntProRowTest : public AverageTestBase,
81 public ::testing::WithParamInterface<IntProRowParam> {
Frank Galligan1395b562015-06-19 08:59:42 -070082 public:
83 IntProRowTest()
clang-format3a826f12016-08-11 17:46:05 -070084 : AverageTestBase(16, GET_PARAM(0)), hbuf_asm_(NULL), hbuf_c_(NULL) {
Frank Galligan1395b562015-06-19 08:59:42 -070085 asm_func_ = GET_PARAM(1);
86 c_func_ = GET_PARAM(2);
87 }
88
89 protected:
90 virtual void SetUp() {
clang-format3a826f12016-08-11 17:46:05 -070091 hbuf_asm_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070092 aom_memalign(kDataAlignment, sizeof(*hbuf_asm_) * 16));
clang-format3a826f12016-08-11 17:46:05 -070093 hbuf_c_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070094 aom_memalign(kDataAlignment, sizeof(*hbuf_c_) * 16));
Frank Galligan1395b562015-06-19 08:59:42 -070095 }
96
97 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -070098 aom_free(hbuf_c_);
Frank Galligan1395b562015-06-19 08:59:42 -070099 hbuf_c_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700100 aom_free(hbuf_asm_);
Frank Galligan1395b562015-06-19 08:59:42 -0700101 hbuf_asm_ = NULL;
102 }
103
104 void RunComparison() {
105 ASM_REGISTER_STATE_CHECK(c_func_(hbuf_c_, source_data_, 0, height_));
106 ASM_REGISTER_STATE_CHECK(asm_func_(hbuf_asm_, source_data_, 0, height_));
107 EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * 16))
108 << "Output mismatch";
109 }
110
111 private:
112 IntProRowFunc asm_func_;
113 IntProRowFunc c_func_;
114 int16_t *hbuf_asm_;
115 int16_t *hbuf_c_;
116};
117
118typedef int16_t (*IntProColFunc)(uint8_t const *ref, const int width);
119
120typedef std::tr1::tuple<int, IntProColFunc, IntProColFunc> IntProColParam;
121
clang-format3a826f12016-08-11 17:46:05 -0700122class IntProColTest : public AverageTestBase,
123 public ::testing::WithParamInterface<IntProColParam> {
Frank Galligan1395b562015-06-19 08:59:42 -0700124 public:
125 IntProColTest() : AverageTestBase(GET_PARAM(0), 1), sum_asm_(0), sum_c_(0) {
126 asm_func_ = GET_PARAM(1);
127 c_func_ = GET_PARAM(2);
128 }
129
130 protected:
131 void RunComparison() {
132 ASM_REGISTER_STATE_CHECK(sum_c_ = c_func_(source_data_, width_));
133 ASM_REGISTER_STATE_CHECK(sum_asm_ = asm_func_(source_data_, width_));
134 EXPECT_EQ(sum_c_, sum_asm_) << "Output mismatch";
135 }
136
137 private:
138 IntProColFunc asm_func_;
139 IntProColFunc c_func_;
140 int16_t sum_asm_;
141 int16_t sum_c_;
142};
143
James Zern3e0138e2015-11-18 23:17:27 -0800144typedef int (*SatdFunc)(const int16_t *coeffs, int length);
145typedef std::tr1::tuple<int, SatdFunc> SatdTestParam;
146
clang-format3a826f12016-08-11 17:46:05 -0700147class SatdTest : public ::testing::Test,
148 public ::testing::WithParamInterface<SatdTestParam> {
James Zern3e0138e2015-11-18 23:17:27 -0800149 protected:
150 virtual void SetUp() {
151 satd_size_ = GET_PARAM(0);
152 satd_func_ = GET_PARAM(1);
153 rnd_.Reset(ACMRandom::DeterministicSeed());
clang-format3a826f12016-08-11 17:46:05 -0700154 src_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700155 aom_memalign(16, sizeof(*src_) * satd_size_));
James Zern3e0138e2015-11-18 23:17:27 -0800156 ASSERT_TRUE(src_ != NULL);
157 }
158
159 virtual void TearDown() {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700160 libaom_test::ClearSystemState();
Yaowu Xuf883b422016-08-30 14:01:10 -0700161 aom_free(src_);
James Zern3e0138e2015-11-18 23:17:27 -0800162 }
163
164 void FillConstant(const int16_t val) {
165 for (int i = 0; i < satd_size_; ++i) src_[i] = val;
166 }
167
168 void FillRandom() {
169 for (int i = 0; i < satd_size_; ++i) src_[i] = rnd_.Rand16();
170 }
171
Yaowu Xu4ff59b52017-04-24 12:41:56 -0700172 void Check(int expected) {
James Zern3e0138e2015-11-18 23:17:27 -0800173 int total;
174 ASM_REGISTER_STATE_CHECK(total = satd_func_(src_, satd_size_));
175 EXPECT_EQ(expected, total);
176 }
177
178 int satd_size_;
179
180 private:
181 int16_t *src_;
182 SatdFunc satd_func_;
183 ACMRandom rnd_;
184};
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700185
clang-format3a826f12016-08-11 17:46:05 -0700186uint8_t *AverageTestBase::source_data_ = NULL;
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700187
Frank Galligan1395b562015-06-19 08:59:42 -0700188TEST_P(IntProRowTest, MinValue) {
189 FillConstant(0);
190 RunComparison();
191}
192
193TEST_P(IntProRowTest, MaxValue) {
194 FillConstant(255);
195 RunComparison();
196}
197
198TEST_P(IntProRowTest, Random) {
199 FillRandom();
200 RunComparison();
201}
202
203TEST_P(IntProColTest, MinValue) {
204 FillConstant(0);
205 RunComparison();
206}
207
208TEST_P(IntProColTest, MaxValue) {
209 FillConstant(255);
210 RunComparison();
211}
212
213TEST_P(IntProColTest, Random) {
214 FillRandom();
215 RunComparison();
216}
217
James Zern3e0138e2015-11-18 23:17:27 -0800218TEST_P(SatdTest, MinValue) {
219 const int kMin = -32640;
220 const int expected = -kMin * satd_size_;
221 FillConstant(kMin);
222 Check(expected);
223}
224
225TEST_P(SatdTest, MaxValue) {
226 const int kMax = 32640;
227 const int expected = kMax * satd_size_;
228 FillConstant(kMax);
229 Check(expected);
230}
231
232TEST_P(SatdTest, Random) {
233 int expected;
234 switch (satd_size_) {
235 case 16: expected = 205298; break;
236 case 64: expected = 1113950; break;
237 case 256: expected = 4268415; break;
238 case 1024: expected = 16954082; break;
239 default:
240 FAIL() << "Invalid satd size (" << satd_size_
241 << ") valid: 16/64/256/1024";
242 }
243 FillRandom();
244 Check(expected);
245}
246
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700247using std::tr1::make_tuple;
248
clang-format3a826f12016-08-11 17:46:05 -0700249INSTANTIATE_TEST_CASE_P(C, SatdTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700250 ::testing::Values(make_tuple(16, &aom_satd_c),
251 make_tuple(64, &aom_satd_c),
252 make_tuple(256, &aom_satd_c),
253 make_tuple(1024, &aom_satd_c)));
James Zern3e0138e2015-11-18 23:17:27 -0800254
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700255#if HAVE_SSE2
256INSTANTIATE_TEST_CASE_P(
clang-format3a826f12016-08-11 17:46:05 -0700257 SSE2, IntProRowTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700258 ::testing::Values(make_tuple(16, &aom_int_pro_row_sse2, &aom_int_pro_row_c),
259 make_tuple(32, &aom_int_pro_row_sse2, &aom_int_pro_row_c),
260 make_tuple(64, &aom_int_pro_row_sse2,
261 &aom_int_pro_row_c)));
Frank Galligan1395b562015-06-19 08:59:42 -0700262
263INSTANTIATE_TEST_CASE_P(
clang-format3a826f12016-08-11 17:46:05 -0700264 SSE2, IntProColTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700265 ::testing::Values(make_tuple(16, &aom_int_pro_col_sse2, &aom_int_pro_col_c),
266 make_tuple(32, &aom_int_pro_col_sse2, &aom_int_pro_col_c),
267 make_tuple(64, &aom_int_pro_col_sse2,
268 &aom_int_pro_col_c)));
James Zern60760f72015-11-19 20:04:16 -0800269
clang-format3a826f12016-08-11 17:46:05 -0700270INSTANTIATE_TEST_CASE_P(SSE2, SatdTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700271 ::testing::Values(make_tuple(16, &aom_satd_sse2),
272 make_tuple(64, &aom_satd_sse2),
273 make_tuple(256, &aom_satd_sse2),
274 make_tuple(1024, &aom_satd_sse2)));
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700275#endif
276
Frank Galligan6e7e1cf2015-01-15 14:36:41 -0800277#if HAVE_NEON
278INSTANTIATE_TEST_CASE_P(
clang-format3a826f12016-08-11 17:46:05 -0700279 NEON, IntProRowTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700280 ::testing::Values(make_tuple(16, &aom_int_pro_row_neon, &aom_int_pro_row_c),
281 make_tuple(32, &aom_int_pro_row_neon, &aom_int_pro_row_c),
282 make_tuple(64, &aom_int_pro_row_neon,
283 &aom_int_pro_row_c)));
Frank Galligan1c399982015-07-15 09:04:28 -0700284
285INSTANTIATE_TEST_CASE_P(
clang-format3a826f12016-08-11 17:46:05 -0700286 NEON, IntProColTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700287 ::testing::Values(make_tuple(16, &aom_int_pro_col_neon, &aom_int_pro_col_c),
288 make_tuple(32, &aom_int_pro_col_neon, &aom_int_pro_col_c),
289 make_tuple(64, &aom_int_pro_col_neon,
290 &aom_int_pro_col_c)));
James Zerneb1d0f82015-11-19 23:39:10 -0800291
clang-format3a826f12016-08-11 17:46:05 -0700292INSTANTIATE_TEST_CASE_P(NEON, SatdTest,
Yaowu Xuf883b422016-08-30 14:01:10 -0700293 ::testing::Values(make_tuple(16, &aom_satd_neon),
294 make_tuple(64, &aom_satd_neon),
295 make_tuple(256, &aom_satd_neon),
296 make_tuple(1024, &aom_satd_neon)));
Frank Galligan6e7e1cf2015-01-15 14:36:41 -0800297#endif
298
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700299} // namespace