blob: f49d7368d0b900a9b44eaf609d665ac3bfef740f [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
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070013
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,
Lester Lu27319b62017-07-10 16:57:15 -070028 const TxfmParam *txfm_param);
Yaowu Xuf883b422016-08-30 14:01:10 -070029using std::tr1::tuple;
30using libaom_test::FhtFunc;
31typedef tuple<FhtFunc, IhtFunc, int, aom_bit_depth_t, int> Ht4x4Param;
32
Lester Lud8b1ddc2017-07-06 16:13:29 -070033void fht4x4_ref(const int16_t *in, tran_low_t *out, int stride,
Lester Lu27319b62017-07-10 16:57:15 -070034 TxfmParam *txfm_param) {
35 av1_fht4x4_c(in, out, stride, txfm_param);
Yaowu Xuf883b422016-08-30 14:01:10 -070036}
37
Lester Lud8b1ddc2017-07-06 16:13:29 -070038void iht4x4_ref(const tran_low_t *in, uint8_t *out, int stride,
Lester Lu27319b62017-07-10 16:57:15 -070039 const TxfmParam *txfm_param) {
40 av1_iht4x4_16_add_c(in, out, stride, txfm_param);
Yi Luo8245b9a2016-11-17 14:56:43 -080041}
42
Sebastien Alaiwan71e87842017-04-12 16:03:28 +020043#if CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -070044typedef void (*IhighbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride,
45 int tx_type, int bd);
46typedef void (*HBDFhtFunc)(const int16_t *input, int32_t *output, int stride,
47 int tx_type, int bd);
48
49// HighbdHt4x4Param argument list:
50// <Target optimized function, tx_type, bit depth>
51typedef tuple<HBDFhtFunc, int, int> HighbdHt4x4Param;
52
53void highbe_fht4x4_ref(const int16_t *in, int32_t *out, int stride, int tx_type,
54 int bd) {
55 av1_fwd_txfm2d_4x4_c(in, out, stride, tx_type, bd);
56}
Sebastien Alaiwan71e87842017-04-12 16:03:28 +020057#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -070058
59class AV1Trans4x4HT : public libaom_test::TransformTestBase,
60 public ::testing::TestWithParam<Ht4x4Param> {
61 public:
62 virtual ~AV1Trans4x4HT() {}
63
64 virtual void SetUp() {
65 fwd_txfm_ = GET_PARAM(0);
66 inv_txfm_ = GET_PARAM(1);
Yaowu Xuf883b422016-08-30 14:01:10 -070067 pitch_ = 4;
David Barker78250222016-10-13 15:10:14 +010068 height_ = 4;
Yaowu Xuf883b422016-08-30 14:01:10 -070069 fwd_txfm_ref = fht4x4_ref;
Yi Luo8245b9a2016-11-17 14:56:43 -080070 inv_txfm_ref = iht4x4_ref;
Yaowu Xuf883b422016-08-30 14:01:10 -070071 bit_depth_ = GET_PARAM(3);
72 mask_ = (1 << bit_depth_) - 1;
73 num_coeffs_ = GET_PARAM(4);
Lester Lu27319b62017-07-10 16:57:15 -070074 txfm_param_.tx_type = GET_PARAM(2);
Yaowu Xuf883b422016-08-30 14:01:10 -070075 }
76 virtual void TearDown() { libaom_test::ClearSystemState(); }
77
78 protected:
79 void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
Lester Lu27319b62017-07-10 16:57:15 -070080 fwd_txfm_(in, out, stride, &txfm_param_);
Yaowu Xuf883b422016-08-30 14:01:10 -070081 }
82
83 void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
Lester Lu27319b62017-07-10 16:57:15 -070084 inv_txfm_(out, dst, stride, &txfm_param_);
Yaowu Xuf883b422016-08-30 14:01:10 -070085 }
86
87 FhtFunc fwd_txfm_;
88 IhtFunc inv_txfm_;
89};
90
Yi Luo8245b9a2016-11-17 14:56:43 -080091TEST_P(AV1Trans4x4HT, MemCheck) { RunMemCheck(); }
Yaowu Xuf883b422016-08-30 14:01:10 -070092TEST_P(AV1Trans4x4HT, CoeffCheck) { RunCoeffCheck(); }
Yi Luo8245b9a2016-11-17 14:56:43 -080093// Note:
94// TODO(luoyi): Add tx_type, 9-15 for inverse transform.
95// Need cleanup since same tests may be done in fdct4x4_test.cc
96// TEST_P(AV1Trans4x4HT, AccuracyCheck) { RunAccuracyCheck(0); }
97// TEST_P(AV1Trans4x4HT, InvAccuracyCheck) { RunInvAccuracyCheck(0); }
98// TEST_P(AV1Trans4x4HT, InvCoeffCheck) { RunInvCoeffCheck(); }
Yaowu Xuf883b422016-08-30 14:01:10 -070099
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200100#if CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -0700101class AV1HighbdTrans4x4HT : public ::testing::TestWithParam<HighbdHt4x4Param> {
102 public:
103 virtual ~AV1HighbdTrans4x4HT() {}
104
105 virtual void SetUp() {
106 fwd_txfm_ = GET_PARAM(0);
107 fwd_txfm_ref_ = highbe_fht4x4_ref;
108 tx_type_ = GET_PARAM(1);
109 bit_depth_ = GET_PARAM(2);
110 mask_ = (1 << bit_depth_) - 1;
111 num_coeffs_ = 16;
112
113 input_ = reinterpret_cast<int16_t *>(
114 aom_memalign(16, sizeof(int16_t) * num_coeffs_));
115 output_ = reinterpret_cast<int32_t *>(
116 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
117 output_ref_ = reinterpret_cast<int32_t *>(
118 aom_memalign(16, sizeof(int32_t) * num_coeffs_));
119 }
120
121 virtual void TearDown() {
122 aom_free(input_);
123 aom_free(output_);
124 aom_free(output_ref_);
125 libaom_test::ClearSystemState();
126 }
127
128 protected:
129 void RunBitexactCheck();
130
131 private:
132 HBDFhtFunc fwd_txfm_;
133 HBDFhtFunc fwd_txfm_ref_;
134 int tx_type_;
135 int bit_depth_;
136 int mask_;
137 int num_coeffs_;
138 int16_t *input_;
139 int32_t *output_;
140 int32_t *output_ref_;
141};
142
143void AV1HighbdTrans4x4HT::RunBitexactCheck() {
144 ACMRandom rnd(ACMRandom::DeterministicSeed());
145 int i, j;
146 const int stride = 4;
147 const int num_tests = 1000;
148 const int num_coeffs = 16;
149
150 for (i = 0; i < num_tests; ++i) {
151 for (j = 0; j < num_coeffs; ++j) {
152 input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
153 }
154
155 fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_);
156 fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_);
157
158 for (j = 0; j < num_coeffs; ++j) {
159 EXPECT_EQ(output_[j], output_ref_[j])
160 << "Not bit-exact result at index: " << j << " at test block: " << i;
161 }
162 }
163}
164
165TEST_P(AV1HighbdTrans4x4HT, HighbdCoeffCheck) { RunBitexactCheck(); }
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200166#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -0700167
168using std::tr1::make_tuple;
169
Sebastien Alaiwanc6a48a22017-04-20 10:12:43 +0200170#if HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -0700171const Ht4x4Param kArrayHt4x4Param_sse2[] = {
172 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 0, AOM_BITS_8, 16),
173 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 1, AOM_BITS_8, 16),
174 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 2, AOM_BITS_8, 16),
175 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 3, AOM_BITS_8, 16),
176#if CONFIG_EXT_TX
177 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 4, AOM_BITS_8, 16),
178 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 5, AOM_BITS_8, 16),
179 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 6, AOM_BITS_8, 16),
180 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 7, AOM_BITS_8, 16),
181 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 8, AOM_BITS_8, 16),
Yi Luo13d2aee2017-03-29 17:48:13 -0700182 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 9, AOM_BITS_8, 16),
Yaowu Xuf883b422016-08-30 14:01:10 -0700183 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 10, AOM_BITS_8, 16),
184 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 11, AOM_BITS_8, 16),
185 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 12, AOM_BITS_8, 16),
186 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 13, AOM_BITS_8, 16),
187 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 14, AOM_BITS_8, 16),
188 make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 15, AOM_BITS_8, 16)
189#endif // CONFIG_EXT_TX
190};
191INSTANTIATE_TEST_CASE_P(SSE2, AV1Trans4x4HT,
192 ::testing::ValuesIn(kArrayHt4x4Param_sse2));
Sebastien Alaiwanc6a48a22017-04-20 10:12:43 +0200193#endif // HAVE_SSE2
Yaowu Xuf883b422016-08-30 14:01:10 -0700194
Sebastien Alaiwanc6a48a22017-04-20 10:12:43 +0200195#if HAVE_SSE4_1 && CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -0700196const HighbdHt4x4Param kArrayHighbdHt4x4Param[] = {
197 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 10),
198 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 12),
199 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 10),
200 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 12),
201 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 10),
202 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 12),
203 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 10),
204 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 12),
205#if CONFIG_EXT_TX
206 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 10),
207 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 12),
208 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 10),
209 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 12),
210 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 10),
211 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 12),
212 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 10),
213 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 12),
214 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 10),
215 make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 12),
216#endif // CONFIG_EXT_TX
217};
218
219INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdTrans4x4HT,
220 ::testing::ValuesIn(kArrayHighbdHt4x4Param));
221
Sebastien Alaiwanc6a48a22017-04-20 10:12:43 +0200222#endif // HAVE_SSE4_1 && CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -0700223
224} // namespace