blob: b45b7bb3fdc15afbc273634f2dbd42298499e668 [file] [log] [blame]
Peng Bin640ea402018-03-30 14:12:53 +08001/*
2 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#include <stdint.h>
13#include <stdio.h>
14#include <string.h>
sarahparkera543df52018-11-02 16:02:05 -070015#include <tuple>
Peng Bin640ea402018-03-30 14:12:53 +080016
Tom Finegan60e653d2018-05-22 11:34:58 -070017#include "config/aom_config.h"
Tom Finegan44702c82018-05-22 13:00:39 -070018#include "config/av1_rtcd.h"
Tom Finegan60e653d2018-05-22 11:34:58 -070019
Peng Bin640ea402018-03-30 14:12:53 +080020#include "aom_ports/mem.h"
21#include "av1/common/scan.h"
22#include "av1/common/txb_common.h"
23#include "test/acm_random.h"
Peng Bin640ea402018-03-30 14:12:53 +080024#include "test/register_state_check.h"
25#include "test/util.h"
26#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
27
28namespace {
29using libaom_test::ACMRandom;
30
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053031typedef void (*buildcompdiffwtdmaskd_func)(uint8_t *mask,
32 DIFFWTD_MASK_TYPE mask_type,
33 const uint8_t *src0, int src0_stride,
34 const uint8_t *src1, int src1_stride,
35 int h, int w);
36
sarahparkera543df52018-11-02 16:02:05 -070037typedef std::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func>
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053038 BuildCompDiffwtdMaskDParam;
39
40#if HAVE_SSE4_1
41::testing::internal::ParamGenerator<BuildCompDiffwtdMaskDParam> BuildParams(
42 buildcompdiffwtdmaskd_func filter) {
43 return ::testing::Combine(::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL),
44 ::testing::Values(filter));
45}
46#endif
47
48class BuildCompDiffwtdMaskTest
49 : public ::testing::TestWithParam<BuildCompDiffwtdMaskDParam> {
Peng Bin640ea402018-03-30 14:12:53 +080050 public:
51 virtual ~BuildCompDiffwtdMaskTest() {}
52
chiyotsai6ddbede2021-06-30 14:24:15 -070053 virtual void TearDown() {}
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053054 void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed,
Peng Bin640ea402018-03-30 14:12:53 +080055 const DIFFWTD_MASK_TYPE type);
56
57 private:
58 ACMRandom rnd_;
59};
60
Ravi Chaudharyea665b02018-04-10 18:39:47 +053061typedef void (*buildcompdiffwtdmaskd16_func)(
62 uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const CONV_BUF_TYPE *src0,
63 int src0_stride, const CONV_BUF_TYPE *src1, int src1_stride, int h, int w,
64 ConvolveParams *conv_params, int bd);
65
sarahparkera543df52018-11-02 16:02:05 -070066typedef std::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE>
Ravi Chaudharyea665b02018-04-10 18:39:47 +053067 BuildCompDiffwtdMaskD16Param;
68
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +053069#if HAVE_SSE4_1 || HAVE_NEON
Ravi Chaudharyea665b02018-04-10 18:39:47 +053070::testing::internal::ParamGenerator<BuildCompDiffwtdMaskD16Param> BuildParams(
71 buildcompdiffwtdmaskd16_func filter) {
72 return ::testing::Combine(::testing::Range(8, 13, 2),
73 ::testing::Values(filter),
74 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
75}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +053076#endif
Ravi Chaudharyea665b02018-04-10 18:39:47 +053077class BuildCompDiffwtdMaskD16Test
78 : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> {
79 public:
80 ~BuildCompDiffwtdMaskD16Test() {}
chiyotsai6ddbede2021-06-30 14:24:15 -070081 virtual void TearDown() {}
Ravi Chaudharyea665b02018-04-10 18:39:47 +053082 void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
83
84 protected:
85 void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl);
Xing Jinaa218b22018-08-22 13:24:59 +080086 void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,
87 DIFFWTD_MASK_TYPE mask_type);
Ravi Chaudharyea665b02018-04-10 18:39:47 +053088 libaom_test::ACMRandom rnd_;
89}; // class BuildCompDiffwtdMaskD16Test
chiyotsai9dfac722020-07-07 17:43:02 -070090GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BuildCompDiffwtdMaskD16Test);
Ravi Chaudharyea665b02018-04-10 18:39:47 +053091
92void BuildCompDiffwtdMaskD16Test::RunCheckOutput(
93 buildcompdiffwtdmaskd16_func test_impl) {
94 const int block_idx = GET_PARAM(2);
95 const int bd = GET_PARAM(0);
96 const int width = block_size_wide[block_idx];
97 const int height = block_size_high[block_idx];
98 DECLARE_ALIGNED(16, uint8_t, mask_ref[2 * MAX_SB_SQUARE]);
99 DECLARE_ALIGNED(16, uint8_t, mask_test[2 * MAX_SB_SQUARE]);
100 DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]);
101 DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]);
102
James Zern664f04d2022-05-24 17:30:58 -0700103 ConvolveParams conv_params =
104 get_conv_params_no_round(0, 0, nullptr, 0, 1, bd);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530105
106 int in_precision =
107 bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
108
109 for (int i = 0; i < MAX_SB_SQUARE; i++) {
110 src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
111 src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
112 }
113
114 for (int mask_type = 0; mask_type < DIFFWTD_MASK_TYPES; mask_type++) {
115 av1_build_compound_diffwtd_mask_d16_c(
116 mask_ref, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
117 height, width, &conv_params, bd);
118
119 test_impl(mask_test, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
120 height, width, &conv_params, bd);
121
122 for (int r = 0; r < height; ++r) {
123 for (int c = 0; c < width; ++c) {
124 ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
125 << "Mismatch at unit tests for BuildCompDiffwtdMaskD16Test\n"
126 << " Pixel mismatch at index "
127 << "[" << r << "," << c << "] "
128 << " @ " << width << "x" << height << " inv " << mask_type;
129 }
130 }
131 }
132}
133
134void BuildCompDiffwtdMaskD16Test::RunSpeedTest(
Xing Jinaa218b22018-08-22 13:24:59 +0800135 buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) {
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530136 const int block_idx = GET_PARAM(2);
137 const int bd = GET_PARAM(0);
138 const int width = block_size_wide[block_idx];
139 const int height = block_size_high[block_idx];
140 DECLARE_ALIGNED(16, uint8_t, mask[MAX_SB_SQUARE]);
141 DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]);
142 DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]);
143
James Zern664f04d2022-05-24 17:30:58 -0700144 ConvolveParams conv_params =
145 get_conv_params_no_round(0, 0, nullptr, 0, 1, bd);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530146
147 int in_precision =
148 bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
149
150 for (int i = 0; i < MAX_SB_SQUARE; i++) {
151 src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
152 src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
153 }
154
Xing Jinaa218b22018-08-22 13:24:59 +0800155 const int num_loops = 10000000 / (width + height);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530156 aom_usec_timer timer;
157 aom_usec_timer_start(&timer);
158
159 for (int i = 0; i < num_loops; ++i)
Xing Jinaa218b22018-08-22 13:24:59 +0800160 av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1,
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530161 width, height, width, &conv_params,
162 bd);
163
164 aom_usec_timer_mark(&timer);
165 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530166
167 aom_usec_timer timer1;
168 aom_usec_timer_start(&timer1);
169
170 for (int i = 0; i < num_loops; ++i)
Xing Jinaa218b22018-08-22 13:24:59 +0800171 test_impl(mask, mask_type, src0, width, src1, width, height, width,
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530172 &conv_params, bd);
173
174 aom_usec_timer_mark(&timer1);
175 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
Xing Jinaa218b22018-08-22 13:24:59 +0800176 printf("av1_build_compound_diffwtd_mask_d16 %3dx%-3d: %7.2f \n", width,
177 height, elapsed_time / double(elapsed_time1));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530178}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530179#if HAVE_SSE4_1
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530180void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl,
181 const int is_speed,
Peng Bin640ea402018-03-30 14:12:53 +0800182 const DIFFWTD_MASK_TYPE type) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530183 const int sb_type = GET_PARAM(0);
Peng Bin640ea402018-03-30 14:12:53 +0800184 const int width = block_size_wide[sb_type];
185 const int height = block_size_high[sb_type];
186 DECLARE_ALIGNED(16, uint8_t, mask_ref[MAX_SB_SQUARE]);
187 DECLARE_ALIGNED(16, uint8_t, mask_test[MAX_SB_SQUARE]);
188 DECLARE_ALIGNED(16, uint8_t, src0[MAX_SB_SQUARE]);
189 DECLARE_ALIGNED(16, uint8_t, src1[MAX_SB_SQUARE]);
190 ACMRandom rnd(ACMRandom::DeterministicSeed());
191 for (int i = 0; i < width * height; i++) {
192 src0[i] = rnd.Rand8();
193 src1[i] = rnd.Rand8();
194 }
195 const int run_times = is_speed ? (10000000 / (width + height)) : 1;
196 aom_usec_timer timer;
197 aom_usec_timer_start(&timer);
198 for (int i = 0; i < run_times; ++i) {
199 av1_build_compound_diffwtd_mask_c(mask_ref, type, src0, width, src1, width,
200 height, width);
201 }
202 const double t1 = get_time_mark(&timer);
203 aom_usec_timer_start(&timer);
204 for (int i = 0; i < run_times; ++i) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530205 test_impl(mask_test, type, src0, width, src1, width, height, width);
Peng Bin640ea402018-03-30 14:12:53 +0800206 }
207 const double t2 = get_time_mark(&timer);
208 if (is_speed) {
209 printf("mask %d %3dx%-3d:%7.2f/%7.2fns", type, width, height, t1, t2);
210 printf("(%3.2f)\n", t1 / t2);
211 }
212 for (int r = 0; r < height; ++r) {
213 for (int c = 0; c < width; ++c) {
214 ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
215 << "[" << r << "," << c << "] " << run_times << " @ " << width << "x"
216 << height << " inv " << type;
217 }
218 }
219}
220
221TEST_P(BuildCompDiffwtdMaskTest, match) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530222 RunTest(GET_PARAM(1), 0, DIFFWTD_38);
223 RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV);
Peng Bin640ea402018-03-30 14:12:53 +0800224}
225TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530226 RunTest(GET_PARAM(1), 1, DIFFWTD_38);
227 RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV);
Peng Bin640ea402018-03-30 14:12:53 +0800228}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530229#endif
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530230TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) {
231 RunCheckOutput(GET_PARAM(1));
232}
233
234TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) {
Xing Jinaa218b22018-08-22 13:24:59 +0800235 RunSpeedTest(GET_PARAM(1), DIFFWTD_38);
236 RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530237}
238
239#if HAVE_SSE4_1
Cheng Chen96786fe2020-02-14 17:28:25 -0800240INSTANTIATE_TEST_SUITE_P(SSE4_1, BuildCompDiffwtdMaskTest,
241 BuildParams(av1_build_compound_diffwtd_mask_sse4_1));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530242
Cheng Chen96786fe2020-02-14 17:28:25 -0800243INSTANTIATE_TEST_SUITE_P(
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530244 SSE4_1, BuildCompDiffwtdMaskD16Test,
245 BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1));
246#endif
247
Xing Jinaa218b22018-08-22 13:24:59 +0800248#if HAVE_AVX2
Cheng Chen96786fe2020-02-14 17:28:25 -0800249INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskTest,
250 BuildParams(av1_build_compound_diffwtd_mask_avx2));
Xing Jinaa218b22018-08-22 13:24:59 +0800251
Cheng Chen96786fe2020-02-14 17:28:25 -0800252INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskD16Test,
253 BuildParams(av1_build_compound_diffwtd_mask_d16_avx2));
Xing Jinaa218b22018-08-22 13:24:59 +0800254#endif
255
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530256#if HAVE_NEON
Cheng Chen96786fe2020-02-14 17:28:25 -0800257INSTANTIATE_TEST_SUITE_P(NEON, BuildCompDiffwtdMaskD16Test,
258 BuildParams(av1_build_compound_diffwtd_mask_d16_neon));
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530259#endif
260
Peng Bin640ea402018-03-30 14:12:53 +0800261} // namespace