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 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 13 | |
| 14 | #include "./av1_rtcd.h" |
| 15 | #include "./aom_dsp_rtcd.h" |
| 16 | |
| 17 | #include "test/acm_random.h" |
| 18 | #include "test/clear_system_state.h" |
| 19 | #include "test/register_state_check.h" |
| 20 | #include "test/transform_test_base.h" |
| 21 | #include "test/util.h" |
| 22 | #include "aom_ports/mem.h" |
| 23 | |
| 24 | using libaom_test::ACMRandom; |
| 25 | |
| 26 | namespace { |
| 27 | typedef void (*IhtFunc)(const tran_low_t *in, uint8_t *out, int stride, |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 28 | const TxfmParam *txfm_param); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 29 | using std::tr1::tuple; |
| 30 | using libaom_test::FhtFunc; |
| 31 | typedef tuple<FhtFunc, IhtFunc, int, aom_bit_depth_t, int> Ht4x4Param; |
| 32 | |
Lester Lu | d8b1ddc | 2017-07-06 16:13:29 -0700 | [diff] [blame] | 33 | void fht4x4_ref(const int16_t *in, tran_low_t *out, int stride, |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 34 | TxfmParam *txfm_param) { |
| 35 | av1_fht4x4_c(in, out, stride, txfm_param); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Lester Lu | d8b1ddc | 2017-07-06 16:13:29 -0700 | [diff] [blame] | 38 | void iht4x4_ref(const tran_low_t *in, uint8_t *out, int stride, |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 39 | const TxfmParam *txfm_param) { |
| 40 | av1_iht4x4_16_add_c(in, out, stride, txfm_param); |
Yi Luo | 8245b9a | 2016-11-17 14:56:43 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 43 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 44 | typedef void (*IhighbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride, |
| 45 | int tx_type, int bd); |
| 46 | typedef void (*HBDFhtFunc)(const int16_t *input, int32_t *output, int stride, |
| 47 | int tx_type, int bd); |
| 48 | |
| 49 | // HighbdHt4x4Param argument list: |
| 50 | // <Target optimized function, tx_type, bit depth> |
| 51 | typedef tuple<HBDFhtFunc, int, int> HighbdHt4x4Param; |
| 52 | |
| 53 | void highbe_fht4x4_ref(const int16_t *in, int32_t *out, int stride, int tx_type, |
| 54 | int bd) { |
| 55 | av1_fwd_txfm2d_4x4_c(in, out, stride, tx_type, bd); |
| 56 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 57 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | |
| 59 | class AV1Trans4x4HT : public libaom_test::TransformTestBase, |
| 60 | public ::testing::TestWithParam<Ht4x4Param> { |
| 61 | public: |
| 62 | virtual ~AV1Trans4x4HT() {} |
| 63 | |
| 64 | virtual void SetUp() { |
| 65 | fwd_txfm_ = GET_PARAM(0); |
| 66 | inv_txfm_ = GET_PARAM(1); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 67 | pitch_ = 4; |
David Barker | 7825022 | 2016-10-13 15:10:14 +0100 | [diff] [blame] | 68 | height_ = 4; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | fwd_txfm_ref = fht4x4_ref; |
Yi Luo | 8245b9a | 2016-11-17 14:56:43 -0800 | [diff] [blame] | 70 | inv_txfm_ref = iht4x4_ref; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | bit_depth_ = GET_PARAM(3); |
| 72 | mask_ = (1 << bit_depth_) - 1; |
| 73 | num_coeffs_ = GET_PARAM(4); |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 74 | txfm_param_.tx_type = GET_PARAM(2); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 75 | } |
| 76 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 77 | |
| 78 | protected: |
| 79 | void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 80 | fwd_txfm_(in, out, stride, &txfm_param_); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 84 | inv_txfm_(out, dst, stride, &txfm_param_); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | FhtFunc fwd_txfm_; |
| 88 | IhtFunc inv_txfm_; |
| 89 | }; |
| 90 | |
Yi Luo | 8245b9a | 2016-11-17 14:56:43 -0800 | [diff] [blame] | 91 | TEST_P(AV1Trans4x4HT, MemCheck) { RunMemCheck(); } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | TEST_P(AV1Trans4x4HT, CoeffCheck) { RunCoeffCheck(); } |
Yi Luo | 8245b9a | 2016-11-17 14:56:43 -0800 | [diff] [blame] | 93 | // Note: |
| 94 | // TODO(luoyi): Add tx_type, 9-15 for inverse transform. |
| 95 | // Need cleanup since same tests may be done in fdct4x4_test.cc |
| 96 | // TEST_P(AV1Trans4x4HT, AccuracyCheck) { RunAccuracyCheck(0); } |
| 97 | // TEST_P(AV1Trans4x4HT, InvAccuracyCheck) { RunInvAccuracyCheck(0); } |
| 98 | // TEST_P(AV1Trans4x4HT, InvCoeffCheck) { RunInvCoeffCheck(); } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 100 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 101 | class AV1HighbdTrans4x4HT : public ::testing::TestWithParam<HighbdHt4x4Param> { |
| 102 | public: |
| 103 | virtual ~AV1HighbdTrans4x4HT() {} |
| 104 | |
| 105 | virtual void SetUp() { |
| 106 | fwd_txfm_ = GET_PARAM(0); |
| 107 | fwd_txfm_ref_ = highbe_fht4x4_ref; |
| 108 | tx_type_ = GET_PARAM(1); |
| 109 | bit_depth_ = GET_PARAM(2); |
| 110 | mask_ = (1 << bit_depth_) - 1; |
| 111 | num_coeffs_ = 16; |
| 112 | |
| 113 | input_ = reinterpret_cast<int16_t *>( |
| 114 | aom_memalign(16, sizeof(int16_t) * num_coeffs_)); |
| 115 | output_ = reinterpret_cast<int32_t *>( |
| 116 | aom_memalign(16, sizeof(int32_t) * num_coeffs_)); |
| 117 | output_ref_ = reinterpret_cast<int32_t *>( |
| 118 | aom_memalign(16, sizeof(int32_t) * num_coeffs_)); |
| 119 | } |
| 120 | |
| 121 | virtual void TearDown() { |
| 122 | aom_free(input_); |
| 123 | aom_free(output_); |
| 124 | aom_free(output_ref_); |
| 125 | libaom_test::ClearSystemState(); |
| 126 | } |
| 127 | |
| 128 | protected: |
| 129 | void RunBitexactCheck(); |
| 130 | |
| 131 | private: |
| 132 | HBDFhtFunc fwd_txfm_; |
| 133 | HBDFhtFunc fwd_txfm_ref_; |
| 134 | int tx_type_; |
| 135 | int bit_depth_; |
| 136 | int mask_; |
| 137 | int num_coeffs_; |
| 138 | int16_t *input_; |
| 139 | int32_t *output_; |
| 140 | int32_t *output_ref_; |
| 141 | }; |
| 142 | |
| 143 | void AV1HighbdTrans4x4HT::RunBitexactCheck() { |
| 144 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 145 | int i, j; |
| 146 | const int stride = 4; |
| 147 | const int num_tests = 1000; |
| 148 | const int num_coeffs = 16; |
| 149 | |
| 150 | for (i = 0; i < num_tests; ++i) { |
| 151 | for (j = 0; j < num_coeffs; ++j) { |
| 152 | input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); |
| 153 | } |
| 154 | |
| 155 | fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_); |
| 156 | fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_); |
| 157 | |
| 158 | for (j = 0; j < num_coeffs; ++j) { |
| 159 | EXPECT_EQ(output_[j], output_ref_[j]) |
| 160 | << "Not bit-exact result at index: " << j << " at test block: " << i; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | TEST_P(AV1HighbdTrans4x4HT, HighbdCoeffCheck) { RunBitexactCheck(); } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 166 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 167 | |
| 168 | using std::tr1::make_tuple; |
| 169 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 170 | #if HAVE_SSE2 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | const Ht4x4Param kArrayHt4x4Param_sse2[] = { |
| 172 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 0, AOM_BITS_8, 16), |
| 173 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 1, AOM_BITS_8, 16), |
| 174 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 2, AOM_BITS_8, 16), |
| 175 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 3, AOM_BITS_8, 16), |
| 176 | #if CONFIG_EXT_TX |
| 177 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 4, AOM_BITS_8, 16), |
| 178 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 5, AOM_BITS_8, 16), |
| 179 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 6, AOM_BITS_8, 16), |
| 180 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 7, AOM_BITS_8, 16), |
| 181 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 8, AOM_BITS_8, 16), |
Yi Luo | 13d2aee | 2017-03-29 17:48:13 -0700 | [diff] [blame] | 182 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 9, AOM_BITS_8, 16), |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 183 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 10, AOM_BITS_8, 16), |
| 184 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 11, AOM_BITS_8, 16), |
| 185 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 12, AOM_BITS_8, 16), |
| 186 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 13, AOM_BITS_8, 16), |
| 187 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 14, AOM_BITS_8, 16), |
| 188 | make_tuple(&av1_fht4x4_sse2, &av1_iht4x4_16_add_sse2, 15, AOM_BITS_8, 16) |
| 189 | #endif // CONFIG_EXT_TX |
| 190 | }; |
| 191 | INSTANTIATE_TEST_CASE_P(SSE2, AV1Trans4x4HT, |
| 192 | ::testing::ValuesIn(kArrayHt4x4Param_sse2)); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 193 | #endif // HAVE_SSE2 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 194 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 195 | #if HAVE_SSE4_1 && CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | const HighbdHt4x4Param kArrayHighbdHt4x4Param[] = { |
| 197 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 10), |
| 198 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 0, 12), |
| 199 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 10), |
| 200 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 1, 12), |
| 201 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 10), |
| 202 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 2, 12), |
| 203 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 10), |
| 204 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 3, 12), |
| 205 | #if CONFIG_EXT_TX |
| 206 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 10), |
| 207 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 4, 12), |
| 208 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 10), |
| 209 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 5, 12), |
| 210 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 10), |
| 211 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 6, 12), |
| 212 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 10), |
| 213 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 7, 12), |
| 214 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 10), |
| 215 | make_tuple(&av1_fwd_txfm2d_4x4_sse4_1, 8, 12), |
| 216 | #endif // CONFIG_EXT_TX |
| 217 | }; |
| 218 | |
| 219 | INSTANTIATE_TEST_CASE_P(SSE4_1, AV1HighbdTrans4x4HT, |
| 220 | ::testing::ValuesIn(kArrayHighbdHt4x4Param)); |
| 221 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 222 | #endif // HAVE_SSE4_1 && CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 223 | |
| 224 | } // namespace |