blob: 422cca5f3415be2009683f64bbbbf04bad3ea140 [file] [log] [blame]
Yi Luo28cdee42016-05-19 14:13:07 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yi Luo28cdee42016-05-19 14:13:07 -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.
Yi Luo28cdee42016-05-19 14:13:07 -070010 */
11
Tom Finegan7a07ece2017-02-07 17:14:05 -080012#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Yi Luo28cdee42016-05-19 14:13:07 -070013
Yaowu Xuf883b422016-08-30 14:01:10 -070014#include "./av1_rtcd.h"
Yi Luo28cdee42016-05-19 14:13:07 -070015#include "test/acm_random.h"
16#include "test/clear_system_state.h"
17#include "test/register_state_check.h"
18#include "test/util.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019#include "av1/common/enums.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070020#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "aom_ports/mem.h"
Yi Luo28cdee42016-05-19 14:13:07 -070022
23namespace {
24
25using std::tr1::tuple;
Yaowu Xuc27fc142016-08-22 16:08:15 -070026using libaom_test::ACMRandom;
Yi Luo28cdee42016-05-19 14:13:07 -070027
28typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride,
29 int tx_type, int bd);
30
31typedef void (*IHbdHtFunc)(const int32_t *coeff, uint16_t *output, int stride,
32 int tx_type, int bd);
33
34// Test parameter argument list:
35// <transform reference function,
36// optimized inverse transform function,
37// inverse transform reference function,
38// num_coeffs,
39// tx_type,
40// bit_depth>
41typedef tuple<HbdHtFunc, IHbdHtFunc, IHbdHtFunc, int, int, int> IHbdHtParam;
42
Yaowu Xuf883b422016-08-30 14:01:10 -070043class AV1HighbdInvHTNxN : public ::testing::TestWithParam<IHbdHtParam> {
Yi Luo28cdee42016-05-19 14:13:07 -070044 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070045 virtual ~AV1HighbdInvHTNxN() {}
Yi Luo28cdee42016-05-19 14:13:07 -070046
47 virtual void SetUp() {
48 txfm_ref_ = GET_PARAM(0);
49 inv_txfm_ = GET_PARAM(1);
50 inv_txfm_ref_ = GET_PARAM(2);
51 num_coeffs_ = GET_PARAM(3);
52 tx_type_ = GET_PARAM(4);
53 bit_depth_ = GET_PARAM(5);
54
55 input_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070056 aom_memalign(16, sizeof(input_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070057
58 // Note:
59 // Inverse transform input buffer is 32-byte aligned
Yaowu Xuc27fc142016-08-22 16:08:15 -070060 // Refer to <root>/av1/encoder/context_tree.c, function,
Yi Luo28cdee42016-05-19 14:13:07 -070061 // void alloc_mode_context().
62 coeffs_ = reinterpret_cast<int32_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070063 aom_memalign(32, sizeof(coeffs_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070064 output_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070065 aom_memalign(32, sizeof(output_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070066 output_ref_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070067 aom_memalign(32, sizeof(output_ref_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070068 }
69
70 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -070071 aom_free(input_);
72 aom_free(coeffs_);
73 aom_free(output_);
74 aom_free(output_ref_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070075 libaom_test::ClearSystemState();
Yi Luo28cdee42016-05-19 14:13:07 -070076 }
77
78 protected:
79 void RunBitexactCheck();
80
81 private:
82 int GetStride() const {
83 if (16 == num_coeffs_) {
84 return 4;
85 } else if (64 == num_coeffs_) {
86 return 8;
87 } else if (256 == num_coeffs_) {
88 return 16;
Yi Luo3bd83772017-01-10 10:11:49 -080089 } else if (1024 == num_coeffs_) {
90 return 32;
Yi Luo28cdee42016-05-19 14:13:07 -070091 } else {
92 return 0;
93 }
94 }
95
96 HbdHtFunc txfm_ref_;
97 IHbdHtFunc inv_txfm_;
98 IHbdHtFunc inv_txfm_ref_;
99 int num_coeffs_;
100 int tx_type_;
101 int bit_depth_;
102
103 int16_t *input_;
104 int32_t *coeffs_;
105 uint16_t *output_;
106 uint16_t *output_ref_;
107};
108
Yaowu Xuf883b422016-08-30 14:01:10 -0700109void AV1HighbdInvHTNxN::RunBitexactCheck() {
Yi Luo28cdee42016-05-19 14:13:07 -0700110 ACMRandom rnd(ACMRandom::DeterministicSeed());
111 const int stride = GetStride();
112 const int num_tests = 20000;
113 const uint16_t mask = (1 << bit_depth_) - 1;
114
115 for (int i = 0; i < num_tests; ++i) {
116 for (int j = 0; j < num_coeffs_; ++j) {
117 input_[j] = (rnd.Rand16() & mask) - (rnd.Rand16() & mask);
118 output_ref_[j] = rnd.Rand16() & mask;
119 output_[j] = output_ref_[j];
120 }
121
122 txfm_ref_(input_, coeffs_, stride, tx_type_, bit_depth_);
123 inv_txfm_ref_(coeffs_, output_ref_, stride, tx_type_, bit_depth_);
clang-format3a826f12016-08-11 17:46:05 -0700124 ASM_REGISTER_STATE_CHECK(
125 inv_txfm_(coeffs_, output_, stride, tx_type_, bit_depth_));
Yi Luo28cdee42016-05-19 14:13:07 -0700126
127 for (int j = 0; j < num_coeffs_; ++j) {
128 EXPECT_EQ(output_ref_[j], output_[j])
clang-format3a826f12016-08-11 17:46:05 -0700129 << "Not bit-exact result at index: " << j << " At test block: " << i;
Yi Luo28cdee42016-05-19 14:13:07 -0700130 }
131 }
132}
133
Yaowu Xuf883b422016-08-30 14:01:10 -0700134TEST_P(AV1HighbdInvHTNxN, InvTransResultCheck) { RunBitexactCheck(); }
Yi Luo28cdee42016-05-19 14:13:07 -0700135
136using std::tr1::make_tuple;
137
Yaowu Xuf883b422016-08-30 14:01:10 -0700138#if HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH
139#define PARAM_LIST_4X4 \
140 &av1_fwd_txfm2d_4x4_c, &av1_inv_txfm2d_add_4x4_sse4_1, \
141 &av1_inv_txfm2d_add_4x4_c, 16
Yi Luo28cdee42016-05-19 14:13:07 -0700142
Yaowu Xuf883b422016-08-30 14:01:10 -0700143#define PARAM_LIST_8X8 \
144 &av1_fwd_txfm2d_8x8_c, &av1_inv_txfm2d_add_8x8_sse4_1, \
145 &av1_inv_txfm2d_add_8x8_c, 64
Yi Luo28cdee42016-05-19 14:13:07 -0700146
Yaowu Xuf883b422016-08-30 14:01:10 -0700147#define PARAM_LIST_16X16 \
148 &av1_fwd_txfm2d_16x16_c, &av1_inv_txfm2d_add_16x16_sse4_1, \
149 &av1_inv_txfm2d_add_16x16_c, 256
Yi Luo28cdee42016-05-19 14:13:07 -0700150
151const IHbdHtParam kArrayIhtParam[] = {
152 // 16x16
Yi Luobfe4c0a2016-05-19 14:13:07 -0700153 make_tuple(PARAM_LIST_16X16, DCT_DCT, 10),
154 make_tuple(PARAM_LIST_16X16, DCT_DCT, 12),
155 make_tuple(PARAM_LIST_16X16, ADST_DCT, 10),
156 make_tuple(PARAM_LIST_16X16, ADST_DCT, 12),
157 make_tuple(PARAM_LIST_16X16, DCT_ADST, 10),
158 make_tuple(PARAM_LIST_16X16, DCT_ADST, 12),
159 make_tuple(PARAM_LIST_16X16, ADST_ADST, 10),
160 make_tuple(PARAM_LIST_16X16, ADST_ADST, 12),
161#if CONFIG_EXT_TX
162 make_tuple(PARAM_LIST_16X16, FLIPADST_DCT, 10),
163 make_tuple(PARAM_LIST_16X16, FLIPADST_DCT, 12),
164 make_tuple(PARAM_LIST_16X16, DCT_FLIPADST, 10),
165 make_tuple(PARAM_LIST_16X16, DCT_FLIPADST, 12),
166 make_tuple(PARAM_LIST_16X16, FLIPADST_FLIPADST, 10),
167 make_tuple(PARAM_LIST_16X16, FLIPADST_FLIPADST, 12),
168 make_tuple(PARAM_LIST_16X16, ADST_FLIPADST, 10),
169 make_tuple(PARAM_LIST_16X16, ADST_FLIPADST, 12),
170 make_tuple(PARAM_LIST_16X16, FLIPADST_ADST, 10),
171 make_tuple(PARAM_LIST_16X16, FLIPADST_ADST, 12),
172#endif
Yi Luo28cdee42016-05-19 14:13:07 -0700173 // 8x8
Yi Luobfe4c0a2016-05-19 14:13:07 -0700174 make_tuple(PARAM_LIST_8X8, DCT_DCT, 10),
175 make_tuple(PARAM_LIST_8X8, DCT_DCT, 12),
176 make_tuple(PARAM_LIST_8X8, ADST_DCT, 10),
177 make_tuple(PARAM_LIST_8X8, ADST_DCT, 12),
178 make_tuple(PARAM_LIST_8X8, DCT_ADST, 10),
179 make_tuple(PARAM_LIST_8X8, DCT_ADST, 12),
180 make_tuple(PARAM_LIST_8X8, ADST_ADST, 10),
181 make_tuple(PARAM_LIST_8X8, ADST_ADST, 12),
182#if CONFIG_EXT_TX
183 make_tuple(PARAM_LIST_8X8, FLIPADST_DCT, 10),
184 make_tuple(PARAM_LIST_8X8, FLIPADST_DCT, 12),
185 make_tuple(PARAM_LIST_8X8, DCT_FLIPADST, 10),
186 make_tuple(PARAM_LIST_8X8, DCT_FLIPADST, 12),
187 make_tuple(PARAM_LIST_8X8, FLIPADST_FLIPADST, 10),
188 make_tuple(PARAM_LIST_8X8, FLIPADST_FLIPADST, 12),
189 make_tuple(PARAM_LIST_8X8, ADST_FLIPADST, 10),
190 make_tuple(PARAM_LIST_8X8, ADST_FLIPADST, 12),
191 make_tuple(PARAM_LIST_8X8, FLIPADST_ADST, 10),
192 make_tuple(PARAM_LIST_8X8, FLIPADST_ADST, 12),
193#endif
Yi Luo28cdee42016-05-19 14:13:07 -0700194 // 4x4
Yi Luobfe4c0a2016-05-19 14:13:07 -0700195 make_tuple(PARAM_LIST_4X4, DCT_DCT, 10),
196 make_tuple(PARAM_LIST_4X4, DCT_DCT, 12),
197 make_tuple(PARAM_LIST_4X4, ADST_DCT, 10),
198 make_tuple(PARAM_LIST_4X4, ADST_DCT, 12),
199 make_tuple(PARAM_LIST_4X4, DCT_ADST, 10),
200 make_tuple(PARAM_LIST_4X4, DCT_ADST, 12),
201 make_tuple(PARAM_LIST_4X4, ADST_ADST, 10),
202 make_tuple(PARAM_LIST_4X4, ADST_ADST, 12),
203#if CONFIG_EXT_TX
204 make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 10),
205 make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 12),
206 make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 10),
207 make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 12),
208 make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 10),
209 make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 12),
210 make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 10),
211 make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 12),
212 make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 10),
213 make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 12),
214#endif
Yi Luo28cdee42016-05-19 14:13:07 -0700215};
216
Yaowu Xuf883b422016-08-30 14:01:10 -0700217INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdInvHTNxN,
clang-format3a826f12016-08-11 17:46:05 -0700218 ::testing::ValuesIn(kArrayIhtParam));
Yaowu Xuf883b422016-08-30 14:01:10 -0700219#endif // HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH
Yi Luo28cdee42016-05-19 14:13:07 -0700220
Yi Luo3bd83772017-01-10 10:11:49 -0800221#if HAVE_AVX2 && CONFIG_AOM_HIGHBITDEPTH
222#define PARAM_LIST_32X32 \
223 &av1_fwd_txfm2d_32x32_c, &av1_inv_txfm2d_add_32x32_avx2, \
224 &av1_inv_txfm2d_add_32x32_c, 1024
225
226const IHbdHtParam kArrayIhtParam32x32[] = {
227 // 32x32
228 make_tuple(PARAM_LIST_32X32, DCT_DCT, 10),
229 make_tuple(PARAM_LIST_32X32, DCT_DCT, 12),
230};
231
232INSTANTIATE_TEST_CASE_P(AVX2, AV1HighbdInvHTNxN,
233 ::testing::ValuesIn(kArrayIhtParam32x32));
234
235#endif // HAVE_AVX2 && CONFIG_AOM_HIGHBITDEPTH
Yi Luo28cdee42016-05-19 14:13:07 -0700236} // namespace