Add dr prediction test
[aom.git] / test / masked_sad_test.cc
blob1a393a001547734dfc961b8bda572951e22e3234
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.
11 #include <math.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
16 #include "test/acm_random.h"
17 #include "test/clear_system_state.h"
18 #include "test/register_state_check.h"
19 #include "test/util.h"
21 #include "config/aom_config.h"
22 #include "config/aom_dsp_rtcd.h"
24 #include "aom/aom_integer.h"
26 using libaom_test::ACMRandom;
28 namespace {
29 const int number_of_iterations = 200;
31 typedef unsigned int (*MaskedSADFunc)(const uint8_t *src, int src_stride,
32 const uint8_t *ref, int ref_stride,
33 const uint8_t *second_pred,
34 const uint8_t *msk, int msk_stride,
35 int invert_mask);
36 typedef ::testing::tuple<MaskedSADFunc, MaskedSADFunc> MaskedSADParam;
38 class MaskedSADTest : public ::testing::TestWithParam<MaskedSADParam> {
39 public:
40 virtual ~MaskedSADTest() {}
41 virtual void SetUp() {
42 maskedSAD_op_ = GET_PARAM(0);
43 ref_maskedSAD_op_ = GET_PARAM(1);
46 virtual void TearDown() { libaom_test::ClearSystemState(); }
48 protected:
49 MaskedSADFunc maskedSAD_op_;
50 MaskedSADFunc ref_maskedSAD_op_;
53 TEST_P(MaskedSADTest, OperationCheck) {
54 unsigned int ref_ret, ret;
55 ACMRandom rnd(ACMRandom::DeterministicSeed());
56 DECLARE_ALIGNED(16, uint8_t, src_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
57 DECLARE_ALIGNED(16, uint8_t, ref_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
58 DECLARE_ALIGNED(16, uint8_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
59 DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
60 int err_count = 0;
61 int first_failure = -1;
62 int src_stride = MAX_SB_SIZE;
63 int ref_stride = MAX_SB_SIZE;
64 int msk_stride = MAX_SB_SIZE;
65 for (int i = 0; i < number_of_iterations; ++i) {
66 for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) {
67 src_ptr[j] = rnd.Rand8();
68 ref_ptr[j] = rnd.Rand8();
69 second_pred_ptr[j] = rnd.Rand8();
70 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
71 assert(msk_ptr[j] <= 64);
74 for (int invert_mask = 0; invert_mask < 2; ++invert_mask) {
75 ref_ret =
76 ref_maskedSAD_op_(src_ptr, src_stride, ref_ptr, ref_stride,
77 second_pred_ptr, msk_ptr, msk_stride, invert_mask);
78 ASM_REGISTER_STATE_CHECK(ret = maskedSAD_op_(src_ptr, src_stride, ref_ptr,
79 ref_stride, second_pred_ptr,
80 msk_ptr, msk_stride,
81 invert_mask));
82 if (ret != ref_ret) {
83 err_count++;
84 if (first_failure == -1) first_failure = i;
88 EXPECT_EQ(0, err_count)
89 << "Error: Masked SAD Test, C output doesn't match SSSE3 output. "
90 << "First failed at test case " << first_failure;
93 typedef unsigned int (*HighbdMaskedSADFunc)(const uint8_t *src, int src_stride,
94 const uint8_t *ref, int ref_stride,
95 const uint8_t *second_pred,
96 const uint8_t *msk, int msk_stride,
97 int invert_mask);
98 typedef ::testing::tuple<HighbdMaskedSADFunc, HighbdMaskedSADFunc>
99 HighbdMaskedSADParam;
101 class HighbdMaskedSADTest
102 : public ::testing::TestWithParam<HighbdMaskedSADParam> {
103 public:
104 virtual ~HighbdMaskedSADTest() {}
105 virtual void SetUp() {
106 maskedSAD_op_ = GET_PARAM(0);
107 ref_maskedSAD_op_ = GET_PARAM(1);
110 virtual void TearDown() { libaom_test::ClearSystemState(); }
112 protected:
113 HighbdMaskedSADFunc maskedSAD_op_;
114 HighbdMaskedSADFunc ref_maskedSAD_op_;
117 TEST_P(HighbdMaskedSADTest, OperationCheck) {
118 unsigned int ref_ret, ret;
119 ACMRandom rnd(ACMRandom::DeterministicSeed());
120 DECLARE_ALIGNED(16, uint16_t, src_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
121 DECLARE_ALIGNED(16, uint16_t, ref_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
122 DECLARE_ALIGNED(16, uint16_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
123 DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
124 uint8_t *src8_ptr = CONVERT_TO_BYTEPTR(src_ptr);
125 uint8_t *ref8_ptr = CONVERT_TO_BYTEPTR(ref_ptr);
126 uint8_t *second_pred8_ptr = CONVERT_TO_BYTEPTR(second_pred_ptr);
127 int err_count = 0;
128 int first_failure = -1;
129 int src_stride = MAX_SB_SIZE;
130 int ref_stride = MAX_SB_SIZE;
131 int msk_stride = MAX_SB_SIZE;
132 for (int i = 0; i < number_of_iterations; ++i) {
133 for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) {
134 src_ptr[j] = rnd.Rand16() & 0xfff;
135 ref_ptr[j] = rnd.Rand16() & 0xfff;
136 second_pred_ptr[j] = rnd.Rand16() & 0xfff;
137 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
140 for (int invert_mask = 0; invert_mask < 2; ++invert_mask) {
141 ref_ret =
142 ref_maskedSAD_op_(src8_ptr, src_stride, ref8_ptr, ref_stride,
143 second_pred8_ptr, msk_ptr, msk_stride, invert_mask);
144 ASM_REGISTER_STATE_CHECK(ret = maskedSAD_op_(src8_ptr, src_stride,
145 ref8_ptr, ref_stride,
146 second_pred8_ptr, msk_ptr,
147 msk_stride, invert_mask));
148 if (ret != ref_ret) {
149 err_count++;
150 if (first_failure == -1) first_failure = i;
154 EXPECT_EQ(0, err_count)
155 << "Error: High BD Masked SAD Test, C output doesn't match SSSE3 output. "
156 << "First failed at test case " << first_failure;
159 using ::testing::make_tuple;
161 #if HAVE_SSSE3
162 const MaskedSADParam msad_test[] = {
163 make_tuple(&aom_masked_sad128x128_ssse3, &aom_masked_sad128x128_c),
164 make_tuple(&aom_masked_sad128x64_ssse3, &aom_masked_sad128x64_c),
165 make_tuple(&aom_masked_sad64x128_ssse3, &aom_masked_sad64x128_c),
166 make_tuple(&aom_masked_sad64x64_ssse3, &aom_masked_sad64x64_c),
167 make_tuple(&aom_masked_sad64x32_ssse3, &aom_masked_sad64x32_c),
168 make_tuple(&aom_masked_sad32x64_ssse3, &aom_masked_sad32x64_c),
169 make_tuple(&aom_masked_sad32x32_ssse3, &aom_masked_sad32x32_c),
170 make_tuple(&aom_masked_sad32x16_ssse3, &aom_masked_sad32x16_c),
171 make_tuple(&aom_masked_sad16x32_ssse3, &aom_masked_sad16x32_c),
172 make_tuple(&aom_masked_sad16x16_ssse3, &aom_masked_sad16x16_c),
173 make_tuple(&aom_masked_sad16x8_ssse3, &aom_masked_sad16x8_c),
174 make_tuple(&aom_masked_sad8x16_ssse3, &aom_masked_sad8x16_c),
175 make_tuple(&aom_masked_sad8x8_ssse3, &aom_masked_sad8x8_c),
176 make_tuple(&aom_masked_sad8x4_ssse3, &aom_masked_sad8x4_c),
177 make_tuple(&aom_masked_sad4x8_ssse3, &aom_masked_sad4x8_c),
178 make_tuple(&aom_masked_sad4x4_ssse3, &aom_masked_sad4x4_c)
181 INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, MaskedSADTest,
182 ::testing::ValuesIn(msad_test));
183 const HighbdMaskedSADParam hbd_msad_test[] = {
184 make_tuple(&aom_highbd_masked_sad128x128_ssse3,
185 &aom_highbd_masked_sad128x128_c),
186 make_tuple(&aom_highbd_masked_sad128x64_ssse3,
187 &aom_highbd_masked_sad128x64_c),
188 make_tuple(&aom_highbd_masked_sad64x128_ssse3,
189 &aom_highbd_masked_sad64x128_c),
190 make_tuple(&aom_highbd_masked_sad64x64_ssse3, &aom_highbd_masked_sad64x64_c),
191 make_tuple(&aom_highbd_masked_sad64x32_ssse3, &aom_highbd_masked_sad64x32_c),
192 make_tuple(&aom_highbd_masked_sad32x64_ssse3, &aom_highbd_masked_sad32x64_c),
193 make_tuple(&aom_highbd_masked_sad32x32_ssse3, &aom_highbd_masked_sad32x32_c),
194 make_tuple(&aom_highbd_masked_sad32x16_ssse3, &aom_highbd_masked_sad32x16_c),
195 make_tuple(&aom_highbd_masked_sad16x32_ssse3, &aom_highbd_masked_sad16x32_c),
196 make_tuple(&aom_highbd_masked_sad16x16_ssse3, &aom_highbd_masked_sad16x16_c),
197 make_tuple(&aom_highbd_masked_sad16x8_ssse3, &aom_highbd_masked_sad16x8_c),
198 make_tuple(&aom_highbd_masked_sad8x16_ssse3, &aom_highbd_masked_sad8x16_c),
199 make_tuple(&aom_highbd_masked_sad8x8_ssse3, &aom_highbd_masked_sad8x8_c),
200 make_tuple(&aom_highbd_masked_sad8x4_ssse3, &aom_highbd_masked_sad8x4_c),
201 make_tuple(&aom_highbd_masked_sad4x8_ssse3, &aom_highbd_masked_sad4x8_c),
202 make_tuple(&aom_highbd_masked_sad4x4_ssse3, &aom_highbd_masked_sad4x4_c)
205 INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, HighbdMaskedSADTest,
206 ::testing::ValuesIn(hbd_msad_test));
207 #endif // HAVE_SSSE3
208 } // namespace