Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [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. |
| 10 | */ |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 11 | |
| 12 | #include <string.h> |
| 13 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 15 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 17 | #include "test/acm_random.h" |
| 18 | #include "test/clear_system_state.h" |
| 19 | #include "test/register_state_check.h" |
| 20 | #include "test/util.h" |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 21 | #include "vp8/common/blockd.h" |
| 22 | #include "vp8/common/onyx.h" |
| 23 | #include "vp8/encoder/block.h" |
| 24 | #include "vp8/encoder/onyx_int.h" |
| 25 | #include "vp8/encoder/quantize.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | #include "aom/aom_integer.h" |
| 27 | #include "aom_mem/aom_mem.h" |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 28 | |
| 29 | namespace { |
Yaowu Xu | 0818a7c | 2016-08-11 09:39:47 -0700 | [diff] [blame] | 30 | #if !CONFIG_AOM_QM |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 31 | |
| 32 | const int kNumBlocks = 25; |
| 33 | const int kNumBlockEntries = 16; |
| 34 | |
| 35 | typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 36 | |
| 37 | typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam; |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 38 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | using libaom_test::ACMRandom; |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 40 | using std::tr1::make_tuple; |
| 41 | |
| 42 | // Create and populate a VP8_COMP instance which has a complete set of |
| 43 | // quantization inputs as well as a second MACROBLOCKD for output. |
| 44 | class QuantizeTestBase { |
| 45 | public: |
| 46 | virtual ~QuantizeTestBase() { |
| 47 | vp8_remove_compressor(&vp8_comp_); |
| 48 | vp8_comp_ = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | aom_free(macroblockd_dst_); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 50 | macroblockd_dst_ = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | libaom_test::ClearSystemState(); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | protected: |
| 55 | void SetupCompressor() { |
| 56 | rnd_.Reset(ACMRandom::DeterministicSeed()); |
| 57 | |
| 58 | // The full configuration is necessary to generate the quantization tables. |
Johann | ee30dd0 | 2014-11-25 12:06:56 -0800 | [diff] [blame] | 59 | VP8_CONFIG vp8_config; |
James Zern | f58011a | 2015-04-23 20:47:40 -0700 | [diff] [blame] | 60 | memset(&vp8_config, 0, sizeof(vp8_config)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 61 | |
Johann | ee30dd0 | 2014-11-25 12:06:56 -0800 | [diff] [blame] | 62 | vp8_comp_ = vp8_create_compressor(&vp8_config); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 63 | |
| 64 | // Set the tables based on a quantizer of 0. |
| 65 | vp8_set_quantizer(vp8_comp_, 0); |
| 66 | |
| 67 | // Set up all the block/blockd pointers for the mb in vp8_comp_. |
| 68 | vp8cx_frame_init_quantizer(vp8_comp_); |
| 69 | |
| 70 | // Copy macroblockd from the reference to get pre-set-up dequant values. |
Johann | dae280d | 2014-11-04 10:32:51 -0800 | [diff] [blame] | 71 | macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>( |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | aom_memalign(32, sizeof(*macroblockd_dst_))); |
James Zern | f274c21 | 2015-04-23 20:42:19 -0700 | [diff] [blame] | 73 | memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 74 | // Fix block pointers - currently they point to the blocks in the reference |
| 75 | // structure. |
| 76 | vp8_setup_block_dptrs(macroblockd_dst_); |
| 77 | } |
| 78 | |
| 79 | void UpdateQuantizer(int q) { |
| 80 | vp8_set_quantizer(vp8_comp_, q); |
| 81 | |
James Zern | f274c21 | 2015-04-23 20:42:19 -0700 | [diff] [blame] | 82 | memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_)); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 83 | vp8_setup_block_dptrs(macroblockd_dst_); |
| 84 | } |
| 85 | |
| 86 | void FillCoeffConstant(int16_t c) { |
| 87 | for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 88 | vp8_comp_->mb.coeff[i] = c; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void FillCoeffRandom() { |
| 93 | for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) { |
| 94 | vp8_comp_->mb.coeff[i] = rnd_.Rand8(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void CheckOutput() { |
| 99 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff, |
| 100 | sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks * |
| 101 | kNumBlockEntries)) |
| 102 | << "qcoeff mismatch"; |
| 103 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff, |
| 104 | sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks * |
| 105 | kNumBlockEntries)) |
| 106 | << "dqcoeff mismatch"; |
| 107 | EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs, |
| 108 | sizeof(*macroblockd_dst_->eobs) * kNumBlocks)) |
| 109 | << "eobs mismatch"; |
| 110 | } |
| 111 | |
| 112 | VP8_COMP *vp8_comp_; |
| 113 | MACROBLOCKD *macroblockd_dst_; |
| 114 | |
| 115 | private: |
| 116 | ACMRandom rnd_; |
| 117 | }; |
| 118 | |
| 119 | class QuantizeTest : public QuantizeTestBase, |
| 120 | public ::testing::TestWithParam<VP8QuantizeParam> { |
| 121 | protected: |
| 122 | virtual void SetUp() { |
| 123 | SetupCompressor(); |
| 124 | asm_quant_ = GET_PARAM(0); |
| 125 | c_quant_ = GET_PARAM(1); |
| 126 | } |
| 127 | |
| 128 | void RunComparison() { |
| 129 | for (int i = 0; i < kNumBlocks; ++i) { |
| 130 | ASM_REGISTER_STATE_CHECK( |
| 131 | c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i])); |
| 132 | ASM_REGISTER_STATE_CHECK( |
| 133 | asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i])); |
| 134 | } |
| 135 | |
| 136 | CheckOutput(); |
| 137 | } |
| 138 | |
| 139 | private: |
| 140 | VP8Quantize asm_quant_; |
| 141 | VP8Quantize c_quant_; |
| 142 | }; |
| 143 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 144 | TEST_P(QuantizeTest, TestZeroInput) { |
| 145 | FillCoeffConstant(0); |
| 146 | RunComparison(); |
| 147 | } |
| 148 | |
Johann | 08ad7e4 | 2014-11-20 13:24:55 -0800 | [diff] [blame] | 149 | TEST_P(QuantizeTest, TestLargeNegativeInput) { |
| 150 | FillCoeffConstant(0); |
| 151 | // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues |
| 152 | // like BUG=883 where the constant being compared was incorrectly initialized. |
| 153 | vp8_comp_->mb.coeff[0] = -8191; |
| 154 | RunComparison(); |
| 155 | } |
| 156 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 157 | TEST_P(QuantizeTest, TestRandomInput) { |
| 158 | FillCoeffRandom(); |
| 159 | RunComparison(); |
| 160 | } |
| 161 | |
| 162 | TEST_P(QuantizeTest, TestMultipleQ) { |
| 163 | for (int q = 0; q < QINDEX_RANGE; ++q) { |
| 164 | UpdateQuantizer(q); |
| 165 | FillCoeffRandom(); |
| 166 | RunComparison(); |
| 167 | } |
| 168 | } |
| 169 | |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 170 | #if HAVE_SSE2 |
| 171 | INSTANTIATE_TEST_CASE_P( |
| 172 | SSE2, QuantizeTest, |
| 173 | ::testing::Values( |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 174 | make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c), |
| 175 | make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 176 | #endif // HAVE_SSE2 |
| 177 | |
| 178 | #if HAVE_SSSE3 |
| 179 | INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest, |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 180 | ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3, |
| 181 | &vp8_fast_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 182 | #endif // HAVE_SSSE3 |
| 183 | |
| 184 | #if HAVE_SSE4_1 |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 185 | INSTANTIATE_TEST_CASE_P( |
| 186 | SSE4_1, QuantizeTest, |
| 187 | ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1, |
| 188 | &vp8_regular_quantize_b_c))); |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 189 | #endif // HAVE_SSE4_1 |
| 190 | |
Johann | d1b64de | 2014-11-05 10:58:26 -0800 | [diff] [blame] | 191 | #if HAVE_NEON |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 192 | INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest, |
Johann | 9c6ce43 | 2014-11-04 08:20:25 -0800 | [diff] [blame] | 193 | ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon, |
| 194 | &vp8_fast_quantize_b_c))); |
Johann | d1b64de | 2014-11-05 10:58:26 -0800 | [diff] [blame] | 195 | #endif // HAVE_NEON |
Parag Salasakar | 56aa0da | 2015-07-30 10:56:40 +0530 | [diff] [blame] | 196 | |
| 197 | #if HAVE_MSA |
| 198 | INSTANTIATE_TEST_CASE_P( |
| 199 | MSA, QuantizeTest, |
| 200 | ::testing::Values( |
| 201 | make_tuple(&vp8_fast_quantize_b_msa, &vp8_fast_quantize_b_c), |
| 202 | make_tuple(&vp8_regular_quantize_b_msa, &vp8_regular_quantize_b_c))); |
| 203 | #endif // HAVE_MSA |
Yaowu Xu | 0818a7c | 2016-08-11 09:39:47 -0700 | [diff] [blame] | 204 | #endif // CONFIG_AOM_QM |
Johann | 53b68de | 2014-10-20 10:04:45 -0700 | [diff] [blame] | 205 | } // namespace |