blob: e1bf16cce8b2b54e33b74d37d704c9feacaaf478 [file] [log] [blame]
Ronald S. Bultje25c588b2013-06-21 09:35:37 -07001/*
2 * Copyright (c) 2012 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 "third_party/googletest/src/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070012
Yaowu Xuf883b422016-08-30 14:01:10 -070013#include "./aom_config.h"
14#include "./aom_dsp_rtcd.h"
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070015#include "test/acm_random.h"
16#include "test/clear_system_state.h"
17#include "test/register_state_check.h"
Yi Luo0f80b1f2016-04-11 10:49:43 -070018#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070019#if CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -070020#include "av1/common/blockd.h"
Geza Lore552d5cd2016-03-07 13:46:39 +000021#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070022#include "aom_mem/aom_mem.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070023#include "aom_ports/mem.h"
Yi Luo0f80b1f2016-04-11 10:49:43 -070024
25#define USE_SPEED_TEST (0)
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070026
clang-format3a826f12016-08-11 17:46:05 -070027typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
28 ptrdiff_t diff_stride, const uint8_t *src_ptr,
29 ptrdiff_t src_stride, const uint8_t *pred_ptr,
30 ptrdiff_t pred_stride);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070031
Geza Lore552d5cd2016-03-07 13:46:39 +000032namespace {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070033
Yaowu Xuf883b422016-08-30 14:01:10 -070034class AV1SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070035 public:
Yaowu Xuc27fc142016-08-22 16:08:15 -070036 virtual void TearDown() { libaom_test::ClearSystemState(); }
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070037};
38
Yaowu Xuc27fc142016-08-22 16:08:15 -070039using libaom_test::ACMRandom;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070040
Yaowu Xuf883b422016-08-30 14:01:10 -070041TEST_P(AV1SubtractBlockTest, SimpleSubtract) {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070042 ACMRandom rnd(ACMRandom::DeterministicSeed());
43
44 // FIXME(rbultje) split in its own file
Dmitry Kovalev45870612013-08-26 11:33:16 -070045 for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
46 bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
Dmitry Kovalev27e6b5b2013-11-21 15:53:06 -080047 const int block_width = 4 * num_4x4_blocks_wide_lookup[bsize];
48 const int block_height = 4 * num_4x4_blocks_high_lookup[bsize];
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070049 int16_t *diff = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070050 aom_memalign(16, sizeof(*diff) * block_width * block_height * 2));
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070051 uint8_t *pred = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070052 aom_memalign(16, block_width * block_height * 2));
clang-format3a826f12016-08-11 17:46:05 -070053 uint8_t *src = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070054 aom_memalign(16, block_width * block_height * 2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070055
56 for (int n = 0; n < 100; n++) {
57 for (int r = 0; r < block_height; ++r) {
58 for (int c = 0; c < block_width * 2; ++c) {
59 src[r * block_width * 2 + c] = rnd.Rand8();
60 pred[r * block_width * 2 + c] = rnd.Rand8();
61 }
62 }
63
clang-format3a826f12016-08-11 17:46:05 -070064 GetParam()(block_height, block_width, diff, block_width, src, block_width,
65 pred, block_width);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070066
67 for (int r = 0; r < block_height; ++r) {
68 for (int c = 0; c < block_width; ++c) {
69 EXPECT_EQ(diff[r * block_width + c],
clang-format3a826f12016-08-11 17:46:05 -070070 (src[r * block_width + c] - pred[r * block_width + c]))
71 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070072 }
73 }
74
clang-format3a826f12016-08-11 17:46:05 -070075 GetParam()(block_height, block_width, diff, block_width * 2, src,
76 block_width * 2, pred, block_width * 2);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070077
78 for (int r = 0; r < block_height; ++r) {
79 for (int c = 0; c < block_width; ++c) {
clang-format3a826f12016-08-11 17:46:05 -070080 EXPECT_EQ(
81 diff[r * block_width * 2 + c],
82 (src[r * block_width * 2 + c] - pred[r * block_width * 2 + c]))
83 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070084 }
85 }
86 }
Yaowu Xuf883b422016-08-30 14:01:10 -070087 aom_free(diff);
88 aom_free(pred);
89 aom_free(src);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070090 }
91}
92
Yaowu Xuf883b422016-08-30 14:01:10 -070093INSTANTIATE_TEST_CASE_P(C, AV1SubtractBlockTest,
94 ::testing::Values(aom_subtract_block_c));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070095
Yaowu Xudec16ab2016-07-20 11:57:29 -070096#if HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -070097INSTANTIATE_TEST_CASE_P(SSE2, AV1SubtractBlockTest,
98 ::testing::Values(aom_subtract_block_sse2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070099#endif
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -0700100#if HAVE_NEON
Yaowu Xuf883b422016-08-30 14:01:10 -0700101INSTANTIATE_TEST_CASE_P(NEON, AV1SubtractBlockTest,
102 ::testing::Values(aom_subtract_block_neon));
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -0700103#endif
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530104#if HAVE_MSA
Yaowu Xuf883b422016-08-30 14:01:10 -0700105INSTANTIATE_TEST_CASE_P(MSA, AV1SubtractBlockTest,
106 ::testing::Values(aom_subtract_block_msa));
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530107#endif
Yi Luo0f80b1f2016-04-11 10:49:43 -0700108
clang-format3a826f12016-08-11 17:46:05 -0700109typedef void (*HBDSubtractFunc)(int rows, int cols, int16_t *diff_ptr,
110 ptrdiff_t diff_stride, const uint8_t *src_ptr,
111 ptrdiff_t src_stride, const uint8_t *pred_ptr,
112 ptrdiff_t pred_stride, int bd);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700113
114using ::std::tr1::get;
115using ::std::tr1::make_tuple;
116using ::std::tr1::tuple;
117
118// <width, height, bit_dpeth, subtract>
119typedef tuple<int, int, int, HBDSubtractFunc> Params;
120
Yaowu Xuf883b422016-08-30 14:01:10 -0700121#if CONFIG_AOM_HIGHBITDEPTH
122class AV1HBDSubtractBlockTest : public ::testing::TestWithParam<Params> {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700123 public:
124 virtual void SetUp() {
125 block_width_ = GET_PARAM(0);
126 block_height_ = GET_PARAM(1);
Yaowu Xuf883b422016-08-30 14:01:10 -0700127 bit_depth_ = static_cast<aom_bit_depth_t>(GET_PARAM(2));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700128 func_ = GET_PARAM(3);
129
130 rnd_.Reset(ACMRandom::DeterministicSeed());
131
132 const size_t max_width = 128;
133 const size_t max_block_size = max_width * max_width;
134 src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700135 aom_memalign(16, max_block_size * sizeof(uint16_t))));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700136 pred_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700137 aom_memalign(16, max_block_size * sizeof(uint16_t))));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700138 diff_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700139 aom_memalign(16, max_block_size * sizeof(int16_t)));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700140 }
141
142 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700143 aom_free(CONVERT_TO_SHORTPTR(src_));
144 aom_free(CONVERT_TO_SHORTPTR(pred_));
145 aom_free(diff_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700146 }
147
148 protected:
149 void RunForSpeed();
150 void CheckResult();
151
152 private:
153 ACMRandom rnd_;
154 int block_height_;
155 int block_width_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700156 aom_bit_depth_t bit_depth_;
Yi Luo0f80b1f2016-04-11 10:49:43 -0700157 HBDSubtractFunc func_;
158 uint8_t *src_;
159 uint8_t *pred_;
160 int16_t *diff_;
161};
162
Yaowu Xuf883b422016-08-30 14:01:10 -0700163void AV1HBDSubtractBlockTest::RunForSpeed() {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700164 const int test_num = 200000;
165 const int max_width = 128;
166 const int max_block_size = max_width * max_width;
167 const int mask = (1 << bit_depth_) - 1;
168 int i, j;
169
170 for (j = 0; j < max_block_size; ++j) {
171 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
172 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
173 }
174
175 for (i = 0; i < test_num; ++i) {
clang-format3a826f12016-08-11 17:46:05 -0700176 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
177 pred_, block_width_, bit_depth_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700178 }
179}
180
Yaowu Xuf883b422016-08-30 14:01:10 -0700181void AV1HBDSubtractBlockTest::CheckResult() {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700182 const int test_num = 100;
183 const int max_width = 128;
184 const int max_block_size = max_width * max_width;
185 const int mask = (1 << bit_depth_) - 1;
186 int i, j;
187
188 for (i = 0; i < test_num; ++i) {
189 for (j = 0; j < max_block_size; ++j) {
190 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
191 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
192 }
193
clang-format3a826f12016-08-11 17:46:05 -0700194 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
195 pred_, block_width_, bit_depth_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700196
197 for (int r = 0; r < block_height_; ++r) {
198 for (int c = 0; c < block_width_; ++c) {
199 EXPECT_EQ(diff_[r * block_width_ + c],
200 (CONVERT_TO_SHORTPTR(src_)[r * block_width_ + c] -
201 CONVERT_TO_SHORTPTR(pred_)[r * block_width_ + c]))
202 << "r = " << r << ", c = " << c << ", test: " << i;
203 }
204 }
205 }
206}
207
Yaowu Xuf883b422016-08-30 14:01:10 -0700208TEST_P(AV1HBDSubtractBlockTest, CheckResult) { CheckResult(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700209
210#if USE_SPEED_TEST
Yaowu Xuf883b422016-08-30 14:01:10 -0700211TEST_P(AV1HBDSubtractBlockTest, CheckSpeed) { RunForSpeed(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700212#endif // USE_SPEED_TEST
213
214#if HAVE_SSE2
clang-format3a826f12016-08-11 17:46:05 -0700215INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700216 SSE2, AV1HBDSubtractBlockTest,
217 ::testing::Values(make_tuple(4, 4, 12, aom_highbd_subtract_block_sse2),
218 make_tuple(4, 4, 12, aom_highbd_subtract_block_c),
219 make_tuple(4, 8, 12, aom_highbd_subtract_block_sse2),
220 make_tuple(4, 8, 12, aom_highbd_subtract_block_c),
221 make_tuple(8, 4, 12, aom_highbd_subtract_block_sse2),
222 make_tuple(8, 4, 12, aom_highbd_subtract_block_c),
223 make_tuple(8, 8, 12, aom_highbd_subtract_block_sse2),
224 make_tuple(8, 8, 12, aom_highbd_subtract_block_c),
225 make_tuple(8, 16, 12, aom_highbd_subtract_block_sse2),
226 make_tuple(8, 16, 12, aom_highbd_subtract_block_c),
227 make_tuple(16, 8, 12, aom_highbd_subtract_block_sse2),
228 make_tuple(16, 8, 12, aom_highbd_subtract_block_c),
229 make_tuple(16, 16, 12, aom_highbd_subtract_block_sse2),
230 make_tuple(16, 16, 12, aom_highbd_subtract_block_c),
231 make_tuple(16, 32, 12, aom_highbd_subtract_block_sse2),
232 make_tuple(16, 32, 12, aom_highbd_subtract_block_c),
233 make_tuple(32, 16, 12, aom_highbd_subtract_block_sse2),
234 make_tuple(32, 16, 12, aom_highbd_subtract_block_c),
235 make_tuple(32, 32, 12, aom_highbd_subtract_block_sse2),
236 make_tuple(32, 32, 12, aom_highbd_subtract_block_c),
237 make_tuple(32, 64, 12, aom_highbd_subtract_block_sse2),
238 make_tuple(32, 64, 12, aom_highbd_subtract_block_c),
239 make_tuple(64, 32, 12, aom_highbd_subtract_block_sse2),
240 make_tuple(64, 32, 12, aom_highbd_subtract_block_c),
241 make_tuple(64, 64, 12, aom_highbd_subtract_block_sse2),
242 make_tuple(64, 64, 12, aom_highbd_subtract_block_c),
243 make_tuple(64, 128, 12, aom_highbd_subtract_block_sse2),
244 make_tuple(64, 128, 12, aom_highbd_subtract_block_c),
245 make_tuple(128, 64, 12, aom_highbd_subtract_block_sse2),
246 make_tuple(128, 64, 12, aom_highbd_subtract_block_c),
247 make_tuple(128, 128, 12, aom_highbd_subtract_block_sse2),
248 make_tuple(128, 128, 12, aom_highbd_subtract_block_c)));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700249#endif // HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -0700250#endif // CONFIG_AOM_HIGHBITDEPTH
Geza Lore552d5cd2016-03-07 13:46:39 +0000251} // namespace