blob: 68ff0be899d238e197037682ebff83690c9ac976 [file] [log] [blame]
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -08001/*
2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <math.h>
12#include <stdlib.h>
13#include <string.h>
14
15#include "third_party/googletest/src/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"
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 {
28const int number_of_iterations = 500;
29
30typedef unsigned int (*MaskedSADFunc)(const uint8_t *a, int a_stride,
31 const uint8_t *b, int b_stride,
32 const uint8_t *m, int m_stride);
33typedef std::tr1::tuple<MaskedSADFunc, MaskedSADFunc> MaskedSADParam;
34
35class MaskedSADTest : public ::testing::TestWithParam<MaskedSADParam> {
36 public:
37 virtual ~MaskedSADTest() {}
38 virtual void SetUp() {
clang-format3a826f12016-08-11 17:46:05 -070039 maskedSAD_op_ = GET_PARAM(0);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080040 ref_maskedSAD_op_ = GET_PARAM(1);
41 }
42
Yaowu Xuc27fc142016-08-22 16:08:15 -070043 virtual void TearDown() { libaom_test::ClearSystemState(); }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080044
45 protected:
46 MaskedSADFunc maskedSAD_op_;
47 MaskedSADFunc ref_maskedSAD_op_;
48};
49
50TEST_P(MaskedSADTest, OperationCheck) {
51 unsigned int ref_ret, ret;
52 ACMRandom rnd(ACMRandom::DeterministicSeed());
clang-format3a826f12016-08-11 17:46:05 -070053 DECLARE_ALIGNED(16, uint8_t, src_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
54 DECLARE_ALIGNED(16, uint8_t, ref_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
55 DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080056 int err_count = 0;
57 int first_failure = -1;
Geza Lore552d5cd2016-03-07 13:46:39 +000058 int src_stride = MAX_SB_SIZE;
59 int ref_stride = MAX_SB_SIZE;
60 int msk_stride = MAX_SB_SIZE;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080061 for (int i = 0; i < number_of_iterations; ++i) {
clang-format3a826f12016-08-11 17:46:05 -070062 for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) {
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080063 src_ptr[j] = rnd.Rand8();
64 ref_ptr[j] = rnd.Rand8();
clang-format3a826f12016-08-11 17:46:05 -070065 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080066 assert(msk_ptr[j] <= 64);
67 }
68
69 ref_ret = ref_maskedSAD_op_(src_ptr, src_stride, ref_ptr, ref_stride,
70 msk_ptr, msk_stride);
clang-format3a826f12016-08-11 17:46:05 -070071 ASM_REGISTER_STATE_CHECK(ret = maskedSAD_op_(src_ptr, src_stride, ref_ptr,
72 ref_stride, msk_ptr,
73 msk_stride));
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080074 if (ret != ref_ret) {
75 err_count++;
clang-format3a826f12016-08-11 17:46:05 -070076 if (first_failure == -1) first_failure = i;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080077 }
78 }
79 EXPECT_EQ(0, err_count)
clang-format3a826f12016-08-11 17:46:05 -070080 << "Error: Masked SAD Test, C output doesn't match SSSE3 output. "
81 << "First failed at test case " << first_failure;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080082}
83
Yaowu Xuf883b422016-08-30 14:01:10 -070084#if CONFIG_AOM_HIGHBITDEPTH
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080085typedef unsigned int (*HighbdMaskedSADFunc)(const uint8_t *a, int a_stride,
86 const uint8_t *b, int b_stride,
87 const uint8_t *m, int m_stride);
88typedef std::tr1::tuple<HighbdMaskedSADFunc, HighbdMaskedSADFunc>
89 HighbdMaskedSADParam;
90
clang-format3a826f12016-08-11 17:46:05 -070091class HighbdMaskedSADTest
92 : public ::testing::TestWithParam<HighbdMaskedSADParam> {
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080093 public:
94 virtual ~HighbdMaskedSADTest() {}
95 virtual void SetUp() {
clang-format3a826f12016-08-11 17:46:05 -070096 maskedSAD_op_ = GET_PARAM(0);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -080097 ref_maskedSAD_op_ = GET_PARAM(1);
98 }
99
Yaowu Xuc27fc142016-08-22 16:08:15 -0700100 virtual void TearDown() { libaom_test::ClearSystemState(); }
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800101
102 protected:
103 HighbdMaskedSADFunc maskedSAD_op_;
104 HighbdMaskedSADFunc ref_maskedSAD_op_;
105};
106
107TEST_P(HighbdMaskedSADTest, OperationCheck) {
108 unsigned int ref_ret, ret;
109 ACMRandom rnd(ACMRandom::DeterministicSeed());
clang-format3a826f12016-08-11 17:46:05 -0700110 DECLARE_ALIGNED(16, uint16_t, src_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
111 DECLARE_ALIGNED(16, uint16_t, ref_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
112 DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]);
113 uint8_t *src8_ptr = CONVERT_TO_BYTEPTR(src_ptr);
114 uint8_t *ref8_ptr = CONVERT_TO_BYTEPTR(ref_ptr);
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800115 int err_count = 0;
116 int first_failure = -1;
Geza Lore552d5cd2016-03-07 13:46:39 +0000117 int src_stride = MAX_SB_SIZE;
118 int ref_stride = MAX_SB_SIZE;
119 int msk_stride = MAX_SB_SIZE;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800120 for (int i = 0; i < number_of_iterations; ++i) {
clang-format3a826f12016-08-11 17:46:05 -0700121 for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) {
122 src_ptr[j] = rnd.Rand16() & 0xfff;
123 ref_ptr[j] = rnd.Rand16() & 0xfff;
124 msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800125 }
126
127 ref_ret = ref_maskedSAD_op_(src8_ptr, src_stride, ref8_ptr, ref_stride,
128 msk_ptr, msk_stride);
clang-format3a826f12016-08-11 17:46:05 -0700129 ASM_REGISTER_STATE_CHECK(ret = maskedSAD_op_(src8_ptr, src_stride, ref8_ptr,
130 ref_stride, msk_ptr,
131 msk_stride));
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800132 if (ret != ref_ret) {
133 err_count++;
clang-format3a826f12016-08-11 17:46:05 -0700134 if (first_failure == -1) first_failure = i;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800135 }
136 }
137 EXPECT_EQ(0, err_count)
clang-format3a826f12016-08-11 17:46:05 -0700138 << "Error: High BD Masked SAD Test, C output doesn't match SSSE3 output. "
139 << "First failed at test case " << first_failure;
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800140}
Yaowu Xuf883b422016-08-30 14:01:10 -0700141#endif // CONFIG_AOM_HIGHBITDEPTH
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800142
143using std::tr1::make_tuple;
144
145#if HAVE_SSSE3
146INSTANTIATE_TEST_CASE_P(
clang-format3a826f12016-08-11 17:46:05 -0700147 SSSE3_C_COMPARE, MaskedSADTest,
148 ::testing::Values(
Geza Lore697bf5b2016-03-02 11:12:52 +0000149#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700150 make_tuple(&aom_masked_sad128x128_ssse3, &aom_masked_sad128x128_c),
151 make_tuple(&aom_masked_sad128x64_ssse3, &aom_masked_sad128x64_c),
152 make_tuple(&aom_masked_sad64x128_ssse3, &aom_masked_sad64x128_c),
Geza Lore697bf5b2016-03-02 11:12:52 +0000153#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 make_tuple(&aom_masked_sad64x64_ssse3, &aom_masked_sad64x64_c),
155 make_tuple(&aom_masked_sad64x32_ssse3, &aom_masked_sad64x32_c),
156 make_tuple(&aom_masked_sad32x64_ssse3, &aom_masked_sad32x64_c),
157 make_tuple(&aom_masked_sad32x32_ssse3, &aom_masked_sad32x32_c),
158 make_tuple(&aom_masked_sad32x16_ssse3, &aom_masked_sad32x16_c),
159 make_tuple(&aom_masked_sad16x32_ssse3, &aom_masked_sad16x32_c),
160 make_tuple(&aom_masked_sad16x16_ssse3, &aom_masked_sad16x16_c),
161 make_tuple(&aom_masked_sad16x8_ssse3, &aom_masked_sad16x8_c),
162 make_tuple(&aom_masked_sad8x16_ssse3, &aom_masked_sad8x16_c),
163 make_tuple(&aom_masked_sad8x8_ssse3, &aom_masked_sad8x8_c),
164 make_tuple(&aom_masked_sad8x4_ssse3, &aom_masked_sad8x4_c),
165 make_tuple(&aom_masked_sad4x8_ssse3, &aom_masked_sad4x8_c),
166 make_tuple(&aom_masked_sad4x4_ssse3, &aom_masked_sad4x4_c)));
167#if CONFIG_AOM_HIGHBITDEPTH
clang-format3a826f12016-08-11 17:46:05 -0700168INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, HighbdMaskedSADTest,
169 ::testing::Values(
Geza Lore697bf5b2016-03-02 11:12:52 +0000170#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700171 make_tuple(&aom_highbd_masked_sad128x128_ssse3,
172 &aom_highbd_masked_sad128x128_c),
173 make_tuple(&aom_highbd_masked_sad128x64_ssse3,
174 &aom_highbd_masked_sad128x64_c),
175 make_tuple(&aom_highbd_masked_sad64x128_ssse3,
176 &aom_highbd_masked_sad64x128_c),
Geza Lore697bf5b2016-03-02 11:12:52 +0000177#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700178 make_tuple(&aom_highbd_masked_sad64x64_ssse3,
179 &aom_highbd_masked_sad64x64_c),
180 make_tuple(&aom_highbd_masked_sad64x32_ssse3,
181 &aom_highbd_masked_sad64x32_c),
182 make_tuple(&aom_highbd_masked_sad32x64_ssse3,
183 &aom_highbd_masked_sad32x64_c),
184 make_tuple(&aom_highbd_masked_sad32x32_ssse3,
185 &aom_highbd_masked_sad32x32_c),
186 make_tuple(&aom_highbd_masked_sad32x16_ssse3,
187 &aom_highbd_masked_sad32x16_c),
188 make_tuple(&aom_highbd_masked_sad16x32_ssse3,
189 &aom_highbd_masked_sad16x32_c),
190 make_tuple(&aom_highbd_masked_sad16x16_ssse3,
191 &aom_highbd_masked_sad16x16_c),
192 make_tuple(&aom_highbd_masked_sad16x8_ssse3,
193 &aom_highbd_masked_sad16x8_c),
194 make_tuple(&aom_highbd_masked_sad8x16_ssse3,
195 &aom_highbd_masked_sad8x16_c),
196 make_tuple(&aom_highbd_masked_sad8x8_ssse3,
197 &aom_highbd_masked_sad8x8_c),
198 make_tuple(&aom_highbd_masked_sad8x4_ssse3,
199 &aom_highbd_masked_sad8x4_c),
200 make_tuple(&aom_highbd_masked_sad4x8_ssse3,
201 &aom_highbd_masked_sad4x8_c),
202 make_tuple(&aom_highbd_masked_sad4x4_ssse3,
203 &aom_highbd_masked_sad4x4_c)));
204#endif // CONFIG_AOM_HIGHBITDEPTH
Debargha Mukherjee1d69cee2016-02-29 16:08:07 -0800205#endif // HAVE_SSSE3
206} // namespace