blob: eaa9aebd5dc4b46506363ecb777b0de94ba7b9a2 [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
Tom Finegan60e653d2018-05-22 11:34:58 -070016#include "config/aom_config.h"
Tom Finegan44702c82018-05-22 13:00:39 -070017#include "config/aom_dsp_rtcd.h"
Tom Finegan60e653d2018-05-22 11:34:58 -070018
Urvang Joshia99a2632018-04-20 17:41:27 -040019#include "aom_dsp/aom_dsp_common.h"
20#include "aom_dsp/aom_filter.h"
21#include "aom_mem/aom_mem.h"
22#include "aom_ports/aom_timer.h"
23#include "aom_ports/mem.h"
24#include "av1/common/filter.h"
Jingning Han097d59c2015-07-29 14:51:36 -070025#include "test/acm_random.h"
26#include "test/clear_system_state.h"
27#include "test/register_state_check.h"
28#include "test/util.h"
John Koleszar5ca6a362013-01-25 09:47:09 -080029
30namespace {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070031
Geza Lore552d5cd2016-03-07 13:46:39 +000032static const unsigned int kMaxDimension = MAX_SB_SIZE;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070033
James Zerndfc4e8f2014-07-16 18:48:20 -070034typedef void (*ConvolveFunc)(const uint8_t *src, ptrdiff_t src_stride,
35 uint8_t *dst, ptrdiff_t dst_stride,
36 const int16_t *filter_x, int filter_x_stride,
37 const int16_t *filter_y, int filter_y_stride,
38 int w, int h);
John Koleszar5ca6a362013-01-25 09:47:09 -080039
40struct ConvolveFunctions {
Urvang Joshiabb71e32018-03-14 11:05:05 -070041 ConvolveFunctions(ConvolveFunc copy, ConvolveFunc h8, ConvolveFunc v8, int bd)
42 : copy_(copy), h8_(h8), v8_(v8), use_highbd_(bd) {}
John Koleszar5ca6a362013-01-25 09:47:09 -080043
Johann1c3594c2014-12-09 12:05:15 -080044 ConvolveFunc copy_;
James Zerndfc4e8f2014-07-16 18:48:20 -070045 ConvolveFunc h8_;
46 ConvolveFunc v8_;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -070047 int use_highbd_; // 0 if high bitdepth not used, else the actual bit depth.
John Koleszar5ca6a362013-01-25 09:47:09 -080048};
49
James Zern95612802018-03-30 11:37:54 -070050typedef ::testing::tuple<int, int, const ConvolveFunctions *> ConvolveParam;
Joshua Litt51490e52013-11-18 17:07:55 -080051
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -070052#define ALL_SIZES_64(convolve_fn) \
clang-format3a826f12016-08-11 17:46:05 -070053 make_tuple(4, 4, &convolve_fn), make_tuple(8, 4, &convolve_fn), \
54 make_tuple(4, 8, &convolve_fn), make_tuple(8, 8, &convolve_fn), \
55 make_tuple(16, 8, &convolve_fn), make_tuple(8, 16, &convolve_fn), \
56 make_tuple(16, 16, &convolve_fn), make_tuple(32, 16, &convolve_fn), \
57 make_tuple(16, 32, &convolve_fn), make_tuple(32, 32, &convolve_fn), \
58 make_tuple(64, 32, &convolve_fn), make_tuple(32, 64, &convolve_fn), \
59 make_tuple(64, 64, &convolve_fn)
Debargha Mukherjee7a160ac2017-10-07 22:29:43 -070060
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)
Alex Conversef03e2382016-04-26 18:09:40 -070064
John Koleszar5ca6a362013-01-25 09:47:09 -080065// Reference 8-tap subpixel filter, slightly modified to fit into this test.
Yaowu Xuf883b422016-08-30 14:01:10 -070066#define AV1_FILTER_WEIGHT 128
67#define AV1_FILTER_SHIFT 7
clang-format3a826f12016-08-11 17:46:05 -070068uint8_t clip_pixel(int x) { return x < 0 ? 0 : x > 255 ? 255 : x; }
John Koleszar5ca6a362013-01-25 09:47:09 -080069
Yaowu Xu032573d2017-04-24 15:04:17 -070070void filter_block2d_8_c(const uint8_t *src_ptr, unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -070071 const int16_t *HFilter, const int16_t *VFilter,
72 uint8_t *dst_ptr, unsigned int dst_stride,
73 unsigned int output_width, unsigned int output_height) {
John Koleszar5ca6a362013-01-25 09:47:09 -080074 // Between passes, we use an intermediate buffer whose height is extended to
75 // have enough horizontally filtered values as input for the vertical pass.
76 // This buffer is allocated to be big enough for the largest block type we
77 // support.
78 const int kInterp_Extend = 4;
79 const unsigned int intermediate_height =
James Zern8fb48af2013-05-02 13:08:19 -070080 (kInterp_Extend - 1) + output_height + kInterp_Extend;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070081 unsigned int i, j;
John Koleszar5ca6a362013-01-25 09:47:09 -080082
Sarah Parkere57473a2017-04-27 16:19:56 -070083 assert(intermediate_height > 7);
84
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070085 // Size of intermediate_buffer is max_intermediate_height * filter_max_width,
86 // where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
87 // + kInterp_Extend
88 // = 3 + 16 + 4
89 // = 23
90 // and filter_max_width = 16
91 //
clang-format3a826f12016-08-11 17:46:05 -070092 uint8_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension];
Tom Finegan6042d682016-05-06 09:43:37 -070093 const int intermediate_next_stride =
94 1 - static_cast<int>(intermediate_height * output_width);
John Koleszar5ca6a362013-01-25 09:47:09 -080095
96 // Horizontal pass (src -> transposed intermediate).
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -070097 uint8_t *output_ptr = intermediate_buffer;
98 const int src_next_row_stride = src_stride - output_width;
99 src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
100 for (i = 0; i < intermediate_height; ++i) {
101 for (j = 0; j < output_width; ++j) {
102 // Apply filter...
clang-format3a826f12016-08-11 17:46:05 -0700103 const int temp = (src_ptr[0] * HFilter[0]) + (src_ptr[1] * HFilter[1]) +
104 (src_ptr[2] * HFilter[2]) + (src_ptr[3] * HFilter[3]) +
105 (src_ptr[4] * HFilter[4]) + (src_ptr[5] * HFilter[5]) +
106 (src_ptr[6] * HFilter[6]) + (src_ptr[7] * HFilter[7]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700107 (AV1_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800108
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700109 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700110 *output_ptr = clip_pixel(temp >> AV1_FILTER_SHIFT);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700111 ++src_ptr;
112 output_ptr += intermediate_height;
John Koleszar5ca6a362013-01-25 09:47:09 -0800113 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700114 src_ptr += src_next_row_stride;
115 output_ptr += intermediate_next_stride;
John Koleszar5ca6a362013-01-25 09:47:09 -0800116 }
117
118 // Vertical pass (transposed intermediate -> dst).
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700119 src_ptr = intermediate_buffer;
120 const int dst_next_row_stride = dst_stride - output_width;
121 for (i = 0; i < output_height; ++i) {
122 for (j = 0; j < output_width; ++j) {
123 // Apply filter...
clang-format3a826f12016-08-11 17:46:05 -0700124 const int temp = (src_ptr[0] * VFilter[0]) + (src_ptr[1] * VFilter[1]) +
125 (src_ptr[2] * VFilter[2]) + (src_ptr[3] * VFilter[3]) +
126 (src_ptr[4] * VFilter[4]) + (src_ptr[5] * VFilter[5]) +
127 (src_ptr[6] * VFilter[6]) + (src_ptr[7] * VFilter[7]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 (AV1_FILTER_WEIGHT >> 1); // Rounding
John Koleszar5ca6a362013-01-25 09:47:09 -0800129
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700130 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 *dst_ptr++ = clip_pixel(temp >> AV1_FILTER_SHIFT);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700132 src_ptr += intermediate_height;
John Koleszar5ca6a362013-01-25 09:47:09 -0800133 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700134 src_ptr += intermediate_next_stride;
135 dst_ptr += dst_next_row_stride;
John Koleszar5ca6a362013-01-25 09:47:09 -0800136 }
137}
138
clang-format3a826f12016-08-11 17:46:05 -0700139void block2d_average_c(uint8_t *src, unsigned int src_stride,
140 uint8_t *output_ptr, unsigned int output_stride,
141 unsigned int output_width, unsigned int output_height) {
John Koleszar5ca6a362013-01-25 09:47:09 -0800142 unsigned int i, j;
143 for (i = 0; i < output_height; ++i) {
144 for (j = 0; j < output_width; ++j) {
145 output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
146 }
147 output_ptr += output_stride;
148 }
149}
150
James Zern8fb48af2013-05-02 13:08:19 -0700151void filter_average_block2d_8_c(const uint8_t *src_ptr,
152 const unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700153 const int16_t *HFilter, const int16_t *VFilter,
154 uint8_t *dst_ptr, unsigned int dst_stride,
James Zern8fb48af2013-05-02 13:08:19 -0700155 unsigned int output_width,
156 unsigned int output_height) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700157 uint8_t tmp[kMaxDimension * kMaxDimension];
John Koleszar5ca6a362013-01-25 09:47:09 -0800158
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700159 assert(output_width <= kMaxDimension);
160 assert(output_height <= kMaxDimension);
Geza Lore938b8df2016-03-04 15:55:48 +0000161 filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp, kMaxDimension,
John Koleszar5ca6a362013-01-25 09:47:09 -0800162 output_width, output_height);
clang-format3a826f12016-08-11 17:46:05 -0700163 block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride, output_width,
164 output_height);
John Koleszar5ca6a362013-01-25 09:47:09 -0800165}
166
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700167void highbd_filter_block2d_8_c(const uint16_t *src_ptr,
168 const unsigned int src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700169 const int16_t *HFilter, const int16_t *VFilter,
170 uint16_t *dst_ptr, unsigned int dst_stride,
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700171 unsigned int output_width,
clang-format3a826f12016-08-11 17:46:05 -0700172 unsigned int output_height, int bd) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700173 // Between passes, we use an intermediate buffer whose height is extended to
174 // have enough horizontally filtered values as input for the vertical pass.
175 // This buffer is allocated to be big enough for the largest block type we
176 // support.
177 const int kInterp_Extend = 4;
178 const unsigned int intermediate_height =
179 (kInterp_Extend - 1) + output_height + kInterp_Extend;
180
181 /* Size of intermediate_buffer is max_intermediate_height * filter_max_width,
182 * where max_intermediate_height = (kInterp_Extend - 1) + filter_max_height
183 * + kInterp_Extend
184 * = 3 + 16 + 4
185 * = 23
186 * and filter_max_width = 16
187 */
Sebastien Alaiwan92400ab2017-03-14 10:39:29 +0100188 uint16_t intermediate_buffer[(kMaxDimension + 8) * kMaxDimension] = { 0 };
Tom Finegan9a56a5e2016-05-13 09:42:58 -0700189 const int intermediate_next_stride =
190 1 - static_cast<int>(intermediate_height * output_width);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700191
192 // Horizontal pass (src -> transposed intermediate).
193 {
194 uint16_t *output_ptr = intermediate_buffer;
195 const int src_next_row_stride = src_stride - output_width;
196 unsigned int i, j;
197 src_ptr -= (kInterp_Extend - 1) * src_stride + (kInterp_Extend - 1);
198 for (i = 0; i < intermediate_height; ++i) {
199 for (j = 0; j < output_width; ++j) {
200 // Apply filter...
clang-format3a826f12016-08-11 17:46:05 -0700201 const int temp = (src_ptr[0] * HFilter[0]) + (src_ptr[1] * HFilter[1]) +
202 (src_ptr[2] * HFilter[2]) + (src_ptr[3] * HFilter[3]) +
203 (src_ptr[4] * HFilter[4]) + (src_ptr[5] * HFilter[5]) +
204 (src_ptr[6] * HFilter[6]) + (src_ptr[7] * HFilter[7]) +
Yaowu Xuf883b422016-08-30 14:01:10 -0700205 (AV1_FILTER_WEIGHT >> 1); // Rounding
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700206
207 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700208 *output_ptr = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700209 ++src_ptr;
210 output_ptr += intermediate_height;
211 }
212 src_ptr += src_next_row_stride;
213 output_ptr += intermediate_next_stride;
214 }
215 }
216
217 // Vertical pass (transposed intermediate -> dst).
218 {
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700219 const uint16_t *interm_ptr = intermediate_buffer;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700220 const int dst_next_row_stride = dst_stride - output_width;
221 unsigned int i, j;
222 for (i = 0; i < output_height; ++i) {
223 for (j = 0; j < output_width; ++j) {
224 // Apply filter...
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700225 const int temp =
226 (interm_ptr[0] * VFilter[0]) + (interm_ptr[1] * VFilter[1]) +
227 (interm_ptr[2] * VFilter[2]) + (interm_ptr[3] * VFilter[3]) +
228 (interm_ptr[4] * VFilter[4]) + (interm_ptr[5] * VFilter[5]) +
229 (interm_ptr[6] * VFilter[6]) + (interm_ptr[7] * VFilter[7]) +
230 (AV1_FILTER_WEIGHT >> 1); // Rounding
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700231
232 // Normalize back to 0-255...
Yaowu Xuf883b422016-08-30 14:01:10 -0700233 *dst_ptr++ = clip_pixel_highbd(temp >> AV1_FILTER_SHIFT, bd);
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700234 interm_ptr += intermediate_height;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700235 }
Urvang Joshi88a03bb2016-10-17 14:34:48 -0700236 interm_ptr += intermediate_next_stride;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700237 dst_ptr += dst_next_row_stride;
238 }
239 }
240}
241
clang-format3a826f12016-08-11 17:46:05 -0700242void highbd_block2d_average_c(uint16_t *src, unsigned int src_stride,
243 uint16_t *output_ptr, unsigned int output_stride,
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700244 unsigned int output_width,
James Zerncffef112016-02-11 18:27:00 -0800245 unsigned int output_height) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700246 unsigned int i, j;
247 for (i = 0; i < output_height; ++i) {
248 for (j = 0; j < output_width; ++j) {
249 output_ptr[j] = (output_ptr[j] + src[i * src_stride + j] + 1) >> 1;
250 }
251 output_ptr += output_stride;
252 }
253}
254
clang-format3a826f12016-08-11 17:46:05 -0700255void highbd_filter_average_block2d_8_c(
Yaowu Xu032573d2017-04-24 15:04:17 -0700256 const uint16_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
257 const int16_t *VFilter, uint16_t *dst_ptr, unsigned int dst_stride,
258 unsigned int output_width, unsigned int output_height, int bd) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700259 uint16_t tmp[kMaxDimension * kMaxDimension];
260
261 assert(output_width <= kMaxDimension);
262 assert(output_height <= kMaxDimension);
clang-format3a826f12016-08-11 17:46:05 -0700263 highbd_filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, tmp,
264 kMaxDimension, output_width, output_height, bd);
Geza Lore938b8df2016-03-04 15:55:48 +0000265 highbd_block2d_average_c(tmp, kMaxDimension, dst_ptr, dst_stride,
James Zerncffef112016-02-11 18:27:00 -0800266 output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700267}
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700268
James Zerndfc4e8f2014-07-16 18:48:20 -0700269class ConvolveTest : public ::testing::TestWithParam<ConvolveParam> {
John Koleszar29d47ac2013-02-07 17:00:37 -0800270 public:
271 static void SetUpTestCase() {
272 // Force input_ to be unaligned, output to be 16 byte aligned.
clang-format3a826f12016-08-11 17:46:05 -0700273 input_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700274 aom_memalign(kDataAlignment, kInputBufferSize + 1)) +
clang-format3a826f12016-08-11 17:46:05 -0700275 1;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700276 ref8_ = reinterpret_cast<uint8_t *>(
277 aom_memalign(kDataAlignment, kOutputStride * kMaxDimension));
clang-format3a826f12016-08-11 17:46:05 -0700278 output_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700279 aom_memalign(kDataAlignment, kOutputBufferSize));
clang-format3a826f12016-08-11 17:46:05 -0700280 output_ref_ = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700281 aom_memalign(kDataAlignment, kOutputBufferSize));
Yaowu Xuf883b422016-08-30 14:01:10 -0700282 input16_ = reinterpret_cast<uint16_t *>(aom_memalign(
clang-format3a826f12016-08-11 17:46:05 -0700283 kDataAlignment, (kInputBufferSize + 1) * sizeof(uint16_t))) +
284 1;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700285 ref16_ = reinterpret_cast<uint16_t *>(aom_memalign(
286 kDataAlignment, kOutputStride * kMaxDimension * sizeof(uint16_t)));
clang-format3a826f12016-08-11 17:46:05 -0700287 output16_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700288 aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
clang-format3a826f12016-08-11 17:46:05 -0700289 output16_ref_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700290 aom_memalign(kDataAlignment, (kOutputBufferSize) * sizeof(uint16_t)));
John Koleszar29d47ac2013-02-07 17:00:37 -0800291 }
292
Yaowu Xuc27fc142016-08-22 16:08:15 -0700293 virtual void TearDown() { libaom_test::ClearSystemState(); }
Jim Bankoski18d32362014-12-12 06:18:56 -0800294
John Koleszar29d47ac2013-02-07 17:00:37 -0800295 static void TearDownTestCase() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700296 aom_free(input_ - 1);
John Koleszar29d47ac2013-02-07 17:00:37 -0800297 input_ = NULL;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700298 aom_free(ref8_);
299 ref8_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700300 aom_free(output_);
John Koleszar29d47ac2013-02-07 17:00:37 -0800301 output_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700302 aom_free(output_ref_);
Johann1c3594c2014-12-09 12:05:15 -0800303 output_ref_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700304 aom_free(input16_ - 1);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700305 input16_ = NULL;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700306 aom_free(ref16_);
307 ref16_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700308 aom_free(output16_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700309 output16_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700310 aom_free(output16_ref_);
Johann1c3594c2014-12-09 12:05:15 -0800311 output16_ref_ = NULL;
John Koleszar29d47ac2013-02-07 17:00:37 -0800312 }
313
James Zern8fb48af2013-05-02 13:08:19 -0700314 protected:
315 static const int kDataAlignment = 16;
clang-format3a826f12016-08-11 17:46:05 -0700316 static const int kOuterBlockSize = 4 * kMaxDimension;
James Zern8fb48af2013-05-02 13:08:19 -0700317 static const int kInputStride = kOuterBlockSize;
318 static const int kOutputStride = kOuterBlockSize;
James Zern8fb48af2013-05-02 13:08:19 -0700319 static const int kInputBufferSize = kOuterBlockSize * kOuterBlockSize;
320 static const int kOutputBufferSize = kOuterBlockSize * kOuterBlockSize;
John Koleszar5ca6a362013-01-25 09:47:09 -0800321
James Zern8fb48af2013-05-02 13:08:19 -0700322 int Width() const { return GET_PARAM(0); }
323 int Height() const { return GET_PARAM(1); }
324 int BorderLeft() const {
325 const int center = (kOuterBlockSize - Width()) / 2;
326 return (center + (kDataAlignment - 1)) & ~(kDataAlignment - 1);
327 }
328 int BorderTop() const { return (kOuterBlockSize - Height()) / 2; }
John Koleszar5ca6a362013-01-25 09:47:09 -0800329
James Zern8fb48af2013-05-02 13:08:19 -0700330 bool IsIndexInBorder(int i) {
331 return (i < BorderTop() * kOuterBlockSize ||
332 i >= (BorderTop() + Height()) * kOuterBlockSize ||
333 i % kOuterBlockSize < BorderLeft() ||
334 i % kOuterBlockSize >= (BorderLeft() + Width()));
335 }
336
337 virtual void SetUp() {
338 UUT_ = GET_PARAM(2);
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700339 if (UUT_->use_highbd_ != 0)
340 mask_ = (1 << UUT_->use_highbd_) - 1;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700341 else
342 mask_ = 255;
Johann158c80c2013-05-23 12:50:41 -0700343 /* Set up guard blocks for an inner block centered in the outer block */
James Zern8fb48af2013-05-02 13:08:19 -0700344 for (int i = 0; i < kOutputBufferSize; ++i) {
Yaowu Xu5ab58722017-05-11 09:39:31 -0700345 if (IsIndexInBorder(i)) {
James Zern8fb48af2013-05-02 13:08:19 -0700346 output_[i] = 255;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700347 output16_[i] = mask_;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700348 } else {
James Zern8fb48af2013-05-02 13:08:19 -0700349 output_[i] = 0;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700350 output16_[i] = 0;
Yaowu Xu5ab58722017-05-11 09:39:31 -0700351 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800352 }
353
Yaowu Xuc27fc142016-08-22 16:08:15 -0700354 ::libaom_test::ACMRandom prng;
Yaowu Xu077144d2014-05-23 12:23:29 -0700355 for (int i = 0; i < kInputBufferSize; ++i) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700356 if (i & 1) {
Yaowu Xu077144d2014-05-23 12:23:29 -0700357 input_[i] = 255;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700358 input16_[i] = mask_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700359 } else {
Yaowu Xu077144d2014-05-23 12:23:29 -0700360 input_[i] = prng.Rand8Extremes();
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700361 input16_[i] = prng.Rand16() & mask_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700362 }
Yaowu Xu077144d2014-05-23 12:23:29 -0700363 }
James Zern8fb48af2013-05-02 13:08:19 -0700364 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800365
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300366 void SetConstantInput(int value) {
367 memset(input_, value, kInputBufferSize);
Yaowu Xuf883b422016-08-30 14:01:10 -0700368 aom_memset16(input16_, value, kInputBufferSize);
Tero Rintaluomae326cec2013-08-22 11:29:19 +0300369 }
370
Johann1c3594c2014-12-09 12:05:15 -0800371 void CopyOutputToRef() {
James Zernf274c212015-04-23 20:42:19 -0700372 memcpy(output_ref_, output_, kOutputBufferSize);
Yaowu Xuc648a9f2016-10-10 17:39:29 -0700373 // Copy 16-bit pixels values. The effective number of bytes is double.
374 memcpy(output16_ref_, output16_, sizeof(output16_[0]) * kOutputBufferSize);
Johann1c3594c2014-12-09 12:05:15 -0800375 }
376
James Zern8fb48af2013-05-02 13:08:19 -0700377 void CheckGuardBlocks() {
378 for (int i = 0; i < kOutputBufferSize; ++i) {
Sebastien Alaiwan7d701682017-10-04 10:07:24 +0200379 if (IsIndexInBorder(i)) {
380 EXPECT_EQ(255, output_[i]);
381 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800382 }
James Zern8fb48af2013-05-02 13:08:19 -0700383 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800384
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700385 uint8_t *input() const {
Johann2967bf32016-06-22 16:08:10 -0700386 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700387 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700388 return input_ + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700389 } else {
Johann2967bf32016-06-22 16:08:10 -0700390 return CONVERT_TO_BYTEPTR(input16_) + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700391 }
James Zern8fb48af2013-05-02 13:08:19 -0700392 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800393
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700394 uint8_t *output() const {
Johann2967bf32016-06-22 16:08:10 -0700395 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700396 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700397 return output_ + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700398 } else {
Johann2967bf32016-06-22 16:08:10 -0700399 return CONVERT_TO_BYTEPTR(output16_) + offset;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700400 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700401 }
402
Johann1c3594c2014-12-09 12:05:15 -0800403 uint8_t *output_ref() const {
Johann2967bf32016-06-22 16:08:10 -0700404 const int offset = BorderTop() * kOuterBlockSize + BorderLeft();
Johann1c3594c2014-12-09 12:05:15 -0800405 if (UUT_->use_highbd_ == 0) {
Johann2967bf32016-06-22 16:08:10 -0700406 return output_ref_ + offset;
Johann1c3594c2014-12-09 12:05:15 -0800407 } else {
Johann2967bf32016-06-22 16:08:10 -0700408 return CONVERT_TO_BYTEPTR(output16_ref_) + offset;
Johann1c3594c2014-12-09 12:05:15 -0800409 }
Johann1c3594c2014-12-09 12:05:15 -0800410 }
411
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700412 uint16_t lookup(uint8_t *list, int index) const {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700413 if (UUT_->use_highbd_ == 0) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700414 return list[index];
415 } else {
416 return CONVERT_TO_SHORTPTR(list)[index];
417 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700418 }
419
420 void assign_val(uint8_t *list, int index, uint16_t val) const {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700421 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700422 list[index] = (uint8_t)val;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700423 } else {
424 CONVERT_TO_SHORTPTR(list)[index] = val;
425 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700426 }
427
clang-format3a826f12016-08-11 17:46:05 -0700428 void wrapper_filter_average_block2d_8_c(
Yaowu Xu032573d2017-04-24 15:04:17 -0700429 const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
430 const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
431 unsigned int output_width, unsigned int output_height) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700432 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700433 filter_average_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
434 dst_stride, output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700435 } else {
clang-format3a826f12016-08-11 17:46:05 -0700436 highbd_filter_average_block2d_8_c(
437 CONVERT_TO_SHORTPTR(src_ptr), src_stride, HFilter, VFilter,
438 CONVERT_TO_SHORTPTR(dst_ptr), dst_stride, output_width, output_height,
439 UUT_->use_highbd_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700440 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700441 }
442
Yaowu Xu032573d2017-04-24 15:04:17 -0700443 void wrapper_filter_block2d_8_c(
444 const uint8_t *src_ptr, unsigned int src_stride, const int16_t *HFilter,
445 const int16_t *VFilter, uint8_t *dst_ptr, unsigned int dst_stride,
446 unsigned int output_width, unsigned int output_height) {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700447 if (UUT_->use_highbd_ == 0) {
clang-format3a826f12016-08-11 17:46:05 -0700448 filter_block2d_8_c(src_ptr, src_stride, HFilter, VFilter, dst_ptr,
449 dst_stride, output_width, output_height);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700450 } else {
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700451 highbd_filter_block2d_8_c(CONVERT_TO_SHORTPTR(src_ptr), src_stride,
clang-format3a826f12016-08-11 17:46:05 -0700452 HFilter, VFilter, CONVERT_TO_SHORTPTR(dst_ptr),
453 dst_stride, output_width, output_height,
454 UUT_->use_highbd_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700455 }
James Zern8fb48af2013-05-02 13:08:19 -0700456 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800457
clang-format3a826f12016-08-11 17:46:05 -0700458 const ConvolveFunctions *UUT_;
459 static uint8_t *input_;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700460 static uint8_t *ref8_;
clang-format3a826f12016-08-11 17:46:05 -0700461 static uint8_t *output_;
462 static uint8_t *output_ref_;
clang-format3a826f12016-08-11 17:46:05 -0700463 static uint16_t *input16_;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700464 static uint16_t *ref16_;
clang-format3a826f12016-08-11 17:46:05 -0700465 static uint16_t *output16_;
466 static uint16_t *output16_ref_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700467 int mask_;
John Koleszar5ca6a362013-01-25 09:47:09 -0800468};
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700469
clang-format3a826f12016-08-11 17:46:05 -0700470uint8_t *ConvolveTest::input_ = NULL;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700471uint8_t *ConvolveTest::ref8_ = NULL;
clang-format3a826f12016-08-11 17:46:05 -0700472uint8_t *ConvolveTest::output_ = NULL;
473uint8_t *ConvolveTest::output_ref_ = NULL;
clang-format3a826f12016-08-11 17:46:05 -0700474uint16_t *ConvolveTest::input16_ = NULL;
Yaowu Xu30cc9502018-10-17 14:36:37 -0700475uint16_t *ConvolveTest::ref16_ = NULL;
clang-format3a826f12016-08-11 17:46:05 -0700476uint16_t *ConvolveTest::output16_ = NULL;
477uint16_t *ConvolveTest::output16_ref_ = NULL;
John Koleszar5ca6a362013-01-25 09:47:09 -0800478
clang-format3a826f12016-08-11 17:46:05 -0700479TEST_P(ConvolveTest, GuardBlocks) { CheckGuardBlocks(); }
John Koleszar5ca6a362013-01-25 09:47:09 -0800480
Johann1c3594c2014-12-09 12:05:15 -0800481TEST_P(ConvolveTest, Copy) {
clang-format3a826f12016-08-11 17:46:05 -0700482 uint8_t *const in = input();
483 uint8_t *const out = output();
Johann1c3594c2014-12-09 12:05:15 -0800484
clang-format3a826f12016-08-11 17:46:05 -0700485 ASM_REGISTER_STATE_CHECK(UUT_->copy_(in, kInputStride, out, kOutputStride,
486 NULL, 0, NULL, 0, Width(), Height()));
Johann1c3594c2014-12-09 12:05:15 -0800487
488 CheckGuardBlocks();
489
490 for (int y = 0; y < Height(); ++y)
491 for (int x = 0; x < Width(); ++x)
492 ASSERT_EQ(lookup(out, y * kOutputStride + x),
493 lookup(in, y * kInputStride + x))
494 << "(" << x << "," << y << ")";
495}
496
Angie Chiangb1372892016-12-01 15:06:06 -0800497const int kNumFilterBanks = SWITCHABLE_FILTERS;
John Koleszara9ebbcc2013-04-18 13:05:38 -0700498const int kNumFilters = 16;
499
500TEST(ConvolveTest, FiltersWontSaturateWhenAddedPairwise) {
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530501 int subpel_search;
502 for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
503 ++subpel_search) {
504 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
505 const InterpFilter filter = (InterpFilter)filter_bank;
506 const InterpKernel *filters =
507 (const InterpKernel *)av1_get_interp_filter_kernel(filter,
508 subpel_search);
509 for (int i = 0; i < kNumFilters; i++) {
510 const int p0 = filters[i][0] + filters[i][1];
511 const int p1 = filters[i][2] + filters[i][3];
512 const int p2 = filters[i][4] + filters[i][5];
513 const int p3 = filters[i][6] + filters[i][7];
514 EXPECT_LE(p0, 128);
515 EXPECT_LE(p1, 128);
516 EXPECT_LE(p2, 128);
517 EXPECT_LE(p3, 128);
518 EXPECT_LE(p0 + p3, 128);
519 EXPECT_LE(p0 + p3 + p1, 128);
520 EXPECT_LE(p0 + p3 + p1 + p2, 128);
521 EXPECT_EQ(p0 + p1 + p2 + p3, 128);
522 }
John Koleszara9ebbcc2013-04-18 13:05:38 -0700523 }
524 }
525}
John Koleszar557a1b22013-02-20 16:13:01 -0800526
John Koleszar04c24072013-02-20 16:32:02 -0800527const int16_t kInvalidFilter[8] = { 0 };
528
John Koleszar5ca6a362013-01-25 09:47:09 -0800529TEST_P(ConvolveTest, MatchesReferenceSubpixelFilter) {
clang-format3a826f12016-08-11 17:46:05 -0700530 uint8_t *const in = input();
531 uint8_t *const out = output();
clang-format3a826f12016-08-11 17:46:05 -0700532 uint8_t *ref;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700533 if (UUT_->use_highbd_ == 0) {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700534 ref = ref8_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700535 } else {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700536 ref = CONVERT_TO_BYTEPTR(ref16_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700537 }
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530538 int subpel_search;
539 for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
540 ++subpel_search) {
541 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
542 const InterpFilter filter = (InterpFilter)filter_bank;
543 const InterpKernel *filters =
544 (const InterpKernel *)av1_get_interp_filter_kernel(filter,
545 subpel_search);
546 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
547 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
548 wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
549 filters[filter_y], ref, kOutputStride,
550 Width(), Height());
John Koleszar5ca6a362013-01-25 09:47:09 -0800551
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530552 if (filter_x && filter_y)
553 continue;
554 else if (filter_y)
555 ASM_REGISTER_STATE_CHECK(
556 UUT_->v8_(in, kInputStride, out, kOutputStride, kInvalidFilter,
557 16, filters[filter_y], 16, Width(), Height()));
558 else if (filter_x)
559 ASM_REGISTER_STATE_CHECK(UUT_->h8_(
560 in, kInputStride, out, kOutputStride, filters[filter_x], 16,
561 kInvalidFilter, 16, Width(), Height()));
562 else
563 ASM_REGISTER_STATE_CHECK(UUT_->copy_(
564 in, kInputStride, out, kOutputStride, kInvalidFilter, 0,
565 kInvalidFilter, 0, Width(), Height()));
Dmitry Kovalev021eaab2014-05-14 16:21:41 -0700566
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530567 CheckGuardBlocks();
John Koleszar5ca6a362013-01-25 09:47:09 -0800568
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530569 for (int y = 0; y < Height(); ++y)
570 for (int x = 0; x < Width(); ++x)
571 ASSERT_EQ(lookup(ref, y * kOutputStride + x),
572 lookup(out, y * kOutputStride + x))
573 << "mismatch at (" << x << "," << y << "), "
574 << "filters (" << filter_bank << "," << filter_x << ","
575 << filter_y << ")";
576 }
John Koleszar557a1b22013-02-20 16:13:01 -0800577 }
John Koleszar5ca6a362013-01-25 09:47:09 -0800578 }
579 }
580}
581
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700582TEST_P(ConvolveTest, FilterExtremes) {
583 uint8_t *const in = input();
584 uint8_t *const out = output();
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700585 uint8_t *ref;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700586 if (UUT_->use_highbd_ == 0) {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700587 ref = ref8_;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700588 } else {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700589 ref = CONVERT_TO_BYTEPTR(ref16_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700590 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700591
592 // Populate ref and out with some random data
Yaowu Xuc27fc142016-08-22 16:08:15 -0700593 ::libaom_test::ACMRandom prng;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700594 for (int y = 0; y < Height(); ++y) {
595 for (int x = 0; x < Width(); ++x) {
596 uint16_t r;
Deb Mukherjee1929c9b2014-10-08 12:43:22 -0700597 if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700598 r = prng.Rand8Extremes();
599 } else {
600 r = prng.Rand16() & mask_;
601 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700602 assign_val(out, y * kOutputStride + x, r);
603 assign_val(ref, y * kOutputStride + x, r);
604 }
605 }
606
607 for (int axis = 0; axis < 2; axis++) {
608 int seed_val = 0;
609 while (seed_val < 256) {
610 for (int y = 0; y < 8; ++y) {
611 for (int x = 0; x < 8; ++x) {
clang-format3a826f12016-08-11 17:46:05 -0700612 assign_val(in, y * kOutputStride + x - SUBPEL_TAPS / 2 + 1,
613 ((seed_val >> (axis ? y : x)) & 1) * mask_);
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700614 if (axis) seed_val++;
615 }
616 if (axis)
clang-format3a826f12016-08-11 17:46:05 -0700617 seed_val -= 8;
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700618 else
619 seed_val++;
620 }
621 if (axis) seed_val += 8;
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530622 int subpel_search;
623 for (subpel_search = USE_4_TAPS; subpel_search <= USE_8_TAPS;
624 ++subpel_search) {
625 for (int filter_bank = 0; filter_bank < kNumFilterBanks;
626 ++filter_bank) {
627 const InterpFilter filter = (InterpFilter)filter_bank;
628 const InterpKernel *filters =
629 (const InterpKernel *)av1_get_interp_filter_kernel(filter,
630 subpel_search);
631 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
632 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
633 wrapper_filter_block2d_8_c(in, kInputStride, filters[filter_x],
634 filters[filter_y], ref, kOutputStride,
635 Width(), Height());
636 if (filter_x && filter_y)
637 continue;
638 else if (filter_y)
639 ASM_REGISTER_STATE_CHECK(UUT_->v8_(
640 in, kInputStride, out, kOutputStride, kInvalidFilter, 16,
641 filters[filter_y], 16, Width(), Height()));
642 else if (filter_x)
643 ASM_REGISTER_STATE_CHECK(UUT_->h8_(
644 in, kInputStride, out, kOutputStride, filters[filter_x], 16,
645 kInvalidFilter, 16, Width(), Height()));
646 else
647 ASM_REGISTER_STATE_CHECK(UUT_->copy_(
648 in, kInputStride, out, kOutputStride, kInvalidFilter, 0,
649 kInvalidFilter, 0, Width(), Height()));
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700650
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530651 for (int y = 0; y < Height(); ++y)
652 for (int x = 0; x < Width(); ++x)
653 ASSERT_EQ(lookup(ref, y * kOutputStride + x),
654 lookup(out, y * kOutputStride + x))
655 << "mismatch at (" << x << "," << y << "), "
656 << "filters (" << filter_bank << "," << filter_x << ","
657 << filter_y << ")";
658 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700659 }
660 }
661 }
662 }
663 }
664}
665
Yi Luoa4d87992017-04-14 17:44:26 -0700666TEST_P(ConvolveTest, DISABLED_Copy_Speed) {
667 const uint8_t *const in = input();
668 uint8_t *const out = output();
669 const int kNumTests = 5000000;
670 const int width = Width();
671 const int height = Height();
672 aom_usec_timer timer;
673
674 aom_usec_timer_start(&timer);
675 for (int n = 0; n < kNumTests; ++n) {
676 UUT_->copy_(in, kInputStride, out, kOutputStride, NULL, 0, NULL, 0, width,
677 height);
678 }
679 aom_usec_timer_mark(&timer);
680
681 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
682 printf("convolve_copy_%dx%d_%d: %d us\n", width, height,
683 UUT_->use_highbd_ ? UUT_->use_highbd_ : 8, elapsed_time);
684}
685
Yi Luo9d247352017-03-16 12:31:46 -0700686TEST_P(ConvolveTest, DISABLED_Speed) {
687 uint8_t *const in = input();
688 uint8_t *const out = output();
Yi Luo9d247352017-03-16 12:31:46 -0700689 uint8_t *ref;
690 if (UUT_->use_highbd_ == 0) {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700691 ref = ref8_;
Yi Luo9d247352017-03-16 12:31:46 -0700692 } else {
Yaowu Xu30cc9502018-10-17 14:36:37 -0700693 ref = CONVERT_TO_BYTEPTR(ref16_);
Yi Luo9d247352017-03-16 12:31:46 -0700694 }
Yi Luo9d247352017-03-16 12:31:46 -0700695
696 // Populate ref and out with some random data
697 ::libaom_test::ACMRandom prng;
698 for (int y = 0; y < Height(); ++y) {
699 for (int x = 0; x < Width(); ++x) {
700 uint16_t r;
Yi Luo9d247352017-03-16 12:31:46 -0700701 if (UUT_->use_highbd_ == 0 || UUT_->use_highbd_ == 8) {
702 r = prng.Rand8Extremes();
703 } else {
704 r = prng.Rand16() & mask_;
705 }
Yi Luo9d247352017-03-16 12:31:46 -0700706 assign_val(out, y * kOutputStride + x, r);
707 assign_val(ref, y * kOutputStride + x, r);
708 }
709 }
710
711 const InterpFilter filter = (InterpFilter)1;
712 const InterpKernel *filters =
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530713 (const InterpKernel *)av1_get_interp_filter_kernel(filter, USE_8_TAPS);
Yi Luo9d247352017-03-16 12:31:46 -0700714 wrapper_filter_average_block2d_8_c(in, kInputStride, filters[1], filters[1],
715 out, kOutputStride, Width(), Height());
716
717 aom_usec_timer timer;
718 int tests_num = 1000;
719
720 aom_usec_timer_start(&timer);
721 while (tests_num > 0) {
722 for (int filter_bank = 0; filter_bank < kNumFilterBanks; ++filter_bank) {
723 const InterpFilter filter = (InterpFilter)filter_bank;
724 const InterpKernel *filters =
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530725 (const InterpKernel *)av1_get_interp_filter_kernel(filter,
726 USE_8_TAPS);
Yi Luo9d247352017-03-16 12:31:46 -0700727 for (int filter_x = 0; filter_x < kNumFilters; ++filter_x) {
728 for (int filter_y = 0; filter_y < kNumFilters; ++filter_y) {
Urvang Joshiabb71e32018-03-14 11:05:05 -0700729 if (filter_x && filter_y) continue;
Yi Luo9d247352017-03-16 12:31:46 -0700730 if (filter_y)
731 ASM_REGISTER_STATE_CHECK(
732 UUT_->v8_(in, kInputStride, out, kOutputStride, kInvalidFilter,
733 16, filters[filter_y], 16, Width(), Height()));
734 else if (filter_x)
735 ASM_REGISTER_STATE_CHECK(UUT_->h8_(
736 in, kInputStride, out, kOutputStride, filters[filter_x], 16,
737 kInvalidFilter, 16, Width(), Height()));
738 }
739 }
740 }
741 tests_num--;
742 }
743 aom_usec_timer_mark(&timer);
744
745 const int elapsed_time =
746 static_cast<int>(aom_usec_timer_elapsed(&timer) / 1000);
747 printf("%dx%d (bitdepth %d) time: %5d ms\n", Width(), Height(),
748 UUT_->use_highbd_, elapsed_time);
749}
750
James Zern95612802018-03-30 11:37:54 -0700751using ::testing::make_tuple;
John Koleszar5ca6a362013-01-25 09:47:09 -0800752
clang-format3a826f12016-08-11 17:46:05 -0700753#define WRAP(func, bd) \
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700754 static void wrap_##func##_##bd( \
clang-format3a826f12016-08-11 17:46:05 -0700755 const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst, \
756 ptrdiff_t dst_stride, const int16_t *filter_x, int filter_x_stride, \
757 const int16_t *filter_y, int filter_y_stride, int w, int h) { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700758 aom_highbd_##func(src, src_stride, dst, dst_stride, filter_x, \
clang-format3a826f12016-08-11 17:46:05 -0700759 filter_x_stride, filter_y, filter_y_stride, w, h, bd); \
760 }
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700761#if HAVE_SSE2 && ARCH_X86_64
Alex Converse0c00af12015-10-06 15:59:03 -0700762WRAP(convolve_copy_sse2, 8)
Alex Converse0c00af12015-10-06 15:59:03 -0700763WRAP(convolve_copy_sse2, 10)
Alex Converse0c00af12015-10-06 15:59:03 -0700764WRAP(convolve_copy_sse2, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700765WRAP(convolve8_horiz_sse2, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700766WRAP(convolve8_vert_sse2, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700767WRAP(convolve8_horiz_sse2, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700768WRAP(convolve8_vert_sse2, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700769WRAP(convolve8_horiz_sse2, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700770WRAP(convolve8_vert_sse2, 12)
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700771#endif // HAVE_SSE2 && ARCH_X86_64
772
Alex Converse7e779382015-10-09 11:42:05 -0700773WRAP(convolve_copy_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700774WRAP(convolve8_horiz_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700775WRAP(convolve8_vert_c, 8)
Alex Converse7e779382015-10-09 11:42:05 -0700776WRAP(convolve_copy_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700777WRAP(convolve8_horiz_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700778WRAP(convolve8_vert_c, 10)
Alex Converse7e779382015-10-09 11:42:05 -0700779WRAP(convolve_copy_c, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700780WRAP(convolve8_horiz_c, 12)
Alex Converse7e779382015-10-09 11:42:05 -0700781WRAP(convolve8_vert_c, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700782
783#if HAVE_AVX2
784WRAP(convolve_copy_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700785WRAP(convolve8_horiz_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700786WRAP(convolve8_vert_avx2, 8)
Yi Luo9d247352017-03-16 12:31:46 -0700787
788WRAP(convolve_copy_avx2, 10)
Yi Luo9d247352017-03-16 12:31:46 -0700789WRAP(convolve8_horiz_avx2, 10)
790WRAP(convolve8_vert_avx2, 10)
Yi Luo9d247352017-03-16 12:31:46 -0700791
792WRAP(convolve_copy_avx2, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700793WRAP(convolve8_horiz_avx2, 12)
794WRAP(convolve8_vert_avx2, 12)
Yi Luo9d247352017-03-16 12:31:46 -0700795#endif // HAVE_AVX2
796
Alex Converse7e779382015-10-09 11:42:05 -0700797#undef WRAP
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700798
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700799const ConvolveFunctions convolve8_c(wrap_convolve_copy_c_8,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700800 wrap_convolve8_horiz_c_8,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700801 wrap_convolve8_vert_c_8, 8);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700802const ConvolveFunctions convolve10_c(wrap_convolve_copy_c_10,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700803 wrap_convolve8_horiz_c_10,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700804 wrap_convolve8_vert_c_10, 10);
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700805const ConvolveFunctions convolve12_c(wrap_convolve_copy_c_12,
Urvang Joshidf8ce4f2018-03-13 15:09:27 -0700806 wrap_convolve8_horiz_c_12,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700807 wrap_convolve8_vert_c_12, 12);
Hien Ho830b8972019-04-04 15:51:14 -0700808const ConvolveParam kArrayConvolve_c[] = { ALL_SIZES(convolve8_c),
809 ALL_SIZES(convolve10_c),
810 ALL_SIZES(convolve12_c) };
Deb Mukherjee0d3c3d32014-09-16 12:47:18 -0700811
clang-format3a826f12016-08-11 17:46:05 -0700812INSTANTIATE_TEST_CASE_P(C, ConvolveTest, ::testing::ValuesIn(kArrayConvolve_c));
John Koleszar29d47ac2013-02-07 17:00:37 -0800813
Deb Mukherjee10783d42014-09-02 16:34:09 -0700814#if HAVE_SSE2 && ARCH_X86_64
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530815const ConvolveFunctions convolve8_sse2(aom_convolve_copy_c,
816 aom_convolve8_horiz_sse2,
817 aom_convolve8_vert_sse2, 0);
818const ConvolveFunctions wrap_convolve8_sse2(wrap_convolve_copy_sse2_8,
819 wrap_convolve8_horiz_sse2_8,
820 wrap_convolve8_vert_sse2_8, 8);
821const ConvolveFunctions wrap_convolve10_sse2(wrap_convolve_copy_sse2_10,
822 wrap_convolve8_horiz_sse2_10,
823 wrap_convolve8_vert_sse2_10, 10);
824const ConvolveFunctions wrap_convolve12_sse2(wrap_convolve_copy_sse2_12,
825 wrap_convolve8_horiz_sse2_12,
826 wrap_convolve8_vert_sse2_12, 12);
clang-format3a826f12016-08-11 17:46:05 -0700827const ConvolveParam kArrayConvolve_sse2[] = { ALL_SIZES(convolve8_sse2),
Sachin Kumar Garg8048e8c2018-10-10 18:48:44 +0530828 ALL_SIZES(wrap_convolve8_sse2),
829 ALL_SIZES(wrap_convolve10_sse2),
830 ALL_SIZES(wrap_convolve12_sse2) };
Alex Conversef03e2382016-04-26 18:09:40 -0700831INSTANTIATE_TEST_CASE_P(SSE2, ConvolveTest,
832 ::testing::ValuesIn(kArrayConvolve_sse2));
Deb Mukherjee10783d42014-09-02 16:34:09 -0700833#endif
Yunqing Wang3fb728c2013-10-10 13:51:35 -0700834
John Koleszar29d47ac2013-02-07 17:00:37 -0800835#if HAVE_SSSE3
Urvang Joshiabb71e32018-03-14 11:05:05 -0700836const ConvolveFunctions convolve8_ssse3(aom_convolve_copy_c,
Urvang Joshib0eebd62018-03-13 13:45:01 -0700837 aom_convolve8_horiz_ssse3,
Urvang Joshiabb71e32018-03-14 11:05:05 -0700838 aom_convolve8_vert_ssse3, 0);
John Koleszar29d47ac2013-02-07 17:00:37 -0800839
Alex Conversef03e2382016-04-26 18:09:40 -0700840const ConvolveParam kArrayConvolve8_ssse3[] = { ALL_SIZES(convolve8_ssse3) };
841INSTANTIATE_TEST_CASE_P(SSSE3, ConvolveTest,
842 ::testing::ValuesIn(kArrayConvolve8_ssse3));
John Koleszar29d47ac2013-02-07 17:00:37 -0800843#endif
Johann158c80c2013-05-23 12:50:41 -0700844
Yi Luo9d247352017-03-16 12:31:46 -0700845#if HAVE_AVX2
Xing Jinfd681912018-07-12 20:21:55 +0800846const ConvolveFunctions convolve8_avx2(aom_convolve_copy_c,
847 aom_convolve8_horiz_avx2,
848 aom_convolve8_vert_avx2, 0);
849
Xing Jinfd681912018-07-12 20:21:55 +0800850const ConvolveFunctions wrap_convolve8_avx2(wrap_convolve_copy_avx2_8,
851 wrap_convolve8_horiz_avx2_8,
852 wrap_convolve8_vert_avx2_8, 8);
853const ConvolveFunctions wrap_convolve10_avx2(wrap_convolve_copy_avx2_10,
854 wrap_convolve8_horiz_avx2_10,
855 wrap_convolve8_vert_avx2_10, 10);
856const ConvolveFunctions wrap_convolve12_avx2(wrap_convolve_copy_avx2_12,
857 wrap_convolve8_horiz_avx2_12,
858 wrap_convolve8_vert_avx2_12, 12);
Xing Jinc67b3cd2018-07-20 13:38:40 +0800859const ConvolveParam kArray_Convolve8_avx2[] = {
Xing Jinfd681912018-07-12 20:21:55 +0800860 ALL_SIZES_64(wrap_convolve8_avx2), ALL_SIZES_64(wrap_convolve10_avx2),
Xing Jinc67b3cd2018-07-20 13:38:40 +0800861 ALL_SIZES_64(wrap_convolve12_avx2), ALL_SIZES(convolve8_avx2)
Xing Jinfd681912018-07-12 20:21:55 +0800862};
Xing Jinc67b3cd2018-07-20 13:38:40 +0800863INSTANTIATE_TEST_CASE_P(AVX2, ConvolveTest,
864 ::testing::ValuesIn(kArray_Convolve8_avx2));
Yi Luo9d247352017-03-16 12:31:46 -0700865#endif // HAVE_AVX2
Yunqing Wang4f0943b2014-05-27 10:36:56 -0700866
James Zern8fb48af2013-05-02 13:08:19 -0700867} // namespace