Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <math.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 15 | #include <vector> |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 17 | #include "config/av1_rtcd.h" |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 18 | |
| 19 | #include "aom_ports/aom_timer.h" |
Sarah Parker | eec47e6 | 2017-05-15 20:49:22 -0700 | [diff] [blame] | 20 | #include "av1/common/av1_inv_txfm1d_cfg.h" |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 21 | #include "av1/common/scan.h" |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 22 | #include "test/acm_random.h" |
| 23 | #include "test/av1_txfm_test.h" |
| 24 | #include "test/util.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 25 | |
| 26 | using libaom_test::ACMRandom; |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 27 | using libaom_test::bd; |
| 28 | using libaom_test::compute_avg_abs_error; |
| 29 | using libaom_test::input_base; |
Johann | 54fa62e | 2018-09-25 14:09:31 -0700 | [diff] [blame] | 30 | using libaom_test::InvTxfm2dFunc; |
| 31 | using libaom_test::LbdInvTxfm2dFunc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 32 | |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 33 | using ::testing::Combine; |
| 34 | using ::testing::Range; |
| 35 | using ::testing::Values; |
| 36 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 37 | using std::vector; |
| 38 | |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 39 | typedef TX_TYPE TxType; |
| 40 | typedef TX_SIZE TxSize; |
| 41 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 44 | static const char *tx_type_name[] = { |
| 45 | "DCT_DCT", |
| 46 | "ADST_DCT", |
| 47 | "DCT_ADST", |
| 48 | "ADST_ADST", |
| 49 | "FLIPADST_DCT", |
| 50 | "DCT_FLIPADST", |
| 51 | "FLIPADST_FLIPADST", |
| 52 | "ADST_FLIPADST", |
| 53 | "FLIPADST_ADST", |
| 54 | "IDTX", |
| 55 | "V_DCT", |
| 56 | "H_DCT", |
| 57 | "V_ADST", |
| 58 | "H_ADST", |
| 59 | "V_FLIPADST", |
| 60 | "H_FLIPADST", |
| 61 | }; |
| 62 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | // AV1InvTxfm2dParam argument list: |
| 64 | // tx_type_, tx_size_, max_error_, max_avg_error_ |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 65 | typedef ::testing::tuple<TxType, TxSize, int, double> AV1InvTxfm2dParam; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 66 | |
| 67 | class AV1InvTxfm2d : public ::testing::TestWithParam<AV1InvTxfm2dParam> { |
| 68 | public: |
| 69 | virtual void SetUp() { |
| 70 | tx_type_ = GET_PARAM(0); |
| 71 | tx_size_ = GET_PARAM(1); |
| 72 | max_error_ = GET_PARAM(2); |
| 73 | max_avg_error_ = GET_PARAM(3); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void RunRoundtripCheck() { |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 77 | int tx_w = tx_size_wide[tx_size_]; |
| 78 | int tx_h = tx_size_high[tx_size_]; |
| 79 | int txfm2d_size = tx_w * tx_h; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 80 | const FwdTxfm2dFunc fwd_txfm_func = libaom_test::fwd_txfm_func_ls[tx_size_]; |
| 81 | const InvTxfm2dFunc inv_txfm_func = libaom_test::inv_txfm_func_ls[tx_size_]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 82 | double avg_abs_error = 0; |
| 83 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Sebastien Alaiwan | f7829f4 | 2017-07-04 11:54:33 +0200 | [diff] [blame] | 84 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 85 | const int count = 500; |
Sebastien Alaiwan | f7829f4 | 2017-07-04 11:54:33 +0200 | [diff] [blame] | 86 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 87 | for (int ci = 0; ci < count; ci++) { |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 88 | DECLARE_ALIGNED(16, int16_t, input[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 89 | ASSERT_LE(txfm2d_size, NELEMENTS(input)); |
Sebastien Alaiwan | 7a6e87b | 2017-07-04 12:32:46 +0200 | [diff] [blame] | 90 | |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 91 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | if (ci == 0) { |
| 93 | int extreme_input = input_base - 1; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 94 | input[ni] = extreme_input; // extreme case |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | } else { |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 96 | input[ni] = rnd.Rand16() % input_base; |
| 97 | } |
| 98 | } |
| 99 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 100 | DECLARE_ALIGNED(16, uint16_t, expected[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 101 | ASSERT_LE(txfm2d_size, NELEMENTS(expected)); |
| 102 | if (TxfmUsesApproximation()) { |
| 103 | // Compare reference forward HT + inverse HT vs forward HT + inverse HT. |
| 104 | double ref_input[64 * 64]; |
| 105 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_input)); |
| 106 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 107 | ref_input[ni] = input[ni]; |
| 108 | } |
| 109 | double ref_coeffs[64 * 64] = { 0 }; |
| 110 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs)); |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 111 | ASSERT_EQ(tx_type_, static_cast<TxType>(DCT_DCT)); |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 112 | libaom_test::reference_hybrid_2d(ref_input, ref_coeffs, tx_type_, |
| 113 | tx_size_); |
Yaowu Xu | e3fb568 | 2017-12-15 07:51:50 -0800 | [diff] [blame] | 114 | DECLARE_ALIGNED(16, int32_t, ref_coeffs_int[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 115 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs_int)); |
| 116 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 117 | ref_coeffs_int[ni] = (int32_t)round(ref_coeffs[ni]); |
| 118 | } |
| 119 | inv_txfm_func(ref_coeffs_int, expected, tx_w, tx_type_, bd); |
| 120 | } else { |
| 121 | // Compare original input vs forward HT + inverse HT. |
| 122 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 123 | expected[ni] = input[ni]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 127 | DECLARE_ALIGNED(16, int32_t, coeffs[64 * 64]) = { 0 }; |
Urvang Joshi | 0e301ba | 2017-12-11 17:49:13 -0800 | [diff] [blame] | 128 | ASSERT_LE(txfm2d_size, NELEMENTS(coeffs)); |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 129 | fwd_txfm_func(input, coeffs, tx_w, tx_type_, bd); |
Sebastien Alaiwan | 7a6e87b | 2017-07-04 12:32:46 +0200 | [diff] [blame] | 130 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 131 | DECLARE_ALIGNED(16, uint16_t, actual[64 * 64]) = { 0 }; |
Urvang Joshi | 0e301ba | 2017-12-11 17:49:13 -0800 | [diff] [blame] | 132 | ASSERT_LE(txfm2d_size, NELEMENTS(actual)); |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 133 | inv_txfm_func(coeffs, actual, tx_w, tx_type_, bd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 134 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 135 | double actual_max_error = 0; |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 136 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 137 | const double this_error = abs(expected[ni] - actual[ni]); |
| 138 | actual_max_error = AOMMAX(actual_max_error, this_error); |
| 139 | } |
| 140 | EXPECT_GE(max_error_, actual_max_error) |
| 141 | << " tx_w: " << tx_w << " tx_h " << tx_h << " tx_type: " << tx_type_; |
| 142 | if (actual_max_error > max_error_) { // exit early. |
| 143 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 144 | } |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 145 | avg_abs_error += compute_avg_abs_error<uint16_t, uint16_t>( |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 146 | expected, actual, txfm2d_size); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 149 | avg_abs_error /= count; |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 150 | EXPECT_GE(max_avg_error_, avg_abs_error) |
| 151 | << " tx_w: " << tx_w << " tx_h " << tx_h << " tx_type: " << tx_type_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 154 | private: |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 155 | bool TxfmUsesApproximation() { |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 156 | if (tx_size_wide[tx_size_] == 64 || tx_size_high[tx_size_] == 64) { |
| 157 | return true; |
| 158 | } |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 159 | return false; |
| 160 | } |
| 161 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 162 | int max_error_; |
| 163 | double max_avg_error_; |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 164 | TxType tx_type_; |
| 165 | TxSize tx_size_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
Angie Chiang | a369522 | 2018-04-23 15:07:07 -0700 | [diff] [blame] | 168 | static int max_error_ls[TX_SIZES_ALL] = { |
| 169 | 2, // 4x4 transform |
| 170 | 2, // 8x8 transform |
| 171 | 2, // 16x16 transform |
| 172 | 4, // 32x32 transform |
| 173 | 3, // 64x64 transform |
| 174 | 2, // 4x8 transform |
| 175 | 2, // 8x4 transform |
| 176 | 2, // 8x16 transform |
| 177 | 2, // 16x8 transform |
| 178 | 3, // 16x32 transform |
| 179 | 3, // 32x16 transform |
| 180 | 5, // 32x64 transform |
| 181 | 5, // 64x32 transform |
| 182 | 2, // 4x16 transform |
| 183 | 2, // 16x4 transform |
| 184 | 2, // 8x32 transform |
| 185 | 2, // 32x8 transform |
| 186 | 3, // 16x64 transform |
| 187 | 3, // 64x16 transform |
| 188 | }; |
| 189 | |
| 190 | static double avg_error_ls[TX_SIZES_ALL] = { |
| 191 | 0.002, // 4x4 transform |
| 192 | 0.05, // 8x8 transform |
| 193 | 0.07, // 16x16 transform |
| 194 | 0.4, // 32x32 transform |
| 195 | 0.3, // 64x64 transform |
| 196 | 0.02, // 4x8 transform |
| 197 | 0.02, // 8x4 transform |
| 198 | 0.04, // 8x16 transform |
| 199 | 0.07, // 16x8 transform |
| 200 | 0.4, // 16x32 transform |
| 201 | 0.5, // 32x16 transform |
| 202 | 0.38, // 32x64 transform |
| 203 | 0.39, // 64x32 transform |
| 204 | 0.2, // 4x16 transform |
| 205 | 0.2, // 16x4 transform |
| 206 | 0.2, // 8x32 transform |
| 207 | 0.2, // 32x8 transform |
| 208 | 0.38, // 16x64 transform |
| 209 | 0.38, // 64x16 transform |
| 210 | }; |
| 211 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 212 | vector<AV1InvTxfm2dParam> GetInvTxfm2dParamList() { |
| 213 | vector<AV1InvTxfm2dParam> param_list; |
Angie Chiang | a369522 | 2018-04-23 15:07:07 -0700 | [diff] [blame] | 214 | for (int s = 0; s < TX_SIZES; ++s) { |
| 215 | const int max_error = max_error_ls[s]; |
| 216 | const double avg_error = avg_error_ls[s]; |
| 217 | for (int t = 0; t < TX_TYPES; ++t) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 218 | const TxType tx_type = static_cast<TxType>(t); |
| 219 | const TxSize tx_size = static_cast<TxSize>(s); |
James Zern | ab1f9dc | 2018-04-30 20:09:00 -0700 | [diff] [blame] | 220 | if (libaom_test::IsTxSizeTypeValid(tx_size, tx_type)) { |
Angie Chiang | a369522 | 2018-04-23 15:07:07 -0700 | [diff] [blame] | 221 | param_list.push_back( |
| 222 | AV1InvTxfm2dParam(tx_type, tx_size, max_error, avg_error)); |
| 223 | } |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 224 | } |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 225 | } |
| 226 | return param_list; |
| 227 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 228 | |
| 229 | INSTANTIATE_TEST_CASE_P(C, AV1InvTxfm2d, |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 230 | ::testing::ValuesIn(GetInvTxfm2dParamList())); |
| 231 | |
| 232 | TEST_P(AV1InvTxfm2d, RunRoundtripCheck) { RunRoundtripCheck(); } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 233 | |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 234 | TEST(AV1InvTxfm2d, CfgTest) { |
| 235 | for (int bd_idx = 0; bd_idx < BD_NUM; ++bd_idx) { |
| 236 | int bd = libaom_test::bd_arr[bd_idx]; |
| 237 | int8_t low_range = libaom_test::low_range_arr[bd_idx]; |
| 238 | int8_t high_range = libaom_test::high_range_arr[bd_idx]; |
Urvang Joshi | a989d83 | 2017-12-11 16:41:26 -0800 | [diff] [blame] | 239 | for (int tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) { |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 240 | for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 241 | if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(tx_size), |
| 242 | static_cast<TxType>(tx_type)) == |
Angie Chiang | e3313cf | 2018-04-20 15:35:16 -0700 | [diff] [blame] | 243 | false) { |
Urvang Joshi | a989d83 | 2017-12-11 16:41:26 -0800 | [diff] [blame] | 244 | continue; |
| 245 | } |
Urvang Joshi | c502216 | 2017-11-21 15:57:42 -0800 | [diff] [blame] | 246 | TXFM_2D_FLIP_CFG cfg; |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 247 | av1_get_inv_txfm_cfg(static_cast<TxType>(tx_type), |
| 248 | static_cast<TxSize>(tx_size), &cfg); |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 249 | int8_t stage_range_col[MAX_TXFM_STAGE_NUM]; |
| 250 | int8_t stage_range_row[MAX_TXFM_STAGE_NUM]; |
| 251 | av1_gen_inv_stage_range(stage_range_col, stage_range_row, &cfg, |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 252 | static_cast<TxSize>(tx_size), bd); |
Angie Chiang | 0c7b8d8 | 2018-01-23 19:20:44 -0800 | [diff] [blame] | 253 | libaom_test::txfm_stage_range_check(stage_range_col, cfg.stage_num_col, |
Angie Chiang | d4327bc | 2018-01-22 20:54:04 -0800 | [diff] [blame] | 254 | cfg.cos_bit_col, low_range, |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 255 | high_range); |
Angie Chiang | 0c7b8d8 | 2018-01-23 19:20:44 -0800 | [diff] [blame] | 256 | libaom_test::txfm_stage_range_check(stage_range_row, cfg.stage_num_row, |
Angie Chiang | d4327bc | 2018-01-22 20:54:04 -0800 | [diff] [blame] | 257 | cfg.cos_bit_row, low_range, |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 258 | high_range); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 263 | |
James Zern | 9561280 | 2018-03-30 11:37:54 -0700 | [diff] [blame] | 264 | typedef ::testing::tuple<const LbdInvTxfm2dFunc> AV1LbdInvTxfm2dParam; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 265 | class AV1LbdInvTxfm2d : public ::testing::TestWithParam<AV1LbdInvTxfm2dParam> { |
| 266 | public: |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 267 | virtual void SetUp() { target_func_ = GET_PARAM(0); } |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 268 | void RunAV1InvTxfm2dTest(TxType tx_type, TxSize tx_size, int run_times, |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 269 | int gt_int16 = 0); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 270 | |
| 271 | private: |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 272 | LbdInvTxfm2dFunc target_func_; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 273 | }; |
| 274 | |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 275 | void AV1LbdInvTxfm2d::RunAV1InvTxfm2dTest(TxType tx_type, TxSize tx_size, |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 276 | int run_times, int gt_int16) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 277 | FwdTxfm2dFunc fwd_func_ = libaom_test::fwd_txfm_func_ls[tx_size]; |
| 278 | InvTxfm2dFunc ref_func_ = libaom_test::inv_txfm_func_ls[tx_size]; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 279 | if (fwd_func_ == NULL || ref_func_ == NULL || target_func_ == NULL) { |
| 280 | return; |
| 281 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 282 | const int bd = 8; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 283 | const int BLK_WIDTH = 64; |
| 284 | const int BLK_SIZE = BLK_WIDTH * BLK_WIDTH; |
| 285 | DECLARE_ALIGNED(16, int16_t, input[BLK_SIZE]) = { 0 }; |
| 286 | DECLARE_ALIGNED(32, int32_t, inv_input[BLK_SIZE]) = { 0 }; |
| 287 | DECLARE_ALIGNED(16, uint8_t, output[BLK_SIZE]) = { 0 }; |
| 288 | DECLARE_ALIGNED(16, uint16_t, ref_output[BLK_SIZE]) = { 0 }; |
| 289 | int stride = BLK_WIDTH; |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 290 | int rows = tx_size_high[tx_size]; |
| 291 | int cols = tx_size_wide[tx_size]; |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 292 | const int rows_nonezero = AOMMIN(32, rows); |
| 293 | const int cols_nonezero = AOMMIN(32, cols); |
| 294 | run_times /= (rows * cols); |
| 295 | run_times = AOMMAX(1, run_times); |
| 296 | const SCAN_ORDER *scan_order = get_default_scan(tx_size, tx_type); |
| 297 | const int16_t *scan = scan_order->scan; |
| 298 | const int16_t eobmax = rows_nonezero * cols_nonezero; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 299 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 300 | int randTimes = run_times == 1 ? (eobmax + 500) : 1; |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 301 | |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 302 | for (int cnt = 0; cnt < randTimes; ++cnt) { |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 303 | const int16_t max_in = (1 << (bd)) - 1; |
| 304 | for (int r = 0; r < BLK_WIDTH; ++r) { |
| 305 | for (int c = 0; c < BLK_WIDTH; ++c) { |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 306 | input[r * cols + c] = (cnt == 0) ? max_in : rnd.Rand8Extremes(); |
| 307 | output[r * stride + c] = (cnt == 0) ? 128 : rnd.Rand8(); |
| 308 | ref_output[r * stride + c] = output[r * stride + c]; |
| 309 | } |
| 310 | } |
| 311 | fwd_func_(input, inv_input, stride, tx_type, bd); |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 312 | |
| 313 | // produce eob input by setting high freq coeffs to zero |
| 314 | const int eob = AOMMIN(cnt + 1, eobmax); |
| 315 | for (int i = eob; i < eobmax; i++) { |
| 316 | inv_input[scan[i]] = 0; |
| 317 | } |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 318 | if (gt_int16) { |
| 319 | inv_input[scan[eob - 1]] = ((int32_t)INT16_MAX * 100 / 141); |
| 320 | } |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 321 | aom_usec_timer timer; |
| 322 | aom_usec_timer_start(&timer); |
| 323 | for (int i = 0; i < run_times; ++i) { |
| 324 | ref_func_(inv_input, ref_output, stride, tx_type, bd); |
| 325 | } |
| 326 | aom_usec_timer_mark(&timer); |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 327 | const double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer)); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 328 | aom_usec_timer_start(&timer); |
| 329 | for (int i = 0; i < run_times; ++i) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 330 | target_func_(inv_input, output, stride, tx_type, tx_size, eob); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 331 | } |
| 332 | aom_usec_timer_mark(&timer); |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 333 | const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer)); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 334 | if (run_times > 10) { |
| 335 | printf("txfm[%d] %3dx%-3d:%7.2f/%7.2fns", tx_type, cols, rows, time1, |
| 336 | time2); |
| 337 | printf("(%3.2f)\n", time1 / time2); |
| 338 | } |
| 339 | for (int r = 0; r < rows; ++r) { |
| 340 | for (int c = 0; c < cols; ++c) { |
Zoe Liu | 87fc8f9 | 2018-02-09 11:36:01 -0800 | [diff] [blame] | 341 | uint8_t ref_value = static_cast<uint8_t>(ref_output[r * stride + c]); |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 342 | if (ref_value != output[r * stride + c]) { |
| 343 | printf(" "); |
| 344 | } |
Zoe Liu | 87fc8f9 | 2018-02-09 11:36:01 -0800 | [diff] [blame] | 345 | ASSERT_EQ(ref_value, output[r * stride + c]) |
Peng Bin | e5f271a | 2018-03-13 14:09:14 +0800 | [diff] [blame] | 346 | << "[" << r << "," << c << "] " << cnt |
| 347 | << " tx_size: " << static_cast<int>(tx_size) |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 348 | << " tx_type: " << tx_type_name[tx_type] << " eob " << eob; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | } |
| 353 | |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 354 | TEST_P(AV1LbdInvTxfm2d, match) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 355 | for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) { |
| 356 | for (int i = 0; i < (int)TX_TYPES; ++i) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 357 | if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(j), |
| 358 | static_cast<TxType>(i))) { |
| 359 | RunAV1InvTxfm2dTest(static_cast<TxType>(i), static_cast<TxSize>(j), 1); |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 360 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 361 | } |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 362 | } |
| 363 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 364 | |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 365 | TEST_P(AV1LbdInvTxfm2d, gt_int16) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 366 | static const TxType types[] = { DCT_DCT, ADST_DCT, FLIPADST_DCT, IDTX, |
| 367 | V_DCT, H_DCT, H_ADST, H_FLIPADST }; |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 368 | for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 369 | const TxSize sz = static_cast<TxSize>(j); |
| 370 | for (uint8_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { |
| 371 | const TxType tp = types[i]; |
Peng Bin | 068f2cc | 2019-03-28 21:10:36 +0800 | [diff] [blame] | 372 | if (libaom_test::IsTxSizeTypeValid(sz, tp)) { |
| 373 | RunAV1InvTxfm2dTest(tp, sz, 1, 1); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | TEST_P(AV1LbdInvTxfm2d, DISABLED_Speed) { |
| 380 | for (int j = 1; j < (int)(TX_SIZES_ALL); ++j) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 381 | for (int i = 0; i < (int)TX_TYPES; ++i) { |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 382 | if (libaom_test::IsTxSizeTypeValid(static_cast<TxSize>(j), |
| 383 | static_cast<TxType>(i))) { |
| 384 | RunAV1InvTxfm2dTest(static_cast<TxType>(i), static_cast<TxSize>(j), |
Angie Chiang | e3313cf | 2018-04-20 15:35:16 -0700 | [diff] [blame] | 385 | 10000000); |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 386 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 387 | } |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 388 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 389 | } |
| 390 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 391 | #if HAVE_SSSE3 |
| 392 | #if defined(_MSC_VER) || defined(__SSSE3__) |
Peng Bin | 188b706 | 2018-02-28 11:20:42 +0800 | [diff] [blame] | 393 | #include "av1/common/x86/av1_inv_txfm_ssse3.h" |
Peng Bin | 188b706 | 2018-02-28 11:20:42 +0800 | [diff] [blame] | 394 | INSTANTIATE_TEST_CASE_P(SSSE3, AV1LbdInvTxfm2d, |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 395 | ::testing::Values(av1_lowbd_inv_txfm2d_add_ssse3)); |
| 396 | #endif // _MSC_VER || __SSSE3__ |
Peng Bin | 0ee9960 | 2018-03-06 19:38:15 +0800 | [diff] [blame] | 397 | #endif // HAVE_SSSE3 |
| 398 | |
| 399 | #if HAVE_AVX2 |
Peng Bin | 34b90dd | 2018-03-12 19:57:16 +0800 | [diff] [blame] | 400 | extern "C" void av1_lowbd_inv_txfm2d_add_avx2(const int32_t *input, |
| 401 | uint8_t *output, int stride, |
Pascal Massimino | a6fe432 | 2019-04-09 09:49:24 +0200 | [diff] [blame] | 402 | TxType tx_type, TxSize tx_size, |
Peng Bin | 34b90dd | 2018-03-12 19:57:16 +0800 | [diff] [blame] | 403 | int eob); |
| 404 | |
Peng Bin | 0ee9960 | 2018-03-06 19:38:15 +0800 | [diff] [blame] | 405 | INSTANTIATE_TEST_CASE_P(AVX2, AV1LbdInvTxfm2d, |
| 406 | ::testing::Values(av1_lowbd_inv_txfm2d_add_avx2)); |
Peng Bin | 0ee9960 | 2018-03-06 19:38:15 +0800 | [diff] [blame] | 407 | #endif // HAVE_AVX2 |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 408 | |
Yunqing Wang | 09c8534 | 2019-04-09 10:11:28 -0700 | [diff] [blame] | 409 | // TODO(yunqing): Re-enable this unit test for NEON version after the functions |
| 410 | // are fixed. |
Sachin Kumar Garg | 37b9a65 | 2019-04-24 20:43:27 +0530 | [diff] [blame] | 411 | #if HAVE_NEON |
| 412 | extern "C" void av1_lowbd_inv_txfm2d_add_neon(const int32_t *input, |
| 413 | uint8_t *output, int stride, |
| 414 | TX_TYPE tx_type, TX_SIZE tx_size, |
| 415 | int eob); |
| 416 | |
| 417 | INSTANTIATE_TEST_CASE_P(NEON, AV1LbdInvTxfm2d, |
| 418 | ::testing::Values(av1_lowbd_inv_txfm2d_add_neon)); |
| 419 | #endif // HAVE_NEON |
Venkat | 000f2f6 | 2018-07-05 12:03:05 +0530 | [diff] [blame] | 420 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 421 | } // namespace |