blob: 51bec0eab75705288fcf28d81da0432585fff70c [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"
24#include "test/clear_system_state.h"
25#include "test/register_state_check.h"
26#include "test/util.h"
27#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
28
29namespace {
30using libaom_test::ACMRandom;
31
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053032typedef void (*buildcompdiffwtdmaskd_func)(uint8_t *mask,
33 DIFFWTD_MASK_TYPE mask_type,
34 const uint8_t *src0, int src0_stride,
35 const uint8_t *src1, int src1_stride,
36 int h, int w);
37
sarahparkera543df52018-11-02 16:02:05 -070038typedef std::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func>
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053039 BuildCompDiffwtdMaskDParam;
40
41#if HAVE_SSE4_1
42::testing::internal::ParamGenerator<BuildCompDiffwtdMaskDParam> BuildParams(
43 buildcompdiffwtdmaskd_func filter) {
44 return ::testing::Combine(::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL),
45 ::testing::Values(filter));
46}
47#endif
48
49class BuildCompDiffwtdMaskTest
50 : public ::testing::TestWithParam<BuildCompDiffwtdMaskDParam> {
Peng Bin640ea402018-03-30 14:12:53 +080051 public:
52 virtual ~BuildCompDiffwtdMaskTest() {}
53
54 virtual void TearDown() { libaom_test::ClearSystemState(); }
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +053055 void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed,
Peng Bin640ea402018-03-30 14:12:53 +080056 const DIFFWTD_MASK_TYPE type);
57
58 private:
59 ACMRandom rnd_;
60};
61
Ravi Chaudharyea665b02018-04-10 18:39:47 +053062typedef void (*buildcompdiffwtdmaskd16_func)(
63 uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const CONV_BUF_TYPE *src0,
64 int src0_stride, const CONV_BUF_TYPE *src1, int src1_stride, int h, int w,
65 ConvolveParams *conv_params, int bd);
66
sarahparkera543df52018-11-02 16:02:05 -070067typedef std::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE>
Ravi Chaudharyea665b02018-04-10 18:39:47 +053068 BuildCompDiffwtdMaskD16Param;
69
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +053070#if HAVE_SSE4_1 || HAVE_NEON
Ravi Chaudharyea665b02018-04-10 18:39:47 +053071::testing::internal::ParamGenerator<BuildCompDiffwtdMaskD16Param> BuildParams(
72 buildcompdiffwtdmaskd16_func filter) {
73 return ::testing::Combine(::testing::Range(8, 13, 2),
74 ::testing::Values(filter),
75 ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL));
76}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +053077#endif
Ravi Chaudharyea665b02018-04-10 18:39:47 +053078class BuildCompDiffwtdMaskD16Test
79 : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> {
80 public:
81 ~BuildCompDiffwtdMaskD16Test() {}
82 virtual void TearDown() { libaom_test::ClearSystemState(); }
83 void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
84
85 protected:
86 void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl);
Xing Jinaa218b22018-08-22 13:24:59 +080087 void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,
88 DIFFWTD_MASK_TYPE mask_type);
Ravi Chaudharyea665b02018-04-10 18:39:47 +053089 libaom_test::ACMRandom rnd_;
90}; // class BuildCompDiffwtdMaskD16Test
91
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
Peng Binf7b11f52018-08-09 17:29:39 +0800103 ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530104
105 int in_precision =
106 bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
107
108 for (int i = 0; i < MAX_SB_SQUARE; i++) {
109 src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
110 src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
111 }
112
113 for (int mask_type = 0; mask_type < DIFFWTD_MASK_TYPES; mask_type++) {
114 av1_build_compound_diffwtd_mask_d16_c(
115 mask_ref, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
116 height, width, &conv_params, bd);
117
118 test_impl(mask_test, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
119 height, width, &conv_params, bd);
120
121 for (int r = 0; r < height; ++r) {
122 for (int c = 0; c < width; ++c) {
123 ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
124 << "Mismatch at unit tests for BuildCompDiffwtdMaskD16Test\n"
125 << " Pixel mismatch at index "
126 << "[" << r << "," << c << "] "
127 << " @ " << width << "x" << height << " inv " << mask_type;
128 }
129 }
130 }
131}
132
133void BuildCompDiffwtdMaskD16Test::RunSpeedTest(
Xing Jinaa218b22018-08-22 13:24:59 +0800134 buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) {
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530135 const int block_idx = GET_PARAM(2);
136 const int bd = GET_PARAM(0);
137 const int width = block_size_wide[block_idx];
138 const int height = block_size_high[block_idx];
139 DECLARE_ALIGNED(16, uint8_t, mask[MAX_SB_SQUARE]);
140 DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]);
141 DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]);
142
Peng Binf7b11f52018-08-09 17:29:39 +0800143 ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530144
145 int in_precision =
146 bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
147
148 for (int i = 0; i < MAX_SB_SQUARE; i++) {
149 src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
150 src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
151 }
152
Xing Jinaa218b22018-08-22 13:24:59 +0800153 const int num_loops = 10000000 / (width + height);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530154 aom_usec_timer timer;
155 aom_usec_timer_start(&timer);
156
157 for (int i = 0; i < num_loops; ++i)
Xing Jinaa218b22018-08-22 13:24:59 +0800158 av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1,
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530159 width, height, width, &conv_params,
160 bd);
161
162 aom_usec_timer_mark(&timer);
163 const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530164
165 aom_usec_timer timer1;
166 aom_usec_timer_start(&timer1);
167
168 for (int i = 0; i < num_loops; ++i)
Xing Jinaa218b22018-08-22 13:24:59 +0800169 test_impl(mask, mask_type, src0, width, src1, width, height, width,
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530170 &conv_params, bd);
171
172 aom_usec_timer_mark(&timer1);
173 const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
Xing Jinaa218b22018-08-22 13:24:59 +0800174 printf("av1_build_compound_diffwtd_mask_d16 %3dx%-3d: %7.2f \n", width,
175 height, elapsed_time / double(elapsed_time1));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530176}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530177#if HAVE_SSE4_1
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530178void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl,
179 const int is_speed,
Peng Bin640ea402018-03-30 14:12:53 +0800180 const DIFFWTD_MASK_TYPE type) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530181 const int sb_type = GET_PARAM(0);
Peng Bin640ea402018-03-30 14:12:53 +0800182 const int width = block_size_wide[sb_type];
183 const int height = block_size_high[sb_type];
184 DECLARE_ALIGNED(16, uint8_t, mask_ref[MAX_SB_SQUARE]);
185 DECLARE_ALIGNED(16, uint8_t, mask_test[MAX_SB_SQUARE]);
186 DECLARE_ALIGNED(16, uint8_t, src0[MAX_SB_SQUARE]);
187 DECLARE_ALIGNED(16, uint8_t, src1[MAX_SB_SQUARE]);
188 ACMRandom rnd(ACMRandom::DeterministicSeed());
189 for (int i = 0; i < width * height; i++) {
190 src0[i] = rnd.Rand8();
191 src1[i] = rnd.Rand8();
192 }
193 const int run_times = is_speed ? (10000000 / (width + height)) : 1;
194 aom_usec_timer timer;
195 aom_usec_timer_start(&timer);
196 for (int i = 0; i < run_times; ++i) {
197 av1_build_compound_diffwtd_mask_c(mask_ref, type, src0, width, src1, width,
198 height, width);
199 }
200 const double t1 = get_time_mark(&timer);
201 aom_usec_timer_start(&timer);
202 for (int i = 0; i < run_times; ++i) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530203 test_impl(mask_test, type, src0, width, src1, width, height, width);
Peng Bin640ea402018-03-30 14:12:53 +0800204 }
205 const double t2 = get_time_mark(&timer);
206 if (is_speed) {
207 printf("mask %d %3dx%-3d:%7.2f/%7.2fns", type, width, height, t1, t2);
208 printf("(%3.2f)\n", t1 / t2);
209 }
210 for (int r = 0; r < height; ++r) {
211 for (int c = 0; c < width; ++c) {
212 ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
213 << "[" << r << "," << c << "] " << run_times << " @ " << width << "x"
214 << height << " inv " << type;
215 }
216 }
217}
218
219TEST_P(BuildCompDiffwtdMaskTest, match) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530220 RunTest(GET_PARAM(1), 0, DIFFWTD_38);
221 RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV);
Peng Bin640ea402018-03-30 14:12:53 +0800222}
223TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) {
Sachin Kumar Garg5b7e5e22018-06-20 19:00:12 +0530224 RunTest(GET_PARAM(1), 1, DIFFWTD_38);
225 RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV);
Peng Bin640ea402018-03-30 14:12:53 +0800226}
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530227#endif
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530228TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) {
229 RunCheckOutput(GET_PARAM(1));
230}
231
232TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) {
Xing Jinaa218b22018-08-22 13:24:59 +0800233 RunSpeedTest(GET_PARAM(1), DIFFWTD_38);
234 RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV);
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530235}
236
237#if HAVE_SSE4_1
Cheng Chen96786fe2020-02-14 17:28:25 -0800238INSTANTIATE_TEST_SUITE_P(SSE4_1, BuildCompDiffwtdMaskTest,
239 BuildParams(av1_build_compound_diffwtd_mask_sse4_1));
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530240
Cheng Chen96786fe2020-02-14 17:28:25 -0800241INSTANTIATE_TEST_SUITE_P(
Ravi Chaudharyea665b02018-04-10 18:39:47 +0530242 SSE4_1, BuildCompDiffwtdMaskD16Test,
243 BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1));
244#endif
245
Xing Jinaa218b22018-08-22 13:24:59 +0800246#if HAVE_AVX2
Cheng Chen96786fe2020-02-14 17:28:25 -0800247INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskTest,
248 BuildParams(av1_build_compound_diffwtd_mask_avx2));
Xing Jinaa218b22018-08-22 13:24:59 +0800249
Cheng Chen96786fe2020-02-14 17:28:25 -0800250INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskD16Test,
251 BuildParams(av1_build_compound_diffwtd_mask_d16_avx2));
Xing Jinaa218b22018-08-22 13:24:59 +0800252#endif
253
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530254#if HAVE_NEON
Cheng Chen96786fe2020-02-14 17:28:25 -0800255INSTANTIATE_TEST_SUITE_P(NEON, BuildCompDiffwtdMaskD16Test,
256 BuildParams(av1_build_compound_diffwtd_mask_d16_neon));
Sachin Kumar Gargd78396e2018-06-21 11:46:30 +0530257#endif
258
Peng Bin640ea402018-03-30 14:12:53 +0800259} // namespace