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 | |
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 | fed8e1c | 2016-10-07 09:46:05 -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); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 29 | using libaom_test::FhtFunc; |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 30 | using std::tr1::tuple; |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 31 | typedef tuple<FhtFunc, IhtFunc, TX_TYPE, aom_bit_depth_t, int> Ht32x32Param; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 32 | |
Lester Lu | d8b1ddc | 2017-07-06 16:13:29 -0700 | [diff] [blame] | 33 | void fht32x32_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_fht32x32_c(in, out, stride, txfm_param); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 38 | typedef void (*IHbdHtFunc)(const tran_low_t *in, uint8_t *out, int stride, |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 39 | TX_TYPE tx_type, int bd); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 40 | typedef void (*HbdHtFunc)(const int16_t *input, int32_t *output, int stride, |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 41 | TX_TYPE tx_type, int bd); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 42 | |
| 43 | // Target optimized function, tx_type, bit depth |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 44 | typedef tuple<HbdHtFunc, TX_TYPE, int> HighbdHt32x32Param; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 45 | |
| 46 | void highbd_fht32x32_ref(const int16_t *in, int32_t *out, int stride, |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 47 | TX_TYPE tx_type, int bd) { |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 48 | av1_fwd_txfm2d_32x32_c(in, out, stride, tx_type, bd); |
| 49 | } |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 50 | |
Sebastien Alaiwan | 5859636 | 2018-01-26 10:11:35 +0100 | [diff] [blame] | 51 | #if (HAVE_SSE2 || HAVE_AVX2) |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 52 | void dummy_inv_txfm(const tran_low_t *in, uint8_t *out, int stride, |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 53 | const TxfmParam *txfm_param) { |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 54 | (void)in; |
| 55 | (void)out; |
| 56 | (void)stride; |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 57 | (void)txfm_param; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 58 | } |
| 59 | #endif |
| 60 | |
| 61 | class AV1Trans32x32HT : public libaom_test::TransformTestBase, |
| 62 | public ::testing::TestWithParam<Ht32x32Param> { |
| 63 | public: |
| 64 | virtual ~AV1Trans32x32HT() {} |
| 65 | |
| 66 | virtual void SetUp() { |
| 67 | fwd_txfm_ = GET_PARAM(0); |
| 68 | inv_txfm_ = GET_PARAM(1); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 69 | pitch_ = 32; |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 70 | height_ = 32; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 71 | fwd_txfm_ref = fht32x32_ref; |
| 72 | bit_depth_ = GET_PARAM(3); |
| 73 | mask_ = (1 << bit_depth_) - 1; |
| 74 | num_coeffs_ = GET_PARAM(4); |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 75 | txfm_param_.tx_type = GET_PARAM(2); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 76 | } |
| 77 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
| 78 | |
| 79 | protected: |
| 80 | void RunFwdTxfm(const int16_t *in, tran_low_t *out, int stride) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 81 | fwd_txfm_(in, out, stride, &txfm_param_); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void RunInvTxfm(const tran_low_t *out, uint8_t *dst, int stride) { |
Lester Lu | 27319b6 | 2017-07-10 16:57:15 -0700 | [diff] [blame] | 85 | inv_txfm_(out, dst, stride, &txfm_param_); |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | FhtFunc fwd_txfm_; |
| 89 | IhtFunc inv_txfm_; |
| 90 | }; |
| 91 | |
| 92 | TEST_P(AV1Trans32x32HT, CoeffCheck) { RunCoeffCheck(); } |
Yi Luo | 157e45a | 2016-10-17 11:18:50 -0700 | [diff] [blame] | 93 | TEST_P(AV1Trans32x32HT, MemCheck) { RunMemCheck(); } |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 94 | |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 95 | class AV1HighbdTrans32x32HT |
| 96 | : public ::testing::TestWithParam<HighbdHt32x32Param> { |
| 97 | public: |
| 98 | virtual ~AV1HighbdTrans32x32HT() {} |
| 99 | |
| 100 | virtual void SetUp() { |
| 101 | fwd_txfm_ = GET_PARAM(0); |
| 102 | fwd_txfm_ref_ = highbd_fht32x32_ref; |
| 103 | tx_type_ = GET_PARAM(1); |
| 104 | bit_depth_ = GET_PARAM(2); |
| 105 | mask_ = (1 << bit_depth_) - 1; |
| 106 | num_coeffs_ = 1024; |
| 107 | |
| 108 | input_ = reinterpret_cast<int16_t *>( |
| 109 | aom_memalign(32, sizeof(int16_t) * num_coeffs_)); |
| 110 | output_ = reinterpret_cast<int32_t *>( |
| 111 | aom_memalign(32, sizeof(int32_t) * num_coeffs_)); |
| 112 | output_ref_ = reinterpret_cast<int32_t *>( |
| 113 | aom_memalign(32, sizeof(int32_t) * num_coeffs_)); |
| 114 | } |
| 115 | |
| 116 | virtual void TearDown() { |
| 117 | aom_free(input_); |
| 118 | aom_free(output_); |
| 119 | aom_free(output_ref_); |
| 120 | libaom_test::ClearSystemState(); |
| 121 | } |
| 122 | |
| 123 | protected: |
| 124 | void RunBitexactCheck(); |
| 125 | |
| 126 | private: |
| 127 | HbdHtFunc fwd_txfm_; |
| 128 | HbdHtFunc fwd_txfm_ref_; |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 129 | TX_TYPE tx_type_; |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 130 | int bit_depth_; |
| 131 | int mask_; |
| 132 | int num_coeffs_; |
| 133 | int16_t *input_; |
| 134 | int32_t *output_; |
| 135 | int32_t *output_ref_; |
| 136 | }; |
| 137 | |
| 138 | void AV1HighbdTrans32x32HT::RunBitexactCheck() { |
| 139 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 140 | int i, j; |
| 141 | const int stride = 32; |
| 142 | const int num_tests = 1000; |
| 143 | |
| 144 | for (i = 0; i < num_tests; ++i) { |
| 145 | for (j = 0; j < num_coeffs_; ++j) { |
| 146 | input_[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); |
| 147 | } |
| 148 | |
| 149 | fwd_txfm_ref_(input_, output_ref_, stride, tx_type_, bit_depth_); |
| 150 | ASM_REGISTER_STATE_CHECK( |
| 151 | fwd_txfm_(input_, output_, stride, tx_type_, bit_depth_)); |
| 152 | |
| 153 | for (j = 0; j < num_coeffs_; ++j) { |
| 154 | EXPECT_EQ(output_ref_[j], output_[j]) |
| 155 | << "Not bit-exact result at index: " << j << " at test block: " << i; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | TEST_P(AV1HighbdTrans32x32HT, HighbdCoeffCheck) { RunBitexactCheck(); } |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 161 | |
| 162 | using std::tr1::make_tuple; |
| 163 | |
Sebastien Alaiwan | 5859636 | 2018-01-26 10:11:35 +0100 | [diff] [blame] | 164 | #if HAVE_SSE2 |
Yi Luo | 9a3d29e | 2017-03-29 11:40:03 -0700 | [diff] [blame] | 165 | const Ht32x32Param kArrayHt32x32Param_sse2[] = { |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 166 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, DCT_DCT, AOM_BITS_8, 1024), |
| 167 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, ADST_DCT, AOM_BITS_8, 1024), |
| 168 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, DCT_ADST, AOM_BITS_8, 1024), |
| 169 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, ADST_ADST, AOM_BITS_8, 1024), |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 170 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, FLIPADST_DCT, AOM_BITS_8, |
| 171 | 1024), |
| 172 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, DCT_FLIPADST, AOM_BITS_8, |
| 173 | 1024), |
| 174 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, FLIPADST_FLIPADST, AOM_BITS_8, |
| 175 | 1024), |
| 176 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, ADST_FLIPADST, AOM_BITS_8, |
| 177 | 1024), |
| 178 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, FLIPADST_ADST, AOM_BITS_8, |
| 179 | 1024), |
| 180 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, IDTX, AOM_BITS_8, 1024), |
| 181 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, V_DCT, AOM_BITS_8, 1024), |
| 182 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, H_DCT, AOM_BITS_8, 1024), |
| 183 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, V_ADST, AOM_BITS_8, 1024), |
| 184 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, H_ADST, AOM_BITS_8, 1024), |
| 185 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, V_FLIPADST, AOM_BITS_8, 1024), |
| 186 | make_tuple(&av1_fht32x32_sse2, &dummy_inv_txfm, H_FLIPADST, AOM_BITS_8, 1024) |
Yi Luo | 9a3d29e | 2017-03-29 11:40:03 -0700 | [diff] [blame] | 187 | }; |
| 188 | INSTANTIATE_TEST_CASE_P(SSE2, AV1Trans32x32HT, |
| 189 | ::testing::ValuesIn(kArrayHt32x32Param_sse2)); |
Sebastien Alaiwan | 5859636 | 2018-01-26 10:11:35 +0100 | [diff] [blame] | 190 | #endif // HAVE_SSE2 |
Yi Luo | 9a3d29e | 2017-03-29 11:40:03 -0700 | [diff] [blame] | 191 | |
Sebastien Alaiwan | 5859636 | 2018-01-26 10:11:35 +0100 | [diff] [blame] | 192 | #if HAVE_AVX2 |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 193 | const Ht32x32Param kArrayHt32x32Param_avx2[] = { |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 194 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, DCT_DCT, AOM_BITS_8, 1024), |
| 195 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, ADST_DCT, AOM_BITS_8, 1024), |
| 196 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, DCT_ADST, AOM_BITS_8, 1024), |
| 197 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, ADST_ADST, AOM_BITS_8, 1024), |
Urvang Joshi | 2283d37 | 2017-10-02 17:16:45 -0700 | [diff] [blame] | 198 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, FLIPADST_DCT, AOM_BITS_8, |
| 199 | 1024), |
| 200 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, DCT_FLIPADST, AOM_BITS_8, |
| 201 | 1024), |
| 202 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, FLIPADST_FLIPADST, AOM_BITS_8, |
| 203 | 1024), |
| 204 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, ADST_FLIPADST, AOM_BITS_8, |
| 205 | 1024), |
| 206 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, FLIPADST_ADST, AOM_BITS_8, |
| 207 | 1024), |
| 208 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, IDTX, AOM_BITS_8, 1024), |
| 209 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, V_DCT, AOM_BITS_8, 1024), |
| 210 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, H_DCT, AOM_BITS_8, 1024), |
| 211 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, V_ADST, AOM_BITS_8, 1024), |
| 212 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, H_ADST, AOM_BITS_8, 1024), |
| 213 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, V_FLIPADST, AOM_BITS_8, 1024), |
| 214 | make_tuple(&av1_fht32x32_avx2, &dummy_inv_txfm, H_FLIPADST, AOM_BITS_8, 1024) |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 215 | }; |
| 216 | INSTANTIATE_TEST_CASE_P(AVX2, AV1Trans32x32HT, |
| 217 | ::testing::ValuesIn(kArrayHt32x32Param_avx2)); |
Sebastien Alaiwan | 5859636 | 2018-01-26 10:11:35 +0100 | [diff] [blame] | 218 | #endif // HAVE_AVX2 |
Yi Luo | fed8e1c | 2016-10-07 09:46:05 -0700 | [diff] [blame] | 219 | } // namespace |