Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 1 | /* |
| 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 Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 13 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
| 16 | #include "./aom_dsp_rtcd.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 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" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "av1/common/blockd.h" |
| 22 | #include "av1/common/pred_common.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | #include "aom_mem/aom_mem.h" |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 24 | |
| 25 | namespace { |
| 26 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | using libaom_test::ACMRandom; |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 28 | |
| 29 | const int count_test_block = 100000; |
| 30 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 31 | typedef void (*IntraPred)(uint16_t *dst, ptrdiff_t stride, |
| 32 | const uint16_t *above, const uint16_t *left, int bps); |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 33 | |
| 34 | struct IntraPredFunc { |
| 35 | IntraPredFunc(IntraPred pred = NULL, IntraPred ref = NULL, |
| 36 | int block_size_value = 0, int bit_depth_value = 0) |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 37 | : pred_fn(pred), ref_fn(ref), block_size(block_size_value), |
| 38 | bit_depth(bit_depth_value) {} |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 39 | |
| 40 | IntraPred pred_fn; |
| 41 | IntraPred ref_fn; |
| 42 | int block_size; |
| 43 | int bit_depth; |
| 44 | }; |
| 45 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | class AV1IntraPredTest : public ::testing::TestWithParam<IntraPredFunc> { |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 47 | public: |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 48 | void RunTest(uint16_t *left_col, uint16_t *above_data, uint16_t *dst, |
| 49 | uint16_t *ref_dst) { |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 50 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 51 | const int block_size = params_.block_size; |
| 52 | above_row_ = above_data + 16; |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 53 | left_col_ = left_col; |
| 54 | dst_ = dst; |
| 55 | ref_dst_ = ref_dst; |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 56 | 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. |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 59 | for (int x = -1; x <= block_size * 2; x++) { |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 60 | if (i == 0) { |
| 61 | above_row_[x] = mask_; |
| 62 | } else { |
| 63 | above_row_[x] = rnd.Rand16() & mask_; |
| 64 | } |
| 65 | } |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 66 | for (int y = 0; y < block_size; y++) { |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 67 | if (i == 0) { |
| 68 | left_col_[y] = mask_; |
| 69 | } else { |
| 70 | left_col_[y] = rnd.Rand16() & mask_; |
| 71 | } |
| 72 | } |
James Zern | cffef11 | 2016-02-11 18:27:00 -0800 | [diff] [blame] | 73 | Predict(); |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 74 | CheckPrediction(i, &error_count); |
| 75 | } |
| 76 | ASSERT_EQ(0, error_count); |
| 77 | } |
| 78 | |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 79 | protected: |
| 80 | virtual void SetUp() { |
| 81 | params_ = GetParam(); |
| 82 | stride_ = params_.block_size * 3; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 83 | mask_ = (1 << params_.bit_depth) - 1; |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 84 | } |
| 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 89 | ASM_REGISTER_STATE_CHECK( |
| 90 | params_.pred_fn(dst_, stride_, above_row_, left_col_, bit_depth)); |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 91 | } |
| 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-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 101 | << " Failed on Test Case Number " << test_case_number; |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 107 | 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 Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 113 | |
Johann | 2967bf3 | 2016-06-22 16:08:10 -0700 | [diff] [blame] | 114 | IntraPredFunc params_; |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 117 | TEST_P(AV1IntraPredTest, IntraPredTests) { |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 118 | // max block size is 32 |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 119 | DECLARE_ALIGNED(16, uint16_t, left_col[2 * 32]); |
| 120 | DECLARE_ALIGNED(16, uint16_t, above_data[2 * 32 + 32]); |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 121 | DECLARE_ALIGNED(16, uint16_t, dst[3 * 32 * 32]); |
| 122 | DECLARE_ALIGNED(16, uint16_t, ref_dst[3 * 32 * 32]); |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 123 | RunTest(left_col, above_data, dst, ref_dst); |
| 124 | } |
| 125 | |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 126 | #if HAVE_SSE2 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 127 | #if CONFIG_AOM_HIGHBITDEPTH |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 128 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 129 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 132 | #if !CONFIG_ALT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 133 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 137 | #endif // !CONFIG_ALT_INTRA |
| 138 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 139 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 152 | &aom_highbd_v_predictor_32x32_c, 32, 8) |
| 153 | #if !CONFIG_ALT_INTRA |
| 154 | , |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 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, |
Urvang Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 158 | &aom_highbd_tm_predictor_8x8_c, 8, 8) |
| 159 | #endif // !CONFIG_ALT_INTRA |
| 160 | )); |
Johann | 1c967f1 | 2015-06-29 17:04:58 -0700 | [diff] [blame] | 161 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 162 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 163 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 166 | #if !CONFIG_ALT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 167 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 171 | #endif // !CONFIG_ALT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 172 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 185 | &aom_highbd_v_predictor_32x32_c, 32, 10) |
| 186 | #if !CONFIG_ALT_INTRA |
| 187 | , |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 188 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 191 | &aom_highbd_tm_predictor_8x8_c, 8, 10) |
| 192 | #endif // !CONFIG_ALT_INTRA |
| 193 | )); |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 194 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 195 | INSTANTIATE_TEST_CASE_P( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 199 | #if !CONFIG_ALT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 204 | #endif // !CONFIG_ALT_INTRA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 205 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 218 | &aom_highbd_v_predictor_32x32_c, 32, 12) |
| 219 | #if !CONFIG_ALT_INTRA |
| 220 | , |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 221 | 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 Joshi | 340593e | 2016-09-01 12:03:20 -0700 | [diff] [blame^] | 224 | &aom_highbd_tm_predictor_8x8_c, 8, 12) |
| 225 | #endif // !CONFIG_ALT_INTRA |
| 226 | )); |
Jian Zhou | 26a6ce4 | 2015-12-22 16:51:57 -0800 | [diff] [blame] | 227 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 228 | #endif // CONFIG_AOM_HIGHBITDEPTH |
Deb Mukherjee | 81a8138 | 2014-09-15 12:59:19 -0700 | [diff] [blame] | 229 | #endif // HAVE_SSE2 |
| 230 | } // namespace |