Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
| 3 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include "third_party/googletest/src/include/gtest/gtest.h" |
| 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, |
| 28 | int tx_type); |
| 29 | using std::tr1::tuple; |
| 30 | using libaom_test::FhtFunc; |
| 31 | typedef tuple<FhtFunc, IhtFunc, int, aom_bit_depth_t, int> Ht32x32Param; |
| 32 | |
| 33 | void fht32x32_ref(const int16_t *in, tran_low_t *out, int stride, int tx_type) { |
| 34 | av1_fht32x32_c(in, out, stride, tx_type); |
| 35 | } |
| 36 | |
| 37 | #if CONFIG_AOM_HIGHBITDEPTH |
| 38 | typedef void (*IHbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride, |
| 39 | int tx_type, int bd); |
| 40 | typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride, |
| 41 | int tx_type, int bd); |
| 42 | |
| 43 | // Target optimized function, tx_type, bit depth |
| 44 | typedef tuple<HbdHtFunc, int, int> HighbdHt32x32Param; |
| 45 | |
| 46 | void highbd_fht32x32_ref(const int16_t *in, int32_t *out, int stride, |
| 47 | int tx_type, int bd) { |
| 48 | av1_fwd_txfm2d_32x32_c(in, out, stride, tx_type, bd); |
| 49 | } |
| 50 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 51 | |
| 52 | #if HAVE_AVX2 |
| 53 | void dummy_inv_txfm(const tran_low_t *in, uint8_t *out, int stride, |
| 54 | int tx_type) { |
| 55 | (void)in; |
| 56 | (void)out; |
| 57 | (void)stride; |
| 58 | (void)tx_type; |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | class AV1Trans32x32HT : public libaom_test::TransformTestBase, |
| 63 | public ::testing::TestWithParam<Ht32x32Param> { |
| 64 | public: |
| 65 | virtual ~AV1Trans32x32HT() {} |
| 66 | |
| 67 | virtual void SetUp() { |
| 68 | fwd_txfm_ = GET_PARAM(0); |
| 69 | inv_txfm_ = GET_PARAM(1); |
| 70 | tx_type_ = GET_PARAM(2); |
| 71 | pitch_ = 32; |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 72 | height_ = 32; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 73 | fwd_txfm_ref = fht32x32_ref; |
| 74 | bit_depth_ = GET_PARAM(3); |
| 75 | mask_ = (1 << bit_depth_) - 1; |
| 76 | num_coeffs_ = GET_PARAM(4); |
| 77 | } |
| 78 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 79 | |
| 80 | protected: |
| 81 | void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) { |
| 82 | fwd_txfm_(in, out, stride, tx_type_); |
| 83 | } |
| 84 | |
| 85 | void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) { |
| 86 | inv_txfm_(out, dst, stride, tx_type_); |
| 87 | } |
| 88 | |
| 89 | FhtFunc fwd_txfm_; |
| 90 | IhtFunc inv_txfm_; |
| 91 | }; |
| 92 | |
| 93 | TEST_P(AV1Trans32x32HT, CoeffCheck) { RunCoeffCheck(); } |
Yi Luo | 0c552df | 2016-10-24 16:30:55 -0700 | [diff] [blame] | 94 | // TODO(luoyi): As CONFIG_AOM_HIGHBITDEPTH = 1, our AVX2 implementation of |
| 95 | // av1_fht32x32 does not support tran_low_t (int32_t) as intermediate result. |
| 96 | // Therefore MemCheck test, tx_type=1,2,...,8 can't pass the test yet. |
| 97 | #if !CONFIG_AOM_HIGHBITDEPTH |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 98 | TEST_P(AV1Trans32x32HT, MemCheck) { RunMemCheck(); } |
Yi Luo | 1a0f27a | 2016-10-21 11:13:48 -0700 | [diff] [blame] | 99 | #endif |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 100 | |
| 101 | #if CONFIG_AOM_HIGHBITDEPTH |
| 102 | class AV1HighbdTrans32x32HT |
| 103 | : public ::testing::TestWithParam<HighbdHt32x32Param> { |
| 104 | public: |
| 105 | virtual ~AV1HighbdTrans32x32HT() {} |
| 106 | |
| 107 | virtual void SetUp() { |
| 108 | fwd_txfm_ = GET_PARAM(0); |
| 109 | fwd_txfm_ref_ = highbd_fht32x32_ref; |
| 110 | tx_type_ = GET_PARAM(1); |
| 111 | bit_depth_ = GET_PARAM(2); |
| 112 | mask_ = (1 << bit_depth_) - 1; |
| 113 | num_coeffs_ = 1024; |
| 114 | |
| 115 | input_ = reinterpret_cast<int16_t *>( |
| 116 | aom_memalign(32, sizeof(int16_t) * num_coeffs_)); |
| 117 | output_ = reinterpret_cast<int32_t *>( |
| 118 | aom_memalign(32, sizeof(int32_t) * num_coeffs_)); |
| 119 | output_ref_ = reinterpret_cast<int32_t *>( |
| 120 | aom_memalign(32, sizeof(int32_t) * num_coeffs_)); |
| 121 | } |
| 122 | |
| 123 | virtual void TearDown() { |
| 124 | aom_free(input_); |
| 125 | aom_free(output_); |
| 126 | aom_free(output_ref_); |
| 127 | libaom_test::ClearSystemState(); |
| 128 | } |
| 129 | |
| 130 | protected: |
| 131 | void RunBitexactCheck(); |
| 132 | |
| 133 | private: |
| 134 | HbdHtFunc fwd_txfm_; |
| 135 | HbdHtFunc fwd_txfm_ref_; |
| 136 | int tx_type_; |
| 137 | int bit_depth_; |
| 138 | int mask_; |
| 139 | int num_coeffs_; |
| 140 | int16_t *input_; |
| 141 | int32_t *output_; |
| 142 | int32_t *output_ref_; |
| 143 | }; |
| 144 | |
| 145 | void AV1HighbdTrans32x32HT::RunBitexactCheck() { |
| 146 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 147 | int i, j; |
| 148 | const int stride = 32; |
| 149 | const int num_tests = 1000; |
| 150 | |
| 151 | for (i = 0; i < num_tests; ++i) { |
| 152 | for (j = 0; j < num_coeffs_; ++j) { |
| 153 | input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); |
| 154 | } |
| 155 | |
| 156 | fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_); |
| 157 | ASM_REGISTER_STATE_CHECK( |
| 158 | fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_)); |
| 159 | |
| 160 | for (j = 0; j < num_coeffs_; ++j) { |
| 161 | EXPECT_EQ(output_ref_[j], output_[j]) |
| 162 | << "Not bit-exact result at index: " << j << " at test block: " << i; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | TEST_P(AV1HighbdTrans32x32HT, HighbdCoeffCheck) { RunBitexactCheck(); } |
| 168 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 169 | |
| 170 | using std::tr1::make_tuple; |
| 171 | |
| 172 | #if HAVE_AVX2 |
| 173 | const Ht32x32Param kArrayHt32x32Param_avx2[] = { |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 174 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 0, AOM_BITS_8, 1024), |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 175 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 1, AOM_BITS_8, 1024), |
| 176 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 2, AOM_BITS_8, 1024), |
| 177 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 3, AOM_BITS_8, 1024), |
| 178 | #if CONFIG_EXT_TX |
| 179 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 4, AOM_BITS_8, 1024), |
| 180 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 5, AOM_BITS_8, 1024), |
| 181 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 6, AOM_BITS_8, 1024), |
| 182 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 7, AOM_BITS_8, 1024), |
| 183 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 8, AOM_BITS_8, 1024), |
| 184 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 10, AOM_BITS_8, 1024), |
| 185 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 11, AOM_BITS_8, 1024), |
| 186 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 12, AOM_BITS_8, 1024), |
| 187 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 13, AOM_BITS_8, 1024), |
| 188 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 14, AOM_BITS_8, 1024), |
| 189 | make_tuple(&av1_fht32x32_avx2, dummy_inv_txfm, 15, AOM_BITS_8, 1024) |
| 190 | #endif // CONFIG_EXT_TX |
| 191 | }; |
| 192 | INSTANTIATE_TEST_CASE_P(AVX2, AV1Trans32x32HT, |
| 193 | ::testing::ValuesIn(kArrayHt32x32Param_avx2)); |
| 194 | #endif // HAVE_AVX2 |
| 195 | } // namespace |