blob: e635234096f041c80cd0b5125817cb84e1179715 [file] [log] [blame]
Deb Mukherjee81a81382014-09-15 12:59:19 -07001/*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <string>
12
Deb Mukherjee81a81382014-09-15 12:59:19 -070013#include "third_party/googletest/src/include/gtest/gtest.h"
14
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
16#include "./aom_dsp_rtcd.h"
Jingning Han097d59c2015-07-29 14:51:36 -070017#include "test/acm_random.h"
18#include "test/clear_system_state.h"
19#include "test/register_state_check.h"
20#include "test/util.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "av1/common/blockd.h"
22#include "av1/common/pred_common.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070023#include "aom_mem/aom_mem.h"
Deb Mukherjee81a81382014-09-15 12:59:19 -070024
25namespace {
26
Yaowu Xuc27fc142016-08-22 16:08:15 -070027using libaom_test::ACMRandom;
Deb Mukherjee81a81382014-09-15 12:59:19 -070028
29const int count_test_block = 100000;
30
clang-format3a826f12016-08-11 17:46:05 -070031typedef void (*IntraPred)(uint16_t *dst, ptrdiff_t stride,
32 const uint16_t *above, const uint16_t *left, int bps);
Johann2967bf32016-06-22 16:08:10 -070033
34struct IntraPredFunc {
35 IntraPredFunc(IntraPred pred = NULL, IntraPred ref = NULL,
36 int block_size_value = 0, int bit_depth_value = 0)
clang-format3a826f12016-08-11 17:46:05 -070037 : pred_fn(pred), ref_fn(ref), block_size(block_size_value),
38 bit_depth(bit_depth_value) {}
Johann2967bf32016-06-22 16:08:10 -070039
40 IntraPred pred_fn;
41 IntraPred ref_fn;
42 int block_size;
43 int bit_depth;
44};
45
Yaowu Xuf883b422016-08-30 14:01:10 -070046class AV1IntraPredTest : public ::testing::TestWithParam<IntraPredFunc> {
Deb Mukherjee81a81382014-09-15 12:59:19 -070047 public:
clang-format3a826f12016-08-11 17:46:05 -070048 void RunTest(uint16_t *left_col, uint16_t *above_data, uint16_t *dst,
49 uint16_t *ref_dst) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070050 ACMRandom rnd(ACMRandom::DeterministicSeed());
Johann2967bf32016-06-22 16:08:10 -070051 const int block_size = params_.block_size;
52 above_row_ = above_data + 16;
Deb Mukherjee81a81382014-09-15 12:59:19 -070053 left_col_ = left_col;
54 dst_ = dst;
55 ref_dst_ = ref_dst;
Deb Mukherjee81a81382014-09-15 12:59:19 -070056 int error_count = 0;
57 for (int i = 0; i < count_test_block; ++i) {
58 // Fill edges with random data, try first with saturated values.
Johann2967bf32016-06-22 16:08:10 -070059 for (int x = -1; x <= block_size * 2; x++) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070060 if (i == 0) {
61 above_row_[x] = mask_;
62 } else {
63 above_row_[x] = rnd.Rand16() & mask_;
64 }
65 }
Johann2967bf32016-06-22 16:08:10 -070066 for (int y = 0; y < block_size; y++) {
Deb Mukherjee81a81382014-09-15 12:59:19 -070067 if (i == 0) {
68 left_col_[y] = mask_;
69 } else {
70 left_col_[y] = rnd.Rand16() & mask_;
71 }
72 }
James Zerncffef112016-02-11 18:27:00 -080073 Predict();
Deb Mukherjee81a81382014-09-15 12:59:19 -070074 CheckPrediction(i, &error_count);
75 }
76 ASSERT_EQ(0, error_count);
77 }
78
Johann2967bf32016-06-22 16:08:10 -070079 protected:
80 virtual void SetUp() {
81 params_ = GetParam();
82 stride_ = params_.block_size * 3;
clang-format3a826f12016-08-11 17:46:05 -070083 mask_ = (1 << params_.bit_depth) - 1;
Johann2967bf32016-06-22 16:08:10 -070084 }
85
86 void Predict() {
87 const int bit_depth = params_.bit_depth;
88 params_.ref_fn(ref_dst_, stride_, above_row_, left_col_, bit_depth);
clang-format3a826f12016-08-11 17:46:05 -070089 ASM_REGISTER_STATE_CHECK(
90 params_.pred_fn(dst_, stride_, above_row_, left_col_, bit_depth));
Johann2967bf32016-06-22 16:08:10 -070091 }
92
93 void CheckPrediction(int test_case_number, int *error_count) const {
94 // For each pixel ensure that the calculated value is the same as reference.
95 const int block_size = params_.block_size;
96 for (int y = 0; y < block_size; y++) {
97 for (int x = 0; x < block_size; x++) {
98 *error_count += ref_dst_[x + y * stride_] != dst_[x + y * stride_];
99 if (*error_count == 1) {
100 ASSERT_EQ(ref_dst_[x + y * stride_], dst_[x + y * stride_])
clang-format3a826f12016-08-11 17:46:05 -0700101 << " Failed on Test Case Number " << test_case_number;
Johann2967bf32016-06-22 16:08:10 -0700102 }
103 }
104 }
105 }
106
Deb Mukherjee81a81382014-09-15 12:59:19 -0700107 uint16_t *above_row_;
108 uint16_t *left_col_;
109 uint16_t *dst_;
110 uint16_t *ref_dst_;
111 ptrdiff_t stride_;
112 int mask_;
Deb Mukherjee81a81382014-09-15 12:59:19 -0700113
Johann2967bf32016-06-22 16:08:10 -0700114 IntraPredFunc params_;
Deb Mukherjee81a81382014-09-15 12:59:19 -0700115};
116
Yaowu Xuf883b422016-08-30 14:01:10 -0700117TEST_P(AV1IntraPredTest, IntraPredTests) {
Deb Mukherjee81a81382014-09-15 12:59:19 -0700118 // max block size is 32
clang-format3a826f12016-08-11 17:46:05 -0700119 DECLARE_ALIGNED(16, uint16_t, left_col[2 * 32]);
120 DECLARE_ALIGNED(16, uint16_t, above_data[2 * 32 + 32]);
James Zernfd3658b2015-05-02 13:24:16 -0700121 DECLARE_ALIGNED(16, uint16_t, dst[3 * 32 * 32]);
122 DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 32 * 32]);
Deb Mukherjee81a81382014-09-15 12:59:19 -0700123 RunTest(left_col, above_data, dst, ref_dst);
124}
125
Deb Mukherjee81a81382014-09-15 12:59:19 -0700126#if HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -0700127#if CONFIG_AOM_HIGHBITDEPTH
clang-format3a826f12016-08-11 17:46:05 -0700128INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700129 SSE2_TO_C_8, AV1IntraPredTest,
130 ::testing::Values(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 Xuf883b422016-08-30 14:01:10 -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 Xuf883b422016-08-30 14:01:10 -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,
146 &aom_highbd_v_predictor_4x4_c, 4, 8),
147 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2,
148 &aom_highbd_v_predictor_8x8_c, 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,
Urvang Joshi340593e2016-09-01 12:03:20 -0700152 &aom_highbd_v_predictor_32x32_c, 32, 8)
153#if !CONFIG_ALT_INTRA
154 ,
Yaowu Xuf883b422016-08-30 14:01:10 -0700155 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
156 &aom_highbd_tm_predictor_4x4_c, 4, 8),
157 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
Urvang Joshi340593e2016-09-01 12:03:20 -0700158 &aom_highbd_tm_predictor_8x8_c, 8, 8)
159#endif // !CONFIG_ALT_INTRA
160 ));
Johann1c967f12015-06-29 17:04:58 -0700161
clang-format3a826f12016-08-11 17:46:05 -0700162INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700163 SSE2_TO_C_10, AV1IntraPredTest,
164 ::testing::Values(IntraPredFunc(&aom_highbd_dc_predictor_32x32_sse2,
165 &aom_highbd_dc_predictor_32x32_c, 32, 10),
Urvang Joshi340593e2016-09-01 12:03:20 -0700166#if !CONFIG_ALT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700167 IntraPredFunc(&aom_highbd_tm_predictor_16x16_sse2,
168 &aom_highbd_tm_predictor_16x16_c, 16, 10),
169 IntraPredFunc(&aom_highbd_tm_predictor_32x32_sse2,
170 &aom_highbd_tm_predictor_32x32_c, 32, 10),
Urvang Joshi340593e2016-09-01 12:03:20 -0700171#endif // !CONFIG_ALT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700172 IntraPredFunc(&aom_highbd_dc_predictor_4x4_sse2,
173 &aom_highbd_dc_predictor_4x4_c, 4, 10),
174 IntraPredFunc(&aom_highbd_dc_predictor_8x8_sse2,
175 &aom_highbd_dc_predictor_8x8_c, 8, 10),
176 IntraPredFunc(&aom_highbd_dc_predictor_16x16_sse2,
177 &aom_highbd_dc_predictor_16x16_c, 16, 10),
178 IntraPredFunc(&aom_highbd_v_predictor_4x4_sse2,
179 &aom_highbd_v_predictor_4x4_c, 4, 10),
180 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2,
181 &aom_highbd_v_predictor_8x8_c, 8, 10),
182 IntraPredFunc(&aom_highbd_v_predictor_16x16_sse2,
183 &aom_highbd_v_predictor_16x16_c, 16, 10),
184 IntraPredFunc(&aom_highbd_v_predictor_32x32_sse2,
Urvang Joshi340593e2016-09-01 12:03:20 -0700185 &aom_highbd_v_predictor_32x32_c, 32, 10)
186#if !CONFIG_ALT_INTRA
187 ,
Yaowu Xuf883b422016-08-30 14:01:10 -0700188 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
189 &aom_highbd_tm_predictor_4x4_c, 4, 10),
190 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
Urvang Joshi340593e2016-09-01 12:03:20 -0700191 &aom_highbd_tm_predictor_8x8_c, 8, 10)
192#endif // !CONFIG_ALT_INTRA
193 ));
Deb Mukherjee81a81382014-09-15 12:59:19 -0700194
clang-format3a826f12016-08-11 17:46:05 -0700195INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700196 SSE2_TO_C_12, AV1IntraPredTest,
197 ::testing::Values(IntraPredFunc(&aom_highbd_dc_predictor_32x32_sse2,
198 &aom_highbd_dc_predictor_32x32_c, 32, 12),
Urvang Joshi340593e2016-09-01 12:03:20 -0700199#if !CONFIG_ALT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700200 IntraPredFunc(&aom_highbd_tm_predictor_16x16_sse2,
201 &aom_highbd_tm_predictor_16x16_c, 16, 12),
202 IntraPredFunc(&aom_highbd_tm_predictor_32x32_sse2,
203 &aom_highbd_tm_predictor_32x32_c, 32, 12),
Urvang Joshi340593e2016-09-01 12:03:20 -0700204#endif // !CONFIG_ALT_INTRA
Yaowu Xuf883b422016-08-30 14:01:10 -0700205 IntraPredFunc(&aom_highbd_dc_predictor_4x4_sse2,
206 &aom_highbd_dc_predictor_4x4_c, 4, 12),
207 IntraPredFunc(&aom_highbd_dc_predictor_8x8_sse2,
208 &aom_highbd_dc_predictor_8x8_c, 8, 12),
209 IntraPredFunc(&aom_highbd_dc_predictor_16x16_sse2,
210 &aom_highbd_dc_predictor_16x16_c, 16, 12),
211 IntraPredFunc(&aom_highbd_v_predictor_4x4_sse2,
212 &aom_highbd_v_predictor_4x4_c, 4, 12),
213 IntraPredFunc(&aom_highbd_v_predictor_8x8_sse2,
214 &aom_highbd_v_predictor_8x8_c, 8, 12),
215 IntraPredFunc(&aom_highbd_v_predictor_16x16_sse2,
216 &aom_highbd_v_predictor_16x16_c, 16, 12),
217 IntraPredFunc(&aom_highbd_v_predictor_32x32_sse2,
Urvang Joshi340593e2016-09-01 12:03:20 -0700218 &aom_highbd_v_predictor_32x32_c, 32, 12)
219#if !CONFIG_ALT_INTRA
220 ,
Yaowu Xuf883b422016-08-30 14:01:10 -0700221 IntraPredFunc(&aom_highbd_tm_predictor_4x4_sse2,
222 &aom_highbd_tm_predictor_4x4_c, 4, 12),
223 IntraPredFunc(&aom_highbd_tm_predictor_8x8_sse2,
Urvang Joshi340593e2016-09-01 12:03:20 -0700224 &aom_highbd_tm_predictor_8x8_c, 8, 12)
225#endif // !CONFIG_ALT_INTRA
226 ));
Jian Zhou26a6ce42015-12-22 16:51:57 -0800227
Yaowu Xuf883b422016-08-30 14:01:10 -0700228#endif // CONFIG_AOM_HIGHBITDEPTH
Deb Mukherjee81a81382014-09-15 12:59:19 -0700229#endif // HAVE_SSE2
230} // namespace