1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <math.h>
13*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
14*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
15*77c1e3ccSAndroid Build Coastguard Worker #include <tuple>
16*77c1e3ccSAndroid Build Coastguard Worker #include <vector>
17*77c1e3ccSAndroid Build Coastguard Worker
18*77c1e3ccSAndroid Build Coastguard Worker #include "config/av1_rtcd.h"
19*77c1e3ccSAndroid Build Coastguard Worker
20*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "test/av1_txfm_test.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_txfm.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/hybrid_fwd_txfm.h"
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom;
27*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::bd;
28*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::compute_avg_abs_error;
29*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::input_base;
30*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::tx_type_name;
31*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::TYPE_TXFM;
32*77c1e3ccSAndroid Build Coastguard Worker
33*77c1e3ccSAndroid Build Coastguard Worker using std::vector;
34*77c1e3ccSAndroid Build Coastguard Worker
35*77c1e3ccSAndroid Build Coastguard Worker namespace {
36*77c1e3ccSAndroid Build Coastguard Worker // tx_type_, tx_size_, max_error_, max_avg_error_
37*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<TX_TYPE, TX_SIZE, double, double> AV1FwdTxfm2dParam;
38*77c1e3ccSAndroid Build Coastguard Worker
39*77c1e3ccSAndroid Build Coastguard Worker class AV1FwdTxfm2d : public ::testing::TestWithParam<AV1FwdTxfm2dParam> {
40*77c1e3ccSAndroid Build Coastguard Worker public:
SetUp()41*77c1e3ccSAndroid Build Coastguard Worker void SetUp() override {
42*77c1e3ccSAndroid Build Coastguard Worker tx_type_ = GET_PARAM(0);
43*77c1e3ccSAndroid Build Coastguard Worker tx_size_ = GET_PARAM(1);
44*77c1e3ccSAndroid Build Coastguard Worker max_error_ = GET_PARAM(2);
45*77c1e3ccSAndroid Build Coastguard Worker max_avg_error_ = GET_PARAM(3);
46*77c1e3ccSAndroid Build Coastguard Worker count_ = 500;
47*77c1e3ccSAndroid Build Coastguard Worker TXFM_2D_FLIP_CFG fwd_txfm_flip_cfg;
48*77c1e3ccSAndroid Build Coastguard Worker av1_get_fwd_txfm_cfg(tx_type_, tx_size_, &fwd_txfm_flip_cfg);
49*77c1e3ccSAndroid Build Coastguard Worker amplify_factor_ = libaom_test::get_amplification_factor(tx_type_, tx_size_);
50*77c1e3ccSAndroid Build Coastguard Worker tx_width_ = tx_size_wide[fwd_txfm_flip_cfg.tx_size];
51*77c1e3ccSAndroid Build Coastguard Worker tx_height_ = tx_size_high[fwd_txfm_flip_cfg.tx_size];
52*77c1e3ccSAndroid Build Coastguard Worker ud_flip_ = fwd_txfm_flip_cfg.ud_flip;
53*77c1e3ccSAndroid Build Coastguard Worker lr_flip_ = fwd_txfm_flip_cfg.lr_flip;
54*77c1e3ccSAndroid Build Coastguard Worker
55*77c1e3ccSAndroid Build Coastguard Worker fwd_txfm_ = libaom_test::fwd_txfm_func_ls[tx_size_];
56*77c1e3ccSAndroid Build Coastguard Worker txfm2d_size_ = tx_width_ * tx_height_;
57*77c1e3ccSAndroid Build Coastguard Worker input_ = reinterpret_cast<int16_t *>(
58*77c1e3ccSAndroid Build Coastguard Worker aom_memalign(16, sizeof(input_[0]) * txfm2d_size_));
59*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(input_, nullptr);
60*77c1e3ccSAndroid Build Coastguard Worker output_ = reinterpret_cast<int32_t *>(
61*77c1e3ccSAndroid Build Coastguard Worker aom_memalign(16, sizeof(output_[0]) * txfm2d_size_));
62*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(output_, nullptr);
63*77c1e3ccSAndroid Build Coastguard Worker ref_input_ = reinterpret_cast<double *>(
64*77c1e3ccSAndroid Build Coastguard Worker aom_memalign(16, sizeof(ref_input_[0]) * txfm2d_size_));
65*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(ref_input_, nullptr);
66*77c1e3ccSAndroid Build Coastguard Worker ref_output_ = reinterpret_cast<double *>(
67*77c1e3ccSAndroid Build Coastguard Worker aom_memalign(16, sizeof(ref_output_[0]) * txfm2d_size_));
68*77c1e3ccSAndroid Build Coastguard Worker ASSERT_NE(ref_output_, nullptr);
69*77c1e3ccSAndroid Build Coastguard Worker }
70*77c1e3ccSAndroid Build Coastguard Worker
RunFwdAccuracyCheck()71*77c1e3ccSAndroid Build Coastguard Worker void RunFwdAccuracyCheck() {
72*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd(ACMRandom::DeterministicSeed());
73*77c1e3ccSAndroid Build Coastguard Worker double avg_abs_error = 0;
74*77c1e3ccSAndroid Build Coastguard Worker for (int ci = 0; ci < count_; ci++) {
75*77c1e3ccSAndroid Build Coastguard Worker for (int ni = 0; ni < txfm2d_size_; ++ni) {
76*77c1e3ccSAndroid Build Coastguard Worker input_[ni] = rnd.Rand16() % input_base;
77*77c1e3ccSAndroid Build Coastguard Worker ref_input_[ni] = static_cast<double>(input_[ni]);
78*77c1e3ccSAndroid Build Coastguard Worker output_[ni] = 0;
79*77c1e3ccSAndroid Build Coastguard Worker ref_output_[ni] = 0;
80*77c1e3ccSAndroid Build Coastguard Worker }
81*77c1e3ccSAndroid Build Coastguard Worker
82*77c1e3ccSAndroid Build Coastguard Worker fwd_txfm_(input_, output_, tx_width_, tx_type_, bd);
83*77c1e3ccSAndroid Build Coastguard Worker
84*77c1e3ccSAndroid Build Coastguard Worker if (lr_flip_ && ud_flip_) {
85*77c1e3ccSAndroid Build Coastguard Worker libaom_test::fliplrud(ref_input_, tx_width_, tx_height_, tx_width_);
86*77c1e3ccSAndroid Build Coastguard Worker } else if (lr_flip_) {
87*77c1e3ccSAndroid Build Coastguard Worker libaom_test::fliplr(ref_input_, tx_width_, tx_height_, tx_width_);
88*77c1e3ccSAndroid Build Coastguard Worker } else if (ud_flip_) {
89*77c1e3ccSAndroid Build Coastguard Worker libaom_test::flipud(ref_input_, tx_width_, tx_height_, tx_width_);
90*77c1e3ccSAndroid Build Coastguard Worker }
91*77c1e3ccSAndroid Build Coastguard Worker
92*77c1e3ccSAndroid Build Coastguard Worker libaom_test::reference_hybrid_2d(ref_input_, ref_output_, tx_type_,
93*77c1e3ccSAndroid Build Coastguard Worker tx_size_);
94*77c1e3ccSAndroid Build Coastguard Worker
95*77c1e3ccSAndroid Build Coastguard Worker double actual_max_error = 0;
96*77c1e3ccSAndroid Build Coastguard Worker for (int ni = 0; ni < txfm2d_size_; ++ni) {
97*77c1e3ccSAndroid Build Coastguard Worker ref_output_[ni] = round(ref_output_[ni]);
98*77c1e3ccSAndroid Build Coastguard Worker const double this_error =
99*77c1e3ccSAndroid Build Coastguard Worker fabs(output_[ni] - ref_output_[ni]) / amplify_factor_;
100*77c1e3ccSAndroid Build Coastguard Worker actual_max_error = AOMMAX(actual_max_error, this_error);
101*77c1e3ccSAndroid Build Coastguard Worker }
102*77c1e3ccSAndroid Build Coastguard Worker EXPECT_GE(max_error_, actual_max_error)
103*77c1e3ccSAndroid Build Coastguard Worker << "tx_w: " << tx_width_ << " tx_h: " << tx_height_
104*77c1e3ccSAndroid Build Coastguard Worker << ", tx_type = " << (int)tx_type_;
105*77c1e3ccSAndroid Build Coastguard Worker if (actual_max_error > max_error_) { // exit early.
106*77c1e3ccSAndroid Build Coastguard Worker break;
107*77c1e3ccSAndroid Build Coastguard Worker }
108*77c1e3ccSAndroid Build Coastguard Worker
109*77c1e3ccSAndroid Build Coastguard Worker avg_abs_error += compute_avg_abs_error<int32_t, double>(
110*77c1e3ccSAndroid Build Coastguard Worker output_, ref_output_, txfm2d_size_);
111*77c1e3ccSAndroid Build Coastguard Worker }
112*77c1e3ccSAndroid Build Coastguard Worker
113*77c1e3ccSAndroid Build Coastguard Worker avg_abs_error /= amplify_factor_;
114*77c1e3ccSAndroid Build Coastguard Worker avg_abs_error /= count_;
115*77c1e3ccSAndroid Build Coastguard Worker EXPECT_GE(max_avg_error_, avg_abs_error)
116*77c1e3ccSAndroid Build Coastguard Worker << "tx_size = " << tx_size_ << ", tx_type = " << tx_type_;
117*77c1e3ccSAndroid Build Coastguard Worker }
118*77c1e3ccSAndroid Build Coastguard Worker
TearDown()119*77c1e3ccSAndroid Build Coastguard Worker void TearDown() override {
120*77c1e3ccSAndroid Build Coastguard Worker aom_free(input_);
121*77c1e3ccSAndroid Build Coastguard Worker aom_free(output_);
122*77c1e3ccSAndroid Build Coastguard Worker aom_free(ref_input_);
123*77c1e3ccSAndroid Build Coastguard Worker aom_free(ref_output_);
124*77c1e3ccSAndroid Build Coastguard Worker }
125*77c1e3ccSAndroid Build Coastguard Worker
126*77c1e3ccSAndroid Build Coastguard Worker private:
127*77c1e3ccSAndroid Build Coastguard Worker double max_error_;
128*77c1e3ccSAndroid Build Coastguard Worker double max_avg_error_;
129*77c1e3ccSAndroid Build Coastguard Worker int count_;
130*77c1e3ccSAndroid Build Coastguard Worker double amplify_factor_;
131*77c1e3ccSAndroid Build Coastguard Worker TX_TYPE tx_type_;
132*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size_;
133*77c1e3ccSAndroid Build Coastguard Worker int tx_width_;
134*77c1e3ccSAndroid Build Coastguard Worker int tx_height_;
135*77c1e3ccSAndroid Build Coastguard Worker int txfm2d_size_;
136*77c1e3ccSAndroid Build Coastguard Worker FwdTxfm2dFunc fwd_txfm_;
137*77c1e3ccSAndroid Build Coastguard Worker int16_t *input_;
138*77c1e3ccSAndroid Build Coastguard Worker int32_t *output_;
139*77c1e3ccSAndroid Build Coastguard Worker double *ref_input_;
140*77c1e3ccSAndroid Build Coastguard Worker double *ref_output_;
141*77c1e3ccSAndroid Build Coastguard Worker int ud_flip_; // flip upside down
142*77c1e3ccSAndroid Build Coastguard Worker int lr_flip_; // flip left to right
143*77c1e3ccSAndroid Build Coastguard Worker };
144*77c1e3ccSAndroid Build Coastguard Worker
145*77c1e3ccSAndroid Build Coastguard Worker static double avg_error_ls[TX_SIZES_ALL] = {
146*77c1e3ccSAndroid Build Coastguard Worker 0.5, // 4x4 transform
147*77c1e3ccSAndroid Build Coastguard Worker 0.5, // 8x8 transform
148*77c1e3ccSAndroid Build Coastguard Worker 1.2, // 16x16 transform
149*77c1e3ccSAndroid Build Coastguard Worker 6.1, // 32x32 transform
150*77c1e3ccSAndroid Build Coastguard Worker 3.4, // 64x64 transform
151*77c1e3ccSAndroid Build Coastguard Worker 0.57, // 4x8 transform
152*77c1e3ccSAndroid Build Coastguard Worker 0.68, // 8x4 transform
153*77c1e3ccSAndroid Build Coastguard Worker 0.92, // 8x16 transform
154*77c1e3ccSAndroid Build Coastguard Worker 1.1, // 16x8 transform
155*77c1e3ccSAndroid Build Coastguard Worker 4.1, // 16x32 transform
156*77c1e3ccSAndroid Build Coastguard Worker 6, // 32x16 transform
157*77c1e3ccSAndroid Build Coastguard Worker 3.5, // 32x64 transform
158*77c1e3ccSAndroid Build Coastguard Worker 5.7, // 64x32 transform
159*77c1e3ccSAndroid Build Coastguard Worker 0.6, // 4x16 transform
160*77c1e3ccSAndroid Build Coastguard Worker 0.9, // 16x4 transform
161*77c1e3ccSAndroid Build Coastguard Worker 1.2, // 8x32 transform
162*77c1e3ccSAndroid Build Coastguard Worker 1.7, // 32x8 transform
163*77c1e3ccSAndroid Build Coastguard Worker 2.0, // 16x64 transform
164*77c1e3ccSAndroid Build Coastguard Worker 4.7, // 64x16 transform
165*77c1e3ccSAndroid Build Coastguard Worker };
166*77c1e3ccSAndroid Build Coastguard Worker
167*77c1e3ccSAndroid Build Coastguard Worker static double max_error_ls[TX_SIZES_ALL] = {
168*77c1e3ccSAndroid Build Coastguard Worker 3, // 4x4 transform
169*77c1e3ccSAndroid Build Coastguard Worker 5, // 8x8 transform
170*77c1e3ccSAndroid Build Coastguard Worker 11, // 16x16 transform
171*77c1e3ccSAndroid Build Coastguard Worker 70, // 32x32 transform
172*77c1e3ccSAndroid Build Coastguard Worker 64, // 64x64 transform
173*77c1e3ccSAndroid Build Coastguard Worker 3.9, // 4x8 transform
174*77c1e3ccSAndroid Build Coastguard Worker 4.3, // 8x4 transform
175*77c1e3ccSAndroid Build Coastguard Worker 12, // 8x16 transform
176*77c1e3ccSAndroid Build Coastguard Worker 12, // 16x8 transform
177*77c1e3ccSAndroid Build Coastguard Worker 32, // 16x32 transform
178*77c1e3ccSAndroid Build Coastguard Worker 46, // 32x16 transform
179*77c1e3ccSAndroid Build Coastguard Worker 136, // 32x64 transform
180*77c1e3ccSAndroid Build Coastguard Worker 136, // 64x32 transform
181*77c1e3ccSAndroid Build Coastguard Worker 5, // 4x16 transform
182*77c1e3ccSAndroid Build Coastguard Worker 6, // 16x4 transform
183*77c1e3ccSAndroid Build Coastguard Worker 21, // 8x32 transform
184*77c1e3ccSAndroid Build Coastguard Worker 13, // 32x8 transform
185*77c1e3ccSAndroid Build Coastguard Worker 30, // 16x64 transform
186*77c1e3ccSAndroid Build Coastguard Worker 36, // 64x16 transform
187*77c1e3ccSAndroid Build Coastguard Worker };
188*77c1e3ccSAndroid Build Coastguard Worker
GetTxfm2dParamList()189*77c1e3ccSAndroid Build Coastguard Worker vector<AV1FwdTxfm2dParam> GetTxfm2dParamList() {
190*77c1e3ccSAndroid Build Coastguard Worker vector<AV1FwdTxfm2dParam> param_list;
191*77c1e3ccSAndroid Build Coastguard Worker for (int s = 0; s < TX_SIZES; ++s) {
192*77c1e3ccSAndroid Build Coastguard Worker const double max_error = max_error_ls[s];
193*77c1e3ccSAndroid Build Coastguard Worker const double avg_error = avg_error_ls[s];
194*77c1e3ccSAndroid Build Coastguard Worker for (int t = 0; t < TX_TYPES; ++t) {
195*77c1e3ccSAndroid Build Coastguard Worker const TX_TYPE tx_type = static_cast<TX_TYPE>(t);
196*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size = static_cast<TX_SIZE>(s);
197*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(tx_size, tx_type)) {
198*77c1e3ccSAndroid Build Coastguard Worker param_list.push_back(
199*77c1e3ccSAndroid Build Coastguard Worker AV1FwdTxfm2dParam(tx_type, tx_size, max_error, avg_error));
200*77c1e3ccSAndroid Build Coastguard Worker }
201*77c1e3ccSAndroid Build Coastguard Worker }
202*77c1e3ccSAndroid Build Coastguard Worker }
203*77c1e3ccSAndroid Build Coastguard Worker return param_list;
204*77c1e3ccSAndroid Build Coastguard Worker }
205*77c1e3ccSAndroid Build Coastguard Worker
206*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(C, AV1FwdTxfm2d,
207*77c1e3ccSAndroid Build Coastguard Worker ::testing::ValuesIn(GetTxfm2dParamList()));
208*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1FwdTxfm2d,RunFwdAccuracyCheck)209*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1FwdTxfm2d, RunFwdAccuracyCheck) { RunFwdAccuracyCheck(); }
210*77c1e3ccSAndroid Build Coastguard Worker
TEST(AV1FwdTxfm2d,CfgTest)211*77c1e3ccSAndroid Build Coastguard Worker TEST(AV1FwdTxfm2d, CfgTest) {
212*77c1e3ccSAndroid Build Coastguard Worker for (int bd_idx = 0; bd_idx < BD_NUM; ++bd_idx) {
213*77c1e3ccSAndroid Build Coastguard Worker int bd = libaom_test::bd_arr[bd_idx];
214*77c1e3ccSAndroid Build Coastguard Worker int8_t low_range = libaom_test::low_range_arr[bd_idx];
215*77c1e3ccSAndroid Build Coastguard Worker int8_t high_range = libaom_test::high_range_arr[bd_idx];
216*77c1e3ccSAndroid Build Coastguard Worker for (int tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
217*77c1e3ccSAndroid Build Coastguard Worker for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
218*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(static_cast<TX_SIZE>(tx_size),
219*77c1e3ccSAndroid Build Coastguard Worker static_cast<TX_TYPE>(tx_type)) ==
220*77c1e3ccSAndroid Build Coastguard Worker false) {
221*77c1e3ccSAndroid Build Coastguard Worker continue;
222*77c1e3ccSAndroid Build Coastguard Worker }
223*77c1e3ccSAndroid Build Coastguard Worker TXFM_2D_FLIP_CFG cfg;
224*77c1e3ccSAndroid Build Coastguard Worker av1_get_fwd_txfm_cfg(static_cast<TX_TYPE>(tx_type),
225*77c1e3ccSAndroid Build Coastguard Worker static_cast<TX_SIZE>(tx_size), &cfg);
226*77c1e3ccSAndroid Build Coastguard Worker int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
227*77c1e3ccSAndroid Build Coastguard Worker int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
228*77c1e3ccSAndroid Build Coastguard Worker av1_gen_fwd_stage_range(stage_range_col, stage_range_row, &cfg, bd);
229*77c1e3ccSAndroid Build Coastguard Worker libaom_test::txfm_stage_range_check(stage_range_col, cfg.stage_num_col,
230*77c1e3ccSAndroid Build Coastguard Worker cfg.cos_bit_col, low_range,
231*77c1e3ccSAndroid Build Coastguard Worker high_range);
232*77c1e3ccSAndroid Build Coastguard Worker libaom_test::txfm_stage_range_check(stage_range_row, cfg.stage_num_row,
233*77c1e3ccSAndroid Build Coastguard Worker cfg.cos_bit_row, low_range,
234*77c1e3ccSAndroid Build Coastguard Worker high_range);
235*77c1e3ccSAndroid Build Coastguard Worker }
236*77c1e3ccSAndroid Build Coastguard Worker }
237*77c1e3ccSAndroid Build Coastguard Worker }
238*77c1e3ccSAndroid Build Coastguard Worker }
239*77c1e3ccSAndroid Build Coastguard Worker
240*77c1e3ccSAndroid Build Coastguard Worker typedef void (*lowbd_fwd_txfm_func)(const int16_t *src_diff, tran_low_t *coeff,
241*77c1e3ccSAndroid Build Coastguard Worker int diff_stride, TxfmParam *txfm_param);
242*77c1e3ccSAndroid Build Coastguard Worker
AV1FwdTxfm2dMatchTest(TX_SIZE tx_size,lowbd_fwd_txfm_func target_func)243*77c1e3ccSAndroid Build Coastguard Worker void AV1FwdTxfm2dMatchTest(TX_SIZE tx_size, lowbd_fwd_txfm_func target_func) {
244*77c1e3ccSAndroid Build Coastguard Worker const int bd = 8;
245*77c1e3ccSAndroid Build Coastguard Worker TxfmParam param;
246*77c1e3ccSAndroid Build Coastguard Worker memset(¶m, 0, sizeof(param));
247*77c1e3ccSAndroid Build Coastguard Worker const int rows = tx_size_high[tx_size];
248*77c1e3ccSAndroid Build Coastguard Worker const int cols = tx_size_wide[tx_size];
249*77c1e3ccSAndroid Build Coastguard Worker // printf("%d x %d\n", cols, rows);
250*77c1e3ccSAndroid Build Coastguard Worker for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
251*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(
252*77c1e3ccSAndroid Build Coastguard Worker tx_size, static_cast<TX_TYPE>(tx_type)) == false) {
253*77c1e3ccSAndroid Build Coastguard Worker continue;
254*77c1e3ccSAndroid Build Coastguard Worker }
255*77c1e3ccSAndroid Build Coastguard Worker
256*77c1e3ccSAndroid Build Coastguard Worker FwdTxfm2dFunc ref_func = libaom_test::fwd_txfm_func_ls[tx_size];
257*77c1e3ccSAndroid Build Coastguard Worker if (ref_func != nullptr) {
258*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, input[64 * 64]) = { 0 };
259*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, output[64 * 64]);
260*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, ref_output[64 * 64]);
261*77c1e3ccSAndroid Build Coastguard Worker int input_stride = 64;
262*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd(ACMRandom::DeterministicSeed());
263*77c1e3ccSAndroid Build Coastguard Worker for (int cnt = 0; cnt < 500; ++cnt) {
264*77c1e3ccSAndroid Build Coastguard Worker if (cnt == 0) {
265*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
266*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
267*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = (1 << bd) - 1;
268*77c1e3ccSAndroid Build Coastguard Worker }
269*77c1e3ccSAndroid Build Coastguard Worker }
270*77c1e3ccSAndroid Build Coastguard Worker } else {
271*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
272*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
273*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = rnd.Rand16() % (1 << bd);
274*77c1e3ccSAndroid Build Coastguard Worker }
275*77c1e3ccSAndroid Build Coastguard Worker }
276*77c1e3ccSAndroid Build Coastguard Worker }
277*77c1e3ccSAndroid Build Coastguard Worker param.tx_type = (TX_TYPE)tx_type;
278*77c1e3ccSAndroid Build Coastguard Worker param.tx_size = (TX_SIZE)tx_size;
279*77c1e3ccSAndroid Build Coastguard Worker param.tx_set_type = EXT_TX_SET_ALL16;
280*77c1e3ccSAndroid Build Coastguard Worker param.bd = bd;
281*77c1e3ccSAndroid Build Coastguard Worker ref_func(input, ref_output, input_stride, (TX_TYPE)tx_type, bd);
282*77c1e3ccSAndroid Build Coastguard Worker target_func(input, output, input_stride, ¶m);
283*77c1e3ccSAndroid Build Coastguard Worker const int check_cols = AOMMIN(32, cols);
284*77c1e3ccSAndroid Build Coastguard Worker const int check_rows = AOMMIN(32, rows * cols / check_cols);
285*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < check_rows; ++r) {
286*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < check_cols; ++c) {
287*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(ref_output[r * check_cols + c],
288*77c1e3ccSAndroid Build Coastguard Worker output[r * check_cols + c])
289*77c1e3ccSAndroid Build Coastguard Worker << "[" << r << "," << c << "] cnt:" << cnt
290*77c1e3ccSAndroid Build Coastguard Worker << " tx_size: " << cols << "x" << rows
291*77c1e3ccSAndroid Build Coastguard Worker << " tx_type: " << tx_type_name[tx_type];
292*77c1e3ccSAndroid Build Coastguard Worker }
293*77c1e3ccSAndroid Build Coastguard Worker }
294*77c1e3ccSAndroid Build Coastguard Worker }
295*77c1e3ccSAndroid Build Coastguard Worker }
296*77c1e3ccSAndroid Build Coastguard Worker }
297*77c1e3ccSAndroid Build Coastguard Worker }
298*77c1e3ccSAndroid Build Coastguard Worker
AV1FwdTxfm2dSpeedTest(TX_SIZE tx_size,lowbd_fwd_txfm_func target_func)299*77c1e3ccSAndroid Build Coastguard Worker void AV1FwdTxfm2dSpeedTest(TX_SIZE tx_size, lowbd_fwd_txfm_func target_func) {
300*77c1e3ccSAndroid Build Coastguard Worker TxfmParam param;
301*77c1e3ccSAndroid Build Coastguard Worker memset(¶m, 0, sizeof(param));
302*77c1e3ccSAndroid Build Coastguard Worker const int rows = tx_size_high[tx_size];
303*77c1e3ccSAndroid Build Coastguard Worker const int cols = tx_size_wide[tx_size];
304*77c1e3ccSAndroid Build Coastguard Worker const int num_loops = 1000000 / (rows * cols);
305*77c1e3ccSAndroid Build Coastguard Worker
306*77c1e3ccSAndroid Build Coastguard Worker const int bd = 8;
307*77c1e3ccSAndroid Build Coastguard Worker for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
308*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(
309*77c1e3ccSAndroid Build Coastguard Worker tx_size, static_cast<TX_TYPE>(tx_type)) == false) {
310*77c1e3ccSAndroid Build Coastguard Worker continue;
311*77c1e3ccSAndroid Build Coastguard Worker }
312*77c1e3ccSAndroid Build Coastguard Worker
313*77c1e3ccSAndroid Build Coastguard Worker FwdTxfm2dFunc ref_func = libaom_test::fwd_txfm_func_ls[tx_size];
314*77c1e3ccSAndroid Build Coastguard Worker if (ref_func != nullptr) {
315*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, input[64 * 64]) = { 0 };
316*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, output[64 * 64]);
317*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, ref_output[64 * 64]);
318*77c1e3ccSAndroid Build Coastguard Worker int input_stride = 64;
319*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd(ACMRandom::DeterministicSeed());
320*77c1e3ccSAndroid Build Coastguard Worker
321*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
322*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
323*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = rnd.Rand16() % (1 << bd);
324*77c1e3ccSAndroid Build Coastguard Worker }
325*77c1e3ccSAndroid Build Coastguard Worker }
326*77c1e3ccSAndroid Build Coastguard Worker
327*77c1e3ccSAndroid Build Coastguard Worker param.tx_type = (TX_TYPE)tx_type;
328*77c1e3ccSAndroid Build Coastguard Worker param.tx_size = (TX_SIZE)tx_size;
329*77c1e3ccSAndroid Build Coastguard Worker param.tx_set_type = EXT_TX_SET_ALL16;
330*77c1e3ccSAndroid Build Coastguard Worker param.bd = bd;
331*77c1e3ccSAndroid Build Coastguard Worker
332*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer ref_timer, test_timer;
333*77c1e3ccSAndroid Build Coastguard Worker
334*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&ref_timer);
335*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < num_loops; ++i) {
336*77c1e3ccSAndroid Build Coastguard Worker ref_func(input, ref_output, input_stride, (TX_TYPE)tx_type, bd);
337*77c1e3ccSAndroid Build Coastguard Worker }
338*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&ref_timer);
339*77c1e3ccSAndroid Build Coastguard Worker const int elapsed_time_c =
340*77c1e3ccSAndroid Build Coastguard Worker static_cast<int>(aom_usec_timer_elapsed(&ref_timer));
341*77c1e3ccSAndroid Build Coastguard Worker
342*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&test_timer);
343*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < num_loops; ++i) {
344*77c1e3ccSAndroid Build Coastguard Worker target_func(input, output, input_stride, ¶m);
345*77c1e3ccSAndroid Build Coastguard Worker }
346*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&test_timer);
347*77c1e3ccSAndroid Build Coastguard Worker const int elapsed_time_simd =
348*77c1e3ccSAndroid Build Coastguard Worker static_cast<int>(aom_usec_timer_elapsed(&test_timer));
349*77c1e3ccSAndroid Build Coastguard Worker
350*77c1e3ccSAndroid Build Coastguard Worker printf(
351*77c1e3ccSAndroid Build Coastguard Worker "txfm_size[%2dx%-2d] \t txfm_type[%d] \t c_time=%d \t"
352*77c1e3ccSAndroid Build Coastguard Worker "simd_time=%d \t gain=%d \n",
353*77c1e3ccSAndroid Build Coastguard Worker rows, cols, tx_type, elapsed_time_c, elapsed_time_simd,
354*77c1e3ccSAndroid Build Coastguard Worker (elapsed_time_c / elapsed_time_simd));
355*77c1e3ccSAndroid Build Coastguard Worker }
356*77c1e3ccSAndroid Build Coastguard Worker }
357*77c1e3ccSAndroid Build Coastguard Worker }
358*77c1e3ccSAndroid Build Coastguard Worker
359*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<TX_SIZE, lowbd_fwd_txfm_func> LbdFwdTxfm2dParam;
360*77c1e3ccSAndroid Build Coastguard Worker
361*77c1e3ccSAndroid Build Coastguard Worker class AV1FwdTxfm2dTest : public ::testing::TestWithParam<LbdFwdTxfm2dParam> {};
362*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1FwdTxfm2dTest);
363*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1FwdTxfm2dTest,match)364*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1FwdTxfm2dTest, match) {
365*77c1e3ccSAndroid Build Coastguard Worker AV1FwdTxfm2dMatchTest(GET_PARAM(0), GET_PARAM(1));
366*77c1e3ccSAndroid Build Coastguard Worker }
TEST_P(AV1FwdTxfm2dTest,DISABLED_Speed)367*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1FwdTxfm2dTest, DISABLED_Speed) {
368*77c1e3ccSAndroid Build Coastguard Worker AV1FwdTxfm2dSpeedTest(GET_PARAM(0), GET_PARAM(1));
369*77c1e3ccSAndroid Build Coastguard Worker }
TEST(AV1FwdTxfm2dTest,DCTScaleTest)370*77c1e3ccSAndroid Build Coastguard Worker TEST(AV1FwdTxfm2dTest, DCTScaleTest) {
371*77c1e3ccSAndroid Build Coastguard Worker BitDepthInfo bd_info;
372*77c1e3ccSAndroid Build Coastguard Worker bd_info.bit_depth = 8;
373*77c1e3ccSAndroid Build Coastguard Worker bd_info.use_highbitdepth_buf = 0;
374*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, src_diff[1024]);
375*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, tran_low_t, coeff[1024]);
376*77c1e3ccSAndroid Build Coastguard Worker
377*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size_list[4] = { TX_4X4, TX_8X8, TX_16X16, TX_32X32 };
378*77c1e3ccSAndroid Build Coastguard Worker const int stride_list[4] = { 4, 8, 16, 32 };
379*77c1e3ccSAndroid Build Coastguard Worker const int ref_scale_list[4] = { 64, 64, 64, 16 };
380*77c1e3ccSAndroid Build Coastguard Worker
381*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++) {
382*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size = tx_size_list[i];
383*77c1e3ccSAndroid Build Coastguard Worker int stride = stride_list[i];
384*77c1e3ccSAndroid Build Coastguard Worker int array_size = stride * stride;
385*77c1e3ccSAndroid Build Coastguard Worker
386*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < array_size; j++) {
387*77c1e3ccSAndroid Build Coastguard Worker src_diff[j] = 8;
388*77c1e3ccSAndroid Build Coastguard Worker coeff[j] = 0;
389*77c1e3ccSAndroid Build Coastguard Worker }
390*77c1e3ccSAndroid Build Coastguard Worker
391*77c1e3ccSAndroid Build Coastguard Worker av1_quick_txfm(/*use_hadamard=*/0, tx_size, bd_info, src_diff, stride,
392*77c1e3ccSAndroid Build Coastguard Worker coeff);
393*77c1e3ccSAndroid Build Coastguard Worker
394*77c1e3ccSAndroid Build Coastguard Worker double input_sse = 0;
395*77c1e3ccSAndroid Build Coastguard Worker double output_sse = 0;
396*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < array_size; j++) {
397*77c1e3ccSAndroid Build Coastguard Worker input_sse += pow(src_diff[j], 2);
398*77c1e3ccSAndroid Build Coastguard Worker output_sse += pow(coeff[j], 2);
399*77c1e3ccSAndroid Build Coastguard Worker }
400*77c1e3ccSAndroid Build Coastguard Worker
401*77c1e3ccSAndroid Build Coastguard Worker double scale = output_sse / input_sse;
402*77c1e3ccSAndroid Build Coastguard Worker
403*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NEAR(scale, ref_scale_list[i], 5);
404*77c1e3ccSAndroid Build Coastguard Worker }
405*77c1e3ccSAndroid Build Coastguard Worker }
TEST(AV1FwdTxfm2dTest,HadamardScaleTest)406*77c1e3ccSAndroid Build Coastguard Worker TEST(AV1FwdTxfm2dTest, HadamardScaleTest) {
407*77c1e3ccSAndroid Build Coastguard Worker BitDepthInfo bd_info;
408*77c1e3ccSAndroid Build Coastguard Worker bd_info.bit_depth = 8;
409*77c1e3ccSAndroid Build Coastguard Worker bd_info.use_highbitdepth_buf = 0;
410*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, src_diff[1024]);
411*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, tran_low_t, coeff[1024]);
412*77c1e3ccSAndroid Build Coastguard Worker
413*77c1e3ccSAndroid Build Coastguard Worker const TX_SIZE tx_size_list[4] = { TX_4X4, TX_8X8, TX_16X16, TX_32X32 };
414*77c1e3ccSAndroid Build Coastguard Worker const int stride_list[4] = { 4, 8, 16, 32 };
415*77c1e3ccSAndroid Build Coastguard Worker const int ref_scale_list[4] = { 1, 64, 64, 16 };
416*77c1e3ccSAndroid Build Coastguard Worker
417*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 4; i++) {
418*77c1e3ccSAndroid Build Coastguard Worker TX_SIZE tx_size = tx_size_list[i];
419*77c1e3ccSAndroid Build Coastguard Worker int stride = stride_list[i];
420*77c1e3ccSAndroid Build Coastguard Worker int array_size = stride * stride;
421*77c1e3ccSAndroid Build Coastguard Worker
422*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < array_size; j++) {
423*77c1e3ccSAndroid Build Coastguard Worker src_diff[j] = 8;
424*77c1e3ccSAndroid Build Coastguard Worker coeff[j] = 0;
425*77c1e3ccSAndroid Build Coastguard Worker }
426*77c1e3ccSAndroid Build Coastguard Worker
427*77c1e3ccSAndroid Build Coastguard Worker av1_quick_txfm(/*use_hadamard=*/1, tx_size, bd_info, src_diff, stride,
428*77c1e3ccSAndroid Build Coastguard Worker coeff);
429*77c1e3ccSAndroid Build Coastguard Worker
430*77c1e3ccSAndroid Build Coastguard Worker double input_sse = 0;
431*77c1e3ccSAndroid Build Coastguard Worker double output_sse = 0;
432*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < array_size; j++) {
433*77c1e3ccSAndroid Build Coastguard Worker input_sse += pow(src_diff[j], 2);
434*77c1e3ccSAndroid Build Coastguard Worker output_sse += pow(coeff[j], 2);
435*77c1e3ccSAndroid Build Coastguard Worker }
436*77c1e3ccSAndroid Build Coastguard Worker
437*77c1e3ccSAndroid Build Coastguard Worker double scale = output_sse / input_sse;
438*77c1e3ccSAndroid Build Coastguard Worker
439*77c1e3ccSAndroid Build Coastguard Worker EXPECT_NEAR(scale, ref_scale_list[i], 5);
440*77c1e3ccSAndroid Build Coastguard Worker }
441*77c1e3ccSAndroid Build Coastguard Worker }
442*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Combine;
443*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Values;
444*77c1e3ccSAndroid Build Coastguard Worker using ::testing::ValuesIn;
445*77c1e3ccSAndroid Build Coastguard Worker
446*77c1e3ccSAndroid Build Coastguard Worker #if AOM_ARCH_X86 && HAVE_SSE2
447*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE fwd_txfm_for_sse2[] = {
448*77c1e3ccSAndroid Build Coastguard Worker TX_4X4,
449*77c1e3ccSAndroid Build Coastguard Worker TX_8X8,
450*77c1e3ccSAndroid Build Coastguard Worker TX_16X16,
451*77c1e3ccSAndroid Build Coastguard Worker TX_32X32,
452*77c1e3ccSAndroid Build Coastguard Worker // TX_64X64,
453*77c1e3ccSAndroid Build Coastguard Worker TX_4X8,
454*77c1e3ccSAndroid Build Coastguard Worker TX_8X4,
455*77c1e3ccSAndroid Build Coastguard Worker TX_8X16,
456*77c1e3ccSAndroid Build Coastguard Worker TX_16X8,
457*77c1e3ccSAndroid Build Coastguard Worker TX_16X32,
458*77c1e3ccSAndroid Build Coastguard Worker TX_32X16,
459*77c1e3ccSAndroid Build Coastguard Worker // TX_32X64,
460*77c1e3ccSAndroid Build Coastguard Worker // TX_64X32,
461*77c1e3ccSAndroid Build Coastguard Worker TX_4X16,
462*77c1e3ccSAndroid Build Coastguard Worker TX_16X4,
463*77c1e3ccSAndroid Build Coastguard Worker TX_8X32,
464*77c1e3ccSAndroid Build Coastguard Worker TX_32X8,
465*77c1e3ccSAndroid Build Coastguard Worker TX_16X64,
466*77c1e3ccSAndroid Build Coastguard Worker TX_64X16,
467*77c1e3ccSAndroid Build Coastguard Worker };
468*77c1e3ccSAndroid Build Coastguard Worker
469*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSE2, AV1FwdTxfm2dTest,
470*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(fwd_txfm_for_sse2),
471*77c1e3ccSAndroid Build Coastguard Worker Values(av1_lowbd_fwd_txfm_sse2)));
472*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_ARCH_X86 && HAVE_SSE2
473*77c1e3ccSAndroid Build Coastguard Worker
474*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE4_1
475*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE fwd_txfm_for_sse41[] = { TX_4X4, TX_8X8, TX_16X16, TX_32X32,
476*77c1e3ccSAndroid Build Coastguard Worker TX_64X64, TX_4X8, TX_8X4, TX_8X16,
477*77c1e3ccSAndroid Build Coastguard Worker TX_16X8, TX_16X32, TX_32X16, TX_32X64,
478*77c1e3ccSAndroid Build Coastguard Worker TX_64X32, TX_4X16, TX_16X4, TX_8X32,
479*77c1e3ccSAndroid Build Coastguard Worker TX_32X8, TX_16X64, TX_64X16 };
480*77c1e3ccSAndroid Build Coastguard Worker
481*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSE4_1, AV1FwdTxfm2dTest,
482*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(fwd_txfm_for_sse41),
483*77c1e3ccSAndroid Build Coastguard Worker Values(av1_lowbd_fwd_txfm_sse4_1)));
484*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_SSE4_1
485*77c1e3ccSAndroid Build Coastguard Worker
486*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
487*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE fwd_txfm_for_avx2[] = {
488*77c1e3ccSAndroid Build Coastguard Worker TX_4X4, TX_8X8, TX_16X16, TX_32X32, TX_64X64, TX_4X8, TX_8X4,
489*77c1e3ccSAndroid Build Coastguard Worker TX_8X16, TX_16X8, TX_16X32, TX_32X16, TX_32X64, TX_64X32, TX_4X16,
490*77c1e3ccSAndroid Build Coastguard Worker TX_16X4, TX_8X32, TX_32X8, TX_16X64, TX_64X16,
491*77c1e3ccSAndroid Build Coastguard Worker };
492*77c1e3ccSAndroid Build Coastguard Worker
493*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(AVX2, AV1FwdTxfm2dTest,
494*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(fwd_txfm_for_avx2),
495*77c1e3ccSAndroid Build Coastguard Worker Values(av1_lowbd_fwd_txfm_avx2)));
496*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_AVX2
497*77c1e3ccSAndroid Build Coastguard Worker
498*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
499*77c1e3ccSAndroid Build Coastguard Worker
500*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE fwd_txfm_for_neon[] = { TX_4X4, TX_8X8, TX_16X16, TX_32X32,
501*77c1e3ccSAndroid Build Coastguard Worker TX_64X64, TX_4X8, TX_8X4, TX_8X16,
502*77c1e3ccSAndroid Build Coastguard Worker TX_16X8, TX_16X32, TX_32X16, TX_32X64,
503*77c1e3ccSAndroid Build Coastguard Worker TX_64X32, TX_4X16, TX_16X4, TX_8X32,
504*77c1e3ccSAndroid Build Coastguard Worker TX_32X8, TX_16X64, TX_64X16 };
505*77c1e3ccSAndroid Build Coastguard Worker
506*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(NEON, AV1FwdTxfm2dTest,
507*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(fwd_txfm_for_neon),
508*77c1e3ccSAndroid Build Coastguard Worker Values(av1_lowbd_fwd_txfm_neon)));
509*77c1e3ccSAndroid Build Coastguard Worker
510*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_NEON
511*77c1e3ccSAndroid Build Coastguard Worker
512*77c1e3ccSAndroid Build Coastguard Worker typedef void (*Highbd_fwd_txfm_func)(const int16_t *src_diff, tran_low_t *coeff,
513*77c1e3ccSAndroid Build Coastguard Worker int diff_stride, TxfmParam *txfm_param);
514*77c1e3ccSAndroid Build Coastguard Worker
AV1HighbdFwdTxfm2dMatchTest(TX_SIZE tx_size,Highbd_fwd_txfm_func target_func)515*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdFwdTxfm2dMatchTest(TX_SIZE tx_size,
516*77c1e3ccSAndroid Build Coastguard Worker Highbd_fwd_txfm_func target_func) {
517*77c1e3ccSAndroid Build Coastguard Worker const int bd_ar[2] = { 10, 12 };
518*77c1e3ccSAndroid Build Coastguard Worker TxfmParam param;
519*77c1e3ccSAndroid Build Coastguard Worker memset(¶m, 0, sizeof(param));
520*77c1e3ccSAndroid Build Coastguard Worker const int rows = tx_size_high[tx_size];
521*77c1e3ccSAndroid Build Coastguard Worker const int cols = tx_size_wide[tx_size];
522*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 2; ++i) {
523*77c1e3ccSAndroid Build Coastguard Worker const int bd = bd_ar[i];
524*77c1e3ccSAndroid Build Coastguard Worker for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
525*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(
526*77c1e3ccSAndroid Build Coastguard Worker tx_size, static_cast<TX_TYPE>(tx_type)) == false) {
527*77c1e3ccSAndroid Build Coastguard Worker continue;
528*77c1e3ccSAndroid Build Coastguard Worker }
529*77c1e3ccSAndroid Build Coastguard Worker
530*77c1e3ccSAndroid Build Coastguard Worker FwdTxfm2dFunc ref_func = libaom_test::fwd_txfm_func_ls[tx_size];
531*77c1e3ccSAndroid Build Coastguard Worker if (ref_func != nullptr) {
532*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, input[64 * 64]) = { 0 };
533*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, output[64 * 64]);
534*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, ref_output[64 * 64]);
535*77c1e3ccSAndroid Build Coastguard Worker int input_stride = 64;
536*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd(ACMRandom::DeterministicSeed());
537*77c1e3ccSAndroid Build Coastguard Worker for (int cnt = 0; cnt < 500; ++cnt) {
538*77c1e3ccSAndroid Build Coastguard Worker if (cnt == 0) {
539*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
540*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
541*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = (1 << bd) - 1;
542*77c1e3ccSAndroid Build Coastguard Worker }
543*77c1e3ccSAndroid Build Coastguard Worker }
544*77c1e3ccSAndroid Build Coastguard Worker } else {
545*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
546*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
547*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = rnd.Rand16() % (1 << bd);
548*77c1e3ccSAndroid Build Coastguard Worker }
549*77c1e3ccSAndroid Build Coastguard Worker }
550*77c1e3ccSAndroid Build Coastguard Worker }
551*77c1e3ccSAndroid Build Coastguard Worker param.tx_type = (TX_TYPE)tx_type;
552*77c1e3ccSAndroid Build Coastguard Worker param.tx_size = (TX_SIZE)tx_size;
553*77c1e3ccSAndroid Build Coastguard Worker param.tx_set_type = EXT_TX_SET_ALL16;
554*77c1e3ccSAndroid Build Coastguard Worker param.bd = bd;
555*77c1e3ccSAndroid Build Coastguard Worker
556*77c1e3ccSAndroid Build Coastguard Worker ref_func(input, ref_output, input_stride, (TX_TYPE)tx_type, bd);
557*77c1e3ccSAndroid Build Coastguard Worker target_func(input, output, input_stride, ¶m);
558*77c1e3ccSAndroid Build Coastguard Worker const int check_cols = AOMMIN(32, cols);
559*77c1e3ccSAndroid Build Coastguard Worker const int check_rows = AOMMIN(32, rows * cols / check_cols);
560*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < check_rows; ++r) {
561*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < check_cols; ++c) {
562*77c1e3ccSAndroid Build Coastguard Worker ASSERT_EQ(ref_output[c * check_rows + r],
563*77c1e3ccSAndroid Build Coastguard Worker output[c * check_rows + r])
564*77c1e3ccSAndroid Build Coastguard Worker << "[" << r << "," << c << "] cnt:" << cnt
565*77c1e3ccSAndroid Build Coastguard Worker << " tx_size: " << cols << "x" << rows
566*77c1e3ccSAndroid Build Coastguard Worker << " tx_type: " << tx_type;
567*77c1e3ccSAndroid Build Coastguard Worker }
568*77c1e3ccSAndroid Build Coastguard Worker }
569*77c1e3ccSAndroid Build Coastguard Worker }
570*77c1e3ccSAndroid Build Coastguard Worker }
571*77c1e3ccSAndroid Build Coastguard Worker }
572*77c1e3ccSAndroid Build Coastguard Worker }
573*77c1e3ccSAndroid Build Coastguard Worker }
574*77c1e3ccSAndroid Build Coastguard Worker
AV1HighbdFwdTxfm2dSpeedTest(TX_SIZE tx_size,Highbd_fwd_txfm_func target_func)575*77c1e3ccSAndroid Build Coastguard Worker void AV1HighbdFwdTxfm2dSpeedTest(TX_SIZE tx_size,
576*77c1e3ccSAndroid Build Coastguard Worker Highbd_fwd_txfm_func target_func) {
577*77c1e3ccSAndroid Build Coastguard Worker const int bd_ar[2] = { 10, 12 };
578*77c1e3ccSAndroid Build Coastguard Worker TxfmParam param;
579*77c1e3ccSAndroid Build Coastguard Worker memset(¶m, 0, sizeof(param));
580*77c1e3ccSAndroid Build Coastguard Worker const int rows = tx_size_high[tx_size];
581*77c1e3ccSAndroid Build Coastguard Worker const int cols = tx_size_wide[tx_size];
582*77c1e3ccSAndroid Build Coastguard Worker const int num_loops = 1000000 / (rows * cols);
583*77c1e3ccSAndroid Build Coastguard Worker
584*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < 2; ++i) {
585*77c1e3ccSAndroid Build Coastguard Worker const int bd = bd_ar[i];
586*77c1e3ccSAndroid Build Coastguard Worker for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
587*77c1e3ccSAndroid Build Coastguard Worker if (libaom_test::IsTxSizeTypeValid(
588*77c1e3ccSAndroid Build Coastguard Worker tx_size, static_cast<TX_TYPE>(tx_type)) == false) {
589*77c1e3ccSAndroid Build Coastguard Worker continue;
590*77c1e3ccSAndroid Build Coastguard Worker }
591*77c1e3ccSAndroid Build Coastguard Worker
592*77c1e3ccSAndroid Build Coastguard Worker FwdTxfm2dFunc ref_func = libaom_test::fwd_txfm_func_ls[tx_size];
593*77c1e3ccSAndroid Build Coastguard Worker if (ref_func != nullptr) {
594*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int16_t, input[64 * 64]) = { 0 };
595*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, output[64 * 64]);
596*77c1e3ccSAndroid Build Coastguard Worker DECLARE_ALIGNED(32, int32_t, ref_output[64 * 64]);
597*77c1e3ccSAndroid Build Coastguard Worker int input_stride = 64;
598*77c1e3ccSAndroid Build Coastguard Worker ACMRandom rnd(ACMRandom::DeterministicSeed());
599*77c1e3ccSAndroid Build Coastguard Worker
600*77c1e3ccSAndroid Build Coastguard Worker for (int r = 0; r < rows; ++r) {
601*77c1e3ccSAndroid Build Coastguard Worker for (int c = 0; c < cols; ++c) {
602*77c1e3ccSAndroid Build Coastguard Worker input[r * input_stride + c] = rnd.Rand16() % (1 << bd);
603*77c1e3ccSAndroid Build Coastguard Worker }
604*77c1e3ccSAndroid Build Coastguard Worker }
605*77c1e3ccSAndroid Build Coastguard Worker
606*77c1e3ccSAndroid Build Coastguard Worker param.tx_type = (TX_TYPE)tx_type;
607*77c1e3ccSAndroid Build Coastguard Worker param.tx_size = (TX_SIZE)tx_size;
608*77c1e3ccSAndroid Build Coastguard Worker param.tx_set_type = EXT_TX_SET_ALL16;
609*77c1e3ccSAndroid Build Coastguard Worker param.bd = bd;
610*77c1e3ccSAndroid Build Coastguard Worker
611*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer ref_timer, test_timer;
612*77c1e3ccSAndroid Build Coastguard Worker
613*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&ref_timer);
614*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < num_loops; ++j) {
615*77c1e3ccSAndroid Build Coastguard Worker ref_func(input, ref_output, input_stride, (TX_TYPE)tx_type, bd);
616*77c1e3ccSAndroid Build Coastguard Worker }
617*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&ref_timer);
618*77c1e3ccSAndroid Build Coastguard Worker const int elapsed_time_c =
619*77c1e3ccSAndroid Build Coastguard Worker static_cast<int>(aom_usec_timer_elapsed(&ref_timer));
620*77c1e3ccSAndroid Build Coastguard Worker
621*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_start(&test_timer);
622*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < num_loops; ++j) {
623*77c1e3ccSAndroid Build Coastguard Worker target_func(input, output, input_stride, ¶m);
624*77c1e3ccSAndroid Build Coastguard Worker }
625*77c1e3ccSAndroid Build Coastguard Worker aom_usec_timer_mark(&test_timer);
626*77c1e3ccSAndroid Build Coastguard Worker const int elapsed_time_simd =
627*77c1e3ccSAndroid Build Coastguard Worker static_cast<int>(aom_usec_timer_elapsed(&test_timer));
628*77c1e3ccSAndroid Build Coastguard Worker
629*77c1e3ccSAndroid Build Coastguard Worker printf(
630*77c1e3ccSAndroid Build Coastguard Worker "txfm_size[%2dx%-2d] \t txfm_type[%d] \t c_time=%d \t"
631*77c1e3ccSAndroid Build Coastguard Worker "simd_time=%d \t gain=%d \n",
632*77c1e3ccSAndroid Build Coastguard Worker cols, rows, tx_type, elapsed_time_c, elapsed_time_simd,
633*77c1e3ccSAndroid Build Coastguard Worker (elapsed_time_c / elapsed_time_simd));
634*77c1e3ccSAndroid Build Coastguard Worker }
635*77c1e3ccSAndroid Build Coastguard Worker }
636*77c1e3ccSAndroid Build Coastguard Worker }
637*77c1e3ccSAndroid Build Coastguard Worker }
638*77c1e3ccSAndroid Build Coastguard Worker
639*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<TX_SIZE, Highbd_fwd_txfm_func> HighbdFwdTxfm2dParam;
640*77c1e3ccSAndroid Build Coastguard Worker
641*77c1e3ccSAndroid Build Coastguard Worker class AV1HighbdFwdTxfm2dTest
642*77c1e3ccSAndroid Build Coastguard Worker : public ::testing::TestWithParam<HighbdFwdTxfm2dParam> {};
643*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1HighbdFwdTxfm2dTest);
644*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1HighbdFwdTxfm2dTest,match)645*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdFwdTxfm2dTest, match) {
646*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdFwdTxfm2dMatchTest(GET_PARAM(0), GET_PARAM(1));
647*77c1e3ccSAndroid Build Coastguard Worker }
648*77c1e3ccSAndroid Build Coastguard Worker
TEST_P(AV1HighbdFwdTxfm2dTest,DISABLED_Speed)649*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1HighbdFwdTxfm2dTest, DISABLED_Speed) {
650*77c1e3ccSAndroid Build Coastguard Worker AV1HighbdFwdTxfm2dSpeedTest(GET_PARAM(0), GET_PARAM(1));
651*77c1e3ccSAndroid Build Coastguard Worker }
652*77c1e3ccSAndroid Build Coastguard Worker
653*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Combine;
654*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Values;
655*77c1e3ccSAndroid Build Coastguard Worker using ::testing::ValuesIn;
656*77c1e3ccSAndroid Build Coastguard Worker
657*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSE4_1
658*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE Highbd_fwd_txfm_for_sse4_1[] = {
659*77c1e3ccSAndroid Build Coastguard Worker TX_4X4, TX_8X8, TX_16X16, TX_32X32, TX_64X64, TX_4X8, TX_8X4,
660*77c1e3ccSAndroid Build Coastguard Worker TX_8X16, TX_16X8, TX_16X32, TX_32X16, TX_32X64, TX_64X32,
661*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
662*77c1e3ccSAndroid Build Coastguard Worker TX_4X16, TX_16X4, TX_8X32, TX_32X8, TX_16X64, TX_64X16,
663*77c1e3ccSAndroid Build Coastguard Worker #endif // !CONFIG_REALTIME_ONLY
664*77c1e3ccSAndroid Build Coastguard Worker };
665*77c1e3ccSAndroid Build Coastguard Worker
666*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSE4_1, AV1HighbdFwdTxfm2dTest,
667*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(Highbd_fwd_txfm_for_sse4_1),
668*77c1e3ccSAndroid Build Coastguard Worker Values(av1_highbd_fwd_txfm)));
669*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_SSE4_1
670*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
671*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE Highbd_fwd_txfm_for_avx2[] = { TX_8X8, TX_16X16, TX_32X32,
672*77c1e3ccSAndroid Build Coastguard Worker TX_64X64, TX_8X16, TX_16X8 };
673*77c1e3ccSAndroid Build Coastguard Worker
674*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(AVX2, AV1HighbdFwdTxfm2dTest,
675*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(Highbd_fwd_txfm_for_avx2),
676*77c1e3ccSAndroid Build Coastguard Worker Values(av1_highbd_fwd_txfm)));
677*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_AVX2
678*77c1e3ccSAndroid Build Coastguard Worker
679*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
680*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE Highbd_fwd_txfm_for_neon[] = {
681*77c1e3ccSAndroid Build Coastguard Worker TX_4X4, TX_8X8, TX_16X16, TX_32X32, TX_64X64, TX_4X8, TX_8X4,
682*77c1e3ccSAndroid Build Coastguard Worker TX_8X16, TX_16X8, TX_16X32, TX_32X16, TX_32X64, TX_64X32,
683*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
684*77c1e3ccSAndroid Build Coastguard Worker TX_4X16, TX_16X4, TX_8X32, TX_32X8, TX_16X64, TX_64X16
685*77c1e3ccSAndroid Build Coastguard Worker #endif // !CONFIG_REALTIME_ONLY
686*77c1e3ccSAndroid Build Coastguard Worker };
687*77c1e3ccSAndroid Build Coastguard Worker
688*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(NEON, AV1HighbdFwdTxfm2dTest,
689*77c1e3ccSAndroid Build Coastguard Worker Combine(ValuesIn(Highbd_fwd_txfm_for_neon),
690*77c1e3ccSAndroid Build Coastguard Worker Values(av1_highbd_fwd_txfm)));
691*77c1e3ccSAndroid Build Coastguard Worker #endif // HAVE_NEON
692*77c1e3ccSAndroid Build Coastguard Worker
693*77c1e3ccSAndroid Build Coastguard Worker } // namespace
694