blob: 89d8c415206f05a8c85eba6c6ea8d5349741579e [file] [log] [blame]
Johannfbea8972012-06-28 11:43:58 -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
Johannfbea8972012-06-28 11:43:58 -070016#include "./vpx_config.h"
John Koleszar6b653cb2013-02-28 17:03:02 -080017#if CONFIG_VP8_ENCODER
John Koleszara9c75972012-11-08 17:09:30 -080018#include "./vp8_rtcd.h"
John Koleszar6b653cb2013-02-28 17:03:02 -080019#endif
20#if CONFIG_VP9_ENCODER
21#include "./vp9_rtcd.h"
22#endif
James Zern10f8b362012-08-27 17:13:09 -070023#include "vpx_mem/vpx_mem.h"
Johannfbea8972012-06-28 11:43:58 -070024
25#include "test/acm_random.h"
James Zern5b756742013-06-17 22:58:40 -070026#include "test/clear_system_state.h"
James Zerneebb6482012-11-27 13:08:05 -080027#include "test/register_state_check.h"
Johannfbea8972012-06-28 11:43:58 -070028#include "test/util.h"
29#include "third_party/googletest/src/include/gtest/gtest.h"
30
31
Deb Mukherjeefc882922014-05-13 10:11:42 -070032#if CONFIG_VP8_ENCODER
Johannfbea8972012-06-28 11:43:58 -070033typedef unsigned int (*sad_m_by_n_fn_t)(const unsigned char *source_ptr,
34 int source_stride,
35 const unsigned char *reference_ptr,
Jim Bankoskia16794d2014-05-15 08:31:20 -070036 int reference_stride,
37 unsigned int max_sad);
James Zern5e3439b2013-05-29 17:47:18 -070038typedef std::tr1::tuple<int, int, sad_m_by_n_fn_t> sad_m_by_n_test_param_t;
Deb Mukherjeefc882922014-05-13 10:11:42 -070039#endif
40#if CONFIG_VP9_ENCODER
41typedef unsigned int (*sad_m_by_n_fn_vp9_t)(const unsigned char *source_ptr,
42 int source_stride,
43 const unsigned char *reference_ptr,
44 int reference_stride);
45typedef std::tr1::tuple<int, int, sad_m_by_n_fn_vp9_t>
46 sad_m_by_n_test_param_vp9_t;
47#endif
Johannfbea8972012-06-28 11:43:58 -070048
John Koleszar1cfc86e2013-03-01 12:43:41 -080049typedef void (*sad_n_by_n_by_4_fn_t)(const uint8_t *src_ptr,
50 int src_stride,
51 const unsigned char * const ref_ptr[],
52 int ref_stride,
53 unsigned int *sad_array);
James Zern5e3439b2013-05-29 17:47:18 -070054typedef std::tr1::tuple<int, int, sad_n_by_n_by_4_fn_t>
55 sad_n_by_n_by_4_test_param_t;
John Koleszar1cfc86e2013-03-01 12:43:41 -080056
Johannfbea8972012-06-28 11:43:58 -070057using libvpx_test::ACMRandom;
58
59namespace {
John Koleszar1cfc86e2013-03-01 12:43:41 -080060class SADTestBase : public ::testing::Test {
James Zern10f8b362012-08-27 17:13:09 -070061 public:
John Koleszar1cfc86e2013-03-01 12:43:41 -080062 SADTestBase(int width, int height) : width_(width), height_(height) {}
63
James Zern10f8b362012-08-27 17:13:09 -070064 static void SetUpTestCase() {
65 source_data_ = reinterpret_cast<uint8_t*>(
John Koleszar1cfc86e2013-03-01 12:43:41 -080066 vpx_memalign(kDataAlignment, kDataBlockSize));
James Zern10f8b362012-08-27 17:13:09 -070067 reference_data_ = reinterpret_cast<uint8_t*>(
68 vpx_memalign(kDataAlignment, kDataBufferSize));
69 }
70
71 static void TearDownTestCase() {
72 vpx_free(source_data_);
73 source_data_ = NULL;
74 vpx_free(reference_data_);
75 reference_data_ = NULL;
76 }
77
James Zern5b756742013-06-17 22:58:40 -070078 virtual void TearDown() {
79 libvpx_test::ClearSystemState();
80 }
81
James Zern10f8b362012-08-27 17:13:09 -070082 protected:
John Koleszar6b653cb2013-02-28 17:03:02 -080083 // Handle blocks up to 4 blocks 64x64 with stride up to 128
James Zern10f8b362012-08-27 17:13:09 -070084 static const int kDataAlignment = 16;
John Koleszar1cfc86e2013-03-01 12:43:41 -080085 static const int kDataBlockSize = 64 * 128;
86 static const int kDataBufferSize = 4 * kDataBlockSize;
James Zern10f8b362012-08-27 17:13:09 -070087
Johannfbea8972012-06-28 11:43:58 -070088 virtual void SetUp() {
John Koleszar6b653cb2013-02-28 17:03:02 -080089 source_stride_ = (width_ + 31) & ~31;
Johannfbea8972012-06-28 11:43:58 -070090 reference_stride_ = width_ * 2;
91 rnd_.Reset(ACMRandom::DeterministicSeed());
92 }
93
John Koleszar1cfc86e2013-03-01 12:43:41 -080094 virtual uint8_t* GetReference(int block_idx) {
95 return reference_data_ + block_idx * kDataBlockSize;
Johannfbea8972012-06-28 11:43:58 -070096 }
97
98 // Sum of Absolute Differences. Given two blocks, calculate the absolute
99 // difference between two pixels in the same relative location; accumulate.
Deb Mukherjeefc882922014-05-13 10:11:42 -0700100 unsigned int ReferenceSAD(unsigned int max_sad, int block_idx) {
Johannfbea8972012-06-28 11:43:58 -0700101 unsigned int sad = 0;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800102 const uint8_t* const reference = GetReference(block_idx);
Johannfbea8972012-06-28 11:43:58 -0700103
104 for (int h = 0; h < height_; ++h) {
105 for (int w = 0; w < width_; ++w) {
106 sad += abs(source_data_[h * source_stride_ + w]
John Koleszar1cfc86e2013-03-01 12:43:41 -0800107 - reference[h * reference_stride_ + w]);
Johannfbea8972012-06-28 11:43:58 -0700108 }
Jim Bankoskia16794d2014-05-15 08:31:20 -0700109 if (sad > max_sad) {
110 break;
111 }
Johannfbea8972012-06-28 11:43:58 -0700112 }
113 return sad;
114 }
115
116 void FillConstant(uint8_t *data, int stride, uint8_t fill_constant) {
117 for (int h = 0; h < height_; ++h) {
118 for (int w = 0; w < width_; ++w) {
119 data[h * stride + w] = fill_constant;
120 }
121 }
122 }
123
124 void FillRandom(uint8_t *data, int stride) {
125 for (int h = 0; h < height_; ++h) {
126 for (int w = 0; w < width_; ++w) {
127 data[h * stride + w] = rnd_.Rand8();
128 }
129 }
130 }
131
John Koleszar1cfc86e2013-03-01 12:43:41 -0800132 int width_, height_;
133 static uint8_t* source_data_;
134 int source_stride_;
135 static uint8_t* reference_data_;
136 int reference_stride_;
137
138 ACMRandom rnd_;
139};
140
Deb Mukherjeefc882922014-05-13 10:11:42 -0700141class SADx4Test
142 : public SADTestBase,
143 public ::testing::WithParamInterface<sad_n_by_n_by_4_test_param_t> {
John Koleszar1cfc86e2013-03-01 12:43:41 -0800144 public:
145 SADx4Test() : SADTestBase(GET_PARAM(0), GET_PARAM(1)) {}
146
147 protected:
148 void SADs(unsigned int *results) {
149 const uint8_t* refs[] = {GetReference(0), GetReference(1),
150 GetReference(2), GetReference(3)};
151
152 REGISTER_STATE_CHECK(GET_PARAM(2)(source_data_, source_stride_,
153 refs, reference_stride_,
154 results));
155 }
156
157 void CheckSADs() {
158 unsigned int reference_sad, exp_sad[4];
159
160 SADs(exp_sad);
Deb Mukherjeefc882922014-05-13 10:11:42 -0700161 for (int block = 0; block < 4; ++block) {
Jim Bankoskia16794d2014-05-15 08:31:20 -0700162 reference_sad = ReferenceSAD(UINT_MAX, block);
John Koleszar1cfc86e2013-03-01 12:43:41 -0800163
Deb Mukherjeefc882922014-05-13 10:11:42 -0700164 EXPECT_EQ(reference_sad, exp_sad[block]) << "block " << block;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800165 }
166 }
167};
168
Deb Mukherjeefc882922014-05-13 10:11:42 -0700169#if CONFIG_VP8_ENCODER
170class SADTest
171 : public SADTestBase,
172 public ::testing::WithParamInterface<sad_m_by_n_test_param_t> {
173 public:
174 SADTest() : SADTestBase(GET_PARAM(0), GET_PARAM(1)) {}
175
176 protected:
177 unsigned int SAD(unsigned int max_sad, int block_idx) {
178 unsigned int ret;
179 const uint8_t* const reference = GetReference(block_idx);
180
181 REGISTER_STATE_CHECK(ret = GET_PARAM(2)(source_data_, source_stride_,
182 reference, reference_stride_,
183 max_sad));
184 return ret;
185 }
186
187 void CheckSAD(unsigned int max_sad) {
188 const unsigned int reference_sad = ReferenceSAD(max_sad, 0);
189 const unsigned int exp_sad = SAD(max_sad, 0);
190
191 if (reference_sad <= max_sad) {
192 ASSERT_EQ(exp_sad, reference_sad);
193 } else {
194 // Alternative implementations are not required to check max_sad
195 ASSERT_GE(exp_sad, reference_sad);
196 }
197 }
198};
199#endif // CONFIG_VP8_ENCODER
200
201#if CONFIG_VP9_ENCODER
202class SADVP9Test
203 : public SADTestBase,
204 public ::testing::WithParamInterface<sad_m_by_n_test_param_vp9_t> {
205 public:
206 SADVP9Test() : SADTestBase(GET_PARAM(0), GET_PARAM(1)) {}
207
208 protected:
209 unsigned int SAD(int block_idx) {
210 unsigned int ret;
211 const uint8_t* const reference = GetReference(block_idx);
212
213 REGISTER_STATE_CHECK(ret = GET_PARAM(2)(source_data_, source_stride_,
214 reference, reference_stride_));
215 return ret;
216 }
217
218 void CheckSAD() {
219 const unsigned int reference_sad = ReferenceSAD(UINT_MAX, 0);
220 const unsigned int exp_sad = SAD(0);
221
222 ASSERT_EQ(reference_sad, exp_sad);
223 }
224};
225#endif // CONFIG_VP9_ENCODER
226
John Koleszar1cfc86e2013-03-01 12:43:41 -0800227uint8_t* SADTestBase::source_data_ = NULL;
228uint8_t* SADTestBase::reference_data_ = NULL;
James Zern10f8b362012-08-27 17:13:09 -0700229
Deb Mukherjeefc882922014-05-13 10:11:42 -0700230#if CONFIG_VP8_ENCODER
Johannfbea8972012-06-28 11:43:58 -0700231TEST_P(SADTest, MaxRef) {
232 FillConstant(source_data_, source_stride_, 0);
233 FillConstant(reference_data_, reference_stride_, 255);
Deb Mukherjeefc882922014-05-13 10:11:42 -0700234 CheckSAD(UINT_MAX);
Johannfbea8972012-06-28 11:43:58 -0700235}
236
Deb Mukherjeefc882922014-05-13 10:11:42 -0700237TEST_P(SADTest, MaxSrc) {
238 FillConstant(source_data_, source_stride_, 255);
239 FillConstant(reference_data_, reference_stride_, 0);
240 CheckSAD(UINT_MAX);
241}
242
243TEST_P(SADTest, ShortRef) {
244 int tmp_stride = reference_stride_;
245 reference_stride_ >>= 1;
246 FillRandom(source_data_, source_stride_);
247 FillRandom(reference_data_, reference_stride_);
248 CheckSAD(UINT_MAX);
249 reference_stride_ = tmp_stride;
250}
251
252TEST_P(SADTest, UnalignedRef) {
253 // The reference frame, but not the source frame, may be unaligned for
254 // certain types of searches.
255 const int tmp_stride = reference_stride_;
256 reference_stride_ -= 1;
257 FillRandom(source_data_, source_stride_);
258 FillRandom(reference_data_, reference_stride_);
259 CheckSAD(UINT_MAX);
260 reference_stride_ = tmp_stride;
261}
262
263TEST_P(SADTest, ShortSrc) {
264 const int tmp_stride = source_stride_;
265 source_stride_ >>= 1;
266 FillRandom(source_data_, source_stride_);
267 FillRandom(reference_data_, reference_stride_);
268 CheckSAD(UINT_MAX);
269 source_stride_ = tmp_stride;
270}
271
272TEST_P(SADTest, MaxSAD) {
273 // Verify that, when max_sad is set, the implementation does not return a
274 // value lower than the reference.
275 FillConstant(source_data_, source_stride_, 255);
276 FillConstant(reference_data_, reference_stride_, 0);
277 CheckSAD(128);
278}
279#endif // CONFIG_VP8_ENCODER
280
281#if CONFIG_VP9_ENCODER
282TEST_P(SADVP9Test, MaxRef) {
283 FillConstant(source_data_, source_stride_, 0);
284 FillConstant(reference_data_, reference_stride_, 255);
285 CheckSAD();
286}
287
288TEST_P(SADVP9Test, MaxSrc) {
289 FillConstant(source_data_, source_stride_, 255);
290 FillConstant(reference_data_, reference_stride_, 0);
291 CheckSAD();
292}
293
294TEST_P(SADVP9Test, ShortRef) {
295 const int tmp_stride = reference_stride_;
296 reference_stride_ >>= 1;
297 FillRandom(source_data_, source_stride_);
298 FillRandom(reference_data_, reference_stride_);
299 CheckSAD();
300 reference_stride_ = tmp_stride;
301}
302
303TEST_P(SADVP9Test, UnalignedRef) {
304 // The reference frame, but not the source frame, may be unaligned for
305 // certain types of searches.
306 const int tmp_stride = reference_stride_;
307 reference_stride_ -= 1;
308 FillRandom(source_data_, source_stride_);
309 FillRandom(reference_data_, reference_stride_);
310 CheckSAD();
311 reference_stride_ = tmp_stride;
312}
313
314TEST_P(SADVP9Test, ShortSrc) {
315 const int tmp_stride = source_stride_;
316 source_stride_ >>= 1;
317 FillRandom(source_data_, source_stride_);
318 FillRandom(reference_data_, reference_stride_);
319 CheckSAD();
320 source_stride_ = tmp_stride;
321}
322#endif // CONFIG_VP9_ENCODER
323
John Koleszar1cfc86e2013-03-01 12:43:41 -0800324TEST_P(SADx4Test, MaxRef) {
325 FillConstant(source_data_, source_stride_, 0);
326 FillConstant(GetReference(0), reference_stride_, 255);
327 FillConstant(GetReference(1), reference_stride_, 255);
328 FillConstant(GetReference(2), reference_stride_, 255);
329 FillConstant(GetReference(3), reference_stride_, 255);
330 CheckSADs();
331}
332
John Koleszar1cfc86e2013-03-01 12:43:41 -0800333TEST_P(SADx4Test, MaxSrc) {
334 FillConstant(source_data_, source_stride_, 255);
335 FillConstant(GetReference(0), reference_stride_, 0);
336 FillConstant(GetReference(1), reference_stride_, 0);
337 FillConstant(GetReference(2), reference_stride_, 0);
338 FillConstant(GetReference(3), reference_stride_, 0);
339 CheckSADs();
340}
341
John Koleszar1cfc86e2013-03-01 12:43:41 -0800342TEST_P(SADx4Test, ShortRef) {
343 int tmp_stride = reference_stride_;
344 reference_stride_ >>= 1;
345 FillRandom(source_data_, source_stride_);
346 FillRandom(GetReference(0), reference_stride_);
347 FillRandom(GetReference(1), reference_stride_);
348 FillRandom(GetReference(2), reference_stride_);
349 FillRandom(GetReference(3), reference_stride_);
350 CheckSADs();
351 reference_stride_ = tmp_stride;
352}
353
John Koleszar1cfc86e2013-03-01 12:43:41 -0800354TEST_P(SADx4Test, UnalignedRef) {
355 // The reference frame, but not the source frame, may be unaligned for
356 // certain types of searches.
357 int tmp_stride = reference_stride_;
358 reference_stride_ -= 1;
359 FillRandom(source_data_, source_stride_);
360 FillRandom(GetReference(0), reference_stride_);
361 FillRandom(GetReference(1), reference_stride_);
362 FillRandom(GetReference(2), reference_stride_);
363 FillRandom(GetReference(3), reference_stride_);
364 CheckSADs();
365 reference_stride_ = tmp_stride;
366}
367
John Koleszar1cfc86e2013-03-01 12:43:41 -0800368TEST_P(SADx4Test, ShortSrc) {
369 int tmp_stride = source_stride_;
370 source_stride_ >>= 1;
371 FillRandom(source_data_, source_stride_);
372 FillRandom(GetReference(0), reference_stride_);
373 FillRandom(GetReference(1), reference_stride_);
374 FillRandom(GetReference(2), reference_stride_);
375 FillRandom(GetReference(3), reference_stride_);
376 CheckSADs();
377 source_stride_ = tmp_stride;
378}
379
James Zern12ddb752012-08-15 11:54:41 -0700380using std::tr1::make_tuple;
381
James Zernd7cff282014-02-27 12:49:02 -0800382//------------------------------------------------------------------------------
383// C functions
John Koleszar6b653cb2013-02-28 17:03:02 -0800384#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700385const sad_m_by_n_fn_t sad_16x16_c = vp8_sad16x16_c;
386const sad_m_by_n_fn_t sad_8x16_c = vp8_sad8x16_c;
387const sad_m_by_n_fn_t sad_16x8_c = vp8_sad16x8_c;
388const sad_m_by_n_fn_t sad_8x8_c = vp8_sad8x8_c;
389const sad_m_by_n_fn_t sad_4x4_c = vp8_sad4x4_c;
James Zern5e3439b2013-05-29 17:47:18 -0700390const sad_m_by_n_test_param_t c_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700391 make_tuple(16, 16, sad_16x16_c),
392 make_tuple(8, 16, sad_8x16_c),
393 make_tuple(16, 8, sad_16x8_c),
394 make_tuple(8, 8, sad_8x8_c),
395 make_tuple(4, 4, sad_4x4_c),
Deb Mukherjeefc882922014-05-13 10:11:42 -0700396};
397INSTANTIATE_TEST_CASE_P(C, SADTest, ::testing::ValuesIn(c_tests));
398#endif // CONFIG_VP8_ENCODER
399
John Koleszar6b653cb2013-02-28 17:03:02 -0800400#if CONFIG_VP9_ENCODER
Deb Mukherjeefc882922014-05-13 10:11:42 -0700401const sad_m_by_n_fn_vp9_t sad_64x64_c_vp9 = vp9_sad64x64_c;
402const sad_m_by_n_fn_vp9_t sad_32x32_c_vp9 = vp9_sad32x32_c;
403const sad_m_by_n_fn_vp9_t sad_16x16_c_vp9 = vp9_sad16x16_c;
404const sad_m_by_n_fn_vp9_t sad_8x16_c_vp9 = vp9_sad8x16_c;
405const sad_m_by_n_fn_vp9_t sad_16x8_c_vp9 = vp9_sad16x8_c;
406const sad_m_by_n_fn_vp9_t sad_8x8_c_vp9 = vp9_sad8x8_c;
407const sad_m_by_n_fn_vp9_t sad_8x4_c_vp9 = vp9_sad8x4_c;
408const sad_m_by_n_fn_vp9_t sad_4x8_c_vp9 = vp9_sad4x8_c;
409const sad_m_by_n_fn_vp9_t sad_4x4_c_vp9 = vp9_sad4x4_c;
410const sad_m_by_n_test_param_vp9_t c_vp9_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700411 make_tuple(64, 64, sad_64x64_c_vp9),
412 make_tuple(32, 32, sad_32x32_c_vp9),
413 make_tuple(16, 16, sad_16x16_c_vp9),
414 make_tuple(8, 16, sad_8x16_c_vp9),
415 make_tuple(16, 8, sad_16x8_c_vp9),
416 make_tuple(8, 8, sad_8x8_c_vp9),
Jingning Han15f50e72013-06-13 11:07:12 -0700417 make_tuple(8, 4, sad_8x4_c_vp9),
418 make_tuple(4, 8, sad_4x8_c_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700419 make_tuple(4, 4, sad_4x4_c_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700420};
Deb Mukherjeefc882922014-05-13 10:11:42 -0700421INSTANTIATE_TEST_CASE_P(C, SADVP9Test, ::testing::ValuesIn(c_vp9_tests));
Johannfbea8972012-06-28 11:43:58 -0700422
John Koleszar1cfc86e2013-03-01 12:43:41 -0800423const sad_n_by_n_by_4_fn_t sad_64x64x4d_c = vp9_sad64x64x4d_c;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700424const sad_n_by_n_by_4_fn_t sad_64x32x4d_c = vp9_sad64x32x4d_c;
425const sad_n_by_n_by_4_fn_t sad_32x64x4d_c = vp9_sad32x64x4d_c;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800426const sad_n_by_n_by_4_fn_t sad_32x32x4d_c = vp9_sad32x32x4d_c;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700427const sad_n_by_n_by_4_fn_t sad_32x16x4d_c = vp9_sad32x16x4d_c;
428const sad_n_by_n_by_4_fn_t sad_16x32x4d_c = vp9_sad16x32x4d_c;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800429const sad_n_by_n_by_4_fn_t sad_16x16x4d_c = vp9_sad16x16x4d_c;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700430const sad_n_by_n_by_4_fn_t sad_16x8x4d_c = vp9_sad16x8x4d_c;
431const sad_n_by_n_by_4_fn_t sad_8x16x4d_c = vp9_sad8x16x4d_c;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800432const sad_n_by_n_by_4_fn_t sad_8x8x4d_c = vp9_sad8x8x4d_c;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700433const sad_n_by_n_by_4_fn_t sad_8x4x4d_c = vp9_sad8x4x4d_c;
434const sad_n_by_n_by_4_fn_t sad_4x8x4d_c = vp9_sad4x8x4d_c;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800435const sad_n_by_n_by_4_fn_t sad_4x4x4d_c = vp9_sad4x4x4d_c;
436INSTANTIATE_TEST_CASE_P(C, SADx4Test, ::testing::Values(
437 make_tuple(64, 64, sad_64x64x4d_c),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700438 make_tuple(64, 32, sad_64x32x4d_c),
439 make_tuple(32, 64, sad_32x64x4d_c),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800440 make_tuple(32, 32, sad_32x32x4d_c),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700441 make_tuple(32, 16, sad_32x16x4d_c),
442 make_tuple(16, 32, sad_16x32x4d_c),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800443 make_tuple(16, 16, sad_16x16x4d_c),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700444 make_tuple(16, 8, sad_16x8x4d_c),
445 make_tuple(8, 16, sad_8x16x4d_c),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800446 make_tuple(8, 8, sad_8x8x4d_c),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700447 make_tuple(8, 4, sad_8x4x4d_c),
448 make_tuple(4, 8, sad_4x8x4d_c),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800449 make_tuple(4, 4, sad_4x4x4d_c)));
James Zernd7cff282014-02-27 12:49:02 -0800450#endif // CONFIG_VP9_ENCODER
John Koleszar1cfc86e2013-03-01 12:43:41 -0800451
James Zernd7cff282014-02-27 12:49:02 -0800452//------------------------------------------------------------------------------
453// ARM functions
Johannfbea8972012-06-28 11:43:58 -0700454#if HAVE_MEDIA
James Zern5f1486f2014-02-27 14:03:21 -0800455#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700456const sad_m_by_n_fn_t sad_16x16_armv6 = vp8_sad16x16_armv6;
Johannfbea8972012-06-28 11:43:58 -0700457INSTANTIATE_TEST_CASE_P(MEDIA, SADTest, ::testing::Values(
James Zern12ddb752012-08-15 11:54:41 -0700458 make_tuple(16, 16, sad_16x16_armv6)));
Deb Mukherjeefc882922014-05-13 10:11:42 -0700459#endif // CONFIG_VP8_ENCODER
460#endif // HAVE_MEDIA
James Zern5f1486f2014-02-27 14:03:21 -0800461
Johannfbea8972012-06-28 11:43:58 -0700462#if HAVE_NEON
James Zern5f1486f2014-02-27 14:03:21 -0800463#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700464const sad_m_by_n_fn_t sad_16x16_neon = vp8_sad16x16_neon;
465const sad_m_by_n_fn_t sad_8x16_neon = vp8_sad8x16_neon;
466const sad_m_by_n_fn_t sad_16x8_neon = vp8_sad16x8_neon;
467const sad_m_by_n_fn_t sad_8x8_neon = vp8_sad8x8_neon;
468const sad_m_by_n_fn_t sad_4x4_neon = vp8_sad4x4_neon;
Johannfbea8972012-06-28 11:43:58 -0700469INSTANTIATE_TEST_CASE_P(NEON, SADTest, ::testing::Values(
James Zern12ddb752012-08-15 11:54:41 -0700470 make_tuple(16, 16, sad_16x16_neon),
471 make_tuple(8, 16, sad_8x16_neon),
472 make_tuple(16, 8, sad_16x8_neon),
473 make_tuple(8, 8, sad_8x8_neon),
474 make_tuple(4, 4, sad_4x4_neon)));
Deb Mukherjeefc882922014-05-13 10:11:42 -0700475#endif // CONFIG_VP8_ENCODER
476#endif // HAVE_NEON
Johannfbea8972012-06-28 11:43:58 -0700477
James Zernd7cff282014-02-27 12:49:02 -0800478//------------------------------------------------------------------------------
479// x86 functions
Johannfbea8972012-06-28 11:43:58 -0700480#if HAVE_MMX
John Koleszar6b653cb2013-02-28 17:03:02 -0800481#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700482const sad_m_by_n_fn_t sad_16x16_mmx = vp8_sad16x16_mmx;
483const sad_m_by_n_fn_t sad_8x16_mmx = vp8_sad8x16_mmx;
484const sad_m_by_n_fn_t sad_16x8_mmx = vp8_sad16x8_mmx;
485const sad_m_by_n_fn_t sad_8x8_mmx = vp8_sad8x8_mmx;
486const sad_m_by_n_fn_t sad_4x4_mmx = vp8_sad4x4_mmx;
James Zern5e3439b2013-05-29 17:47:18 -0700487const sad_m_by_n_test_param_t mmx_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700488 make_tuple(16, 16, sad_16x16_mmx),
489 make_tuple(8, 16, sad_8x16_mmx),
490 make_tuple(16, 8, sad_16x8_mmx),
491 make_tuple(8, 8, sad_8x8_mmx),
492 make_tuple(4, 4, sad_4x4_mmx),
Deb Mukherjeefc882922014-05-13 10:11:42 -0700493};
494INSTANTIATE_TEST_CASE_P(MMX, SADTest, ::testing::ValuesIn(mmx_tests));
495#endif // CONFIG_VP8_ENCODER
496
John Koleszar6b653cb2013-02-28 17:03:02 -0800497#if CONFIG_VP9_ENCODER
Deb Mukherjeefc882922014-05-13 10:11:42 -0700498const sad_m_by_n_fn_vp9_t sad_16x16_mmx_vp9 = vp9_sad16x16_mmx;
499const sad_m_by_n_fn_vp9_t sad_8x16_mmx_vp9 = vp9_sad8x16_mmx;
500const sad_m_by_n_fn_vp9_t sad_16x8_mmx_vp9 = vp9_sad16x8_mmx;
501const sad_m_by_n_fn_vp9_t sad_8x8_mmx_vp9 = vp9_sad8x8_mmx;
502const sad_m_by_n_fn_vp9_t sad_4x4_mmx_vp9 = vp9_sad4x4_mmx;
503const sad_m_by_n_test_param_vp9_t mmx_vp9_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700504 make_tuple(16, 16, sad_16x16_mmx_vp9),
505 make_tuple(8, 16, sad_8x16_mmx_vp9),
506 make_tuple(16, 8, sad_16x8_mmx_vp9),
507 make_tuple(8, 8, sad_8x8_mmx_vp9),
508 make_tuple(4, 4, sad_4x4_mmx_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700509};
Deb Mukherjeefc882922014-05-13 10:11:42 -0700510INSTANTIATE_TEST_CASE_P(MMX, SADVP9Test, ::testing::ValuesIn(mmx_vp9_tests));
511#endif // CONFIG_VP9_ENCODER
512#endif // HAVE_MMX
John Koleszar6b653cb2013-02-28 17:03:02 -0800513
514#if HAVE_SSE
515#if CONFIG_VP9_ENCODER
Jim Bankoskic9126e02013-08-06 07:31:54 -0700516#if CONFIG_USE_X86INC
Deb Mukherjeefc882922014-05-13 10:11:42 -0700517const sad_m_by_n_fn_vp9_t sad_4x4_sse_vp9 = vp9_sad4x4_sse;
518const sad_m_by_n_fn_vp9_t sad_4x8_sse_vp9 = vp9_sad4x8_sse;
519INSTANTIATE_TEST_CASE_P(SSE, SADVP9Test, ::testing::Values(
Jingning Han15f50e72013-06-13 11:07:12 -0700520 make_tuple(4, 4, sad_4x4_sse_vp9),
521 make_tuple(4, 8, sad_4x8_sse_vp9)));
John Koleszar1cfc86e2013-03-01 12:43:41 -0800522
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700523const sad_n_by_n_by_4_fn_t sad_4x8x4d_sse = vp9_sad4x8x4d_sse;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800524const sad_n_by_n_by_4_fn_t sad_4x4x4d_sse = vp9_sad4x4x4d_sse;
525INSTANTIATE_TEST_CASE_P(SSE, SADx4Test, ::testing::Values(
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700526 make_tuple(4, 8, sad_4x8x4d_sse),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800527 make_tuple(4, 4, sad_4x4x4d_sse)));
James Zernd7cff282014-02-27 12:49:02 -0800528#endif // CONFIG_USE_X86INC
529#endif // CONFIG_VP9_ENCODER
530#endif // HAVE_SSE
John Koleszar6b653cb2013-02-28 17:03:02 -0800531
Johannfbea8972012-06-28 11:43:58 -0700532#if HAVE_SSE2
John Koleszar6b653cb2013-02-28 17:03:02 -0800533#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700534const sad_m_by_n_fn_t sad_16x16_wmt = vp8_sad16x16_wmt;
535const sad_m_by_n_fn_t sad_8x16_wmt = vp8_sad8x16_wmt;
536const sad_m_by_n_fn_t sad_16x8_wmt = vp8_sad16x8_wmt;
537const sad_m_by_n_fn_t sad_8x8_wmt = vp8_sad8x8_wmt;
538const sad_m_by_n_fn_t sad_4x4_wmt = vp8_sad4x4_wmt;
James Zern5e3439b2013-05-29 17:47:18 -0700539const sad_m_by_n_test_param_t sse2_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700540 make_tuple(16, 16, sad_16x16_wmt),
541 make_tuple(8, 16, sad_8x16_wmt),
542 make_tuple(16, 8, sad_16x8_wmt),
543 make_tuple(8, 8, sad_8x8_wmt),
544 make_tuple(4, 4, sad_4x4_wmt),
Deb Mukherjeefc882922014-05-13 10:11:42 -0700545};
546INSTANTIATE_TEST_CASE_P(SSE2, SADTest, ::testing::ValuesIn(sse2_tests));
547#endif // CONFIG_VP8_ENCODER
548
John Koleszar6b653cb2013-02-28 17:03:02 -0800549#if CONFIG_VP9_ENCODER
Jim Bankoskic9126e02013-08-06 07:31:54 -0700550#if CONFIG_USE_X86INC
Deb Mukherjeefc882922014-05-13 10:11:42 -0700551const sad_m_by_n_fn_vp9_t sad_64x64_sse2_vp9 = vp9_sad64x64_sse2;
552const sad_m_by_n_fn_vp9_t sad_64x32_sse2_vp9 = vp9_sad64x32_sse2;
553const sad_m_by_n_fn_vp9_t sad_32x64_sse2_vp9 = vp9_sad32x64_sse2;
554const sad_m_by_n_fn_vp9_t sad_32x32_sse2_vp9 = vp9_sad32x32_sse2;
555const sad_m_by_n_fn_vp9_t sad_32x16_sse2_vp9 = vp9_sad32x16_sse2;
556const sad_m_by_n_fn_vp9_t sad_16x32_sse2_vp9 = vp9_sad16x32_sse2;
557const sad_m_by_n_fn_vp9_t sad_16x16_sse2_vp9 = vp9_sad16x16_sse2;
558const sad_m_by_n_fn_vp9_t sad_16x8_sse2_vp9 = vp9_sad16x8_sse2;
559const sad_m_by_n_fn_vp9_t sad_8x16_sse2_vp9 = vp9_sad8x16_sse2;
560const sad_m_by_n_fn_vp9_t sad_8x8_sse2_vp9 = vp9_sad8x8_sse2;
561const sad_m_by_n_fn_vp9_t sad_8x4_sse2_vp9 = vp9_sad8x4_sse2;
562const sad_m_by_n_test_param_vp9_t sse2_vp9_tests[] = {
James Zern5e3439b2013-05-29 17:47:18 -0700563 make_tuple(64, 64, sad_64x64_sse2_vp9),
Ronald S. Bultje3c4abbe2013-06-24 11:28:19 -0700564 make_tuple(64, 32, sad_64x32_sse2_vp9),
565 make_tuple(32, 64, sad_32x64_sse2_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700566 make_tuple(32, 32, sad_32x32_sse2_vp9),
Ronald S. Bultje3c4abbe2013-06-24 11:28:19 -0700567 make_tuple(32, 16, sad_32x16_sse2_vp9),
568 make_tuple(16, 32, sad_16x32_sse2_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700569 make_tuple(16, 16, sad_16x16_sse2_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700570 make_tuple(16, 8, sad_16x8_sse2_vp9),
Ronald S. Bultje3c4abbe2013-06-24 11:28:19 -0700571 make_tuple(8, 16, sad_8x16_sse2_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700572 make_tuple(8, 8, sad_8x8_sse2_vp9),
Jingning Han15f50e72013-06-13 11:07:12 -0700573 make_tuple(8, 4, sad_8x4_sse2_vp9),
James Zern5e3439b2013-05-29 17:47:18 -0700574};
Deb Mukherjeefc882922014-05-13 10:11:42 -0700575INSTANTIATE_TEST_CASE_P(SSE2, SADVP9Test, ::testing::ValuesIn(sse2_vp9_tests));
John Koleszar1cfc86e2013-03-01 12:43:41 -0800576
John Koleszar1cfc86e2013-03-01 12:43:41 -0800577const sad_n_by_n_by_4_fn_t sad_64x64x4d_sse2 = vp9_sad64x64x4d_sse2;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700578const sad_n_by_n_by_4_fn_t sad_64x32x4d_sse2 = vp9_sad64x32x4d_sse2;
579const sad_n_by_n_by_4_fn_t sad_32x64x4d_sse2 = vp9_sad32x64x4d_sse2;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800580const sad_n_by_n_by_4_fn_t sad_32x32x4d_sse2 = vp9_sad32x32x4d_sse2;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700581const sad_n_by_n_by_4_fn_t sad_32x16x4d_sse2 = vp9_sad32x16x4d_sse2;
582const sad_n_by_n_by_4_fn_t sad_16x32x4d_sse2 = vp9_sad16x32x4d_sse2;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800583const sad_n_by_n_by_4_fn_t sad_16x16x4d_sse2 = vp9_sad16x16x4d_sse2;
584const sad_n_by_n_by_4_fn_t sad_16x8x4d_sse2 = vp9_sad16x8x4d_sse2;
585const sad_n_by_n_by_4_fn_t sad_8x16x4d_sse2 = vp9_sad8x16x4d_sse2;
586const sad_n_by_n_by_4_fn_t sad_8x8x4d_sse2 = vp9_sad8x8x4d_sse2;
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700587const sad_n_by_n_by_4_fn_t sad_8x4x4d_sse2 = vp9_sad8x4x4d_sse2;
John Koleszar1cfc86e2013-03-01 12:43:41 -0800588INSTANTIATE_TEST_CASE_P(SSE2, SADx4Test, ::testing::Values(
589 make_tuple(64, 64, sad_64x64x4d_sse2),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700590 make_tuple(64, 32, sad_64x32x4d_sse2),
591 make_tuple(32, 64, sad_32x64x4d_sse2),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800592 make_tuple(32, 32, sad_32x32x4d_sse2),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700593 make_tuple(32, 16, sad_32x16x4d_sse2),
594 make_tuple(16, 32, sad_16x32x4d_sse2),
John Koleszar1cfc86e2013-03-01 12:43:41 -0800595 make_tuple(16, 16, sad_16x16x4d_sse2),
596 make_tuple(16, 8, sad_16x8x4d_sse2),
597 make_tuple(8, 16, sad_8x16x4d_sse2),
Ronald S. Bultjefa96eeb2013-06-11 15:19:14 -0700598 make_tuple(8, 8, sad_8x8x4d_sse2),
599 make_tuple(8, 4, sad_8x4x4d_sse2)));
Deb Mukherjeefc882922014-05-13 10:11:42 -0700600#endif // CONFIG_USE_X86INC
601#endif // CONFIG_VP9_ENCODER
602#endif // HAVE_SSE2
John Koleszar1cfc86e2013-03-01 12:43:41 -0800603
604#if HAVE_SSE3
605#if CONFIG_VP8_ENCODER
606const sad_n_by_n_by_4_fn_t sad_16x16x4d_sse3 = vp8_sad16x16x4d_sse3;
607const sad_n_by_n_by_4_fn_t sad_16x8x4d_sse3 = vp8_sad16x8x4d_sse3;
608const sad_n_by_n_by_4_fn_t sad_8x16x4d_sse3 = vp8_sad8x16x4d_sse3;
609const sad_n_by_n_by_4_fn_t sad_8x8x4d_sse3 = vp8_sad8x8x4d_sse3;
610const sad_n_by_n_by_4_fn_t sad_4x4x4d_sse3 = vp8_sad4x4x4d_sse3;
611INSTANTIATE_TEST_CASE_P(SSE3, SADx4Test, ::testing::Values(
612 make_tuple(16, 16, sad_16x16x4d_sse3),
613 make_tuple(16, 8, sad_16x8x4d_sse3),
614 make_tuple(8, 16, sad_8x16x4d_sse3),
615 make_tuple(8, 8, sad_8x8x4d_sse3),
616 make_tuple(4, 4, sad_4x4x4d_sse3)));
Deb Mukherjeefc882922014-05-13 10:11:42 -0700617#endif // CONFIG_VP8_ENCODER
618#endif // HAVE_SSE3
John Koleszar6b653cb2013-02-28 17:03:02 -0800619
Johannfbea8972012-06-28 11:43:58 -0700620#if HAVE_SSSE3
Jim Bankoski5b307882013-08-06 08:25:10 -0700621#if CONFIG_USE_X86INC
Yaowu Xu24c1734f2014-02-28 15:26:09 -0800622#if CONFIG_VP8_ENCODER
James Zern12ddb752012-08-15 11:54:41 -0700623const sad_m_by_n_fn_t sad_16x16_sse3 = vp8_sad16x16_sse3;
Johannfbea8972012-06-28 11:43:58 -0700624INSTANTIATE_TEST_CASE_P(SSE3, SADTest, ::testing::Values(
James Zern12ddb752012-08-15 11:54:41 -0700625 make_tuple(16, 16, sad_16x16_sse3)));
Deb Mukherjeefc882922014-05-13 10:11:42 -0700626#endif // CONFIG_VP8_ENCODER
627#endif // CONFIG_USE_X86INC
628#endif // HAVE_SSSE3
Johannfbea8972012-06-28 11:43:58 -0700629
James Zernd3ff0092014-06-08 18:25:37 -0700630#if HAVE_AVX2
631#if CONFIG_VP9_ENCODER
632// TODO(jzern): these prototypes can be removed after the avx2 versions are
633// reenabled in vp9_rtcd_defs.pl.
634extern "C" {
635void vp9_sad32x32x4d_avx2(const uint8_t *src_ptr, int src_stride,
636 const uint8_t *const ref_ptr[], int ref_stride,
637 unsigned int *sad_array);
638void vp9_sad64x64x4d_avx2(const uint8_t *src_ptr, int src_stride,
639 const uint8_t *const ref_ptr[], int ref_stride,
640 unsigned int *sad_array);
641}
642const sad_n_by_n_by_4_fn_t sad_64x64x4d_avx2 = vp9_sad64x64x4d_avx2;
643const sad_n_by_n_by_4_fn_t sad_32x32x4d_avx2 = vp9_sad32x32x4d_avx2;
644INSTANTIATE_TEST_CASE_P(DISABLED_AVX2, SADx4Test, ::testing::Values(
645 make_tuple(32, 32, sad_32x32x4d_avx2),
646 make_tuple(64, 64, sad_64x64x4d_avx2)));
647#endif // CONFIG_VP9_ENCODER
648#endif // HAVE_AVX2
649
Johannfbea8972012-06-28 11:43:58 -0700650} // namespace