• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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>
15 
16 #include "config/aom_config.h"
17 #include "config/av1_rtcd.h"
18 
19 #include "aom_ports/mem.h"
20 #include "av1/common/scan.h"
21 #include "av1/common/txb_common.h"
22 #include "test/acm_random.h"
23 #include "test/clear_system_state.h"
24 #include "test/register_state_check.h"
25 #include "test/util.h"
26 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
27 
28 namespace {
29 using libaom_test::ACMRandom;
30 
31 typedef 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 
37 typedef ::testing::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func>
38     BuildCompDiffwtdMaskDParam;
39 
40 #if HAVE_SSE4_1
BuildParams(buildcompdiffwtdmaskd_func filter)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 
48 class BuildCompDiffwtdMaskTest
49     : public ::testing::TestWithParam<BuildCompDiffwtdMaskDParam> {
50  public:
~BuildCompDiffwtdMaskTest()51   virtual ~BuildCompDiffwtdMaskTest() {}
52 
TearDown()53   virtual void TearDown() { libaom_test::ClearSystemState(); }
54   void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed,
55                const DIFFWTD_MASK_TYPE type);
56 
57  private:
58   ACMRandom rnd_;
59 };
60 
61 typedef 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 
66 typedef ::testing::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE>
67     BuildCompDiffwtdMaskD16Param;
68 
69 #if HAVE_SSE4_1 || HAVE_NEON
BuildParams(buildcompdiffwtdmaskd16_func filter)70 ::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 }
76 #endif
77 class BuildCompDiffwtdMaskD16Test
78     : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> {
79  public:
~BuildCompDiffwtdMaskD16Test()80   ~BuildCompDiffwtdMaskD16Test() {}
TearDown()81   virtual void TearDown() { libaom_test::ClearSystemState(); }
SetUp()82   void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); }
83 
84  protected:
85   void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl);
86   void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,
87                     DIFFWTD_MASK_TYPE mask_type);
88   libaom_test::ACMRandom rnd_;
89 };  // class BuildCompDiffwtdMaskD16Test
90 
RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl)91 void BuildCompDiffwtdMaskD16Test::RunCheckOutput(
92     buildcompdiffwtdmaskd16_func test_impl) {
93   const int block_idx = GET_PARAM(2);
94   const int bd = GET_PARAM(0);
95   const int width = block_size_wide[block_idx];
96   const int height = block_size_high[block_idx];
97   DECLARE_ALIGNED(16, uint8_t, mask_ref[2 * MAX_SB_SQUARE]);
98   DECLARE_ALIGNED(16, uint8_t, mask_test[2 * MAX_SB_SQUARE]);
99   DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]);
100   DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]);
101 
102   ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
103 
104   int in_precision =
105       bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
106 
107   for (int i = 0; i < MAX_SB_SQUARE; i++) {
108     src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
109     src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
110   }
111 
112   for (int mask_type = 0; mask_type < DIFFWTD_MASK_TYPES; mask_type++) {
113     av1_build_compound_diffwtd_mask_d16_c(
114         mask_ref, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
115         height, width, &conv_params, bd);
116 
117     test_impl(mask_test, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width,
118               height, width, &conv_params, bd);
119 
120     for (int r = 0; r < height; ++r) {
121       for (int c = 0; c < width; ++c) {
122         ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
123             << "Mismatch at unit tests for BuildCompDiffwtdMaskD16Test\n"
124             << " Pixel mismatch at index "
125             << "[" << r << "," << c << "] "
126             << " @ " << width << "x" << height << " inv " << mask_type;
127       }
128     }
129   }
130 }
131 
RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl,DIFFWTD_MASK_TYPE mask_type)132 void BuildCompDiffwtdMaskD16Test::RunSpeedTest(
133     buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) {
134   const int block_idx = GET_PARAM(2);
135   const int bd = GET_PARAM(0);
136   const int width = block_size_wide[block_idx];
137   const int height = block_size_high[block_idx];
138   DECLARE_ALIGNED(16, uint8_t, mask[MAX_SB_SQUARE]);
139   DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]);
140   DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]);
141 
142   ConvolveParams conv_params = get_conv_params_no_round(0, 0, NULL, 0, 1, bd);
143 
144   int in_precision =
145       bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2;
146 
147   for (int i = 0; i < MAX_SB_SQUARE; i++) {
148     src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
149     src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1);
150   }
151 
152   const int num_loops = 10000000 / (width + height);
153   aom_usec_timer timer;
154   aom_usec_timer_start(&timer);
155 
156   for (int i = 0; i < num_loops; ++i)
157     av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1,
158                                           width, height, width, &conv_params,
159                                           bd);
160 
161   aom_usec_timer_mark(&timer);
162   const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer));
163 
164   aom_usec_timer timer1;
165   aom_usec_timer_start(&timer1);
166 
167   for (int i = 0; i < num_loops; ++i)
168     test_impl(mask, mask_type, src0, width, src1, width, height, width,
169               &conv_params, bd);
170 
171   aom_usec_timer_mark(&timer1);
172   const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1));
173   printf("av1_build_compound_diffwtd_mask_d16  %3dx%-3d: %7.2f \n", width,
174          height, elapsed_time / double(elapsed_time1));
175 }
176 #if HAVE_SSE4_1
RunTest(buildcompdiffwtdmaskd_func test_impl,const int is_speed,const DIFFWTD_MASK_TYPE type)177 void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl,
178                                        const int is_speed,
179                                        const DIFFWTD_MASK_TYPE type) {
180   const int sb_type = GET_PARAM(0);
181   const int width = block_size_wide[sb_type];
182   const int height = block_size_high[sb_type];
183   DECLARE_ALIGNED(16, uint8_t, mask_ref[MAX_SB_SQUARE]);
184   DECLARE_ALIGNED(16, uint8_t, mask_test[MAX_SB_SQUARE]);
185   DECLARE_ALIGNED(16, uint8_t, src0[MAX_SB_SQUARE]);
186   DECLARE_ALIGNED(16, uint8_t, src1[MAX_SB_SQUARE]);
187   ACMRandom rnd(ACMRandom::DeterministicSeed());
188   for (int i = 0; i < width * height; i++) {
189     src0[i] = rnd.Rand8();
190     src1[i] = rnd.Rand8();
191   }
192   const int run_times = is_speed ? (10000000 / (width + height)) : 1;
193   aom_usec_timer timer;
194   aom_usec_timer_start(&timer);
195   for (int i = 0; i < run_times; ++i) {
196     av1_build_compound_diffwtd_mask_c(mask_ref, type, src0, width, src1, width,
197                                       height, width);
198   }
199   const double t1 = get_time_mark(&timer);
200   aom_usec_timer_start(&timer);
201   for (int i = 0; i < run_times; ++i) {
202     test_impl(mask_test, type, src0, width, src1, width, height, width);
203   }
204   const double t2 = get_time_mark(&timer);
205   if (is_speed) {
206     printf("mask %d %3dx%-3d:%7.2f/%7.2fns", type, width, height, t1, t2);
207     printf("(%3.2f)\n", t1 / t2);
208   }
209   for (int r = 0; r < height; ++r) {
210     for (int c = 0; c < width; ++c) {
211       ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width])
212           << "[" << r << "," << c << "] " << run_times << " @ " << width << "x"
213           << height << " inv " << type;
214     }
215   }
216 }
217 
TEST_P(BuildCompDiffwtdMaskTest,match)218 TEST_P(BuildCompDiffwtdMaskTest, match) {
219   RunTest(GET_PARAM(1), 0, DIFFWTD_38);
220   RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV);
221 }
TEST_P(BuildCompDiffwtdMaskTest,DISABLED_Speed)222 TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) {
223   RunTest(GET_PARAM(1), 1, DIFFWTD_38);
224   RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV);
225 }
226 #endif
TEST_P(BuildCompDiffwtdMaskD16Test,CheckOutput)227 TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) {
228   RunCheckOutput(GET_PARAM(1));
229 }
230 
TEST_P(BuildCompDiffwtdMaskD16Test,DISABLED_Speed)231 TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) {
232   RunSpeedTest(GET_PARAM(1), DIFFWTD_38);
233   RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV);
234 }
235 
236 #if HAVE_SSE4_1
237 INSTANTIATE_TEST_CASE_P(SSE4_1, BuildCompDiffwtdMaskTest,
238                         BuildParams(av1_build_compound_diffwtd_mask_sse4_1));
239 
240 INSTANTIATE_TEST_CASE_P(
241     SSE4_1, BuildCompDiffwtdMaskD16Test,
242     BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1));
243 #endif
244 
245 #if HAVE_AVX2
246 INSTANTIATE_TEST_CASE_P(AVX2, BuildCompDiffwtdMaskTest,
247                         BuildParams(av1_build_compound_diffwtd_mask_avx2));
248 
249 INSTANTIATE_TEST_CASE_P(AVX2, BuildCompDiffwtdMaskD16Test,
250                         BuildParams(av1_build_compound_diffwtd_mask_d16_avx2));
251 #endif
252 
253 #if HAVE_NEON
254 INSTANTIATE_TEST_CASE_P(NEON, BuildCompDiffwtdMaskD16Test,
255                         BuildParams(av1_build_compound_diffwtd_mask_d16_neon));
256 #endif
257 
258 }  // namespace
259