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