blob: 8c5caaac7aab2e2e85163a48ae41426710660f7c [file] [log] [blame]
Yi Luod61e6082017-05-26 16:14:39 -07001/*
2 * Copyright (c) 2017, Alliance for Open Media. All rights reserved
3 *
4 * 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 */
11
12#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
13
14#include "./aom_config.h"
15#include "./av1_rtcd.h"
16
17#include "test/acm_random.h"
18#include "test/clear_system_state.h"
19#include "test/register_state_check.h"
20#include "test/util.h"
21
22namespace {
23using libaom_test::ACMRandom;
24
25typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff,
26 const tran_low_t *dqcoeff, intptr_t size,
27 int64_t *ssz);
Yi Luod61e6082017-05-26 16:14:39 -070028typedef int64_t (*HbdBlockErrorFunc)(const tran_low_t *coeff,
29 const tran_low_t *dqcoeff, intptr_t size,
30 int64_t *ssz, int bd);
Yi Luod61e6082017-05-26 16:14:39 -070031
32typedef std::tr1::tuple<BlockErrorFunc, BlockErrorFunc, TX_SIZE,
33 aom_bit_depth_t>
34 BlockErrorParam;
35
36const int kTestNum = 10000;
37
38class BlockErrorTest : public ::testing::TestWithParam<BlockErrorParam> {
39 public:
40 BlockErrorTest()
41 : blk_err_ref_(GET_PARAM(0)), blk_err_(GET_PARAM(1)),
42 tx_size_(GET_PARAM(2)), bd_(GET_PARAM(3)) {}
43
44 virtual ~BlockErrorTest() {}
45
46 virtual void SetUp() {
47 const intptr_t block_size = getCoeffNum();
48 coeff_ = reinterpret_cast<tran_low_t *>(
49 aom_memalign(16, 2 * block_size * sizeof(tran_low_t)));
50 }
51
52 virtual void TearDown() {
53 aom_free(coeff_);
54 coeff_ = NULL;
55 libaom_test::ClearSystemState();
56 }
57
58 void BlockErrorRun(int testNum) {
59 int i;
60 int64_t error_ref, error;
61 int64_t sse_ref, sse;
62 const intptr_t block_size = getCoeffNum();
63 tran_low_t *dqcoeff = coeff_ + block_size;
64 for (i = 0; i < testNum; ++i) {
65 FillRandomData();
66
67 error_ref = blk_err_ref_(coeff_, dqcoeff, block_size, &sse_ref);
68 ASM_REGISTER_STATE_CHECK(error =
69 blk_err_(coeff_, dqcoeff, block_size, &sse));
70
71 EXPECT_EQ(error_ref, error) << "Error doesn't match on test: " << i;
72 EXPECT_EQ(sse_ref, sse) << "SSE doesn't match on test: " << i;
73 }
74 }
75
Urvang Joshi80893152017-10-27 11:51:14 -070076 intptr_t getCoeffNum() { return av1_get_max_eob(tx_size_); }
Yi Luod61e6082017-05-26 16:14:39 -070077
78 void FillRandomData() {
79 const intptr_t block_size = getCoeffNum();
80 tran_low_t *dqcoeff = coeff_ + block_size;
81 intptr_t i;
82 int16_t margin = 512;
83 for (i = 0; i < block_size; ++i) {
84 coeff_[i] = GetRandomNumWithRange(INT16_MIN + margin, INT16_MAX - margin);
85 dqcoeff[i] = coeff_[i] + GetRandomDeltaWithRange(margin);
86 }
87 }
88
89 void FillConstantData() {
90 const intptr_t block_size = getCoeffNum();
91 tran_low_t *dqcoeff = coeff_ + block_size;
92 intptr_t i;
93 for (i = 0; i < block_size; ++i) {
94 coeff_[i] = 5;
95 dqcoeff[i] = 7;
96 }
97 }
98
99 tran_low_t GetRandomNumWithRange(int16_t min, int16_t max) {
100 return clamp((int16_t)rnd_.Rand16(), min, max);
101 }
102
103 tran_low_t GetRandomDeltaWithRange(int16_t delta) {
104 tran_low_t value = (int16_t)rnd_.Rand16();
105 value %= delta;
106 return value;
107 }
108
109 BlockErrorFunc blk_err_ref_;
110 BlockErrorFunc blk_err_;
111 TX_SIZE tx_size_;
112 aom_bit_depth_t bd_;
113 ACMRandom rnd_;
114 tran_low_t *coeff_;
115};
116
117TEST_P(BlockErrorTest, BitExact) { BlockErrorRun(kTestNum); }
118
119using std::tr1::make_tuple;
120
Yi Luod61e6082017-05-26 16:14:39 -0700121#if HAVE_AVX2
122const BlockErrorParam kBlkErrParamArrayAvx2[] = { make_tuple(
123 &av1_block_error_c, &av1_block_error_avx2, TX_32X32, AOM_BITS_8) };
124INSTANTIATE_TEST_CASE_P(AVX2, BlockErrorTest,
125 ::testing::ValuesIn(kBlkErrParamArrayAvx2));
126#endif
127} // namespace