blob: 913add4e233ec4dd35ad1444d1aad9f513255a64 [file] [log] [blame]
Yaowu Xuf883b422016-08-30 14:01:10 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuf883b422016-08-30 14:01:10 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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.
Yaowu Xuf883b422016-08-30 14:01:10 -070010 */
11
12#include "third_party/googletest/src/include/gtest/gtest.h"
13
14#include "./av1_rtcd.h"
15#include "./aom_dsp_rtcd.h"
16
17#include "test/acm_random.h"
18#include "test/clear_system_state.h"
19#include "test/register_state_check.h"
20#include "test/transform_test_base.h"
21#include "test/util.h"
22#include "aom_ports/mem.h"
23
24using libaom_test::ACMRandom;
25
26namespace {
27typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride,
28 int tx_type);
29using std::tr1::tuple;
30using libaom_test::FhtFunc;
31typedef tuple<FhtFunc, IhtFunc, int, aom_bit_depth_t, int> Ht4x4Param;
32
33void fht4x4_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
34 av1_fht4x4_c(in, out, stride, tx_type);
35}
36
Yi Luo8245b9a2016-11-17 14:56:43 -080037void iht4x4_ref(const tran_low_t *in, uint8_t *out, int stride, int tx_type) {
38 av1_iht4x4_16_add_c(in, out, stride, tx_type);
39}
40
Yaowu Xuf883b422016-08-30 14:01:10 -070041#if CONFIG_AOM_HIGHBITDEPTH
42typedef void (*IhighbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride,
43 int tx_type, int bd);
44typedef void (*HBDFhtFunc)(const int16_t *input, int32_t *output, int stride,
45 int tx_type, int bd);
46
47// HighbdHt4x4Param argument list:
48// <Target optimized function, tx_type, bit depth>
49typedef tuple<HBDFhtFunc, int, int> HighbdHt4x4Param;
50
51void highbe_fht4x4_ref(const int16_t *in, int32_t *out, int stride, int tx_type,
52 int bd) {
53 av1_fwd_txfm2d_4x4_c(in, out, stride, tx_type, bd);
54}
55#endif // CONFIG_AOM_HIGHBITDEPTH
56
57class AV1Trans4x4HT : public libaom_test::TransformTestBase,
58 public ::testing::TestWithParam<Ht4x4Param> {
59 public:
60 virtual ~AV1Trans4x4HT() {}
61
62 virtual void SetUp() {
63 fwd_txfm_ = GET_PARAM(0);
64 inv_txfm_ = GET_PARAM(1);
65 tx_type_ = GET_PARAM(2);
66 pitch_ = 4;
David Barker78250222016-10-13 15:10:14 +010067 height_ = 4;
Yaowu Xuf883b422016-08-30 14:01:10 -070068 fwd_txfm_ref = fht4x4_ref;
Yi Luo8245b9a2016-11-17 14:56:43 -080069 inv_txfm_ref = iht4x4_ref;
Yaowu Xuf883b422016-08-30 14:01:10 -070070 bit_depth_ = GET_PARAM(3);
71 mask_ = (1 << bit_depth_) - 1;
72 num_coeffs_ = GET_PARAM(4);
73 }
74 virtual void TearDown() { libaom_test::ClearSystemState(); }
75
76 protected:
77 void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
78 fwd_txfm_(in, out, stride, tx_type_);
79 }
80
81 void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
82 inv_txfm_(out, dst, stride, tx_type_);
83 }
84
85 FhtFunc fwd_txfm_;
86 IhtFunc inv_txfm_;
87};
88
Yi Luo8245b9a2016-11-17 14:56:43 -080089TEST_P(AV1Trans4x4HT, MemCheck) { RunMemCheck(); }
Yaowu Xuf883b422016-08-30 14:01:10 -070090TEST_P(AV1Trans4x4HT, CoeffCheck) { RunCoeffCheck(); }
Yi Luo8245b9a2016-11-17 14:56:43 -080091// Note:
92// TODO(luoyi): Add tx_type, 9-15 for inverse transform.
93// Need cleanup since same tests may be done in fdct4x4_test.cc
94// TEST_P(AV1Trans4x4HT, AccuracyCheck) { RunAccuracyCheck(0); }
95// TEST_P(AV1Trans4x4HT, InvAccuracyCheck) { RunInvAccuracyCheck(0); }
96// TEST_P(AV1Trans4x4HT, InvCoeffCheck) { RunInvCoeffCheck(); }
Yaowu Xuf883b422016-08-30 14:01:10 -070097
98#if CONFIG_AOM_HIGHBITDEPTH
99class AV1HighbdTrans4x4HT : public ::testing::TestWithParam<HighbdHt4x4Param> {
100 public:
101 virtual ~AV1HighbdTrans4x4HT() {}
102
103 virtual void SetUp() {
104 fwd_txfm_ = GET_PARAM(0);
105 fwd_txfm_ref_ = highbe_fht4x4_ref;
106 tx_type_ = GET_PARAM(1);
107 bit_depth_ = GET_PARAM(2);
108 mask_ = (1 << bit_depth_) - 1;
109 num_coeffs_ = 16;
110
111 input_ = reinterpret_cast<int16_t *>(
112 aom_memalign(16, sizeof(int16_t) * num_coeffs_));
113 output_ = reinterpret_cast<int32_t *>(
114 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
115 output_ref_ = reinterpret_cast<int32_t *>(
116 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
117 }
118
119 virtual void TearDown() {
120 aom_free(input_);
121 aom_free(output_);
122 aom_free(output_ref_);
123 libaom_test::ClearSystemState();
124 }
125
126 protected:
127 void RunBitexactCheck();
128
129 private:
130 HBDFhtFunc fwd_txfm_;
131 HBDFhtFunc fwd_txfm_ref_;
132 int tx_type_;
133 int bit_depth_;
134 int mask_;
135 int num_coeffs_;
136 int16_t *input_;
137 int32_t *output_;
138 int32_t *output_ref_;
139};
140
141void AV1HighbdTrans4x4HT::RunBitexactCheck() {
142 ACMRandom rnd(ACMRandom::DeterministicSeed());
143 int i, j;
144 const int stride = 4;
145 const int num_tests = 1000;
146 const int num_coeffs = 16;
147
148 for (i = 0; i < num_tests; ++i) {
149 for (j = 0; j < num_coeffs; ++j) {
150 input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
151 }
152
153 fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_);
154 fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_);
155
156 for (j = 0; j < num_coeffs; ++j) {
157 EXPECT_EQ(output_[j], output_ref_[j])
158 << "Not bit-exact result at index: " << j << " at test block: " << i;
159 }
160 }
161}
162
163TEST_P(AV1HighbdTrans4x4HT, HighbdCoeffCheck) { RunBitexactCheck(); }
164#endif // CONFIG_AOM_HIGHBITDEPTH
165
166using std::tr1::make_tuple;
167
Yaowu Xu46f0f292016-11-28 10:08:53 -0800168#if HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE
Yaowu Xuf883b422016-08-30 14:01:10 -0700169const Ht4x4Param kArrayHt4x4Param_sse2[] = {
170 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 0, AOM_BITS_8, 16),
171 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 1, AOM_BITS_8, 16),
172 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 2, AOM_BITS_8, 16),
173 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 3, AOM_BITS_8, 16),
174#if CONFIG_EXT_TX
175 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 4, AOM_BITS_8, 16),
176 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 5, AOM_BITS_8, 16),
177 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 6, AOM_BITS_8, 16),
178 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 7, AOM_BITS_8, 16),
179 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 8, AOM_BITS_8, 16),
180 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 10, AOM_BITS_8, 16),
181 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 11, AOM_BITS_8, 16),
182 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 12, AOM_BITS_8, 16),
183 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 13, AOM_BITS_8, 16),
184 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 14, AOM_BITS_8, 16),
185 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 15, AOM_BITS_8, 16)
186#endif // CONFIG_EXT_TX
187};
188INSTANTIATE_TEST_CASE_P(SSE2, AV1Trans4x4HT,
189 ::testing::ValuesIn(kArrayHt4x4Param_sse2));
Yaowu Xu46f0f292016-11-28 10:08:53 -0800190#endif // HAVE_SSE2 && !CONFIG_EMULATE_HARDWARE
Yaowu Xuf883b422016-08-30 14:01:10 -0700191
Yaowu Xu46f0f292016-11-28 10:08:53 -0800192#if HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Yaowu Xuf883b422016-08-30 14:01:10 -0700193const HighbdHt4x4Param kArrayHighbdHt4x4Param[] = {
194 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 10),
195 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 12),
196 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 10),
197 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 12),
198 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 10),
199 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 12),
200 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 10),
201 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 12),
202#if CONFIG_EXT_TX
203 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 10),
204 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 12),
205 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 10),
206 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 12),
207 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 10),
208 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 12),
209 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 10),
210 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 12),
211 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 10),
212 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 12),
213#endif // CONFIG_EXT_TX
214};
215
216INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdTrans4x4HT,
217 ::testing::ValuesIn(kArrayHighbdHt4x4Param));
218
Yaowu Xu46f0f292016-11-28 10:08:53 -0800219#endif // HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE
Yaowu Xuf883b422016-08-30 14:01:10 -0700220
221} // namespace