Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, Alliance for Open Media. All rights reserved |
| 3 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <stdint.h> |
| 13 | #include <stdio.h> |
| 14 | #include <string.h> |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 15 | #include <tuple> |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 16 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 17 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 18 | #include "config/av1_rtcd.h" |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 19 | |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 20 | #include "aom_ports/mem.h" |
| 21 | #include "av1/common/scan.h" |
| 22 | #include "av1/common/txb_common.h" |
| 23 | #include "test/acm_random.h" |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 24 | #include "test/register_state_check.h" |
| 25 | #include "test/util.h" |
| 26 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
| 27 | |
| 28 | namespace { |
| 29 | using libaom_test::ACMRandom; |
| 30 | |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 31 | typedef void (*buildcompdiffwtdmaskd_func)(uint8_t *mask, |
| 32 | DIFFWTD_MASK_TYPE mask_type, |
| 33 | const uint8_t *src0, int src0_stride, |
| 34 | const uint8_t *src1, int src1_stride, |
| 35 | int h, int w); |
| 36 | |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 37 | typedef std::tuple<BLOCK_SIZE, buildcompdiffwtdmaskd_func> |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 38 | BuildCompDiffwtdMaskDParam; |
| 39 | |
| 40 | #if HAVE_SSE4_1 |
| 41 | ::testing::internal::ParamGenerator<BuildCompDiffwtdMaskDParam> BuildParams( |
| 42 | buildcompdiffwtdmaskd_func filter) { |
| 43 | return ::testing::Combine(::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL), |
| 44 | ::testing::Values(filter)); |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | class BuildCompDiffwtdMaskTest |
| 49 | : public ::testing::TestWithParam<BuildCompDiffwtdMaskDParam> { |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 50 | public: |
| 51 | virtual ~BuildCompDiffwtdMaskTest() {} |
| 52 | |
chiyotsai | 6ddbede | 2021-06-30 14:24:15 -0700 | [diff] [blame] | 53 | virtual void TearDown() {} |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 54 | void RunTest(buildcompdiffwtdmaskd_func test_impl, const int is_speed, |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 55 | const DIFFWTD_MASK_TYPE type); |
| 56 | |
| 57 | private: |
| 58 | ACMRandom rnd_; |
| 59 | }; |
| 60 | |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 61 | typedef void (*buildcompdiffwtdmaskd16_func)( |
| 62 | uint8_t *mask, DIFFWTD_MASK_TYPE mask_type, const CONV_BUF_TYPE *src0, |
| 63 | int src0_stride, const CONV_BUF_TYPE *src1, int src1_stride, int h, int w, |
| 64 | ConvolveParams *conv_params, int bd); |
| 65 | |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 66 | typedef std::tuple<int, buildcompdiffwtdmaskd16_func, BLOCK_SIZE> |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 67 | BuildCompDiffwtdMaskD16Param; |
| 68 | |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 69 | #if HAVE_SSE4_1 || HAVE_NEON |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 70 | ::testing::internal::ParamGenerator<BuildCompDiffwtdMaskD16Param> BuildParams( |
| 71 | buildcompdiffwtdmaskd16_func filter) { |
| 72 | return ::testing::Combine(::testing::Range(8, 13, 2), |
| 73 | ::testing::Values(filter), |
| 74 | ::testing::Range(BLOCK_4X4, BLOCK_SIZES_ALL)); |
| 75 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 76 | #endif |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 77 | class BuildCompDiffwtdMaskD16Test |
| 78 | : public ::testing::TestWithParam<BuildCompDiffwtdMaskD16Param> { |
| 79 | public: |
| 80 | ~BuildCompDiffwtdMaskD16Test() {} |
chiyotsai | 6ddbede | 2021-06-30 14:24:15 -0700 | [diff] [blame] | 81 | virtual void TearDown() {} |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 82 | void SetUp() { rnd_.Reset(ACMRandom::DeterministicSeed()); } |
| 83 | |
| 84 | protected: |
| 85 | void RunCheckOutput(buildcompdiffwtdmaskd16_func test_impl); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 86 | void RunSpeedTest(buildcompdiffwtdmaskd16_func test_impl, |
| 87 | DIFFWTD_MASK_TYPE mask_type); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 88 | libaom_test::ACMRandom rnd_; |
| 89 | }; // class BuildCompDiffwtdMaskD16Test |
chiyotsai | 9dfac72 | 2020-07-07 17:43:02 -0700 | [diff] [blame] | 90 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BuildCompDiffwtdMaskD16Test); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 91 | |
| 92 | void BuildCompDiffwtdMaskD16Test::RunCheckOutput( |
| 93 | buildcompdiffwtdmaskd16_func test_impl) { |
| 94 | const int block_idx = GET_PARAM(2); |
| 95 | const int bd = GET_PARAM(0); |
| 96 | const int width = block_size_wide[block_idx]; |
| 97 | const int height = block_size_high[block_idx]; |
| 98 | DECLARE_ALIGNED(16, uint8_t, mask_ref[2 * MAX_SB_SQUARE]); |
| 99 | DECLARE_ALIGNED(16, uint8_t, mask_test[2 * MAX_SB_SQUARE]); |
| 100 | DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]); |
| 101 | DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]); |
| 102 | |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame] | 103 | ConvolveParams conv_params = |
| 104 | get_conv_params_no_round(0, 0, nullptr, 0, 1, bd); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 105 | |
| 106 | int in_precision = |
| 107 | bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2; |
| 108 | |
| 109 | for (int i = 0; i < MAX_SB_SQUARE; i++) { |
| 110 | src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 111 | src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 112 | } |
| 113 | |
| 114 | for (int mask_type = 0; mask_type < DIFFWTD_MASK_TYPES; mask_type++) { |
| 115 | av1_build_compound_diffwtd_mask_d16_c( |
| 116 | mask_ref, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width, |
| 117 | height, width, &conv_params, bd); |
| 118 | |
| 119 | test_impl(mask_test, (DIFFWTD_MASK_TYPE)mask_type, src0, width, src1, width, |
| 120 | height, width, &conv_params, bd); |
| 121 | |
| 122 | for (int r = 0; r < height; ++r) { |
| 123 | for (int c = 0; c < width; ++c) { |
| 124 | ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width]) |
| 125 | << "Mismatch at unit tests for BuildCompDiffwtdMaskD16Test\n" |
| 126 | << " Pixel mismatch at index " |
| 127 | << "[" << r << "," << c << "] " |
| 128 | << " @ " << width << "x" << height << " inv " << mask_type; |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void BuildCompDiffwtdMaskD16Test::RunSpeedTest( |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 135 | buildcompdiffwtdmaskd16_func test_impl, DIFFWTD_MASK_TYPE mask_type) { |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 136 | const int block_idx = GET_PARAM(2); |
| 137 | const int bd = GET_PARAM(0); |
| 138 | const int width = block_size_wide[block_idx]; |
| 139 | const int height = block_size_high[block_idx]; |
| 140 | DECLARE_ALIGNED(16, uint8_t, mask[MAX_SB_SQUARE]); |
| 141 | DECLARE_ALIGNED(32, uint16_t, src0[MAX_SB_SQUARE]); |
| 142 | DECLARE_ALIGNED(32, uint16_t, src1[MAX_SB_SQUARE]); |
| 143 | |
James Zern | 664f04d | 2022-05-24 17:30:58 -0700 | [diff] [blame] | 144 | ConvolveParams conv_params = |
| 145 | get_conv_params_no_round(0, 0, nullptr, 0, 1, bd); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 146 | |
| 147 | int in_precision = |
| 148 | bd + 2 * FILTER_BITS - conv_params.round_0 - conv_params.round_1 + 2; |
| 149 | |
| 150 | for (int i = 0; i < MAX_SB_SQUARE; i++) { |
| 151 | src0[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 152 | src1[i] = rnd_.Rand16() & ((1 << in_precision) - 1); |
| 153 | } |
| 154 | |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 155 | const int num_loops = 10000000 / (width + height); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 156 | aom_usec_timer timer; |
| 157 | aom_usec_timer_start(&timer); |
| 158 | |
| 159 | for (int i = 0; i < num_loops; ++i) |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 160 | av1_build_compound_diffwtd_mask_d16_c(mask, mask_type, src0, width, src1, |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 161 | width, height, width, &conv_params, |
| 162 | bd); |
| 163 | |
| 164 | aom_usec_timer_mark(&timer); |
| 165 | const int elapsed_time = static_cast<int>(aom_usec_timer_elapsed(&timer)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 166 | |
| 167 | aom_usec_timer timer1; |
| 168 | aom_usec_timer_start(&timer1); |
| 169 | |
| 170 | for (int i = 0; i < num_loops; ++i) |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 171 | test_impl(mask, mask_type, src0, width, src1, width, height, width, |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 172 | &conv_params, bd); |
| 173 | |
| 174 | aom_usec_timer_mark(&timer1); |
| 175 | const int elapsed_time1 = static_cast<int>(aom_usec_timer_elapsed(&timer1)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 176 | printf("av1_build_compound_diffwtd_mask_d16 %3dx%-3d: %7.2f \n", width, |
| 177 | height, elapsed_time / double(elapsed_time1)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 178 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 179 | #if HAVE_SSE4_1 |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 180 | void BuildCompDiffwtdMaskTest::RunTest(buildcompdiffwtdmaskd_func test_impl, |
| 181 | const int is_speed, |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 182 | const DIFFWTD_MASK_TYPE type) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 183 | const int sb_type = GET_PARAM(0); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 184 | const int width = block_size_wide[sb_type]; |
| 185 | const int height = block_size_high[sb_type]; |
| 186 | DECLARE_ALIGNED(16, uint8_t, mask_ref[MAX_SB_SQUARE]); |
| 187 | DECLARE_ALIGNED(16, uint8_t, mask_test[MAX_SB_SQUARE]); |
| 188 | DECLARE_ALIGNED(16, uint8_t, src0[MAX_SB_SQUARE]); |
| 189 | DECLARE_ALIGNED(16, uint8_t, src1[MAX_SB_SQUARE]); |
| 190 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 191 | for (int i = 0; i < width * height; i++) { |
| 192 | src0[i] = rnd.Rand8(); |
| 193 | src1[i] = rnd.Rand8(); |
| 194 | } |
| 195 | const int run_times = is_speed ? (10000000 / (width + height)) : 1; |
| 196 | aom_usec_timer timer; |
| 197 | aom_usec_timer_start(&timer); |
| 198 | for (int i = 0; i < run_times; ++i) { |
| 199 | av1_build_compound_diffwtd_mask_c(mask_ref, type, src0, width, src1, width, |
| 200 | height, width); |
| 201 | } |
| 202 | const double t1 = get_time_mark(&timer); |
| 203 | aom_usec_timer_start(&timer); |
| 204 | for (int i = 0; i < run_times; ++i) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 205 | test_impl(mask_test, type, src0, width, src1, width, height, width); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 206 | } |
| 207 | const double t2 = get_time_mark(&timer); |
| 208 | if (is_speed) { |
| 209 | printf("mask %d %3dx%-3d:%7.2f/%7.2fns", type, width, height, t1, t2); |
| 210 | printf("(%3.2f)\n", t1 / t2); |
| 211 | } |
| 212 | for (int r = 0; r < height; ++r) { |
| 213 | for (int c = 0; c < width; ++c) { |
| 214 | ASSERT_EQ(mask_ref[c + r * width], mask_test[c + r * width]) |
| 215 | << "[" << r << "," << c << "] " << run_times << " @ " << width << "x" |
| 216 | << height << " inv " << type; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | TEST_P(BuildCompDiffwtdMaskTest, match) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 222 | RunTest(GET_PARAM(1), 0, DIFFWTD_38); |
| 223 | RunTest(GET_PARAM(1), 0, DIFFWTD_38_INV); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 224 | } |
| 225 | TEST_P(BuildCompDiffwtdMaskTest, DISABLED_Speed) { |
Sachin Kumar Garg | 5b7e5e2 | 2018-06-20 19:00:12 +0530 | [diff] [blame] | 226 | RunTest(GET_PARAM(1), 1, DIFFWTD_38); |
| 227 | RunTest(GET_PARAM(1), 1, DIFFWTD_38_INV); |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 228 | } |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 229 | #endif |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 230 | TEST_P(BuildCompDiffwtdMaskD16Test, CheckOutput) { |
| 231 | RunCheckOutput(GET_PARAM(1)); |
| 232 | } |
| 233 | |
| 234 | TEST_P(BuildCompDiffwtdMaskD16Test, DISABLED_Speed) { |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 235 | RunSpeedTest(GET_PARAM(1), DIFFWTD_38); |
| 236 | RunSpeedTest(GET_PARAM(1), DIFFWTD_38_INV); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | #if HAVE_SSE4_1 |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 240 | INSTANTIATE_TEST_SUITE_P(SSE4_1, BuildCompDiffwtdMaskTest, |
| 241 | BuildParams(av1_build_compound_diffwtd_mask_sse4_1)); |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 242 | |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 243 | INSTANTIATE_TEST_SUITE_P( |
Ravi Chaudhary | ea665b0 | 2018-04-10 18:39:47 +0530 | [diff] [blame] | 244 | SSE4_1, BuildCompDiffwtdMaskD16Test, |
| 245 | BuildParams(av1_build_compound_diffwtd_mask_d16_sse4_1)); |
| 246 | #endif |
| 247 | |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 248 | #if HAVE_AVX2 |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 249 | INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskTest, |
| 250 | BuildParams(av1_build_compound_diffwtd_mask_avx2)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 251 | |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 252 | INSTANTIATE_TEST_SUITE_P(AVX2, BuildCompDiffwtdMaskD16Test, |
| 253 | BuildParams(av1_build_compound_diffwtd_mask_d16_avx2)); |
Xing Jin | aa218b2 | 2018-08-22 13:24:59 +0800 | [diff] [blame] | 254 | #endif |
| 255 | |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 256 | #if HAVE_NEON |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 257 | INSTANTIATE_TEST_SUITE_P(NEON, BuildCompDiffwtdMaskD16Test, |
| 258 | BuildParams(av1_build_compound_diffwtd_mask_d16_neon)); |
Sachin Kumar Garg | d78396e | 2018-06-21 11:46:30 +0530 | [diff] [blame] | 259 | #endif |
| 260 | |
Peng Bin | 640ea40 | 2018-03-30 14:12:53 +0800 | [diff] [blame] | 261 | } // namespace |