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.
16 #include "third_party/googletest/src/include/gtest/gtest.h"
18 #include "./vpx_config.h"
19 #include "./vp9_rtcd.h"
20 #include "test/acm_random.h"
21 #include "test/clear_system_state.h"
22 #include "test/register_state_check.h"
23 #include "test/util.h"
24 #include "vp9/common/vp9_entropy.h"
25 #include "vpx/vpx_codec.h"
26 #include "vpx/vpx_integer.h"
27 #include "vpx_dsp/vpx_dsp_common.h"
29 using libvpx_test::ACMRandom;
32 const int kNumIterations = 1000;
34 typedef int64_t (*HBDBlockErrorFunc)(const tran_low_t *coeff,
35 const tran_low_t *dqcoeff,
36 intptr_t block_size, int64_t *ssz,
39 typedef std::tuple<HBDBlockErrorFunc, HBDBlockErrorFunc, vpx_bit_depth_t>
42 typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff,
43 const tran_low_t *dqcoeff,
44 intptr_t block_size, int64_t *ssz);
46 template <BlockErrorFunc fn>
47 int64_t BlockError8BitWrapper(const tran_low_t *coeff,
48 const tran_low_t *dqcoeff, intptr_t block_size,
49 int64_t *ssz, int bps) {
51 return fn(coeff, dqcoeff, block_size, ssz);
54 class BlockErrorTest : public ::testing::TestWithParam<BlockErrorParam> {
56 virtual ~BlockErrorTest() {}
57 virtual void SetUp() {
58 error_block_op_ = GET_PARAM(0);
59 ref_error_block_op_ = GET_PARAM(1);
60 bit_depth_ = GET_PARAM(2);
63 virtual void TearDown() { libvpx_test::ClearSystemState(); }
66 vpx_bit_depth_t bit_depth_;
67 HBDBlockErrorFunc error_block_op_;
68 HBDBlockErrorFunc ref_error_block_op_;
70 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BlockErrorTest);
72 TEST_P(BlockErrorTest, OperationCheck) {
73 ACMRandom rnd(ACMRandom::DeterministicSeed());
74 DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
75 DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
76 int err_count_total = 0;
77 int first_failure = -1;
83 const int msb = bit_depth_ + 8 - 1;
84 for (int i = 0; i < kNumIterations; ++i) {
86 block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
87 for (int j = 0; j < block_size; j++) {
88 // coeff and dqcoeff will always have at least the same sign, and this
89 // can be used for optimization, so generate test input precisely.
92 coeff[j] = rnd(1 << msb);
93 dqcoeff[j] = rnd(1 << msb);
96 coeff[j] = -rnd(1 << msb);
97 dqcoeff[j] = -rnd(1 << msb);
101 ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
102 ASM_REGISTER_STATE_CHECK(
103 ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
104 err_count += (ref_ret != ret) | (ref_ssz != ssz);
105 if (err_count && !err_count_total) {
108 err_count_total += err_count;
110 EXPECT_EQ(0, err_count_total)
111 << "Error: Error Block Test, C output doesn't match optimized output. "
112 << "First failed at test case " << first_failure;
115 TEST_P(BlockErrorTest, ExtremeValues) {
116 ACMRandom rnd(ACMRandom::DeterministicSeed());
117 DECLARE_ALIGNED(16, tran_low_t, coeff[4096]);
118 DECLARE_ALIGNED(16, tran_low_t, dqcoeff[4096]);
119 int err_count_total = 0;
120 int first_failure = -1;
126 const int msb = bit_depth_ + 8 - 1;
127 int max_val = ((1 << msb) - 1);
128 for (int i = 0; i < kNumIterations; ++i) {
132 // Change the maximum coeff value, to test different bit boundaries
133 if (k == 8 && (i % 9) == 0) {
136 block_size = 16 << (i % 9); // All block sizes from 4x4, 8x4 ..64x64
137 for (int j = 0; j < block_size; j++) {
139 // Test at positive maximum values
140 coeff[j] = k % 2 ? max_val : 0;
141 dqcoeff[j] = (k >> 1) % 2 ? max_val : 0;
143 // Test at negative maximum values
144 coeff[j] = k % 2 ? -max_val : 0;
145 dqcoeff[j] = (k >> 1) % 2 ? -max_val : 0;
149 coeff[j] = rnd(1 << 14);
150 dqcoeff[j] = rnd(1 << 14);
153 coeff[j] = -rnd(1 << 14);
154 dqcoeff[j] = -rnd(1 << 14);
159 ref_error_block_op_(coeff, dqcoeff, block_size, &ref_ssz, bit_depth_);
160 ASM_REGISTER_STATE_CHECK(
161 ret = error_block_op_(coeff, dqcoeff, block_size, &ssz, bit_depth_));
162 err_count += (ref_ret != ret) | (ref_ssz != ssz);
163 if (err_count && !err_count_total) {
166 err_count_total += err_count;
168 EXPECT_EQ(0, err_count_total)
169 << "Error: Error Block Test, C output doesn't match optimized output. "
170 << "First failed at test case " << first_failure;
173 using std::make_tuple;
176 const BlockErrorParam sse2_block_error_tests[] = {
177 #if CONFIG_VP9_HIGHBITDEPTH
178 make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
180 make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
182 make_tuple(&vp9_highbd_block_error_sse2, &vp9_highbd_block_error_c,
184 #endif // CONFIG_VP9_HIGHBITDEPTH
185 make_tuple(&BlockError8BitWrapper<vp9_block_error_sse2>,
186 &BlockError8BitWrapper<vp9_block_error_c>, VPX_BITS_8)
189 INSTANTIATE_TEST_SUITE_P(SSE2, BlockErrorTest,
190 ::testing::ValuesIn(sse2_block_error_tests));
194 INSTANTIATE_TEST_SUITE_P(
195 AVX2, BlockErrorTest,
196 ::testing::Values(make_tuple(&BlockError8BitWrapper<vp9_block_error_avx2>,
197 &BlockError8BitWrapper<vp9_block_error_c>,