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 | |
| 17 | #include "./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 | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 21 | #include "test/acm_random.h" |
| 22 | #include "test/av1_txfm_test.h" |
| 23 | #include "test/util.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | |
| 25 | using libaom_test::ACMRandom; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 26 | using libaom_test::FwdTxfm2dFunc; |
| 27 | using libaom_test::InvTxfm2dFunc; |
| 28 | using libaom_test::LbdInvTxfm2dFunc; |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 29 | using libaom_test::bd; |
| 30 | using libaom_test::compute_avg_abs_error; |
| 31 | using libaom_test::input_base; |
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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 39 | namespace { |
| 40 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | // AV1InvTxfm2dParam argument list: |
| 42 | // tx_type_, tx_size_, max_error_, max_avg_error_ |
| 43 | typedef std::tr1::tuple<TX_TYPE, TX_SIZE, int, double> AV1InvTxfm2dParam; |
| 44 | |
| 45 | class AV1InvTxfm2d : public ::testing::TestWithParam<AV1InvTxfm2dParam> { |
| 46 | public: |
| 47 | virtual void SetUp() { |
| 48 | tx_type_ = GET_PARAM(0); |
| 49 | tx_size_ = GET_PARAM(1); |
| 50 | max_error_ = GET_PARAM(2); |
| 51 | max_avg_error_ = GET_PARAM(3); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void RunRoundtripCheck() { |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 55 | int tx_w = tx_size_wide[tx_size_]; |
| 56 | int tx_h = tx_size_high[tx_size_]; |
| 57 | int txfm2d_size = tx_w * tx_h; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 58 | const FwdTxfm2dFunc fwd_txfm_func = libaom_test::fwd_txfm_func_ls[tx_size_]; |
| 59 | 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] | 60 | double avg_abs_error = 0; |
| 61 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Sebastien Alaiwan | f7829f4 | 2017-07-04 11:54:33 +0200 | [diff] [blame] | 62 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 63 | const int count = 500; |
Sebastien Alaiwan | f7829f4 | 2017-07-04 11:54:33 +0200 | [diff] [blame] | 64 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 65 | for (int ci = 0; ci < count; ci++) { |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 66 | DECLARE_ALIGNED(16, int16_t, input[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 67 | ASSERT_LE(txfm2d_size, NELEMENTS(input)); |
Sebastien Alaiwan | 7a6e87b | 2017-07-04 12:32:46 +0200 | [diff] [blame] | 68 | |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 69 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 70 | if (ci == 0) { |
| 71 | int extreme_input = input_base - 1; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 72 | input[ni] = extreme_input; // extreme case |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | } else { |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 74 | input[ni] = rnd.Rand16() % input_base; |
| 75 | } |
| 76 | } |
| 77 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 78 | DECLARE_ALIGNED(16, uint16_t, expected[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 79 | ASSERT_LE(txfm2d_size, NELEMENTS(expected)); |
| 80 | if (TxfmUsesApproximation()) { |
| 81 | // Compare reference forward HT + inverse HT vs forward HT + inverse HT. |
| 82 | double ref_input[64 * 64]; |
| 83 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_input)); |
| 84 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 85 | ref_input[ni] = input[ni]; |
| 86 | } |
| 87 | double ref_coeffs[64 * 64] = { 0 }; |
| 88 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs)); |
| 89 | ASSERT_EQ(tx_type_, DCT_DCT); |
| 90 | libaom_test::reference_hybrid_2d(ref_input, ref_coeffs, tx_type_, |
| 91 | tx_size_); |
Yaowu Xu | e3fb568 | 2017-12-15 07:51:50 -0800 | [diff] [blame] | 92 | DECLARE_ALIGNED(16, int32_t, ref_coeffs_int[64 * 64]) = { 0 }; |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 93 | ASSERT_LE(txfm2d_size, NELEMENTS(ref_coeffs_int)); |
| 94 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 95 | ref_coeffs_int[ni] = (int32_t)round(ref_coeffs[ni]); |
| 96 | } |
| 97 | inv_txfm_func(ref_coeffs_int, expected, tx_w, tx_type_, bd); |
| 98 | } else { |
| 99 | // Compare original input vs forward HT + inverse HT. |
| 100 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
| 101 | expected[ni] = input[ni]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 105 | DECLARE_ALIGNED(16, int32_t, coeffs[64 * 64]) = { 0 }; |
Urvang Joshi | 0e301ba | 2017-12-11 17:49:13 -0800 | [diff] [blame] | 106 | ASSERT_LE(txfm2d_size, NELEMENTS(coeffs)); |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 107 | fwd_txfm_func(input, coeffs, tx_w, tx_type_, bd); |
Sebastien Alaiwan | 7a6e87b | 2017-07-04 12:32:46 +0200 | [diff] [blame] | 108 | |
Yaowu Xu | b971c86 | 2017-12-14 17:58:50 -0800 | [diff] [blame] | 109 | DECLARE_ALIGNED(16, uint16_t, actual[64 * 64]) = { 0 }; |
Urvang Joshi | 0e301ba | 2017-12-11 17:49:13 -0800 | [diff] [blame] | 110 | ASSERT_LE(txfm2d_size, NELEMENTS(actual)); |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 111 | inv_txfm_func(coeffs, actual, tx_w, tx_type_, bd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 112 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 113 | double actual_max_error = 0; |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 114 | for (int ni = 0; ni < txfm2d_size; ++ni) { |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 115 | const double this_error = abs(expected[ni] - actual[ni]); |
| 116 | actual_max_error = AOMMAX(actual_max_error, this_error); |
| 117 | } |
| 118 | EXPECT_GE(max_error_, actual_max_error) |
| 119 | << " tx_w: " << tx_w << " tx_h " << tx_h << " tx_type: " << tx_type_; |
| 120 | if (actual_max_error > max_error_) { // exit early. |
| 121 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 122 | } |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 123 | avg_abs_error += compute_avg_abs_error<uint16_t, uint16_t>( |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 124 | expected, actual, txfm2d_size); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Sebastien Alaiwan | 6c933e1 | 2017-07-07 14:54:29 +0200 | [diff] [blame] | 127 | avg_abs_error /= count; |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 128 | EXPECT_GE(max_avg_error_, avg_abs_error) |
| 129 | << " tx_w: " << tx_w << " tx_h " << tx_h << " tx_type: " << tx_type_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 132 | private: |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 133 | bool TxfmUsesApproximation() { |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 134 | if (tx_size_wide[tx_size_] == 64 || tx_size_high[tx_size_] == 64) { |
| 135 | return true; |
| 136 | } |
Urvang Joshi | 5dbb9b4 | 2017-12-13 18:32:58 -0800 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 140 | int max_error_; |
| 141 | double max_avg_error_; |
| 142 | TX_TYPE tx_type_; |
| 143 | TX_SIZE tx_size_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 146 | vector<AV1InvTxfm2dParam> GetInvTxfm2dParamList() { |
| 147 | vector<AV1InvTxfm2dParam> param_list; |
Debargha Mukherjee | aa84f3e | 2018-01-04 12:45:10 -0800 | [diff] [blame] | 148 | for (int t = 0; t < TX_TYPES; ++t) { |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 149 | const TX_TYPE tx_type = static_cast<TX_TYPE>(t); |
| 150 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_4X4, 2, 0.002)); |
Angie Chiang | 0625027 | 2018-01-16 17:03:35 -0800 | [diff] [blame] | 151 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_8X8, 2, 0.05)); |
Angie Chiang | 463bd75 | 2018-01-30 17:11:27 -0800 | [diff] [blame] | 152 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_16X16, 2, 0.07)); |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 153 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_32X32, 4, 0.4)); |
Yue Chen | c1d9aef | 2017-12-28 16:13:13 -0800 | [diff] [blame] | 154 | if (tx_type == DCT_DCT) { // Other types not supported by these tx sizes. |
Angie Chiang | 0625027 | 2018-01-16 17:03:35 -0800 | [diff] [blame] | 155 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_64X64, 3, 0.3)); |
Yue Chen | c1d9aef | 2017-12-28 16:13:13 -0800 | [diff] [blame] | 156 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 157 | |
Angie Chiang | 463bd75 | 2018-01-30 17:11:27 -0800 | [diff] [blame] | 158 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_4X8, 2, 0.02)); |
| 159 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_8X4, 2, 0.02)); |
| 160 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_8X16, 2, 0.04)); |
Angie Chiang | a87dc76 | 2018-02-06 17:16:48 -0800 | [diff] [blame] | 161 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_16X8, 2, 0.07)); |
Debargha Mukherjee | 1158bff | 2018-01-01 18:23:59 -0800 | [diff] [blame] | 162 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_16X32, 3, 0.4)); |
Angie Chiang | a4c8048 | 2018-01-10 11:09:22 -0800 | [diff] [blame] | 163 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_32X16, 3, 0.5)); |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 164 | |
Debargha Mukherjee | 1158bff | 2018-01-01 18:23:59 -0800 | [diff] [blame] | 165 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_4X16, 2, 0.2)); |
| 166 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_16X4, 2, 0.2)); |
Urvang Joshi | 46e8fda | 2017-12-14 14:53:36 -0800 | [diff] [blame] | 167 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_8X32, 2, 0.2)); |
Debargha Mukherjee | 1158bff | 2018-01-01 18:23:59 -0800 | [diff] [blame] | 168 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_32X8, 2, 0.2)); |
Angie Chiang | d2db658 | 2017-08-06 20:46:48 -0700 | [diff] [blame] | 169 | |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 170 | if (tx_type == DCT_DCT) { // Other types not supported by these tx sizes. |
Yue Chen | 7580f25 | 2018-01-03 11:25:59 -0800 | [diff] [blame] | 171 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_32X64, 5, 0.38)); |
Angie Chiang | 4b29ea8 | 2018-01-12 14:52:36 -0800 | [diff] [blame] | 172 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_64X32, 5, 0.39)); |
Debargha Mukherjee | 1158bff | 2018-01-01 18:23:59 -0800 | [diff] [blame] | 173 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_16X64, 3, 0.38)); |
| 174 | param_list.push_back(AV1InvTxfm2dParam(tx_type, TX_64X16, 3, 0.38)); |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 175 | } |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 176 | } |
| 177 | return param_list; |
| 178 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 179 | |
| 180 | INSTANTIATE_TEST_CASE_P(C, AV1InvTxfm2d, |
Urvang Joshi | e035b5d | 2017-12-13 10:01:59 -0800 | [diff] [blame] | 181 | ::testing::ValuesIn(GetInvTxfm2dParamList())); |
| 182 | |
| 183 | TEST_P(AV1InvTxfm2d, RunRoundtripCheck) { RunRoundtripCheck(); } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 185 | TEST(AV1InvTxfm2d, CfgTest) { |
| 186 | for (int bd_idx = 0; bd_idx < BD_NUM; ++bd_idx) { |
| 187 | int bd = libaom_test::bd_arr[bd_idx]; |
| 188 | int8_t low_range = libaom_test::low_range_arr[bd_idx]; |
| 189 | int8_t high_range = libaom_test::high_range_arr[bd_idx]; |
Urvang Joshi | a989d83 | 2017-12-11 16:41:26 -0800 | [diff] [blame] | 190 | for (int tx_size = 0; tx_size < TX_SIZES_ALL; ++tx_size) { |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 191 | for (int tx_type = 0; tx_type < TX_TYPES; ++tx_type) { |
Urvang Joshi | a989d83 | 2017-12-11 16:41:26 -0800 | [diff] [blame] | 192 | if ((tx_size_wide[tx_size] == 64 || tx_size_high[tx_size] == 64) && |
| 193 | tx_type != DCT_DCT) { |
| 194 | continue; |
| 195 | } |
Urvang Joshi | c502216 | 2017-11-21 15:57:42 -0800 | [diff] [blame] | 196 | TXFM_2D_FLIP_CFG cfg; |
| 197 | av1_get_inv_txfm_cfg(static_cast<TX_TYPE>(tx_type), |
| 198 | static_cast<TX_SIZE>(tx_size), &cfg); |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 199 | int8_t stage_range_col[MAX_TXFM_STAGE_NUM]; |
| 200 | int8_t stage_range_row[MAX_TXFM_STAGE_NUM]; |
| 201 | av1_gen_inv_stage_range(stage_range_col, stage_range_row, &cfg, |
Debargha Mukherjee | 1158bff | 2018-01-01 18:23:59 -0800 | [diff] [blame] | 202 | (TX_SIZE)tx_size, bd); |
Angie Chiang | 0c7b8d8 | 2018-01-23 19:20:44 -0800 | [diff] [blame] | 203 | 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] | 204 | cfg.cos_bit_col, low_range, |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 205 | high_range); |
Angie Chiang | 0c7b8d8 | 2018-01-23 19:20:44 -0800 | [diff] [blame] | 206 | 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] | 207 | cfg.cos_bit_row, low_range, |
Angie Chiang | 9c7089a | 2017-08-08 16:21:11 -0700 | [diff] [blame] | 208 | high_range); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 213 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 214 | typedef std::tr1::tuple<const LbdInvTxfm2dFunc> AV1LbdInvTxfm2dParam; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 215 | class AV1LbdInvTxfm2d : public ::testing::TestWithParam<AV1LbdInvTxfm2dParam> { |
| 216 | public: |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 217 | virtual void SetUp() { target_func_ = GET_PARAM(0); } |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 218 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 219 | bool ValidTypeSize(TX_TYPE tx_type, TX_SIZE tx_size) const { |
| 220 | const int rows = tx_size_wide[tx_size]; |
| 221 | const int cols = tx_size_high[tx_size]; |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 222 | const TX_TYPE_1D vtype = vtx_tab[tx_type]; |
| 223 | const TX_TYPE_1D htype = htx_tab[tx_type]; |
Peng Bin | a7ba23f | 2018-02-10 15:12:31 +0800 | [diff] [blame] | 224 | if (rows >= 32 && (htype == ADST_1D || htype == FLIPADST_1D)) { |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 225 | return false; |
Peng Bin | a7ba23f | 2018-02-10 15:12:31 +0800 | [diff] [blame] | 226 | } else if (cols >= 32 && (vtype == ADST_1D || vtype == FLIPADST_1D)) { |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 227 | return false; |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 228 | } |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 229 | return true; |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 230 | } |
Peng Bin | e193a70 | 2018-02-10 11:01:23 +0800 | [diff] [blame] | 231 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 232 | void RunAV1InvTxfm2dTest(TX_TYPE tx_type, TX_SIZE tx_size, int run_times); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 233 | |
| 234 | private: |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 235 | LbdInvTxfm2dFunc target_func_; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 236 | }; |
| 237 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 238 | void AV1LbdInvTxfm2d::RunAV1InvTxfm2dTest(TX_TYPE tx_type, TX_SIZE tx_size, |
| 239 | int run_times) { |
| 240 | FwdTxfm2dFunc fwd_func_ = libaom_test::fwd_txfm_func_ls[tx_size]; |
| 241 | InvTxfm2dFunc ref_func_ = libaom_test::inv_txfm_func_ls[tx_size]; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 242 | if (fwd_func_ == NULL || ref_func_ == NULL || target_func_ == NULL) { |
| 243 | return; |
| 244 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 245 | const int bd = 8; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 246 | const int BLK_WIDTH = 64; |
| 247 | const int BLK_SIZE = BLK_WIDTH * BLK_WIDTH; |
| 248 | DECLARE_ALIGNED(16, int16_t, input[BLK_SIZE]) = { 0 }; |
| 249 | DECLARE_ALIGNED(32, int32_t, inv_input[BLK_SIZE]) = { 0 }; |
| 250 | DECLARE_ALIGNED(16, uint8_t, output[BLK_SIZE]) = { 0 }; |
| 251 | DECLARE_ALIGNED(16, uint16_t, ref_output[BLK_SIZE]) = { 0 }; |
| 252 | int stride = BLK_WIDTH; |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 253 | int rows = tx_size_high[tx_size]; |
| 254 | int cols = tx_size_wide[tx_size]; |
| 255 | run_times = AOMMAX(run_times / (rows * cols), 1); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 256 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 257 | int randTimes = run_times == 1 ? 500 : 1; |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 258 | for (int cnt = 0; cnt < randTimes; ++cnt) { |
| 259 | const int16_t max_in = (1 << (bd + 1)) - 1; |
| 260 | for (int r = 0; r < rows; ++r) { |
| 261 | for (int c = 0; c < cols; ++c) { |
| 262 | input[r * cols + c] = (cnt == 0) ? max_in : rnd.Rand8Extremes(); |
| 263 | output[r * stride + c] = (cnt == 0) ? 128 : rnd.Rand8(); |
| 264 | ref_output[r * stride + c] = output[r * stride + c]; |
| 265 | } |
| 266 | } |
| 267 | fwd_func_(input, inv_input, stride, tx_type, bd); |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 268 | int eob = AOMMIN(32, rows) * AOMMIN(32, cols); |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 269 | |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 270 | aom_usec_timer timer; |
| 271 | aom_usec_timer_start(&timer); |
| 272 | for (int i = 0; i < run_times; ++i) { |
| 273 | ref_func_(inv_input, ref_output, stride, tx_type, bd); |
| 274 | } |
| 275 | aom_usec_timer_mark(&timer); |
| 276 | double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer)); |
| 277 | aom_usec_timer_start(&timer); |
| 278 | for (int i = 0; i < run_times; ++i) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 279 | target_func_(inv_input, output, stride, tx_type, tx_size, eob); |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 280 | } |
| 281 | aom_usec_timer_mark(&timer); |
| 282 | double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer)); |
| 283 | if (run_times > 10) { |
| 284 | printf("txfm[%d] %3dx%-3d:%7.2f/%7.2fns", tx_type, cols, rows, time1, |
| 285 | time2); |
| 286 | printf("(%3.2f)\n", time1 / time2); |
| 287 | } |
| 288 | for (int r = 0; r < rows; ++r) { |
| 289 | for (int c = 0; c < cols; ++c) { |
Zoe Liu | 87fc8f9 | 2018-02-09 11:36:01 -0800 | [diff] [blame] | 290 | uint8_t ref_value = static_cast<uint8_t>(ref_output[r * stride + c]); |
| 291 | ASSERT_EQ(ref_value, output[r * stride + c]) |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 292 | << "[" << r << "," << c << "] " << cnt << " tx_size: " << tx_size |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 293 | << " tx_type: " << tx_type; |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 299 | TEST_P(AV1LbdInvTxfm2d, match) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 300 | for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) { |
| 301 | for (int i = 0; i < (int)TX_TYPES; ++i) { |
| 302 | if (ValidTypeSize((TX_TYPE)(i), (TX_SIZE)(j))) { |
| 303 | RunAV1InvTxfm2dTest((TX_TYPE)i, (TX_SIZE)(j), 1); |
| 304 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 305 | } |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 306 | } |
| 307 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 308 | |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 309 | TEST_P(AV1LbdInvTxfm2d, DISABLED_Speed) { |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 310 | for (int j = 0; j < (int)(TX_SIZES_ALL); ++j) { |
| 311 | for (int i = 0; i < (int)TX_TYPES; ++i) { |
| 312 | if (ValidTypeSize((TX_TYPE)(i), (TX_SIZE)(j))) { |
| 313 | RunAV1InvTxfm2dTest((TX_TYPE)i, (TX_SIZE)(j), 10000000); |
| 314 | } |
Peng Bin | 3285bc4 | 2018-02-09 16:54:46 +0800 | [diff] [blame] | 315 | } |
Peng Bin | ba7815a | 2018-02-08 21:31:18 +0800 | [diff] [blame] | 316 | } |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 317 | } |
| 318 | |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 319 | #if HAVE_SSSE3 |
| 320 | #if defined(_MSC_VER) || defined(__SSSE3__) |
Peng Bin | 188b706 | 2018-02-28 11:20:42 +0800 | [diff] [blame] | 321 | #include "av1/common/x86/av1_inv_txfm_ssse3.h" |
Peng Bin | 188b706 | 2018-02-28 11:20:42 +0800 | [diff] [blame] | 322 | INSTANTIATE_TEST_CASE_P(SSSE3, AV1LbdInvTxfm2d, |
Peng Bin | 56750cf | 2018-03-02 17:01:19 +0800 | [diff] [blame] | 323 | ::testing::Values(av1_lowbd_inv_txfm2d_add_ssse3)); |
| 324 | #endif // _MSC_VER || __SSSE3__ |
Peng Bin | 0ee9960 | 2018-03-06 19:38:15 +0800 | [diff] [blame] | 325 | #endif // HAVE_SSSE3 |
| 326 | |
| 327 | #if HAVE_AVX2 |
| 328 | #if defined(_MSC_VER) || defined(__AVX2__) |
| 329 | #include "av1/common/x86/av1_inv_txfm_avx2.h" |
| 330 | INSTANTIATE_TEST_CASE_P(AVX2, AV1LbdInvTxfm2d, |
| 331 | ::testing::Values(av1_lowbd_inv_txfm2d_add_avx2)); |
| 332 | #endif // (_MSC_VER) || (__AVX2__) |
| 333 | #endif // HAVE_AVX2 |
Peng Bin | 58bd7ce | 2018-02-07 21:10:54 +0800 | [diff] [blame] | 334 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 335 | } // namespace |