2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
14 #include "third_party/googletest/src/include/gtest/gtest.h"
16 #include "./vp8_rtcd.h"
17 #include "./vpx_config.h"
18 #include "test/acm_random.h"
19 #include "test/bench.h"
20 #include "test/clear_system_state.h"
21 #include "test/register_state_check.h"
22 #include "test/util.h"
23 #include "vp8/common/blockd.h"
24 #include "vp8/common/onyx.h"
25 #include "vp8/encoder/block.h"
26 #include "vp8/encoder/onyx_int.h"
27 #include "vp8/encoder/quantize.h"
28 #include "vpx/vpx_integer.h"
29 #include "vpx_mem/vpx_mem.h"
33 const int kNumBlocks = 25;
34 const int kNumBlockEntries = 16;
36 typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
38 typedef std::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
40 using libvpx_test::ACMRandom;
41 using std::make_tuple;
43 // Create and populate a VP8_COMP instance which has a complete set of
44 // quantization inputs as well as a second MACROBLOCKD for output.
45 class QuantizeTestBase {
47 virtual ~QuantizeTestBase() {
48 vp8_remove_compressor(&vp8_comp_);
50 vpx_free(macroblockd_dst_);
51 macroblockd_dst_ = nullptr;
52 libvpx_test::ClearSystemState();
56 void SetupCompressor() {
57 rnd_.Reset(ACMRandom::DeterministicSeed());
59 // The full configuration is necessary to generate the quantization tables.
60 VP8_CONFIG vp8_config;
61 memset(&vp8_config, 0, sizeof(vp8_config));
63 vp8_comp_ = vp8_create_compressor(&vp8_config);
65 // Set the tables based on a quantizer of 0.
66 vp8_set_quantizer(vp8_comp_, 0);
68 // Set up all the block/blockd pointers for the mb in vp8_comp_.
69 vp8cx_frame_init_quantizer(vp8_comp_);
71 // Copy macroblockd from the reference to get pre-set-up dequant values.
72 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>(
73 vpx_memalign(32, sizeof(*macroblockd_dst_)));
74 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
75 // Fix block pointers - currently they point to the blocks in the reference
77 vp8_setup_block_dptrs(macroblockd_dst_);
80 void UpdateQuantizer(int q) {
81 vp8_set_quantizer(vp8_comp_, q);
83 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
84 vp8_setup_block_dptrs(macroblockd_dst_);
87 void FillCoeffConstant(int16_t c) {
88 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
89 vp8_comp_->mb.coeff[i] = c;
93 void FillCoeffRandom() {
94 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
95 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
100 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
101 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
103 << "qcoeff mismatch";
104 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
105 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
107 << "dqcoeff mismatch";
108 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
109 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
114 MACROBLOCKD *macroblockd_dst_;
120 class QuantizeTest : public QuantizeTestBase,
121 public ::testing::TestWithParam<VP8QuantizeParam>,
122 public AbstractBench {
124 virtual void SetUp() {
126 asm_quant_ = GET_PARAM(0);
127 c_quant_ = GET_PARAM(1);
131 asm_quant_(&vp8_comp_->mb.block[0], ¯oblockd_dst_->block[0]);
134 void RunComparison() {
135 for (int i = 0; i < kNumBlocks; ++i) {
136 ASM_REGISTER_STATE_CHECK(
137 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i]));
138 ASM_REGISTER_STATE_CHECK(
139 asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i]));
146 VP8Quantize asm_quant_;
147 VP8Quantize c_quant_;
149 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(QuantizeTest);
151 TEST_P(QuantizeTest, TestZeroInput) {
152 FillCoeffConstant(0);
156 TEST_P(QuantizeTest, TestLargeNegativeInput) {
157 FillCoeffConstant(0);
158 // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues
159 // like BUG=883 where the constant being compared was incorrectly initialized.
160 vp8_comp_->mb.coeff[0] = -8191;
164 TEST_P(QuantizeTest, TestRandomInput) {
169 TEST_P(QuantizeTest, TestMultipleQ) {
170 for (int q = 0; q < QINDEX_RANGE; ++q) {
177 TEST_P(QuantizeTest, DISABLED_Speed) {
181 PrintMedian("vp8 quantize");
185 INSTANTIATE_TEST_SUITE_P(
188 make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c),
189 make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c)));
193 INSTANTIATE_TEST_SUITE_P(
195 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
196 &vp8_fast_quantize_b_c)));
200 INSTANTIATE_TEST_SUITE_P(
201 SSE4_1, QuantizeTest,
202 ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1,
203 &vp8_regular_quantize_b_c)));
204 #endif // HAVE_SSE4_1
207 INSTANTIATE_TEST_SUITE_P(NEON, QuantizeTest,
208 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon,
209 &vp8_fast_quantize_b_c)));
213 INSTANTIATE_TEST_SUITE_P(
216 make_tuple(&vp8_fast_quantize_b_msa, &vp8_fast_quantize_b_c),
217 make_tuple(&vp8_regular_quantize_b_msa, &vp8_regular_quantize_b_c)));
221 INSTANTIATE_TEST_SUITE_P(
224 make_tuple(&vp8_fast_quantize_b_mmi, &vp8_fast_quantize_b_c),
225 make_tuple(&vp8_regular_quantize_b_mmi, &vp8_regular_quantize_b_c)));
229 INSTANTIATE_TEST_SUITE_P(
231 ::testing::Values(make_tuple(&vp8_regular_quantize_b_lsx,
232 &vp8_regular_quantize_b_c)));