blob: 104b86527caf0631ad2ee7683edf545c6ddfbcb3 [file] [log] [blame]
Yaowu Xuf883b422016-08-30 14:01:10 -07001/*
2 * Copyright (c) 2016 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 "./av1_rtcd.h"
14#include "./aom_dsp_rtcd.h"
15
16#include "test/acm_random.h"
17#include "test/clear_system_state.h"
18#include "test/register_state_check.h"
19#include "test/transform_test_base.h"
20#include "test/util.h"
21#include "aom_ports/mem.h"
22
23using libaom_test::ACMRandom;
24
25namespace {
26typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
27 int tx_type);
28using std::tr1::tuple;
29using libaom_test::FhtFunc;
30typedef tuple<FhtFunc, IhtFunc, int, aom_bit_depth_t, int> Ht4x4Param;
31
32void fht4x4_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
33 av1_fht4x4_c(in, out, stride, tx_type);
34}
35
36#if CONFIG_AOM_HIGHBITDEPTH
37typedef void (*IhighbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride,
38 int tx_type, int bd);
39typedef void (*HBDFhtFunc)(const int16_t *input, int32_t *output, int stride,
40 int tx_type, int bd);
41
42// HighbdHt4x4Param argument list:
43// <Target optimized function, tx_type, bit depth>
44typedef tuple<HBDFhtFunc, int, int> HighbdHt4x4Param;
45
46void highbe_fht4x4_ref(const int16_t *in, int32_t *out, int stride, int tx_type,
47 int bd) {
48 av1_fwd_txfm2d_4x4_c(in, out, stride, tx_type, bd);
49}
50#endif // CONFIG_AOM_HIGHBITDEPTH
51
52class AV1Trans4x4HT : public libaom_test::TransformTestBase,
53 public ::testing::TestWithParam<Ht4x4Param> {
54 public:
55 virtual ~AV1Trans4x4HT() {}
56
57 virtual void SetUp() {
58 fwd_txfm_ = GET_PARAM(0);
59 inv_txfm_ = GET_PARAM(1);
60 tx_type_ = GET_PARAM(2);
61 pitch_ = 4;
62 fwd_txfm_ref = fht4x4_ref;
63 bit_depth_ = GET_PARAM(3);
64 mask_ = (1 << bit_depth_) - 1;
65 num_coeffs_ = GET_PARAM(4);
66 }
67 virtual void TearDown() { libaom_test::ClearSystemState(); }
68
69 protected:
70 void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
71 fwd_txfm_(in, out, stride, tx_type_);
72 }
73
74 void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
75 inv_txfm_(out, dst, stride, tx_type_);
76 }
77
78 FhtFunc fwd_txfm_;
79 IhtFunc inv_txfm_;
80};
81
82TEST_P(AV1Trans4x4HT, CoeffCheck) { RunCoeffCheck(); }
83
84#if CONFIG_AOM_HIGHBITDEPTH
85class AV1HighbdTrans4x4HT : public ::testing::TestWithParam<HighbdHt4x4Param> {
86 public:
87 virtual ~AV1HighbdTrans4x4HT() {}
88
89 virtual void SetUp() {
90 fwd_txfm_ = GET_PARAM(0);
91 fwd_txfm_ref_ = highbe_fht4x4_ref;
92 tx_type_ = GET_PARAM(1);
93 bit_depth_ = GET_PARAM(2);
94 mask_ = (1 << bit_depth_) - 1;
95 num_coeffs_ = 16;
96
97 input_ = reinterpret_cast<int16_t *>(
98 aom_memalign(16, sizeof(int16_t) * num_coeffs_));
99 output_ = reinterpret_cast<int32_t *>(
100 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
101 output_ref_ = reinterpret_cast<int32_t *>(
102 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
103 }
104
105 virtual void TearDown() {
106 aom_free(input_);
107 aom_free(output_);
108 aom_free(output_ref_);
109 libaom_test::ClearSystemState();
110 }
111
112 protected:
113 void RunBitexactCheck();
114
115 private:
116 HBDFhtFunc fwd_txfm_;
117 HBDFhtFunc fwd_txfm_ref_;
118 int tx_type_;
119 int bit_depth_;
120 int mask_;
121 int num_coeffs_;
122 int16_t *input_;
123 int32_t *output_;
124 int32_t *output_ref_;
125};
126
127void AV1HighbdTrans4x4HT::RunBitexactCheck() {
128 ACMRandom rnd(ACMRandom::DeterministicSeed());
129 int i, j;
130 const int stride = 4;
131 const int num_tests = 1000;
132 const int num_coeffs = 16;
133
134 for (i = 0; i < num_tests; ++i) {
135 for (j = 0; j < num_coeffs; ++j) {
136 input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
137 }
138
139 fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_);
140 fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_);
141
142 for (j = 0; j < num_coeffs; ++j) {
143 EXPECT_EQ(output_[j], output_ref_[j])
144 << "Not bit-exact result at index: " << j << " at test block: " << i;
145 }
146 }
147}
148
149TEST_P(AV1HighbdTrans4x4HT, HighbdCoeffCheck) { RunBitexactCheck(); }
150#endif // CONFIG_AOM_HIGHBITDEPTH
151
152using std::tr1::make_tuple;
153
154#if HAVE_SSE2
155const Ht4x4Param kArrayHt4x4Param_sse2[] = {
156 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 0, AOM_BITS_8, 16),
157 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 1, AOM_BITS_8, 16),
158 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 2, AOM_BITS_8, 16),
159 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 3, AOM_BITS_8, 16),
160#if CONFIG_EXT_TX
161 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 4, AOM_BITS_8, 16),
162 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 5, AOM_BITS_8, 16),
163 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 6, AOM_BITS_8, 16),
164 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 7, AOM_BITS_8, 16),
165 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 8, AOM_BITS_8, 16),
166 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 10, AOM_BITS_8, 16),
167 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 11, AOM_BITS_8, 16),
168 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 12, AOM_BITS_8, 16),
169 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 13, AOM_BITS_8, 16),
170 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 14, AOM_BITS_8, 16),
171 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 15, AOM_BITS_8, 16)
172#endif // CONFIG_EXT_TX
173};
174INSTANTIATE_TEST_CASE_P(SSE2, AV1Trans4x4HT,
175 ::testing::ValuesIn(kArrayHt4x4Param_sse2));
176#endif // HAVE_SSE2
177
178#if HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH
179const HighbdHt4x4Param kArrayHighbdHt4x4Param[] = {
180 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 10),
181 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 12),
182 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 10),
183 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 12),
184 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 10),
185 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 12),
186 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 10),
187 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 12),
188#if CONFIG_EXT_TX
189 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 10),
190 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 12),
191 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 10),
192 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 12),
193 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 10),
194 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 12),
195 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 10),
196 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 12),
197 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 10),
198 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 12),
199#endif // CONFIG_EXT_TX
200};
201
202INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdTrans4x4HT,
203 ::testing::ValuesIn(kArrayHighbdHt4x4Param));
204
205#endif // HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH
206
207} // namespace