Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2018, Alliance for Open Media. All rights reserved. |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 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 <math.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 15 | #include <tuple> |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 16 | |
Johann | 98dae94 | 2018-12-07 10:38:47 -0800 | [diff] [blame] | 17 | #include "config/av1_rtcd.h" |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 18 | |
| 19 | #include "aom_mem/aom_mem.h" |
| 20 | #include "aom_ports/aom_timer.h" |
| 21 | #include "aom_ports/mem.h" |
Wan-Teh Chang | c8b1fc2 | 2024-08-01 12:09:28 -0700 | [diff] [blame] | 22 | #include "gtest/gtest.h" |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 23 | #include "test/acm_random.h" |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 24 | #include "test/util.h" |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 25 | |
| 26 | namespace AV1CompRoundShift { |
| 27 | |
| 28 | typedef void (*comp_round_shift_array_func)(int32_t *arr, int size, int bit); |
| 29 | |
Debargha Mukherjee | 184cfc7 | 2018-08-02 09:05:04 -0700 | [diff] [blame] | 30 | #if HAVE_SSE4_1 || HAVE_NEON |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 31 | const int kValidBitCheck[] = { |
Johann Koenig | 70bffc7 | 2018-06-21 15:49:04 +0000 | [diff] [blame] | 32 | -4, -3, -2, -1, 0, 1, 2, 3, 4, |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 33 | }; |
Debargha Mukherjee | 184cfc7 | 2018-08-02 09:05:04 -0700 | [diff] [blame] | 34 | #endif // HAVE_SSE4_1 || HAVE_NEON |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 35 | |
sarahparker | a543df5 | 2018-11-02 16:02:05 -0700 | [diff] [blame] | 36 | typedef std::tuple<comp_round_shift_array_func, BLOCK_SIZE, int> |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 37 | CompRoundShiftParam; |
| 38 | |
| 39 | class AV1CompRoundShiftTest |
| 40 | : public ::testing::TestWithParam<CompRoundShiftParam> { |
| 41 | public: |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 42 | ~AV1CompRoundShiftTest() override; |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 43 | |
James Zern | faa2dcf | 2023-07-24 18:29:51 -0700 | [diff] [blame] | 44 | void SetUp() override { |
| 45 | rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed()); |
| 46 | } |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 47 | |
| 48 | protected: |
| 49 | void RunCheckOutput(comp_round_shift_array_func test_impl, BLOCK_SIZE bsize, |
| 50 | int bit); |
| 51 | void RunSpeedTest(comp_round_shift_array_func test_impl, BLOCK_SIZE bsize, |
| 52 | int bit); |
| 53 | |
| 54 | libaom_test::ACMRandom rnd_; |
| 55 | }; |
chiyotsai | 9dfac72 | 2020-07-07 17:43:02 -0700 | [diff] [blame] | 56 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1CompRoundShiftTest); |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 57 | |
James Zern | f1fa1eb | 2023-07-25 15:34:13 -0700 | [diff] [blame] | 58 | AV1CompRoundShiftTest::~AV1CompRoundShiftTest() = default; |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 59 | |
| 60 | void AV1CompRoundShiftTest::RunCheckOutput( |
| 61 | comp_round_shift_array_func test_impl, BLOCK_SIZE bsize, int bit) { |
| 62 | const int w = block_size_wide[bsize]; |
| 63 | const int h = block_size_high[bsize]; |
| 64 | const int blk_wd = 64; |
| 65 | DECLARE_ALIGNED(32, int32_t, pred_[blk_wd]); |
| 66 | DECLARE_ALIGNED(32, int32_t, ref_buffer_[blk_wd]); |
| 67 | for (int i = 0; i < (blk_wd); ++i) { |
Yaowu Xu | 58f109b | 2018-06-15 08:34:11 -0700 | [diff] [blame] | 68 | ref_buffer_[i] = pred_[i] = rnd_.Rand31() / 16; |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 69 | } |
| 70 | av1_round_shift_array_c(ref_buffer_, w, bit); |
| 71 | test_impl(pred_, w, bit); |
| 72 | for (int x = 0; x < w; ++x) { |
| 73 | ASSERT_EQ(ref_buffer_[x], pred_[x]) << w << "x" << h << "mismatch @" |
| 74 | << "(" << x << ")"; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void AV1CompRoundShiftTest::RunSpeedTest(comp_round_shift_array_func test_impl, |
| 79 | BLOCK_SIZE bsize, int bit) { |
| 80 | const int w = block_size_wide[bsize]; |
| 81 | const int h = block_size_high[bsize]; |
| 82 | const int blk_wd = 64; |
| 83 | DECLARE_ALIGNED(32, int32_t, ref_buffer_[blk_wd]); |
| 84 | for (int i = 0; i < (blk_wd); ++i) { |
| 85 | ref_buffer_[i] = rnd_.Rand31(); |
| 86 | } |
| 87 | |
| 88 | const int num_loops = 1000000000 / (w + h); |
| 89 | comp_round_shift_array_func funcs[2] = { av1_round_shift_array_c, test_impl }; |
| 90 | double elapsed_time[2] = { 0 }; |
| 91 | for (int i = 0; i < 2; ++i) { |
| 92 | aom_usec_timer timer; |
| 93 | aom_usec_timer_start(&timer); |
| 94 | comp_round_shift_array_func func = funcs[i]; |
| 95 | for (int j = 0; j < num_loops; ++j) { |
| 96 | func(ref_buffer_, w, bit); |
| 97 | } |
| 98 | aom_usec_timer_mark(&timer); |
| 99 | double time = static_cast<double>(aom_usec_timer_elapsed(&timer)); |
| 100 | elapsed_time[i] = 1000.0 * time / num_loops; |
| 101 | } |
| 102 | printf("av1_round_shift_array %3dx%-3d: bit : %d %7.2f/%7.2fns", w, h, bit, |
| 103 | elapsed_time[0], elapsed_time[1]); |
| 104 | printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]); |
| 105 | } |
| 106 | |
| 107 | TEST_P(AV1CompRoundShiftTest, CheckOutput) { |
| 108 | RunCheckOutput(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2)); |
| 109 | } |
| 110 | |
| 111 | TEST_P(AV1CompRoundShiftTest, DISABLED_Speed) { |
| 112 | RunSpeedTest(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2)); |
| 113 | } |
| 114 | |
| 115 | #if HAVE_SSE4_1 |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 116 | INSTANTIATE_TEST_SUITE_P( |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 117 | SSE4_1, AV1CompRoundShiftTest, |
| 118 | ::testing::Combine(::testing::Values(&av1_round_shift_array_sse4_1), |
| 119 | ::testing::ValuesIn(txsize_to_bsize), |
| 120 | ::testing::ValuesIn(kValidBitCheck))); |
| 121 | #endif |
| 122 | |
| 123 | #if HAVE_NEON |
Cheng Chen | 96786fe | 2020-02-14 17:28:25 -0800 | [diff] [blame] | 124 | INSTANTIATE_TEST_SUITE_P( |
Sachin Kumar Garg | b01600c | 2018-06-01 18:16:46 +0530 | [diff] [blame] | 125 | NEON, AV1CompRoundShiftTest, |
| 126 | ::testing::Combine(::testing::Values(&av1_round_shift_array_neon), |
| 127 | ::testing::ValuesIn(txsize_to_bsize), |
| 128 | ::testing::ValuesIn(kValidBitCheck))); |
| 129 | #endif |
| 130 | |
James Zern | f2658a3 | 2022-02-09 10:18:38 -0800 | [diff] [blame] | 131 | } // namespace AV1CompRoundShift |