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.
72 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>(
73 vpx_memalign(32, sizeof(*macroblockd_dst_)));
74 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd,
75 sizeof(*macroblockd_dst_));
76 // Fix block pointers - currently they point to the blocks in the reference
78 vp8_setup_block_dptrs(macroblockd_dst_);
81 void UpdateQuantizer(int q) {
82 vp8_set_quantizer(vp8_comp_, q);
84 vpx_memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd,
85 sizeof(*macroblockd_dst_));
86 vp8_setup_block_dptrs(macroblockd_dst_);
89 void FillCoeffConstant(int16_t c) {
90 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
91 vp8_comp_->mb.coeff[i] = c;
95 void FillCoeffRandom() {
96 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
97 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
102 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
103 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
105 << "qcoeff mismatch";
106 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
107 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
109 << "dqcoeff mismatch";
110 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
111 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
116 MACROBLOCKD *macroblockd_dst_;
122 class QuantizeTest : public QuantizeTestBase,
123 public ::testing::TestWithParam<VP8QuantizeParam> {
125 virtual void SetUp() {
127 asm_quant_ = GET_PARAM(0);
128 c_quant_ = GET_PARAM(1);
131 void RunComparison() {
132 for (int i = 0; i < kNumBlocks; ++i) {
133 ASM_REGISTER_STATE_CHECK(
134 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i]));
135 ASM_REGISTER_STATE_CHECK(
136 asm_quant_(&vp8_comp_->mb.block[i], ¯oblockd_dst_->block[i]));
143 VP8Quantize asm_quant_;
144 VP8Quantize c_quant_;
147 class QuantizeTestPair : public QuantizeTestBase,
148 public ::testing::TestWithParam<VP8QuantizePairParam> {
150 virtual void SetUp() {
152 asm_quant_pair_ = GET_PARAM(0);
153 c_quant_pair_ = GET_PARAM(1);
156 void RunComparison() {
157 // Skip the last, unpaired, block.
158 for (int i = 0; i < kNumBlocks - 1; i += 2) {
159 ASM_REGISTER_STATE_CHECK(c_quant_pair_(
160 &vp8_comp_->mb.block[i], &vp8_comp_->mb.block[i + 1],
161 &vp8_comp_->mb.e_mbd.block[i], &vp8_comp_->mb.e_mbd.block[i + 1]));
162 ASM_REGISTER_STATE_CHECK(asm_quant_pair_(
163 &vp8_comp_->mb.block[i], &vp8_comp_->mb.block[i + 1],
164 ¯oblockd_dst_->block[i], ¯oblockd_dst_->block[i + 1]));
171 VP8QuantizePair asm_quant_pair_;
172 VP8QuantizePair c_quant_pair_;
175 TEST_P(QuantizeTest, TestZeroInput) {
176 FillCoeffConstant(0);
180 TEST_P(QuantizeTest, TestRandomInput) {
185 TEST_P(QuantizeTest, TestMultipleQ) {
186 for (int q = 0; q < QINDEX_RANGE; ++q) {
193 TEST_P(QuantizeTestPair, TestZeroInput) {
194 FillCoeffConstant(0);
198 TEST_P(QuantizeTestPair, TestRandomInput) {
203 TEST_P(QuantizeTestPair, TestMultipleQ) {
204 for (int q = 0; q < QINDEX_RANGE; ++q) {
212 INSTANTIATE_TEST_CASE_P(
215 make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c),
216 make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c)));
220 INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
221 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
222 &vp8_fast_quantize_b_c)));
226 INSTANTIATE_TEST_CASE_P(
227 SSE4_1, QuantizeTest,
228 ::testing::Values(make_tuple(&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