1 /*
2 * Copyright (c) 2018, 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 <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <tuple>
16
17 #include "config/av1_rtcd.h"
18
19 #include "aom_mem/aom_mem.h"
20 #include "aom_ports/aom_timer.h"
21 #include "aom_ports/mem.h"
22 #include "test/acm_random.h"
23 #include "test/clear_system_state.h"
24 #include "test/util.h"
25 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
26
27 namespace AV1CompRoundShift {
28
29 typedef void (*comp_round_shift_array_func)(int32_t *arr, int size, int bit);
30
31 #if HAVE_SSE4_1 || HAVE_NEON
32 const int kValidBitCheck[] = {
33 -4, -3, -2, -1, 0, 1, 2, 3, 4,
34 };
35 #endif // HAVE_SSE4_1 || HAVE_NEON
36
37 typedef std::tuple<comp_round_shift_array_func, BLOCK_SIZE, int>
38 CompRoundShiftParam;
39
40 class AV1CompRoundShiftTest
41 : public ::testing::TestWithParam<CompRoundShiftParam> {
42 public:
43 ~AV1CompRoundShiftTest();
44
SetUp()45 void SetUp() { rnd_.Reset(libaom_test::ACMRandom::DeterministicSeed()); }
TearDown()46 void TearDown() { libaom_test::ClearSystemState(); }
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 };
56
~AV1CompRoundShiftTest()57 AV1CompRoundShiftTest::~AV1CompRoundShiftTest() { ; }
58
RunCheckOutput(comp_round_shift_array_func test_impl,BLOCK_SIZE bsize,int bit)59 void AV1CompRoundShiftTest::RunCheckOutput(
60 comp_round_shift_array_func test_impl, BLOCK_SIZE bsize, int bit) {
61 const int w = block_size_wide[bsize];
62 const int h = block_size_high[bsize];
63 const int blk_wd = 64;
64 DECLARE_ALIGNED(32, int32_t, pred_[blk_wd]);
65 DECLARE_ALIGNED(32, int32_t, ref_buffer_[blk_wd]);
66 for (int i = 0; i < (blk_wd); ++i) {
67 ref_buffer_[i] = pred_[i] = rnd_.Rand31() / 16;
68 }
69 av1_round_shift_array_c(ref_buffer_, w, bit);
70 test_impl(pred_, w, bit);
71 for (int x = 0; x < w; ++x) {
72 ASSERT_EQ(ref_buffer_[x], pred_[x]) << w << "x" << h << "mismatch @"
73 << "(" << x << ")";
74 }
75 }
76
RunSpeedTest(comp_round_shift_array_func test_impl,BLOCK_SIZE bsize,int bit)77 void AV1CompRoundShiftTest::RunSpeedTest(comp_round_shift_array_func test_impl,
78 BLOCK_SIZE bsize, int bit) {
79 const int w = block_size_wide[bsize];
80 const int h = block_size_high[bsize];
81 const int blk_wd = 64;
82 DECLARE_ALIGNED(32, int32_t, ref_buffer_[blk_wd]);
83 for (int i = 0; i < (blk_wd); ++i) {
84 ref_buffer_[i] = rnd_.Rand31();
85 }
86
87 const int num_loops = 1000000000 / (w + h);
88 comp_round_shift_array_func funcs[2] = { av1_round_shift_array_c, test_impl };
89 double elapsed_time[2] = { 0 };
90 for (int i = 0; i < 2; ++i) {
91 aom_usec_timer timer;
92 aom_usec_timer_start(&timer);
93 comp_round_shift_array_func func = funcs[i];
94 for (int j = 0; j < num_loops; ++j) {
95 func(ref_buffer_, w, bit);
96 }
97 aom_usec_timer_mark(&timer);
98 double time = static_cast<double>(aom_usec_timer_elapsed(&timer));
99 elapsed_time[i] = 1000.0 * time / num_loops;
100 }
101 printf("av1_round_shift_array %3dx%-3d: bit : %d %7.2f/%7.2fns", w, h, bit,
102 elapsed_time[0], elapsed_time[1]);
103 printf("(%3.2f)\n", elapsed_time[0] / elapsed_time[1]);
104 }
105
TEST_P(AV1CompRoundShiftTest,CheckOutput)106 TEST_P(AV1CompRoundShiftTest, CheckOutput) {
107 RunCheckOutput(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2));
108 }
109
TEST_P(AV1CompRoundShiftTest,DISABLED_Speed)110 TEST_P(AV1CompRoundShiftTest, DISABLED_Speed) {
111 RunSpeedTest(GET_PARAM(0), GET_PARAM(1), GET_PARAM(2));
112 }
113
114 #if HAVE_SSE4_1
115 INSTANTIATE_TEST_SUITE_P(
116 SSE4_1, AV1CompRoundShiftTest,
117 ::testing::Combine(::testing::Values(&av1_round_shift_array_sse4_1),
118 ::testing::ValuesIn(txsize_to_bsize),
119 ::testing::ValuesIn(kValidBitCheck)));
120 #endif
121
122 #if HAVE_NEON
123 INSTANTIATE_TEST_SUITE_P(
124 NEON, AV1CompRoundShiftTest,
125 ::testing::Combine(::testing::Values(&av1_round_shift_array_neon),
126 ::testing::ValuesIn(txsize_to_bsize),
127 ::testing::ValuesIn(kValidBitCheck)));
128 #endif
129
130 }; // namespace AV1CompRoundShift
131