blob: 5dd8c00beff019eae719e5bd2a3b91e1fefb172c [file] [log] [blame]
Deb Mukherjee81a81382014-09-15 12:59:19 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Deb Mukherjee81a81382014-09-15 12:59:19 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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*/
Deb Mukherjee81a81382014-09-15 12:59:19 -070011
12#include <string>
13
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Deb Mukherjee81a81382014-09-15 12:59:19 -070015
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
17#include "./aom_dsp_rtcd.h"
Jingning Han097d59c2015-07-29 14:51:36 -070018#include "test/acm_random.h"
19#include "test/clear_system_state.h"
20#include "test/register_state_check.h"
21#include "test/util.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070022#include "av1/common/blockd.h"
23#include "av1/common/pred_common.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070024#include "aom_mem/aom_mem.h"
Deb Mukherjee81a81382014-09-15 12:59:19 -070025
26namespace {
27
Yaowu Xuc27fc142016-08-22 16:08:15 -070028using libaom_test::ACMRandom;
Deb Mukherjee81a81382014-09-15 12:59:19 -070029
30const int count_test_block = 100000;
31
clang-format3a826f12016-08-11 17:46:05 -070032typedef void (*IntraPred)(uint16_t *dst, ptrdiff_t stride,
33 const uint16_t *above, const uint16_t *left, int bps);
Johann2967bf32016-06-22 16:08:10 -070034
35struct IntraPredFunc {
36 IntraPredFunc(IntraPred pred = NULL, IntraPred ref = NULL,
37 int block_size_value = 0, int bit_depth_value = 0)
clang-format3a826f12016-08-11 17:46:05 -070038 : pred_fn(pred), ref_fn(ref), block_size(block_size_value),
39 bit_depth(bit_depth_value) {}
Johann2967bf32016-06-22 16:08:10 -070040
41 IntraPred pred_fn;
42 IntraPred ref_fn;
43 int block_size;
44 int bit_depth;
45};
46
Yaowu Xuf883b422016-08-30 14:01:10 -070047class AV1IntraPredTest : public ::testing::TestWithParam<IntraPredFunc> {
Deb Mukherjee81a81382014-09-15 12:59:19 -070048 public:
clang-format3a826f12016-08-11 17:46:05 -070049 void RunTest(uint16_t *left_col, uint16_t *above_data, uint16_t *dst,
50 uint16_t *ref_dst) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070051 ACMRandom rnd(ACMRandom::DeterministicSeed());
Johann2967bf32016-06-22 16:08:10 -070052 const int block_size = params_.block_size;
53 above_row_ = above_data + 16;
Deb Mukherjee81a81382014-09-15 12:59:19 -070054 left_col_ = left_col;
55 dst_ = dst;
56 ref_dst_ = ref_dst;
Deb Mukherjee81a81382014-09-15 12:59:19 -070057 int error_count = 0;
58 for (int i = 0; i < count_test_block; ++i) {
59 // Fill edges with random data, try first with saturated values.
Johann2967bf32016-06-22 16:08:10 -070060 for (int x = -1; x <= block_size * 2; x++) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070061 if (i == 0) {
62 above_row_[x] = mask_;
63 } else {
64 above_row_[x] = rnd.Rand16() & mask_;
65 }
66 }
Johann2967bf32016-06-22 16:08:10 -070067 for (int y = 0; y < block_size; y++) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070068 if (i == 0) {
69 left_col_[y] = mask_;
70 } else {
71 left_col_[y] = rnd.Rand16() & mask_;
72 }
73 }
James Zerncffef112016-02-11 18:27:00 -080074 Predict();
Deb Mukherjee81a81382014-09-15 12:59:19 -070075 CheckPrediction(i, &error_count);
76 }
77 ASSERT_EQ(0, error_count);
78 }
79
Johann2967bf32016-06-22 16:08:10 -070080 protected:
81 virtual void SetUp() {
82 params_ = GetParam();
83 stride_ = params_.block_size * 3;
clang-format3a826f12016-08-11 17:46:05 -070084 mask_ = (1 << params_.bit_depth) - 1;
Johann2967bf32016-06-22 16:08:10 -070085 }
86
87 void Predict() {
88 const int bit_depth = params_.bit_depth;
89 params_.ref_fn(ref_dst_, stride_, above_row_, left_col_, bit_depth);
clang-format3a826f12016-08-11 17:46:05 -070090 ASM_REGISTER_STATE_CHECK(
91 params_.pred_fn(dst_, stride_, above_row_, left_col_, bit_depth));
Johann2967bf32016-06-22 16:08:10 -070092 }
93
94 void CheckPrediction(int test_case_number, int *error_count) const {
95 // For each pixel ensure that the calculated value is the same as reference.
96 const int block_size = params_.block_size;
97 for (int y = 0; y < block_size; y++) {
98 for (int x = 0; x < block_size; x++) {
99 *error_count += ref_dst_[x + y * stride_] != dst_[x + y * stride_];
100 if (*error_count == 1) {
101 ASSERT_EQ(ref_dst_[x + y * stride_], dst_[x + y * stride_])
clang-format3a826f12016-08-11 17:46:05 -0700102 << " Failed on Test Case Number " << test_case_number;
Johann2967bf32016-06-22 16:08:10 -0700103 }
104 }
105 }
106 }
107
Deb Mukherjee81a81382014-09-15 12:59:19 -0700108 uint16_t *above_row_;
109 uint16_t *left_col_;
110 uint16_t *dst_;
111 uint16_t *ref_dst_;
112 ptrdiff_t stride_;
113 int mask_;
Deb Mukherjee81a81382014-09-15 12:59:19 -0700114
Johann2967bf32016-06-22 16:08:10 -0700115 IntraPredFunc params_;
Deb Mukherjee81a81382014-09-15 12:59:19 -0700116};
117
Yaowu Xuf883b422016-08-30 14:01:10 -0700118TEST_P(AV1IntraPredTest, IntraPredTests) {
Deb Mukherjee81a81382014-09-15 12:59:19 -0700119 // max block size is 32
clang-format3a826f12016-08-11 17:46:05 -0700120 DECLARE_ALIGNED(16, uint16_t, left_col[2 * 32]);
121 DECLARE_ALIGNED(16, uint16_t, above_data[2 * 32 + 32]);
James Zernfd3658b2015-05-02 13:24:16 -0700122 DECLARE_ALIGNED(16, uint16_t, dst[3 * 32 * 32]);
123 DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 32 * 32]);
Deb Mukherjee81a81382014-09-15 12:59:19 -0700124 RunTest(left_col, above_data, dst, ref_dst);
125}
126
Deb Mukherjee81a81382014-09-15 12:59:19 -0700127#if HAVE_SSE2
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200128#if CONFIG_HIGHBITDEPTH
Yaowu Xu16591912017-05-03 08:58:12 -0700129const IntraPredFunc IntraPredTestVector8[] = {
130 IntraPredFunc(&aom_highbd_dc_predictor_32x32_sse2,
131 &aom_highbd_dc_predictor_32x32_c, 32, 8),
Urvang Joshi340593e2016-09-01 12:03:20 -0700132#if !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700133 IntraPredFunc(&aom_highbd_tm_predictor_16x16_sse2,
134 &aom_highbd_tm_predictor_16x16_c, 16, 8),
135 IntraPredFunc(&aom_highbd_tm_predictor_32x32_sse2,
136 &aom_highbd_tm_predictor_32x32_c, 32, 8),
Urvang Joshi340593e2016-09-01 12:03:20 -0700137#endif // !CONFIG_ALT_INTRA
138
Yaowu Xu16591912017-05-03 08:58:12 -0700139 IntraPredFunc(&aom_highbd_dc_predictor_4x4_sse2,
140 &aom_highbd_dc_predictor_4x4_c, 4, 8),
141 IntraPredFunc(&aom_highbd_dc_predictor_8x8_sse2,
142 &aom_highbd_dc_predictor_8x8_c, 8, 8),
143 IntraPredFunc(&aom_highbd_dc_predictor_16x16_sse2,
144 &aom_highbd_dc_predictor_16x16_c, 16, 8),
145 IntraPredFunc(&aom_highbd_v_predictor_4x4_sse2, &aom_highbd_v_predictor_4x4_c,
146 4, 8),
147 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2, &aom_highbd_v_predictor_8x8_c,
148 8, 8),
149 IntraPredFunc(&aom_highbd_v_predictor_16x16_sse2,
150 &aom_highbd_v_predictor_16x16_c, 16, 8),
151 IntraPredFunc(&aom_highbd_v_predictor_32x32_sse2,
152 &aom_highbd_v_predictor_32x32_c, 32, 8)
Urvang Joshi340593e2016-09-01 12:03:20 -0700153#if !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700154 ,
155 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
156 &aom_highbd_tm_predictor_4x4_c, 4, 8),
157 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
158 &aom_highbd_tm_predictor_8x8_c, 8, 8)
Urvang Joshi340593e2016-09-01 12:03:20 -0700159#endif // !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700160};
Johann1c967f12015-06-29 17:04:58 -0700161
Yaowu Xu16591912017-05-03 08:58:12 -0700162INSTANTIATE_TEST_CASE_P(SSE2_TO_C_8, AV1IntraPredTest,
163 ::testing::ValuesIn(IntraPredTestVector8));
Deb Mukherjee81a81382014-09-15 12:59:19 -0700164
Yaowu Xu16591912017-05-03 08:58:12 -0700165const IntraPredFunc IntraPredTestVector10[] = {
166 IntraPredFunc(&aom_highbd_dc_predictor_32x32_sse2,
167 &aom_highbd_dc_predictor_32x32_c, 32, 10),
Urvang Joshi340593e2016-09-01 12:03:20 -0700168#if !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700169 IntraPredFunc(&aom_highbd_tm_predictor_16x16_sse2,
170 &aom_highbd_tm_predictor_16x16_c, 16, 10),
171 IntraPredFunc(&aom_highbd_tm_predictor_32x32_sse2,
172 &aom_highbd_tm_predictor_32x32_c, 32, 10),
Urvang Joshi340593e2016-09-01 12:03:20 -0700173#endif // !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700174 IntraPredFunc(&aom_highbd_dc_predictor_4x4_sse2,
175 &aom_highbd_dc_predictor_4x4_c, 4, 10),
176 IntraPredFunc(&aom_highbd_dc_predictor_8x8_sse2,
177 &aom_highbd_dc_predictor_8x8_c, 8, 10),
178 IntraPredFunc(&aom_highbd_dc_predictor_16x16_sse2,
179 &aom_highbd_dc_predictor_16x16_c, 16, 10),
180 IntraPredFunc(&aom_highbd_v_predictor_4x4_sse2, &aom_highbd_v_predictor_4x4_c,
181 4, 10),
182 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2, &aom_highbd_v_predictor_8x8_c,
183 8, 10),
184 IntraPredFunc(&aom_highbd_v_predictor_16x16_sse2,
185 &aom_highbd_v_predictor_16x16_c, 16, 10),
186 IntraPredFunc(&aom_highbd_v_predictor_32x32_sse2,
187 &aom_highbd_v_predictor_32x32_c, 32, 10)
Urvang Joshi340593e2016-09-01 12:03:20 -0700188#if !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700189 ,
190 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
191 &aom_highbd_tm_predictor_4x4_c, 4, 10),
192 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
193 &aom_highbd_tm_predictor_8x8_c, 8, 10)
Urvang Joshi340593e2016-09-01 12:03:20 -0700194#endif // !CONFIG_ALT_INTRA
Yaowu Xu16591912017-05-03 08:58:12 -0700195};
196
197INSTANTIATE_TEST_CASE_P(SSE2_TO_C_10, AV1IntraPredTest,
198 ::testing::ValuesIn(IntraPredTestVector10));
199
200const IntraPredFunc IntraPredTestVector12[] = {
201 IntraPredFunc(&aom_highbd_dc_predictor_32x32_sse2,
202 &aom_highbd_dc_predictor_32x32_c, 32, 12),
203#if !CONFIG_ALT_INTRA
204 IntraPredFunc(&aom_highbd_tm_predictor_16x16_sse2,
205 &aom_highbd_tm_predictor_16x16_c, 16, 12),
206 IntraPredFunc(&aom_highbd_tm_predictor_32x32_sse2,
207 &aom_highbd_tm_predictor_32x32_c, 32, 12),
208#endif // !CONFIG_ALT_INTRA
209 IntraPredFunc(&aom_highbd_dc_predictor_4x4_sse2,
210 &aom_highbd_dc_predictor_4x4_c, 4, 12),
211 IntraPredFunc(&aom_highbd_dc_predictor_8x8_sse2,
212 &aom_highbd_dc_predictor_8x8_c, 8, 12),
213 IntraPredFunc(&aom_highbd_dc_predictor_16x16_sse2,
214 &aom_highbd_dc_predictor_16x16_c, 16, 12),
215 IntraPredFunc(&aom_highbd_v_predictor_4x4_sse2, &aom_highbd_v_predictor_4x4_c,
216 4, 12),
217 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2, &aom_highbd_v_predictor_8x8_c,
218 8, 12),
219 IntraPredFunc(&aom_highbd_v_predictor_16x16_sse2,
220 &aom_highbd_v_predictor_16x16_c, 16, 12),
221 IntraPredFunc(&aom_highbd_v_predictor_32x32_sse2,
222 &aom_highbd_v_predictor_32x32_c, 32, 12)
223#if !CONFIG_ALT_INTRA
224 ,
225 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
226 &aom_highbd_tm_predictor_4x4_c, 4, 12),
227 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
228 &aom_highbd_tm_predictor_8x8_c, 8, 12)
229#endif // !CONFIG_ALT_INTRA
230};
231
232INSTANTIATE_TEST_CASE_P(SSE2_TO_C_12, AV1IntraPredTest,
233 ::testing::ValuesIn(IntraPredTestVector12));
Jian Zhou26a6ce42015-12-22 16:51:57 -0800234
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200235#endif // CONFIG_HIGHBITDEPTH
Deb Mukherjee81a81382014-09-15 12:59:19 -0700236#endif // HAVE_SSE2
237} // namespace