]> granicus.if.org Git - libvpx/blob - test/sixtap_predict_test.cc
Revert "Restore vp8_sixtap_predict4x4_neon"
[libvpx] / test / sixtap_predict_test.cc
1 /*
2  *  Copyright (c) 2013 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 <math.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "third_party/googletest/src/include/gtest/gtest.h"
16
17 #include "./vpx_config.h"
18 #include "./vp8_rtcd.h"
19 #include "test/acm_random.h"
20 #include "test/clear_system_state.h"
21 #include "test/register_state_check.h"
22 #include "test/util.h"
23 #include "vpx/vpx_integer.h"
24 #include "vpx_mem/vpx_mem.h"
25
26 namespace {
27
28 typedef void (*SixtapPredictFunc)(uint8_t *src_ptr, int src_pixels_per_line,
29                                   int xoffset, int yoffset, uint8_t *dst_ptr,
30                                   int dst_pitch);
31
32 typedef std::tr1::tuple<int, int, SixtapPredictFunc> SixtapPredictParam;
33
34 class SixtapPredictTest : public ::testing::TestWithParam<SixtapPredictParam> {
35  public:
36   static void SetUpTestCase() {
37     src_ = reinterpret_cast<uint8_t *>(vpx_memalign(kDataAlignment, kSrcSize));
38     dst_ = reinterpret_cast<uint8_t *>(vpx_memalign(kDataAlignment, kDstSize));
39     dst_c_ =
40         reinterpret_cast<uint8_t *>(vpx_memalign(kDataAlignment, kDstSize));
41   }
42
43   static void TearDownTestCase() {
44     vpx_free(src_);
45     src_ = NULL;
46     vpx_free(dst_);
47     dst_ = NULL;
48     vpx_free(dst_c_);
49     dst_c_ = NULL;
50   }
51
52   virtual void TearDown() { libvpx_test::ClearSystemState(); }
53
54  protected:
55   // Make test arrays big enough for 16x16 functions. Six-tap filters
56   // need 5 extra pixels outside of the macroblock.
57   static const int kSrcStride = 21;
58   static const int kDstStride = 16;
59   static const int kDataAlignment = 16;
60   static const int kSrcSize = kSrcStride * kSrcStride + 1;
61   static const int kDstSize = kDstStride * kDstStride;
62
63   virtual void SetUp() {
64     width_ = GET_PARAM(0);
65     height_ = GET_PARAM(1);
66     sixtap_predict_ = GET_PARAM(2);
67     memset(src_, 0, kSrcSize);
68     memset(dst_, 0, kDstSize);
69     memset(dst_c_, 0, kDstSize);
70   }
71
72   int width_;
73   int height_;
74   SixtapPredictFunc sixtap_predict_;
75   // The src stores the macroblock we will filter on, and makes it 1 byte larger
76   // in order to test unaligned access. The result is stored in dst and dst_c(c
77   // reference code result).
78   static uint8_t *src_;
79   static uint8_t *dst_;
80   static uint8_t *dst_c_;
81 };
82
83 uint8_t *SixtapPredictTest::src_ = NULL;
84 uint8_t *SixtapPredictTest::dst_ = NULL;
85 uint8_t *SixtapPredictTest::dst_c_ = NULL;
86
87 TEST_P(SixtapPredictTest, TestWithPresetData) {
88   // Test input
89   static const uint8_t test_data[kSrcSize] = {
90     216, 184, 4,   191, 82,  92,  41,  0,   1,   226, 236, 172, 20,  182, 42,
91     226, 177, 79,  94,  77,  179, 203, 206, 198, 22,  192, 19,  75,  17,  192,
92     44,  233, 120, 48,  168, 203, 141, 210, 203, 143, 180, 184, 59,  201, 110,
93     102, 171, 32,  182, 10,  109, 105, 213, 60,  47,  236, 253, 67,  55,  14,
94     3,   99,  247, 124, 148, 159, 71,  34,  114, 19,  177, 38,  203, 237, 239,
95     58,  83,  155, 91,  10,  166, 201, 115, 124, 5,   163, 104, 2,   231, 160,
96     16,  234, 4,   8,   103, 153, 167, 174, 187, 26,  193, 109, 64,  141, 90,
97     48,  200, 174, 204, 36,  184, 114, 237, 43,  238, 242, 207, 86,  245, 182,
98     247, 6,   161, 251, 14,  8,   148, 182, 182, 79,  208, 120, 188, 17,  6,
99     23,  65,  206, 197, 13,  242, 126, 128, 224, 170, 110, 211, 121, 197, 200,
100     47,  188, 207, 208, 184, 221, 216, 76,  148, 143, 156, 100, 8,   89,  117,
101     14,  112, 183, 221, 54,  197, 208, 180, 69,  176, 94,  180, 131, 215, 121,
102     76,  7,   54,  28,  216, 238, 249, 176, 58,  142, 64,  215, 242, 72,  49,
103     104, 87,  161, 32,  52,  216, 230, 4,   141, 44,  181, 235, 224, 57,  195,
104     89,  134, 203, 144, 162, 163, 126, 156, 84,  185, 42,  148, 145, 29,  221,
105     194, 134, 52,  100, 166, 105, 60,  140, 110, 201, 184, 35,  181, 153, 93,
106     121, 243, 227, 68,  131, 134, 232, 2,   35,  60,  187, 77,  209, 76,  106,
107     174, 15,  241, 227, 115, 151, 77,  175, 36,  187, 121, 221, 223, 47,  118,
108     61,  168, 105, 32,  237, 236, 167, 213, 238, 202, 17,  170, 24,  226, 247,
109     131, 145, 6,   116, 117, 121, 11,  194, 41,  48,  126, 162, 13,  93,  209,
110     131, 154, 122, 237, 187, 103, 217, 99,  60,  200, 45,  78,  115, 69,  49,
111     106, 200, 194, 112, 60,  56,  234, 72,  251, 19,  120, 121, 182, 134, 215,
112     135, 10,  114, 2,   247, 46,  105, 209, 145, 165, 153, 191, 243, 12,  5,
113     36,  119, 206, 231, 231, 11,  32,  209, 83,  27,  229, 204, 149, 155, 83,
114     109, 35,  93,  223, 37,  84,  14,  142, 37,  160, 52,  191, 96,  40,  204,
115     101, 77,  67,  52,  53,  43,  63,  85,  253, 147, 113, 226, 96,  6,   125,
116     179, 115, 161, 17,  83,  198, 101, 98,  85,  139, 3,   137, 75,  99,  178,
117     23,  201, 255, 91,  253, 52,  134, 60,  138, 131, 208, 251, 101, 48,  2,
118     227, 228, 118, 132, 245, 202, 75,  91,  44,  160, 231, 47,  41,  50,  147,
119     220, 74,  92,  219, 165, 89,  16
120   };
121
122   // Expected result
123   static const uint8_t expected_dst[kDstSize] = {
124     117, 102, 74,  135, 42,  98,  175, 206, 70,  73,  222, 197, 50,  24,  39,
125     49,  38,  105, 90,  47,  169, 40,  171, 215, 200, 73,  109, 141, 53,  85,
126     177, 164, 79,  208, 124, 89,  212, 18,  81,  145, 151, 164, 217, 153, 91,
127     154, 102, 102, 159, 75,  164, 152, 136, 51,  213, 219, 186, 116, 193, 224,
128     186, 36,  231, 208, 84,  211, 155, 167, 35,  59,  42,  76,  216, 149, 73,
129     201, 78,  149, 184, 100, 96,  196, 189, 198, 188, 235, 195, 117, 129, 120,
130     129, 49,  25,  133, 113, 69,  221, 114, 70,  143, 99,  157, 108, 189, 140,
131     78,  6,   55,  65,  240, 255, 245, 184, 72,  90,  100, 116, 131, 39,  60,
132     234, 167, 33,  160, 88,  185, 200, 157, 159, 176, 127, 151, 138, 102, 168,
133     106, 170, 86,  82,  219, 189, 76,  33,  115, 197, 106, 96,  198, 136, 97,
134     141, 237, 151, 98,  137, 191, 185, 2,   57,  95,  142, 91,  255, 185, 97,
135     137, 76,  162, 94,  173, 131, 193, 161, 81,  106, 72,  135, 222, 234, 137,
136     66,  137, 106, 243, 210, 147, 95,  15,  137, 110, 85,  66,  16,  96,  167,
137     147, 150, 173, 203, 140, 118, 196, 84,  147, 160, 19,  95,  101, 123, 74,
138     132, 202, 82,  166, 12,  131, 166, 189, 170, 159, 85,  79,  66,  57,  152,
139     132, 203, 194, 0,   1,   56,  146, 180, 224, 156, 28,  83,  181, 79,  76,
140     80,  46,  160, 175, 59,  106, 43,  87,  75,  136, 85,  189, 46,  71,  200,
141     90
142   };
143
144   uint8_t *src = const_cast<uint8_t *>(test_data);
145
146   ASM_REGISTER_STATE_CHECK(sixtap_predict_(&src[kSrcStride * 2 + 2 + 1],
147                                            kSrcStride, 2, 2, dst_, kDstStride));
148
149   for (int i = 0; i < height_; ++i) {
150     for (int j = 0; j < width_; ++j)
151       ASSERT_EQ(expected_dst[i * kDstStride + j], dst_[i * kDstStride + j])
152           << "i==" << (i * width_ + j);
153   }
154 }
155
156 using libvpx_test::ACMRandom;
157
158 TEST_P(SixtapPredictTest, TestWithRandomData) {
159   ACMRandom rnd(ACMRandom::DeterministicSeed());
160   for (int i = 0; i < kSrcSize; ++i) src_[i] = rnd.Rand8();
161
162   // Run tests for all possible offsets.
163   for (int xoffset = 0; xoffset < 8; ++xoffset) {
164     for (int yoffset = 0; yoffset < 8; ++yoffset) {
165       // Call c reference function.
166       // Move start point to next pixel to test if the function reads
167       // unaligned data correctly.
168       vp8_sixtap_predict16x16_c(&src_[kSrcStride * 2 + 2 + 1], kSrcStride,
169                                 xoffset, yoffset, dst_c_, kDstStride);
170
171       // Run test.
172       ASM_REGISTER_STATE_CHECK(sixtap_predict_(&src_[kSrcStride * 2 + 2 + 1],
173                                                kSrcStride, xoffset, yoffset,
174                                                dst_, kDstStride));
175
176       for (int i = 0; i < height_; ++i) {
177         for (int j = 0; j < width_; ++j)
178           ASSERT_EQ(dst_c_[i * kDstStride + j], dst_[i * kDstStride + j])
179               << "i==" << (i * width_ + j);
180       }
181     }
182   }
183 }
184
185 using std::tr1::make_tuple;
186
187 INSTANTIATE_TEST_CASE_P(
188     C, SixtapPredictTest,
189     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_c),
190                       make_tuple(8, 8, &vp8_sixtap_predict8x8_c),
191                       make_tuple(8, 4, &vp8_sixtap_predict8x4_c),
192                       make_tuple(4, 4, &vp8_sixtap_predict4x4_c)));
193 #if HAVE_NEON
194 INSTANTIATE_TEST_CASE_P(
195     NEON, SixtapPredictTest,
196     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_neon),
197                       make_tuple(8, 8, &vp8_sixtap_predict8x8_neon),
198                       make_tuple(8, 4, &vp8_sixtap_predict8x4_neon)));
199 #endif
200 #if HAVE_MMX
201 INSTANTIATE_TEST_CASE_P(
202     MMX, SixtapPredictTest,
203     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_mmx),
204                       make_tuple(8, 8, &vp8_sixtap_predict8x8_mmx),
205                       make_tuple(8, 4, &vp8_sixtap_predict8x4_mmx),
206                       make_tuple(4, 4, &vp8_sixtap_predict4x4_mmx)));
207 #endif
208 #if HAVE_SSE2
209 INSTANTIATE_TEST_CASE_P(
210     SSE2, SixtapPredictTest,
211     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_sse2),
212                       make_tuple(8, 8, &vp8_sixtap_predict8x8_sse2),
213                       make_tuple(8, 4, &vp8_sixtap_predict8x4_sse2)));
214 #endif
215 #if HAVE_SSSE3
216 INSTANTIATE_TEST_CASE_P(
217     SSSE3, SixtapPredictTest,
218     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_ssse3),
219                       make_tuple(8, 8, &vp8_sixtap_predict8x8_ssse3),
220                       make_tuple(8, 4, &vp8_sixtap_predict8x4_ssse3),
221                       make_tuple(4, 4, &vp8_sixtap_predict4x4_ssse3)));
222 #endif
223 #if HAVE_MSA
224 INSTANTIATE_TEST_CASE_P(
225     MSA, SixtapPredictTest,
226     ::testing::Values(make_tuple(16, 16, &vp8_sixtap_predict16x16_msa),
227                       make_tuple(8, 8, &vp8_sixtap_predict8x8_msa),
228                       make_tuple(8, 4, &vp8_sixtap_predict8x4_msa),
229                       make_tuple(4, 4, &vp8_sixtap_predict4x4_msa)));
230 #endif
231 }  // namespace