blob: 4f61484a269aad2ba87f7b513748c4d77bce03d9 [file] [log] [blame]
Johann53b68de2014-10-20 10:04:45 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Johann53b68de2014-10-20 10:04:45 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*/
Johann53b68de2014-10-20 10:04:45 -070011
12#include <string.h>
13
Tom Finegan7a07ece2017-02-07 17:14:05 -080014#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
Jingning Han097d59c2015-07-29 14:51:36 -070015
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.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"
Yaowu Xuf883b422016-08-30 14:01:10 -070026#include "aom/aom_integer.h"
27#include "aom_mem/aom_mem.h"
Johann53b68de2014-10-20 10:04:45 -070028
29namespace {
Yaowu Xu0818a7c2016-08-11 09:39:47 -070030#if !CONFIG_AOM_QM
Johann53b68de2014-10-20 10:04:45 -070031
32const int kNumBlocks = 25;
33const int kNumBlockEntries = 16;
34
35typedef void (*VP8Quantize)(BLOCK *b, BLOCKD *d);
Johann53b68de2014-10-20 10:04:45 -070036
37typedef std::tr1::tuple<VP8Quantize, VP8Quantize> VP8QuantizeParam;
Johann53b68de2014-10-20 10:04:45 -070038
Yaowu Xuc27fc142016-08-22 16:08:15 -070039using libaom_test::ACMRandom;
Johann53b68de2014-10-20 10:04:45 -070040using std::tr1::make_tuple;
41
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.
44class QuantizeTestBase {
45 public:
46 virtual ~QuantizeTestBase() {
47 vp8_remove_compressor(&vp8_comp_);
48 vp8_comp_ = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -070049 aom_free(macroblockd_dst_);
Johann53b68de2014-10-20 10:04:45 -070050 macroblockd_dst_ = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 libaom_test::ClearSystemState();
Johann53b68de2014-10-20 10:04:45 -070052 }
53
54 protected:
55 void SetupCompressor() {
56 rnd_.Reset(ACMRandom::DeterministicSeed());
57
58 // The full configuration is necessary to generate the quantization tables.
Johannee30dd02014-11-25 12:06:56 -080059 VP8_CONFIG vp8_config;
James Zernf58011a2015-04-23 20:47:40 -070060 memset(&vp8_config, 0, sizeof(vp8_config));
Johann53b68de2014-10-20 10:04:45 -070061
Johannee30dd02014-11-25 12:06:56 -080062 vp8_comp_ = vp8_create_compressor(&vp8_config);
Johann53b68de2014-10-20 10:04:45 -070063
64 // Set the tables based on a quantizer of 0.
65 vp8_set_quantizer(vp8_comp_, 0);
66
67 // Set up all the block/blockd pointers for the mb in vp8_comp_.
68 vp8cx_frame_init_quantizer(vp8_comp_);
69
70 // Copy macroblockd from the reference to get pre-set-up dequant values.
Johanndae280d2014-11-04 10:32:51 -080071 macroblockd_dst_ = reinterpret_cast<MACROBLOCKD *>(
Yaowu Xuf883b422016-08-30 14:01:10 -070072 aom_memalign(32, sizeof(*macroblockd_dst_)));
James Zernf274c212015-04-23 20:42:19 -070073 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
Johann53b68de2014-10-20 10:04:45 -070074 // Fix block pointers - currently they point to the blocks in the reference
75 // structure.
76 vp8_setup_block_dptrs(macroblockd_dst_);
77 }
78
79 void UpdateQuantizer(int q) {
80 vp8_set_quantizer(vp8_comp_, q);
81
James Zernf274c212015-04-23 20:42:19 -070082 memcpy(macroblockd_dst_, &vp8_comp_->mb.e_mbd, sizeof(*macroblockd_dst_));
Johann53b68de2014-10-20 10:04:45 -070083 vp8_setup_block_dptrs(macroblockd_dst_);
84 }
85
86 void FillCoeffConstant(int16_t c) {
87 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
88 vp8_comp_->mb.coeff[i] = c;
89 }
90 }
91
92 void FillCoeffRandom() {
93 for (int i = 0; i < kNumBlocks * kNumBlockEntries; ++i) {
94 vp8_comp_->mb.coeff[i] = rnd_.Rand8();
95 }
96 }
97
98 void CheckOutput() {
99 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.qcoeff, macroblockd_dst_->qcoeff,
100 sizeof(*macroblockd_dst_->qcoeff) * kNumBlocks *
101 kNumBlockEntries))
102 << "qcoeff mismatch";
103 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.dqcoeff, macroblockd_dst_->dqcoeff,
104 sizeof(*macroblockd_dst_->dqcoeff) * kNumBlocks *
105 kNumBlockEntries))
106 << "dqcoeff mismatch";
107 EXPECT_EQ(0, memcmp(vp8_comp_->mb.e_mbd.eobs, macroblockd_dst_->eobs,
108 sizeof(*macroblockd_dst_->eobs) * kNumBlocks))
109 << "eobs mismatch";
110 }
111
112 VP8_COMP *vp8_comp_;
113 MACROBLOCKD *macroblockd_dst_;
114
115 private:
116 ACMRandom rnd_;
117};
118
119class QuantizeTest : public QuantizeTestBase,
120 public ::testing::TestWithParam<VP8QuantizeParam> {
121 protected:
122 virtual void SetUp() {
123 SetupCompressor();
124 asm_quant_ = GET_PARAM(0);
125 c_quant_ = GET_PARAM(1);
126 }
127
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], &macroblockd_dst_->block[i]));
134 }
135
136 CheckOutput();
137 }
138
139 private:
140 VP8Quantize asm_quant_;
141 VP8Quantize c_quant_;
142};
143
Johann53b68de2014-10-20 10:04:45 -0700144TEST_P(QuantizeTest, TestZeroInput) {
145 FillCoeffConstant(0);
146 RunComparison();
147}
148
Johann08ad7e42014-11-20 13:24:55 -0800149TEST_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;
154 RunComparison();
155}
156
Johann53b68de2014-10-20 10:04:45 -0700157TEST_P(QuantizeTest, TestRandomInput) {
158 FillCoeffRandom();
159 RunComparison();
160}
161
162TEST_P(QuantizeTest, TestMultipleQ) {
163 for (int q = 0; q < QINDEX_RANGE; ++q) {
164 UpdateQuantizer(q);
165 FillCoeffRandom();
166 RunComparison();
167 }
168}
169
Johann53b68de2014-10-20 10:04:45 -0700170#if HAVE_SSE2
171INSTANTIATE_TEST_CASE_P(
172 SSE2, QuantizeTest,
173 ::testing::Values(
Johann9c6ce432014-11-04 08:20:25 -0800174 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)));
Johann53b68de2014-10-20 10:04:45 -0700176#endif // HAVE_SSE2
177
178#if HAVE_SSSE3
179INSTANTIATE_TEST_CASE_P(SSSE3, QuantizeTest,
Johann9c6ce432014-11-04 08:20:25 -0800180 ::testing::Values(make_tuple(&vp8_fast_quantize_b_ssse3,
181 &vp8_fast_quantize_b_c)));
Johann53b68de2014-10-20 10:04:45 -0700182#endif // HAVE_SSSE3
183
184#if HAVE_SSE4_1
Johann9c6ce432014-11-04 08:20:25 -0800185INSTANTIATE_TEST_CASE_P(
186 SSE4_1, QuantizeTest,
187 ::testing::Values(make_tuple(&vp8_regular_quantize_b_sse4_1,
188 &vp8_regular_quantize_b_c)));
Johann53b68de2014-10-20 10:04:45 -0700189#endif // HAVE_SSE4_1
190
Johannd1b64de2014-11-05 10:58:26 -0800191#if HAVE_NEON
Johann53b68de2014-10-20 10:04:45 -0700192INSTANTIATE_TEST_CASE_P(NEON, QuantizeTest,
Johann9c6ce432014-11-04 08:20:25 -0800193 ::testing::Values(make_tuple(&vp8_fast_quantize_b_neon,
194 &vp8_fast_quantize_b_c)));
Johannd1b64de2014-11-05 10:58:26 -0800195#endif // HAVE_NEON
Parag Salasakar56aa0da2015-07-30 10:56:40 +0530196
197#if HAVE_MSA
198INSTANTIATE_TEST_CASE_P(
199 MSA, QuantizeTest,
200 ::testing::Values(
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)));
203#endif // HAVE_MSA
Yaowu Xu0818a7c2016-08-11 09:39:47 -0700204#endif // CONFIG_AOM_QM
Johann53b68de2014-10-20 10:04:45 -0700205} // namespace