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