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.
13 #include "third_party/googletest/src/include/gtest/gtest.h"
14 #include "test/acm_random.h"
15 #include "test/clear_system_state.h"
16 #include "test/register_state_check.h"
17 #include "test/util.h"
19 #include "./vpx_config.h"
20 #include "./vp8_rtcd.h"
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"
26 #include "vpx/vpx_integer.h"
27 #include "vpx_mem/vpx_mem.h"
31 const int kNumBlocks = 25;
32 const int kNumBlockEntries = 16;
34 typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
35 typedef void (*VP8QuantizePair)(BLOCK *b0, BLOCK *b1, BLOCKD *d0, BLOCKD *d1);
37 typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
38 typedef std::tr1::tuple<VP8QuantizePair, VP8QuantizePair> VP8QuantizePairParam;
40 using libvpx_test::ACMRandom;
41 using std::tr1::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_ = NULL;
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 *const vp8_config =
61 reinterpret_cast<VP8_CONFIG *>(vpx_calloc(sizeof(*vp8_config), 1));
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.
73 reinterpret_cast<MACROBLOCKD *>(
74 vpx_calloc(sizeof(*macroblockd_dst_), 1));
75 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd,
76 sizeof(*macroblockd_dst_));
77 // Fix block pointers - currently they point to the blocks in the reference
79 vp8_setup_block_dptrs(macroblockd_dst_);
82 void UpdateQuantizer(int q) {
83 vp8_set_quantizer(vp8_comp_, q);
85 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd,
86 sizeof(*macroblockd_dst_));
87 vp8_setup_block_dptrs(macroblockd_dst_);
90 void FillCoeffConstant(int16_t c) {
91 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
92 vp8_comp_->mb.coeff[i] = c;
96 void FillCoeffRandom() {
97 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
98 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
103 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
104 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
106 << "qcoeff mismatch";
107 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
108 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
110 << "dqcoeff mismatch";
111 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
112 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
117 MACROBLOCKD *macroblockd_dst_;
123 class QuantizeTest : public QuantizeTestBase,
124 public ::testing::TestWithParam<VP8QuantizeParam> {
126 virtual void SetUp() {
128 asm_quant_ = GET_PARAM(0);
129 c_quant_ = GET_PARAM(1);
132 void RunComparison() {
133 for (int i = 0; i < kNumBlocks; ++i) {
134 ASM_REGISTER_STATE_CHECK(
135 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i]));
136 ASM_REGISTER_STATE_CHECK(
137 asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i]));
144 VP8Quantize asm_quant_;
145 VP8Quantize c_quant_;
148 class QuantizeTestPair : public QuantizeTestBase,
149 public ::testing::TestWithParam<VP8QuantizePairParam> {
151 virtual void SetUp() {
153 asm_quant_pair_ = GET_PARAM(0);
154 c_quant_pair_ = GET_PARAM(1);
157 void RunComparison() {
158 // Skip the last, unpaired, block.
159 for (int i = 0; i < kNumBlocks - 1; i += 2) {
160 ASM_REGISTER_STATE_CHECK(c_quant_pair_(
161 &vp8_comp_->mb.block[i], &vp8_comp_->mb.block[i + 1],
162 &vp8_comp_->mb.e_mbd.block[i], &vp8_comp_->mb.e_mbd.block[i + 1]));
163 ASM_REGISTER_STATE_CHECK(asm_quant_pair_(
164 &vp8_comp_->mb.block[i], &vp8_comp_->mb.block[i + 1],
165 ¯oblockd_dst_->block[i], ¯oblockd_dst_->block[i + 1]));
172 VP8QuantizePair asm_quant_pair_;
173 VP8QuantizePair c_quant_pair_;
176 TEST_P(QuantizeTest, TestZeroInput) {
177 FillCoeffConstant(0);
181 TEST_P(QuantizeTest, TestRandomInput) {
186 TEST_P(QuantizeTest, TestMultipleQ) {
187 for (int q = 0; q < QINDEX_RANGE; ++q) {
194 TEST_P(QuantizeTestPair, TestZeroInput) {
195 FillCoeffConstant(0);
199 TEST_P(QuantizeTestPair, TestRandomInput) {
204 TEST_P(QuantizeTestPair, TestMultipleQ) {
205 for (int q = 0; q < QINDEX_RANGE; ++q) {
213 INSTANTIATE_TEST_CASE_P(
216 make_tuple(vp8_fast_quantize_b_sse2, vp8_fast_quantize_b_c),
217 make_tuple(vp8_regular_quantize_b_sse2, vp8_regular_quantize_b_c)));
221 INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
222 ::testing::Values(make_tuple(vp8_fast_quantize_b_ssse3,
223 vp8_fast_quantize_b_c)));
227 INSTANTIATE_TEST_CASE_P(SSE4_1, QuantizeTest, ::testing::Values(make_tuple(
228 vp8_regular_quantize_b_sse4_1,
229 vp8_regular_quantize_b_c)));
230 #endif // HAVE_SSE4_1
233 INSTANTIATE_TEST_CASE_P(MEDIA, QuantizeTest,
234 ::testing::Values(make_tuple(vp8_fast_quantize_b_armv6,
235 vp8_fast_quantize_b_c)));
239 INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest,
240 ::testing::Values(make_tuple(vp8_fast_quantize_b_neon,
241 vp8_fast_quantize_b_c)));
243 INSTANTIATE_TEST_CASE_P(
244 NEON, QuantizeTestPair,
245 ::testing::Values(make_tuple(vp8_fast_quantize_b_pair_neon,
246 vp8_fast_quantize_b_pair_c)));
247 #endif // HAVE_NEON_ASM