Add ssse3 aom_smooth_h_predictor_4xh
[aom.git] / test / obmc_variance_test.cc
blob5fc1e9c829702890228ea57ae23dbcd46e145aa5
1 /*
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"
13 #include "test/acm_random.h"
15 #include "test/function_equivalence_test.h"
16 #include "test/register_state_check.h"
18 #include "./aom_config.h"
19 #include "./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::ACMRandom;
25 using libaom_test::FunctionEquivalenceTest;
27 namespace {
29 static const int kIterations = 1000;
30 static const int kMaskMax = 64;
32 typedef unsigned int (*ObmcVarF)(const uint8_t *pre, int pre_stride,
33 const int32_t *wsrc, const int32_t *mask,
34 unsigned int *sse);
35 typedef libaom_test::FuncParam<ObmcVarF> TestFuncs;
37 ////////////////////////////////////////////////////////////////////////////////
38 // 8 bit
39 ////////////////////////////////////////////////////////////////////////////////
41 class ObmcVarianceTest : public FunctionEquivalenceTest<ObmcVarF> {};
43 TEST_P(ObmcVarianceTest, RandomValues) {
44 DECLARE_ALIGNED(32, uint8_t, pre[MAX_SB_SQUARE]);
45 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
46 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
48 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
49 const int pre_stride = this->rng_(MAX_SB_SIZE + 1);
51 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
52 pre[i] = this->rng_.Rand8();
53 wsrc[i] = this->rng_.Rand8() * this->rng_(kMaskMax * kMaskMax + 1);
54 mask[i] = this->rng_(kMaskMax * kMaskMax + 1);
57 unsigned int ref_sse, tst_sse;
58 const unsigned int ref_res =
59 params_.ref_func(pre, pre_stride, wsrc, mask, &ref_sse);
60 unsigned int tst_res;
61 ASM_REGISTER_STATE_CHECK(
62 tst_res = params_.tst_func(pre, pre_stride, wsrc, mask, &tst_sse));
64 ASSERT_EQ(ref_res, tst_res);
65 ASSERT_EQ(ref_sse, tst_sse);
69 TEST_P(ObmcVarianceTest, ExtremeValues) {
70 DECLARE_ALIGNED(32, uint8_t, pre[MAX_SB_SQUARE]);
71 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
72 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
74 for (int iter = 0; iter < MAX_SB_SIZE && !HasFatalFailure(); ++iter) {
75 const int pre_stride = iter;
77 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
78 pre[i] = UINT8_MAX;
79 wsrc[i] = UINT8_MAX * kMaskMax * kMaskMax;
80 mask[i] = kMaskMax * kMaskMax;
83 unsigned int ref_sse, tst_sse;
84 const unsigned int ref_res =
85 params_.ref_func(pre, pre_stride, wsrc, mask, &ref_sse);
86 unsigned int tst_res;
87 ASM_REGISTER_STATE_CHECK(
88 tst_res = params_.tst_func(pre, pre_stride, wsrc, mask, &tst_sse));
90 ASSERT_EQ(ref_res, tst_res);
91 ASSERT_EQ(ref_sse, tst_sse);
95 #if HAVE_SSE4_1
96 const ObmcVarianceTest::ParamType sse4_functions[] = {
97 TestFuncs(aom_obmc_variance128x128_c, aom_obmc_variance128x128_sse4_1),
98 TestFuncs(aom_obmc_variance128x64_c, aom_obmc_variance128x64_sse4_1),
99 TestFuncs(aom_obmc_variance64x128_c, aom_obmc_variance64x128_sse4_1),
100 TestFuncs(aom_obmc_variance64x64_c, aom_obmc_variance64x64_sse4_1),
101 TestFuncs(aom_obmc_variance64x32_c, aom_obmc_variance64x32_sse4_1),
102 TestFuncs(aom_obmc_variance32x64_c, aom_obmc_variance32x64_sse4_1),
103 TestFuncs(aom_obmc_variance32x32_c, aom_obmc_variance32x32_sse4_1),
104 TestFuncs(aom_obmc_variance32x16_c, aom_obmc_variance32x16_sse4_1),
105 TestFuncs(aom_obmc_variance16x32_c, aom_obmc_variance16x32_sse4_1),
106 TestFuncs(aom_obmc_variance16x16_c, aom_obmc_variance16x16_sse4_1),
107 TestFuncs(aom_obmc_variance16x8_c, aom_obmc_variance16x8_sse4_1),
108 TestFuncs(aom_obmc_variance8x16_c, aom_obmc_variance8x16_sse4_1),
109 TestFuncs(aom_obmc_variance8x8_c, aom_obmc_variance8x8_sse4_1),
110 TestFuncs(aom_obmc_variance8x4_c, aom_obmc_variance8x4_sse4_1),
111 TestFuncs(aom_obmc_variance4x8_c, aom_obmc_variance4x8_sse4_1),
112 TestFuncs(aom_obmc_variance4x4_c, aom_obmc_variance4x4_sse4_1)
115 INSTANTIATE_TEST_CASE_P(SSE4_1, ObmcVarianceTest,
116 ::testing::ValuesIn(sse4_functions));
117 #endif // HAVE_SSE4_1
119 ////////////////////////////////////////////////////////////////////////////////
120 // High bit-depth
121 ////////////////////////////////////////////////////////////////////////////////
123 class ObmcVarianceHBDTest : public FunctionEquivalenceTest<ObmcVarF> {};
125 TEST_P(ObmcVarianceHBDTest, RandomValues) {
126 DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
127 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
128 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
130 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
131 const int pre_stride = this->rng_(MAX_SB_SIZE + 1);
133 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
134 pre[i] = this->rng_(1 << params_.bit_depth);
135 wsrc[i] = this->rng_(1 << params_.bit_depth) *
136 this->rng_(kMaskMax * kMaskMax + 1);
137 mask[i] = this->rng_(kMaskMax * kMaskMax + 1);
140 unsigned int ref_sse, tst_sse;
141 const unsigned int ref_res = params_.ref_func(
142 CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask, &ref_sse);
143 unsigned int tst_res;
144 ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(CONVERT_TO_BYTEPTR(pre),
145 pre_stride, wsrc, mask,
146 &tst_sse));
148 ASSERT_EQ(ref_res, tst_res);
149 ASSERT_EQ(ref_sse, tst_sse);
153 TEST_P(ObmcVarianceHBDTest, ExtremeValues) {
154 DECLARE_ALIGNED(32, uint16_t, pre[MAX_SB_SQUARE]);
155 DECLARE_ALIGNED(32, int32_t, wsrc[MAX_SB_SQUARE]);
156 DECLARE_ALIGNED(32, int32_t, mask[MAX_SB_SQUARE]);
158 for (int iter = 0; iter < MAX_SB_SIZE && !HasFatalFailure(); ++iter) {
159 const int pre_stride = iter;
161 for (int i = 0; i < MAX_SB_SQUARE; ++i) {
162 pre[i] = (1 << params_.bit_depth) - 1;
163 wsrc[i] = ((1 << params_.bit_depth) - 1) * kMaskMax * kMaskMax;
164 mask[i] = kMaskMax * kMaskMax;
167 unsigned int ref_sse, tst_sse;
168 const unsigned int ref_res = params_.ref_func(
169 CONVERT_TO_BYTEPTR(pre), pre_stride, wsrc, mask, &ref_sse);
170 unsigned int tst_res;
171 ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(CONVERT_TO_BYTEPTR(pre),
172 pre_stride, wsrc, mask,
173 &tst_sse));
175 ASSERT_EQ(ref_res, tst_res);
176 ASSERT_EQ(ref_sse, tst_sse);
180 #if HAVE_SSE4_1
181 ObmcVarianceHBDTest::ParamType sse4_functions_hbd[] = {
182 TestFuncs(aom_highbd_obmc_variance128x128_c,
183 aom_highbd_obmc_variance128x128_sse4_1, 8),
184 TestFuncs(aom_highbd_obmc_variance128x64_c,
185 aom_highbd_obmc_variance128x64_sse4_1, 8),
186 TestFuncs(aom_highbd_obmc_variance64x128_c,
187 aom_highbd_obmc_variance64x128_sse4_1, 8),
188 TestFuncs(aom_highbd_obmc_variance64x64_c,
189 aom_highbd_obmc_variance64x64_sse4_1, 8),
190 TestFuncs(aom_highbd_obmc_variance64x32_c,
191 aom_highbd_obmc_variance64x32_sse4_1, 8),
192 TestFuncs(aom_highbd_obmc_variance32x64_c,
193 aom_highbd_obmc_variance32x64_sse4_1, 8),
194 TestFuncs(aom_highbd_obmc_variance32x32_c,
195 aom_highbd_obmc_variance32x32_sse4_1, 8),
196 TestFuncs(aom_highbd_obmc_variance32x16_c,
197 aom_highbd_obmc_variance32x16_sse4_1, 8),
198 TestFuncs(aom_highbd_obmc_variance16x32_c,
199 aom_highbd_obmc_variance16x32_sse4_1, 8),
200 TestFuncs(aom_highbd_obmc_variance16x16_c,
201 aom_highbd_obmc_variance16x16_sse4_1, 8),
202 TestFuncs(aom_highbd_obmc_variance16x8_c, aom_highbd_obmc_variance16x8_sse4_1,
204 TestFuncs(aom_highbd_obmc_variance8x16_c, aom_highbd_obmc_variance8x16_sse4_1,
206 TestFuncs(aom_highbd_obmc_variance8x8_c, aom_highbd_obmc_variance8x8_sse4_1,
208 TestFuncs(aom_highbd_obmc_variance8x4_c, aom_highbd_obmc_variance8x4_sse4_1,
210 TestFuncs(aom_highbd_obmc_variance4x8_c, aom_highbd_obmc_variance4x8_sse4_1,
212 TestFuncs(aom_highbd_obmc_variance4x4_c, aom_highbd_obmc_variance4x4_sse4_1,
214 TestFuncs(aom_highbd_10_obmc_variance128x128_c,
215 aom_highbd_10_obmc_variance128x128_sse4_1, 10),
216 TestFuncs(aom_highbd_10_obmc_variance128x64_c,
217 aom_highbd_10_obmc_variance128x64_sse4_1, 10),
218 TestFuncs(aom_highbd_10_obmc_variance64x128_c,
219 aom_highbd_10_obmc_variance64x128_sse4_1, 10),
220 TestFuncs(aom_highbd_10_obmc_variance64x64_c,
221 aom_highbd_10_obmc_variance64x64_sse4_1, 10),
222 TestFuncs(aom_highbd_10_obmc_variance64x32_c,
223 aom_highbd_10_obmc_variance64x32_sse4_1, 10),
224 TestFuncs(aom_highbd_10_obmc_variance32x64_c,
225 aom_highbd_10_obmc_variance32x64_sse4_1, 10),
226 TestFuncs(aom_highbd_10_obmc_variance32x32_c,
227 aom_highbd_10_obmc_variance32x32_sse4_1, 10),
228 TestFuncs(aom_highbd_10_obmc_variance32x16_c,
229 aom_highbd_10_obmc_variance32x16_sse4_1, 10),
230 TestFuncs(aom_highbd_10_obmc_variance16x32_c,
231 aom_highbd_10_obmc_variance16x32_sse4_1, 10),
232 TestFuncs(aom_highbd_10_obmc_variance16x16_c,
233 aom_highbd_10_obmc_variance16x16_sse4_1, 10),
234 TestFuncs(aom_highbd_10_obmc_variance16x8_c,
235 aom_highbd_10_obmc_variance16x8_sse4_1, 10),
236 TestFuncs(aom_highbd_10_obmc_variance8x16_c,
237 aom_highbd_10_obmc_variance8x16_sse4_1, 10),
238 TestFuncs(aom_highbd_10_obmc_variance8x8_c,
239 aom_highbd_10_obmc_variance8x8_sse4_1, 10),
240 TestFuncs(aom_highbd_10_obmc_variance8x4_c,
241 aom_highbd_10_obmc_variance8x4_sse4_1, 10),
242 TestFuncs(aom_highbd_10_obmc_variance4x8_c,
243 aom_highbd_10_obmc_variance4x8_sse4_1, 10),
244 TestFuncs(aom_highbd_10_obmc_variance4x4_c,
245 aom_highbd_10_obmc_variance4x4_sse4_1, 10),
246 TestFuncs(aom_highbd_12_obmc_variance128x128_c,
247 aom_highbd_12_obmc_variance128x128_sse4_1, 12),
248 TestFuncs(aom_highbd_12_obmc_variance128x64_c,
249 aom_highbd_12_obmc_variance128x64_sse4_1, 12),
250 TestFuncs(aom_highbd_12_obmc_variance64x128_c,
251 aom_highbd_12_obmc_variance64x128_sse4_1, 12),
252 TestFuncs(aom_highbd_12_obmc_variance64x64_c,
253 aom_highbd_12_obmc_variance64x64_sse4_1, 12),
254 TestFuncs(aom_highbd_12_obmc_variance64x32_c,
255 aom_highbd_12_obmc_variance64x32_sse4_1, 12),
256 TestFuncs(aom_highbd_12_obmc_variance32x64_c,
257 aom_highbd_12_obmc_variance32x64_sse4_1, 12),
258 TestFuncs(aom_highbd_12_obmc_variance32x32_c,
259 aom_highbd_12_obmc_variance32x32_sse4_1, 12),
260 TestFuncs(aom_highbd_12_obmc_variance32x16_c,
261 aom_highbd_12_obmc_variance32x16_sse4_1, 12),
262 TestFuncs(aom_highbd_12_obmc_variance16x32_c,
263 aom_highbd_12_obmc_variance16x32_sse4_1, 12),
264 TestFuncs(aom_highbd_12_obmc_variance16x16_c,
265 aom_highbd_12_obmc_variance16x16_sse4_1, 12),
266 TestFuncs(aom_highbd_12_obmc_variance16x8_c,
267 aom_highbd_12_obmc_variance16x8_sse4_1, 12),
268 TestFuncs(aom_highbd_12_obmc_variance8x16_c,
269 aom_highbd_12_obmc_variance8x16_sse4_1, 12),
270 TestFuncs(aom_highbd_12_obmc_variance8x8_c,
271 aom_highbd_12_obmc_variance8x8_sse4_1, 12),
272 TestFuncs(aom_highbd_12_obmc_variance8x4_c,
273 aom_highbd_12_obmc_variance8x4_sse4_1, 12),
274 TestFuncs(aom_highbd_12_obmc_variance4x8_c,
275 aom_highbd_12_obmc_variance4x8_sse4_1, 12),
276 TestFuncs(aom_highbd_12_obmc_variance4x4_c,
277 aom_highbd_12_obmc_variance4x4_sse4_1, 12)
280 INSTANTIATE_TEST_CASE_P(SSE4_1, ObmcVarianceHBDTest,
281 ::testing::ValuesIn(sse4_functions_hbd));
282 #endif // HAVE_SSE4_1
283 } // namespace