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 <string>
13
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15
16 #include "config/aom_config.h"
17 #include "config/aom_dsp_rtcd.h"
18
19 #include "test/acm_random.h"
20 #include "test/clear_system_state.h"
21 #include "test/register_state_check.h"
22 #include "test/util.h"
23 #include "av1/common/blockd.h"
24 #include "av1/common/common.h"
25 #include "av1/common/pred_common.h"
26 #include "aom_mem/aom_mem.h"
27
28 namespace {
29
30 using libaom_test::ACMRandom;
31
32 const int count_test_block = 100000;
33
34 typedef void (*HighbdIntraPred)(uint16_t *dst, ptrdiff_t stride,
35 const uint16_t *above, const uint16_t *left,
36 int bps);
37 typedef void (*IntraPred)(uint8_t *dst, ptrdiff_t stride, const uint8_t *above,
38 const uint8_t *left);
39
40 } // namespace
41
42 // NOTE: Under gcc version 7.3.0 (Debian 7.3.0-5), if this template is in the
43 // anonymous namespace, then we get a strange compiler warning in
44 // the begin() and end() methods of the ParamGenerator template class in
45 // gtest/internal/gtest-param-util.h:
46 // warning: ‘<anonymous>’ is used uninitialized in this function
47 // As a workaround, put this template outside the anonymous namespace.
48 // See bug aomedia:2003.
49 template <typename FuncType>
50 struct IntraPredFunc {
IntraPredFuncIntraPredFunc51 IntraPredFunc(FuncType pred = NULL, FuncType ref = NULL,
52 int block_width_value = 0, int block_height_value = 0,
53 int bit_depth_value = 0)
54 : pred_fn(pred), ref_fn(ref), block_width(block_width_value),
55 block_height(block_height_value), bit_depth(bit_depth_value) {}
56
57 FuncType pred_fn;
58 FuncType ref_fn;
59 int block_width;
60 int block_height;
61 int bit_depth;
62 };
63
64 namespace {
65
66 template <typename FuncType, typename Pixel>
67 class AV1IntraPredTest
68 : public ::testing::TestWithParam<IntraPredFunc<FuncType> > {
69 public:
RunTest(Pixel * left_col,Pixel * above_data,Pixel * dst,Pixel * ref_dst)70 void RunTest(Pixel *left_col, Pixel *above_data, Pixel *dst, Pixel *ref_dst) {
71 ACMRandom rnd(ACMRandom::DeterministicSeed());
72 const int block_width = params_.block_width;
73 const int block_height = params_.block_height;
74 above_row_ = above_data + 16;
75 left_col_ = left_col;
76 dst_ = dst;
77 ref_dst_ = ref_dst;
78 int error_count = 0;
79 for (int i = 0; i < count_test_block; ++i) {
80 // Fill edges with random data, try first with saturated values.
81 for (int x = -1; x <= block_width * 2; x++) {
82 if (i == 0) {
83 above_row_[x] = mask_;
84 } else {
85 above_row_[x] = rnd.Rand16() & mask_;
86 }
87 }
88 for (int y = 0; y < block_height; y++) {
89 if (i == 0) {
90 left_col_[y] = mask_;
91 } else {
92 left_col_[y] = rnd.Rand16() & mask_;
93 }
94 }
95 Predict();
96 CheckPrediction(i, &error_count);
97 }
98 ASSERT_EQ(0, error_count);
99 }
100
101 protected:
SetUp()102 virtual void SetUp() {
103 params_ = this->GetParam();
104 stride_ = params_.block_width * 3;
105 mask_ = (1 << params_.bit_depth) - 1;
106 }
107
108 virtual void Predict() = 0;
109
CheckPrediction(int test_case_number,int * error_count) const110 void CheckPrediction(int test_case_number, int *error_count) const {
111 // For each pixel ensure that the calculated value is the same as reference.
112 const int block_width = params_.block_width;
113 const int block_height = params_.block_height;
114 for (int y = 0; y < block_height; y++) {
115 for (int x = 0; x < block_width; x++) {
116 *error_count += ref_dst_[x + y * stride_] != dst_[x + y * stride_];
117 if (*error_count == 1) {
118 ASSERT_EQ(ref_dst_[x + y * stride_], dst_[x + y * stride_])
119 << " Failed on Test Case Number " << test_case_number
120 << " location: x = " << x << " y = " << y;
121 }
122 }
123 }
124 }
125
126 Pixel *above_row_;
127 Pixel *left_col_;
128 Pixel *dst_;
129 Pixel *ref_dst_;
130 ptrdiff_t stride_;
131 int mask_;
132
133 IntraPredFunc<FuncType> params_;
134 };
135
136 class HighbdIntraPredTest : public AV1IntraPredTest<HighbdIntraPred, uint16_t> {
137 protected:
Predict()138 void Predict() {
139 const int bit_depth = params_.bit_depth;
140 params_.ref_fn(ref_dst_, stride_, above_row_, left_col_, bit_depth);
141 ASM_REGISTER_STATE_CHECK(
142 params_.pred_fn(dst_, stride_, above_row_, left_col_, bit_depth));
143 }
144 };
145
146 class LowbdIntraPredTest : public AV1IntraPredTest<IntraPred, uint8_t> {
147 protected:
Predict()148 void Predict() {
149 params_.ref_fn(ref_dst_, stride_, above_row_, left_col_);
150 ASM_REGISTER_STATE_CHECK(
151 params_.pred_fn(dst_, stride_, above_row_, left_col_));
152 }
153 };
154
155 // Suppress an unitialized warning. Once there are implementations to test then
156 // this can be restored.
TEST_P(HighbdIntraPredTest,Bitexact)157 TEST_P(HighbdIntraPredTest, Bitexact) {
158 // max block size is 64
159 DECLARE_ALIGNED(16, uint16_t, left_col[2 * 64]);
160 DECLARE_ALIGNED(16, uint16_t, above_data[2 * 64 + 64]);
161 DECLARE_ALIGNED(16, uint16_t, dst[3 * 64 * 64]);
162 DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 64 * 64]);
163 av1_zero(left_col);
164 av1_zero(above_data);
165 RunTest(left_col, above_data, dst, ref_dst);
166 }
167
168 // Same issue as above but for arm.
169 #if !HAVE_NEON
TEST_P(LowbdIntraPredTest,Bitexact)170 TEST_P(LowbdIntraPredTest, Bitexact) {
171 // max block size is 32
172 DECLARE_ALIGNED(16, uint8_t, left_col[2 * 32]);
173 DECLARE_ALIGNED(16, uint8_t, above_data[2 * 32 + 32]);
174 DECLARE_ALIGNED(16, uint8_t, dst[3 * 32 * 32]);
175 DECLARE_ALIGNED(16, uint8_t, ref_dst[3 * 32 * 32]);
176 av1_zero(left_col);
177 av1_zero(above_data);
178 RunTest(left_col, above_data, dst, ref_dst);
179 }
180 #endif // !HAVE_NEON
181
182 // -----------------------------------------------------------------------------
183 // High Bit Depth Tests
184 #define highbd_entry(type, width, height, opt, bd) \
185 IntraPredFunc<HighbdIntraPred>( \
186 &aom_highbd_##type##_predictor_##width##x##height##_##opt, \
187 &aom_highbd_##type##_predictor_##width##x##height##_c, width, height, \
188 bd)
189
190 #if 0
191 #define highbd_intrapred(type, opt, bd) \
192 highbd_entry(type, 4, 4, opt, bd), highbd_entry(type, 4, 8, opt, bd), \
193 highbd_entry(type, 8, 4, opt, bd), highbd_entry(type, 8, 8, opt, bd), \
194 highbd_entry(type, 8, 16, opt, bd), highbd_entry(type, 16, 8, opt, bd), \
195 highbd_entry(type, 16, 16, opt, bd), \
196 highbd_entry(type, 16, 32, opt, bd), \
197 highbd_entry(type, 32, 16, opt, bd), highbd_entry(type, 32, 32, opt, bd)
198 #endif
199
200 // ---------------------------------------------------------------------------
201 // Low Bit Depth Tests
202
203 #define lowbd_entry(type, width, height, opt) \
204 IntraPredFunc<IntraPred>(&aom_##type##_predictor_##width##x##height##_##opt, \
205 &aom_##type##_predictor_##width##x##height##_c, \
206 width, height, 8)
207
208 #define lowbd_intrapred(type, opt) \
209 lowbd_entry(type, 4, 4, opt), lowbd_entry(type, 4, 8, opt), \
210 lowbd_entry(type, 8, 4, opt), lowbd_entry(type, 8, 8, opt), \
211 lowbd_entry(type, 8, 16, opt), lowbd_entry(type, 16, 8, opt), \
212 lowbd_entry(type, 16, 16, opt), lowbd_entry(type, 16, 32, opt), \
213 lowbd_entry(type, 32, 16, opt), lowbd_entry(type, 32, 32, opt)
214
215 #if HAVE_SSE2
216 const IntraPredFunc<IntraPred> LowbdIntraPredTestVector[] = {
217 lowbd_intrapred(dc, sse2), lowbd_intrapred(dc_top, sse2),
218 lowbd_intrapred(dc_left, sse2), lowbd_intrapred(dc_128, sse2),
219 lowbd_intrapred(v, sse2), lowbd_intrapred(h, sse2),
220 };
221
222 INSTANTIATE_TEST_CASE_P(SSE2, LowbdIntraPredTest,
223 ::testing::ValuesIn(LowbdIntraPredTestVector));
224
225 #endif // HAVE_SSE2
226
227 #if HAVE_SSSE3
228 const IntraPredFunc<IntraPred> LowbdIntraPredTestVectorSsse3[] = {
229 lowbd_intrapred(paeth, ssse3),
230 lowbd_intrapred(smooth, ssse3),
231 };
232
233 INSTANTIATE_TEST_CASE_P(SSSE3, LowbdIntraPredTest,
234 ::testing::ValuesIn(LowbdIntraPredTestVectorSsse3));
235
236 #endif // HAVE_SSSE3
237
238 #if HAVE_AVX2
239 const IntraPredFunc<IntraPred> LowbdIntraPredTestVectorAvx2[] = {
240 lowbd_entry(dc, 32, 32, avx2), lowbd_entry(dc_top, 32, 32, avx2),
241 lowbd_entry(dc_left, 32, 32, avx2), lowbd_entry(dc_128, 32, 32, avx2),
242 lowbd_entry(v, 32, 32, avx2), lowbd_entry(h, 32, 32, avx2),
243 lowbd_entry(dc, 32, 16, avx2), lowbd_entry(dc_top, 32, 16, avx2),
244 lowbd_entry(dc_left, 32, 16, avx2), lowbd_entry(dc_128, 32, 16, avx2),
245 lowbd_entry(v, 32, 16, avx2), lowbd_entry(paeth, 16, 8, avx2),
246 lowbd_entry(paeth, 16, 16, avx2), lowbd_entry(paeth, 16, 32, avx2),
247 lowbd_entry(paeth, 32, 16, avx2), lowbd_entry(paeth, 32, 32, avx2),
248 };
249
250 INSTANTIATE_TEST_CASE_P(AVX2, LowbdIntraPredTest,
251 ::testing::ValuesIn(LowbdIntraPredTestVectorAvx2));
252
253 #endif // HAVE_AVX2
254
255 #if HAVE_NEON
256 const IntraPredFunc<HighbdIntraPred> HighbdIntraPredTestVectorNeon[] = {
257 highbd_entry(dc, 4, 4, neon, 8), highbd_entry(dc, 8, 8, neon, 8),
258 highbd_entry(dc, 16, 16, neon, 8), highbd_entry(dc, 32, 32, neon, 8),
259 highbd_entry(dc, 64, 64, neon, 8),
260 };
261
262 INSTANTIATE_TEST_CASE_P(NEON, HighbdIntraPredTest,
263 ::testing::ValuesIn(HighbdIntraPredTestVectorNeon));
264
265 #endif // HAVE_NEON
266 } // namespace
267