Yi Luo | d61e608 | 2017-05-26 16:14:39 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | namespace { |
| 23 | using libaom_test::ACMRandom; |
| 24 | |
| 25 | typedef int64_t (*BlockErrorFunc)(const tran_low_t *coeff, |
| 26 | const tran_low_t *dqcoeff, intptr_t size, |
| 27 | int64_t *ssz); |
Yi Luo | d61e608 | 2017-05-26 16:14:39 -0700 | [diff] [blame] | 28 | typedef int64_t (*HbdBlockErrorFunc)(const tran_low_t *coeff, |
| 29 | const tran_low_t *dqcoeff, intptr_t size, |
| 30 | int64_t *ssz, int bd); |
Yi Luo | d61e608 | 2017-05-26 16:14:39 -0700 | [diff] [blame] | 31 | |
| 32 | typedef std::tr1::tuple<BlockErrorFunc, BlockErrorFunc, TX_SIZE, |
| 33 | aom_bit_depth_t> |
| 34 | BlockErrorParam; |
| 35 | |
| 36 | const int kTestNum = 10000; |
| 37 | |
| 38 | class 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 Joshi | 8089315 | 2017-10-27 11:51:14 -0700 | [diff] [blame] | 76 | intptr_t getCoeffNum() { return av1_get_max_eob(tx_size_); } |
Yi Luo | d61e608 | 2017-05-26 16:14:39 -0700 | [diff] [blame] | 77 | |
| 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 | |
| 117 | TEST_P(BlockErrorTest, BitExact) { BlockErrorRun(kTestNum); } |
| 118 | |
| 119 | using std::tr1::make_tuple; |
| 120 | |
Yi Luo | d61e608 | 2017-05-26 16:14:39 -0700 | [diff] [blame] | 121 | #if HAVE_AVX2 |
| 122 | const BlockErrorParam kBlkErrParamArrayAvx2[] = { make_tuple( |
| 123 | &av1_block_error_c, &av1_block_error_avx2, TX_32X32, AOM_BITS_8) }; |
| 124 | INSTANTIATE_TEST_CASE_P(AVX2, BlockErrorTest, |
| 125 | ::testing::ValuesIn(kBlkErrParamArrayAvx2)); |
| 126 | #endif |
| 127 | } // namespace |