blob: 7f077b657cd18c12ba5c624044897b942ee157a5 [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
Tom Finegan44702c82018-05-22 13:00:39 -070014#include "config/av1_rtcd.h"
15
Yi Luo28cdee42016-05-19 14:13:07 -070016#include "test/acm_random.h"
Venkatb01bfcf2018-08-20 16:07:05 +053017#include "test/av1_txfm_test.h"
Yi Luo28cdee42016-05-19 14:13:07 -070018#include "test/clear_system_state.h"
19#include "test/register_state_check.h"
20#include "test/util.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "av1/common/enums.h"
Venkatb01bfcf2018-08-20 16:07:05 +053022#include "av1/common/scan.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070023#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070024#include "aom_ports/mem.h"
Yi Luo28cdee42016-05-19 14:13:07 -070025
26namespace {
27
Yaowu Xuc27fc142016-08-22 16:08:15 -070028using libaom_test::ACMRandom;
Johann54fa62e2018-09-25 14:09:31 -070029using ::testing::tuple;
Yi Luo28cdee42016-05-19 14:13:07 -070030
31typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride,
Urvang Joshi2283d372017-10-02 17:16:45 -070032 TX_TYPE tx_type, int bd);
Yi Luo28cdee42016-05-19 14:13:07 -070033
34typedef void (*IHbdHtFunc)(const int32_t *coeff, uint16_t *output, int stride,
Urvang Joshi2283d372017-10-02 17:16:45 -070035 TX_TYPE tx_type, int bd);
Yi Luo28cdee42016-05-19 14:13:07 -070036
37// Test parameter argument list:
38// <transform reference function,
39// optimized inverse transform function,
40// inverse transform reference function,
41// num_coeffs,
42// tx_type,
43// bit_depth>
Urvang Joshi2283d372017-10-02 17:16:45 -070044typedef tuple<HbdHtFunc, IHbdHtFunc, IHbdHtFunc, int, TX_TYPE, int> IHbdHtParam;
Yi Luo28cdee42016-05-19 14:13:07 -070045
Yaowu Xuf883b422016-08-30 14:01:10 -070046class AV1HighbdInvHTNxN : public ::testing::TestWithParam<IHbdHtParam> {
Yi Luo28cdee42016-05-19 14:13:07 -070047 public:
Yaowu Xuf883b422016-08-30 14:01:10 -070048 virtual ~AV1HighbdInvHTNxN() {}
Yi Luo28cdee42016-05-19 14:13:07 -070049
50 virtual void SetUp() {
51 txfm_ref_ = GET_PARAM(0);
52 inv_txfm_ = GET_PARAM(1);
53 inv_txfm_ref_ = GET_PARAM(2);
54 num_coeffs_ = GET_PARAM(3);
55 tx_type_ = GET_PARAM(4);
56 bit_depth_ = GET_PARAM(5);
57
58 input_ = reinterpret_cast<int16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070059 aom_memalign(16, sizeof(input_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070060
61 // Note:
62 // Inverse transform input buffer is 32-byte aligned
Yaowu Xuc27fc142016-08-22 16:08:15 -070063 // Refer to <root>/av1/encoder/context_tree.c, function,
Yi Luo28cdee42016-05-19 14:13:07 -070064 // void alloc_mode_context().
65 coeffs_ = reinterpret_cast<int32_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070066 aom_memalign(32, sizeof(coeffs_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070067 output_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070068 aom_memalign(32, sizeof(output_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070069 output_ref_ = reinterpret_cast<uint16_t *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070070 aom_memalign(32, sizeof(output_ref_[0]) * num_coeffs_));
Yi Luo28cdee42016-05-19 14:13:07 -070071 }
72
73 virtual void TearDown() {
Yaowu Xuf883b422016-08-30 14:01:10 -070074 aom_free(input_);
75 aom_free(coeffs_);
76 aom_free(output_);
77 aom_free(output_ref_);
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 libaom_test::ClearSystemState();
Yi Luo28cdee42016-05-19 14:13:07 -070079 }
80
81 protected:
82 void RunBitexactCheck();
83
84 private:
85 int GetStride() const {
86 if (16 == num_coeffs_) {
87 return 4;
88 } else if (64 == num_coeffs_) {
89 return 8;
90 } else if (256 == num_coeffs_) {
91 return 16;
Yi Luo3bd83772017-01-10 10:11:49 -080092 } else if (1024 == num_coeffs_) {
93 return 32;
Frank Bossen5a06fe32018-01-23 22:02:54 -050094 } else if (4096 == num_coeffs_) {
95 return 64;
Yi Luo28cdee42016-05-19 14:13:07 -070096 } else {
97 return 0;
98 }
99 }
100
101 HbdHtFunc txfm_ref_;
102 IHbdHtFunc inv_txfm_;
103 IHbdHtFunc inv_txfm_ref_;
104 int num_coeffs_;
Urvang Joshi2283d372017-10-02 17:16:45 -0700105 TX_TYPE tx_type_;
Yi Luo28cdee42016-05-19 14:13:07 -0700106 int bit_depth_;
107
108 int16_t *input_;
109 int32_t *coeffs_;
110 uint16_t *output_;
111 uint16_t *output_ref_;
112};
113
Yaowu Xuf883b422016-08-30 14:01:10 -0700114void AV1HighbdInvHTNxN::RunBitexactCheck() {
Yi Luo28cdee42016-05-19 14:13:07 -0700115 ACMRandom rnd(ACMRandom::DeterministicSeed());
116 const int stride = GetStride();
117 const int num_tests = 20000;
118 const uint16_t mask = (1 << bit_depth_) - 1;
119
120 for (int i = 0; i < num_tests; ++i) {
121 for (int j = 0; j < num_coeffs_; ++j) {
122 input_[j] = (rnd.Rand16() & mask) - (rnd.Rand16() & mask);
123 output_ref_[j] = rnd.Rand16() & mask;
124 output_[j] = output_ref_[j];
125 }
126
127 txfm_ref_(input_, coeffs_, stride, tx_type_, bit_depth_);
128 inv_txfm_ref_(coeffs_, output_ref_, stride, tx_type_, bit_depth_);
clang-format3a826f12016-08-11 17:46:05 -0700129 ASM_REGISTER_STATE_CHECK(
130 inv_txfm_(coeffs_, output_, stride, tx_type_, bit_depth_));
Yi Luo28cdee42016-05-19 14:13:07 -0700131
132 for (int j = 0; j < num_coeffs_; ++j) {
133 EXPECT_EQ(output_ref_[j], output_[j])
clang-format3a826f12016-08-11 17:46:05 -0700134 << "Not bit-exact result at index: " << j << " At test block: " << i;
Yi Luo28cdee42016-05-19 14:13:07 -0700135 }
136 }
137}
138
Yaowu Xuf883b422016-08-30 14:01:10 -0700139TEST_P(AV1HighbdInvHTNxN, InvTransResultCheck) { RunBitexactCheck(); }
Yi Luo28cdee42016-05-19 14:13:07 -0700140
James Zern95612802018-03-30 11:37:54 -0700141using ::testing::make_tuple;
Yi Luo28cdee42016-05-19 14:13:07 -0700142
Sebastien Alaiwan58596362018-01-26 10:11:35 +0100143#if HAVE_SSE4_1
Yaowu Xuf883b422016-08-30 14:01:10 -0700144#define PARAM_LIST_4X4 \
145 &av1_fwd_txfm2d_4x4_c, &av1_inv_txfm2d_add_4x4_sse4_1, \
146 &av1_inv_txfm2d_add_4x4_c, 16
Frank Bossen5a06fe32018-01-23 22:02:54 -0500147
Yi Luo28cdee42016-05-19 14:13:07 -0700148const IHbdHtParam kArrayIhtParam[] = {
Sebastien Alaiwan58596362018-01-26 10:11:35 +0100149 // 4x4
Yi Luobfe4c0a2016-05-19 14:13:07 -0700150 make_tuple(PARAM_LIST_4X4, DCT_DCT, 10),
151 make_tuple(PARAM_LIST_4X4, DCT_DCT, 12),
152 make_tuple(PARAM_LIST_4X4, ADST_DCT, 10),
153 make_tuple(PARAM_LIST_4X4, ADST_DCT, 12),
154 make_tuple(PARAM_LIST_4X4, DCT_ADST, 10),
155 make_tuple(PARAM_LIST_4X4, DCT_ADST, 12),
156 make_tuple(PARAM_LIST_4X4, ADST_ADST, 10),
157 make_tuple(PARAM_LIST_4X4, ADST_ADST, 12),
Yi Luobfe4c0a2016-05-19 14:13:07 -0700158 make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 10),
159 make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 12),
160 make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 10),
161 make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 12),
162 make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 10),
163 make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 12),
164 make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 10),
165 make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 12),
166 make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 10),
167 make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 12),
Yi Luo28cdee42016-05-19 14:13:07 -0700168};
169
Yaowu Xuf883b422016-08-30 14:01:10 -0700170INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdInvHTNxN,
clang-format3a826f12016-08-11 17:46:05 -0700171 ::testing::ValuesIn(kArrayIhtParam));
Sebastien Alaiwan58596362018-01-26 10:11:35 +0100172#endif // HAVE_SSE4_1
Yi Luo28cdee42016-05-19 14:13:07 -0700173
Venkatb01bfcf2018-08-20 16:07:05 +0530174typedef void (*HighbdInvTxfm2dFunc)(const int32_t *input, uint8_t *output,
175 int stride, const TxfmParam *txfm_param);
176
177typedef ::testing::tuple<const HighbdInvTxfm2dFunc> AV1HighbdInvTxfm2dParam;
178class AV1HighbdInvTxfm2d
179 : public ::testing::TestWithParam<AV1HighbdInvTxfm2dParam> {
180 public:
181 virtual void SetUp() { target_func_ = GET_PARAM(0); }
182 void RunAV1InvTxfm2dTest(TX_TYPE tx_type, TX_SIZE tx_size, int run_times,
183 int bit_depth);
184
185 private:
186 HighbdInvTxfm2dFunc target_func_;
187};
188
189void AV1HighbdInvTxfm2d::RunAV1InvTxfm2dTest(TX_TYPE tx_type_, TX_SIZE tx_size_,
190 int run_times, int bit_depth_) {
191 FwdTxfm2dFunc fwd_func_ = libaom_test::fwd_txfm_func_ls[tx_size_];
192 TxfmParam txfm_param;
193 const int BLK_WIDTH = 64;
194 const int BLK_SIZE = BLK_WIDTH * BLK_WIDTH;
195 DECLARE_ALIGNED(16, int16_t, input[BLK_SIZE]) = { 0 };
196 DECLARE_ALIGNED(32, int32_t, inv_input[BLK_SIZE]) = { 0 };
197 DECLARE_ALIGNED(32, uint16_t, output[BLK_SIZE]) = { 0 };
198 DECLARE_ALIGNED(32, uint16_t, ref_output[BLK_SIZE]) = { 0 };
199 int stride = BLK_WIDTH;
200 int rows = tx_size_high[tx_size_];
201 int cols = tx_size_wide[tx_size_];
202 const int rows_nonezero = AOMMIN(32, rows);
203 const int cols_nonezero = AOMMIN(32, cols);
204 const uint16_t mask = (1 << bit_depth_) - 1;
205 run_times /= (rows * cols);
206 run_times = AOMMAX(1, run_times);
207 const SCAN_ORDER *scan_order = get_default_scan(tx_size_, tx_type_);
208 const int16_t *scan = scan_order->scan;
209 const int16_t eobmax = rows_nonezero * cols_nonezero;
210 ACMRandom rnd(ACMRandom::DeterministicSeed());
211 int randTimes = run_times == 1 ? (eobmax) : 1;
212
213 txfm_param.tx_type = tx_type_;
214 txfm_param.tx_size = tx_size_;
215 txfm_param.lossless = 0;
216 txfm_param.bd = bit_depth_;
217 txfm_param.is_hbd = 1;
218 txfm_param.tx_set_type = EXT_TX_SET_ALL16;
219
220 for (int cnt = 0; cnt < randTimes; ++cnt) {
221 for (int r = 0; r < BLK_WIDTH; ++r) {
222 for (int c = 0; c < BLK_WIDTH; ++c) {
223 input[r * cols + c] = (rnd.Rand16() & mask) - (rnd.Rand16() & mask);
224 output[r * stride + c] = rnd.Rand16() & mask;
225
226 ref_output[r * stride + c] = output[r * stride + c];
227 }
228 }
229 fwd_func_(input, inv_input, stride, tx_type_, bit_depth_);
230
231 // produce eob input by setting high freq coeffs to zero
232 const int eob = AOMMIN(cnt + 1, eobmax);
233 for (int i = eob; i < eobmax; i++) {
234 inv_input[scan[i]] = 0;
235 }
236 txfm_param.eob = eob;
237 aom_usec_timer ref_timer, test_timer;
238
239 aom_usec_timer_start(&ref_timer);
240 for (int i = 0; i < run_times; ++i) {
241 av1_highbd_inv_txfm_add_c(inv_input, CONVERT_TO_BYTEPTR(ref_output),
242 stride, &txfm_param);
243 }
244 aom_usec_timer_mark(&ref_timer);
245 const int elapsed_time_c =
246 static_cast<int>(aom_usec_timer_elapsed(&ref_timer));
247
248 aom_usec_timer_start(&test_timer);
249 for (int i = 0; i < run_times; ++i) {
250 target_func_(inv_input, CONVERT_TO_BYTEPTR(output), stride, &txfm_param);
251 }
252 aom_usec_timer_mark(&test_timer);
253 const int elapsed_time_simd =
254 static_cast<int>(aom_usec_timer_elapsed(&test_timer));
255 if (run_times > 10) {
256 printf(
257 "txfm_size[%d] \t txfm_type[%d] \t c_time=%d \t simd_time=%d \t "
258 "gain=%d \n",
259 tx_size_, tx_type_, elapsed_time_c, elapsed_time_simd,
260 (elapsed_time_c / elapsed_time_simd));
261 } else {
262 for (int r = 0; r < rows; ++r) {
263 for (int c = 0; c < cols; ++c) {
264 ASSERT_EQ(ref_output[r * stride + c], output[r * stride + c])
265 << "[" << r << "," << c << "] " << cnt
266 << " tx_size: " << static_cast<int>(tx_size_)
267 << " tx_type: " << tx_type_ << " eob " << eob;
268 }
269 }
270 }
271 }
272}
273
274TEST_P(AV1HighbdInvTxfm2d, match) {
275 int bitdepth_ar[2] = { 10, 12 };
276 for (int k = 0; k < 2; ++k) {
277 int bd = bitdepth_ar[k];
278 for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) {
279 for (int i = 0; i < (int)TX_TYPES; ++i) {
280 if (libaom_test::IsTxSizeTypeValid(static_cast<TX_SIZE>(j),
281 static_cast<TX_TYPE>(i))) {
282 RunAV1InvTxfm2dTest(static_cast<TX_TYPE>(i), static_cast<TX_SIZE>(j),
283 1, bd);
284 }
285 }
286 }
287 }
288}
289
290TEST_P(AV1HighbdInvTxfm2d, DISABLED_Speed) {
291 int bitdepth_ar[2] = { 10, 12 };
292 for (int k = 0; k < 2; ++k) {
293 int bd = bitdepth_ar[k];
294 for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) {
295 for (int i = 0; i < (int)TX_TYPES; ++i) {
296 if (libaom_test::IsTxSizeTypeValid(static_cast<TX_SIZE>(j),
297 static_cast<TX_TYPE>(i))) {
298 RunAV1InvTxfm2dTest(static_cast<TX_TYPE>(i), static_cast<TX_SIZE>(j),
299 1000000, bd);
300 }
301 }
302 }
303 }
304}
305
306#if HAVE_SSE4_1
307INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdInvTxfm2d,
308 ::testing::Values(av1_highbd_inv_txfm_add_sse4_1));
309#endif
310
311#if HAVE_AVX2
312INSTANTIATE_TEST_CASE_P(AVX2, AV1HighbdInvTxfm2d,
313 ::testing::Values(av1_highbd_inv_txfm_add_avx2));
314#endif
Yi Luo28cdee42016-05-19 14:13:07 -0700315} // namespace