xref: /aosp_15_r20/external/libaom/test/av1_inv_txfm2d_test.cc (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 "aom_ports/aom_timer.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_inv_txfm1d_cfg.h"
22*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/scan.h"
23*77c1e3ccSAndroid Build Coastguard Worker #include "test/acm_random.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "test/av1_txfm_test.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "test/util.h"
26*77c1e3ccSAndroid Build Coastguard Worker 
27*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::ACMRandom;
28*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::bd;
29*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::compute_avg_abs_error;
30*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::input_base;
31*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::InvTxfm2dFunc;
32*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::LbdInvTxfm2dFunc;
33*77c1e3ccSAndroid Build Coastguard Worker using libaom_test::tx_type_name;
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Combine;
36*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Range;
37*77c1e3ccSAndroid Build Coastguard Worker using ::testing::Values;
38*77c1e3ccSAndroid Build Coastguard Worker 
39*77c1e3ccSAndroid Build Coastguard Worker using std::vector;
40*77c1e3ccSAndroid Build Coastguard Worker 
41*77c1e3ccSAndroid Build Coastguard Worker typedef TX_TYPE TxType;
42*77c1e3ccSAndroid Build Coastguard Worker typedef TX_SIZE TxSize;
43*77c1e3ccSAndroid Build Coastguard Worker 
44*77c1e3ccSAndroid Build Coastguard Worker namespace {
45*77c1e3ccSAndroid Build Coastguard Worker 
46*77c1e3ccSAndroid Build Coastguard Worker // AV1InvTxfm2dParam argument list:
47*77c1e3ccSAndroid Build Coastguard Worker // tx_type_, tx_size_, max_error_, max_avg_error_
48*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<TxType, TxSize, int, double> AV1InvTxfm2dParam;
49*77c1e3ccSAndroid Build Coastguard Worker 
50*77c1e3ccSAndroid Build Coastguard Worker class AV1InvTxfm2d : public ::testing::TestWithParam<AV1InvTxfm2dParam> {
51*77c1e3ccSAndroid Build Coastguard Worker  public:
SetUp()52*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override {
53*77c1e3ccSAndroid Build Coastguard Worker     tx_type_ = GET_PARAM(0);
54*77c1e3ccSAndroid Build Coastguard Worker     tx_size_ = GET_PARAM(1);
55*77c1e3ccSAndroid Build Coastguard Worker     max_error_ = GET_PARAM(2);
56*77c1e3ccSAndroid Build Coastguard Worker     max_avg_error_ = GET_PARAM(3);
57*77c1e3ccSAndroid Build Coastguard Worker   }
58*77c1e3ccSAndroid Build Coastguard Worker 
RunRoundtripCheck()59*77c1e3ccSAndroid Build Coastguard Worker   void RunRoundtripCheck() {
60*77c1e3ccSAndroid Build Coastguard Worker     int tx_w = tx_size_wide[tx_size_];
61*77c1e3ccSAndroid Build Coastguard Worker     int tx_h = tx_size_high[tx_size_];
62*77c1e3ccSAndroid Build Coastguard Worker     int txfm2d_size = tx_w * tx_h;
63*77c1e3ccSAndroid Build Coastguard Worker     const FwdTxfm2dFunc fwd_txfm_func = libaom_test::fwd_txfm_func_ls[tx_size_];
64*77c1e3ccSAndroid Build Coastguard Worker     const InvTxfm2dFunc inv_txfm_func = libaom_test::inv_txfm_func_ls[tx_size_];
65*77c1e3ccSAndroid Build Coastguard Worker     double avg_abs_error = 0;
66*77c1e3ccSAndroid Build Coastguard Worker     ACMRandom rnd(ACMRandom::DeterministicSeed());
67*77c1e3ccSAndroid Build Coastguard Worker 
68*77c1e3ccSAndroid Build Coastguard Worker     const int count = 500;
69*77c1e3ccSAndroid Build Coastguard Worker 
70*77c1e3ccSAndroid Build Coastguard Worker     for (int ci = 0; ci < count; ci++) {
71*77c1e3ccSAndroid Build Coastguard Worker       DECLARE_ALIGNED(16, int16_t, input[64 * 64]) = { 0 };
72*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_LE(txfm2d_size, NELEMENTS(input));
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker       for (int ni = 0; ni < txfm2d_size; ++ni) {
75*77c1e3ccSAndroid Build Coastguard Worker         if (ci == 0) {
76*77c1e3ccSAndroid Build Coastguard Worker           int extreme_input = input_base - 1;
77*77c1e3ccSAndroid Build Coastguard Worker           input[ni] = extreme_input;  // extreme case
78*77c1e3ccSAndroid Build Coastguard Worker         } else {
79*77c1e3ccSAndroid Build Coastguard Worker           input[ni] = rnd.Rand16() % input_base;
80*77c1e3ccSAndroid Build Coastguard Worker         }
81*77c1e3ccSAndroid Build Coastguard Worker       }
82*77c1e3ccSAndroid Build Coastguard Worker 
83*77c1e3ccSAndroid Build Coastguard Worker       DECLARE_ALIGNED(16, uint16_t, expected[64 * 64]) = { 0 };
84*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_LE(txfm2d_size, NELEMENTS(expected));
85*77c1e3ccSAndroid Build Coastguard Worker       if (TxfmUsesApproximation()) {
86*77c1e3ccSAndroid Build Coastguard Worker         // Compare reference forward HT + inverse HT vs forward HT + inverse HT.
87*77c1e3ccSAndroid Build Coastguard Worker         double ref_input[64 * 64];
88*77c1e3ccSAndroid Build Coastguard Worker         ASSERT_LE(txfm2d_size, NELEMENTS(ref_input));
89*77c1e3ccSAndroid Build Coastguard Worker         for (int ni = 0; ni < txfm2d_size; ++ni) {
90*77c1e3ccSAndroid Build Coastguard Worker           ref_input[ni] = input[ni];
91*77c1e3ccSAndroid Build Coastguard Worker         }
92*77c1e3ccSAndroid Build Coastguard Worker         double ref_coeffs[64 * 64] = { 0 };
93*77c1e3ccSAndroid Build Coastguard Worker         ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs));
94*77c1e3ccSAndroid Build Coastguard Worker         ASSERT_EQ(tx_type_, static_cast<TxType>(DCT_DCT));
95*77c1e3ccSAndroid Build Coastguard Worker         libaom_test::reference_hybrid_2d(ref_input, ref_coeffs, tx_type_,
96*77c1e3ccSAndroid Build Coastguard Worker                                          tx_size_);
97*77c1e3ccSAndroid Build Coastguard Worker         DECLARE_ALIGNED(16, int32_t, ref_coeffs_int[64 * 64]) = { 0 };
98*77c1e3ccSAndroid Build Coastguard Worker         ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs_int));
99*77c1e3ccSAndroid Build Coastguard Worker         for (int ni = 0; ni < txfm2d_size; ++ni) {
100*77c1e3ccSAndroid Build Coastguard Worker           ref_coeffs_int[ni] = (int32_t)round(ref_coeffs[ni]);
101*77c1e3ccSAndroid Build Coastguard Worker         }
102*77c1e3ccSAndroid Build Coastguard Worker         inv_txfm_func(ref_coeffs_int, expected, tx_w, tx_type_, bd);
103*77c1e3ccSAndroid Build Coastguard Worker       } else {
104*77c1e3ccSAndroid Build Coastguard Worker         // Compare original input vs forward HT + inverse HT.
105*77c1e3ccSAndroid Build Coastguard Worker         for (int ni = 0; ni < txfm2d_size; ++ni) {
106*77c1e3ccSAndroid Build Coastguard Worker           expected[ni] = input[ni];
107*77c1e3ccSAndroid Build Coastguard Worker         }
108*77c1e3ccSAndroid Build Coastguard Worker       }
109*77c1e3ccSAndroid Build Coastguard Worker 
110*77c1e3ccSAndroid Build Coastguard Worker       DECLARE_ALIGNED(16, int32_t, coeffs[64 * 64]) = { 0 };
111*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_LE(txfm2d_size, NELEMENTS(coeffs));
112*77c1e3ccSAndroid Build Coastguard Worker       fwd_txfm_func(input, coeffs, tx_w, tx_type_, bd);
113*77c1e3ccSAndroid Build Coastguard Worker 
114*77c1e3ccSAndroid Build Coastguard Worker       DECLARE_ALIGNED(16, uint16_t, actual[64 * 64]) = { 0 };
115*77c1e3ccSAndroid Build Coastguard Worker       ASSERT_LE(txfm2d_size, NELEMENTS(actual));
116*77c1e3ccSAndroid Build Coastguard Worker       inv_txfm_func(coeffs, actual, tx_w, tx_type_, bd);
117*77c1e3ccSAndroid Build Coastguard Worker 
118*77c1e3ccSAndroid Build Coastguard Worker       double actual_max_error = 0;
119*77c1e3ccSAndroid Build Coastguard Worker       for (int ni = 0; ni < txfm2d_size; ++ni) {
120*77c1e3ccSAndroid Build Coastguard Worker         const double this_error = abs(expected[ni] - actual[ni]);
121*77c1e3ccSAndroid Build Coastguard Worker         actual_max_error = AOMMAX(actual_max_error, this_error);
122*77c1e3ccSAndroid Build Coastguard Worker       }
123*77c1e3ccSAndroid Build Coastguard Worker       EXPECT_GE(max_error_, actual_max_error)
124*77c1e3ccSAndroid Build Coastguard Worker           << " tx_w: " << tx_w << " tx_h " << tx_h
125*77c1e3ccSAndroid Build Coastguard Worker           << " tx_type: " << tx_type_name[tx_type_];
126*77c1e3ccSAndroid Build Coastguard Worker       if (actual_max_error > max_error_) {  // exit early.
127*77c1e3ccSAndroid Build Coastguard Worker         break;
128*77c1e3ccSAndroid Build Coastguard Worker       }
129*77c1e3ccSAndroid Build Coastguard Worker       avg_abs_error += compute_avg_abs_error<uint16_t, uint16_t>(
130*77c1e3ccSAndroid Build Coastguard Worker           expected, actual, txfm2d_size);
131*77c1e3ccSAndroid Build Coastguard Worker     }
132*77c1e3ccSAndroid Build Coastguard Worker 
133*77c1e3ccSAndroid Build Coastguard Worker     avg_abs_error /= count;
134*77c1e3ccSAndroid Build Coastguard Worker     EXPECT_GE(max_avg_error_, avg_abs_error)
135*77c1e3ccSAndroid Build Coastguard Worker         << " tx_w: " << tx_w << " tx_h " << tx_h
136*77c1e3ccSAndroid Build Coastguard Worker         << " tx_type: " << tx_type_name[tx_type_];
137*77c1e3ccSAndroid Build Coastguard Worker   }
138*77c1e3ccSAndroid Build Coastguard Worker 
139*77c1e3ccSAndroid Build Coastguard Worker  private:
TxfmUsesApproximation()140*77c1e3ccSAndroid Build Coastguard Worker   bool TxfmUsesApproximation() {
141*77c1e3ccSAndroid Build Coastguard Worker     if (tx_size_wide[tx_size_] == 64 || tx_size_high[tx_size_] == 64) {
142*77c1e3ccSAndroid Build Coastguard Worker       return true;
143*77c1e3ccSAndroid Build Coastguard Worker     }
144*77c1e3ccSAndroid Build Coastguard Worker     return false;
145*77c1e3ccSAndroid Build Coastguard Worker   }
146*77c1e3ccSAndroid Build Coastguard Worker 
147*77c1e3ccSAndroid Build Coastguard Worker   int max_error_;
148*77c1e3ccSAndroid Build Coastguard Worker   double max_avg_error_;
149*77c1e3ccSAndroid Build Coastguard Worker   TxType tx_type_;
150*77c1e3ccSAndroid Build Coastguard Worker   TxSize tx_size_;
151*77c1e3ccSAndroid Build Coastguard Worker };
152*77c1e3ccSAndroid Build Coastguard Worker 
153*77c1e3ccSAndroid Build Coastguard Worker static int max_error_ls[TX_SIZES_ALL] = {
154*77c1e3ccSAndroid Build Coastguard Worker   2,  // 4x4 transform
155*77c1e3ccSAndroid Build Coastguard Worker   2,  // 8x8 transform
156*77c1e3ccSAndroid Build Coastguard Worker   2,  // 16x16 transform
157*77c1e3ccSAndroid Build Coastguard Worker   4,  // 32x32 transform
158*77c1e3ccSAndroid Build Coastguard Worker   3,  // 64x64 transform
159*77c1e3ccSAndroid Build Coastguard Worker   2,  // 4x8 transform
160*77c1e3ccSAndroid Build Coastguard Worker   2,  // 8x4 transform
161*77c1e3ccSAndroid Build Coastguard Worker   2,  // 8x16 transform
162*77c1e3ccSAndroid Build Coastguard Worker   2,  // 16x8 transform
163*77c1e3ccSAndroid Build Coastguard Worker   3,  // 16x32 transform
164*77c1e3ccSAndroid Build Coastguard Worker   3,  // 32x16 transform
165*77c1e3ccSAndroid Build Coastguard Worker   5,  // 32x64 transform
166*77c1e3ccSAndroid Build Coastguard Worker   5,  // 64x32 transform
167*77c1e3ccSAndroid Build Coastguard Worker   2,  // 4x16 transform
168*77c1e3ccSAndroid Build Coastguard Worker   2,  // 16x4 transform
169*77c1e3ccSAndroid Build Coastguard Worker   2,  // 8x32 transform
170*77c1e3ccSAndroid Build Coastguard Worker   2,  // 32x8 transform
171*77c1e3ccSAndroid Build Coastguard Worker   3,  // 16x64 transform
172*77c1e3ccSAndroid Build Coastguard Worker   3,  // 64x16 transform
173*77c1e3ccSAndroid Build Coastguard Worker };
174*77c1e3ccSAndroid Build Coastguard Worker 
175*77c1e3ccSAndroid Build Coastguard Worker static double avg_error_ls[TX_SIZES_ALL] = {
176*77c1e3ccSAndroid Build Coastguard Worker   0.002,  // 4x4 transform
177*77c1e3ccSAndroid Build Coastguard Worker   0.05,   // 8x8 transform
178*77c1e3ccSAndroid Build Coastguard Worker   0.07,   // 16x16 transform
179*77c1e3ccSAndroid Build Coastguard Worker   0.4,    // 32x32 transform
180*77c1e3ccSAndroid Build Coastguard Worker   0.3,    // 64x64 transform
181*77c1e3ccSAndroid Build Coastguard Worker   0.02,   // 4x8 transform
182*77c1e3ccSAndroid Build Coastguard Worker   0.02,   // 8x4 transform
183*77c1e3ccSAndroid Build Coastguard Worker   0.04,   // 8x16 transform
184*77c1e3ccSAndroid Build Coastguard Worker   0.07,   // 16x8 transform
185*77c1e3ccSAndroid Build Coastguard Worker   0.4,    // 16x32 transform
186*77c1e3ccSAndroid Build Coastguard Worker   0.5,    // 32x16 transform
187*77c1e3ccSAndroid Build Coastguard Worker   0.38,   // 32x64 transform
188*77c1e3ccSAndroid Build Coastguard Worker   0.39,   // 64x32 transform
189*77c1e3ccSAndroid Build Coastguard Worker   0.2,    // 4x16 transform
190*77c1e3ccSAndroid Build Coastguard Worker   0.2,    // 16x4 transform
191*77c1e3ccSAndroid Build Coastguard Worker   0.2,    // 8x32 transform
192*77c1e3ccSAndroid Build Coastguard Worker   0.2,    // 32x8 transform
193*77c1e3ccSAndroid Build Coastguard Worker   0.38,   // 16x64 transform
194*77c1e3ccSAndroid Build Coastguard Worker   0.38,   // 64x16 transform
195*77c1e3ccSAndroid Build Coastguard Worker };
196*77c1e3ccSAndroid Build Coastguard Worker 
GetInvTxfm2dParamList()197*77c1e3ccSAndroid Build Coastguard Worker vector<AV1InvTxfm2dParam> GetInvTxfm2dParamList() {
198*77c1e3ccSAndroid Build Coastguard Worker   vector<AV1InvTxfm2dParam> param_list;
199*77c1e3ccSAndroid Build Coastguard Worker   for (int s = 0; s < TX_SIZES; ++s) {
200*77c1e3ccSAndroid Build Coastguard Worker     const int max_error = max_error_ls[s];
201*77c1e3ccSAndroid Build Coastguard Worker     const double avg_error = avg_error_ls[s];
202*77c1e3ccSAndroid Build Coastguard Worker     for (int t = 0; t < TX_TYPES; ++t) {
203*77c1e3ccSAndroid Build Coastguard Worker       const TxType tx_type = static_cast<TxType>(t);
204*77c1e3ccSAndroid Build Coastguard Worker       const TxSize tx_size = static_cast<TxSize>(s);
205*77c1e3ccSAndroid Build Coastguard Worker       if (libaom_test::IsTxSizeTypeValid(tx_size, tx_type)) {
206*77c1e3ccSAndroid Build Coastguard Worker         param_list.push_back(
207*77c1e3ccSAndroid Build Coastguard Worker             AV1InvTxfm2dParam(tx_type, tx_size, max_error, avg_error));
208*77c1e3ccSAndroid Build Coastguard Worker       }
209*77c1e3ccSAndroid Build Coastguard Worker     }
210*77c1e3ccSAndroid Build Coastguard Worker   }
211*77c1e3ccSAndroid Build Coastguard Worker   return param_list;
212*77c1e3ccSAndroid Build Coastguard Worker }
213*77c1e3ccSAndroid Build Coastguard Worker 
214*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(C, AV1InvTxfm2d,
215*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::ValuesIn(GetInvTxfm2dParamList()));
216*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1InvTxfm2d,RunRoundtripCheck)217*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1InvTxfm2d, RunRoundtripCheck) { RunRoundtripCheck(); }
218*77c1e3ccSAndroid Build Coastguard Worker 
TEST(AV1InvTxfm2d,CfgTest)219*77c1e3ccSAndroid Build Coastguard Worker TEST(AV1InvTxfm2d, CfgTest) {
220*77c1e3ccSAndroid Build Coastguard Worker   for (int bd_idx = 0; bd_idx < BD_NUM; ++bd_idx) {
221*77c1e3ccSAndroid Build Coastguard Worker     int bd = libaom_test::bd_arr[bd_idx];
222*77c1e3ccSAndroid Build Coastguard Worker     int8_t low_range = libaom_test::low_range_arr[bd_idx];
223*77c1e3ccSAndroid Build Coastguard Worker     int8_t high_range = libaom_test::high_range_arr[bd_idx];
224*77c1e3ccSAndroid Build Coastguard Worker     for (int tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) {
225*77c1e3ccSAndroid Build Coastguard Worker       for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) {
226*77c1e3ccSAndroid Build Coastguard Worker         if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(tx_size),
227*77c1e3ccSAndroid Build Coastguard Worker                                            static_cast<TxType>(tx_type)) ==
228*77c1e3ccSAndroid Build Coastguard Worker             false) {
229*77c1e3ccSAndroid Build Coastguard Worker           continue;
230*77c1e3ccSAndroid Build Coastguard Worker         }
231*77c1e3ccSAndroid Build Coastguard Worker         TXFM_2D_FLIP_CFG cfg;
232*77c1e3ccSAndroid Build Coastguard Worker         av1_get_inv_txfm_cfg(static_cast<TxType>(tx_type),
233*77c1e3ccSAndroid Build Coastguard Worker                              static_cast<TxSize>(tx_size), &cfg);
234*77c1e3ccSAndroid Build Coastguard Worker         int8_t stage_range_col[MAX_TXFM_STAGE_NUM];
235*77c1e3ccSAndroid Build Coastguard Worker         int8_t stage_range_row[MAX_TXFM_STAGE_NUM];
236*77c1e3ccSAndroid Build Coastguard Worker         av1_gen_inv_stage_range(stage_range_col, stage_range_row, &cfg,
237*77c1e3ccSAndroid Build Coastguard Worker                                 static_cast<TxSize>(tx_size), bd);
238*77c1e3ccSAndroid Build Coastguard Worker         libaom_test::txfm_stage_range_check(stage_range_col, cfg.stage_num_col,
239*77c1e3ccSAndroid Build Coastguard Worker                                             cfg.cos_bit_col, low_range,
240*77c1e3ccSAndroid Build Coastguard Worker                                             high_range);
241*77c1e3ccSAndroid Build Coastguard Worker         libaom_test::txfm_stage_range_check(stage_range_row, cfg.stage_num_row,
242*77c1e3ccSAndroid Build Coastguard Worker                                             cfg.cos_bit_row, low_range,
243*77c1e3ccSAndroid Build Coastguard Worker                                             high_range);
244*77c1e3ccSAndroid Build Coastguard Worker       }
245*77c1e3ccSAndroid Build Coastguard Worker     }
246*77c1e3ccSAndroid Build Coastguard Worker   }
247*77c1e3ccSAndroid Build Coastguard Worker }
248*77c1e3ccSAndroid Build Coastguard Worker 
249*77c1e3ccSAndroid Build Coastguard Worker typedef std::tuple<const LbdInvTxfm2dFunc> AV1LbdInvTxfm2dParam;
250*77c1e3ccSAndroid Build Coastguard Worker class AV1LbdInvTxfm2d : public ::testing::TestWithParam<AV1LbdInvTxfm2dParam> {
251*77c1e3ccSAndroid Build Coastguard Worker  public:
SetUp()252*77c1e3ccSAndroid Build Coastguard Worker   void SetUp() override { target_func_ = GET_PARAM(0); }
253*77c1e3ccSAndroid Build Coastguard Worker   void RunAV1InvTxfm2dTest(TxType tx_type, TxSize tx_size, int run_times,
254*77c1e3ccSAndroid Build Coastguard Worker                            int gt_int16 = 0);
255*77c1e3ccSAndroid Build Coastguard Worker 
256*77c1e3ccSAndroid Build Coastguard Worker  private:
257*77c1e3ccSAndroid Build Coastguard Worker   LbdInvTxfm2dFunc target_func_;
258*77c1e3ccSAndroid Build Coastguard Worker };
259*77c1e3ccSAndroid Build Coastguard Worker GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AV1LbdInvTxfm2d);
260*77c1e3ccSAndroid Build Coastguard Worker 
RunAV1InvTxfm2dTest(TxType tx_type,TxSize tx_size,int run_times,int gt_int16)261*77c1e3ccSAndroid Build Coastguard Worker void AV1LbdInvTxfm2d::RunAV1InvTxfm2dTest(TxType tx_type, TxSize tx_size,
262*77c1e3ccSAndroid Build Coastguard Worker                                           int run_times, int gt_int16) {
263*77c1e3ccSAndroid Build Coastguard Worker   FwdTxfm2dFunc fwd_func_ = libaom_test::fwd_txfm_func_ls[tx_size];
264*77c1e3ccSAndroid Build Coastguard Worker   InvTxfm2dFunc ref_func_ = libaom_test::inv_txfm_func_ls[tx_size];
265*77c1e3ccSAndroid Build Coastguard Worker   if (fwd_func_ == nullptr || ref_func_ == nullptr || target_func_ == nullptr) {
266*77c1e3ccSAndroid Build Coastguard Worker     return;
267*77c1e3ccSAndroid Build Coastguard Worker   }
268*77c1e3ccSAndroid Build Coastguard Worker   const int bd = 8;
269*77c1e3ccSAndroid Build Coastguard Worker   const int BLK_WIDTH = 64;
270*77c1e3ccSAndroid Build Coastguard Worker   const int BLK_SIZE = BLK_WIDTH * BLK_WIDTH;
271*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(16, int16_t, input[BLK_SIZE]) = { 0 };
272*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(32, int32_t, inv_input[BLK_SIZE]) = { 0 };
273*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(16, uint8_t, output[BLK_SIZE]) = { 0 };
274*77c1e3ccSAndroid Build Coastguard Worker   DECLARE_ALIGNED(16, uint16_t, ref_output[BLK_SIZE]) = { 0 };
275*77c1e3ccSAndroid Build Coastguard Worker   int stride = BLK_WIDTH;
276*77c1e3ccSAndroid Build Coastguard Worker   int rows = tx_size_high[tx_size];
277*77c1e3ccSAndroid Build Coastguard Worker   int cols = tx_size_wide[tx_size];
278*77c1e3ccSAndroid Build Coastguard Worker   const int rows_nonezero = AOMMIN(32, rows);
279*77c1e3ccSAndroid Build Coastguard Worker   const int cols_nonezero = AOMMIN(32, cols);
280*77c1e3ccSAndroid Build Coastguard Worker   run_times /= (rows * cols);
281*77c1e3ccSAndroid Build Coastguard Worker   run_times = AOMMAX(1, run_times);
282*77c1e3ccSAndroid Build Coastguard Worker   const SCAN_ORDER *scan_order = get_default_scan(tx_size, tx_type);
283*77c1e3ccSAndroid Build Coastguard Worker   const int16_t *scan = scan_order->scan;
284*77c1e3ccSAndroid Build Coastguard Worker   const int16_t eobmax = rows_nonezero * cols_nonezero;
285*77c1e3ccSAndroid Build Coastguard Worker   ACMRandom rnd(ACMRandom::DeterministicSeed());
286*77c1e3ccSAndroid Build Coastguard Worker   int randTimes = run_times == 1 ? (eobmax + 500) : 1;
287*77c1e3ccSAndroid Build Coastguard Worker 
288*77c1e3ccSAndroid Build Coastguard Worker   for (int cnt = 0; cnt < randTimes; ++cnt) {
289*77c1e3ccSAndroid Build Coastguard Worker     const int16_t max_in = (1 << (bd)) - 1;
290*77c1e3ccSAndroid Build Coastguard Worker     for (int r = 0; r < BLK_WIDTH; ++r) {
291*77c1e3ccSAndroid Build Coastguard Worker       for (int c = 0; c < BLK_WIDTH; ++c) {
292*77c1e3ccSAndroid Build Coastguard Worker         input[r * cols + c] = (cnt == 0) ? max_in : rnd.Rand8Extremes();
293*77c1e3ccSAndroid Build Coastguard Worker         output[r * stride + c] = (cnt == 0) ? 128 : rnd.Rand8();
294*77c1e3ccSAndroid Build Coastguard Worker         ref_output[r * stride + c] = output[r * stride + c];
295*77c1e3ccSAndroid Build Coastguard Worker       }
296*77c1e3ccSAndroid Build Coastguard Worker     }
297*77c1e3ccSAndroid Build Coastguard Worker     fwd_func_(input, inv_input, stride, tx_type, bd);
298*77c1e3ccSAndroid Build Coastguard Worker 
299*77c1e3ccSAndroid Build Coastguard Worker     // produce eob input by setting high freq coeffs to zero
300*77c1e3ccSAndroid Build Coastguard Worker     const int eob = AOMMIN(cnt + 1, eobmax);
301*77c1e3ccSAndroid Build Coastguard Worker     for (int i = eob; i < eobmax; i++) {
302*77c1e3ccSAndroid Build Coastguard Worker       inv_input[scan[i]] = 0;
303*77c1e3ccSAndroid Build Coastguard Worker     }
304*77c1e3ccSAndroid Build Coastguard Worker     if (gt_int16) {
305*77c1e3ccSAndroid Build Coastguard Worker       inv_input[scan[eob - 1]] = ((int32_t)INT16_MAX * 100 / 141);
306*77c1e3ccSAndroid Build Coastguard Worker     }
307*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer timer;
308*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
309*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < run_times; ++i) {
310*77c1e3ccSAndroid Build Coastguard Worker       ref_func_(inv_input, ref_output, stride, tx_type, bd);
311*77c1e3ccSAndroid Build Coastguard Worker     }
312*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
313*77c1e3ccSAndroid Build Coastguard Worker     const double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer));
314*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_start(&timer);
315*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < run_times; ++i) {
316*77c1e3ccSAndroid Build Coastguard Worker       target_func_(inv_input, output, stride, tx_type, tx_size, eob);
317*77c1e3ccSAndroid Build Coastguard Worker     }
318*77c1e3ccSAndroid Build Coastguard Worker     aom_usec_timer_mark(&timer);
319*77c1e3ccSAndroid Build Coastguard Worker     const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer));
320*77c1e3ccSAndroid Build Coastguard Worker     if (run_times > 10) {
321*77c1e3ccSAndroid Build Coastguard Worker       printf("txfm[%d] %3dx%-3d:%7.2f/%7.2fns", tx_type, cols, rows, time1,
322*77c1e3ccSAndroid Build Coastguard Worker              time2);
323*77c1e3ccSAndroid Build Coastguard Worker       printf("(%3.2f)\n", time1 / time2);
324*77c1e3ccSAndroid Build Coastguard Worker     }
325*77c1e3ccSAndroid Build Coastguard Worker     for (int r = 0; r < rows; ++r) {
326*77c1e3ccSAndroid Build Coastguard Worker       for (int c = 0; c < cols; ++c) {
327*77c1e3ccSAndroid Build Coastguard Worker         uint8_t ref_value = static_cast<uint8_t>(ref_output[r * stride + c]);
328*77c1e3ccSAndroid Build Coastguard Worker         if (ref_value != output[r * stride + c]) {
329*77c1e3ccSAndroid Build Coastguard Worker           printf(" ");
330*77c1e3ccSAndroid Build Coastguard Worker         }
331*77c1e3ccSAndroid Build Coastguard Worker         ASSERT_EQ(ref_value, output[r * stride + c])
332*77c1e3ccSAndroid Build Coastguard Worker             << "[" << r << "," << c << "] " << cnt << " tx_size: " << cols
333*77c1e3ccSAndroid Build Coastguard Worker             << "x" << rows << " tx_type: " << tx_type_name[tx_type] << " eob "
334*77c1e3ccSAndroid Build Coastguard Worker             << eob;
335*77c1e3ccSAndroid Build Coastguard Worker       }
336*77c1e3ccSAndroid Build Coastguard Worker     }
337*77c1e3ccSAndroid Build Coastguard Worker   }
338*77c1e3ccSAndroid Build Coastguard Worker }
339*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1LbdInvTxfm2d,match)340*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1LbdInvTxfm2d, match) {
341*77c1e3ccSAndroid Build Coastguard Worker   for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) {
342*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < (int)TX_TYPES; ++i) {
343*77c1e3ccSAndroid Build Coastguard Worker       if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(j),
344*77c1e3ccSAndroid Build Coastguard Worker                                          static_cast<TxType>(i))) {
345*77c1e3ccSAndroid Build Coastguard Worker         RunAV1InvTxfm2dTest(static_cast<TxType>(i), static_cast<TxSize>(j), 1);
346*77c1e3ccSAndroid Build Coastguard Worker       }
347*77c1e3ccSAndroid Build Coastguard Worker     }
348*77c1e3ccSAndroid Build Coastguard Worker   }
349*77c1e3ccSAndroid Build Coastguard Worker }
350*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1LbdInvTxfm2d,gt_int16)351*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1LbdInvTxfm2d, gt_int16) {
352*77c1e3ccSAndroid Build Coastguard Worker   static const TxType types[] = { DCT_DCT, ADST_DCT, FLIPADST_DCT, IDTX,
353*77c1e3ccSAndroid Build Coastguard Worker                                   V_DCT,   H_DCT,    H_ADST,       H_FLIPADST };
354*77c1e3ccSAndroid Build Coastguard Worker   for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) {
355*77c1e3ccSAndroid Build Coastguard Worker     const TxSize sz = static_cast<TxSize>(j);
356*77c1e3ccSAndroid Build Coastguard Worker     for (uint8_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) {
357*77c1e3ccSAndroid Build Coastguard Worker       const TxType tp = types[i];
358*77c1e3ccSAndroid Build Coastguard Worker       if (libaom_test::IsTxSizeTypeValid(sz, tp)) {
359*77c1e3ccSAndroid Build Coastguard Worker         RunAV1InvTxfm2dTest(tp, sz, 1, 1);
360*77c1e3ccSAndroid Build Coastguard Worker       }
361*77c1e3ccSAndroid Build Coastguard Worker     }
362*77c1e3ccSAndroid Build Coastguard Worker   }
363*77c1e3ccSAndroid Build Coastguard Worker }
364*77c1e3ccSAndroid Build Coastguard Worker 
TEST_P(AV1LbdInvTxfm2d,DISABLED_Speed)365*77c1e3ccSAndroid Build Coastguard Worker TEST_P(AV1LbdInvTxfm2d, DISABLED_Speed) {
366*77c1e3ccSAndroid Build Coastguard Worker   for (int j = 1; j < (int)(TX_SIZES_ALL); ++j) {
367*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < (int)TX_TYPES; ++i) {
368*77c1e3ccSAndroid Build Coastguard Worker       if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(j),
369*77c1e3ccSAndroid Build Coastguard Worker                                          static_cast<TxType>(i))) {
370*77c1e3ccSAndroid Build Coastguard Worker         RunAV1InvTxfm2dTest(static_cast<TxType>(i), static_cast<TxSize>(j),
371*77c1e3ccSAndroid Build Coastguard Worker                             10000000);
372*77c1e3ccSAndroid Build Coastguard Worker       }
373*77c1e3ccSAndroid Build Coastguard Worker     }
374*77c1e3ccSAndroid Build Coastguard Worker   }
375*77c1e3ccSAndroid Build Coastguard Worker }
376*77c1e3ccSAndroid Build Coastguard Worker 
377*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_SSSE3
378*77c1e3ccSAndroid Build Coastguard Worker extern "C" void av1_lowbd_inv_txfm2d_add_ssse3(const int32_t *input,
379*77c1e3ccSAndroid Build Coastguard Worker                                                uint8_t *output, int stride,
380*77c1e3ccSAndroid Build Coastguard Worker                                                TxType tx_type, TxSize tx_size,
381*77c1e3ccSAndroid Build Coastguard Worker                                                int eob);
382*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(SSSE3, AV1LbdInvTxfm2d,
383*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_lowbd_inv_txfm2d_add_ssse3));
384*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_SSSE3
385*77c1e3ccSAndroid Build Coastguard Worker 
386*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_AVX2
387*77c1e3ccSAndroid Build Coastguard Worker extern "C" void av1_lowbd_inv_txfm2d_add_avx2(const int32_t *input,
388*77c1e3ccSAndroid Build Coastguard Worker                                               uint8_t *output, int stride,
389*77c1e3ccSAndroid Build Coastguard Worker                                               TxType tx_type, TxSize tx_size,
390*77c1e3ccSAndroid Build Coastguard Worker                                               int eob);
391*77c1e3ccSAndroid Build Coastguard Worker 
392*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(AVX2, AV1LbdInvTxfm2d,
393*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_lowbd_inv_txfm2d_add_avx2));
394*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_AVX2
395*77c1e3ccSAndroid Build Coastguard Worker 
396*77c1e3ccSAndroid Build Coastguard Worker #if HAVE_NEON
397*77c1e3ccSAndroid Build Coastguard Worker extern "C" void av1_lowbd_inv_txfm2d_add_neon(const int32_t *input,
398*77c1e3ccSAndroid Build Coastguard Worker                                               uint8_t *output, int stride,
399*77c1e3ccSAndroid Build Coastguard Worker                                               TX_TYPE tx_type, TX_SIZE tx_size,
400*77c1e3ccSAndroid Build Coastguard Worker                                               int eob);
401*77c1e3ccSAndroid Build Coastguard Worker 
402*77c1e3ccSAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(NEON, AV1LbdInvTxfm2d,
403*77c1e3ccSAndroid Build Coastguard Worker                          ::testing::Values(av1_lowbd_inv_txfm2d_add_neon));
404*77c1e3ccSAndroid Build Coastguard Worker #endif  // HAVE_NEON
405*77c1e3ccSAndroid Build Coastguard Worker 
406*77c1e3ccSAndroid Build Coastguard Worker }  // namespace
407