blob: a949ebf7a1253f9474ec955b1cfad0de195c4c79 [file] [log] [blame]
Yi Luofed8e1c2016-10-07 09:46:05 -07001/*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * 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.
10 */
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> Ht32x32Param;
32
33void fht32x32_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) {
34 av1_fht32x32_c(in, out, stride, tx_type);
35}
36
37#if CONFIG_AOM_HIGHBITDEPTH
38typedef void (*IHbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride,
39 int tx_type, int bd);
40typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride,
41 int tx_type, int bd);
42
43// Target optimized function, tx_type, bit depth
44typedef tuple<HbdHtFunc, int, int> HighbdHt32x32Param;
45
46void highbd_fht32x32_ref(const int16_t *in, int32_t *out, int stride,
47 int tx_type, int bd) {
48 av1_fwd_txfm2d_32x32_c(in, out, stride, tx_type, bd);
49}
50#endif // CONFIG_AOM_HIGHBITDEPTH
51
52#if HAVE_AVX2
53void dummy_inv_txfm(const tran_low_t *in, uint8_t *out, int stride,
54 int tx_type) {
55 (void)in;
56 (void)out;
57 (void)stride;
58 (void)tx_type;
59}
60#endif
61
62class AV1Trans32x32HT : public libaom_test::TransformTestBase,
63 public ::testing::TestWithParam<Ht32x32Param> {
64 public:
65 virtual ~AV1Trans32x32HT() {}
66
67 virtual void SetUp() {
68 fwd_txfm_ = GET_PARAM(0);
69 inv_txfm_ = GET_PARAM(1);
70 tx_type_ = GET_PARAM(2);
71 pitch_ = 32;
72 fwd_txfm_ref = fht32x32_ref;
73 bit_depth_ = GET_PARAM(3);
74 mask_ = (1 << bit_depth_) - 1;
75 num_coeffs_ = GET_PARAM(4);
76 }
77 virtual void TearDown() { libaom_test::ClearSystemState(); }
78
79 protected:
80 void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
81 fwd_txfm_(in, out, stride, tx_type_);
82 }
83
84 void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
85 inv_txfm_(out, dst, stride, tx_type_);
86 }
87
88 FhtFunc fwd_txfm_;
89 IhtFunc inv_txfm_;
90};
91
92TEST_P(AV1Trans32x32HT, CoeffCheck) { RunCoeffCheck(); }
93
94#if CONFIG_AOM_HIGHBITDEPTH
95class AV1HighbdTrans32x32HT
96 : public ::testing::TestWithParam<HighbdHt32x32Param> {
97 public:
98 virtual ~AV1HighbdTrans32x32HT() {}
99
100 virtual void SetUp() {
101 fwd_txfm_ = GET_PARAM(0);
102 fwd_txfm_ref_ = highbd_fht32x32_ref;
103 tx_type_ = GET_PARAM(1);
104 bit_depth_ = GET_PARAM(2);
105 mask_ = (1 << bit_depth_) - 1;
106 num_coeffs_ = 1024;
107
108 input_ = reinterpret_cast<int16_t *>(
109 aom_memalign(32, sizeof(int16_t) * num_coeffs_));
110 output_ = reinterpret_cast<int32_t *>(
111 aom_memalign(32, sizeof(int32_t) * num_coeffs_));
112 output_ref_ = reinterpret_cast<int32_t *>(
113 aom_memalign(32, sizeof(int32_t) * num_coeffs_));
114 }
115
116 virtual void TearDown() {
117 aom_free(input_);
118 aom_free(output_);
119 aom_free(output_ref_);
120 libaom_test::ClearSystemState();
121 }
122
123 protected:
124 void RunBitexactCheck();
125
126 private:
127 HbdHtFunc fwd_txfm_;
128 HbdHtFunc fwd_txfm_ref_;
129 int tx_type_;
130 int bit_depth_;
131 int mask_;
132 int num_coeffs_;
133 int16_t *input_;
134 int32_t *output_;
135 int32_t *output_ref_;
136};
137
138void AV1HighbdTrans32x32HT::RunBitexactCheck() {
139 ACMRandom rnd(ACMRandom::DeterministicSeed());
140 int i, j;
141 const int stride = 32;
142 const int num_tests = 1000;
143
144 for (i = 0; i < num_tests; ++i) {
145 for (j = 0; j < num_coeffs_; ++j) {
146 input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
147 }
148
149 fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_);
150 ASM_REGISTER_STATE_CHECK(
151 fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_));
152
153 for (j = 0; j < num_coeffs_; ++j) {
154 EXPECT_EQ(output_ref_[j], output_[j])
155 << "Not bit-exact result at index: " << j << " at test block: " << i;
156 }
157 }
158}
159
160TEST_P(AV1HighbdTrans32x32HT, HighbdCoeffCheck) { RunBitexactCheck(); }
161#endif // CONFIG_AOM_HIGHBITDEPTH
162
163using std::tr1::make_tuple;
164
165#if HAVE_AVX2
166const Ht32x32Param kArrayHt32x32Param_avx2[] = {
167 // TODO(luoyi): DCT_DCT tx_type is not enabled in av1_fht32x32_c(avx2) yet.
168 // make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 0, AOM_BITS_8, 1024),
169 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 1, AOM_BITS_8, 1024),
170 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 2, AOM_BITS_8, 1024),
171 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 3, AOM_BITS_8, 1024),
172#if CONFIG_EXT_TX
173 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 4, AOM_BITS_8, 1024),
174 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 5, AOM_BITS_8, 1024),
175 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 6, AOM_BITS_8, 1024),
176 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 7, AOM_BITS_8, 1024),
177 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 8, AOM_BITS_8, 1024),
178 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 10, AOM_BITS_8, 1024),
179 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 11, AOM_BITS_8, 1024),
180 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 12, AOM_BITS_8, 1024),
181 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 13, AOM_BITS_8, 1024),
182 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 14, AOM_BITS_8, 1024),
183 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 15, AOM_BITS_8, 1024)
184#endif // CONFIG_EXT_TX
185};
186INSTANTIATE_TEST_CASE_P(AVX2, AV1Trans32x32HT,
187 ::testing::ValuesIn(kArrayHt32x32Param_avx2));
188#endif // HAVE_AVX2
189} // namespace