Merge "remove mmx variance functions"
[aom.git] / test / vp9_intrapred_test.cc
blob416f3c322ed0411644862dbe2697c104f31774c2
1 /*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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 */
11 #include <string>
13 #include "third_party/googletest/src/include/gtest/gtest.h"
15 #include "./vpx_config.h"
16 #include "./vpx_dsp_rtcd.h"
17 #include "test/acm_random.h"
18 #include "test/clear_system_state.h"
19 #include "test/register_state_check.h"
20 #include "test/util.h"
21 #include "vp9/common/vp9_blockd.h"
22 #include "vp9/common/vp9_pred_common.h"
23 #include "vpx_mem/vpx_mem.h"
25 namespace {
27 using libvpx_test::ACMRandom;
29 const int count_test_block = 100000;
31 // Base class for VP9 intra prediction tests.
32 class VP9IntraPredBase {
33 public:
34 virtual ~VP9IntraPredBase() { libvpx_test::ClearSystemState(); }
36 protected:
37 virtual void Predict() = 0;
39 void CheckPrediction(int test_case_number, int *error_count) const {
40 // For each pixel ensure that the calculated value is the same as reference.
41 for (int y = 0; y < block_size_; y++) {
42 for (int x = 0; x < block_size_; x++) {
43 *error_count += ref_dst_[x + y * stride_] != dst_[x + y * stride_];
44 if (*error_count == 1) {
45 ASSERT_EQ(ref_dst_[x + y * stride_], dst_[x + y * stride_])
46 << " Failed on Test Case Number "<< test_case_number;
52 void RunTest(uint16_t* left_col, uint16_t* above_data,
53 uint16_t* dst, uint16_t* ref_dst) {
54 ACMRandom rnd(ACMRandom::DeterministicSeed());
55 left_col_ = left_col;
56 dst_ = dst;
57 ref_dst_ = ref_dst;
58 above_row_ = above_data + 16;
59 int error_count = 0;
60 for (int i = 0; i < count_test_block; ++i) {
61 // Fill edges with random data, try first with saturated values.
62 for (int x = -1; x <= block_size_*2; x++) {
63 if (i == 0) {
64 above_row_[x] = mask_;
65 } else {
66 above_row_[x] = rnd.Rand16() & mask_;
69 for (int y = 0; y < block_size_; y++) {
70 if (i == 0) {
71 left_col_[y] = mask_;
72 } else {
73 left_col_[y] = rnd.Rand16() & mask_;
76 Predict();
77 CheckPrediction(i, &error_count);
79 ASSERT_EQ(0, error_count);
82 int block_size_;
83 uint16_t *above_row_;
84 uint16_t *left_col_;
85 uint16_t *dst_;
86 uint16_t *ref_dst_;
87 ptrdiff_t stride_;
88 int mask_;
91 typedef void (*intra_pred_fn_t)(
92 uint16_t *dst, ptrdiff_t stride, const uint16_t *above,
93 const uint16_t *left, int bps);
94 typedef std::tr1::tuple<intra_pred_fn_t,
95 intra_pred_fn_t, int, int> intra_pred_params_t;
96 class VP9IntraPredTest
97 : public VP9IntraPredBase,
98 public ::testing::TestWithParam<intra_pred_params_t> {
100 virtual void SetUp() {
101 pred_fn_ = GET_PARAM(0);
102 ref_fn_ = GET_PARAM(1);
103 block_size_ = GET_PARAM(2);
104 bit_depth_ = GET_PARAM(3);
105 stride_ = block_size_ * 3;
106 mask_ = (1 << bit_depth_) - 1;
109 virtual void Predict() {
110 const uint16_t *const_above_row = above_row_;
111 const uint16_t *const_left_col = left_col_;
112 ref_fn_(ref_dst_, stride_, const_above_row, const_left_col, bit_depth_);
113 ASM_REGISTER_STATE_CHECK(pred_fn_(dst_, stride_, const_above_row,
114 const_left_col, bit_depth_));
116 intra_pred_fn_t pred_fn_;
117 intra_pred_fn_t ref_fn_;
118 int bit_depth_;
121 TEST_P(VP9IntraPredTest, IntraPredTests) {
122 // max block size is 32
123 DECLARE_ALIGNED(16, uint16_t, left_col[2*32]);
124 DECLARE_ALIGNED(16, uint16_t, above_data[2*32+32]);
125 DECLARE_ALIGNED(16, uint16_t, dst[3 * 32 * 32]);
126 DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 32 * 32]);
127 RunTest(left_col, above_data, dst, ref_dst);
130 using std::tr1::make_tuple;
132 #if HAVE_SSE2
133 #if CONFIG_VP9_HIGHBITDEPTH
134 #if CONFIG_USE_X86INC
135 INSTANTIATE_TEST_CASE_P(SSE2_TO_C_8, VP9IntraPredTest,
136 ::testing::Values(
137 make_tuple(&vpx_highbd_dc_predictor_32x32_sse2,
138 &vpx_highbd_dc_predictor_32x32_c, 32, 8),
139 make_tuple(&vpx_highbd_tm_predictor_16x16_sse2,
140 &vpx_highbd_tm_predictor_16x16_c, 16, 8),
141 make_tuple(&vpx_highbd_tm_predictor_32x32_sse2,
142 &vpx_highbd_tm_predictor_32x32_c, 32, 8),
143 make_tuple(&vpx_highbd_dc_predictor_4x4_sse2,
144 &vpx_highbd_dc_predictor_4x4_c, 4, 8),
145 make_tuple(&vpx_highbd_dc_predictor_8x8_sse2,
146 &vpx_highbd_dc_predictor_8x8_c, 8, 8),
147 make_tuple(&vpx_highbd_dc_predictor_16x16_sse2,
148 &vpx_highbd_dc_predictor_16x16_c, 16, 8),
149 make_tuple(&vpx_highbd_v_predictor_4x4_sse2,
150 &vpx_highbd_v_predictor_4x4_c, 4, 8),
151 make_tuple(&vpx_highbd_v_predictor_8x8_sse2,
152 &vpx_highbd_v_predictor_8x8_c, 8, 8),
153 make_tuple(&vpx_highbd_v_predictor_16x16_sse2,
154 &vpx_highbd_v_predictor_16x16_c, 16, 8),
155 make_tuple(&vpx_highbd_v_predictor_32x32_sse2,
156 &vpx_highbd_v_predictor_32x32_c, 32, 8),
157 make_tuple(&vpx_highbd_tm_predictor_4x4_sse2,
158 &vpx_highbd_tm_predictor_4x4_c, 4, 8),
159 make_tuple(&vpx_highbd_tm_predictor_8x8_sse2,
160 &vpx_highbd_tm_predictor_8x8_c, 8, 8)));
162 INSTANTIATE_TEST_CASE_P(SSE2_TO_C_10, VP9IntraPredTest,
163 ::testing::Values(
164 make_tuple(&vpx_highbd_dc_predictor_32x32_sse2,
165 &vpx_highbd_dc_predictor_32x32_c, 32,
166 10),
167 make_tuple(&vpx_highbd_tm_predictor_16x16_sse2,
168 &vpx_highbd_tm_predictor_16x16_c, 16,
169 10),
170 make_tuple(&vpx_highbd_tm_predictor_32x32_sse2,
171 &vpx_highbd_tm_predictor_32x32_c, 32,
172 10),
173 make_tuple(&vpx_highbd_dc_predictor_4x4_sse2,
174 &vpx_highbd_dc_predictor_4x4_c, 4, 10),
175 make_tuple(&vpx_highbd_dc_predictor_8x8_sse2,
176 &vpx_highbd_dc_predictor_8x8_c, 8, 10),
177 make_tuple(&vpx_highbd_dc_predictor_16x16_sse2,
178 &vpx_highbd_dc_predictor_16x16_c, 16,
179 10),
180 make_tuple(&vpx_highbd_v_predictor_4x4_sse2,
181 &vpx_highbd_v_predictor_4x4_c, 4, 10),
182 make_tuple(&vpx_highbd_v_predictor_8x8_sse2,
183 &vpx_highbd_v_predictor_8x8_c, 8, 10),
184 make_tuple(&vpx_highbd_v_predictor_16x16_sse2,
185 &vpx_highbd_v_predictor_16x16_c, 16,
186 10),
187 make_tuple(&vpx_highbd_v_predictor_32x32_sse2,
188 &vpx_highbd_v_predictor_32x32_c, 32,
189 10),
190 make_tuple(&vpx_highbd_tm_predictor_4x4_sse2,
191 &vpx_highbd_tm_predictor_4x4_c, 4, 10),
192 make_tuple(&vpx_highbd_tm_predictor_8x8_sse2,
193 &vpx_highbd_tm_predictor_8x8_c, 8, 10)));
195 INSTANTIATE_TEST_CASE_P(SSE2_TO_C_12, VP9IntraPredTest,
196 ::testing::Values(
197 make_tuple(&vpx_highbd_dc_predictor_32x32_sse2,
198 &vpx_highbd_dc_predictor_32x32_c, 32,
199 12),
200 make_tuple(&vpx_highbd_tm_predictor_16x16_sse2,
201 &vpx_highbd_tm_predictor_16x16_c, 16,
202 12),
203 make_tuple(&vpx_highbd_tm_predictor_32x32_sse2,
204 &vpx_highbd_tm_predictor_32x32_c, 32,
205 12),
206 make_tuple(&vpx_highbd_dc_predictor_4x4_sse2,
207 &vpx_highbd_dc_predictor_4x4_c, 4, 12),
208 make_tuple(&vpx_highbd_dc_predictor_8x8_sse2,
209 &vpx_highbd_dc_predictor_8x8_c, 8, 12),
210 make_tuple(&vpx_highbd_dc_predictor_16x16_sse2,
211 &vpx_highbd_dc_predictor_16x16_c, 16,
212 12),
213 make_tuple(&vpx_highbd_v_predictor_4x4_sse2,
214 &vpx_highbd_v_predictor_4x4_c, 4, 12),
215 make_tuple(&vpx_highbd_v_predictor_8x8_sse2,
216 &vpx_highbd_v_predictor_8x8_c, 8, 12),
217 make_tuple(&vpx_highbd_v_predictor_16x16_sse2,
218 &vpx_highbd_v_predictor_16x16_c, 16,
219 12),
220 make_tuple(&vpx_highbd_v_predictor_32x32_sse2,
221 &vpx_highbd_v_predictor_32x32_c, 32,
222 12),
223 make_tuple(&vpx_highbd_tm_predictor_4x4_sse2,
224 &vpx_highbd_tm_predictor_4x4_c, 4, 12),
225 make_tuple(&vpx_highbd_tm_predictor_8x8_sse2,
226 &vpx_highbd_tm_predictor_8x8_c, 8, 12)));
228 #endif // CONFIG_USE_X86INC
229 #endif // CONFIG_VP9_HIGHBITDEPTH
230 #endif // HAVE_SSE2
231 } // namespace