blob: 139c41298f511bab1cbb843d5a4e855afb0f8aa5 [file] [log] [blame]
Jim Bankoski0ce51d82014-10-07 16:36:14 -07001/*
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3 *
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 */
10
11
12#include <string.h>
13#include <limits.h>
14#include <stdio.h>
15
16#include "./vpx_config.h"
17#if CONFIG_VP9_ENCODER
18#include "./vp9_rtcd.h"
19#endif
20#include "vpx_mem/vpx_mem.h"
21
22#include "test/acm_random.h"
23#include "test/clear_system_state.h"
24#include "test/register_state_check.h"
25#include "test/util.h"
26#include "third_party/googletest/src/include/gtest/gtest.h"
27
28using libvpx_test::ACMRandom;
29
30namespace {
31class AverageTestBase : public ::testing::Test {
32 public:
33 AverageTestBase(int width, int height) : width_(width), height_(height) {}
34
35 static void SetUpTestCase() {
36 source_data_ = reinterpret_cast<uint8_t*>(
37 vpx_memalign(kDataAlignment, kDataBlockSize));
38 }
39
40 static void TearDownTestCase() {
41 vpx_free(source_data_);
42 source_data_ = NULL;
43 }
44
45 virtual void TearDown() {
46 libvpx_test::ClearSystemState();
47 }
48
49 protected:
50 // Handle blocks up to 4 blocks 64x64 with stride up to 128
51 static const int kDataAlignment = 16;
52 static const int kDataBlockSize = 64 * 128;
53
54 virtual void SetUp() {
55 source_stride_ = (width_ + 31) & ~31;
56 rnd_.Reset(ACMRandom::DeterministicSeed());
57 }
58
59 // Sum Pixels
Marco8fd3f9a2014-11-12 14:51:49 -080060 unsigned int ReferenceAverage8x8(const uint8_t* source, int pitch ) {
Jim Bankoski0ce51d82014-10-07 16:36:14 -070061 unsigned int average = 0;
62 for (int h = 0; h < 8; ++h)
63 for (int w = 0; w < 8; ++w)
64 average += source[h * source_stride_ + w];
65 return ((average + 32) >> 6);
66 }
67
Marco8fd3f9a2014-11-12 14:51:49 -080068 unsigned int ReferenceAverage4x4(const uint8_t* source, int pitch ) {
69 unsigned int average = 0;
70 for (int h = 0; h < 4; ++h)
71 for (int w = 0; w < 4; ++w)
72 average += source[h * source_stride_ + w];
73 return ((average + 8) >> 4);
74 }
75
Jim Bankoski0ce51d82014-10-07 16:36:14 -070076 void FillConstant(uint8_t fill_constant) {
77 for (int i = 0; i < width_ * height_; ++i) {
78 source_data_[i] = fill_constant;
79 }
80 }
81
82 void FillRandom() {
83 for (int i = 0; i < width_ * height_; ++i) {
84 source_data_[i] = rnd_.Rand8();
85 }
86 }
87
88 int width_, height_;
89 static uint8_t* source_data_;
90 int source_stride_;
91
92 ACMRandom rnd_;
93};
94typedef unsigned int (*AverageFunction)(const uint8_t* s, int pitch);
95
Marco8fd3f9a2014-11-12 14:51:49 -080096typedef std::tr1::tuple<int, int, int, int, AverageFunction> AvgFunc;
Jim Bankoski0ce51d82014-10-07 16:36:14 -070097
98class AverageTest
99 : public AverageTestBase,
100 public ::testing::WithParamInterface<AvgFunc>{
101 public:
102 AverageTest() : AverageTestBase(GET_PARAM(0), GET_PARAM(1)) {}
103
104 protected:
105 void CheckAverages() {
Marco8fd3f9a2014-11-12 14:51:49 -0800106 unsigned int expected = 0;
107 if (GET_PARAM(3) == 8) {
108 expected = ReferenceAverage8x8(source_data_+ GET_PARAM(2),
109 source_stride_);
110 } else if (GET_PARAM(3) == 4) {
111 expected = ReferenceAverage4x4(source_data_+ GET_PARAM(2),
112 source_stride_);
113 }
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700114
Marco8fd3f9a2014-11-12 14:51:49 -0800115 ASM_REGISTER_STATE_CHECK(GET_PARAM(4)(source_data_+ GET_PARAM(2),
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700116 source_stride_));
Marco8fd3f9a2014-11-12 14:51:49 -0800117 unsigned int actual = GET_PARAM(4)(source_data_+ GET_PARAM(2),
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700118 source_stride_);
119
120 EXPECT_EQ(expected, actual);
121 }
122};
123
Frank Galligan1395b562015-06-19 08:59:42 -0700124typedef void (*IntProRowFunc)(int16_t hbuf[16], uint8_t const *ref,
125 const int ref_stride, const int height);
126
127typedef std::tr1::tuple<int, IntProRowFunc, IntProRowFunc> IntProRowParam;
128
129class IntProRowTest
130 : public AverageTestBase,
131 public ::testing::WithParamInterface<IntProRowParam> {
132 public:
133 IntProRowTest()
134 : AverageTestBase(16, GET_PARAM(0)),
135 hbuf_asm_(NULL),
136 hbuf_c_(NULL) {
137 asm_func_ = GET_PARAM(1);
138 c_func_ = GET_PARAM(2);
139 }
140
141 protected:
142 virtual void SetUp() {
143 hbuf_asm_ = reinterpret_cast<int16_t*>(
144 vpx_memalign(kDataAlignment, sizeof(*hbuf_asm_) * 16));
145 hbuf_c_ = reinterpret_cast<int16_t*>(
146 vpx_memalign(kDataAlignment, sizeof(*hbuf_c_) * 16));
147 }
148
149 virtual void TearDown() {
150 vpx_free(hbuf_c_);
151 hbuf_c_ = NULL;
152 vpx_free(hbuf_asm_);
153 hbuf_asm_ = NULL;
154 }
155
156 void RunComparison() {
157 ASM_REGISTER_STATE_CHECK(c_func_(hbuf_c_, source_data_, 0, height_));
158 ASM_REGISTER_STATE_CHECK(asm_func_(hbuf_asm_, source_data_, 0, height_));
159 EXPECT_EQ(0, memcmp(hbuf_c_, hbuf_asm_, sizeof(*hbuf_c_) * 16))
160 << "Output mismatch";
161 }
162
163 private:
164 IntProRowFunc asm_func_;
165 IntProRowFunc c_func_;
166 int16_t *hbuf_asm_;
167 int16_t *hbuf_c_;
168};
169
170typedef int16_t (*IntProColFunc)(uint8_t const *ref, const int width);
171
172typedef std::tr1::tuple<int, IntProColFunc, IntProColFunc> IntProColParam;
173
174class IntProColTest
175 : public AverageTestBase,
176 public ::testing::WithParamInterface<IntProColParam> {
177 public:
178 IntProColTest() : AverageTestBase(GET_PARAM(0), 1), sum_asm_(0), sum_c_(0) {
179 asm_func_ = GET_PARAM(1);
180 c_func_ = GET_PARAM(2);
181 }
182
183 protected:
184 void RunComparison() {
185 ASM_REGISTER_STATE_CHECK(sum_c_ = c_func_(source_data_, width_));
186 ASM_REGISTER_STATE_CHECK(sum_asm_ = asm_func_(source_data_, width_));
187 EXPECT_EQ(sum_c_, sum_asm_) << "Output mismatch";
188 }
189
190 private:
191 IntProColFunc asm_func_;
192 IntProColFunc c_func_;
193 int16_t sum_asm_;
194 int16_t sum_c_;
195};
196
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700197
198uint8_t* AverageTestBase::source_data_ = NULL;
199
200TEST_P(AverageTest, MinValue) {
201 FillConstant(0);
202 CheckAverages();
203}
204
205TEST_P(AverageTest, MaxValue) {
206 FillConstant(255);
207 CheckAverages();
208}
209
210TEST_P(AverageTest, Random) {
211 // The reference frame, but not the source frame, may be unaligned for
212 // certain types of searches.
213 for (int i = 0; i < 1000; i++) {
214 FillRandom();
215 CheckAverages();
216 }
217}
218
Frank Galligan1395b562015-06-19 08:59:42 -0700219TEST_P(IntProRowTest, MinValue) {
220 FillConstant(0);
221 RunComparison();
222}
223
224TEST_P(IntProRowTest, MaxValue) {
225 FillConstant(255);
226 RunComparison();
227}
228
229TEST_P(IntProRowTest, Random) {
230 FillRandom();
231 RunComparison();
232}
233
234TEST_P(IntProColTest, MinValue) {
235 FillConstant(0);
236 RunComparison();
237}
238
239TEST_P(IntProColTest, MaxValue) {
240 FillConstant(255);
241 RunComparison();
242}
243
244TEST_P(IntProColTest, Random) {
245 FillRandom();
246 RunComparison();
247}
248
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700249using std::tr1::make_tuple;
250
251INSTANTIATE_TEST_CASE_P(
252 C, AverageTest,
253 ::testing::Values(
Marco8fd3f9a2014-11-12 14:51:49 -0800254 make_tuple(16, 16, 1, 8, &vp9_avg_8x8_c),
255 make_tuple(16, 16, 1, 4, &vp9_avg_4x4_c)));
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700256
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700257#if HAVE_SSE2
258INSTANTIATE_TEST_CASE_P(
259 SSE2, AverageTest,
260 ::testing::Values(
Marco8fd3f9a2014-11-12 14:51:49 -0800261 make_tuple(16, 16, 0, 8, &vp9_avg_8x8_sse2),
262 make_tuple(16, 16, 5, 8, &vp9_avg_8x8_sse2),
263 make_tuple(32, 32, 15, 8, &vp9_avg_8x8_sse2),
264 make_tuple(16, 16, 0, 4, &vp9_avg_4x4_sse2),
265 make_tuple(16, 16, 5, 4, &vp9_avg_4x4_sse2),
266 make_tuple(32, 32, 15, 4, &vp9_avg_4x4_sse2)));
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700267
Frank Galligan1395b562015-06-19 08:59:42 -0700268INSTANTIATE_TEST_CASE_P(
269 SSE2, IntProRowTest, ::testing::Values(
270 make_tuple(16, &vp9_int_pro_row_sse2, &vp9_int_pro_row_c),
271 make_tuple(32, &vp9_int_pro_row_sse2, &vp9_int_pro_row_c),
272 make_tuple(64, &vp9_int_pro_row_sse2, &vp9_int_pro_row_c)));
273
274INSTANTIATE_TEST_CASE_P(
275 SSE2, IntProColTest, ::testing::Values(
276 make_tuple(16, &vp9_int_pro_col_sse2, &vp9_int_pro_col_c),
277 make_tuple(32, &vp9_int_pro_col_sse2, &vp9_int_pro_col_c),
278 make_tuple(64, &vp9_int_pro_col_sse2, &vp9_int_pro_col_c)));
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700279#endif
280
Frank Galligan6e7e1cf2015-01-15 14:36:41 -0800281#if HAVE_NEON
282INSTANTIATE_TEST_CASE_P(
283 NEON, AverageTest,
284 ::testing::Values(
285 make_tuple(16, 16, 0, 8, &vp9_avg_8x8_neon),
286 make_tuple(16, 16, 5, 8, &vp9_avg_8x8_neon),
287 make_tuple(32, 32, 15, 8, &vp9_avg_8x8_neon)));
288
289#endif
290
Parag Salasakar7555e2b2015-06-23 07:32:25 +0530291#if HAVE_MSA
292INSTANTIATE_TEST_CASE_P(
293 MSA, AverageTest,
294 ::testing::Values(
295 make_tuple(16, 16, 0, 8, &vp9_avg_8x8_msa),
296 make_tuple(16, 16, 5, 8, &vp9_avg_8x8_msa),
297 make_tuple(32, 32, 15, 8, &vp9_avg_8x8_msa),
298 make_tuple(16, 16, 0, 4, &vp9_avg_4x4_msa),
299 make_tuple(16, 16, 5, 4, &vp9_avg_4x4_msa),
300 make_tuple(32, 32, 15, 4, &vp9_avg_4x4_msa)));
301#endif
302
Jim Bankoski0ce51d82014-10-07 16:36:14 -0700303} // namespace