2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
14 #include "test/function_equivalence_test.h"
15 #include "test/register_state_check.h"
17 #include "config/aom_config.h"
18 #include "config/aom_dsp_rtcd.h"
20 #include "aom/aom_integer.h"
22 #define MAX_SB_SQUARE (MAX_SB_SIZE * MAX_SB_SIZE)
24 using libaom_test::FunctionEquivalenceTest
;
28 static const int kIterations
= 1000;
29 static const int kMaskMax
= 64;
31 typedef unsigned int (*ObmcSadF
)(const uint8_t *pre
, int pre_stride
,
32 const int32_t *wsrc
, const int32_t *mask
);
33 typedef libaom_test::FuncParam
<ObmcSadF
> TestFuncs
;
35 ////////////////////////////////////////////////////////////////////////////////
37 ////////////////////////////////////////////////////////////////////////////////
39 class ObmcSadTest
: public FunctionEquivalenceTest
<ObmcSadF
> {};
40 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObmcSadTest
);
42 TEST_P(ObmcSadTest
, RandomValues
) {
43 DECLARE_ALIGNED(32, uint8_t, pre
[MAX_SB_SQUARE
]);
44 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
45 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
47 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
48 const int pre_stride
= rng_(MAX_SB_SIZE
+ 1);
50 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
51 pre
[i
] = rng_
.Rand8();
52 wsrc
[i
] = rng_
.Rand8() * rng_(kMaskMax
* kMaskMax
+ 1);
53 mask
[i
] = rng_(kMaskMax
* kMaskMax
+ 1);
56 const unsigned int ref_res
= params_
.ref_func(pre
, pre_stride
, wsrc
, mask
);
58 API_REGISTER_STATE_CHECK(tst_res
=
59 params_
.tst_func(pre
, pre_stride
, wsrc
, mask
));
61 ASSERT_EQ(ref_res
, tst_res
);
65 TEST_P(ObmcSadTest
, ExtremeValues
) {
66 DECLARE_ALIGNED(32, uint8_t, pre
[MAX_SB_SQUARE
]);
67 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
68 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
70 for (int iter
= 0; iter
< MAX_SB_SIZE
&& !HasFatalFailure(); ++iter
) {
71 const int pre_stride
= iter
;
73 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
75 wsrc
[i
] = UINT8_MAX
* kMaskMax
* kMaskMax
;
76 mask
[i
] = kMaskMax
* kMaskMax
;
79 const unsigned int ref_res
= params_
.ref_func(pre
, pre_stride
, wsrc
, mask
);
81 API_REGISTER_STATE_CHECK(tst_res
=
82 params_
.tst_func(pre
, pre_stride
, wsrc
, mask
));
84 ASSERT_EQ(ref_res
, tst_res
);
89 const ObmcSadTest::ParamType sse4_functions
[] = {
90 TestFuncs(aom_obmc_sad128x128_c
, aom_obmc_sad128x128_sse4_1
),
91 TestFuncs(aom_obmc_sad128x64_c
, aom_obmc_sad128x64_sse4_1
),
92 TestFuncs(aom_obmc_sad64x128_c
, aom_obmc_sad64x128_sse4_1
),
93 TestFuncs(aom_obmc_sad64x64_c
, aom_obmc_sad64x64_sse4_1
),
94 TestFuncs(aom_obmc_sad64x32_c
, aom_obmc_sad64x32_sse4_1
),
95 TestFuncs(aom_obmc_sad32x64_c
, aom_obmc_sad32x64_sse4_1
),
96 TestFuncs(aom_obmc_sad32x32_c
, aom_obmc_sad32x32_sse4_1
),
97 TestFuncs(aom_obmc_sad32x16_c
, aom_obmc_sad32x16_sse4_1
),
98 TestFuncs(aom_obmc_sad16x32_c
, aom_obmc_sad16x32_sse4_1
),
99 TestFuncs(aom_obmc_sad16x16_c
, aom_obmc_sad16x16_sse4_1
),
100 TestFuncs(aom_obmc_sad16x8_c
, aom_obmc_sad16x8_sse4_1
),
101 TestFuncs(aom_obmc_sad8x16_c
, aom_obmc_sad8x16_sse4_1
),
102 TestFuncs(aom_obmc_sad8x8_c
, aom_obmc_sad8x8_sse4_1
),
103 TestFuncs(aom_obmc_sad8x4_c
, aom_obmc_sad8x4_sse4_1
),
104 TestFuncs(aom_obmc_sad4x8_c
, aom_obmc_sad4x8_sse4_1
),
105 TestFuncs(aom_obmc_sad4x4_c
, aom_obmc_sad4x4_sse4_1
),
107 TestFuncs(aom_obmc_sad64x16_c
, aom_obmc_sad64x16_sse4_1
),
108 TestFuncs(aom_obmc_sad16x64_c
, aom_obmc_sad16x64_sse4_1
),
109 TestFuncs(aom_obmc_sad32x8_c
, aom_obmc_sad32x8_sse4_1
),
110 TestFuncs(aom_obmc_sad8x32_c
, aom_obmc_sad8x32_sse4_1
),
111 TestFuncs(aom_obmc_sad16x4_c
, aom_obmc_sad16x4_sse4_1
),
112 TestFuncs(aom_obmc_sad4x16_c
, aom_obmc_sad4x16_sse4_1
),
115 INSTANTIATE_TEST_SUITE_P(SSE4_1
, ObmcSadTest
,
116 ::testing::ValuesIn(sse4_functions
));
117 #endif // HAVE_SSE4_1
120 const ObmcSadTest::ParamType avx2_functions
[] = {
121 TestFuncs(aom_obmc_sad128x128_c
, aom_obmc_sad128x128_avx2
),
122 TestFuncs(aom_obmc_sad128x64_c
, aom_obmc_sad128x64_avx2
),
123 TestFuncs(aom_obmc_sad64x128_c
, aom_obmc_sad64x128_avx2
),
124 TestFuncs(aom_obmc_sad64x64_c
, aom_obmc_sad64x64_avx2
),
125 TestFuncs(aom_obmc_sad64x32_c
, aom_obmc_sad64x32_avx2
),
126 TestFuncs(aom_obmc_sad32x64_c
, aom_obmc_sad32x64_avx2
),
127 TestFuncs(aom_obmc_sad32x32_c
, aom_obmc_sad32x32_avx2
),
128 TestFuncs(aom_obmc_sad32x16_c
, aom_obmc_sad32x16_avx2
),
129 TestFuncs(aom_obmc_sad16x32_c
, aom_obmc_sad16x32_avx2
),
130 TestFuncs(aom_obmc_sad16x16_c
, aom_obmc_sad16x16_avx2
),
131 TestFuncs(aom_obmc_sad16x8_c
, aom_obmc_sad16x8_avx2
),
132 TestFuncs(aom_obmc_sad8x16_c
, aom_obmc_sad8x16_avx2
),
133 TestFuncs(aom_obmc_sad8x8_c
, aom_obmc_sad8x8_avx2
),
134 TestFuncs(aom_obmc_sad8x4_c
, aom_obmc_sad8x4_avx2
),
135 TestFuncs(aom_obmc_sad4x8_c
, aom_obmc_sad4x8_avx2
),
136 TestFuncs(aom_obmc_sad4x4_c
, aom_obmc_sad4x4_avx2
),
138 TestFuncs(aom_obmc_sad64x16_c
, aom_obmc_sad64x16_avx2
),
139 TestFuncs(aom_obmc_sad16x64_c
, aom_obmc_sad16x64_avx2
),
140 TestFuncs(aom_obmc_sad32x8_c
, aom_obmc_sad32x8_avx2
),
141 TestFuncs(aom_obmc_sad8x32_c
, aom_obmc_sad8x32_avx2
),
142 TestFuncs(aom_obmc_sad16x4_c
, aom_obmc_sad16x4_avx2
),
143 TestFuncs(aom_obmc_sad4x16_c
, aom_obmc_sad4x16_avx2
),
146 INSTANTIATE_TEST_SUITE_P(AVX2
, ObmcSadTest
,
147 ::testing::ValuesIn(avx2_functions
));
150 #if CONFIG_AV1_HIGHBITDEPTH
151 ////////////////////////////////////////////////////////////////////////////////
153 ////////////////////////////////////////////////////////////////////////////////
155 class ObmcSadHBDTest
: public FunctionEquivalenceTest
<ObmcSadF
> {};
156 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObmcSadHBDTest
);
158 TEST_P(ObmcSadHBDTest
, RandomValues
) {
159 DECLARE_ALIGNED(32, uint16_t, pre
[MAX_SB_SQUARE
]);
160 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
161 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
163 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
164 const int pre_stride
= rng_(MAX_SB_SIZE
+ 1);
166 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
167 pre
[i
] = rng_(1 << 12);
168 wsrc
[i
] = rng_(1 << 12) * rng_(kMaskMax
* kMaskMax
+ 1);
169 mask
[i
] = rng_(kMaskMax
* kMaskMax
+ 1);
172 const unsigned int ref_res
=
173 params_
.ref_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
);
174 unsigned int tst_res
;
175 API_REGISTER_STATE_CHECK(
177 params_
.tst_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
));
179 ASSERT_EQ(ref_res
, tst_res
);
183 TEST_P(ObmcSadHBDTest
, ExtremeValues
) {
184 DECLARE_ALIGNED(32, uint16_t, pre
[MAX_SB_SQUARE
]);
185 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
186 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
188 for (int iter
= 0; iter
< MAX_SB_SIZE
&& !HasFatalFailure(); ++iter
) {
189 const int pre_stride
= iter
;
191 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
192 pre
[i
] = (1 << 12) - 1;
193 wsrc
[i
] = ((1 << 12) - 1) * kMaskMax
* kMaskMax
;
194 mask
[i
] = kMaskMax
* kMaskMax
;
197 const unsigned int ref_res
=
198 params_
.ref_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
);
199 unsigned int tst_res
;
200 API_REGISTER_STATE_CHECK(
202 params_
.tst_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
));
204 ASSERT_EQ(ref_res
, tst_res
);
209 ObmcSadHBDTest::ParamType sse4_functions_hbd
[] = {
210 TestFuncs(aom_highbd_obmc_sad128x128_c
, aom_highbd_obmc_sad128x128_sse4_1
),
211 TestFuncs(aom_highbd_obmc_sad128x64_c
, aom_highbd_obmc_sad128x64_sse4_1
),
212 TestFuncs(aom_highbd_obmc_sad64x128_c
, aom_highbd_obmc_sad64x128_sse4_1
),
213 TestFuncs(aom_highbd_obmc_sad64x64_c
, aom_highbd_obmc_sad64x64_sse4_1
),
214 TestFuncs(aom_highbd_obmc_sad64x32_c
, aom_highbd_obmc_sad64x32_sse4_1
),
215 TestFuncs(aom_highbd_obmc_sad32x64_c
, aom_highbd_obmc_sad32x64_sse4_1
),
216 TestFuncs(aom_highbd_obmc_sad32x32_c
, aom_highbd_obmc_sad32x32_sse4_1
),
217 TestFuncs(aom_highbd_obmc_sad32x16_c
, aom_highbd_obmc_sad32x16_sse4_1
),
218 TestFuncs(aom_highbd_obmc_sad16x32_c
, aom_highbd_obmc_sad16x32_sse4_1
),
219 TestFuncs(aom_highbd_obmc_sad16x16_c
, aom_highbd_obmc_sad16x16_sse4_1
),
220 TestFuncs(aom_highbd_obmc_sad16x8_c
, aom_highbd_obmc_sad16x8_sse4_1
),
221 TestFuncs(aom_highbd_obmc_sad8x16_c
, aom_highbd_obmc_sad8x16_sse4_1
),
222 TestFuncs(aom_highbd_obmc_sad8x8_c
, aom_highbd_obmc_sad8x8_sse4_1
),
223 TestFuncs(aom_highbd_obmc_sad8x4_c
, aom_highbd_obmc_sad8x4_sse4_1
),
224 TestFuncs(aom_highbd_obmc_sad4x8_c
, aom_highbd_obmc_sad4x8_sse4_1
),
225 TestFuncs(aom_highbd_obmc_sad4x4_c
, aom_highbd_obmc_sad4x4_sse4_1
),
227 TestFuncs(aom_highbd_obmc_sad64x16_c
, aom_highbd_obmc_sad64x16_sse4_1
),
228 TestFuncs(aom_highbd_obmc_sad16x64_c
, aom_highbd_obmc_sad16x64_sse4_1
),
229 TestFuncs(aom_highbd_obmc_sad32x8_c
, aom_highbd_obmc_sad32x8_sse4_1
),
230 TestFuncs(aom_highbd_obmc_sad8x32_c
, aom_highbd_obmc_sad8x32_sse4_1
),
231 TestFuncs(aom_highbd_obmc_sad16x4_c
, aom_highbd_obmc_sad16x4_sse4_1
),
232 TestFuncs(aom_highbd_obmc_sad4x16_c
, aom_highbd_obmc_sad4x16_sse4_1
),
235 INSTANTIATE_TEST_SUITE_P(SSE4_1
, ObmcSadHBDTest
,
236 ::testing::ValuesIn(sse4_functions_hbd
));
237 #endif // HAVE_SSE4_1
240 ObmcSadHBDTest::ParamType avx2_functions_hbd
[] = {
241 TestFuncs(aom_highbd_obmc_sad128x128_c
, aom_highbd_obmc_sad128x128_avx2
),
242 TestFuncs(aom_highbd_obmc_sad128x64_c
, aom_highbd_obmc_sad128x64_avx2
),
243 TestFuncs(aom_highbd_obmc_sad64x128_c
, aom_highbd_obmc_sad64x128_avx2
),
244 TestFuncs(aom_highbd_obmc_sad64x64_c
, aom_highbd_obmc_sad64x64_avx2
),
245 TestFuncs(aom_highbd_obmc_sad64x32_c
, aom_highbd_obmc_sad64x32_avx2
),
246 TestFuncs(aom_highbd_obmc_sad32x64_c
, aom_highbd_obmc_sad32x64_avx2
),
247 TestFuncs(aom_highbd_obmc_sad32x32_c
, aom_highbd_obmc_sad32x32_avx2
),
248 TestFuncs(aom_highbd_obmc_sad32x16_c
, aom_highbd_obmc_sad32x16_avx2
),
249 TestFuncs(aom_highbd_obmc_sad16x32_c
, aom_highbd_obmc_sad16x32_avx2
),
250 TestFuncs(aom_highbd_obmc_sad16x16_c
, aom_highbd_obmc_sad16x16_avx2
),
251 TestFuncs(aom_highbd_obmc_sad16x8_c
, aom_highbd_obmc_sad16x8_avx2
),
252 TestFuncs(aom_highbd_obmc_sad8x16_c
, aom_highbd_obmc_sad8x16_avx2
),
253 TestFuncs(aom_highbd_obmc_sad8x8_c
, aom_highbd_obmc_sad8x8_avx2
),
254 TestFuncs(aom_highbd_obmc_sad8x4_c
, aom_highbd_obmc_sad8x4_avx2
),
255 TestFuncs(aom_highbd_obmc_sad4x8_c
, aom_highbd_obmc_sad4x8_avx2
),
256 TestFuncs(aom_highbd_obmc_sad4x4_c
, aom_highbd_obmc_sad4x4_avx2
),
258 TestFuncs(aom_highbd_obmc_sad64x16_c
, aom_highbd_obmc_sad64x16_avx2
),
259 TestFuncs(aom_highbd_obmc_sad16x64_c
, aom_highbd_obmc_sad16x64_avx2
),
260 TestFuncs(aom_highbd_obmc_sad32x8_c
, aom_highbd_obmc_sad32x8_avx2
),
261 TestFuncs(aom_highbd_obmc_sad8x32_c
, aom_highbd_obmc_sad8x32_avx2
),
262 TestFuncs(aom_highbd_obmc_sad16x4_c
, aom_highbd_obmc_sad16x4_avx2
),
263 TestFuncs(aom_highbd_obmc_sad4x16_c
, aom_highbd_obmc_sad4x16_avx2
),
266 INSTANTIATE_TEST_SUITE_P(AVX2
, ObmcSadHBDTest
,
267 ::testing::ValuesIn(avx2_functions_hbd
));
269 #endif // CONFIG_AV1_HIGHBITDEPTH