blob: 75c999aaf1870c2e7615ddf64b115a6262180d84 [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.
Johann123e8a62017-12-28 14:40:49 -080010 */
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070011
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/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
clang-format3a826f12016-08-11 17:46:05 -070026typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
27 ptrdiff_t diff_stride, const uint8_t *src_ptr,
28 ptrdiff_t src_stride, const uint8_t *pred_ptr,
29 ptrdiff_t pred_stride);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070030
Geza Lore552d5cd2016-03-07 13:46:39 +000031namespace {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070032
Yaowu Xuf883b422016-08-30 14:01:10 -070033class AV1SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070034 public:
Yaowu Xuc27fc142016-08-22 16:08:15 -070035 virtual void TearDown() { libaom_test::ClearSystemState(); }
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070036};
37
Yaowu Xuc27fc142016-08-22 16:08:15 -070038using libaom_test::ACMRandom;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070039
Yaowu Xuf883b422016-08-30 14:01:10 -070040TEST_P(AV1SubtractBlockTest, SimpleSubtract) {
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070041 ACMRandom rnd(ACMRandom::DeterministicSeed());
42
43 // FIXME(rbultje) split in its own file
Dmitry Kovalev45870612013-08-26 11:33:16 -070044 for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
45 bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
Jingning Hanae5cfde2016-11-30 12:01:44 -080046 const int block_width = block_size_wide[bsize];
47 const int block_height = block_size_high[bsize];
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070048 int16_t *diff = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070049 aom_memalign(16, sizeof(*diff) * block_width * block_height * 2));
Ronald S. Bultjeac6ea2a2013-06-21 17:03:57 -070050 uint8_t *pred = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070051 aom_memalign(16, block_width * block_height * 2));
clang-format3a826f12016-08-11 17:46:05 -070052 uint8_t *src = reinterpret_cast<uint8_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070053 aom_memalign(16, block_width * block_height * 2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070054
55 for (int n = 0; n < 100; n++) {
56 for (int r = 0; r < block_height; ++r) {
57 for (int c = 0; c < block_width * 2; ++c) {
58 src[r * block_width * 2 + c] = rnd.Rand8();
59 pred[r * block_width * 2 + c] = rnd.Rand8();
60 }
61 }
62
clang-format3a826f12016-08-11 17:46:05 -070063 GetParam()(block_height, block_width, diff, block_width, src, block_width,
64 pred, block_width);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070065
66 for (int r = 0; r < block_height; ++r) {
67 for (int c = 0; c < block_width; ++c) {
68 EXPECT_EQ(diff[r * block_width + c],
clang-format3a826f12016-08-11 17:46:05 -070069 (src[r * block_width + c] - pred[r * block_width + c]))
70 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070071 }
72 }
73
clang-format3a826f12016-08-11 17:46:05 -070074 GetParam()(block_height, block_width, diff, block_width * 2, src,
75 block_width * 2, pred, block_width * 2);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070076
77 for (int r = 0; r < block_height; ++r) {
78 for (int c = 0; c < block_width; ++c) {
clang-format3a826f12016-08-11 17:46:05 -070079 EXPECT_EQ(
80 diff[r * block_width * 2 + c],
81 (src[r * block_width * 2 + c] - pred[r * block_width * 2 + c]))
82 << "r = " << r << ", c = " << c << ", bs = " << bsize;
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070083 }
84 }
85 }
Yaowu Xuf883b422016-08-30 14:01:10 -070086 aom_free(diff);
87 aom_free(pred);
88 aom_free(src);
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070089 }
90}
91
Yaowu Xuf883b422016-08-30 14:01:10 -070092INSTANTIATE_TEST_CASE_P(C, AV1SubtractBlockTest,
93 ::testing::Values(aom_subtract_block_c));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070094
Yaowu Xudec16ab2016-07-20 11:57:29 -070095#if HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -070096INSTANTIATE_TEST_CASE_P(SSE2, AV1SubtractBlockTest,
97 ::testing::Values(aom_subtract_block_sse2));
Ronald S. Bultje25c588b2013-06-21 09:35:37 -070098#endif
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -070099#if HAVE_NEON
Yaowu Xuf883b422016-08-30 14:01:10 -0700100INSTANTIATE_TEST_CASE_P(NEON, AV1SubtractBlockTest,
101 ::testing::Values(aom_subtract_block_neon));
Scott LaVarnway6f4b8dc2014-07-30 12:16:04 -0700102#endif
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530103#if HAVE_MSA
Yaowu Xuf883b422016-08-30 14:01:10 -0700104INSTANTIATE_TEST_CASE_P(MSA, AV1SubtractBlockTest,
105 ::testing::Values(aom_subtract_block_msa));
Parag Salasakar4bfe3bd2015-08-03 09:42:11 +0530106#endif
Yi Luo0f80b1f2016-04-11 10:49:43 -0700107
clang-format3a826f12016-08-11 17:46:05 -0700108typedef void (*HBDSubtractFunc)(int rows, int cols, int16_t *diff_ptr,
109 ptrdiff_t diff_stride, const uint8_t *src_ptr,
110 ptrdiff_t src_stride, const uint8_t *pred_ptr,
111 ptrdiff_t pred_stride, int bd);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700112
113using ::std::tr1::get;
114using ::std::tr1::make_tuple;
115using ::std::tr1::tuple;
116
117// <width, height, bit_dpeth, subtract>
118typedef tuple<int, int, int, HBDSubtractFunc> Params;
119
Yaowu Xuf883b422016-08-30 14:01:10 -0700120class AV1HBDSubtractBlockTest : public ::testing::TestWithParam<Params> {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700121 public:
122 virtual void SetUp() {
123 block_width_ = GET_PARAM(0);
124 block_height_ = GET_PARAM(1);
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 bit_depth_ = static_cast<aom_bit_depth_t>(GET_PARAM(2));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700126 func_ = GET_PARAM(3);
127
128 rnd_.Reset(ACMRandom::DeterministicSeed());
129
130 const size_t max_width = 128;
131 const size_t max_block_size = max_width * max_width;
132 src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700133 aom_memalign(16, max_block_size * sizeof(uint16_t))));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700134 pred_ = 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 diff_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -0700137 aom_memalign(16, max_block_size * sizeof(int16_t)));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700138 }
139
140 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -0700141 aom_free(CONVERT_TO_SHORTPTR(src_));
142 aom_free(CONVERT_TO_SHORTPTR(pred_));
143 aom_free(diff_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700144 }
145
146 protected:
Yi Luo0f80b1f2016-04-11 10:49:43 -0700147 void CheckResult();
Tom Fineganb8dcfc52017-08-22 10:28:39 -0700148 void RunForSpeed();
Yi Luo0f80b1f2016-04-11 10:49:43 -0700149
150 private:
151 ACMRandom rnd_;
152 int block_height_;
153 int block_width_;
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 aom_bit_depth_t bit_depth_;
Yi Luo0f80b1f2016-04-11 10:49:43 -0700155 HBDSubtractFunc func_;
156 uint8_t *src_;
157 uint8_t *pred_;
158 int16_t *diff_;
159};
160
Yaowu Xuf883b422016-08-30 14:01:10 -0700161void AV1HBDSubtractBlockTest::CheckResult() {
Yi Luo0f80b1f2016-04-11 10:49:43 -0700162 const int test_num = 100;
Rupert Swarbrick4b5c2bb2017-09-04 16:10:53 +0100163 const size_t max_width = 128;
Yi Luo0f80b1f2016-04-11 10:49:43 -0700164 const int max_block_size = max_width * max_width;
165 const int mask = (1 << bit_depth_) - 1;
166 int i, j;
167
168 for (i = 0; i < test_num; ++i) {
169 for (j = 0; j < max_block_size; ++j) {
170 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
171 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
172 }
173
clang-format3a826f12016-08-11 17:46:05 -0700174 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
175 pred_, block_width_, bit_depth_);
Yi Luo0f80b1f2016-04-11 10:49:43 -0700176
177 for (int r = 0; r < block_height_; ++r) {
178 for (int c = 0; c < block_width_; ++c) {
179 EXPECT_EQ(diff_[r * block_width_ + c],
180 (CONVERT_TO_SHORTPTR(src_)[r * block_width_ + c] -
181 CONVERT_TO_SHORTPTR(pred_)[r * block_width_ + c]))
182 << "r = " << r << ", c = " << c << ", test: " << i;
183 }
184 }
185 }
186}
187
Yaowu Xuf883b422016-08-30 14:01:10 -0700188TEST_P(AV1HBDSubtractBlockTest, CheckResult) { CheckResult(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700189
Tom Fineganb8dcfc52017-08-22 10:28:39 -0700190void AV1HBDSubtractBlockTest::RunForSpeed() {
191 const int test_num = 200000;
Rupert Swarbrick4b5c2bb2017-09-04 16:10:53 +0100192 const size_t max_width = 128;
Tom Fineganb8dcfc52017-08-22 10:28:39 -0700193 const int max_block_size = max_width * max_width;
194 const int mask = (1 << bit_depth_) - 1;
195 int i, j;
196
197 for (j = 0; j < max_block_size; ++j) {
198 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
199 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
200 }
201
202 for (i = 0; i < test_num; ++i) {
203 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
204 pred_, block_width_, bit_depth_);
205 }
206}
207
208TEST_P(AV1HBDSubtractBlockTest, DISABLED_Speed) { RunForSpeed(); }
Yi Luo0f80b1f2016-04-11 10:49:43 -0700209
210#if HAVE_SSE2
James Zern71840652017-06-20 22:58:56 -0700211
212const Params kAV1HBDSubtractBlock_sse2[] = {
213 make_tuple(4, 4, 12, &aom_highbd_subtract_block_sse2),
214 make_tuple(4, 4, 12, &aom_highbd_subtract_block_c),
215 make_tuple(4, 8, 12, &aom_highbd_subtract_block_sse2),
216 make_tuple(4, 8, 12, &aom_highbd_subtract_block_c),
217 make_tuple(8, 4, 12, &aom_highbd_subtract_block_sse2),
218 make_tuple(8, 4, 12, &aom_highbd_subtract_block_c),
219 make_tuple(8, 8, 12, &aom_highbd_subtract_block_sse2),
220 make_tuple(8, 8, 12, &aom_highbd_subtract_block_c),
221 make_tuple(8, 16, 12, &aom_highbd_subtract_block_sse2),
222 make_tuple(8, 16, 12, &aom_highbd_subtract_block_c),
223 make_tuple(16, 8, 12, &aom_highbd_subtract_block_sse2),
224 make_tuple(16, 8, 12, &aom_highbd_subtract_block_c),
225 make_tuple(16, 16, 12, &aom_highbd_subtract_block_sse2),
226 make_tuple(16, 16, 12, &aom_highbd_subtract_block_c),
227 make_tuple(16, 32, 12, &aom_highbd_subtract_block_sse2),
228 make_tuple(16, 32, 12, &aom_highbd_subtract_block_c),
229 make_tuple(32, 16, 12, &aom_highbd_subtract_block_sse2),
230 make_tuple(32, 16, 12, &aom_highbd_subtract_block_c),
231 make_tuple(32, 32, 12, &aom_highbd_subtract_block_sse2),
232 make_tuple(32, 32, 12, &aom_highbd_subtract_block_c),
233 make_tuple(32, 64, 12, &aom_highbd_subtract_block_sse2),
234 make_tuple(32, 64, 12, &aom_highbd_subtract_block_c),
235 make_tuple(64, 32, 12, &aom_highbd_subtract_block_sse2),
236 make_tuple(64, 32, 12, &aom_highbd_subtract_block_c),
237 make_tuple(64, 64, 12, &aom_highbd_subtract_block_sse2),
238 make_tuple(64, 64, 12, &aom_highbd_subtract_block_c),
239 make_tuple(64, 128, 12, &aom_highbd_subtract_block_sse2),
240 make_tuple(64, 128, 12, &aom_highbd_subtract_block_c),
241 make_tuple(128, 64, 12, &aom_highbd_subtract_block_sse2),
242 make_tuple(128, 64, 12, &aom_highbd_subtract_block_c),
243 make_tuple(128, 128, 12, &aom_highbd_subtract_block_sse2),
244 make_tuple(128, 128, 12, &aom_highbd_subtract_block_c)
245};
246
247INSTANTIATE_TEST_CASE_P(SSE2, AV1HBDSubtractBlockTest,
248 ::testing::ValuesIn(kAV1HBDSubtractBlock_sse2));
Yi Luo0f80b1f2016-04-11 10:49:43 -0700249#endif // HAVE_SSE2
Geza Lore552d5cd2016-03-07 13:46:39 +0000250} // namespace