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 "./vpx_config.h"
17 #include "./vp8_rtcd.h"
18 #include "test/acm_random.h"
19 #include "test/clear_system_state.h"
20 #include "test/register_state_check.h"
21 #include "test/util.h"
22 #include "vp8/common/blockd.h"
23 #include "vp8/common/onyx.h"
24 #include "vp8/encoder/block.h"
25 #include "vp8/encoder/onyx_int.h"
26 #include "vp8/encoder/quantize.h"
27 #include "vpx/vpx_integer.h"
28 #include "vpx_mem/vpx_mem.h"
32 const int kNumBlocks = 25;
33 const int kNumBlockEntries = 16;
35 typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
37 typedef std::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
39 using libvpx_test::ACMRandom;
40 using std::make_tuple;
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 {
46 virtual ~QuantizeTestBase() {
47 vp8_remove_compressor(&vp8_comp_);
49 vpx_free(macroblockd_dst_);
50 macroblockd_dst_ = NULL;
51 libvpx_test::ClearSystemState();
55 void SetupCompressor() {
56 rnd_.Reset(ACMRandom::DeterministicSeed());
58 // The full configuration is necessary to generate the quantization tables.
59 VP8_CONFIG vp8_config;
60 memset(&vp8_config, 0, sizeof(vp8_config));
62 vp8_comp_ = vp8_create_compressor(&vp8_config);
64 // Set the tables based on a quantizer of 0.
65 vp8_set_quantizer(vp8_comp_, 0);
67 // Set up all the block/blockd pointers for the mb in vp8_comp_.
68 vp8cx_frame_init_quantizer(vp8_comp_);
70 // Copy macroblockd from the reference to get pre-set-up dequant values.
71 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>(
72 vpx_memalign(32, sizeof(*macroblockd_dst_)));
73 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
74 // Fix block pointers - currently they point to the blocks in the reference
76 vp8_setup_block_dptrs(macroblockd_dst_);
79 void UpdateQuantizer(int q) {
80 vp8_set_quantizer(vp8_comp_, q);
82 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
83 vp8_setup_block_dptrs(macroblockd_dst_);
86 void FillCoeffConstant(int16_t c) {
87 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
88 vp8_comp_->mb.coeff[i] = c;
92 void FillCoeffRandom() {
93 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
94 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
99 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
100 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
102 << "qcoeff mismatch";
103 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
104 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
106 << "dqcoeff mismatch";
107 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
108 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
113 MACROBLOCKD *macroblockd_dst_;
119 class QuantizeTest : public QuantizeTestBase,
120 public ::testing::TestWithParam<VP8QuantizeParam> {
122 virtual void SetUp() {
124 asm_quant_ = GET_PARAM(0);
125 c_quant_ = GET_PARAM(1);
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]));
140 VP8Quantize asm_quant_;
141 VP8Quantize c_quant_;
144 TEST_P(QuantizeTest, TestZeroInput) {
145 FillCoeffConstant(0);
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;
157 TEST_P(QuantizeTest, TestRandomInput) {
162 TEST_P(QuantizeTest, TestMultipleQ) {
163 for (int q = 0; q < QINDEX_RANGE; ++q) {
171 INSTANTIATE_TEST_CASE_P(
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)));
179 INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
180 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
181 &vp8_fast_quantize_b_c)));
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)));
189 #endif // HAVE_SSE4_1
192 INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest,
193 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon,
194 &vp8_fast_quantize_b_c)));
198 INSTANTIATE_TEST_CASE_P(
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)));
206 INSTANTIATE_TEST_CASE_P(
209 make_tuple(&vp8_fast_quantize_b_mmi, &vp8_fast_quantize_b_c),
210 make_tuple(&vp8_regular_quantize_b_mmi, &vp8_regular_quantize_b_c)));