blob: 6bd1b2ba87854f7d32504e9de371d90c883871c8 [file] [log] [blame]
Ronald S. Bultje25c588b2013-06-21 09:35:37 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Ronald S. Bultje25c588b2013-06-21 09:35:37 -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*/
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070011
12#include "third_party/googletest/src/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070013
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./aom_config.h"
15#include "./aom_dsp_rtcd.h"
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070016#include "test/acm_random.h"
17#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
Yi Luo0f80b1f2016-04-11 10:49:43 -070019#include "test/util.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070020#if CONFIG_AV1
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "av1/common/blockd.h"
Geza Lore552d5cd2016-03-07 13:46:39 +000022#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070023#include "aom_mem/aom_mem.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070024#include "aom_ports/mem.h"
Yi Luo0f80b1f2016-04-11 10:49:43 -070025
26#define USE_SPEED_TEST (0)
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070027
clang-format3a826f12016-08-11 17:46:05 -070028typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
29 ptrdiff_t diff_stride, const uint8_t *src_ptr,
30 ptrdiff_t src_stride, const uint8_t *pred_ptr,
31 ptrdiff_t pred_stride);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070032
Geza Lore552d5cd2016-03-07 13:46:39 +000033namespace {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070034
Yaowu Xuf883b422016-08-30 14:01:10 -070035class AV1SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070036 public:
Yaowu Xuc27fc142016-08-22 16:08:15 -070037 virtual void TearDown() { libaom_test::ClearSystemState(); }
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070038};
39
Yaowu Xuc27fc142016-08-22 16:08:15 -070040using libaom_test::ACMRandom;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070041
Yaowu Xuf883b422016-08-30 14:01:10 -070042TEST_P(AV1SubtractBlockTest, SimpleSubtract) {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070043 ACMRandom rnd(ACMRandom::DeterministicSeed());
44
45 // FIXME(rbultje) split in its own file
Dmitry Kovalev45870612013-08-26 11:33:16 -070046 for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
47 bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
Dmitry Kovalev27e6b5b2013-11-21 15:53:06 -080048 const int block_width = 4 * num_4x4_blocks_wide_lookup[bsize];
49 const int block_height = 4 * num_4x4_blocks_high_lookup[bsize];
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070050 int16_t *diff = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070051 aom_memalign(16, sizeof(*diff) * block_width * block_height * 2));
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070052 uint8_t *pred = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070053 aom_memalign(16, block_width * block_height * 2));
clang-format3a826f12016-08-11 17:46:05 -070054 uint8_t *src = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070055 aom_memalign(16, block_width * block_height * 2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070056
57 for (int n = 0; n < 100; n++) {
58 for (int r = 0; r < block_height; ++r) {
59 for (int c = 0; c < block_width * 2; ++c) {
60 src[r * block_width * 2 + c] = rnd.Rand8();
61 pred[r * block_width * 2 + c] = rnd.Rand8();
62 }
63 }
64
clang-format3a826f12016-08-11 17:46:05 -070065 GetParam()(block_height, block_width, diff, block_width, src, block_width,
66 pred, block_width);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070067
68 for (int r = 0; r < block_height; ++r) {
69 for (int c = 0; c < block_width; ++c) {
70 EXPECT_EQ(diff[r * block_width + c],
clang-format3a826f12016-08-11 17:46:05 -070071 (src[r * block_width + c] - pred[r * block_width + c]))
72 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070073 }
74 }
75
clang-format3a826f12016-08-11 17:46:05 -070076 GetParam()(block_height, block_width, diff, block_width * 2, src,
77 block_width * 2, pred, block_width * 2);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070078
79 for (int r = 0; r < block_height; ++r) {
80 for (int c = 0; c < block_width; ++c) {
clang-format3a826f12016-08-11 17:46:05 -070081 EXPECT_EQ(
82 diff[r * block_width * 2 + c],
83 (src[r * block_width * 2 + c] - pred[r * block_width * 2 + c]))
84 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070085 }
86 }
87 }
Yaowu Xuf883b422016-08-30 14:01:10 -070088 aom_free(diff);
89 aom_free(pred);
90 aom_free(src);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070091 }
92}
93
Yaowu Xuf883b422016-08-30 14:01:10 -070094INSTANTIATE_TEST_CASE_P(C, AV1SubtractBlockTest,
95 ::testing::Values(aom_subtract_block_c));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070096
Yaowu Xudec16ab2016-07-20 11:57:29 -070097#if HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -070098INSTANTIATE_TEST_CASE_P(SSE2, AV1SubtractBlockTest,
99 ::testing::Values(aom_subtract_block_sse2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -0700100#endif
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -0700101#if HAVE_NEON
Yaowu Xuf883b422016-08-30 14:01:10 -0700102INSTANTIATE_TEST_CASE_P(NEON, AV1SubtractBlockTest,
103 ::testing::Values(aom_subtract_block_neon));
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -0700104#endif
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530105#if HAVE_MSA
Yaowu Xuf883b422016-08-30 14:01:10 -0700106INSTANTIATE_TEST_CASE_P(MSA, AV1SubtractBlockTest,
107 ::testing::Values(aom_subtract_block_msa));
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530108#endif
Yi Luo0f80b1f2016-04-11 10:49:43 -0700109
clang-format3a826f12016-08-11 17:46:05 -0700110typedef void (*HBDSubtractFunc)(int rows, int cols, int16_t *diff_ptr,
111 ptrdiff_t diff_stride, const uint8_t *src_ptr,
112 ptrdiff_t src_stride, const uint8_t *pred_ptr,
113 ptrdiff_t pred_stride, int bd);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700114
115using ::std::tr1::get;
116using ::std::tr1::make_tuple;
117using ::std::tr1::tuple;
118
119// <width, height, bit_dpeth, subtract>
120typedef tuple<int, int, int, HBDSubtractFunc> Params;
121
Yaowu Xuf883b422016-08-30 14:01:10 -0700122#if CONFIG_AOM_HIGHBITDEPTH
123class AV1HBDSubtractBlockTest : public ::testing::TestWithParam<Params> {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700124 public:
125 virtual void SetUp() {
126 block_width_ = GET_PARAM(0);
127 block_height_ = GET_PARAM(1);
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 bit_depth_ = static_cast<aom_bit_depth_t>(GET_PARAM(2));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700129 func_ = GET_PARAM(3);
130
131 rnd_.Reset(ACMRandom::DeterministicSeed());
132
133 const size_t max_width = 128;
134 const size_t max_block_size = max_width * max_width;
135 src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700136 aom_memalign(16, max_block_size * sizeof(uint16_t))));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700137 pred_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700138 aom_memalign(16, max_block_size * sizeof(uint16_t))));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700139 diff_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700140 aom_memalign(16, max_block_size * sizeof(int16_t)));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700141 }
142
143 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700144 aom_free(CONVERT_TO_SHORTPTR(src_));
145 aom_free(CONVERT_TO_SHORTPTR(pred_));
146 aom_free(diff_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700147 }
148
149 protected:
150 void RunForSpeed();
151 void CheckResult();
152
153 private:
154 ACMRandom rnd_;
155 int block_height_;
156 int block_width_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700157 aom_bit_depth_t bit_depth_;
Yi Luo0f80b1f2016-04-11 10:49:43 -0700158 HBDSubtractFunc func_;
159 uint8_t *src_;
160 uint8_t *pred_;
161 int16_t *diff_;
162};
163
Yaowu Xuf883b422016-08-30 14:01:10 -0700164void AV1HBDSubtractBlockTest::RunForSpeed() {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700165 const int test_num = 200000;
166 const int max_width = 128;
167 const int max_block_size = max_width * max_width;
168 const int mask = (1 << bit_depth_) - 1;
169 int i, j;
170
171 for (j = 0; j < max_block_size; ++j) {
172 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
173 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
174 }
175
176 for (i = 0; i < test_num; ++i) {
clang-format3a826f12016-08-11 17:46:05 -0700177 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
178 pred_, block_width_, bit_depth_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700179 }
180}
181
Yaowu Xuf883b422016-08-30 14:01:10 -0700182void AV1HBDSubtractBlockTest::CheckResult() {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700183 const int test_num = 100;
184 const int max_width = 128;
185 const int max_block_size = max_width * max_width;
186 const int mask = (1 << bit_depth_) - 1;
187 int i, j;
188
189 for (i = 0; i < test_num; ++i) {
190 for (j = 0; j < max_block_size; ++j) {
191 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
192 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
193 }
194
clang-format3a826f12016-08-11 17:46:05 -0700195 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
196 pred_, block_width_, bit_depth_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700197
198 for (int r = 0; r < block_height_; ++r) {
199 for (int c = 0; c < block_width_; ++c) {
200 EXPECT_EQ(diff_[r * block_width_ + c],
201 (CONVERT_TO_SHORTPTR(src_)[r * block_width_ + c] -
202 CONVERT_TO_SHORTPTR(pred_)[r * block_width_ + c]))
203 << "r = " << r << ", c = " << c << ", test: " << i;
204 }
205 }
206 }
207}
208
Yaowu Xuf883b422016-08-30 14:01:10 -0700209TEST_P(AV1HBDSubtractBlockTest, CheckResult) { CheckResult(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700210
211#if USE_SPEED_TEST
Yaowu Xuf883b422016-08-30 14:01:10 -0700212TEST_P(AV1HBDSubtractBlockTest, CheckSpeed) { RunForSpeed(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700213#endif // USE_SPEED_TEST
214
215#if HAVE_SSE2
clang-format3a826f12016-08-11 17:46:05 -0700216INSTANTIATE_TEST_CASE_P(
Yaowu Xuf883b422016-08-30 14:01:10 -0700217 SSE2, AV1HBDSubtractBlockTest,
218 ::testing::Values(make_tuple(4, 4, 12, aom_highbd_subtract_block_sse2),
219 make_tuple(4, 4, 12, aom_highbd_subtract_block_c),
220 make_tuple(4, 8, 12, aom_highbd_subtract_block_sse2),
221 make_tuple(4, 8, 12, aom_highbd_subtract_block_c),
222 make_tuple(8, 4, 12, aom_highbd_subtract_block_sse2),
223 make_tuple(8, 4, 12, aom_highbd_subtract_block_c),
224 make_tuple(8, 8, 12, aom_highbd_subtract_block_sse2),
225 make_tuple(8, 8, 12, aom_highbd_subtract_block_c),
226 make_tuple(8, 16, 12, aom_highbd_subtract_block_sse2),
227 make_tuple(8, 16, 12, aom_highbd_subtract_block_c),
228 make_tuple(16, 8, 12, aom_highbd_subtract_block_sse2),
229 make_tuple(16, 8, 12, aom_highbd_subtract_block_c),
230 make_tuple(16, 16, 12, aom_highbd_subtract_block_sse2),
231 make_tuple(16, 16, 12, aom_highbd_subtract_block_c),
232 make_tuple(16, 32, 12, aom_highbd_subtract_block_sse2),
233 make_tuple(16, 32, 12, aom_highbd_subtract_block_c),
234 make_tuple(32, 16, 12, aom_highbd_subtract_block_sse2),
235 make_tuple(32, 16, 12, aom_highbd_subtract_block_c),
236 make_tuple(32, 32, 12, aom_highbd_subtract_block_sse2),
237 make_tuple(32, 32, 12, aom_highbd_subtract_block_c),
238 make_tuple(32, 64, 12, aom_highbd_subtract_block_sse2),
239 make_tuple(32, 64, 12, aom_highbd_subtract_block_c),
240 make_tuple(64, 32, 12, aom_highbd_subtract_block_sse2),
241 make_tuple(64, 32, 12, aom_highbd_subtract_block_c),
242 make_tuple(64, 64, 12, aom_highbd_subtract_block_sse2),
243 make_tuple(64, 64, 12, aom_highbd_subtract_block_c),
244 make_tuple(64, 128, 12, aom_highbd_subtract_block_sse2),
245 make_tuple(64, 128, 12, aom_highbd_subtract_block_c),
246 make_tuple(128, 64, 12, aom_highbd_subtract_block_sse2),
247 make_tuple(128, 64, 12, aom_highbd_subtract_block_c),
248 make_tuple(128, 128, 12, aom_highbd_subtract_block_sse2),
249 make_tuple(128, 128, 12, aom_highbd_subtract_block_c)));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700250#endif // HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -0700251#endif // CONFIG_AOM_HIGHBITDEPTH
Geza Lore552d5cd2016-03-07 13:46:39 +0000252} // namespace