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
> {};
41 TEST_P(ObmcSadTest
, RandomValues
) {
42 DECLARE_ALIGNED(32, uint8_t, pre
[MAX_SB_SQUARE
]);
43 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
44 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
46 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
47 const int pre_stride
= rng_(MAX_SB_SIZE
+ 1);
49 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
50 pre
[i
] = rng_
.Rand8();
51 wsrc
[i
] = rng_
.Rand8() * rng_(kMaskMax
* kMaskMax
+ 1);
52 mask
[i
] = rng_(kMaskMax
* kMaskMax
+ 1);
55 const unsigned int ref_res
= params_
.ref_func(pre
, pre_stride
, wsrc
, mask
);
57 ASM_REGISTER_STATE_CHECK(tst_res
=
58 params_
.tst_func(pre
, pre_stride
, wsrc
, mask
));
60 ASSERT_EQ(ref_res
, tst_res
);
64 TEST_P(ObmcSadTest
, ExtremeValues
) {
65 DECLARE_ALIGNED(32, uint8_t, pre
[MAX_SB_SQUARE
]);
66 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
67 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
69 for (int iter
= 0; iter
< MAX_SB_SIZE
&& !HasFatalFailure(); ++iter
) {
70 const int pre_stride
= iter
;
72 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
74 wsrc
[i
] = UINT8_MAX
* kMaskMax
* kMaskMax
;
75 mask
[i
] = kMaskMax
* kMaskMax
;
78 const unsigned int ref_res
= params_
.ref_func(pre
, pre_stride
, wsrc
, mask
);
80 ASM_REGISTER_STATE_CHECK(tst_res
=
81 params_
.tst_func(pre
, pre_stride
, wsrc
, mask
));
83 ASSERT_EQ(ref_res
, tst_res
);
88 const ObmcSadTest::ParamType sse4_functions
[] = {
89 TestFuncs(aom_obmc_sad128x128_c
, aom_obmc_sad128x128_sse4_1
),
90 TestFuncs(aom_obmc_sad128x64_c
, aom_obmc_sad128x64_sse4_1
),
91 TestFuncs(aom_obmc_sad64x128_c
, aom_obmc_sad64x128_sse4_1
),
92 TestFuncs(aom_obmc_sad64x64_c
, aom_obmc_sad64x64_sse4_1
),
93 TestFuncs(aom_obmc_sad64x32_c
, aom_obmc_sad64x32_sse4_1
),
94 TestFuncs(aom_obmc_sad32x64_c
, aom_obmc_sad32x64_sse4_1
),
95 TestFuncs(aom_obmc_sad32x32_c
, aom_obmc_sad32x32_sse4_1
),
96 TestFuncs(aom_obmc_sad32x16_c
, aom_obmc_sad32x16_sse4_1
),
97 TestFuncs(aom_obmc_sad16x32_c
, aom_obmc_sad16x32_sse4_1
),
98 TestFuncs(aom_obmc_sad16x16_c
, aom_obmc_sad16x16_sse4_1
),
99 TestFuncs(aom_obmc_sad16x8_c
, aom_obmc_sad16x8_sse4_1
),
100 TestFuncs(aom_obmc_sad8x16_c
, aom_obmc_sad8x16_sse4_1
),
101 TestFuncs(aom_obmc_sad8x8_c
, aom_obmc_sad8x8_sse4_1
),
102 TestFuncs(aom_obmc_sad8x4_c
, aom_obmc_sad8x4_sse4_1
),
103 TestFuncs(aom_obmc_sad4x8_c
, aom_obmc_sad4x8_sse4_1
),
104 TestFuncs(aom_obmc_sad4x4_c
, aom_obmc_sad4x4_sse4_1
)
107 INSTANTIATE_TEST_CASE_P(SSE4_1
, ObmcSadTest
,
108 ::testing::ValuesIn(sse4_functions
));
109 #endif // HAVE_SSE4_1
112 const ObmcSadTest::ParamType avx2_functions
[] = {
113 TestFuncs(aom_obmc_sad128x128_c
, aom_obmc_sad128x128_avx2
),
114 TestFuncs(aom_obmc_sad128x64_c
, aom_obmc_sad128x64_avx2
),
115 TestFuncs(aom_obmc_sad64x128_c
, aom_obmc_sad64x128_avx2
),
116 TestFuncs(aom_obmc_sad64x64_c
, aom_obmc_sad64x64_avx2
),
117 TestFuncs(aom_obmc_sad64x32_c
, aom_obmc_sad64x32_avx2
),
118 TestFuncs(aom_obmc_sad32x64_c
, aom_obmc_sad32x64_avx2
),
119 TestFuncs(aom_obmc_sad32x32_c
, aom_obmc_sad32x32_avx2
),
120 TestFuncs(aom_obmc_sad32x16_c
, aom_obmc_sad32x16_avx2
),
121 TestFuncs(aom_obmc_sad16x32_c
, aom_obmc_sad16x32_avx2
),
122 TestFuncs(aom_obmc_sad16x16_c
, aom_obmc_sad16x16_avx2
),
123 TestFuncs(aom_obmc_sad16x8_c
, aom_obmc_sad16x8_avx2
),
124 TestFuncs(aom_obmc_sad8x16_c
, aom_obmc_sad8x16_avx2
),
125 TestFuncs(aom_obmc_sad8x8_c
, aom_obmc_sad8x8_avx2
),
126 TestFuncs(aom_obmc_sad8x4_c
, aom_obmc_sad8x4_avx2
),
127 TestFuncs(aom_obmc_sad4x8_c
, aom_obmc_sad4x8_avx2
),
128 TestFuncs(aom_obmc_sad4x4_c
, aom_obmc_sad4x4_avx2
)
131 INSTANTIATE_TEST_CASE_P(AVX2
, ObmcSadTest
, ::testing::ValuesIn(avx2_functions
));
134 ////////////////////////////////////////////////////////////////////////////////
136 ////////////////////////////////////////////////////////////////////////////////
138 class ObmcSadHBDTest
: public FunctionEquivalenceTest
<ObmcSadF
> {};
140 TEST_P(ObmcSadHBDTest
, RandomValues
) {
141 DECLARE_ALIGNED(32, uint16_t, pre
[MAX_SB_SQUARE
]);
142 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
143 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
145 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
146 const int pre_stride
= rng_(MAX_SB_SIZE
+ 1);
148 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
149 pre
[i
] = rng_(1 << 12);
150 wsrc
[i
] = rng_(1 << 12) * rng_(kMaskMax
* kMaskMax
+ 1);
151 mask
[i
] = rng_(kMaskMax
* kMaskMax
+ 1);
154 const unsigned int ref_res
=
155 params_
.ref_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
);
156 unsigned int tst_res
;
157 ASM_REGISTER_STATE_CHECK(
159 params_
.tst_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
));
161 ASSERT_EQ(ref_res
, tst_res
);
165 TEST_P(ObmcSadHBDTest
, ExtremeValues
) {
166 DECLARE_ALIGNED(32, uint16_t, pre
[MAX_SB_SQUARE
]);
167 DECLARE_ALIGNED(32, int32_t, wsrc
[MAX_SB_SQUARE
]);
168 DECLARE_ALIGNED(32, int32_t, mask
[MAX_SB_SQUARE
]);
170 for (int iter
= 0; iter
< MAX_SB_SIZE
&& !HasFatalFailure(); ++iter
) {
171 const int pre_stride
= iter
;
173 for (int i
= 0; i
< MAX_SB_SQUARE
; ++i
) {
174 pre
[i
] = (1 << 12) - 1;
175 wsrc
[i
] = ((1 << 12) - 1) * kMaskMax
* kMaskMax
;
176 mask
[i
] = kMaskMax
* kMaskMax
;
179 const unsigned int ref_res
=
180 params_
.ref_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
);
181 unsigned int tst_res
;
182 ASM_REGISTER_STATE_CHECK(
184 params_
.tst_func(CONVERT_TO_BYTEPTR(pre
), pre_stride
, wsrc
, mask
));
186 ASSERT_EQ(ref_res
, tst_res
);
191 ObmcSadHBDTest::ParamType sse4_functions_hbd
[] = {
192 TestFuncs(aom_highbd_obmc_sad128x128_c
, aom_highbd_obmc_sad128x128_sse4_1
),
193 TestFuncs(aom_highbd_obmc_sad128x64_c
, aom_highbd_obmc_sad128x64_sse4_1
),
194 TestFuncs(aom_highbd_obmc_sad64x128_c
, aom_highbd_obmc_sad64x128_sse4_1
),
195 TestFuncs(aom_highbd_obmc_sad64x64_c
, aom_highbd_obmc_sad64x64_sse4_1
),
196 TestFuncs(aom_highbd_obmc_sad64x32_c
, aom_highbd_obmc_sad64x32_sse4_1
),
197 TestFuncs(aom_highbd_obmc_sad32x64_c
, aom_highbd_obmc_sad32x64_sse4_1
),
198 TestFuncs(aom_highbd_obmc_sad32x32_c
, aom_highbd_obmc_sad32x32_sse4_1
),
199 TestFuncs(aom_highbd_obmc_sad32x16_c
, aom_highbd_obmc_sad32x16_sse4_1
),
200 TestFuncs(aom_highbd_obmc_sad16x32_c
, aom_highbd_obmc_sad16x32_sse4_1
),
201 TestFuncs(aom_highbd_obmc_sad16x16_c
, aom_highbd_obmc_sad16x16_sse4_1
),
202 TestFuncs(aom_highbd_obmc_sad16x8_c
, aom_highbd_obmc_sad16x8_sse4_1
),
203 TestFuncs(aom_highbd_obmc_sad8x16_c
, aom_highbd_obmc_sad8x16_sse4_1
),
204 TestFuncs(aom_highbd_obmc_sad8x8_c
, aom_highbd_obmc_sad8x8_sse4_1
),
205 TestFuncs(aom_highbd_obmc_sad8x4_c
, aom_highbd_obmc_sad8x4_sse4_1
),
206 TestFuncs(aom_highbd_obmc_sad4x8_c
, aom_highbd_obmc_sad4x8_sse4_1
),
207 TestFuncs(aom_highbd_obmc_sad4x4_c
, aom_highbd_obmc_sad4x4_sse4_1
)
210 INSTANTIATE_TEST_CASE_P(SSE4_1
, ObmcSadHBDTest
,
211 ::testing::ValuesIn(sse4_functions_hbd
));
212 #endif // HAVE_SSE4_1
215 ObmcSadHBDTest::ParamType avx2_functions_hbd
[] = {
216 TestFuncs(aom_highbd_obmc_sad128x128_c
, aom_highbd_obmc_sad128x128_avx2
),
217 TestFuncs(aom_highbd_obmc_sad128x64_c
, aom_highbd_obmc_sad128x64_avx2
),
218 TestFuncs(aom_highbd_obmc_sad64x128_c
, aom_highbd_obmc_sad64x128_avx2
),
219 TestFuncs(aom_highbd_obmc_sad64x64_c
, aom_highbd_obmc_sad64x64_avx2
),
220 TestFuncs(aom_highbd_obmc_sad64x32_c
, aom_highbd_obmc_sad64x32_avx2
),
221 TestFuncs(aom_highbd_obmc_sad32x64_c
, aom_highbd_obmc_sad32x64_avx2
),
222 TestFuncs(aom_highbd_obmc_sad32x32_c
, aom_highbd_obmc_sad32x32_avx2
),
223 TestFuncs(aom_highbd_obmc_sad32x16_c
, aom_highbd_obmc_sad32x16_avx2
),
224 TestFuncs(aom_highbd_obmc_sad16x32_c
, aom_highbd_obmc_sad16x32_avx2
),
225 TestFuncs(aom_highbd_obmc_sad16x16_c
, aom_highbd_obmc_sad16x16_avx2
),
226 TestFuncs(aom_highbd_obmc_sad16x8_c
, aom_highbd_obmc_sad16x8_avx2
),
227 TestFuncs(aom_highbd_obmc_sad8x16_c
, aom_highbd_obmc_sad8x16_avx2
),
228 TestFuncs(aom_highbd_obmc_sad8x8_c
, aom_highbd_obmc_sad8x8_avx2
),
229 TestFuncs(aom_highbd_obmc_sad8x4_c
, aom_highbd_obmc_sad8x4_avx2
),
230 TestFuncs(aom_highbd_obmc_sad4x8_c
, aom_highbd_obmc_sad4x8_avx2
),
231 TestFuncs(aom_highbd_obmc_sad4x4_c
, aom_highbd_obmc_sad4x4_avx2
)
234 INSTANTIATE_TEST_CASE_P(AVX2
, ObmcSadHBDTest
,
235 ::testing::ValuesIn(avx2_functions_hbd
));