2 * Copyright (c) 2017, 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.
16 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17 #include "test/register_state_check.h"
18 #include "test/function_equivalence_test.h"
20 #include "config/aom_config.h"
21 #include "config/aom_dsp_rtcd.h"
22 #include "config/av1_rtcd.h"
24 #include "aom/aom_integer.h"
25 #include "av1/common/enums.h"
27 using libaom_test::FunctionEquivalenceTest
;
31 template <typename F
, typename T
>
32 class UpsampleTest
: public FunctionEquivalenceTest
<F
> {
34 static const int kIterations
= 1000000;
35 static const int kMinEdge
= 4;
36 static const int kMaxEdge
= 24;
37 static const int kBufSize
= 2 * 64 + 32;
38 static const int kOffset
= 16;
40 virtual ~UpsampleTest() {}
42 virtual void Execute(T
*edge_tst
) = 0;
45 edge_ref_
= &edge_ref_data_
[kOffset
];
46 edge_tst_
= &edge_tst_data_
[kOffset
];
50 const int max_idx
= (size_
- 1) * 2;
51 for (int r
= -2; r
<= max_idx
; ++r
) {
52 ASSERT_EQ(edge_ref_
[r
], edge_tst_
[r
]);
56 T edge_ref_data_
[kBufSize
];
57 T edge_tst_data_
[kBufSize
];
65 //////////////////////////////////////////////////////////////////////////////
67 //////////////////////////////////////////////////////////////////////////////
69 typedef void (*UP8B
)(uint8_t *p
, int size
);
70 typedef libaom_test::FuncParam
<UP8B
> TestFuncs
;
72 class UpsampleTest8B
: public UpsampleTest
<UP8B
, uint8_t> {
74 void Execute(uint8_t *edge_tst
) {
75 params_
.ref_func(edge_ref_
, size_
);
76 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst
, size_
));
80 TEST_P(UpsampleTest8B
, RandomValues
) {
81 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
82 size_
= 4 * (this->rng_(4) + 1);
85 for (i
= 0; i
< kOffset
+ size_
; ++i
) {
87 edge_ref_data_
[i
] = pix
;
88 edge_tst_data_
[i
] = edge_ref_data_
[i
];
91 // Extend final sample
92 while (i
< kBufSize
) {
93 edge_ref_data_
[i
] = pix
;
94 edge_tst_data_
[i
] = pix
;
103 INSTANTIATE_TEST_CASE_P(
104 SSE4_1
, UpsampleTest8B
,
105 ::testing::Values(TestFuncs(av1_upsample_intra_edge_c
,
106 av1_upsample_intra_edge_sse4_1
)));
107 #endif // HAVE_SSE4_1
109 //////////////////////////////////////////////////////////////////////////////
110 // High bit-depth version
111 //////////////////////////////////////////////////////////////////////////////
113 typedef void (*UPHB
)(uint16_t *p
, int size
, int bd
);
114 typedef libaom_test::FuncParam
<UPHB
> TestFuncsHBD
;
116 class UpsampleTestHB
: public UpsampleTest
<UPHB
, uint16_t> {
118 void Execute(uint16_t *edge_tst
) {
119 params_
.ref_func(edge_ref_
, size_
, bit_depth_
);
120 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst
, size_
, bit_depth_
));
125 TEST_P(UpsampleTestHB
, RandomValues
) {
126 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
128 case 0: bit_depth_
= 8; break;
129 case 1: bit_depth_
= 10; break;
130 default: bit_depth_
= 12; break;
132 const int hi
= 1 << bit_depth_
;
134 size_
= 4 * (this->rng_(4) + 1);
137 for (i
= 0; i
< kOffset
+ size_
; ++i
) {
139 edge_ref_data_
[i
] = pix
;
140 edge_tst_data_
[i
] = pix
;
143 // Extend final sample
144 while (i
< kBufSize
) {
145 edge_ref_data_
[i
] = pix
;
146 edge_tst_data_
[i
] = pix
;
155 INSTANTIATE_TEST_CASE_P(
156 SSE4_1
, UpsampleTestHB
,
157 ::testing::Values(TestFuncsHBD(av1_upsample_intra_edge_high_c
,
158 av1_upsample_intra_edge_high_sse4_1
)));
159 #endif // HAVE_SSE4_1
161 template <typename F
, typename T
>
162 class FilterEdgeTest
: public FunctionEquivalenceTest
<F
> {
164 static const int kIterations
= 1000000;
165 static const int kMaxEdge
= 2 * 64;
166 static const int kBufSize
= kMaxEdge
+ 32;
167 static const int kOffset
= 15;
169 virtual ~FilterEdgeTest() {}
171 virtual void Execute(T
*edge_tst
) = 0;
174 edge_ref_
= &edge_ref_data_
[kOffset
];
175 edge_tst_
= &edge_tst_data_
[kOffset
];
179 for (int r
= 0; r
< size_
; ++r
) {
180 ASSERT_EQ(edge_ref_
[r
], edge_tst_
[r
]);
184 T edge_ref_data_
[kBufSize
];
185 T edge_tst_data_
[kBufSize
];
194 //////////////////////////////////////////////////////////////////////////////
196 //////////////////////////////////////////////////////////////////////////////
198 typedef void (*FE8B
)(uint8_t *p
, int size
, int strength
);
199 typedef libaom_test::FuncParam
<FE8B
> FilterEdgeTestFuncs
;
201 class FilterEdgeTest8B
: public FilterEdgeTest
<FE8B
, uint8_t> {
203 void Execute(uint8_t *edge_tst
) {
204 params_
.ref_func(edge_ref_
, size_
, strength_
);
205 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst
, size_
, strength_
));
209 TEST_P(FilterEdgeTest8B
, RandomValues
) {
210 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
211 strength_
= this->rng_(4);
212 size_
= 4 * (this->rng_(128 / 4) + 1) + 1;
215 for (i
= 0; i
< kOffset
+ size_
; ++i
) {
217 edge_ref_data_
[i
] = pix
;
218 edge_tst_data_
[i
] = pix
;
226 INSTANTIATE_TEST_CASE_P(
227 SSE4_1
, FilterEdgeTest8B
,
228 ::testing::Values(FilterEdgeTestFuncs(av1_filter_intra_edge_c
,
229 av1_filter_intra_edge_sse4_1
)));
230 #endif // HAVE_SSE4_1
232 //////////////////////////////////////////////////////////////////////////////
233 // High bit-depth version
234 //////////////////////////////////////////////////////////////////////////////
236 typedef void (*FEHB
)(uint16_t *p
, int size
, int strength
);
237 typedef libaom_test::FuncParam
<FEHB
> FilterEdgeTestFuncsHBD
;
239 class FilterEdgeTestHB
: public FilterEdgeTest
<FEHB
, uint16_t> {
241 void Execute(uint16_t *edge_tst
) {
242 params_
.ref_func(edge_ref_
, size_
, strength_
);
243 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst
, size_
, strength_
));
248 TEST_P(FilterEdgeTestHB
, RandomValues
) {
249 for (int iter
= 0; iter
< kIterations
&& !HasFatalFailure(); ++iter
) {
251 case 0: bit_depth_
= 8; break;
252 case 1: bit_depth_
= 10; break;
253 default: bit_depth_
= 12; break;
255 const int hi
= 1 << bit_depth_
;
256 strength_
= this->rng_(4);
257 size_
= 4 * (this->rng_(128 / 4) + 1) + 1;
260 for (i
= 0; i
< kOffset
+ size_
; ++i
) {
262 edge_ref_data_
[i
] = pix
;
263 edge_tst_data_
[i
] = pix
;
271 INSTANTIATE_TEST_CASE_P(SSE4_1
, FilterEdgeTestHB
,
272 ::testing::Values(FilterEdgeTestFuncsHBD(
273 av1_filter_intra_edge_high_c
,
274 av1_filter_intra_edge_high_sse4_1
)));
275 #endif // HAVE_SSE4_1
279 TEST_P(UpsampleTest8B
, DISABLED_Speed
) {
280 const int test_count
= 10000000;
282 for (int i
= 0; i
< kOffset
+ size_
; ++i
) {
283 edge_tst_data_
[i
] = rng_
.Rand8();
285 edge_tst_
= &edge_tst_data_
[kOffset
];
286 for (int iter
= 0; iter
< test_count
; ++iter
) {
287 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst_
, size_
));
291 TEST_P(UpsampleTestHB
, DISABLED_Speed
) {
292 const int test_count
= 10000000;
295 const int hi
= 1 << bit_depth_
;
296 for (int i
= 0; i
< kOffset
+ size_
; ++i
) {
297 edge_tst_data_
[i
] = rng_(hi
);
299 edge_tst_
= &edge_tst_data_
[kOffset
];
300 for (int iter
= 0; iter
< test_count
; ++iter
) {
301 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst_
, size_
, bit_depth_
));
305 TEST_P(FilterEdgeTest8B
, DISABLED_Speed
) {
306 const int test_count
= 10000000;
309 for (int i
= 0; i
< kOffset
+ size_
; ++i
) {
310 edge_tst_data_
[i
] = rng_
.Rand8();
312 edge_tst_
= &edge_tst_data_
[kOffset
];
313 for (int iter
= 0; iter
< test_count
; ++iter
) {
314 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst_
, size_
, strength_
));
315 // iterate over filter strengths (1,2,3)
316 strength_
= (strength_
== 3) ? 1 : strength_
+ 1;
320 TEST_P(FilterEdgeTestHB
, DISABLED_Speed
) {
321 const int test_count
= 10000000;
325 const int hi
= 1 << bit_depth_
;
326 for (int i
= 0; i
< kOffset
+ size_
; ++i
) {
327 edge_tst_data_
[i
] = rng_(hi
);
329 edge_tst_
= &edge_tst_data_
[kOffset
];
330 for (int iter
= 0; iter
< test_count
; ++iter
) {
331 ASM_REGISTER_STATE_CHECK(params_
.tst_func(edge_tst_
, size_
, strength_
));
332 // iterate over filter strengths (1,2,3)
333 strength_
= (strength_
== 3) ? 1 : strength_
+ 1;