Add aom_lowbd_blend_a64_d16_mask_sse4_1
[aom.git] / test / blend_a64_mask_test.cc
blob77d8b8108794a9955faf1407aeff455a5bd8ceac
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #include <math.h>
13 #include <stdlib.h>
14 #include <string.h>
16 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
17 #include "test/register_state_check.h"
18 #include "test/function_equivalence_test.h"
20 #include "config/aom_config.h"
21 #include "config/aom_dsp_rtcd.h"
22 #include "config/av1_rtcd.h"
24 #include "aom/aom_integer.h"
26 #include "av1/common/enums.h"
28 #include "aom_dsp/blend.h"
30 using libaom_test::FunctionEquivalenceTest;
32 namespace {
34 template <typename BlendA64Func, typename SrcPixel, typename DstPixel>
35 class BlendA64MaskTest : public FunctionEquivalenceTest<BlendA64Func> {
36 protected:
37 static const int kIterations = 10000;
38 static const int kMaxWidth = MAX_SB_SIZE * 5; // * 5 to cover longer strides
39 static const int kMaxHeight = MAX_SB_SIZE;
40 static const int kBufSize = kMaxWidth * kMaxHeight;
41 static const int kMaxMaskWidth = 2 * MAX_SB_SIZE;
42 static const int kMaxMaskSize = kMaxMaskWidth * kMaxMaskWidth;
44 virtual ~BlendA64MaskTest() {}
46 virtual void Execute(const SrcPixel *p_src0, const SrcPixel *p_src1) = 0;
48 template <typename Pixel>
49 void GetSources(Pixel **src0, Pixel **src1, Pixel * /*dst*/) {
50 switch (this->rng_(3)) {
51 case 0: // Separate sources
52 *src0 = src0_;
53 *src1 = src1_;
54 break;
55 case 1: // src0 == dst
56 *src0 = dst_tst_;
57 src0_stride_ = dst_stride_;
58 src0_offset_ = dst_offset_;
59 *src1 = src1_;
60 break;
61 case 2: // src1 == dst
62 *src0 = src0_;
63 *src1 = dst_tst_;
64 src1_stride_ = dst_stride_;
65 src1_offset_ = dst_offset_;
66 break;
67 default: FAIL();
71 void GetSources(uint16_t **src0, uint16_t **src1, uint8_t * /*dst*/) {
72 *src0 = src0_;
73 *src1 = src1_;
76 uint8_t Rand1() { return this->rng_.Rand8() & 1; }
78 void Common() {
79 w_ = 4 << this->rng_(MAX_SB_SIZE_LOG2 - 1);
80 h_ = 4 << this->rng_(MAX_SB_SIZE_LOG2 - 1);
82 subx_ = Rand1();
83 suby_ = Rand1();
85 dst_offset_ = this->rng_(33);
86 dst_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
88 src0_offset_ = this->rng_(33);
89 src0_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
91 src1_offset_ = this->rng_(33);
92 src1_stride_ = this->rng_(kMaxWidth + 1 - w_) + w_;
94 mask_stride_ =
95 this->rng_(kMaxWidth + 1 - w_ * (subx_ ? 2 : 1)) + w_ * (subx_ ? 2 : 1);
97 SrcPixel *p_src0;
98 SrcPixel *p_src1;
100 p_src0 = src0_;
101 p_src1 = src1_;
103 GetSources(&p_src0, &p_src1, &dst_ref_[0]);
105 Execute(p_src0, p_src1);
107 for (int r = 0; r < h_; ++r) {
108 for (int c = 0; c < w_; ++c) {
109 ASSERT_EQ(dst_ref_[dst_offset_ + r * dst_stride_ + c],
110 dst_tst_[dst_offset_ + r * dst_stride_ + c]);
115 DstPixel dst_ref_[kBufSize];
116 DstPixel dst_tst_[kBufSize];
117 uint32_t dst_stride_;
118 uint32_t dst_offset_;
120 SrcPixel src0_[kBufSize];
121 uint32_t src0_stride_;
122 uint32_t src0_offset_;
124 SrcPixel src1_[kBufSize];
125 uint32_t src1_stride_;
126 uint32_t src1_offset_;
128 uint8_t mask_[kMaxMaskSize];
129 size_t mask_stride_;
131 int w_;
132 int h_;
134 int suby_;
135 int subx_;
138 //////////////////////////////////////////////////////////////////////////////
139 // 8 bit version
140 //////////////////////////////////////////////////////////////////////////////
142 typedef void (*F8B)(uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
143 uint32_t src0_stride, const uint8_t *src1,
144 uint32_t src1_stride, const uint8_t *mask,
145 uint32_t mask_stride, int h, int w, int suby, int subx);
146 typedef libaom_test::FuncParam<F8B> TestFuncs;
148 class BlendA64MaskTest8B : public BlendA64MaskTest<F8B, uint8_t, uint8_t> {
149 protected:
150 void Execute(const uint8_t *p_src0, const uint8_t *p_src1) {
151 params_.ref_func(dst_ref_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
152 src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_,
153 kMaxMaskWidth, h_, w_, suby_, subx_);
154 ASM_REGISTER_STATE_CHECK(params_.tst_func(
155 dst_tst_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
156 src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_, kMaxMaskWidth,
157 h_, w_, suby_, subx_));
161 TEST_P(BlendA64MaskTest8B, RandomValues) {
162 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
163 for (int i = 0; i < kBufSize; ++i) {
164 dst_ref_[i] = rng_.Rand8();
165 dst_tst_[i] = rng_.Rand8();
167 src0_[i] = rng_.Rand8();
168 src1_[i] = rng_.Rand8();
171 for (int i = 0; i < kMaxMaskSize; ++i)
172 mask_[i] = rng_(AOM_BLEND_A64_MAX_ALPHA + 1);
174 Common();
178 TEST_P(BlendA64MaskTest8B, ExtremeValues) {
179 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
180 for (int i = 0; i < kBufSize; ++i) {
181 dst_ref_[i] = rng_(2) + 254;
182 dst_tst_[i] = rng_(2) + 254;
183 src0_[i] = rng_(2) + 254;
184 src1_[i] = rng_(2) + 254;
187 for (int i = 0; i < kMaxMaskSize; ++i)
188 mask_[i] = rng_(2) + AOM_BLEND_A64_MAX_ALPHA - 1;
190 Common();
194 #if HAVE_SSE4_1
195 INSTANTIATE_TEST_CASE_P(SSE4_1, BlendA64MaskTest8B,
196 ::testing::Values(TestFuncs(
197 aom_blend_a64_mask_c, aom_blend_a64_mask_sse4_1)));
198 #endif // HAVE_SSE4_1
200 //////////////////////////////////////////////////////////////////////////////
201 // 8 bit _d16 version
202 //////////////////////////////////////////////////////////////////////////////
204 typedef void (*F8B_D16)(uint8_t *dst, uint32_t dst_stride, const uint16_t *src0,
205 uint32_t src0_stride, const uint16_t *src1,
206 uint32_t src1_stride, const uint8_t *mask,
207 uint32_t mask_stride, int h, int w, int suby, int subx,
208 ConvolveParams *conv_params);
209 typedef libaom_test::FuncParam<F8B_D16> TestFuncs_d16;
211 class BlendA64MaskTest8B_d16
212 : public BlendA64MaskTest<F8B_D16, uint16_t, uint8_t> {
213 protected:
214 // max number of bits used by the source
215 static const int kSrcMaxBitsMask = 0x3fff;
217 void Execute(const uint16_t *p_src0, const uint16_t *p_src1) {
218 ConvolveParams conv_params;
219 conv_params.round_0 = ROUND0_BITS;
220 conv_params.round_1 = COMPOUND_ROUND1_BITS;
221 params_.ref_func(dst_ref_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
222 src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_,
223 kMaxMaskWidth, h_, w_, suby_, subx_, &conv_params);
224 ASM_REGISTER_STATE_CHECK(params_.tst_func(
225 dst_tst_ + dst_offset_, dst_stride_, p_src0 + src0_offset_,
226 src0_stride_, p_src1 + src1_offset_, src1_stride_, mask_, kMaxMaskWidth,
227 h_, w_, suby_, subx_, &conv_params));
231 TEST_P(BlendA64MaskTest8B_d16, RandomValues) {
232 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
233 for (int i = 0; i < kBufSize; ++i) {
234 dst_ref_[i] = rng_.Rand8();
235 dst_tst_[i] = rng_.Rand8();
237 src0_[i] = rng_.Rand16() & kSrcMaxBitsMask;
238 src1_[i] = rng_.Rand16() & kSrcMaxBitsMask;
241 for (int i = 0; i < kMaxMaskSize; ++i)
242 mask_[i] = rng_(AOM_BLEND_A64_MAX_ALPHA + 1);
244 Common();
248 TEST_P(BlendA64MaskTest8B_d16, ExtremeValues) {
249 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
250 for (int i = 0; i < kBufSize; ++i) {
251 dst_ref_[i] = 255;
252 dst_tst_[i] = 255;
254 src0_[i] = kSrcMaxBitsMask;
255 src1_[i] = kSrcMaxBitsMask;
258 for (int i = 0; i < kMaxMaskSize; ++i)
259 mask_[i] = AOM_BLEND_A64_MAX_ALPHA - 1;
261 Common();
265 #if HAVE_SSE4_1
266 INSTANTIATE_TEST_CASE_P(
267 SSE4_1, BlendA64MaskTest8B_d16,
268 ::testing::Values(TestFuncs_d16(aom_lowbd_blend_a64_d16_mask_c,
269 aom_lowbd_blend_a64_d16_mask_sse4_1)));
270 #endif // HAVE_SSE4_1
272 //////////////////////////////////////////////////////////////////////////////
273 // High bit-depth version
274 //////////////////////////////////////////////////////////////////////////////
276 typedef void (*FHBD)(uint8_t *dst, uint32_t dst_stride, const uint8_t *src0,
277 uint32_t src0_stride, const uint8_t *src1,
278 uint32_t src1_stride, const uint8_t *mask,
279 uint32_t mask_stride, int h, int w, int suby, int subx,
280 int bd);
281 typedef libaom_test::FuncParam<FHBD> TestFuncsHBD;
283 class BlendA64MaskTestHBD : public BlendA64MaskTest<FHBD, uint16_t, uint16_t> {
284 protected:
285 void Execute(const uint16_t *p_src0, const uint16_t *p_src1) {
286 params_.ref_func(CONVERT_TO_BYTEPTR(dst_ref_ + dst_offset_), dst_stride_,
287 CONVERT_TO_BYTEPTR(p_src0 + src0_offset_), src0_stride_,
288 CONVERT_TO_BYTEPTR(p_src1 + src1_offset_), src1_stride_,
289 mask_, kMaxMaskWidth, h_, w_, suby_, subx_, bit_depth_);
290 ASM_REGISTER_STATE_CHECK(params_.tst_func(
291 CONVERT_TO_BYTEPTR(dst_tst_ + dst_offset_), dst_stride_,
292 CONVERT_TO_BYTEPTR(p_src0 + src0_offset_), src0_stride_,
293 CONVERT_TO_BYTEPTR(p_src1 + src1_offset_), src1_stride_, mask_,
294 kMaxMaskWidth, h_, w_, suby_, subx_, bit_depth_));
297 int bit_depth_;
300 TEST_P(BlendA64MaskTestHBD, RandomValues) {
301 for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
302 switch (rng_(3)) {
303 case 0: bit_depth_ = 8; break;
304 case 1: bit_depth_ = 10; break;
305 default: bit_depth_ = 12; break;
308 const int hi = 1 << bit_depth_;
310 for (int i = 0; i < kBufSize; ++i) {
311 dst_ref_[i] = rng_(hi);
312 dst_tst_[i] = rng_(hi);
313 src0_[i] = rng_(hi);
314 src1_[i] = rng_(hi);
317 for (int i = 0; i < kMaxMaskSize; ++i)
318 mask_[i] = rng_(AOM_BLEND_A64_MAX_ALPHA + 1);
320 Common();
324 TEST_P(BlendA64MaskTestHBD, ExtremeValues) {
325 for (int iter = 0; iter < 1000 && !HasFatalFailure(); ++iter) {
326 switch (rng_(3)) {
327 case 0: bit_depth_ = 8; break;
328 case 1: bit_depth_ = 10; break;
329 default: bit_depth_ = 12; break;
332 const int hi = 1 << bit_depth_;
333 const int lo = hi - 2;
335 for (int i = 0; i < kBufSize; ++i) {
336 dst_ref_[i] = rng_(hi - lo) + lo;
337 dst_tst_[i] = rng_(hi - lo) + lo;
338 src0_[i] = rng_(hi - lo) + lo;
339 src1_[i] = rng_(hi - lo) + lo;
342 for (int i = 0; i < kMaxMaskSize; ++i)
343 mask_[i] = rng_(2) + AOM_BLEND_A64_MAX_ALPHA - 1;
345 Common();
349 #if HAVE_SSE4_1
350 INSTANTIATE_TEST_CASE_P(
351 SSE4_1, BlendA64MaskTestHBD,
352 ::testing::Values(TestFuncsHBD(aom_highbd_blend_a64_mask_c,
353 aom_highbd_blend_a64_mask_sse4_1)));
354 #endif // HAVE_SSE4_1
355 } // namespace