blob: 928b47ee14bbe742d497a335aa49a556f664647e [file] [log] [blame]
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -08001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -08003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080010 */
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080011#include <math.h>
12#include <stdlib.h>
13#include <string.h>
14
Tom Finegan7a07ece2017-02-07 17:14:05 -080015#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080016#include "test/acm_random.h"
17#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
19#include "test/util.h"
20
Yaowu Xuf883b422016-08-30 14:01:10 -070021#include "./aom_config.h"
22#include "./aom_dsp_rtcd.h"
23#include "aom/aom_integer.h"
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080024
Yaowu Xuc27fc142016-08-22 16:08:15 -070025using libaom_test::ACMRandom;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080026
27namespace {
David Barker0aa39ff2017-05-23 12:53:08 +010028const int number_of_iterations = 200;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080029
David Barker0f3c94e2017-05-16 15:21:50 +010030typedef 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);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080035typedef std::tr1::tuple<MaskedSADFunc, MaskedSADFunc> MaskedSADParam;
36
37class MaskedSADTest : public ::testing::TestWithParam<MaskedSADParam> {
38 public:
39 virtual ~MaskedSADTest() {}
40 virtual void SetUp() {
clang-format3a826f12016-08-11 17:46:05 -070041 maskedSAD_op_ = GET_PARAM(0);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080042 ref_maskedSAD_op_ = GET_PARAM(1);
43 }
44
Yaowu Xuc27fc142016-08-22 16:08:15 -070045 virtual void TearDown() { libaom_test::ClearSystemState(); }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080046
47 protected:
48 MaskedSADFunc maskedSAD_op_;
49 MaskedSADFunc ref_maskedSAD_op_;
50};
51
52TEST_P(MaskedSADTest, OperationCheck) {
53 unsigned int ref_ret, ret;
54 ACMRandom rnd(ACMRandom::DeterministicSeed());
clang-format3a826f12016-08-11 17:46:05 -070055 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]);
David Barker0f3c94e2017-05-16 15:21:50 +010057 DECLARE_ALIGNED(16, uint8_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
clang-format3a826f12016-08-11 17:46:05 -070058 DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080059 int err_count = 0;
60 int first_failure = -1;
Geza Lore552d5cd2016-03-07 13:46:39 +000061 int src_stride = MAX_SB_SIZE;
62 int ref_stride = MAX_SB_SIZE;
63 int msk_stride = MAX_SB_SIZE;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080064 for (int i = 0; i < number_of_iterations; ++i) {
clang-format3a826f12016-08-11 17:46:05 -070065 for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) {
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080066 src_ptr[j] = rnd.Rand8();
67 ref_ptr[j] = rnd.Rand8();
David Barker0f3c94e2017-05-16 15:21:50 +010068 second_pred_ptr[j] = rnd.Rand8();
clang-format3a826f12016-08-11 17:46:05 -070069 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080070 assert(msk_ptr[j] <= 64);
71 }
72
David Barker0f3c94e2017-05-16 15:21:50 +010073 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;
84 }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080085 }
86 }
87 EXPECT_EQ(0, err_count)
clang-format3a826f12016-08-11 17:46:05 -070088 << "Error: Masked SAD Test, C output doesn't match SSSE3 output. "
89 << "First failed at test case " << first_failure;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080090}
91
David Barker0f3c94e2017-05-16 15:21:50 +010092typedef 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);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080097typedef std::tr1::tuple<HighbdMaskedSADFunc, HighbdMaskedSADFunc>
98 HighbdMaskedSADParam;
99
clang-format3a826f12016-08-11 17:46:05 -0700100class HighbdMaskedSADTest
101 : public ::testing::TestWithParam<HighbdMaskedSADParam> {
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800102 public:
103 virtual ~HighbdMaskedSADTest() {}
104 virtual void SetUp() {
clang-format3a826f12016-08-11 17:46:05 -0700105 maskedSAD_op_ = GET_PARAM(0);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800106 ref_maskedSAD_op_ = GET_PARAM(1);
107 }
108
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 virtual void TearDown() { libaom_test::ClearSystemState(); }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800110
111 protected:
112 HighbdMaskedSADFunc maskedSAD_op_;
113 HighbdMaskedSADFunc ref_maskedSAD_op_;
114};
115
116TEST_P(HighbdMaskedSADTest, OperationCheck) {
117 unsigned int ref_ret, ret;
118 ACMRandom rnd(ACMRandom::DeterministicSeed());
clang-format3a826f12016-08-11 17:46:05 -0700119 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]);
David Barker0f3c94e2017-05-16 15:21:50 +0100121 DECLARE_ALIGNED(16, uint16_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
clang-format3a826f12016-08-11 17:46:05 -0700122 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);
David Barker0f3c94e2017-05-16 15:21:50 +0100125 uint8_t *second_pred8_ptr = CONVERT_TO_BYTEPTR(second_pred_ptr);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800126 int err_count = 0;
127 int first_failure = -1;
Geza Lore552d5cd2016-03-07 13:46:39 +0000128 int src_stride = MAX_SB_SIZE;
129 int ref_stride = MAX_SB_SIZE;
130 int msk_stride = MAX_SB_SIZE;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800131 for (int i = 0; i < number_of_iterations; ++i) {
clang-format3a826f12016-08-11 17:46:05 -0700132 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;
David Barker0f3c94e2017-05-16 15:21:50 +0100135 second_pred_ptr[j] = rnd.Rand16() & 0xfff;
clang-format3a826f12016-08-11 17:46:05 -0700136 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800137 }
138
David Barker0f3c94e2017-05-16 15:21:50 +0100139 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;
150 }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800151 }
152 }
153 EXPECT_EQ(0, err_count)
clang-format3a826f12016-08-11 17:46:05 -0700154 << "Error: High BD Masked SAD Test, C output doesn't match SSSE3 output. "
155 << "First failed at test case " << first_failure;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800156}
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800157
158using std::tr1::make_tuple;
159
David Barker0aa39ff2017-05-23 12:53:08 +0100160#if HAVE_SSSE3
Yaowu Xu28c779b2017-06-03 08:40:49 -0700161const MaskedSADParam msad_test[] = {
David Barker0f3c94e2017-05-16 15:21:50 +0100162#if CONFIG_EXT_PARTITION
Yaowu Xu28c779b2017-06-03 08:40:49 -0700163 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),
David Barker0f3c94e2017-05-16 15:21:50 +0100166#endif // CONFIG_EXT_PARTITION
Yaowu Xu28c779b2017-06-03 08:40:49 -0700167 make_tuple(&aom_masked_sad64x64_ssse3, &aom_masked_sad64x64_c),
168 make_tuple(&aom_masked_sad64x32_ssse3, &aom_masked_sad64x32_c),
169 make_tuple(&aom_masked_sad32x64_ssse3, &aom_masked_sad32x64_c),
170 make_tuple(&aom_masked_sad32x32_ssse3, &aom_masked_sad32x32_c),
171 make_tuple(&aom_masked_sad32x16_ssse3, &aom_masked_sad32x16_c),
172 make_tuple(&aom_masked_sad16x32_ssse3, &aom_masked_sad16x32_c),
173 make_tuple(&aom_masked_sad16x16_ssse3, &aom_masked_sad16x16_c),
174 make_tuple(&aom_masked_sad16x8_ssse3, &aom_masked_sad16x8_c),
175 make_tuple(&aom_masked_sad8x16_ssse3, &aom_masked_sad8x16_c),
176 make_tuple(&aom_masked_sad8x8_ssse3, &aom_masked_sad8x8_c),
177 make_tuple(&aom_masked_sad8x4_ssse3, &aom_masked_sad8x4_c),
178 make_tuple(&aom_masked_sad4x8_ssse3, &aom_masked_sad4x8_c),
179 make_tuple(&aom_masked_sad4x4_ssse3, &aom_masked_sad4x4_c)
180};
181
182INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, MaskedSADTest,
183 ::testing::ValuesIn(msad_test));
Yaowu Xu28c779b2017-06-03 08:40:49 -0700184const HighbdMaskedSADParam hbd_msad_test[] = {
David Barkerf19f35f2017-05-22 16:33:22 +0100185#if CONFIG_EXT_PARTITION
Yaowu Xu28c779b2017-06-03 08:40:49 -0700186 make_tuple(&aom_highbd_masked_sad128x128_ssse3,
187 &aom_highbd_masked_sad128x128_c),
188 make_tuple(&aom_highbd_masked_sad128x64_ssse3,
189 &aom_highbd_masked_sad128x64_c),
190 make_tuple(&aom_highbd_masked_sad64x128_ssse3,
191 &aom_highbd_masked_sad64x128_c),
David Barkerf19f35f2017-05-22 16:33:22 +0100192#endif // CONFIG_EXT_PARTITION
Yaowu Xu28c779b2017-06-03 08:40:49 -0700193 make_tuple(&aom_highbd_masked_sad64x64_ssse3, &aom_highbd_masked_sad64x64_c),
194 make_tuple(&aom_highbd_masked_sad64x32_ssse3, &aom_highbd_masked_sad64x32_c),
195 make_tuple(&aom_highbd_masked_sad32x64_ssse3, &aom_highbd_masked_sad32x64_c),
196 make_tuple(&aom_highbd_masked_sad32x32_ssse3, &aom_highbd_masked_sad32x32_c),
197 make_tuple(&aom_highbd_masked_sad32x16_ssse3, &aom_highbd_masked_sad32x16_c),
198 make_tuple(&aom_highbd_masked_sad16x32_ssse3, &aom_highbd_masked_sad16x32_c),
199 make_tuple(&aom_highbd_masked_sad16x16_ssse3, &aom_highbd_masked_sad16x16_c),
200 make_tuple(&aom_highbd_masked_sad16x8_ssse3, &aom_highbd_masked_sad16x8_c),
201 make_tuple(&aom_highbd_masked_sad8x16_ssse3, &aom_highbd_masked_sad8x16_c),
202 make_tuple(&aom_highbd_masked_sad8x8_ssse3, &aom_highbd_masked_sad8x8_c),
203 make_tuple(&aom_highbd_masked_sad8x4_ssse3, &aom_highbd_masked_sad8x4_c),
204 make_tuple(&aom_highbd_masked_sad4x8_ssse3, &aom_highbd_masked_sad4x8_c),
205 make_tuple(&aom_highbd_masked_sad4x4_ssse3, &aom_highbd_masked_sad4x4_c)
206};
207
208INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, HighbdMaskedSADTest,
209 ::testing::ValuesIn(hbd_msad_test));
David Barker0aa39ff2017-05-23 12:53:08 +0100210#endif // HAVE_SSSE3
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800211} // namespace