• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * 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.
10  */
11 
12 #include <string.h>
13 #include <tuple>
14 
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 
17 #include "config/aom_config.h"
18 #include "config/aom_dsp_rtcd.h"
19 
20 #include "aom_dsp/aom_dsp_common.h"
21 #include "aom_dsp/aom_filter.h"
22 #include "aom_mem/aom_mem.h"
23 #include "aom_ports/aom_timer.h"
24 #include "aom_ports/mem.h"
25 #include "av1/common/filter.h"
26 #include "test/acm_random.h"
27 #include "test/register_state_check.h"
28 #include "test/util.h"
29 
30 namespace {
31 
32 static const unsigned int kMaxDimension = MAX_SB_SIZE;
33 
34 static const int16_t kInvalidFilter[8] = {};
35 static const int kNumFilterBanks = SWITCHABLE_FILTERS;
36 static const int kNumFilters = 16;
37 
38 typedef void (*ConvolveFunc)(const uint8_t *src, ptrdiff_t src_stride,
39                              uint8_t *dst, ptrdiff_t dst_stride,
40                              const int16_t *filter_x, int filter_x_stride,
41                              const int16_t *filter_y, int filter_y_stride,
42                              int w, int h);
43 
44 struct ConvolveFunctions {
ConvolveFunctions__anon2ca081f60111::ConvolveFunctions45   ConvolveFunctions(ConvolveFunc h8, ConvolveFunc v8, int bd)
46       : h8_(h8), v8_(v8), use_highbd_(bd) {}
47 
48   ConvolveFunc h8_;
49   ConvolveFunc v8_;
50   int use_highbd_;  // 0 if high bitdepth not used, else the actual bit depth.
51 };
52 
53 typedef std::tuple<int, int, const ConvolveFunctions *> ConvolveParam;
54 
55 #define ALL_SIZES_64(convolve_fn)                                         \
56   make_tuple(4, 4, &convolve_fn), make_tuple(8, 4, &convolve_fn),         \
57       make_tuple(4, 8, &convolve_fn), make_tuple(8, 8, &convolve_fn),     \
58       make_tuple(16, 8, &convolve_fn), make_tuple(8, 16, &convolve_fn),   \
59       make_tuple(16, 16, &convolve_fn), make_tuple(32, 16, &convolve_fn), \
60       make_tuple(16, 32, &convolve_fn), make_tuple(32, 32, &convolve_fn), \
61       make_tuple(64, 32, &convolve_fn), make_tuple(32, 64, &convolve_fn), \
62       make_tuple(64, 64, &convolve_fn)
63 
64 #define ALL_SIZES(convolve_fn)                                          \
65   make_tuple(128, 64, &convolve_fn), make_tuple(64, 128, &convolve_fn), \
66       make_tuple(128, 128, &convolve_fn), ALL_SIZES_64(convolve_fn)
67 
68 // Reference 8-tap subpixel filter, slightly modified to fit into this test.
69 #define AV1_FILTER_WEIGHT 128
70 #define AV1_FILTER_SHIFT 7
clip_pixel(int x)71 uint8_t clip_pixel(int x) { return x < 0 ? 0 : x > 255 ? 255 : x; }
72 
filter_block2d_8_c(const uint8_t * src_ptr,unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint8_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height)73 void filter_block2d_8_c(const uint8_t *src_ptr, unsigned int src_stride,
74                         const int16_t *HFilter, const int16_t *VFilter,
75                         uint8_t *dst_ptr, unsigned int dst_stride,
76                         unsigned int output_width, unsigned int output_height) {
77   // Between passes, we use an intermediate buffer whose height is extended to
78   // have enough horizontally filtered values as input for the vertical pass.
79   // This buffer is allocated to be big enough for the largest block type we
80   // support.
81   const int kInterp_Extend = 4;
82   const unsigned int intermediate_height =
83       (kInterp_Extend - 1) + output_height + kInterp_Extend;
84   unsigned int i, j;
85 
86   assert(intermediate_height > 7);
87 
88   // Size of intermediate_buffer is max_intermediate_height * filter_max_width,
89   // where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
90   //                                 + kInterp_Extend
91   //                               = 3 + 16 + 4
92   //                               = 23
93   // and filter_max_width          = 16
94   //
95   uint8_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension];
96   const int intermediate_next_stride =
97       1 - static_cast<int>(intermediate_height * output_width);
98 
99   // Horizontal pass (src -> transposed intermediate).
100   uint8_t *output_ptr = intermediate_buffer;
101   const int src_next_row_stride = src_stride - output_width;
102   src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
103   for (i = 0; i < intermediate_height; ++i) {
104     for (j = 0; j < output_width; ++j) {
105       // Apply filter...
106       const int temp = (src_ptr[0] * HFilter[0]) + (src_ptr[1] * HFilter[1]) +
107                        (src_ptr[2] * HFilter[2]) + (src_ptr[3] * HFilter[3]) +
108                        (src_ptr[4] * HFilter[4]) + (src_ptr[5] * HFilter[5]) +
109                        (src_ptr[6] * HFilter[6]) + (src_ptr[7] * HFilter[7]) +
110                        (AV1_FILTER_WEIGHT >> 1);  // Rounding
111 
112       // Normalize back to 0-255...
113       *output_ptr = clip_pixel(temp >> AV1_FILTER_SHIFT);
114       ++src_ptr;
115       output_ptr += intermediate_height;
116     }
117     src_ptr += src_next_row_stride;
118     output_ptr += intermediate_next_stride;
119   }
120 
121   // Vertical pass (transposed intermediate -> dst).
122   src_ptr = intermediate_buffer;
123   const int dst_next_row_stride = dst_stride - output_width;
124   for (i = 0; i < output_height; ++i) {
125     for (j = 0; j < output_width; ++j) {
126       // Apply filter...
127       const int temp = (src_ptr[0] * VFilter[0]) + (src_ptr[1] * VFilter[1]) +
128                        (src_ptr[2] * VFilter[2]) + (src_ptr[3] * VFilter[3]) +
129                        (src_ptr[4] * VFilter[4]) + (src_ptr[5] * VFilter[5]) +
130                        (src_ptr[6] * VFilter[6]) + (src_ptr[7] * VFilter[7]) +
131                        (AV1_FILTER_WEIGHT >> 1);  // Rounding
132 
133       // Normalize back to 0-255...
134       *dst_ptr++ = clip_pixel(temp >> AV1_FILTER_SHIFT);
135       src_ptr += intermediate_height;
136     }
137     src_ptr += intermediate_next_stride;
138     dst_ptr += dst_next_row_stride;
139   }
140 }
141 
block2d_average_c(uint8_t * src,unsigned int src_stride,uint8_t * output_ptr,unsigned int output_stride,unsigned int output_width,unsigned int output_height)142 void block2d_average_c(uint8_t *src, unsigned int src_stride,
143                        uint8_t *output_ptr, unsigned int output_stride,
144                        unsigned int output_width, unsigned int output_height) {
145   unsigned int i, j;
146   for (i = 0; i < output_height; ++i) {
147     for (j = 0; j < output_width; ++j) {
148       output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
149     }
150     output_ptr += output_stride;
151   }
152 }
153 
filter_average_block2d_8_c(const uint8_t * src_ptr,const unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint8_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height)154 void filter_average_block2d_8_c(const uint8_t *src_ptr,
155                                 const unsigned int src_stride,
156                                 const int16_t *HFilter, const int16_t *VFilter,
157                                 uint8_t *dst_ptr, unsigned int dst_stride,
158                                 unsigned int output_width,
159                                 unsigned int output_height) {
160   uint8_t tmp[kMaxDimension * kMaxDimension];
161 
162   assert(output_width <= kMaxDimension);
163   assert(output_height <= kMaxDimension);
164   filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, kMaxDimension,
165                      output_width, output_height);
166   block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride, output_width,
167                     output_height);
168 }
169 
highbd_filter_block2d_8_c(const uint16_t * src_ptr,const unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint16_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height,int bd)170 void highbd_filter_block2d_8_c(const uint16_t *src_ptr,
171                                const unsigned int src_stride,
172                                const int16_t *HFilter, const int16_t *VFilter,
173                                uint16_t *dst_ptr, unsigned int dst_stride,
174                                unsigned int output_width,
175                                unsigned int output_height, int bd) {
176   // Between passes, we use an intermediate buffer whose height is extended to
177   // have enough horizontally filtered values as input for the vertical pass.
178   // This buffer is allocated to be big enough for the largest block type we
179   // support.
180   const int kInterp_Extend = 4;
181   const unsigned int intermediate_height =
182       (kInterp_Extend - 1) + output_height + kInterp_Extend;
183 
184   /* Size of intermediate_buffer is max_intermediate_height * filter_max_width,
185    * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
186    *                                 + kInterp_Extend
187    *                               = 3 + 16 + 4
188    *                               = 23
189    * and filter_max_width = 16
190    */
191   uint16_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension] = { 0 };
192   const int intermediate_next_stride =
193       1 - static_cast<int>(intermediate_height * output_width);
194 
195   // Horizontal pass (src -> transposed intermediate).
196   {
197     uint16_t *output_ptr = intermediate_buffer;
198     const int src_next_row_stride = src_stride - output_width;
199     unsigned int i, j;
200     src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
201     for (i = 0; i < intermediate_height; ++i) {
202       for (j = 0; j < output_width; ++j) {
203         // Apply filter...
204         const int temp = (src_ptr[0] * HFilter[0]) + (src_ptr[1] * HFilter[1]) +
205                          (src_ptr[2] * HFilter[2]) + (src_ptr[3] * HFilter[3]) +
206                          (src_ptr[4] * HFilter[4]) + (src_ptr[5] * HFilter[5]) +
207                          (src_ptr[6] * HFilter[6]) + (src_ptr[7] * HFilter[7]) +
208                          (AV1_FILTER_WEIGHT >> 1);  // Rounding
209 
210         // Normalize back to 0-255...
211         *output_ptr = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
212         ++src_ptr;
213         output_ptr += intermediate_height;
214       }
215       src_ptr += src_next_row_stride;
216       output_ptr += intermediate_next_stride;
217     }
218   }
219 
220   // Vertical pass (transposed intermediate -> dst).
221   {
222     const uint16_t *interm_ptr = intermediate_buffer;
223     const int dst_next_row_stride = dst_stride - output_width;
224     unsigned int i, j;
225     for (i = 0; i < output_height; ++i) {
226       for (j = 0; j < output_width; ++j) {
227         // Apply filter...
228         const int temp =
229             (interm_ptr[0] * VFilter[0]) + (interm_ptr[1] * VFilter[1]) +
230             (interm_ptr[2] * VFilter[2]) + (interm_ptr[3] * VFilter[3]) +
231             (interm_ptr[4] * VFilter[4]) + (interm_ptr[5] * VFilter[5]) +
232             (interm_ptr[6] * VFilter[6]) + (interm_ptr[7] * VFilter[7]) +
233             (AV1_FILTER_WEIGHT >> 1);  // Rounding
234 
235         // Normalize back to 0-255...
236         *dst_ptr++ = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
237         interm_ptr += intermediate_height;
238       }
239       interm_ptr += intermediate_next_stride;
240       dst_ptr += dst_next_row_stride;
241     }
242   }
243 }
244 
highbd_block2d_average_c(uint16_t * src,unsigned int src_stride,uint16_t * output_ptr,unsigned int output_stride,unsigned int output_width,unsigned int output_height)245 void highbd_block2d_average_c(uint16_t *src, unsigned int src_stride,
246                               uint16_t *output_ptr, unsigned int output_stride,
247                               unsigned int output_width,
248                               unsigned int output_height) {
249   unsigned int i, j;
250   for (i = 0; i < output_height; ++i) {
251     for (j = 0; j < output_width; ++j) {
252       output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
253     }
254     output_ptr += output_stride;
255   }
256 }
257 
highbd_filter_average_block2d_8_c(const uint16_t * src_ptr,unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint16_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height,int bd)258 void highbd_filter_average_block2d_8_c(
259     const uint16_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
260     const int16_t *VFilter, uint16_t *dst_ptr, unsigned int dst_stride,
261     unsigned int output_width, unsigned int output_height, int bd) {
262   uint16_t tmp[kMaxDimension * kMaxDimension];
263 
264   assert(output_width <= kMaxDimension);
265   assert(output_height <= kMaxDimension);
266   highbd_filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp,
267                             kMaxDimension, output_width, output_height, bd);
268   highbd_block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride,
269                            output_width, output_height);
270 }
271 
272 class ConvolveTestBase : public ::testing::TestWithParam<ConvolveParam> {
273  public:
SetUpTestSuite()274   static void SetUpTestSuite() {
275     // Force input_ to be unaligned, output to be 16 byte aligned.
276     input_ = reinterpret_cast<uint8_t *>(
277                  aom_memalign(kDataAlignment, kInputBufferSize + 1)) +
278              1;
279     ASSERT_NE(input_, nullptr);
280     ref8_ = reinterpret_cast<uint8_t *>(
281         aom_memalign(kDataAlignment, kOutputStride * kMaxDimension));
282     ASSERT_NE(ref8_, nullptr);
283     output_ = reinterpret_cast<uint8_t *>(
284         aom_memalign(kDataAlignment, kOutputBufferSize));
285     ASSERT_NE(output_, nullptr);
286     output_ref_ = reinterpret_cast<uint8_t *>(
287         aom_memalign(kDataAlignment, kOutputBufferSize));
288     ASSERT_NE(output_ref_, nullptr);
289     input16_ = reinterpret_cast<uint16_t *>(aom_memalign(
290                    kDataAlignment, (kInputBufferSize + 1) * sizeof(uint16_t))) +
291                1;
292     ASSERT_NE(input16_, nullptr);
293     ref16_ = reinterpret_cast<uint16_t *>(aom_memalign(
294         kDataAlignment, kOutputStride * kMaxDimension * sizeof(uint16_t)));
295     ASSERT_NE(ref16_, nullptr);
296     output16_ = reinterpret_cast<uint16_t *>(
297         aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
298     ASSERT_NE(output16_, nullptr);
299     output16_ref_ = reinterpret_cast<uint16_t *>(
300         aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
301     ASSERT_NE(output16_ref_, nullptr);
302   }
303 
TearDownTestSuite()304   static void TearDownTestSuite() {
305     aom_free(input_ - 1);
306     input_ = nullptr;
307     aom_free(ref8_);
308     ref8_ = nullptr;
309     aom_free(output_);
310     output_ = nullptr;
311     aom_free(output_ref_);
312     output_ref_ = nullptr;
313     aom_free(input16_ - 1);
314     input16_ = nullptr;
315     aom_free(ref16_);
316     ref16_ = nullptr;
317     aom_free(output16_);
318     output16_ = nullptr;
319     aom_free(output16_ref_);
320     output16_ref_ = nullptr;
321   }
322 
323  protected:
324   static const int kDataAlignment = 16;
325   static const int kOuterBlockSize = 4 * kMaxDimension;
326   static const int kInputStride = kOuterBlockSize;
327   static const int kOutputStride = kOuterBlockSize;
328   static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;
329   static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;
330 
Width() const331   int Width() const { return GET_PARAM(0); }
Height() const332   int Height() const { return GET_PARAM(1); }
BorderLeft() const333   int BorderLeft() const {
334     const int center = (kOuterBlockSize - Width()) / 2;
335     return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);
336   }
BorderTop() const337   int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }
338 
IsIndexInBorder(int i)339   bool IsIndexInBorder(int i) {
340     return (i < BorderTop() * kOuterBlockSize ||
341             i >= (BorderTop() + Height()) * kOuterBlockSize ||
342             i % kOuterBlockSize < BorderLeft() ||
343             i % kOuterBlockSize >= (BorderLeft() + Width()));
344   }
345 
SetUp()346   void SetUp() override {
347     UUT_ = GET_PARAM(2);
348     if (UUT_->use_highbd_ != 0)
349       mask_ = (1 << UUT_->use_highbd_) - 1;
350     else
351       mask_ = 255;
352     /* Set up guard blocks for an inner block centered in the outer block */
353     for (int i = 0; i < kOutputBufferSize; ++i) {
354       if (IsIndexInBorder(i)) {
355         output_[i] = 255;
356         output16_[i] = mask_;
357       } else {
358         output_[i] = 0;
359         output16_[i] = 0;
360       }
361     }
362 
363     ::libaom_test::ACMRandom prng;
364     for (int i = 0; i < kInputBufferSize; ++i) {
365       if (i & 1) {
366         input_[i] = 255;
367         input16_[i] = mask_;
368       } else {
369         input_[i] = prng.Rand8Extremes();
370         input16_[i] = prng.Rand16() & mask_;
371       }
372     }
373   }
374 
SetConstantInput(int value)375   void SetConstantInput(int value) {
376     memset(input_, value, kInputBufferSize);
377     aom_memset16(input16_, value, kInputBufferSize);
378   }
379 
CopyOutputToRef()380   void CopyOutputToRef() {
381     memcpy(output_ref_, output_, kOutputBufferSize);
382     // Copy 16-bit pixels values. The effective number of bytes is double.
383     memcpy(output16_ref_, output16_, sizeof(output16_[0]) * kOutputBufferSize);
384   }
385 
CheckGuardBlocks()386   void CheckGuardBlocks() {
387     for (int i = 0; i < kOutputBufferSize; ++i) {
388       if (IsIndexInBorder(i)) {
389         EXPECT_EQ(255, output_[i]);
390       }
391     }
392   }
393 
input() const394   uint8_t *input() const {
395     const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
396     if (UUT_->use_highbd_ == 0) {
397       return input_ + offset;
398     } else {
399       return CONVERT_TO_BYTEPTR(input16_) + offset;
400     }
401   }
402 
output() const403   uint8_t *output() const {
404     const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
405     if (UUT_->use_highbd_ == 0) {
406       return output_ + offset;
407     } else {
408       return CONVERT_TO_BYTEPTR(output16_) + offset;
409     }
410   }
411 
output_ref() const412   uint8_t *output_ref() const {
413     const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
414     if (UUT_->use_highbd_ == 0) {
415       return output_ref_ + offset;
416     } else {
417       return CONVERT_TO_BYTEPTR(output16_ref_) + offset;
418     }
419   }
420 
lookup(uint8_t * list,int index) const421   uint16_t lookup(uint8_t *list, int index) const {
422     if (UUT_->use_highbd_ == 0) {
423       return list[index];
424     } else {
425       return CONVERT_TO_SHORTPTR(list)[index];
426     }
427   }
428 
assign_val(uint8_t * list,int index,uint16_t val) const429   void assign_val(uint8_t *list, int index, uint16_t val) const {
430     if (UUT_->use_highbd_ == 0) {
431       list[index] = (uint8_t)val;
432     } else {
433       CONVERT_TO_SHORTPTR(list)[index] = val;
434     }
435   }
436 
wrapper_filter_average_block2d_8_c(const uint8_t * src_ptr,unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint8_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height)437   void wrapper_filter_average_block2d_8_c(
438       const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
439       const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
440       unsigned int output_width, unsigned int output_height) {
441     if (UUT_->use_highbd_ == 0) {
442       filter_average_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
443                                  dst_stride, output_width, output_height);
444     } else {
445       highbd_filter_average_block2d_8_c(
446           CONVERT_TO_SHORTPTR(src_ptr), src_stride, HFilter, VFilter,
447           CONVERT_TO_SHORTPTR(dst_ptr), dst_stride, output_width, output_height,
448           UUT_->use_highbd_);
449     }
450   }
451 
wrapper_filter_block2d_8_c(const uint8_t * src_ptr,unsigned int src_stride,const int16_t * HFilter,const int16_t * VFilter,uint8_t * dst_ptr,unsigned int dst_stride,unsigned int output_width,unsigned int output_height)452   void wrapper_filter_block2d_8_c(
453       const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
454       const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
455       unsigned int output_width, unsigned int output_height) {
456     if (UUT_->use_highbd_ == 0) {
457       filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
458                          dst_stride, output_width, output_height);
459     } else {
460       highbd_filter_block2d_8_c(CONVERT_TO_SHORTPTR(src_ptr), src_stride,
461                                 HFilter, VFilter, CONVERT_TO_SHORTPTR(dst_ptr),
462                                 dst_stride, output_width, output_height,
463                                 UUT_->use_highbd_);
464     }
465   }
466 
MatchesReferenceSubpixelFilter()467   void MatchesReferenceSubpixelFilter() {
468     uint8_t *const in = input();
469     uint8_t *const out = output();
470     uint8_t *ref;
471     if (UUT_->use_highbd_ == 0) {
472       ref = ref8_;
473     } else {
474       ref = CONVERT_TO_BYTEPTR(ref16_);
475     }
476     int subpel_search;
477     for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
478          ++subpel_search) {
479       for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
480         const InterpFilter filter = (InterpFilter)filter_bank;
481         const InterpKernel *filters =
482             (const InterpKernel *)av1_get_interp_filter_kernel(filter,
483                                                                subpel_search);
484         for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
485           for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
486             wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
487                                        filters[filter_y], ref, kOutputStride,
488                                        Width(), Height());
489 
490             if (filter_x && filter_y)
491               continue;
492             else if (filter_y)
493               UUT_->v8_(in, kInputStride, out, kOutputStride, kInvalidFilter,
494                         16, filters[filter_y], 16, Width(), Height());
495             else if (filter_x)
496               API_REGISTER_STATE_CHECK(UUT_->h8_(
497                   in, kInputStride, out, kOutputStride, filters[filter_x], 16,
498                   kInvalidFilter, 16, Width(), Height()));
499             else
500               continue;
501 
502             CheckGuardBlocks();
503 
504             for (int y = 0; y < Height(); ++y)
505               for (int x = 0; x < Width(); ++x)
506                 ASSERT_EQ(lookup(ref, y * kOutputStride + x),
507                           lookup(out, y * kOutputStride + x))
508                     << "mismatch at (" << x << "," << y << "), "
509                     << "filters (" << filter_bank << "," << filter_x << ","
510                     << filter_y << ")";
511           }
512         }
513       }
514     }
515   }
516 
FilterExtremes()517   void FilterExtremes() {
518     uint8_t *const in = input();
519     uint8_t *const out = output();
520     uint8_t *ref;
521     if (UUT_->use_highbd_ == 0) {
522       ref = ref8_;
523     } else {
524       ref = CONVERT_TO_BYTEPTR(ref16_);
525     }
526 
527     // Populate ref and out with some random data
528     ::libaom_test::ACMRandom prng;
529     for (int y = 0; y < Height(); ++y) {
530       for (int x = 0; x < Width(); ++x) {
531         uint16_t r;
532         if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
533           r = prng.Rand8Extremes();
534         } else {
535           r = prng.Rand16() & mask_;
536         }
537         assign_val(out, y * kOutputStride + x, r);
538         assign_val(ref, y * kOutputStride + x, r);
539       }
540     }
541 
542     for (int axis = 0; axis < 2; axis++) {
543       int seed_val = 0;
544       while (seed_val < 256) {
545         for (int y = 0; y < 8; ++y) {
546           for (int x = 0; x < 8; ++x) {
547             assign_val(in, y * kOutputStride + x - SUBPEL_TAPS / 2 + 1,
548                        ((seed_val >> (axis ? y : x)) & 1) * mask_);
549             if (axis) seed_val++;
550           }
551           if (axis)
552             seed_val -= 8;
553           else
554             seed_val++;
555         }
556         if (axis) seed_val += 8;
557         int subpel_search;
558         for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
559              ++subpel_search) {
560           for (int filter_bank = 0; filter_bank < kNumFilterBanks;
561                ++filter_bank) {
562             const InterpFilter filter = (InterpFilter)filter_bank;
563             const InterpKernel *filters =
564                 (const InterpKernel *)av1_get_interp_filter_kernel(
565                     filter, subpel_search);
566             for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
567               for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
568                 wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
569                                            filters[filter_y], ref,
570                                            kOutputStride, Width(), Height());
571                 if (filter_x && filter_y)
572                   continue;
573                 else if (filter_y)
574                   API_REGISTER_STATE_CHECK(UUT_->v8_(
575                       in, kInputStride, out, kOutputStride, kInvalidFilter, 16,
576                       filters[filter_y], 16, Width(), Height()));
577                 else if (filter_x)
578                   API_REGISTER_STATE_CHECK(UUT_->h8_(
579                       in, kInputStride, out, kOutputStride, filters[filter_x],
580                       16, kInvalidFilter, 16, Width(), Height()));
581                 else
582                   continue;
583 
584                 for (int y = 0; y < Height(); ++y)
585                   for (int x = 0; x < Width(); ++x)
586                     ASSERT_EQ(lookup(ref, y * kOutputStride + x),
587                               lookup(out, y * kOutputStride + x))
588                         << "mismatch at (" << x << "," << y << "), "
589                         << "filters (" << filter_bank << "," << filter_x << ","
590                         << filter_y << ")";
591               }
592             }
593           }
594         }
595       }
596     }
597   }
598 
SpeedTest()599   void SpeedTest() {
600     uint8_t *const in = input();
601     uint8_t *const out = output();
602     uint8_t *ref;
603     if (UUT_->use_highbd_ == 0) {
604       ref = ref8_;
605     } else {
606       ref = CONVERT_TO_BYTEPTR(ref16_);
607     }
608 
609     // Populate ref and out with some random data
610     ::libaom_test::ACMRandom prng;
611     for (int y = 0; y < Height(); ++y) {
612       for (int x = 0; x < Width(); ++x) {
613         uint16_t r;
614         if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
615           r = prng.Rand8Extremes();
616         } else {
617           r = prng.Rand16() & mask_;
618         }
619         assign_val(out, y * kOutputStride + x, r);
620         assign_val(ref, y * kOutputStride + x, r);
621       }
622     }
623 
624     InterpFilter filter = (InterpFilter)1;
625     const InterpKernel *filters =
626         (const InterpKernel *)av1_get_interp_filter_kernel(filter, USE_8_TAPS);
627     wrapper_filter_average_block2d_8_c(in, kInputStride, filters[1], filters[1],
628                                        out, kOutputStride, Width(), Height());
629 
630     aom_usec_timer timer;
631     int tests_num = 1000;
632 
633     aom_usec_timer_start(&timer);
634     while (tests_num > 0) {
635       for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
636         filter = (InterpFilter)filter_bank;
637         filters = (const InterpKernel *)av1_get_interp_filter_kernel(
638             filter, USE_8_TAPS);
639         for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
640           for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
641             if (filter_x && filter_y) continue;
642             if (filter_y)
643               API_REGISTER_STATE_CHECK(UUT_->v8_(
644                   in, kInputStride, out, kOutputStride, kInvalidFilter, 16,
645                   filters[filter_y], 16, Width(), Height()));
646             else if (filter_x)
647               API_REGISTER_STATE_CHECK(UUT_->h8_(
648                   in, kInputStride, out, kOutputStride, filters[filter_x], 16,
649                   kInvalidFilter, 16, Width(), Height()));
650           }
651         }
652       }
653       tests_num--;
654     }
655     aom_usec_timer_mark(&timer);
656 
657     const int elapsed_time =
658         static_cast<int>(aom_usec_timer_elapsed(&timer) / 1000);
659     printf("%dx%d (bitdepth %d) time: %5d ms\n", Width(), Height(),
660            UUT_->use_highbd_, elapsed_time);
661   }
662 
663   const ConvolveFunctions *UUT_;
664   static uint8_t *input_;
665   static uint8_t *ref8_;
666   static uint8_t *output_;
667   static uint8_t *output_ref_;
668   static uint16_t *input16_;
669   static uint16_t *ref16_;
670   static uint16_t *output16_;
671   static uint16_t *output16_ref_;
672   int mask_;
673 };
674 
675 uint8_t *ConvolveTestBase::input_ = nullptr;
676 uint8_t *ConvolveTestBase::ref8_ = nullptr;
677 uint8_t *ConvolveTestBase::output_ = nullptr;
678 uint8_t *ConvolveTestBase::output_ref_ = nullptr;
679 uint16_t *ConvolveTestBase::input16_ = nullptr;
680 uint16_t *ConvolveTestBase::ref16_ = nullptr;
681 uint16_t *ConvolveTestBase::output16_ = nullptr;
682 uint16_t *ConvolveTestBase::output16_ref_ = nullptr;
683 
684 using LowbdConvolveTest = ConvolveTestBase;
685 
TEST_P(LowbdConvolveTest,GuardBlocks)686 TEST_P(LowbdConvolveTest, GuardBlocks) { CheckGuardBlocks(); }
687 
FiltersWontSaturateWhenAddedPairwise()688 void FiltersWontSaturateWhenAddedPairwise() {
689   int subpel_search;
690   for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
691        ++subpel_search) {
692     for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
693       const InterpFilter filter = (InterpFilter)filter_bank;
694       const InterpKernel *filters =
695           (const InterpKernel *)av1_get_interp_filter_kernel(filter,
696                                                              subpel_search);
697       for (int i = 0; i < kNumFilters; i++) {
698         const int p0 = filters[i][0] + filters[i][1];
699         const int p1 = filters[i][2] + filters[i][3];
700         const int p2 = filters[i][4] + filters[i][5];
701         const int p3 = filters[i][6] + filters[i][7];
702         EXPECT_LE(p0, 128);
703         EXPECT_LE(p1, 128);
704         EXPECT_LE(p2, 128);
705         EXPECT_LE(p3, 128);
706         EXPECT_LE(p0 + p3, 128);
707         EXPECT_LE(p0 + p3 + p1, 128);
708         EXPECT_LE(p0 + p3 + p1 + p2, 128);
709         EXPECT_EQ(p0 + p1 + p2 + p3, 128);
710       }
711     }
712   }
713 }
714 
TEST(LowbdConvolveTest,FiltersWontSaturateWhenAddedPairwise)715 TEST(LowbdConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
716   FiltersWontSaturateWhenAddedPairwise();
717 }
718 
TEST_P(LowbdConvolveTest,MatchesReferenceSubpixelFilter)719 TEST_P(LowbdConvolveTest, MatchesReferenceSubpixelFilter) {
720   MatchesReferenceSubpixelFilter();
721 }
722 
TEST_P(LowbdConvolveTest,FilterExtremes)723 TEST_P(LowbdConvolveTest, FilterExtremes) { FilterExtremes(); }
724 
TEST_P(LowbdConvolveTest,DISABLED_Speed)725 TEST_P(LowbdConvolveTest, DISABLED_Speed) { SpeedTest(); }
726 
727 using std::make_tuple;
728 
729 // WRAP macro is only used for high bitdepth build.
730 #if CONFIG_AV1_HIGHBITDEPTH
731 #define WRAP(func, bd)                                                       \
732   static void wrap_##func##_##bd(                                            \
733       const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,                \
734       ptrdiff_t dst_stride, const int16_t *filter_x, int filter_x_stride,    \
735       const int16_t *filter_y, int filter_y_stride, int w, int h) {          \
736     aom_highbd_##func(src, src_stride, dst, dst_stride, filter_x,            \
737                       filter_x_stride, filter_y, filter_y_stride, w, h, bd); \
738   }
739 #if HAVE_SSE2 && AOM_ARCH_X86_64
740 WRAP(convolve8_horiz_sse2, 8)
741 WRAP(convolve8_vert_sse2, 8)
742 WRAP(convolve8_horiz_sse2, 10)
743 WRAP(convolve8_vert_sse2, 10)
744 WRAP(convolve8_horiz_sse2, 12)
745 WRAP(convolve8_vert_sse2, 12)
746 #endif  // HAVE_SSE2 && AOM_ARCH_X86_64
747 
748 WRAP(convolve8_horiz_c, 8)
749 WRAP(convolve8_vert_c, 8)
750 WRAP(convolve8_horiz_c, 10)
751 WRAP(convolve8_vert_c, 10)
752 WRAP(convolve8_horiz_c, 12)
753 WRAP(convolve8_vert_c, 12)
754 
755 #if HAVE_AVX2
756 WRAP(convolve8_horiz_avx2, 8)
757 WRAP(convolve8_vert_avx2, 8)
758 
759 WRAP(convolve8_horiz_avx2, 10)
760 WRAP(convolve8_vert_avx2, 10)
761 
762 WRAP(convolve8_horiz_avx2, 12)
763 WRAP(convolve8_vert_avx2, 12)
764 #endif  // HAVE_AVX2
765 
766 #if HAVE_NEON
767 WRAP(convolve8_horiz_neon, 8)
768 WRAP(convolve8_vert_neon, 8)
769 
770 WRAP(convolve8_horiz_neon, 10)
771 WRAP(convolve8_vert_neon, 10)
772 
773 WRAP(convolve8_horiz_neon, 12)
774 WRAP(convolve8_vert_neon, 12)
775 #endif  // HAVE_NEON
776 
777 #if HAVE_SVE
778 WRAP(convolve8_horiz_sve, 8)
779 WRAP(convolve8_vert_sve, 8)
780 
781 WRAP(convolve8_horiz_sve, 10)
782 WRAP(convolve8_vert_sve, 10)
783 
784 WRAP(convolve8_horiz_sve, 12)
785 WRAP(convolve8_vert_sve, 12)
786 #endif  // HAVE_SVE
787 #endif  // CONFIG_AV1_HIGHBITDEPTH
788 
789 #undef WRAP
790 
791 #if CONFIG_AV1_HIGHBITDEPTH
792 
793 using HighbdConvolveTest = ConvolveTestBase;
794 
TEST_P(HighbdConvolveTest,GuardBlocks)795 TEST_P(HighbdConvolveTest, GuardBlocks) { CheckGuardBlocks(); }
796 
TEST(HighbdConvolveTest,FiltersWontSaturateWhenAddedPairwise)797 TEST(HighbdConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
798   FiltersWontSaturateWhenAddedPairwise();
799 }
800 
TEST_P(HighbdConvolveTest,MatchesReferenceSubpixelFilter)801 TEST_P(HighbdConvolveTest, MatchesReferenceSubpixelFilter) {
802   MatchesReferenceSubpixelFilter();
803 }
804 
TEST_P(HighbdConvolveTest,FilterExtremes)805 TEST_P(HighbdConvolveTest, FilterExtremes) { FilterExtremes(); }
806 
TEST_P(HighbdConvolveTest,DISABLED_Speed)807 TEST_P(HighbdConvolveTest, DISABLED_Speed) { SpeedTest(); }
808 
809 const ConvolveFunctions wrap_convolve8_c(wrap_convolve8_horiz_c_8,
810                                          wrap_convolve8_vert_c_8, 8);
811 const ConvolveFunctions wrap_convolve10_c(wrap_convolve8_horiz_c_10,
812                                           wrap_convolve8_vert_c_10, 10);
813 const ConvolveFunctions wrap_convolve12_c(wrap_convolve8_horiz_c_12,
814                                           wrap_convolve8_vert_c_12, 12);
815 const ConvolveParam kArrayHighbdConvolve_c[] = { ALL_SIZES(wrap_convolve8_c),
816                                                  ALL_SIZES(wrap_convolve10_c),
817                                                  ALL_SIZES(wrap_convolve12_c) };
818 
819 INSTANTIATE_TEST_SUITE_P(C, HighbdConvolveTest,
820                          ::testing::ValuesIn(kArrayHighbdConvolve_c));
821 #endif  // CONFIG_AV1_HIGHBITDEPTH
822 
823 const ConvolveFunctions convolve8_c(aom_convolve8_horiz_c, aom_convolve8_vert_c,
824                                     0);
825 const ConvolveParam kArrayConvolve_c[] = { ALL_SIZES(convolve8_c) };
826 
827 INSTANTIATE_TEST_SUITE_P(C, LowbdConvolveTest,
828                          ::testing::ValuesIn(kArrayConvolve_c));
829 
830 #if HAVE_SSE2 && AOM_ARCH_X86_64
831 #if CONFIG_AV1_HIGHBITDEPTH
832 const ConvolveFunctions wrap_convolve8_sse2(wrap_convolve8_horiz_sse2_8,
833                                             wrap_convolve8_vert_sse2_8, 8);
834 const ConvolveFunctions wrap_convolve10_sse2(wrap_convolve8_horiz_sse2_10,
835                                              wrap_convolve8_vert_sse2_10, 10);
836 const ConvolveFunctions wrap_convolve12_sse2(wrap_convolve8_horiz_sse2_12,
837                                              wrap_convolve8_vert_sse2_12, 12);
838 const ConvolveParam kArrayHighbdConvolve_sse2[] = {
839   ALL_SIZES(wrap_convolve8_sse2), ALL_SIZES(wrap_convolve10_sse2),
840   ALL_SIZES(wrap_convolve12_sse2)
841 };
842 
843 INSTANTIATE_TEST_SUITE_P(SSE2, HighbdConvolveTest,
844                          ::testing::ValuesIn(kArrayHighbdConvolve_sse2));
845 #endif
846 #endif
847 
848 #if HAVE_SSSE3
849 const ConvolveFunctions convolve8_ssse3(aom_convolve8_horiz_ssse3,
850                                         aom_convolve8_vert_ssse3, 0);
851 
852 const ConvolveParam kArrayConvolve8_ssse3[] = { ALL_SIZES(convolve8_ssse3) };
853 
854 INSTANTIATE_TEST_SUITE_P(SSSE3, LowbdConvolveTest,
855                          ::testing::ValuesIn(kArrayConvolve8_ssse3));
856 #endif
857 
858 #if HAVE_AVX2
859 #if CONFIG_AV1_HIGHBITDEPTH
860 const ConvolveFunctions wrap_convolve8_avx2(wrap_convolve8_horiz_avx2_8,
861                                             wrap_convolve8_vert_avx2_8, 8);
862 const ConvolveFunctions wrap_convolve10_avx2(wrap_convolve8_horiz_avx2_10,
863                                              wrap_convolve8_vert_avx2_10, 10);
864 const ConvolveFunctions wrap_convolve12_avx2(wrap_convolve8_horiz_avx2_12,
865                                              wrap_convolve8_vert_avx2_12, 12);
866 const ConvolveParam kArray_HighbdConvolve8_avx2[] = {
867   ALL_SIZES_64(wrap_convolve8_avx2), ALL_SIZES_64(wrap_convolve10_avx2),
868   ALL_SIZES_64(wrap_convolve12_avx2)
869 };
870 
871 INSTANTIATE_TEST_SUITE_P(AVX2, HighbdConvolveTest,
872                          ::testing::ValuesIn(kArray_HighbdConvolve8_avx2));
873 #endif
874 const ConvolveFunctions convolve8_avx2(aom_convolve8_horiz_avx2,
875                                        aom_convolve8_vert_avx2, 0);
876 const ConvolveParam kArray_Convolve8_avx2[] = { ALL_SIZES(convolve8_avx2) };
877 
878 INSTANTIATE_TEST_SUITE_P(AVX2, LowbdConvolveTest,
879                          ::testing::ValuesIn(kArray_Convolve8_avx2));
880 #endif  // HAVE_AVX2
881 
882 #if HAVE_NEON
883 #if CONFIG_AV1_HIGHBITDEPTH
884 const ConvolveFunctions wrap_convolve8_neon(wrap_convolve8_horiz_neon_8,
885                                             wrap_convolve8_vert_neon_8, 8);
886 const ConvolveFunctions wrap_convolve10_neon(wrap_convolve8_horiz_neon_10,
887                                              wrap_convolve8_vert_neon_10, 10);
888 const ConvolveFunctions wrap_convolve12_neon(wrap_convolve8_horiz_neon_12,
889                                              wrap_convolve8_vert_neon_12, 12);
890 const ConvolveParam kArray_HighbdConvolve8_neon[] = {
891   ALL_SIZES_64(wrap_convolve8_neon), ALL_SIZES_64(wrap_convolve10_neon),
892   ALL_SIZES_64(wrap_convolve12_neon)
893 };
894 
895 INSTANTIATE_TEST_SUITE_P(NEON, HighbdConvolveTest,
896                          ::testing::ValuesIn(kArray_HighbdConvolve8_neon));
897 #endif
898 const ConvolveFunctions convolve8_neon(aom_convolve8_horiz_neon,
899                                        aom_convolve8_vert_neon, 0);
900 const ConvolveParam kArray_Convolve8_neon[] = { ALL_SIZES(convolve8_neon) };
901 
902 INSTANTIATE_TEST_SUITE_P(NEON, LowbdConvolveTest,
903                          ::testing::ValuesIn(kArray_Convolve8_neon));
904 #endif  // HAVE_NEON
905 
906 #if HAVE_NEON_DOTPROD
907 const ConvolveFunctions convolve8_neon_dotprod(aom_convolve8_horiz_neon_dotprod,
908                                                aom_convolve8_vert_neon_dotprod,
909                                                0);
910 const ConvolveParam kArray_Convolve8_neon_dotprod[] = { ALL_SIZES(
911     convolve8_neon_dotprod) };
912 
913 INSTANTIATE_TEST_SUITE_P(NEON_DOTPROD, LowbdConvolveTest,
914                          ::testing::ValuesIn(kArray_Convolve8_neon_dotprod));
915 #endif  // HAVE_NEON_DOTPROD
916 
917 #if HAVE_NEON_I8MM
918 const ConvolveFunctions convolve8_neon_i8mm(aom_convolve8_horiz_neon_i8mm,
919                                             aom_convolve8_vert_neon_i8mm, 0);
920 const ConvolveParam kArray_Convolve8_neon_i8mm[] = { ALL_SIZES(
921     convolve8_neon_i8mm) };
922 
923 INSTANTIATE_TEST_SUITE_P(NEON_I8MM, LowbdConvolveTest,
924                          ::testing::ValuesIn(kArray_Convolve8_neon_i8mm));
925 #endif  // HAVE_NEON_I8MM
926 
927 #if HAVE_SVE
928 #if CONFIG_AV1_HIGHBITDEPTH
929 const ConvolveFunctions wrap_convolve8_sve(wrap_convolve8_horiz_sve_8,
930                                            wrap_convolve8_vert_sve_8, 8);
931 const ConvolveFunctions wrap_convolve10_sve(wrap_convolve8_horiz_sve_10,
932                                             wrap_convolve8_vert_sve_10, 10);
933 const ConvolveFunctions wrap_convolve12_sve(wrap_convolve8_horiz_sve_12,
934                                             wrap_convolve8_vert_sve_12, 12);
935 const ConvolveParam kArray_HighbdConvolve8_sve[] = {
936   ALL_SIZES_64(wrap_convolve8_sve), ALL_SIZES_64(wrap_convolve10_sve),
937   ALL_SIZES_64(wrap_convolve12_sve)
938 };
939 
940 INSTANTIATE_TEST_SUITE_P(SVE, HighbdConvolveTest,
941                          ::testing::ValuesIn(kArray_HighbdConvolve8_sve));
942 #endif
943 #endif  // HAVE_SVE
944 
945 }  // namespace
946