1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * 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 */
11
12 #include <tuple>
13
14 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
15
16 #include "config/aom_config.h"
17 #include "config/aom_dsp_rtcd.h"
18
19 #include "test/acm_random.h"
20 #include "test/register_state_check.h"
21 #include "test/util.h"
22 #include "av1/common/blockd.h"
23 #include "aom_mem/aom_mem.h"
24 #include "aom_ports/mem.h"
25
26 typedef 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);
30
31 namespace {
32
33 class AV1SubtractBlockTest : public ::testing::TestWithParam<SubtractFunc> {
34 public:
TearDown()35 virtual void TearDown() {}
36 };
37
38 using libaom_test::ACMRandom;
39
TEST_P(AV1SubtractBlockTest,SimpleSubtract)40 TEST_P(AV1SubtractBlockTest, SimpleSubtract) {
41 ACMRandom rnd(ACMRandom::DeterministicSeed());
42
43 // FIXME(rbultje) split in its own file
44 for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
45 bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
46 const int block_width = block_size_wide[bsize];
47 const int block_height = block_size_high[bsize];
48 int16_t *diff = reinterpret_cast<int16_t *>(
49 aom_memalign(16, sizeof(*diff) * block_width * block_height * 2));
50 uint8_t *pred = reinterpret_cast<uint8_t *>(
51 aom_memalign(16, block_width * block_height * 2));
52 uint8_t *src = reinterpret_cast<uint8_t *>(
53 aom_memalign(16, block_width * block_height * 2));
54
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
63 GetParam()(block_height, block_width, diff, block_width, src, block_width,
64 pred, block_width);
65
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],
69 (src[r * block_width + c] - pred[r * block_width + c]))
70 << "r = " << r << ", c = " << c << ", bs = " << bsize;
71 }
72 }
73
74 GetParam()(block_height, block_width, diff, block_width * 2, src,
75 block_width * 2, pred, block_width * 2);
76
77 for (int r = 0; r < block_height; ++r) {
78 for (int c = 0; c < block_width; ++c) {
79 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;
83 }
84 }
85 }
86 aom_free(diff);
87 aom_free(pred);
88 aom_free(src);
89 }
90 }
91
92 INSTANTIATE_TEST_SUITE_P(C, AV1SubtractBlockTest,
93 ::testing::Values(aom_subtract_block_c));
94
95 #if HAVE_SSE2
96 INSTANTIATE_TEST_SUITE_P(SSE2, AV1SubtractBlockTest,
97 ::testing::Values(aom_subtract_block_sse2));
98 #endif
99 #if HAVE_NEON
100 INSTANTIATE_TEST_SUITE_P(NEON, AV1SubtractBlockTest,
101 ::testing::Values(aom_subtract_block_neon));
102 #endif
103 #if HAVE_MSA
104 INSTANTIATE_TEST_SUITE_P(MSA, AV1SubtractBlockTest,
105 ::testing::Values(aom_subtract_block_msa));
106 #endif
107
108 #if CONFIG_AV1_HIGHBITDEPTH
109 typedef 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);
113
114 using std::get;
115 using std::make_tuple;
116 using std::tuple;
117
118 // <width, height, bit_dpeth, subtract>
119 typedef tuple<int, int, int, HBDSubtractFunc> Params;
120
121 class AV1HBDSubtractBlockTest : public ::testing::TestWithParam<Params> {
122 public:
SetUp()123 virtual void SetUp() {
124 block_width_ = GET_PARAM(0);
125 block_height_ = GET_PARAM(1);
126 bit_depth_ = static_cast<aom_bit_depth_t>(GET_PARAM(2));
127 func_ = GET_PARAM(3);
128
129 rnd_.Reset(ACMRandom::DeterministicSeed());
130
131 const size_t max_width = 128;
132 const size_t max_block_size = max_width * max_width;
133 src_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
134 aom_memalign(16, max_block_size * sizeof(uint16_t))));
135 pred_ = CONVERT_TO_BYTEPTR(reinterpret_cast<uint16_t *>(
136 aom_memalign(16, max_block_size * sizeof(uint16_t))));
137 diff_ = reinterpret_cast<int16_t *>(
138 aom_memalign(16, max_block_size * sizeof(int16_t)));
139 }
140
TearDown()141 virtual void TearDown() {
142 aom_free(CONVERT_TO_SHORTPTR(src_));
143 aom_free(CONVERT_TO_SHORTPTR(pred_));
144 aom_free(diff_);
145 }
146
147 protected:
148 void CheckResult();
149 void RunForSpeed();
150
151 private:
152 ACMRandom rnd_;
153 int block_height_;
154 int block_width_;
155 aom_bit_depth_t bit_depth_;
156 HBDSubtractFunc func_;
157 uint8_t *src_;
158 uint8_t *pred_;
159 int16_t *diff_;
160 };
161 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HBDSubtractBlockTest);
162
CheckResult()163 void AV1HBDSubtractBlockTest::CheckResult() {
164 const int test_num = 100;
165 const size_t 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 (i = 0; i < test_num; ++i) {
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 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
177 pred_, block_width_, bit_depth_);
178
179 for (int r = 0; r < block_height_; ++r) {
180 for (int c = 0; c < block_width_; ++c) {
181 EXPECT_EQ(diff_[r * block_width_ + c],
182 (CONVERT_TO_SHORTPTR(src_)[r * block_width_ + c] -
183 CONVERT_TO_SHORTPTR(pred_)[r * block_width_ + c]))
184 << "r = " << r << ", c = " << c << ", test: " << i;
185 }
186 }
187 }
188 }
189
TEST_P(AV1HBDSubtractBlockTest,CheckResult)190 TEST_P(AV1HBDSubtractBlockTest, CheckResult) { CheckResult(); }
191
RunForSpeed()192 void AV1HBDSubtractBlockTest::RunForSpeed() {
193 const int test_num = 200000;
194 const size_t max_width = 128;
195 const int max_block_size = max_width * max_width;
196 const int mask = (1 << bit_depth_) - 1;
197 int i, j;
198
199 for (j = 0; j < max_block_size; ++j) {
200 CONVERT_TO_SHORTPTR(src_)[j] = rnd_.Rand16() & mask;
201 CONVERT_TO_SHORTPTR(pred_)[j] = rnd_.Rand16() & mask;
202 }
203
204 for (i = 0; i < test_num; ++i) {
205 func_(block_height_, block_width_, diff_, block_width_, src_, block_width_,
206 pred_, block_width_, bit_depth_);
207 }
208 }
209
TEST_P(AV1HBDSubtractBlockTest,DISABLED_Speed)210 TEST_P(AV1HBDSubtractBlockTest, DISABLED_Speed) { RunForSpeed(); }
211
212 #if HAVE_SSE2
213 const Params kAV1HBDSubtractBlock_sse2[] = {
214 make_tuple(4, 4, 12, &aom_highbd_subtract_block_sse2),
215 make_tuple(4, 4, 12, &aom_highbd_subtract_block_c),
216 make_tuple(4, 8, 12, &aom_highbd_subtract_block_sse2),
217 make_tuple(4, 8, 12, &aom_highbd_subtract_block_c),
218 make_tuple(8, 4, 12, &aom_highbd_subtract_block_sse2),
219 make_tuple(8, 4, 12, &aom_highbd_subtract_block_c),
220 make_tuple(8, 8, 12, &aom_highbd_subtract_block_sse2),
221 make_tuple(8, 8, 12, &aom_highbd_subtract_block_c),
222 make_tuple(8, 16, 12, &aom_highbd_subtract_block_sse2),
223 make_tuple(8, 16, 12, &aom_highbd_subtract_block_c),
224 make_tuple(16, 8, 12, &aom_highbd_subtract_block_sse2),
225 make_tuple(16, 8, 12, &aom_highbd_subtract_block_c),
226 make_tuple(16, 16, 12, &aom_highbd_subtract_block_sse2),
227 make_tuple(16, 16, 12, &aom_highbd_subtract_block_c),
228 make_tuple(16, 32, 12, &aom_highbd_subtract_block_sse2),
229 make_tuple(16, 32, 12, &aom_highbd_subtract_block_c),
230 make_tuple(32, 16, 12, &aom_highbd_subtract_block_sse2),
231 make_tuple(32, 16, 12, &aom_highbd_subtract_block_c),
232 make_tuple(32, 32, 12, &aom_highbd_subtract_block_sse2),
233 make_tuple(32, 32, 12, &aom_highbd_subtract_block_c),
234 make_tuple(32, 64, 12, &aom_highbd_subtract_block_sse2),
235 make_tuple(32, 64, 12, &aom_highbd_subtract_block_c),
236 make_tuple(64, 32, 12, &aom_highbd_subtract_block_sse2),
237 make_tuple(64, 32, 12, &aom_highbd_subtract_block_c),
238 make_tuple(64, 64, 12, &aom_highbd_subtract_block_sse2),
239 make_tuple(64, 64, 12, &aom_highbd_subtract_block_c),
240 make_tuple(64, 128, 12, &aom_highbd_subtract_block_sse2),
241 make_tuple(64, 128, 12, &aom_highbd_subtract_block_c),
242 make_tuple(128, 64, 12, &aom_highbd_subtract_block_sse2),
243 make_tuple(128, 64, 12, &aom_highbd_subtract_block_c),
244 make_tuple(128, 128, 12, &aom_highbd_subtract_block_sse2),
245 make_tuple(128, 128, 12, &aom_highbd_subtract_block_c)
246 };
247
248 INSTANTIATE_TEST_SUITE_P(SSE2, AV1HBDSubtractBlockTest,
249 ::testing::ValuesIn(kAV1HBDSubtractBlock_sse2));
250 #endif // HAVE_SSE2
251 #endif // CONFIG_AV1_HIGHBITDEPTH
252 } // namespace
253