blob: 19a8e1c913d64bc4b2c7121ddf520e2c6f800c4c [file] [log] [blame]
John Koleszar5ca6a362013-01-25 09:47:09 -08001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar5ca6a362013-01-25 09:47:09 -08003 *
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 */
John Koleszar5ca6a362013-01-25 09:47:09 -080011
Tero Rintaluomae326cec2013-08-22 11:29:19 +030012#include <string.h>
Jingning Han097d59c2015-07-29 14:51:36 -070013
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
John Koleszar5ca6a362013-01-25 09:47:09 -080015
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
17#include "./aom_dsp_rtcd.h"
Jingning Han097d59c2015-07-29 14:51:36 -070018#include "test/acm_random.h"
19#include "test/clear_system_state.h"
20#include "test/register_state_check.h"
21#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070022#include "aom_dsp/aom_dsp_common.h"
23#include "aom_dsp/aom_filter.h"
24#include "aom_mem/aom_mem.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#include "aom_ports/mem.h"
Yi Luo9d247352017-03-16 12:31:46 -070026#include "aom_ports/aom_timer.h"
Angie Chiangb1372892016-12-01 15:06:06 -080027#include "av1/common/filter.h"
John Koleszar5ca6a362013-01-25 09:47:09 -080028
29namespace {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070030
Geza Lore552d5cd2016-03-07 13:46:39 +000031static const unsigned int kMaxDimension = MAX_SB_SIZE;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070032
James Zerndfc4e8f2014-07-16 18:48:20 -070033typedef void (*ConvolveFunc)(const uint8_t *src, ptrdiff_t src_stride,
34 uint8_t *dst, ptrdiff_t dst_stride,
35 const int16_t *filter_x, int filter_x_stride,
36 const int16_t *filter_y, int filter_y_stride,
37 int w, int h);
John Koleszar5ca6a362013-01-25 09:47:09 -080038
39struct ConvolveFunctions {
Urvang Joshiabb71e32018-03-14 11:05:05 -070040 ConvolveFunctions(ConvolveFunc copy, ConvolveFunc h8, ConvolveFunc v8, int bd)
41 : copy_(copy), h8_(h8), v8_(v8), use_highbd_(bd) {}
John Koleszar5ca6a362013-01-25 09:47:09 -080042
Johann1c3594c2014-12-09 12:05:15 -080043 ConvolveFunc copy_;
James Zerndfc4e8f2014-07-16 18:48:20 -070044 ConvolveFunc h8_;
45 ConvolveFunc v8_;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -070046 int use_highbd_; // 0 if high bitdepth not used, else the actual bit depth.
John Koleszar5ca6a362013-01-25 09:47:09 -080047};
48
James Zerndfc4e8f2014-07-16 18:48:20 -070049typedef std::tr1::tuple<int, int, const ConvolveFunctions *> ConvolveParam;
Joshua Litt51490e52013-11-18 17:07:55 -080050
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -070051#define ALL_SIZES_64(convolve_fn) \
clang-format3a826f12016-08-11 17:46:05 -070052 make_tuple(4, 4, &convolve_fn), make_tuple(8, 4, &convolve_fn), \
53 make_tuple(4, 8, &convolve_fn), make_tuple(8, 8, &convolve_fn), \
54 make_tuple(16, 8, &convolve_fn), make_tuple(8, 16, &convolve_fn), \
55 make_tuple(16, 16, &convolve_fn), make_tuple(32, 16, &convolve_fn), \
56 make_tuple(16, 32, &convolve_fn), make_tuple(32, 32, &convolve_fn), \
57 make_tuple(64, 32, &convolve_fn), make_tuple(32, 64, &convolve_fn), \
58 make_tuple(64, 64, &convolve_fn)
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -070059
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -080060#if CONFIG_AV1
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -070061#define ALL_SIZES(convolve_fn) \
62 make_tuple(128, 64, &convolve_fn), make_tuple(64, 128, &convolve_fn), \
63 make_tuple(128, 128, &convolve_fn), ALL_SIZES_64(convolve_fn)
64#else
65#define ALL_SIZES ALL_SIZES_64
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -080066#endif // CONFIG_AV1
Alex Conversef03e2382016-04-26 18:09:40 -070067
John Koleszar5ca6a362013-01-25 09:47:09 -080068// Reference 8-tap subpixel filter, slightly modified to fit into this test.
Yaowu Xuf883b422016-08-30 14:01:10 -070069#define AV1_FILTER_WEIGHT 128
70#define AV1_FILTER_SHIFT 7
clang-format3a826f12016-08-11 17:46:05 -070071uint8_t clip_pixel(int x) { return x < 0 ? 0 : x > 255 ? 255 : x; }
John Koleszar5ca6a362013-01-25 09:47:09 -080072
Yaowu Xu032573d2017-04-24 15:04:17 -070073void filter_block2d_8_c(const uint8_t *src_ptr, unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -070074 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) {
John Koleszar5ca6a362013-01-25 09:47:09 -080077 // 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 =
James Zern8fb48af2013-05-02 13:08:19 -070083 (kInterp_Extend - 1) + output_height + kInterp_Extend;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070084 unsigned int i, j;
John Koleszar5ca6a362013-01-25 09:47:09 -080085
Sarah Parkere57473a2017-04-27 16:19:56 -070086 assert(intermediate_height > 7);
87
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070088 // 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 //
clang-format3a826f12016-08-11 17:46:05 -070095 uint8_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension];
Tom Finegan6042d682016-05-06 09:43:37 -070096 const int intermediate_next_stride =
97 1 - static_cast<int>(intermediate_height * output_width);
John Koleszar5ca6a362013-01-25 09:47:09 -080098
99 // Horizontal pass (src -> transposed intermediate).
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700100 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...
clang-format3a826f12016-08-11 17:46:05 -0700106 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]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700110 (AV1_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800111
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700112 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700113 *output_ptr = clip_pixel(temp >> AV1_FILTER_SHIFT);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700114 ++src_ptr;
115 output_ptr += intermediate_height;
John Koleszar5ca6a362013-01-25 09:47:09 -0800116 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700117 src_ptr += src_next_row_stride;
118 output_ptr += intermediate_next_stride;
John Koleszar5ca6a362013-01-25 09:47:09 -0800119 }
120
121 // Vertical pass (transposed intermediate -> dst).
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700122 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...
clang-format3a826f12016-08-11 17:46:05 -0700127 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]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 (AV1_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800132
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700133 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700134 *dst_ptr++ = clip_pixel(temp >> AV1_FILTER_SHIFT);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700135 src_ptr += intermediate_height;
John Koleszar5ca6a362013-01-25 09:47:09 -0800136 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700137 src_ptr += intermediate_next_stride;
138 dst_ptr += dst_next_row_stride;
John Koleszar5ca6a362013-01-25 09:47:09 -0800139 }
140}
141
clang-format3a826f12016-08-11 17:46:05 -0700142void 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) {
John Koleszar5ca6a362013-01-25 09:47:09 -0800145 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
James Zern8fb48af2013-05-02 13:08:19 -0700154void filter_average_block2d_8_c(const uint8_t *src_ptr,
155 const unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700156 const int16_t *HFilter, const int16_t *VFilter,
157 uint8_t *dst_ptr, unsigned int dst_stride,
James Zern8fb48af2013-05-02 13:08:19 -0700158 unsigned int output_width,
159 unsigned int output_height) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700160 uint8_t tmp[kMaxDimension * kMaxDimension];
John Koleszar5ca6a362013-01-25 09:47:09 -0800161
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700162 assert(output_width <= kMaxDimension);
163 assert(output_height <= kMaxDimension);
Geza Lore938b8df2016-03-04 15:55:48 +0000164 filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, kMaxDimension,
John Koleszar5ca6a362013-01-25 09:47:09 -0800165 output_width, output_height);
clang-format3a826f12016-08-11 17:46:05 -0700166 block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride, output_width,
167 output_height);
John Koleszar5ca6a362013-01-25 09:47:09 -0800168}
169
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700170void highbd_filter_block2d_8_c(const uint16_t *src_ptr,
171 const unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700172 const int16_t *HFilter, const int16_t *VFilter,
173 uint16_t *dst_ptr, unsigned int dst_stride,
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700174 unsigned int output_width,
clang-format3a826f12016-08-11 17:46:05 -0700175 unsigned int output_height, int bd) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700176 // 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 */
Sebastien Alaiwan92400ab2017-03-14 10:39:29 +0100191 uint16_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension] = { 0 };
Tom Finegan9a56a5e2016-05-13 09:42:58 -0700192 const int intermediate_next_stride =
193 1 - static_cast<int>(intermediate_height * output_width);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700194
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...
clang-format3a826f12016-08-11 17:46:05 -0700204 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]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700208 (AV1_FILTER_WEIGHT >> 1); // Rounding
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700209
210 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700211 *output_ptr = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700212 ++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 {
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700222 const uint16_t *interm_ptr = intermediate_buffer;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700223 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...
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700228 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
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700234
235 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700236 *dst_ptr++ = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700237 interm_ptr += intermediate_height;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700238 }
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700239 interm_ptr += intermediate_next_stride;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700240 dst_ptr += dst_next_row_stride;
241 }
242 }
243}
244
clang-format3a826f12016-08-11 17:46:05 -0700245void highbd_block2d_average_c(uint16_t *src, unsigned int src_stride,
246 uint16_t *output_ptr, unsigned int output_stride,
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700247 unsigned int output_width,
James Zerncffef112016-02-11 18:27:00 -0800248 unsigned int output_height) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700249 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
clang-format3a826f12016-08-11 17:46:05 -0700258void highbd_filter_average_block2d_8_c(
Yaowu Xu032573d2017-04-24 15:04:17 -0700259 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) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700262 uint16_t tmp[kMaxDimension * kMaxDimension];
263
264 assert(output_width <= kMaxDimension);
265 assert(output_height <= kMaxDimension);
clang-format3a826f12016-08-11 17:46:05 -0700266 highbd_filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp,
267 kMaxDimension, output_width, output_height, bd);
Geza Lore938b8df2016-03-04 15:55:48 +0000268 highbd_block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride,
James Zerncffef112016-02-11 18:27:00 -0800269 output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700270}
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700271
James Zerndfc4e8f2014-07-16 18:48:20 -0700272class ConvolveTest : public ::testing::TestWithParam<ConvolveParam> {
John Koleszar29d47ac2013-02-07 17:00:37 -0800273 public:
274 static void SetUpTestCase() {
275 // Force input_ to be unaligned, output to be 16 byte aligned.
clang-format3a826f12016-08-11 17:46:05 -0700276 input_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700277 aom_memalign(kDataAlignment, kInputBufferSize + 1)) +
clang-format3a826f12016-08-11 17:46:05 -0700278 1;
279 output_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700280 aom_memalign(kDataAlignment, kOutputBufferSize));
clang-format3a826f12016-08-11 17:46:05 -0700281 output_ref_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700282 aom_memalign(kDataAlignment, kOutputBufferSize));
Yaowu Xuf883b422016-08-30 14:01:10 -0700283 input16_ = reinterpret_cast<uint16_t *>(aom_memalign(
clang-format3a826f12016-08-11 17:46:05 -0700284 kDataAlignment, (kInputBufferSize + 1) * sizeof(uint16_t))) +
285 1;
286 output16_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700287 aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
clang-format3a826f12016-08-11 17:46:05 -0700288 output16_ref_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700289 aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
John Koleszar29d47ac2013-02-07 17:00:37 -0800290 }
291
Yaowu Xuc27fc142016-08-22 16:08:15 -0700292 virtual void TearDown() { libaom_test::ClearSystemState(); }
Jim Bankoski18d32362014-12-12 06:18:56 -0800293
John Koleszar29d47ac2013-02-07 17:00:37 -0800294 static void TearDownTestCase() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700295 aom_free(input_ - 1);
John Koleszar29d47ac2013-02-07 17:00:37 -0800296 input_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700297 aom_free(output_);
John Koleszar29d47ac2013-02-07 17:00:37 -0800298 output_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700299 aom_free(output_ref_);
Johann1c3594c2014-12-09 12:05:15 -0800300 output_ref_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700301 aom_free(input16_ - 1);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700302 input16_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700303 aom_free(output16_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700304 output16_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700305 aom_free(output16_ref_);
Johann1c3594c2014-12-09 12:05:15 -0800306 output16_ref_ = NULL;
John Koleszar29d47ac2013-02-07 17:00:37 -0800307 }
308
James Zern8fb48af2013-05-02 13:08:19 -0700309 protected:
310 static const int kDataAlignment = 16;
clang-format3a826f12016-08-11 17:46:05 -0700311 static const int kOuterBlockSize = 4 * kMaxDimension;
James Zern8fb48af2013-05-02 13:08:19 -0700312 static const int kInputStride = kOuterBlockSize;
313 static const int kOutputStride = kOuterBlockSize;
James Zern8fb48af2013-05-02 13:08:19 -0700314 static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;
315 static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;
John Koleszar5ca6a362013-01-25 09:47:09 -0800316
James Zern8fb48af2013-05-02 13:08:19 -0700317 int Width() const { return GET_PARAM(0); }
318 int Height() const { return GET_PARAM(1); }
319 int BorderLeft() const {
320 const int center = (kOuterBlockSize - Width()) / 2;
321 return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);
322 }
323 int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }
John Koleszar5ca6a362013-01-25 09:47:09 -0800324
James Zern8fb48af2013-05-02 13:08:19 -0700325 bool IsIndexInBorder(int i) {
326 return (i < BorderTop() * kOuterBlockSize ||
327 i >= (BorderTop() + Height()) * kOuterBlockSize ||
328 i % kOuterBlockSize < BorderLeft() ||
329 i % kOuterBlockSize >= (BorderLeft() + Width()));
330 }
331
332 virtual void SetUp() {
333 UUT_ = GET_PARAM(2);
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700334 if (UUT_->use_highbd_ != 0)
335 mask_ = (1 << UUT_->use_highbd_) - 1;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700336 else
337 mask_ = 255;
Johann158c80c2013-05-23 12:50:41 -0700338 /* Set up guard blocks for an inner block centered in the outer block */
James Zern8fb48af2013-05-02 13:08:19 -0700339 for (int i = 0; i < kOutputBufferSize; ++i) {
Yaowu Xu5ab58722017-05-11 09:39:31 -0700340 if (IsIndexInBorder(i)) {
James Zern8fb48af2013-05-02 13:08:19 -0700341 output_[i] = 255;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700342 output16_[i] = mask_;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700343 } else {
James Zern8fb48af2013-05-02 13:08:19 -0700344 output_[i] = 0;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700345 output16_[i] = 0;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700346 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800347 }
348
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 ::libaom_test::ACMRandom prng;
Yaowu Xu077144d2014-05-23 12:23:29 -0700350 for (int i = 0; i < kInputBufferSize; ++i) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700351 if (i & 1) {
Yaowu Xu077144d2014-05-23 12:23:29 -0700352 input_[i] = 255;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700353 input16_[i] = mask_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700354 } else {
Yaowu Xu077144d2014-05-23 12:23:29 -0700355 input_[i] = prng.Rand8Extremes();
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700356 input16_[i] = prng.Rand16() & mask_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700357 }
Yaowu Xu077144d2014-05-23 12:23:29 -0700358 }
James Zern8fb48af2013-05-02 13:08:19 -0700359 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800360
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300361 void SetConstantInput(int value) {
362 memset(input_, value, kInputBufferSize);
Yaowu Xuf883b422016-08-30 14:01:10 -0700363 aom_memset16(input16_, value, kInputBufferSize);
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300364 }
365
Johann1c3594c2014-12-09 12:05:15 -0800366 void CopyOutputToRef() {
James Zernf274c212015-04-23 20:42:19 -0700367 memcpy(output_ref_, output_, kOutputBufferSize);
Yaowu Xuc648a9f2016-10-10 17:39:29 -0700368 // Copy 16-bit pixels values. The effective number of bytes is double.
369 memcpy(output16_ref_, output16_, sizeof(output16_[0]) * kOutputBufferSize);
Johann1c3594c2014-12-09 12:05:15 -0800370 }
371
James Zern8fb48af2013-05-02 13:08:19 -0700372 void CheckGuardBlocks() {
373 for (int i = 0; i < kOutputBufferSize; ++i) {
Sebastien Alaiwan7d701682017-10-04 10:07:24 +0200374 if (IsIndexInBorder(i)) {
375 EXPECT_EQ(255, output_[i]);
376 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800377 }
James Zern8fb48af2013-05-02 13:08:19 -0700378 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800379
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700380 uint8_t *input() const {
Johann2967bf32016-06-22 16:08:10 -0700381 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700382 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700383 return input_ + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700384 } else {
Johann2967bf32016-06-22 16:08:10 -0700385 return CONVERT_TO_BYTEPTR(input16_) + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700386 }
James Zern8fb48af2013-05-02 13:08:19 -0700387 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800388
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700389 uint8_t *output() const {
Johann2967bf32016-06-22 16:08:10 -0700390 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700391 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700392 return output_ + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700393 } else {
Johann2967bf32016-06-22 16:08:10 -0700394 return CONVERT_TO_BYTEPTR(output16_) + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700395 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700396 }
397
Johann1c3594c2014-12-09 12:05:15 -0800398 uint8_t *output_ref() const {
Johann2967bf32016-06-22 16:08:10 -0700399 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Johann1c3594c2014-12-09 12:05:15 -0800400 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700401 return output_ref_ + offset;
Johann1c3594c2014-12-09 12:05:15 -0800402 } else {
Johann2967bf32016-06-22 16:08:10 -0700403 return CONVERT_TO_BYTEPTR(output16_ref_) + offset;
Johann1c3594c2014-12-09 12:05:15 -0800404 }
Johann1c3594c2014-12-09 12:05:15 -0800405 }
406
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700407 uint16_t lookup(uint8_t *list, int index) const {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700408 if (UUT_->use_highbd_ == 0) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700409 return list[index];
410 } else {
411 return CONVERT_TO_SHORTPTR(list)[index];
412 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700413 }
414
415 void assign_val(uint8_t *list, int index, uint16_t val) const {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700416 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700417 list[index] = (uint8_t)val;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700418 } else {
419 CONVERT_TO_SHORTPTR(list)[index] = val;
420 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700421 }
422
clang-format3a826f12016-08-11 17:46:05 -0700423 void wrapper_filter_average_block2d_8_c(
Yaowu Xu032573d2017-04-24 15:04:17 -0700424 const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
425 const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
426 unsigned int output_width, unsigned int output_height) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700427 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700428 filter_average_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
429 dst_stride, output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700430 } else {
clang-format3a826f12016-08-11 17:46:05 -0700431 highbd_filter_average_block2d_8_c(
432 CONVERT_TO_SHORTPTR(src_ptr), src_stride, HFilter, VFilter,
433 CONVERT_TO_SHORTPTR(dst_ptr), dst_stride, output_width, output_height,
434 UUT_->use_highbd_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700435 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700436 }
437
Yaowu Xu032573d2017-04-24 15:04:17 -0700438 void wrapper_filter_block2d_8_c(
439 const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
440 const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
441 unsigned int output_width, unsigned int output_height) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700442 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700443 filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
444 dst_stride, output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700445 } else {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700446 highbd_filter_block2d_8_c(CONVERT_TO_SHORTPTR(src_ptr), src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700447 HFilter, VFilter, CONVERT_TO_SHORTPTR(dst_ptr),
448 dst_stride, output_width, output_height,
449 UUT_->use_highbd_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700450 }
James Zern8fb48af2013-05-02 13:08:19 -0700451 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800452
clang-format3a826f12016-08-11 17:46:05 -0700453 const ConvolveFunctions *UUT_;
454 static uint8_t *input_;
455 static uint8_t *output_;
456 static uint8_t *output_ref_;
clang-format3a826f12016-08-11 17:46:05 -0700457 static uint16_t *input16_;
458 static uint16_t *output16_;
459 static uint16_t *output16_ref_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700460 int mask_;
John Koleszar5ca6a362013-01-25 09:47:09 -0800461};
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700462
clang-format3a826f12016-08-11 17:46:05 -0700463uint8_t *ConvolveTest::input_ = NULL;
464uint8_t *ConvolveTest::output_ = NULL;
465uint8_t *ConvolveTest::output_ref_ = NULL;
clang-format3a826f12016-08-11 17:46:05 -0700466uint16_t *ConvolveTest::input16_ = NULL;
467uint16_t *ConvolveTest::output16_ = NULL;
468uint16_t *ConvolveTest::output16_ref_ = NULL;
John Koleszar5ca6a362013-01-25 09:47:09 -0800469
clang-format3a826f12016-08-11 17:46:05 -0700470TEST_P(ConvolveTest, GuardBlocks) { CheckGuardBlocks(); }
John Koleszar5ca6a362013-01-25 09:47:09 -0800471
Johann1c3594c2014-12-09 12:05:15 -0800472TEST_P(ConvolveTest, Copy) {
clang-format3a826f12016-08-11 17:46:05 -0700473 uint8_t *const in = input();
474 uint8_t *const out = output();
Johann1c3594c2014-12-09 12:05:15 -0800475
clang-format3a826f12016-08-11 17:46:05 -0700476 ASM_REGISTER_STATE_CHECK(UUT_->copy_(in, kInputStride, out, kOutputStride,
477 NULL, 0, NULL, 0, Width(), Height()));
Johann1c3594c2014-12-09 12:05:15 -0800478
479 CheckGuardBlocks();
480
481 for (int y = 0; y < Height(); ++y)
482 for (int x = 0; x < Width(); ++x)
483 ASSERT_EQ(lookup(out, y * kOutputStride + x),
484 lookup(in, y * kInputStride + x))
485 << "(" << x << "," << y << ")";
486}
487
Angie Chiangb1372892016-12-01 15:06:06 -0800488const int kNumFilterBanks = SWITCHABLE_FILTERS;
John Koleszara9ebbcc2013-04-18 13:05:38 -0700489const int kNumFilters = 16;
490
491TEST(ConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
492 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
Urvang Joshia9b174b2017-02-17 11:50:12 -0800493 const InterpFilter filter = (InterpFilter)filter_bank;
Dmitry Kovalev3d4ed272014-04-21 14:15:35 -0700494 const InterpKernel *filters =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800495 (const InterpKernel *)av1_get_interp_filter_kernel(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800496 const InterpFilterParams filter_params =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800497 av1_get_interp_filter_params(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800498 if (filter_params.taps != SUBPEL_TAPS) continue;
John Koleszara9ebbcc2013-04-18 13:05:38 -0700499 for (int i = 0; i < kNumFilters; i++) {
500 const int p0 = filters[i][0] + filters[i][1];
501 const int p1 = filters[i][2] + filters[i][3];
502 const int p2 = filters[i][4] + filters[i][5];
503 const int p3 = filters[i][6] + filters[i][7];
504 EXPECT_LE(p0, 128);
505 EXPECT_LE(p1, 128);
506 EXPECT_LE(p2, 128);
507 EXPECT_LE(p3, 128);
508 EXPECT_LE(p0 + p3, 128);
509 EXPECT_LE(p0 + p3 + p1, 128);
510 EXPECT_LE(p0 + p3 + p1 + p2, 128);
511 EXPECT_EQ(p0 + p1 + p2 + p3, 128);
512 }
513 }
514}
John Koleszar557a1b22013-02-20 16:13:01 -0800515
John Koleszar04c24072013-02-20 16:32:02 -0800516const int16_t kInvalidFilter[8] = { 0 };
517
John Koleszar5ca6a362013-01-25 09:47:09 -0800518TEST_P(ConvolveTest, MatchesReferenceSubpixelFilter) {
clang-format3a826f12016-08-11 17:46:05 -0700519 uint8_t *const in = input();
520 uint8_t *const out = output();
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700521 uint8_t ref8[kOutputStride * kMaxDimension];
522 uint16_t ref16[kOutputStride * kMaxDimension];
clang-format3a826f12016-08-11 17:46:05 -0700523 uint8_t *ref;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700524 if (UUT_->use_highbd_ == 0) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700525 ref = ref8;
526 } else {
527 ref = CONVERT_TO_BYTEPTR(ref16);
528 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800529
John Koleszar557a1b22013-02-20 16:13:01 -0800530 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
Urvang Joshia9b174b2017-02-17 11:50:12 -0800531 const InterpFilter filter = (InterpFilter)filter_bank;
Dmitry Kovalev3d4ed272014-04-21 14:15:35 -0700532 const InterpKernel *filters =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800533 (const InterpKernel *)av1_get_interp_filter_kernel(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800534 const InterpFilterParams filter_params =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800535 av1_get_interp_filter_params(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800536 if (filter_params.taps != SUBPEL_TAPS) continue;
Dmitry Kovalev021eaab2014-05-14 16:21:41 -0700537
John Koleszar557a1b22013-02-20 16:13:01 -0800538 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
539 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
clang-format3a826f12016-08-11 17:46:05 -0700540 wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
541 filters[filter_y], ref, kOutputStride,
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700542 Width(), Height());
John Koleszar5ca6a362013-01-25 09:47:09 -0800543
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700544 if (filter_x && filter_y)
Urvang Joshiabb71e32018-03-14 11:05:05 -0700545 continue;
John Koleszar557a1b22013-02-20 16:13:01 -0800546 else if (filter_y)
James Zern29e1b1a2014-07-09 21:02:02 -0700547 ASM_REGISTER_STATE_CHECK(
clang-format3a826f12016-08-11 17:46:05 -0700548 UUT_->v8_(in, kInputStride, out, kOutputStride, kInvalidFilter,
549 16, filters[filter_y], 16, Width(), Height()));
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700550 else if (filter_x)
James Zern29e1b1a2014-07-09 21:02:02 -0700551 ASM_REGISTER_STATE_CHECK(
clang-format3a826f12016-08-11 17:46:05 -0700552 UUT_->h8_(in, kInputStride, out, kOutputStride, filters[filter_x],
553 16, kInvalidFilter, 16, Width(), Height()));
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700554 else
555 ASM_REGISTER_STATE_CHECK(
clang-format3a826f12016-08-11 17:46:05 -0700556 UUT_->copy_(in, kInputStride, out, kOutputStride, kInvalidFilter,
557 0, kInvalidFilter, 0, Width(), Height()));
John Koleszar5ca6a362013-01-25 09:47:09 -0800558
John Koleszar557a1b22013-02-20 16:13:01 -0800559 CheckGuardBlocks();
John Koleszar5ca6a362013-01-25 09:47:09 -0800560
John Koleszar557a1b22013-02-20 16:13:01 -0800561 for (int y = 0; y < Height(); ++y)
562 for (int x = 0; x < Width(); ++x)
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700563 ASSERT_EQ(lookup(ref, y * kOutputStride + x),
564 lookup(out, y * kOutputStride + x))
John Koleszar557a1b22013-02-20 16:13:01 -0800565 << "mismatch at (" << x << "," << y << "), "
clang-format3a826f12016-08-11 17:46:05 -0700566 << "filters (" << filter_bank << "," << filter_x << ","
567 << filter_y << ")";
John Koleszar557a1b22013-02-20 16:13:01 -0800568 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800569 }
570 }
571}
572
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700573TEST_P(ConvolveTest, FilterExtremes) {
574 uint8_t *const in = input();
575 uint8_t *const out = output();
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700576 uint8_t ref8[kOutputStride * kMaxDimension];
577 uint16_t ref16[kOutputStride * kMaxDimension];
578 uint8_t *ref;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700579 if (UUT_->use_highbd_ == 0) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700580 ref = ref8;
581 } else {
582 ref = CONVERT_TO_BYTEPTR(ref16);
583 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700584
585 // Populate ref and out with some random data
Yaowu Xuc27fc142016-08-22 16:08:15 -0700586 ::libaom_test::ACMRandom prng;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700587 for (int y = 0; y < Height(); ++y) {
588 for (int x = 0; x < Width(); ++x) {
589 uint16_t r;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700590 if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700591 r = prng.Rand8Extremes();
592 } else {
593 r = prng.Rand16() & mask_;
594 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700595 assign_val(out, y * kOutputStride + x, r);
596 assign_val(ref, y * kOutputStride + x, r);
597 }
598 }
599
600 for (int axis = 0; axis < 2; axis++) {
601 int seed_val = 0;
602 while (seed_val < 256) {
603 for (int y = 0; y < 8; ++y) {
604 for (int x = 0; x < 8; ++x) {
clang-format3a826f12016-08-11 17:46:05 -0700605 assign_val(in, y * kOutputStride + x - SUBPEL_TAPS / 2 + 1,
606 ((seed_val >> (axis ? y : x)) & 1) * mask_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700607 if (axis) seed_val++;
608 }
609 if (axis)
clang-format3a826f12016-08-11 17:46:05 -0700610 seed_val -= 8;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700611 else
612 seed_val++;
613 }
614 if (axis) seed_val += 8;
615
616 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
Urvang Joshia9b174b2017-02-17 11:50:12 -0800617 const InterpFilter filter = (InterpFilter)filter_bank;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700618 const InterpKernel *filters =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800619 (const InterpKernel *)av1_get_interp_filter_kernel(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800620 const InterpFilterParams filter_params =
Urvang Joshia9b174b2017-02-17 11:50:12 -0800621 av1_get_interp_filter_params(filter);
Angie Chiangb1372892016-12-01 15:06:06 -0800622 if (filter_params.taps != SUBPEL_TAPS) continue;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700623 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
624 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
clang-format3a826f12016-08-11 17:46:05 -0700625 wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
626 filters[filter_y], ref, kOutputStride,
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700627 Width(), Height());
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700628 if (filter_x && filter_y)
Urvang Joshiabb71e32018-03-14 11:05:05 -0700629 continue;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700630 else if (filter_y)
clang-format3a826f12016-08-11 17:46:05 -0700631 ASM_REGISTER_STATE_CHECK(UUT_->v8_(
632 in, kInputStride, out, kOutputStride, kInvalidFilter, 16,
633 filters[filter_y], 16, Width(), Height()));
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700634 else if (filter_x)
clang-format3a826f12016-08-11 17:46:05 -0700635 ASM_REGISTER_STATE_CHECK(UUT_->h8_(
636 in, kInputStride, out, kOutputStride, filters[filter_x], 16,
637 kInvalidFilter, 16, Width(), Height()));
Scott LaVarnway4e6b5072015-08-05 10:47:06 -0700638 else
clang-format3a826f12016-08-11 17:46:05 -0700639 ASM_REGISTER_STATE_CHECK(UUT_->copy_(
640 in, kInputStride, out, kOutputStride, kInvalidFilter, 0,
641 kInvalidFilter, 0, Width(), Height()));
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700642
643 for (int y = 0; y < Height(); ++y)
644 for (int x = 0; x < Width(); ++x)
645 ASSERT_EQ(lookup(ref, y * kOutputStride + x),
646 lookup(out, y * kOutputStride + x))
647 << "mismatch at (" << x << "," << y << "), "
clang-format3a826f12016-08-11 17:46:05 -0700648 << "filters (" << filter_bank << "," << filter_x << ","
649 << filter_y << ")";
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700650 }
651 }
652 }
653 }
654 }
655}
656
Yi Luoa4d87992017-04-14 17:44:26 -0700657TEST_P(ConvolveTest, DISABLED_Copy_Speed) {
658 const uint8_t *const in = input();
659 uint8_t *const out = output();
660 const int kNumTests = 5000000;
661 const int width = Width();
662 const int height = Height();
663 aom_usec_timer timer;
664
665 aom_usec_timer_start(&timer);
666 for (int n = 0; n < kNumTests; ++n) {
667 UUT_->copy_(in, kInputStride, out, kOutputStride, NULL, 0, NULL, 0, width,
668 height);
669 }
670 aom_usec_timer_mark(&timer);
671
672 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
673 printf("convolve_copy_%dx%d_%d: %d us\n", width, height,
674 UUT_->use_highbd_ ? UUT_->use_highbd_ : 8, elapsed_time);
675}
676
Yi Luo9d247352017-03-16 12:31:46 -0700677TEST_P(ConvolveTest, DISABLED_Speed) {
678 uint8_t *const in = input();
679 uint8_t *const out = output();
Yi Luo9d247352017-03-16 12:31:46 -0700680 uint8_t ref8[kOutputStride * kMaxDimension];
681 uint16_t ref16[kOutputStride * kMaxDimension];
682 uint8_t *ref;
683 if (UUT_->use_highbd_ == 0) {
684 ref = ref8;
685 } else {
686 ref = CONVERT_TO_BYTEPTR(ref16);
687 }
Yi Luo9d247352017-03-16 12:31:46 -0700688
689 // Populate ref and out with some random data
690 ::libaom_test::ACMRandom prng;
691 for (int y = 0; y < Height(); ++y) {
692 for (int x = 0; x < Width(); ++x) {
693 uint16_t r;
Yi Luo9d247352017-03-16 12:31:46 -0700694 if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
695 r = prng.Rand8Extremes();
696 } else {
697 r = prng.Rand16() & mask_;
698 }
Yi Luo9d247352017-03-16 12:31:46 -0700699 assign_val(out, y * kOutputStride + x, r);
700 assign_val(ref, y * kOutputStride + x, r);
701 }
702 }
703
704 const InterpFilter filter = (InterpFilter)1;
705 const InterpKernel *filters =
706 (const InterpKernel *)av1_get_interp_filter_kernel(filter);
707 wrapper_filter_average_block2d_8_c(in, kInputStride, filters[1], filters[1],
708 out, kOutputStride, Width(), Height());
709
710 aom_usec_timer timer;
711 int tests_num = 1000;
712
713 aom_usec_timer_start(&timer);
714 while (tests_num > 0) {
715 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
716 const InterpFilter filter = (InterpFilter)filter_bank;
717 const InterpKernel *filters =
718 (const InterpKernel *)av1_get_interp_filter_kernel(filter);
Yi Luo9d247352017-03-16 12:31:46 -0700719 const InterpFilterParams filter_params =
720 av1_get_interp_filter_params(filter);
721 if (filter_params.taps != SUBPEL_TAPS) continue;
Yi Luo9d247352017-03-16 12:31:46 -0700722
723 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
724 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
Urvang Joshiabb71e32018-03-14 11:05:05 -0700725 if (filter_x && filter_y) continue;
Yi Luo9d247352017-03-16 12:31:46 -0700726 if (filter_y)
727 ASM_REGISTER_STATE_CHECK(
728 UUT_->v8_(in, kInputStride, out, kOutputStride, kInvalidFilter,
729 16, filters[filter_y], 16, Width(), Height()));
730 else if (filter_x)
731 ASM_REGISTER_STATE_CHECK(UUT_->h8_(
732 in, kInputStride, out, kOutputStride, filters[filter_x], 16,
733 kInvalidFilter, 16, Width(), Height()));
734 }
735 }
736 }
737 tests_num--;
738 }
739 aom_usec_timer_mark(&timer);
740
741 const int elapsed_time =
742 static_cast<int>(aom_usec_timer_elapsed(&timer) / 1000);
743 printf("%dx%d (bitdepth %d) time: %5d ms\n", Width(), Height(),
744 UUT_->use_highbd_, elapsed_time);
745}
746
John Koleszar5ca6a362013-01-25 09:47:09 -0800747using std::tr1::make_tuple;
748
clang-format3a826f12016-08-11 17:46:05 -0700749#define WRAP(func, bd) \
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700750 static void wrap_##func##_##bd( \
clang-format3a826f12016-08-11 17:46:05 -0700751 const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, \
752 ptrdiff_t dst_stride, const int16_t *filter_x, int filter_x_stride, \
753 const int16_t *filter_y, int filter_y_stride, int w, int h) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700754 aom_highbd_##func(src, src_stride, dst, dst_stride, filter_x, \
clang-format3a826f12016-08-11 17:46:05 -0700755 filter_x_stride, filter_y, filter_y_stride, w, h, bd); \
756 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700757#if HAVE_SSE2 && ARCH_X86_64
Alex Converse0c00af12015-10-06 15:59:03 -0700758WRAP(convolve_copy_sse2, 8)
Alex Converse0c00af12015-10-06 15:59:03 -0700759WRAP(convolve_copy_sse2, 10)
Alex Converse0c00af12015-10-06 15:59:03 -0700760WRAP(convolve_copy_sse2, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700761WRAP(convolve8_horiz_sse2, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700762WRAP(convolve8_vert_sse2, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700763WRAP(convolve8_horiz_sse2, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700764WRAP(convolve8_vert_sse2, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700765WRAP(convolve8_horiz_sse2, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700766WRAP(convolve8_vert_sse2, 12)
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700767#endif // HAVE_SSE2 && ARCH_X86_64
768
Alex Converse7e779382015-10-09 11:42:05 -0700769WRAP(convolve_copy_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700770WRAP(convolve8_horiz_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700771WRAP(convolve8_vert_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700772WRAP(convolve_copy_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700773WRAP(convolve8_horiz_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700774WRAP(convolve8_vert_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700775WRAP(convolve_copy_c, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700776WRAP(convolve8_horiz_c, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700777WRAP(convolve8_vert_c, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700778
779#if HAVE_AVX2
780WRAP(convolve_copy_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700781WRAP(convolve8_horiz_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700782WRAP(convolve8_vert_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700783
784WRAP(convolve_copy_avx2, 10)
Yi Luo9d247352017-03-16 12:31:46 -0700785WRAP(convolve8_horiz_avx2, 10)
786WRAP(convolve8_vert_avx2, 10)
Yi Luo9d247352017-03-16 12:31:46 -0700787
788WRAP(convolve_copy_avx2, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700789WRAP(convolve8_horiz_avx2, 12)
790WRAP(convolve8_vert_avx2, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700791#endif // HAVE_AVX2
792
Alex Converse7e779382015-10-09 11:42:05 -0700793#undef WRAP
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700794
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700795const ConvolveFunctions convolve8_c(wrap_convolve_copy_c_8,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700796 wrap_convolve8_horiz_c_8,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700797 wrap_convolve8_vert_c_8, 8);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700798const ConvolveFunctions convolve10_c(wrap_convolve_copy_c_10,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700799 wrap_convolve8_horiz_c_10,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700800 wrap_convolve8_vert_c_10, 10);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700801const ConvolveFunctions convolve12_c(wrap_convolve_copy_c_12,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700802 wrap_convolve8_horiz_c_12,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700803 wrap_convolve8_vert_c_12, 12);
Alex Conversef03e2382016-04-26 18:09:40 -0700804const ConvolveParam kArrayConvolve_c[] = {
clang-format3a826f12016-08-11 17:46:05 -0700805 ALL_SIZES(convolve8_c), ALL_SIZES(convolve10_c), ALL_SIZES(convolve12_c)
Alex Conversef03e2382016-04-26 18:09:40 -0700806};
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700807
clang-format3a826f12016-08-11 17:46:05 -0700808INSTANTIATE_TEST_CASE_P(C, ConvolveTest, ::testing::ValuesIn(kArrayConvolve_c));
John Koleszar29d47ac2013-02-07 17:00:37 -0800809
Deb Mukherjee10783d42014-09-02 16:34:09 -0700810#if HAVE_SSE2 && ARCH_X86_64
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700811const ConvolveFunctions convolve8_sse2(wrap_convolve_copy_sse2_8,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700812 wrap_convolve8_horiz_sse2_8,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700813 wrap_convolve8_vert_sse2_8, 8);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700814const ConvolveFunctions convolve10_sse2(wrap_convolve_copy_sse2_10,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700815 wrap_convolve8_horiz_sse2_10,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700816 wrap_convolve8_vert_sse2_10, 10);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700817const ConvolveFunctions convolve12_sse2(wrap_convolve_copy_sse2_12,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700818 wrap_convolve8_horiz_sse2_12,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700819 wrap_convolve8_vert_sse2_12, 12);
clang-format3a826f12016-08-11 17:46:05 -0700820const ConvolveParam kArrayConvolve_sse2[] = { ALL_SIZES(convolve8_sse2),
821 ALL_SIZES(convolve10_sse2),
822 ALL_SIZES(convolve12_sse2) };
Alex Conversef03e2382016-04-26 18:09:40 -0700823INSTANTIATE_TEST_CASE_P(SSE2, ConvolveTest,
824 ::testing::ValuesIn(kArrayConvolve_sse2));
Deb Mukherjee10783d42014-09-02 16:34:09 -0700825#endif
Yunqing Wang3fb728c2013-10-10 13:51:35 -0700826
John Koleszar29d47ac2013-02-07 17:00:37 -0800827#if HAVE_SSSE3
Urvang Joshiabb71e32018-03-14 11:05:05 -0700828const ConvolveFunctions convolve8_ssse3(aom_convolve_copy_c,
Urvang Joshib0eebd62018-03-13 13:45:01 -0700829 aom_convolve8_horiz_ssse3,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700830 aom_convolve8_vert_ssse3, 0);
John Koleszar29d47ac2013-02-07 17:00:37 -0800831
Alex Conversef03e2382016-04-26 18:09:40 -0700832const ConvolveParam kArrayConvolve8_ssse3[] = { ALL_SIZES(convolve8_ssse3) };
833INSTANTIATE_TEST_CASE_P(SSSE3, ConvolveTest,
834 ::testing::ValuesIn(kArrayConvolve8_ssse3));
John Koleszar29d47ac2013-02-07 17:00:37 -0800835#endif
Johann158c80c2013-05-23 12:50:41 -0700836
Yi Luo9d247352017-03-16 12:31:46 -0700837#if HAVE_AVX2
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700838const ConvolveFunctions convolve8_avx2(wrap_convolve_copy_avx2_8,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700839 wrap_convolve8_horiz_avx2_8,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700840 wrap_convolve8_vert_avx2_8, 8);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700841const ConvolveFunctions convolve10_avx2(wrap_convolve_copy_avx2_10,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700842 wrap_convolve8_horiz_avx2_10,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700843 wrap_convolve8_vert_avx2_10, 10);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700844const ConvolveFunctions convolve12_avx2(wrap_convolve_copy_avx2_12,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700845 wrap_convolve8_horiz_avx2_12,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700846 wrap_convolve8_vert_avx2_12, 12);
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -0700847const ConvolveParam kArrayConvolve8_avx2[] = { ALL_SIZES_64(convolve8_avx2),
848 ALL_SIZES_64(convolve10_avx2),
849 ALL_SIZES_64(convolve12_avx2) };
Alex Conversef03e2382016-04-26 18:09:40 -0700850INSTANTIATE_TEST_CASE_P(AVX2, ConvolveTest,
851 ::testing::ValuesIn(kArrayConvolve8_avx2));
Yi Luo9d247352017-03-16 12:31:46 -0700852#endif // HAVE_AVX2
Yunqing Wang4f0943b2014-05-27 10:36:56 -0700853
Geza Lore938b8df2016-03-04 15:55:48 +0000854// TODO(any): Make NEON versions support 128x128 128x64 64x128 block sizes
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800855#if HAVE_NEON && !(CONFIG_AV1)
Johannce239312014-05-07 11:01:31 -0700856#if HAVE_NEON_ASM
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700857const ConvolveFunctions convolve8_neon(aom_convolve_copy_neon,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700858 aom_convolve8_horiz_neon,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700859 aom_convolve8_vert_neon, 0);
clang-format3a826f12016-08-11 17:46:05 -0700860#else // HAVE_NEON
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700861const ConvolveFunctions convolve8_neon(aom_convolve_copy_neon,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700862 aom_convolve8_horiz_neon,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700863 aom_convolve8_vert_neon, 0);
Scott LaVarnway617382a2014-09-10 09:49:34 -0700864#endif // HAVE_NEON_ASM
Johann158c80c2013-05-23 12:50:41 -0700865
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -0700866const ConvolveParam kArrayConvolve8_neon[] = { ALL_SIZES_64(convolve8_neon) };
Alex Conversef03e2382016-04-26 18:09:40 -0700867INSTANTIATE_TEST_CASE_P(NEON, ConvolveTest,
868 ::testing::ValuesIn(kArrayConvolve8_neon));
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800869#endif // HAVE_NEON && !(CONFIG_AV1)
Parag Salasakar40edab52013-09-13 15:18:32 +0530870
Geza Lore938b8df2016-03-04 15:55:48 +0000871// TODO(any): Make DSPR2 versions support 128x128 128x64 64x128 block sizes
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800872#if HAVE_DSPR2 && !(CONFIG_AV1)
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700873const ConvolveFunctions convolve8_dspr2(aom_convolve_copy_dspr2,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700874 aom_convolve8_horiz_dspr2,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700875 aom_convolve8_vert_dspr2, 0);
Parag Salasakar40edab52013-09-13 15:18:32 +0530876
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -0700877const ConvolveParam kArrayConvolve8_dspr2[] = { ALL_SIZES_64(convolve8_dspr2) };
Alex Conversef03e2382016-04-26 18:09:40 -0700878INSTANTIATE_TEST_CASE_P(DSPR2, ConvolveTest,
879 ::testing::ValuesIn(kArrayConvolve8_dspr2));
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800880#endif // HAVE_DSPR2 && !(CONFIG_AV1)
Parag Salasakar27d083c2015-04-16 11:03:24 +0530881
Geza Lore938b8df2016-03-04 15:55:48 +0000882// TODO(any): Make MSA versions support 128x128 128x64 64x128 block sizes
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800883#if HAVE_MSA && !(CONFIG_AV1)
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700884const ConvolveFunctions convolve8_msa(aom_convolve_copy_msa,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700885 aom_convolve8_horiz_msa,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700886 aom_convolve8_vert_msa, 0);
Parag Salasakar27d083c2015-04-16 11:03:24 +0530887
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -0700888const ConvolveParam kArrayConvolve8_msa[] = { ALL_SIZES_64(convolve8_msa) };
Alex Conversef03e2382016-04-26 18:09:40 -0700889INSTANTIATE_TEST_CASE_P(MSA, ConvolveTest,
890 ::testing::ValuesIn(kArrayConvolve8_msa));
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800891#endif // HAVE_MSA && !(CONFIG_AV1)
James Zern8fb48af2013-05-02 13:08:19 -0700892} // namespace