Merge "Rework 8x8 transpose SSSE3 for inverse 2D-DCT"
[platform/upstream/libvpx.git] / test / idct_test.cc
1 /*
2  *  Copyright (c) 2010 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 "./vpx_config.h"
12 #include "./vp8_rtcd.h"
13
14 #include "third_party/googletest/src/include/gtest/gtest.h"
15
16 #include "test/buffer.h"
17 #include "test/clear_system_state.h"
18 #include "test/register_state_check.h"
19 #include "vpx/vpx_integer.h"
20
21 typedef void (*IdctFunc)(int16_t *input, unsigned char *pred_ptr,
22                          int pred_stride, unsigned char *dst_ptr,
23                          int dst_stride);
24 namespace {
25
26 using libvpx_test::Buffer;
27
28 class IDCTTest : public ::testing::TestWithParam<IdctFunc> {
29  protected:
30   virtual void SetUp() {
31     UUT = GetParam();
32
33     input = new (std::nothrow) Buffer<int16_t>(4, 4, 0);
34     ASSERT_TRUE(input != NULL);
35     predict = new (std::nothrow) Buffer<uint8_t>(4, 4, 3);
36     ASSERT_TRUE(predict != NULL);
37     output = new (std::nothrow) Buffer<uint8_t>(4, 4, 3);
38     ASSERT_TRUE(output != NULL);
39   }
40
41   virtual void TearDown() {
42     delete input;
43     delete predict;
44     delete output;
45     libvpx_test::ClearSystemState();
46   }
47
48   IdctFunc UUT;
49   Buffer<int16_t> *input;
50   Buffer<uint8_t> *predict;
51   Buffer<uint8_t> *output;
52 };
53
54 TEST_P(IDCTTest, TestAllZeros) {
55   // When the input is '0' the output will be '0'.
56   input->Set(0);
57   predict->Set(0);
58   output->Set(0);
59
60   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
61                                predict->stride(), output->TopLeftPixel(),
62                                output->stride()));
63
64   ASSERT_TRUE(input->CheckValues(0));
65   ASSERT_TRUE(input->CheckPadding());
66   ASSERT_TRUE(output->CheckValues(0));
67   ASSERT_TRUE(output->CheckPadding());
68 }
69
70 TEST_P(IDCTTest, TestAllOnes) {
71   input->Set(0);
72   // When the first element is '4' it will fill the output buffer with '1'.
73   input->TopLeftPixel()[0] = 4;
74   predict->Set(0);
75   output->Set(0);
76
77   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
78                                predict->stride(), output->TopLeftPixel(),
79                                output->stride()));
80
81   ASSERT_TRUE(output->CheckValues(1));
82   ASSERT_TRUE(output->CheckPadding());
83 }
84
85 TEST_P(IDCTTest, TestAddOne) {
86   // Set the transform output to '1' and make sure it gets added to the
87   // prediction buffer.
88   input->Set(0);
89   input->TopLeftPixel()[0] = 4;
90   output->Set(0);
91
92   uint8_t *pred = predict->TopLeftPixel();
93   for (int y = 0; y < 4; ++y) {
94     for (int x = 0; x < 4; ++x) {
95       pred[y * predict->stride() + x] = y * 4 + x;
96     }
97   }
98
99   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
100                                predict->stride(), output->TopLeftPixel(),
101                                output->stride()));
102
103   uint8_t const *out = output->TopLeftPixel();
104   for (int y = 0; y < 4; ++y) {
105     for (int x = 0; x < 4; ++x) {
106       EXPECT_EQ(1 + y * 4 + x, out[y * output->stride() + x]);
107     }
108   }
109
110   if (HasFailure()) {
111     output->DumpBuffer();
112   }
113
114   ASSERT_TRUE(output->CheckPadding());
115 }
116
117 TEST_P(IDCTTest, TestWithData) {
118   // Test a single known input.
119   predict->Set(0);
120
121   int16_t *in = input->TopLeftPixel();
122   for (int y = 0; y < 4; ++y) {
123     for (int x = 0; x < 4; ++x) {
124       in[y * input->stride() + x] = y * 4 + x;
125     }
126   }
127
128   ASM_REGISTER_STATE_CHECK(UUT(input->TopLeftPixel(), predict->TopLeftPixel(),
129                                predict->stride(), output->TopLeftPixel(),
130                                output->stride()));
131
132   uint8_t *out = output->TopLeftPixel();
133   for (int y = 0; y < 4; ++y) {
134     for (int x = 0; x < 4; ++x) {
135       switch (y * 4 + x) {
136         case 0: EXPECT_EQ(11, out[y * output->stride() + x]); break;
137         case 2:
138         case 5:
139         case 8: EXPECT_EQ(3, out[y * output->stride() + x]); break;
140         case 10: EXPECT_EQ(1, out[y * output->stride() + x]); break;
141         default: EXPECT_EQ(0, out[y * output->stride() + x]);
142       }
143     }
144   }
145
146   if (HasFailure()) {
147     output->DumpBuffer();
148   }
149
150   ASSERT_TRUE(output->CheckPadding());
151 }
152
153 INSTANTIATE_TEST_CASE_P(C, IDCTTest, ::testing::Values(vp8_short_idct4x4llm_c));
154
155 #if HAVE_NEON
156 INSTANTIATE_TEST_CASE_P(NEON, IDCTTest,
157                         ::testing::Values(vp8_short_idct4x4llm_neon));
158 #endif  // HAVE_NEON
159
160 #if HAVE_MMX
161 INSTANTIATE_TEST_CASE_P(MMX, IDCTTest,
162                         ::testing::Values(vp8_short_idct4x4llm_mmx));
163 #endif  // HAVE_MMX
164
165 #if HAVE_MSA
166 INSTANTIATE_TEST_CASE_P(MSA, IDCTTest,
167                         ::testing::Values(vp8_short_idct4x4llm_msa));
168 #endif  // HAVE_MSA
169 }