blob: 3d07b44daf48c0a21f493bebe85bdbf6bd7594e7 [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;
Yi Luo157e45a2016-10-17 11:18:50 -070072 height_ = 32;
Yi Luofed8e1c2016-10-07 09:46:05 -070073 fwd_txfm_ref = fht32x32_ref;
74 bit_depth_ = GET_PARAM(3);
75 mask_ = (1 << bit_depth_) - 1;
76 num_coeffs_ = GET_PARAM(4);
77 }
78 virtual void TearDown() { libaom_test::ClearSystemState(); }
79
80 protected:
81 void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) {
82 fwd_txfm_(in, out, stride, tx_type_);
83 }
84
85 void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) {
86 inv_txfm_(out, dst, stride, tx_type_);
87 }
88
89 FhtFunc fwd_txfm_;
90 IhtFunc inv_txfm_;
91};
92
93TEST_P(AV1Trans32x32HT, CoeffCheck) { RunCoeffCheck(); }
Yi Luo157e45a2016-10-17 11:18:50 -070094TEST_P(AV1Trans32x32HT, MemCheck) { RunMemCheck(); }
Yi Luofed8e1c2016-10-07 09:46:05 -070095
96#if CONFIG_AOM_HIGHBITDEPTH
97class AV1HighbdTrans32x32HT
98 : public ::testing::TestWithParam<HighbdHt32x32Param> {
99 public:
100 virtual ~AV1HighbdTrans32x32HT() {}
101
102 virtual void SetUp() {
103 fwd_txfm_ = GET_PARAM(0);
104 fwd_txfm_ref_ = highbd_fht32x32_ref;
105 tx_type_ = GET_PARAM(1);
106 bit_depth_ = GET_PARAM(2);
107 mask_ = (1 << bit_depth_) - 1;
108 num_coeffs_ = 1024;
109
110 input_ = reinterpret_cast<int16_t *>(
111 aom_memalign(32, sizeof(int16_t) * num_coeffs_));
112 output_ = reinterpret_cast<int32_t *>(
113 aom_memalign(32, sizeof(int32_t) * num_coeffs_));
114 output_ref_ = reinterpret_cast<int32_t *>(
115 aom_memalign(32, sizeof(int32_t) * num_coeffs_));
116 }
117
118 virtual void TearDown() {
119 aom_free(input_);
120 aom_free(output_);
121 aom_free(output_ref_);
122 libaom_test::ClearSystemState();
123 }
124
125 protected:
126 void RunBitexactCheck();
127
128 private:
129 HbdHtFunc fwd_txfm_;
130 HbdHtFunc fwd_txfm_ref_;
131 int tx_type_;
132 int bit_depth_;
133 int mask_;
134 int num_coeffs_;
135 int16_t *input_;
136 int32_t *output_;
137 int32_t *output_ref_;
138};
139
140void AV1HighbdTrans32x32HT::RunBitexactCheck() {
141 ACMRandom rnd(ACMRandom::DeterministicSeed());
142 int i, j;
143 const int stride = 32;
144 const int num_tests = 1000;
145
146 for (i = 0; i < num_tests; ++i) {
147 for (j = 0; j < num_coeffs_; ++j) {
148 input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_);
149 }
150
151 fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_);
152 ASM_REGISTER_STATE_CHECK(
153 fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_));
154
155 for (j = 0; j < num_coeffs_; ++j) {
156 EXPECT_EQ(output_ref_[j], output_[j])
157 << "Not bit-exact result at index: " << j << " at test block: " << i;
158 }
159 }
160}
161
162TEST_P(AV1HighbdTrans32x32HT, HighbdCoeffCheck) { RunBitexactCheck(); }
163#endif // CONFIG_AOM_HIGHBITDEPTH
164
165using std::tr1::make_tuple;
166
167#if HAVE_AVX2
168const Ht32x32Param kArrayHt32x32Param_avx2[] = {
Yi Luo157e45a2016-10-17 11:18:50 -0700169 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 0, AOM_BITS_8, 1024),
Yi Luofed8e1c2016-10-07 09:46:05 -0700170 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 1, AOM_BITS_8, 1024),
171 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 2, AOM_BITS_8, 1024),
172 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 3, AOM_BITS_8, 1024),
173#if CONFIG_EXT_TX
174 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 4, AOM_BITS_8, 1024),
175 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 5, AOM_BITS_8, 1024),
176 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 6, AOM_BITS_8, 1024),
177 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 7, AOM_BITS_8, 1024),
178 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 8, AOM_BITS_8, 1024),
179 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 10, AOM_BITS_8, 1024),
180 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 11, AOM_BITS_8, 1024),
181 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 12, AOM_BITS_8, 1024),
182 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 13, AOM_BITS_8, 1024),
183 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 14, AOM_BITS_8, 1024),
184 make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 15, AOM_BITS_8, 1024)
185#endif // CONFIG_EXT_TX
186};
187INSTANTIATE_TEST_CASE_P(AVX2, AV1Trans32x32HT,
188 ::testing::ValuesIn(kArrayHt32x32Param_avx2));
189#endif // HAVE_AVX2
190} // namespace