• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "third_party/googletest/src/include/gtest/gtest.h"
12 
13 #include "./vp9_rtcd.h"
14 #include "./vpx_config.h"
15 #include "./vpx_dsp_rtcd.h"
16 #include "test/acm_random.h"
17 #include "test/bench.h"
18 #include "test/clear_system_state.h"
19 #include "test/register_state_check.h"
20 #include "vp9/common/vp9_blockd.h"
21 #include "vpx_ports/msvc.h"
22 #include "vpx_mem/vpx_mem.h"
23 
24 typedef void (*SubtractFunc)(int rows, int cols, int16_t *diff_ptr,
25                              ptrdiff_t diff_stride, const uint8_t *src_ptr,
26                              ptrdiff_t src_stride, const uint8_t *pred_ptr,
27                              ptrdiff_t pred_stride);
28 
29 namespace vp9 {
30 
31 class VP9SubtractBlockTest : public AbstractBench,
32                              public ::testing::TestWithParam<SubtractFunc> {
33  public:
TearDown()34   virtual void TearDown() { libvpx_test::ClearSystemState(); }
35 
36  protected:
Run()37   virtual void Run() {
38     GetParam()(block_height_, block_width_, diff_, block_width_, src_,
39                block_width_, pred_, block_width_);
40   }
41 
SetupBlocks(BLOCK_SIZE bsize)42   void SetupBlocks(BLOCK_SIZE bsize) {
43     block_width_ = 4 * num_4x4_blocks_wide_lookup[bsize];
44     block_height_ = 4 * num_4x4_blocks_high_lookup[bsize];
45     diff_ = reinterpret_cast<int16_t *>(
46         vpx_memalign(16, sizeof(*diff_) * block_width_ * block_height_ * 2));
47     pred_ = reinterpret_cast<uint8_t *>(
48         vpx_memalign(16, block_width_ * block_height_ * 2));
49     src_ = reinterpret_cast<uint8_t *>(
50         vpx_memalign(16, block_width_ * block_height_ * 2));
51   }
52 
53   int block_width_;
54   int block_height_;
55   int16_t *diff_;
56   uint8_t *pred_;
57   uint8_t *src_;
58 };
59 
60 using libvpx_test::ACMRandom;
61 
TEST_P(VP9SubtractBlockTest,DISABLED_Speed)62 TEST_P(VP9SubtractBlockTest, DISABLED_Speed) {
63   ACMRandom rnd(ACMRandom::DeterministicSeed());
64 
65   for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
66        bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
67     SetupBlocks(bsize);
68 
69     RunNTimes(100000000 / (block_height_ * block_width_));
70     char block_size[16];
71     snprintf(block_size, sizeof(block_size), "%dx%d", block_height_,
72              block_width_);
73     char title[100];
74     snprintf(title, sizeof(title), "%8s ", block_size);
75     PrintMedian(title);
76 
77     vpx_free(diff_);
78     vpx_free(pred_);
79     vpx_free(src_);
80   }
81 }
82 
TEST_P(VP9SubtractBlockTest,SimpleSubtract)83 TEST_P(VP9SubtractBlockTest, SimpleSubtract) {
84   ACMRandom rnd(ACMRandom::DeterministicSeed());
85 
86   for (BLOCK_SIZE bsize = BLOCK_4X4; bsize < BLOCK_SIZES;
87        bsize = static_cast<BLOCK_SIZE>(static_cast<int>(bsize) + 1)) {
88     SetupBlocks(bsize);
89 
90     for (int n = 0; n < 100; n++) {
91       for (int r = 0; r < block_height_; ++r) {
92         for (int c = 0; c < block_width_ * 2; ++c) {
93           src_[r * block_width_ * 2 + c] = rnd.Rand8();
94           pred_[r * block_width_ * 2 + c] = rnd.Rand8();
95         }
96       }
97 
98       GetParam()(block_height_, block_width_, diff_, block_width_, src_,
99                  block_width_, pred_, block_width_);
100 
101       for (int r = 0; r < block_height_; ++r) {
102         for (int c = 0; c < block_width_; ++c) {
103           EXPECT_EQ(diff_[r * block_width_ + c],
104                     (src_[r * block_width_ + c] - pred_[r * block_width_ + c]))
105               << "r = " << r << ", c = " << c
106               << ", bs = " << static_cast<int>(bsize);
107         }
108       }
109 
110       GetParam()(block_height_, block_width_, diff_, block_width_ * 2, src_,
111                  block_width_ * 2, pred_, block_width_ * 2);
112 
113       for (int r = 0; r < block_height_; ++r) {
114         for (int c = 0; c < block_width_; ++c) {
115           EXPECT_EQ(diff_[r * block_width_ * 2 + c],
116                     (src_[r * block_width_ * 2 + c] -
117                      pred_[r * block_width_ * 2 + c]))
118               << "r = " << r << ", c = " << c
119               << ", bs = " << static_cast<int>(bsize);
120         }
121       }
122     }
123     vpx_free(diff_);
124     vpx_free(pred_);
125     vpx_free(src_);
126   }
127 }
128 
129 INSTANTIATE_TEST_CASE_P(C, VP9SubtractBlockTest,
130                         ::testing::Values(vpx_subtract_block_c));
131 
132 #if HAVE_SSE2
133 INSTANTIATE_TEST_CASE_P(SSE2, VP9SubtractBlockTest,
134                         ::testing::Values(vpx_subtract_block_sse2));
135 #endif
136 #if HAVE_NEON
137 INSTANTIATE_TEST_CASE_P(NEON, VP9SubtractBlockTest,
138                         ::testing::Values(vpx_subtract_block_neon));
139 #endif
140 #if HAVE_MSA
141 INSTANTIATE_TEST_CASE_P(MSA, VP9SubtractBlockTest,
142                         ::testing::Values(vpx_subtract_block_msa));
143 #endif
144 
145 #if HAVE_MMI
146 INSTANTIATE_TEST_CASE_P(MMI, VP9SubtractBlockTest,
147                         ::testing::Values(vpx_subtract_block_mmi));
148 #endif
149 
150 #if HAVE_VSX
151 INSTANTIATE_TEST_CASE_P(VSX, VP9SubtractBlockTest,
152                         ::testing::Values(vpx_subtract_block_vsx));
153 #endif
154 
155 }  // namespace vp9
156