1 /*
2 * Copyright (c) 2016, 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 "gtest/gtest.h"
13
14 #include "test/function_equivalence_test.h"
15 #include "test/register_state_check.h"
16
17 #include "config/aom_config.h"
18 #include "config/aom_dsp_rtcd.h"
19
20 #include "aom/aom_integer.h"
21
22 #define MAX_SB_SQUARE (MAX_SB_SIZE * MAX_SB_SIZE)
23
24 using libaom_test::FunctionEquivalenceTest;
25
26 namespace {
27
28 static const int kIterations = 1000;
29 static const int kMaskMax = 64;
30
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;
34
35 ////////////////////////////////////////////////////////////////////////////////
36 // 8 bit
37 ////////////////////////////////////////////////////////////////////////////////
38
39 class ObmcSadTest : public FunctionEquivalenceTest<ObmcSadF> {};
40 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObmcSadTest);
41
TEST_P(ObmcSadTest,RandomValues)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]);
46
47 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
48 const int pre_stride = rng_(MAX_SB_SIZE + 1);
49
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);
54 }
55
56 const unsigned int ref_res = params_.ref_func(pre, pre_stride, wsrc, mask);
57 unsigned int tst_res;
58 API_REGISTER_STATE_CHECK(tst_res =
59 params_.tst_func(pre, pre_stride, wsrc, mask));
60
61 ASSERT_EQ(ref_res, tst_res);
62 }
63 }
64
TEST_P(ObmcSadTest,ExtremeValues)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]);
69
70 for (int iter = 0; iter < MAX_SB_SIZE && !HasFatalFailure(); ++iter) {
71 const int pre_stride = iter;
72
73 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
74 pre[i] = UINT8_MAX;
75 wsrc[i] = UINT8_MAX * kMaskMax * kMaskMax;
76 mask[i] = kMaskMax * kMaskMax;
77 }
78
79 const unsigned int ref_res = params_.ref_func(pre, pre_stride, wsrc, mask);
80 unsigned int tst_res;
81 API_REGISTER_STATE_CHECK(tst_res =
82 params_.tst_func(pre, pre_stride, wsrc, mask));
83
84 ASSERT_EQ(ref_res, tst_res);
85 }
86 }
87
88 #if HAVE_SSE4_1
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),
106
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),
113 };
114
115 INSTANTIATE_TEST_SUITE_P(SSE4_1, ObmcSadTest,
116 ::testing::ValuesIn(sse4_functions));
117 #endif // HAVE_SSE4_1
118
119 #if HAVE_AVX2
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),
137
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),
144 };
145
146 INSTANTIATE_TEST_SUITE_P(AVX2, ObmcSadTest,
147 ::testing::ValuesIn(avx2_functions));
148 #endif // HAVE_AVX2
149
150 #if HAVE_NEON
151 const ObmcSadTest::ParamType neon_functions[] = {
152 TestFuncs(aom_obmc_sad128x128_c, aom_obmc_sad128x128_neon),
153 TestFuncs(aom_obmc_sad128x64_c, aom_obmc_sad128x64_neon),
154 TestFuncs(aom_obmc_sad64x128_c, aom_obmc_sad64x128_neon),
155 TestFuncs(aom_obmc_sad64x64_c, aom_obmc_sad64x64_neon),
156 TestFuncs(aom_obmc_sad64x32_c, aom_obmc_sad64x32_neon),
157 TestFuncs(aom_obmc_sad32x64_c, aom_obmc_sad32x64_neon),
158 TestFuncs(aom_obmc_sad32x32_c, aom_obmc_sad32x32_neon),
159 TestFuncs(aom_obmc_sad32x16_c, aom_obmc_sad32x16_neon),
160 TestFuncs(aom_obmc_sad16x32_c, aom_obmc_sad16x32_neon),
161 TestFuncs(aom_obmc_sad16x16_c, aom_obmc_sad16x16_neon),
162 TestFuncs(aom_obmc_sad16x8_c, aom_obmc_sad16x8_neon),
163 TestFuncs(aom_obmc_sad8x16_c, aom_obmc_sad8x16_neon),
164 TestFuncs(aom_obmc_sad8x8_c, aom_obmc_sad8x8_neon),
165 TestFuncs(aom_obmc_sad8x4_c, aom_obmc_sad8x4_neon),
166 TestFuncs(aom_obmc_sad4x8_c, aom_obmc_sad4x8_neon),
167 TestFuncs(aom_obmc_sad4x4_c, aom_obmc_sad4x4_neon),
168
169 TestFuncs(aom_obmc_sad64x16_c, aom_obmc_sad64x16_neon),
170 TestFuncs(aom_obmc_sad16x64_c, aom_obmc_sad16x64_neon),
171 TestFuncs(aom_obmc_sad32x8_c, aom_obmc_sad32x8_neon),
172 TestFuncs(aom_obmc_sad8x32_c, aom_obmc_sad8x32_neon),
173 TestFuncs(aom_obmc_sad16x4_c, aom_obmc_sad16x4_neon),
174 TestFuncs(aom_obmc_sad4x16_c, aom_obmc_sad4x16_neon),
175 };
176
177 INSTANTIATE_TEST_SUITE_P(NEON, ObmcSadTest,
178 ::testing::ValuesIn(neon_functions));
179 #endif // HAVE_NEON
180
181 #if CONFIG_AV1_HIGHBITDEPTH
182 ////////////////////////////////////////////////////////////////////////////////
183 // High bit-depth
184 ////////////////////////////////////////////////////////////////////////////////
185
186 class ObmcSadHBDTest : public FunctionEquivalenceTest<ObmcSadF> {};
187 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ObmcSadHBDTest);
188
TEST_P(ObmcSadHBDTest,RandomValues)189 TEST_P(ObmcSadHBDTest, RandomValues) {
190 DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
191 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
192 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
193
194 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
195 const int pre_stride = rng_(MAX_SB_SIZE + 1);
196
197 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
198 pre[i] = rng_(1 << 12);
199 wsrc[i] = rng_(1 << 12) * rng_(kMaskMax * kMaskMax + 1);
200 mask[i] = rng_(kMaskMax * kMaskMax + 1);
201 }
202
203 const unsigned int ref_res =
204 params_.ref_func(CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask);
205 unsigned int tst_res;
206 API_REGISTER_STATE_CHECK(
207 tst_res =
208 params_.tst_func(CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask));
209
210 ASSERT_EQ(ref_res, tst_res);
211 }
212 }
213
TEST_P(ObmcSadHBDTest,ExtremeValues)214 TEST_P(ObmcSadHBDTest, ExtremeValues) {
215 DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
216 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
217 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
218
219 for (int iter = 0; iter < MAX_SB_SIZE && !HasFatalFailure(); ++iter) {
220 const int pre_stride = iter;
221
222 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
223 pre[i] = (1 << 12) - 1;
224 wsrc[i] = ((1 << 12) - 1) * kMaskMax * kMaskMax;
225 mask[i] = kMaskMax * kMaskMax;
226 }
227
228 const unsigned int ref_res =
229 params_.ref_func(CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask);
230 unsigned int tst_res;
231 API_REGISTER_STATE_CHECK(
232 tst_res =
233 params_.tst_func(CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask));
234
235 ASSERT_EQ(ref_res, tst_res);
236 }
237 }
238
239 #if HAVE_NEON
240 ObmcSadHBDTest::ParamType neon_functions_hbd[] = {
241 TestFuncs(aom_highbd_obmc_sad128x128_c, aom_highbd_obmc_sad128x128_neon),
242 TestFuncs(aom_highbd_obmc_sad128x64_c, aom_highbd_obmc_sad128x64_neon),
243 TestFuncs(aom_highbd_obmc_sad64x128_c, aom_highbd_obmc_sad64x128_neon),
244 TestFuncs(aom_highbd_obmc_sad64x64_c, aom_highbd_obmc_sad64x64_neon),
245 TestFuncs(aom_highbd_obmc_sad64x32_c, aom_highbd_obmc_sad64x32_neon),
246 TestFuncs(aom_highbd_obmc_sad32x64_c, aom_highbd_obmc_sad32x64_neon),
247 TestFuncs(aom_highbd_obmc_sad32x32_c, aom_highbd_obmc_sad32x32_neon),
248 TestFuncs(aom_highbd_obmc_sad32x16_c, aom_highbd_obmc_sad32x16_neon),
249 TestFuncs(aom_highbd_obmc_sad16x32_c, aom_highbd_obmc_sad16x32_neon),
250 TestFuncs(aom_highbd_obmc_sad16x16_c, aom_highbd_obmc_sad16x16_neon),
251 TestFuncs(aom_highbd_obmc_sad16x8_c, aom_highbd_obmc_sad16x8_neon),
252 TestFuncs(aom_highbd_obmc_sad8x16_c, aom_highbd_obmc_sad8x16_neon),
253 TestFuncs(aom_highbd_obmc_sad8x8_c, aom_highbd_obmc_sad8x8_neon),
254 TestFuncs(aom_highbd_obmc_sad8x4_c, aom_highbd_obmc_sad8x4_neon),
255 TestFuncs(aom_highbd_obmc_sad4x8_c, aom_highbd_obmc_sad4x8_neon),
256 TestFuncs(aom_highbd_obmc_sad4x4_c, aom_highbd_obmc_sad4x4_neon),
257 #if !CONFIG_REALTIME_ONLY
258 TestFuncs(aom_highbd_obmc_sad64x16_c, aom_highbd_obmc_sad64x16_neon),
259 TestFuncs(aom_highbd_obmc_sad16x64_c, aom_highbd_obmc_sad16x64_neon),
260 TestFuncs(aom_highbd_obmc_sad32x8_c, aom_highbd_obmc_sad32x8_neon),
261 TestFuncs(aom_highbd_obmc_sad8x32_c, aom_highbd_obmc_sad8x32_neon),
262 TestFuncs(aom_highbd_obmc_sad16x4_c, aom_highbd_obmc_sad16x4_neon),
263 TestFuncs(aom_highbd_obmc_sad4x16_c, aom_highbd_obmc_sad4x16_neon),
264 #endif // !CONFIG_REALTIME_ONLY
265 };
266
267 INSTANTIATE_TEST_SUITE_P(NEON, ObmcSadHBDTest,
268 ::testing::ValuesIn(neon_functions_hbd));
269 #endif // HAVE_NEON
270
271 #if HAVE_SSE4_1
272 ObmcSadHBDTest::ParamType sse4_functions_hbd[] = {
273 TestFuncs(aom_highbd_obmc_sad128x128_c, aom_highbd_obmc_sad128x128_sse4_1),
274 TestFuncs(aom_highbd_obmc_sad128x64_c, aom_highbd_obmc_sad128x64_sse4_1),
275 TestFuncs(aom_highbd_obmc_sad64x128_c, aom_highbd_obmc_sad64x128_sse4_1),
276 TestFuncs(aom_highbd_obmc_sad64x64_c, aom_highbd_obmc_sad64x64_sse4_1),
277 TestFuncs(aom_highbd_obmc_sad64x32_c, aom_highbd_obmc_sad64x32_sse4_1),
278 TestFuncs(aom_highbd_obmc_sad32x64_c, aom_highbd_obmc_sad32x64_sse4_1),
279 TestFuncs(aom_highbd_obmc_sad32x32_c, aom_highbd_obmc_sad32x32_sse4_1),
280 TestFuncs(aom_highbd_obmc_sad32x16_c, aom_highbd_obmc_sad32x16_sse4_1),
281 TestFuncs(aom_highbd_obmc_sad16x32_c, aom_highbd_obmc_sad16x32_sse4_1),
282 TestFuncs(aom_highbd_obmc_sad16x16_c, aom_highbd_obmc_sad16x16_sse4_1),
283 TestFuncs(aom_highbd_obmc_sad16x8_c, aom_highbd_obmc_sad16x8_sse4_1),
284 TestFuncs(aom_highbd_obmc_sad8x16_c, aom_highbd_obmc_sad8x16_sse4_1),
285 TestFuncs(aom_highbd_obmc_sad8x8_c, aom_highbd_obmc_sad8x8_sse4_1),
286 TestFuncs(aom_highbd_obmc_sad8x4_c, aom_highbd_obmc_sad8x4_sse4_1),
287 TestFuncs(aom_highbd_obmc_sad4x8_c, aom_highbd_obmc_sad4x8_sse4_1),
288 TestFuncs(aom_highbd_obmc_sad4x4_c, aom_highbd_obmc_sad4x4_sse4_1),
289
290 TestFuncs(aom_highbd_obmc_sad64x16_c, aom_highbd_obmc_sad64x16_sse4_1),
291 TestFuncs(aom_highbd_obmc_sad16x64_c, aom_highbd_obmc_sad16x64_sse4_1),
292 TestFuncs(aom_highbd_obmc_sad32x8_c, aom_highbd_obmc_sad32x8_sse4_1),
293 TestFuncs(aom_highbd_obmc_sad8x32_c, aom_highbd_obmc_sad8x32_sse4_1),
294 TestFuncs(aom_highbd_obmc_sad16x4_c, aom_highbd_obmc_sad16x4_sse4_1),
295 TestFuncs(aom_highbd_obmc_sad4x16_c, aom_highbd_obmc_sad4x16_sse4_1),
296 };
297
298 INSTANTIATE_TEST_SUITE_P(SSE4_1, ObmcSadHBDTest,
299 ::testing::ValuesIn(sse4_functions_hbd));
300 #endif // HAVE_SSE4_1
301
302 #if HAVE_AVX2
303 ObmcSadHBDTest::ParamType avx2_functions_hbd[] = {
304 TestFuncs(aom_highbd_obmc_sad128x128_c, aom_highbd_obmc_sad128x128_avx2),
305 TestFuncs(aom_highbd_obmc_sad128x64_c, aom_highbd_obmc_sad128x64_avx2),
306 TestFuncs(aom_highbd_obmc_sad64x128_c, aom_highbd_obmc_sad64x128_avx2),
307 TestFuncs(aom_highbd_obmc_sad64x64_c, aom_highbd_obmc_sad64x64_avx2),
308 TestFuncs(aom_highbd_obmc_sad64x32_c, aom_highbd_obmc_sad64x32_avx2),
309 TestFuncs(aom_highbd_obmc_sad32x64_c, aom_highbd_obmc_sad32x64_avx2),
310 TestFuncs(aom_highbd_obmc_sad32x32_c, aom_highbd_obmc_sad32x32_avx2),
311 TestFuncs(aom_highbd_obmc_sad32x16_c, aom_highbd_obmc_sad32x16_avx2),
312 TestFuncs(aom_highbd_obmc_sad16x32_c, aom_highbd_obmc_sad16x32_avx2),
313 TestFuncs(aom_highbd_obmc_sad16x16_c, aom_highbd_obmc_sad16x16_avx2),
314 TestFuncs(aom_highbd_obmc_sad16x8_c, aom_highbd_obmc_sad16x8_avx2),
315 TestFuncs(aom_highbd_obmc_sad8x16_c, aom_highbd_obmc_sad8x16_avx2),
316 TestFuncs(aom_highbd_obmc_sad8x8_c, aom_highbd_obmc_sad8x8_avx2),
317 TestFuncs(aom_highbd_obmc_sad8x4_c, aom_highbd_obmc_sad8x4_avx2),
318 TestFuncs(aom_highbd_obmc_sad4x8_c, aom_highbd_obmc_sad4x8_avx2),
319 TestFuncs(aom_highbd_obmc_sad4x4_c, aom_highbd_obmc_sad4x4_avx2),
320
321 TestFuncs(aom_highbd_obmc_sad64x16_c, aom_highbd_obmc_sad64x16_avx2),
322 TestFuncs(aom_highbd_obmc_sad16x64_c, aom_highbd_obmc_sad16x64_avx2),
323 TestFuncs(aom_highbd_obmc_sad32x8_c, aom_highbd_obmc_sad32x8_avx2),
324 TestFuncs(aom_highbd_obmc_sad8x32_c, aom_highbd_obmc_sad8x32_avx2),
325 TestFuncs(aom_highbd_obmc_sad16x4_c, aom_highbd_obmc_sad16x4_avx2),
326 TestFuncs(aom_highbd_obmc_sad4x16_c, aom_highbd_obmc_sad4x16_avx2),
327 };
328
329 INSTANTIATE_TEST_SUITE_P(AVX2, ObmcSadHBDTest,
330 ::testing::ValuesIn(avx2_functions_hbd));
331 #endif // HAVE_AVX2
332 #endif // CONFIG_AV1_HIGHBITDEPTH
333 } // namespace
334