Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 10 | */ |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 11 | #include <math.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 15 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 21 | #include "./aom_config.h" |
| 22 | #include "./aom_dsp_rtcd.h" |
| 23 | #include "aom/aom_integer.h" |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 24 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | using libaom_test::ACMRandom; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 26 | |
| 27 | namespace { |
David Barker | 0aa39ff | 2017-05-23 12:53:08 +0100 | [diff] [blame] | 28 | const int number_of_iterations = 200; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 29 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 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); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 35 | typedef std::tr1::tuple<MaskedSADFunc, MaskedSADFunc> MaskedSADParam; |
| 36 | |
| 37 | class MaskedSADTest : public ::testing::TestWithParam<MaskedSADParam> { |
| 38 | public: |
| 39 | virtual ~MaskedSADTest() {} |
| 40 | virtual void SetUp() { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 41 | maskedSAD_op_ = GET_PARAM(0); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 42 | ref_maskedSAD_op_ = GET_PARAM(1); |
| 43 | } |
| 44 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 45 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | MaskedSADFunc maskedSAD_op_; |
| 49 | MaskedSADFunc ref_maskedSAD_op_; |
| 50 | }; |
| 51 | |
| 52 | TEST_P(MaskedSADTest, OperationCheck) { |
| 53 | unsigned int ref_ret, ret; |
| 54 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 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]); |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 57 | DECLARE_ALIGNED(16, uint8_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 58 | DECLARE_ALIGNED(16, uint8_t, msk_ptr[MAX_SB_SIZE * MAX_SB_SIZE]); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 59 | int err_count = 0; |
| 60 | int first_failure = -1; |
Geza Lore | 552d5cd | 2016-03-07 13:46:39 +0000 | [diff] [blame] | 61 | int src_stride = MAX_SB_SIZE; |
| 62 | int ref_stride = MAX_SB_SIZE; |
| 63 | int msk_stride = MAX_SB_SIZE; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 64 | for (int i = 0; i < number_of_iterations; ++i) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 65 | for (int j = 0; j < MAX_SB_SIZE * MAX_SB_SIZE; j++) { |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 66 | src_ptr[j] = rnd.Rand8(); |
| 67 | ref_ptr[j] = rnd.Rand8(); |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 68 | second_pred_ptr[j] = rnd.Rand8(); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 69 | msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 70 | assert(msk_ptr[j] <= 64); |
| 71 | } |
| 72 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 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; |
| 84 | } |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | EXPECT_EQ(0, err_count) |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 88 | << "Error: Masked SAD Test, C output doesn't match SSSE3 output. " |
| 89 | << "First failed at test case " << first_failure; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 90 | } |
| 91 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 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); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 97 | typedef std::tr1::tuple<HighbdMaskedSADFunc, HighbdMaskedSADFunc> |
| 98 | HighbdMaskedSADParam; |
| 99 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 100 | class HighbdMaskedSADTest |
| 101 | : public ::testing::TestWithParam<HighbdMaskedSADParam> { |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 102 | public: |
| 103 | virtual ~HighbdMaskedSADTest() {} |
| 104 | virtual void SetUp() { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 105 | maskedSAD_op_ = GET_PARAM(0); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 106 | ref_maskedSAD_op_ = GET_PARAM(1); |
| 107 | } |
| 108 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 109 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 110 | |
| 111 | protected: |
| 112 | HighbdMaskedSADFunc maskedSAD_op_; |
| 113 | HighbdMaskedSADFunc ref_maskedSAD_op_; |
| 114 | }; |
| 115 | |
| 116 | TEST_P(HighbdMaskedSADTest, OperationCheck) { |
| 117 | unsigned int ref_ret, ret; |
| 118 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 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]); |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 121 | DECLARE_ALIGNED(16, uint16_t, second_pred_ptr[MAX_SB_SIZE * MAX_SB_SIZE]); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 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); |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 125 | uint8_t *second_pred8_ptr = CONVERT_TO_BYTEPTR(second_pred_ptr); |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 126 | int err_count = 0; |
| 127 | int first_failure = -1; |
Geza Lore | 552d5cd | 2016-03-07 13:46:39 +0000 | [diff] [blame] | 128 | int src_stride = MAX_SB_SIZE; |
| 129 | int ref_stride = MAX_SB_SIZE; |
| 130 | int msk_stride = MAX_SB_SIZE; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 131 | for (int i = 0; i < number_of_iterations; ++i) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 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; |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 135 | second_pred_ptr[j] = rnd.Rand16() & 0xfff; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 136 | msk_ptr[j] = ((rnd.Rand8() & 0x7f) > 64) ? rnd.Rand8() & 0x3f : 64; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 137 | } |
| 138 | |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 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; |
| 150 | } |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | EXPECT_EQ(0, err_count) |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 154 | << "Error: High BD Masked SAD Test, C output doesn't match SSSE3 output. " |
| 155 | << "First failed at test case " << first_failure; |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 156 | } |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 157 | |
| 158 | using std::tr1::make_tuple; |
| 159 | |
David Barker | 0aa39ff | 2017-05-23 12:53:08 +0100 | [diff] [blame] | 160 | #if HAVE_SSSE3 |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 161 | const MaskedSADParam msad_test[] = { |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 162 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 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), |
David Barker | 0f3c94e | 2017-05-16 15:21:50 +0100 | [diff] [blame] | 166 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 167 | 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 | |
| 182 | INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, MaskedSADTest, |
| 183 | ::testing::ValuesIn(msad_test)); |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 184 | const HighbdMaskedSADParam hbd_msad_test[] = { |
David Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 185 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 186 | 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 Barker | f19f35f | 2017-05-22 16:33:22 +0100 | [diff] [blame] | 192 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | 28c779b | 2017-06-03 08:40:49 -0700 | [diff] [blame] | 193 | 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 | |
| 208 | INSTANTIATE_TEST_CASE_P(SSSE3_C_COMPARE, HighbdMaskedSADTest, |
| 209 | ::testing::ValuesIn(hbd_msad_test)); |
David Barker | 0aa39ff | 2017-05-23 12:53:08 +0100 | [diff] [blame] | 210 | #endif // HAVE_SSSE3 |
Debargha Mukherjee | 1d69cee | 2016-02-29 16:08:07 -0800 | [diff] [blame] | 211 | } // namespace |