blob: 69da8994ca1d3b876195eac13fc0fac74bf5f348 [file] [log] [blame]
Johann53b68de2014-10-20 10:04:45 -07001/*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
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.
9 */
10
11#include <string.h>
12
13#include "third_party/googletest/src/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070014
15#include "./vpx_config.h"
16#include "./vp8_rtcd.h"
Johann53b68de2014-10-20 10:04:45 -070017#include "test/acm_random.h"
18#include "test/clear_system_state.h"
19#include "test/register_state_check.h"
20#include "test/util.h"
Johann53b68de2014-10-20 10:04:45 -070021#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"
28
29namespace {
30
31const int kNumBlocks = 25;
32const int kNumBlockEntries = 16;
33
34typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
Johann53b68de2014-10-20 10:04:45 -070035
36typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
Johann53b68de2014-10-20 10:04:45 -070037
38using libvpx_test::ACMRandom;
39using std::tr1::make_tuple;
40
41// Create and populate a VP8_COMP instance which has a complete set of
42// quantization inputs as well as a second MACROBLOCKD for output.
43class QuantizeTestBase {
44 public:
45 virtual ~QuantizeTestBase() {
46 vp8_remove_compressor(&vp8_comp_);
47 vp8_comp_ = NULL;
48 vpx_free(macroblockd_dst_);
49 macroblockd_dst_ = NULL;
50 libvpx_test::ClearSystemState();
51 }
52
53 protected:
54 void SetupCompressor() {
55 rnd_.Reset(ACMRandom::DeterministicSeed());
56
57 // The full configuration is necessary to generate the quantization tables.
Johannee30dd02014-11-25 12:06:56 -080058 VP8_CONFIG vp8_config;
James Zernf58011a2015-04-23 20:47:40 -070059 memset(&vp8_config, 0, sizeof(vp8_config));
Johann53b68de2014-10-20 10:04:45 -070060
Johannee30dd02014-11-25 12:06:56 -080061 vp8_comp_ = vp8_create_compressor(&vp8_config);
Johann53b68de2014-10-20 10:04:45 -070062
63 // Set the tables based on a quantizer of 0.
64 vp8_set_quantizer(vp8_comp_, 0);
65
66 // Set up all the block/blockd pointers for the mb in vp8_comp_.
67 vp8cx_frame_init_quantizer(vp8_comp_);
68
69 // Copy macroblockd from the reference to get pre-set-up dequant values.
Johanndae280d2014-11-04 10:32:51 -080070 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>(
71 vpx_memalign(32, sizeof(*macroblockd_dst_)));
James Zernf274c212015-04-23 20:42:19 -070072 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
Johann53b68de2014-10-20 10:04:45 -070073 // Fix block pointers - currently they point to the blocks in the reference
74 // structure.
75 vp8_setup_block_dptrs(macroblockd_dst_);
76 }
77
78 void UpdateQuantizer(int q) {
79 vp8_set_quantizer(vp8_comp_, q);
80
James Zernf274c212015-04-23 20:42:19 -070081 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
Johann53b68de2014-10-20 10:04:45 -070082 vp8_setup_block_dptrs(macroblockd_dst_);
83 }
84
85 void FillCoeffConstant(int16_t c) {
86 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
87 vp8_comp_->mb.coeff[i] = c;
88 }
89 }
90
91 void FillCoeffRandom() {
92 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
93 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
94 }
95 }
96
97 void CheckOutput() {
98 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
99 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
100 kNumBlockEntries))
101 << "qcoeff mismatch";
102 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
103 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
104 kNumBlockEntries))
105 << "dqcoeff mismatch";
106 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
107 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
108 << "eobs mismatch";
109 }
110
111 VP8_COMP *vp8_comp_;
112 MACROBLOCKD *macroblockd_dst_;
113
114 private:
115 ACMRandom rnd_;
116};
117
118class QuantizeTest : public QuantizeTestBase,
119 public ::testing::TestWithParam<VP8QuantizeParam> {
120 protected:
121 virtual void SetUp() {
122 SetupCompressor();
123 asm_quant_ = GET_PARAM(0);
124 c_quant_ = GET_PARAM(1);
125 }
126
127 void RunComparison() {
128 for (int i = 0; i < kNumBlocks; ++i) {
129 ASM_REGISTER_STATE_CHECK(
130 c_quant_(&vp8_comp_->mb.block[i], &vp8_comp_->mb.e_mbd.block[i]));
131 ASM_REGISTER_STATE_CHECK(
132 asm_quant_(&vp8_comp_->mb.block[i], &macroblockd_dst_->block[i]));
133 }
134
135 CheckOutput();
136 }
137
138 private:
139 VP8Quantize asm_quant_;
140 VP8Quantize c_quant_;
141};
142
Johann53b68de2014-10-20 10:04:45 -0700143TEST_P(QuantizeTest, TestZeroInput) {
144 FillCoeffConstant(0);
145 RunComparison();
146}
147
Johann08ad7e42014-11-20 13:24:55 -0800148TEST_P(QuantizeTest, TestLargeNegativeInput) {
149 FillCoeffConstant(0);
150 // Generate a qcoeff which contains 512/-512 (0x0100/0xFE00) to catch issues
151 // like BUG=883 where the constant being compared was incorrectly initialized.
152 vp8_comp_->mb.coeff[0] = -8191;
153 RunComparison();
154}
155
Johann53b68de2014-10-20 10:04:45 -0700156TEST_P(QuantizeTest, TestRandomInput) {
157 FillCoeffRandom();
158 RunComparison();
159}
160
161TEST_P(QuantizeTest, TestMultipleQ) {
162 for (int q = 0; q < QINDEX_RANGE; ++q) {
163 UpdateQuantizer(q);
164 FillCoeffRandom();
165 RunComparison();
166 }
167}
168
Johann53b68de2014-10-20 10:04:45 -0700169#if HAVE_SSE2
170INSTANTIATE_TEST_CASE_P(
171 SSE2, QuantizeTest,
172 ::testing::Values(
Johann9c6ce432014-11-04 08:20:25 -0800173 make_tuple(&vp8_fast_quantize_b_sse2, &vp8_fast_quantize_b_c),
174 make_tuple(&vp8_regular_quantize_b_sse2, &vp8_regular_quantize_b_c)));
Johann53b68de2014-10-20 10:04:45 -0700175#endif // HAVE_SSE2
176
177#if HAVE_SSSE3
178INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
Johann9c6ce432014-11-04 08:20:25 -0800179 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
180 &vp8_fast_quantize_b_c)));
Johann53b68de2014-10-20 10:04:45 -0700181#endif // HAVE_SSSE3
182
183#if HAVE_SSE4_1
Johann9c6ce432014-11-04 08:20:25 -0800184INSTANTIATE_TEST_CASE_P(
185 SSE4_1, QuantizeTest,
186 ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1,
187 &vp8_regular_quantize_b_c)));
Johann53b68de2014-10-20 10:04:45 -0700188#endif // HAVE_SSE4_1
189
Johannd1b64de2014-11-05 10:58:26 -0800190#if HAVE_NEON
Johann53b68de2014-10-20 10:04:45 -0700191INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest,
Johann9c6ce432014-11-04 08:20:25 -0800192 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon,
193 &vp8_fast_quantize_b_c)));
Johannd1b64de2014-11-05 10:58:26 -0800194#endif // HAVE_NEON
Parag Salasakar56aa0da2015-07-30 10:56:40 +0530195
196#if HAVE_MSA
197INSTANTIATE_TEST_CASE_P(
198 MSA, QuantizeTest,
199 ::testing::Values(
200 make_tuple(&vp8_fast_quantize_b_msa, &vp8_fast_quantize_b_c),
201 make_tuple(&vp8_regular_quantize_b_msa, &vp8_regular_quantize_b_c)));
202#endif // HAVE_MSA
Johann53b68de2014-10-20 10:04:45 -0700203} // namespace