Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -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 |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -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. |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "./av1_rtcd.h" |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 15 | #include "test/acm_random.h" |
| 16 | #include "test/clear_system_state.h" |
| 17 | #include "test/register_state_check.h" |
| 18 | #include "test/util.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | #include "av1/common/enums.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "aom_ports/mem.h" |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 22 | |
| 23 | namespace { |
| 24 | |
| 25 | using std::tr1::tuple; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | using libaom_test::ACMRandom; |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 27 | |
| 28 | typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride, |
| 29 | int tx_type, int bd); |
| 30 | |
| 31 | typedef void (*IHbdHtFunc)(const int32_t *coeff, uint16_t *output, int stride, |
| 32 | int tx_type, int bd); |
| 33 | |
| 34 | // Test parameter argument list: |
| 35 | // <transform reference function, |
| 36 | // optimized inverse transform function, |
| 37 | // inverse transform reference function, |
| 38 | // num_coeffs, |
| 39 | // tx_type, |
| 40 | // bit_depth> |
| 41 | typedef tuple<HbdHtFunc, IHbdHtFunc, IHbdHtFunc, int, int, int> IHbdHtParam; |
| 42 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | class AV1HighbdInvHTNxN : public ::testing::TestWithParam<IHbdHtParam> { |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 44 | public: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | virtual ~AV1HighbdInvHTNxN() {} |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 46 | |
| 47 | virtual void SetUp() { |
| 48 | txfm_ref_ = GET_PARAM(0); |
| 49 | inv_txfm_ = GET_PARAM(1); |
| 50 | inv_txfm_ref_ = GET_PARAM(2); |
| 51 | num_coeffs_ = GET_PARAM(3); |
| 52 | tx_type_ = GET_PARAM(4); |
| 53 | bit_depth_ = GET_PARAM(5); |
| 54 | |
| 55 | input_ = reinterpret_cast<int16_t *>( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 56 | aom_memalign(16, sizeof(input_[0]) * num_coeffs_)); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 57 | |
| 58 | // Note: |
| 59 | // Inverse transform input buffer is 32-byte aligned |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 60 | // Refer to <root>/av1/encoder/context_tree.c, function, |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 61 | // void alloc_mode_context(). |
| 62 | coeffs_ = reinterpret_cast<int32_t *>( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | aom_memalign(32, sizeof(coeffs_[0]) * num_coeffs_)); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 64 | output_ = reinterpret_cast<uint16_t *>( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | aom_memalign(32, sizeof(output_[0]) * num_coeffs_)); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 66 | output_ref_ = reinterpret_cast<uint16_t *>( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | aom_memalign(32, sizeof(output_ref_[0]) * num_coeffs_)); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | virtual void TearDown() { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | aom_free(input_); |
| 72 | aom_free(coeffs_); |
| 73 | aom_free(output_); |
| 74 | aom_free(output_ref_); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 75 | libaom_test::ClearSystemState(); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | protected: |
| 79 | void RunBitexactCheck(); |
| 80 | |
| 81 | private: |
| 82 | int GetStride() const { |
| 83 | if (16 == num_coeffs_) { |
| 84 | return 4; |
| 85 | } else if (64 == num_coeffs_) { |
| 86 | return 8; |
| 87 | } else if (256 == num_coeffs_) { |
| 88 | return 16; |
Yi Luo | 3bd8377 | 2017-01-10 10:11:49 -0800 | [diff] [blame] | 89 | } else if (1024 == num_coeffs_) { |
| 90 | return 32; |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 91 | } else { |
| 92 | return 0; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | HbdHtFunc txfm_ref_; |
| 97 | IHbdHtFunc inv_txfm_; |
| 98 | IHbdHtFunc inv_txfm_ref_; |
| 99 | int num_coeffs_; |
| 100 | int tx_type_; |
| 101 | int bit_depth_; |
| 102 | |
| 103 | int16_t *input_; |
| 104 | int32_t *coeffs_; |
| 105 | uint16_t *output_; |
| 106 | uint16_t *output_ref_; |
| 107 | }; |
| 108 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 109 | void AV1HighbdInvHTNxN::RunBitexactCheck() { |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 110 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 111 | const int stride = GetStride(); |
| 112 | const int num_tests = 20000; |
| 113 | const uint16_t mask = (1 << bit_depth_) - 1; |
| 114 | |
| 115 | for (int i = 0; i < num_tests; ++i) { |
| 116 | for (int j = 0; j < num_coeffs_; ++j) { |
| 117 | input_[j] = (rnd.Rand16() & mask) - (rnd.Rand16() & mask); |
| 118 | output_ref_[j] = rnd.Rand16() & mask; |
| 119 | output_[j] = output_ref_[j]; |
| 120 | } |
| 121 | |
| 122 | txfm_ref_(input_, coeffs_, stride, tx_type_, bit_depth_); |
| 123 | inv_txfm_ref_(coeffs_, output_ref_, stride, tx_type_, bit_depth_); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 124 | ASM_REGISTER_STATE_CHECK( |
| 125 | inv_txfm_(coeffs_, output_, stride, tx_type_, bit_depth_)); |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 126 | |
| 127 | for (int j = 0; j < num_coeffs_; ++j) { |
| 128 | EXPECT_EQ(output_ref_[j], output_[j]) |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 129 | << "Not bit-exact result at index: " << j << " At test block: " << i; |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 134 | TEST_P(AV1HighbdInvHTNxN, InvTransResultCheck) { RunBitexactCheck(); } |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 135 | |
| 136 | using std::tr1::make_tuple; |
| 137 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 138 | #if HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH |
| 139 | #define PARAM_LIST_4X4 \ |
| 140 | &av1_fwd_txfm2d_4x4_c, &av1_inv_txfm2d_add_4x4_sse4_1, \ |
| 141 | &av1_inv_txfm2d_add_4x4_c, 16 |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 143 | #define PARAM_LIST_8X8 \ |
| 144 | &av1_fwd_txfm2d_8x8_c, &av1_inv_txfm2d_add_8x8_sse4_1, \ |
| 145 | &av1_inv_txfm2d_add_8x8_c, 64 |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 146 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 147 | #define PARAM_LIST_16X16 \ |
| 148 | &av1_fwd_txfm2d_16x16_c, &av1_inv_txfm2d_add_16x16_sse4_1, \ |
| 149 | &av1_inv_txfm2d_add_16x16_c, 256 |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 150 | |
| 151 | const IHbdHtParam kArrayIhtParam[] = { |
| 152 | // 16x16 |
Yi Luo | bfe4c0a | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 153 | make_tuple(PARAM_LIST_16X16, DCT_DCT, 10), |
| 154 | make_tuple(PARAM_LIST_16X16, DCT_DCT, 12), |
| 155 | make_tuple(PARAM_LIST_16X16, ADST_DCT, 10), |
| 156 | make_tuple(PARAM_LIST_16X16, ADST_DCT, 12), |
| 157 | make_tuple(PARAM_LIST_16X16, DCT_ADST, 10), |
| 158 | make_tuple(PARAM_LIST_16X16, DCT_ADST, 12), |
| 159 | make_tuple(PARAM_LIST_16X16, ADST_ADST, 10), |
| 160 | make_tuple(PARAM_LIST_16X16, ADST_ADST, 12), |
| 161 | #if CONFIG_EXT_TX |
| 162 | make_tuple(PARAM_LIST_16X16, FLIPADST_DCT, 10), |
| 163 | make_tuple(PARAM_LIST_16X16, FLIPADST_DCT, 12), |
| 164 | make_tuple(PARAM_LIST_16X16, DCT_FLIPADST, 10), |
| 165 | make_tuple(PARAM_LIST_16X16, DCT_FLIPADST, 12), |
| 166 | make_tuple(PARAM_LIST_16X16, FLIPADST_FLIPADST, 10), |
| 167 | make_tuple(PARAM_LIST_16X16, FLIPADST_FLIPADST, 12), |
| 168 | make_tuple(PARAM_LIST_16X16, ADST_FLIPADST, 10), |
| 169 | make_tuple(PARAM_LIST_16X16, ADST_FLIPADST, 12), |
| 170 | make_tuple(PARAM_LIST_16X16, FLIPADST_ADST, 10), |
| 171 | make_tuple(PARAM_LIST_16X16, FLIPADST_ADST, 12), |
| 172 | #endif |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 173 | // 8x8 |
Yi Luo | bfe4c0a | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 174 | make_tuple(PARAM_LIST_8X8, DCT_DCT, 10), |
| 175 | make_tuple(PARAM_LIST_8X8, DCT_DCT, 12), |
| 176 | make_tuple(PARAM_LIST_8X8, ADST_DCT, 10), |
| 177 | make_tuple(PARAM_LIST_8X8, ADST_DCT, 12), |
| 178 | make_tuple(PARAM_LIST_8X8, DCT_ADST, 10), |
| 179 | make_tuple(PARAM_LIST_8X8, DCT_ADST, 12), |
| 180 | make_tuple(PARAM_LIST_8X8, ADST_ADST, 10), |
| 181 | make_tuple(PARAM_LIST_8X8, ADST_ADST, 12), |
| 182 | #if CONFIG_EXT_TX |
| 183 | make_tuple(PARAM_LIST_8X8, FLIPADST_DCT, 10), |
| 184 | make_tuple(PARAM_LIST_8X8, FLIPADST_DCT, 12), |
| 185 | make_tuple(PARAM_LIST_8X8, DCT_FLIPADST, 10), |
| 186 | make_tuple(PARAM_LIST_8X8, DCT_FLIPADST, 12), |
| 187 | make_tuple(PARAM_LIST_8X8, FLIPADST_FLIPADST, 10), |
| 188 | make_tuple(PARAM_LIST_8X8, FLIPADST_FLIPADST, 12), |
| 189 | make_tuple(PARAM_LIST_8X8, ADST_FLIPADST, 10), |
| 190 | make_tuple(PARAM_LIST_8X8, ADST_FLIPADST, 12), |
| 191 | make_tuple(PARAM_LIST_8X8, FLIPADST_ADST, 10), |
| 192 | make_tuple(PARAM_LIST_8X8, FLIPADST_ADST, 12), |
| 193 | #endif |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 194 | // 4x4 |
Yi Luo | bfe4c0a | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 195 | make_tuple(PARAM_LIST_4X4, DCT_DCT, 10), |
| 196 | make_tuple(PARAM_LIST_4X4, DCT_DCT, 12), |
| 197 | make_tuple(PARAM_LIST_4X4, ADST_DCT, 10), |
| 198 | make_tuple(PARAM_LIST_4X4, ADST_DCT, 12), |
| 199 | make_tuple(PARAM_LIST_4X4, DCT_ADST, 10), |
| 200 | make_tuple(PARAM_LIST_4X4, DCT_ADST, 12), |
| 201 | make_tuple(PARAM_LIST_4X4, ADST_ADST, 10), |
| 202 | make_tuple(PARAM_LIST_4X4, ADST_ADST, 12), |
| 203 | #if CONFIG_EXT_TX |
| 204 | make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 10), |
| 205 | make_tuple(PARAM_LIST_4X4, FLIPADST_DCT, 12), |
| 206 | make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 10), |
| 207 | make_tuple(PARAM_LIST_4X4, DCT_FLIPADST, 12), |
| 208 | make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 10), |
| 209 | make_tuple(PARAM_LIST_4X4, FLIPADST_FLIPADST, 12), |
| 210 | make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 10), |
| 211 | make_tuple(PARAM_LIST_4X4, ADST_FLIPADST, 12), |
| 212 | make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 10), |
| 213 | make_tuple(PARAM_LIST_4X4, FLIPADST_ADST, 12), |
| 214 | #endif |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 217 | INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdInvHTNxN, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 218 | ::testing::ValuesIn(kArrayIhtParam)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 219 | #endif // HAVE_SSE4_1 && CONFIG_AOM_HIGHBITDEPTH |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 220 | |
Yi Luo | 3bd8377 | 2017-01-10 10:11:49 -0800 | [diff] [blame] | 221 | #if HAVE_AVX2 && CONFIG_AOM_HIGHBITDEPTH |
| 222 | #define PARAM_LIST_32X32 \ |
| 223 | &av1_fwd_txfm2d_32x32_c, &av1_inv_txfm2d_add_32x32_avx2, \ |
| 224 | &av1_inv_txfm2d_add_32x32_c, 1024 |
| 225 | |
| 226 | const IHbdHtParam kArrayIhtParam32x32[] = { |
| 227 | // 32x32 |
| 228 | make_tuple(PARAM_LIST_32X32, DCT_DCT, 10), |
| 229 | make_tuple(PARAM_LIST_32X32, DCT_DCT, 12), |
| 230 | }; |
| 231 | |
| 232 | INSTANTIATE_TEST_CASE_P(AVX2, AV1HighbdInvHTNxN, |
| 233 | ::testing::ValuesIn(kArrayIhtParam32x32)); |
| 234 | |
| 235 | #endif // HAVE_AVX2 && CONFIG_AOM_HIGHBITDEPTH |
Yi Luo | 28cdee4 | 2016-05-19 14:13:07 -0700 | [diff] [blame] | 236 | } // namespace |