Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <math.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | |
| 15 | #include "third_party/googletest/src/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 17 | #include "./av1_rtcd.h" |
| 18 | #include "./aom_dsp_rtcd.h" |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 19 | #include "test/acm_random.h" |
| 20 | #include "test/clear_system_state.h" |
| 21 | #include "test/register_state_check.h" |
| 22 | #include "test/util.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "av1/common/blockd.h" |
| 24 | #include "av1/common/scan.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 25 | #include "aom/aom_integer.h" |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 26 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | using libaom_test::ACMRandom; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 28 | |
| 29 | namespace { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 30 | typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); |
| 31 | typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 32 | typedef std::tr1::tuple<FwdTxfmFunc, InvTxfmFunc, InvTxfmFunc, TX_SIZE, int> |
| 33 | PartialInvTxfmParam; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 34 | const int kMaxNumCoeffs = 1024; |
James Zern | 49135d3 | 2014-07-16 18:58:16 -0700 | [diff] [blame] | 35 | class PartialIDctTest : public ::testing::TestWithParam<PartialInvTxfmParam> { |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 36 | public: |
| 37 | virtual ~PartialIDctTest() {} |
| 38 | virtual void SetUp() { |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 39 | ftxfm_ = GET_PARAM(0); |
| 40 | full_itxfm_ = GET_PARAM(1); |
| 41 | partial_itxfm_ = GET_PARAM(2); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 42 | tx_size_ = GET_PARAM(3); |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 43 | last_nonzero_ = GET_PARAM(4); |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 47 | |
| 48 | protected: |
| 49 | int last_nonzero_; |
| 50 | TX_SIZE tx_size_; |
James Zern | 49135d3 | 2014-07-16 18:58:16 -0700 | [diff] [blame] | 51 | FwdTxfmFunc ftxfm_; |
| 52 | InvTxfmFunc full_itxfm_; |
| 53 | InvTxfmFunc partial_itxfm_; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 56 | TEST_P(PartialIDctTest, RunQuantCheck) { |
| 57 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 58 | int size; |
| 59 | switch (tx_size_) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 60 | case TX_4X4: size = 4; break; |
| 61 | case TX_8X8: size = 8; break; |
| 62 | case TX_16X16: size = 16; break; |
| 63 | case TX_32X32: size = 32; break; |
| 64 | default: FAIL() << "Wrong Size!"; break; |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 65 | } |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 66 | DECLARE_ALIGNED(16, tran_low_t, test_coef_block1[kMaxNumCoeffs]); |
| 67 | DECLARE_ALIGNED(16, tran_low_t, test_coef_block2[kMaxNumCoeffs]); |
| 68 | DECLARE_ALIGNED(16, uint8_t, dst1[kMaxNumCoeffs]); |
| 69 | DECLARE_ALIGNED(16, uint8_t, dst2[kMaxNumCoeffs]); |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 70 | |
| 71 | const int count_test_block = 1000; |
| 72 | const int block_size = size * size; |
| 73 | |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 74 | DECLARE_ALIGNED(16, int16_t, input_extreme_block[kMaxNumCoeffs]); |
| 75 | DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kMaxNumCoeffs]); |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 76 | |
| 77 | int max_error = 0; |
| 78 | for (int i = 0; i < count_test_block; ++i) { |
| 79 | // clear out destination buffer |
| 80 | memset(dst1, 0, sizeof(*dst1) * block_size); |
| 81 | memset(dst2, 0, sizeof(*dst2) * block_size); |
| 82 | memset(test_coef_block1, 0, sizeof(*test_coef_block1) * block_size); |
| 83 | memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size); |
| 84 | |
| 85 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 86 | |
| 87 | for (int i = 0; i < count_test_block; ++i) { |
| 88 | // Initialize a test block with input range [-255, 255]. |
| 89 | if (i == 0) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 90 | for (int j = 0; j < block_size; ++j) input_extreme_block[j] = 255; |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 91 | } else if (i == 1) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 92 | for (int j = 0; j < block_size; ++j) input_extreme_block[j] = -255; |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 93 | } else { |
| 94 | for (int j = 0; j < block_size; ++j) { |
| 95 | input_extreme_block[j] = rnd.Rand8() % 2 ? 255 : -255; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | ftxfm_(input_extreme_block, output_ref_block, size); |
| 100 | |
| 101 | // quantization with maximum allowed step sizes |
| 102 | test_coef_block1[0] = (output_ref_block[0] / 1336) * 1336; |
| 103 | for (int j = 1; j < last_nonzero_; ++j) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 104 | test_coef_block1[av1_default_scan_orders[tx_size_].scan[j]] = |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 105 | (output_ref_block[j] / 1828) * 1828; |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 106 | } |
| 107 | |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 108 | ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size)); |
| 109 | ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block1, dst2, size)); |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 110 | |
| 111 | for (int j = 0; j < block_size; ++j) { |
| 112 | const int diff = dst1[j] - dst2[j]; |
| 113 | const int error = diff * diff; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 114 | if (max_error < error) max_error = error; |
Jingning Han | 7eaad70 | 2014-05-28 11:18:33 -0700 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | EXPECT_EQ(0, max_error) |
| 119 | << "Error: partial inverse transform produces different results"; |
| 120 | } |
| 121 | |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 122 | TEST_P(PartialIDctTest, ResultsMatch) { |
| 123 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 124 | int size; |
| 125 | switch (tx_size_) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 126 | case TX_4X4: size = 4; break; |
| 127 | case TX_8X8: size = 8; break; |
| 128 | case TX_16X16: size = 16; break; |
| 129 | case TX_32X32: size = 32; break; |
| 130 | default: FAIL() << "Wrong Size!"; break; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 131 | } |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 132 | DECLARE_ALIGNED(16, tran_low_t, test_coef_block1[kMaxNumCoeffs]); |
| 133 | DECLARE_ALIGNED(16, tran_low_t, test_coef_block2[kMaxNumCoeffs]); |
| 134 | DECLARE_ALIGNED(16, uint8_t, dst1[kMaxNumCoeffs]); |
| 135 | DECLARE_ALIGNED(16, uint8_t, dst2[kMaxNumCoeffs]); |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 136 | const int count_test_block = 1000; |
| 137 | const int max_coeff = 32766 / 4; |
| 138 | const int block_size = size * size; |
| 139 | int max_error = 0; |
| 140 | for (int i = 0; i < count_test_block; ++i) { |
| 141 | // clear out destination buffer |
| 142 | memset(dst1, 0, sizeof(*dst1) * block_size); |
| 143 | memset(dst2, 0, sizeof(*dst2) * block_size); |
| 144 | memset(test_coef_block1, 0, sizeof(*test_coef_block1) * block_size); |
| 145 | memset(test_coef_block2, 0, sizeof(*test_coef_block2) * block_size); |
| 146 | int max_energy_leftover = max_coeff * max_coeff; |
| 147 | for (int j = 0; j < last_nonzero_; ++j) { |
James Zern | a5768f6 | 2013-12-18 16:38:41 -0800 | [diff] [blame] | 148 | int16_t coef = static_cast<int16_t>(sqrt(1.0 * max_energy_leftover) * |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 149 | (rnd.Rand16() - 32768) / 65536); |
| 150 | max_energy_leftover -= coef * coef; |
| 151 | if (max_energy_leftover < 0) { |
| 152 | max_energy_leftover = 0; |
| 153 | coef = 0; |
| 154 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 155 | test_coef_block1[av1_default_scan_orders[tx_size_].scan[j]] = coef; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | memcpy(test_coef_block2, test_coef_block1, |
| 159 | sizeof(*test_coef_block2) * block_size); |
| 160 | |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 161 | ASM_REGISTER_STATE_CHECK(full_itxfm_(test_coef_block1, dst1, size)); |
| 162 | ASM_REGISTER_STATE_CHECK(partial_itxfm_(test_coef_block2, dst2, size)); |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 163 | |
| 164 | for (int j = 0; j < block_size; ++j) { |
| 165 | const int diff = dst1[j] - dst2[j]; |
| 166 | const int error = diff * diff; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 167 | if (max_error < error) max_error = error; |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | EXPECT_EQ(0, max_error) |
| 172 | << "Error: partial inverse transform produces different results"; |
| 173 | } |
| 174 | using std::tr1::make_tuple; |
| 175 | |
| 176 | INSTANTIATE_TEST_CASE_P( |
| 177 | C, PartialIDctTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 178 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 179 | &aom_idct32x32_34_add_c, TX_32X32, 34), |
| 180 | make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 181 | &aom_idct32x32_1_add_c, TX_32X32, 1), |
| 182 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 183 | &aom_idct16x16_10_add_c, TX_16X16, 10), |
| 184 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 185 | &aom_idct16x16_1_add_c, TX_16X16, 1), |
| 186 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 187 | &aom_idct8x8_12_add_c, TX_8X8, 12), |
| 188 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 189 | &aom_idct8x8_1_add_c, TX_8X8, 1), |
| 190 | make_tuple(&aom_fdct4x4_c, &aom_idct4x4_16_add_c, |
| 191 | &aom_idct4x4_1_add_c, TX_4X4, 1))); |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 192 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 193 | #if HAVE_NEON && !CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE |
James Zern | 2a66e9f | 2014-02-25 23:11:49 -0800 | [diff] [blame] | 194 | INSTANTIATE_TEST_CASE_P( |
| 195 | NEON, PartialIDctTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 196 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 197 | &aom_idct32x32_1_add_neon, TX_32X32, 1), |
| 198 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 199 | &aom_idct16x16_10_add_neon, TX_16X16, 10), |
| 200 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 201 | &aom_idct16x16_1_add_neon, TX_16X16, 1), |
| 202 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 203 | &aom_idct8x8_12_add_neon, TX_8X8, 12), |
| 204 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 205 | &aom_idct8x8_1_add_neon, TX_8X8, 1), |
| 206 | make_tuple(&aom_fdct4x4_c, &aom_idct4x4_16_add_c, |
| 207 | &aom_idct4x4_1_add_neon, TX_4X4, 1))); |
| 208 | #endif // HAVE_NEON && !CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE |
James Zern | 2a66e9f | 2014-02-25 23:11:49 -0800 | [diff] [blame] | 209 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 210 | #if HAVE_SSE2 && !CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 211 | INSTANTIATE_TEST_CASE_P( |
| 212 | SSE2, PartialIDctTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 213 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 214 | &aom_idct32x32_34_add_sse2, TX_32X32, 34), |
| 215 | make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 216 | &aom_idct32x32_1_add_sse2, TX_32X32, 1), |
| 217 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 218 | &aom_idct16x16_10_add_sse2, TX_16X16, 10), |
| 219 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 220 | &aom_idct16x16_1_add_sse2, TX_16X16, 1), |
| 221 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 222 | &aom_idct8x8_12_add_sse2, TX_8X8, 12), |
| 223 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 224 | &aom_idct8x8_1_add_sse2, TX_8X8, 1), |
| 225 | make_tuple(&aom_fdct4x4_c, &aom_idct4x4_16_add_c, |
| 226 | &aom_idct4x4_1_add_sse2, TX_4X4, 1))); |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 227 | #endif |
Jingning Han | b466ad5 | 2014-05-08 09:56:38 -0700 | [diff] [blame] | 228 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 229 | #if HAVE_SSSE3 && ARCH_X86_64 && !CONFIG_AOM_HIGHBITDEPTH && \ |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 230 | !CONFIG_EMULATE_HARDWARE |
James Zern | 8da5088 | 2014-11-13 10:59:54 -0800 | [diff] [blame] | 231 | INSTANTIATE_TEST_CASE_P( |
| 232 | SSSE3_64, PartialIDctTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 233 | ::testing::Values(make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 234 | &aom_idct8x8_12_add_ssse3, TX_8X8, 12))); |
James Zern | 8da5088 | 2014-11-13 10:59:54 -0800 | [diff] [blame] | 235 | #endif |
| 236 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 237 | #if HAVE_MSA && !CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE |
Parag Salasakar | 60052b6 | 2015-05-04 13:45:55 +0530 | [diff] [blame] | 238 | INSTANTIATE_TEST_CASE_P( |
| 239 | MSA, PartialIDctTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame^] | 240 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 241 | &aom_idct32x32_34_add_msa, TX_32X32, 34), |
| 242 | make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, |
| 243 | &aom_idct32x32_1_add_msa, TX_32X32, 1), |
| 244 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 245 | &aom_idct16x16_10_add_msa, TX_16X16, 10), |
| 246 | make_tuple(&aom_fdct16x16_c, &aom_idct16x16_256_add_c, |
| 247 | &aom_idct16x16_1_add_msa, TX_16X16, 1), |
| 248 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 249 | &aom_idct8x8_12_add_msa, TX_8X8, 10), |
| 250 | make_tuple(&aom_fdct8x8_c, &aom_idct8x8_64_add_c, |
| 251 | &aom_idct8x8_1_add_msa, TX_8X8, 1), |
| 252 | make_tuple(&aom_fdct4x4_c, &aom_idct4x4_16_add_c, |
| 253 | &aom_idct4x4_1_add_msa, TX_4X4, 1))); |
| 254 | #endif // HAVE_MSA && !CONFIG_AOM_HIGHBITDEPTH && !CONFIG_EMULATE_HARDWARE |
Parag Salasakar | 60052b6 | 2015-05-04 13:45:55 +0530 | [diff] [blame] | 255 | |
Yaowu Xu | ed7e3d2 | 2013-12-13 10:05:40 -0800 | [diff] [blame] | 256 | } // namespace |