Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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 | */ |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 11 | |
| 12 | #include <math.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 16 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 17 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "./av1_rtcd.h" |
| 19 | #include "./aom_config.h" |
| 20 | #include "./aom_dsp_rtcd.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 21 | #include "test/acm_random.h" |
| 22 | #include "test/clear_system_state.h" |
| 23 | #include "test/register_state_check.h" |
| 24 | #include "test/util.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/common/entropy.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | #include "aom/aom_codec.h" |
| 27 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | #include "aom_ports/mem.h" |
| 29 | #include "aom_ports/msvc.h" // for round() |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 30 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 31 | using libaom_test::ACMRandom; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 32 | |
| 33 | namespace { |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 34 | |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 35 | const int kNumCoeffs = 1024; |
| 36 | const double kPi = 3.141592653589793238462643383279502884; |
James Zern | eb2f000 | 2014-08-22 12:29:37 -0700 | [diff] [blame] | 37 | void reference_32x32_dct_1d(const double in[32], double out[32]) { |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 38 | const double kInvSqrt2 = 0.707106781186547524400844362104; |
| 39 | for (int k = 0; k < 32; k++) { |
| 40 | out[k] = 0.0; |
| 41 | for (int n = 0; n < 32; n++) |
| 42 | out[k] += in[n] * cos(kPi * (2 * n + 1) * k / 64.0); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 43 | if (k == 0) out[k] = out[k] * kInvSqrt2; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 47 | void reference_32x32_dct_2d(const int16_t input[kNumCoeffs], |
| 48 | double output[kNumCoeffs]) { |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 49 | // First transform columns |
| 50 | for (int i = 0; i < 32; ++i) { |
| 51 | double temp_in[32], temp_out[32]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 52 | for (int j = 0; j < 32; ++j) temp_in[j] = input[j * 32 + i]; |
James Zern | eb2f000 | 2014-08-22 12:29:37 -0700 | [diff] [blame] | 53 | reference_32x32_dct_1d(temp_in, temp_out); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 54 | for (int j = 0; j < 32; ++j) output[j * 32 + i] = temp_out[j]; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 55 | } |
| 56 | // Then transform rows |
| 57 | for (int i = 0; i < 32; ++i) { |
| 58 | double temp_in[32], temp_out[32]; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 59 | for (int j = 0; j < 32; ++j) temp_in[j] = output[j + i * 32]; |
James Zern | eb2f000 | 2014-08-22 12:29:37 -0700 | [diff] [blame] | 60 | reference_32x32_dct_1d(temp_in, temp_out); |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 61 | // Scale by some magic number |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 62 | for (int j = 0; j < 32; ++j) output[j + i * 32] = temp_out[j] / 4; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 66 | typedef void (*FwdTxfmFunc)(const int16_t *in, tran_low_t *out, int stride); |
| 67 | typedef void (*InvTxfmFunc)(const tran_low_t *in, uint8_t *out, int stride); |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 68 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 69 | typedef std::tr1::tuple<FwdTxfmFunc, InvTxfmFunc, int, aom_bit_depth_t> |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 70 | Trans32x32Param; |
| 71 | |
James Zern | fd38e70 | 2014-07-16 18:54:31 -0700 | [diff] [blame] | 72 | class Trans32x32Test : public ::testing::TestWithParam<Trans32x32Param> { |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 73 | public: |
| 74 | virtual ~Trans32x32Test() {} |
| 75 | virtual void SetUp() { |
| 76 | fwd_txfm_ = GET_PARAM(0); |
| 77 | inv_txfm_ = GET_PARAM(1); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 78 | version_ = GET_PARAM(2); // 0: high precision forward transform |
| 79 | // 1: low precision version for rd loop |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 80 | bit_depth_ = GET_PARAM(3); |
| 81 | mask_ = (1 << bit_depth_) - 1; |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 85 | |
| 86 | protected: |
| 87 | int version_; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 88 | aom_bit_depth_t bit_depth_; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 89 | int mask_; |
James Zern | fd38e70 | 2014-07-16 18:54:31 -0700 | [diff] [blame] | 90 | FwdTxfmFunc fwd_txfm_; |
| 91 | InvTxfmFunc inv_txfm_; |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | TEST_P(Trans32x32Test, AccuracyCheck) { |
| 95 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 96 | uint32_t max_error = 0; |
| 97 | int64_t total_error = 0; |
Peter de Rivaz | 7e40a55 | 2014-10-24 08:48:02 +0100 | [diff] [blame] | 98 | const int count_test_block = 10000; |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 99 | DECLARE_ALIGNED(16, int16_t, test_input_block[kNumCoeffs]); |
| 100 | DECLARE_ALIGNED(16, tran_low_t, test_temp_block[kNumCoeffs]); |
| 101 | DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); |
| 102 | DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 103 | #if CONFIG_HIGHBITDEPTH |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 104 | DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); |
| 105 | DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 106 | #endif |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 107 | |
| 108 | for (int i = 0; i < count_test_block; ++i) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 109 | // Initialize a test block with input range [-mask_, mask_]. |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 110 | for (int j = 0; j < kNumCoeffs; ++j) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | if (bit_depth_ == AOM_BITS_8) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 112 | src[j] = rnd.Rand8(); |
| 113 | dst[j] = rnd.Rand8(); |
| 114 | test_input_block[j] = src[j] - dst[j]; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 115 | #if CONFIG_HIGHBITDEPTH |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 116 | } else { |
| 117 | src16[j] = rnd.Rand16() & mask_; |
| 118 | dst16[j] = rnd.Rand16() & mask_; |
| 119 | test_input_block[j] = src16[j] - dst16[j]; |
| 120 | #endif |
| 121 | } |
Scott LaVarnway | 2cf0d4b | 2013-05-14 11:58:13 -0400 | [diff] [blame] | 122 | } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 123 | |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 124 | ASM_REGISTER_STATE_CHECK(fwd_txfm_(test_input_block, test_temp_block, 32)); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 125 | if (bit_depth_ == AOM_BITS_8) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 126 | ASM_REGISTER_STATE_CHECK(inv_txfm_(test_temp_block, dst, 32)); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 127 | #if CONFIG_HIGHBITDEPTH |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 128 | } else { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 129 | ASM_REGISTER_STATE_CHECK( |
| 130 | inv_txfm_(test_temp_block, CONVERT_TO_BYTEPTR(dst16), 32)); |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 131 | #endif |
| 132 | } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 133 | |
| 134 | for (int j = 0; j < kNumCoeffs; ++j) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 135 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 6382727 | 2016-05-31 16:54:58 -0700 | [diff] [blame] | 136 | const int32_t diff = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 137 | bit_depth_ == AOM_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 138 | #else |
Yaowu Xu | 6382727 | 2016-05-31 16:54:58 -0700 | [diff] [blame] | 139 | const int32_t diff = dst[j] - src[j]; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 140 | #endif |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 141 | const uint32_t error = diff * diff; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 142 | if (max_error < error) max_error = error; |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 143 | total_error += error; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (version_ == 1) { |
| 148 | max_error /= 2; |
| 149 | total_error /= 45; |
| 150 | } |
| 151 | |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 152 | EXPECT_GE(1u << 2 * (bit_depth_ - 8), max_error) |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 153 | << "Error: 32x32 FDCT/IDCT has an individual round-trip error > 1"; |
| 154 | |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 155 | EXPECT_GE(count_test_block << 2 * (bit_depth_ - 8), total_error) |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 156 | << "Error: 32x32 FDCT/IDCT has average round-trip error > 1 per block"; |
| 157 | } |
| 158 | |
| 159 | TEST_P(Trans32x32Test, CoeffCheck) { |
| 160 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 161 | const int count_test_block = 1000; |
| 162 | |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 163 | DECLARE_ALIGNED(16, int16_t, input_block[kNumCoeffs]); |
| 164 | DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); |
| 165 | DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 166 | |
| 167 | for (int i = 0; i < count_test_block; ++i) { |
| 168 | for (int j = 0; j < kNumCoeffs; ++j) |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 169 | input_block[j] = (rnd.Rand16() & mask_) - (rnd.Rand16() & mask_); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 170 | |
Dmitry Kovalev | e05412f | 2013-10-17 13:02:28 -0700 | [diff] [blame] | 171 | const int stride = 32; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 172 | aom_fdct32x32_c(input_block, output_ref_block, stride); |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 173 | ASM_REGISTER_STATE_CHECK(fwd_txfm_(input_block, output_block, stride)); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 174 | |
| 175 | if (version_ == 0) { |
| 176 | for (int j = 0; j < kNumCoeffs; ++j) |
| 177 | EXPECT_EQ(output_block[j], output_ref_block[j]) |
| 178 | << "Error: 32x32 FDCT versions have mismatched coefficients"; |
| 179 | } else { |
| 180 | for (int j = 0; j < kNumCoeffs; ++j) |
| 181 | EXPECT_GE(6, abs(output_block[j] - output_ref_block[j])) |
| 182 | << "Error: 32x32 FDCT rd has mismatched coefficients"; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | TEST_P(Trans32x32Test, MemCheck) { |
| 188 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 189 | const int count_test_block = 2000; |
| 190 | |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 191 | DECLARE_ALIGNED(16, int16_t, input_extreme_block[kNumCoeffs]); |
| 192 | DECLARE_ALIGNED(16, tran_low_t, output_ref_block[kNumCoeffs]); |
| 193 | DECLARE_ALIGNED(16, tran_low_t, output_block[kNumCoeffs]); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 194 | |
| 195 | for (int i = 0; i < count_test_block; ++i) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 196 | // Initialize a test block with input range [-mask_, mask_]. |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 197 | for (int j = 0; j < kNumCoeffs; ++j) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 198 | input_extreme_block[j] = rnd.Rand8() & 1 ? mask_ : -mask_; |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 199 | } |
Jingning Han | 5c2696c | 2014-06-02 16:40:01 -0700 | [diff] [blame] | 200 | if (i == 0) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 201 | for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = mask_; |
Jingning Han | 5c2696c | 2014-06-02 16:40:01 -0700 | [diff] [blame] | 202 | } else if (i == 1) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 203 | for (int j = 0; j < kNumCoeffs; ++j) input_extreme_block[j] = -mask_; |
Jingning Han | 5c2696c | 2014-06-02 16:40:01 -0700 | [diff] [blame] | 204 | } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 205 | |
Dmitry Kovalev | e05412f | 2013-10-17 13:02:28 -0700 | [diff] [blame] | 206 | const int stride = 32; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 207 | aom_fdct32x32_c(input_extreme_block, output_ref_block, stride); |
James Zern | 29e1b1a | 2014-07-09 21:02:02 -0700 | [diff] [blame] | 208 | ASM_REGISTER_STATE_CHECK( |
| 209 | fwd_txfm_(input_extreme_block, output_block, stride)); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 210 | |
| 211 | // The minimum quant value is 4. |
| 212 | for (int j = 0; j < kNumCoeffs; ++j) { |
| 213 | if (version_ == 0) { |
| 214 | EXPECT_EQ(output_block[j], output_ref_block[j]) |
| 215 | << "Error: 32x32 FDCT versions have mismatched coefficients"; |
| 216 | } else { |
| 217 | EXPECT_GE(6, abs(output_block[j] - output_ref_block[j])) |
| 218 | << "Error: 32x32 FDCT rd has mismatched coefficients"; |
| 219 | } |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 220 | EXPECT_GE(4 * DCT_MAX_VALUE << (bit_depth_ - 8), abs(output_ref_block[j])) |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 221 | << "Error: 32x32 FDCT C has coefficient larger than 4*DCT_MAX_VALUE"; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 222 | EXPECT_GE(4 * DCT_MAX_VALUE << (bit_depth_ - 8), abs(output_block[j])) |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 223 | << "Error: 32x32 FDCT has coefficient larger than " |
| 224 | << "4*DCT_MAX_VALUE"; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | TEST_P(Trans32x32Test, InverseAccuracy) { |
| 230 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 231 | const int count_test_block = 1000; |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 232 | DECLARE_ALIGNED(16, int16_t, in[kNumCoeffs]); |
| 233 | DECLARE_ALIGNED(16, tran_low_t, coeff[kNumCoeffs]); |
| 234 | DECLARE_ALIGNED(16, uint8_t, dst[kNumCoeffs]); |
| 235 | DECLARE_ALIGNED(16, uint8_t, src[kNumCoeffs]); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 236 | #if CONFIG_HIGHBITDEPTH |
James Zern | fd3658b | 2015-05-02 13:24:16 -0700 | [diff] [blame] | 237 | DECLARE_ALIGNED(16, uint16_t, dst16[kNumCoeffs]); |
| 238 | DECLARE_ALIGNED(16, uint16_t, src16[kNumCoeffs]); |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 239 | #endif |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 240 | |
| 241 | for (int i = 0; i < count_test_block; ++i) { |
| 242 | double out_r[kNumCoeffs]; |
| 243 | |
| 244 | // Initialize a test block with input range [-255, 255] |
| 245 | for (int j = 0; j < kNumCoeffs; ++j) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 246 | if (bit_depth_ == AOM_BITS_8) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 247 | src[j] = rnd.Rand8(); |
| 248 | dst[j] = rnd.Rand8(); |
| 249 | in[j] = src[j] - dst[j]; |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 250 | #if CONFIG_HIGHBITDEPTH |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 251 | } else { |
| 252 | src16[j] = rnd.Rand16() & mask_; |
| 253 | dst16[j] = rnd.Rand16() & mask_; |
| 254 | in[j] = src16[j] - dst16[j]; |
| 255 | #endif |
| 256 | } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 257 | } |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 258 | |
| 259 | reference_32x32_dct_2d(in, out_r); |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 260 | for (int j = 0; j < kNumCoeffs; ++j) |
Peter de Rivaz | 7e40a55 | 2014-10-24 08:48:02 +0100 | [diff] [blame] | 261 | coeff[j] = static_cast<tran_low_t>(round(out_r[j])); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 262 | if (bit_depth_ == AOM_BITS_8) { |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 263 | ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, dst, 32)); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 264 | #if CONFIG_HIGHBITDEPTH |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 265 | } else { |
| 266 | ASM_REGISTER_STATE_CHECK(inv_txfm_(coeff, CONVERT_TO_BYTEPTR(dst16), 32)); |
| 267 | #endif |
| 268 | } |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 269 | for (int j = 0; j < kNumCoeffs; ++j) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 270 | #if CONFIG_HIGHBITDEPTH |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 271 | const int diff = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 272 | bit_depth_ == AOM_BITS_8 ? dst[j] - src[j] : dst16[j] - src16[j]; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 273 | #else |
Scott LaVarnway | 2cf0d4b | 2013-05-14 11:58:13 -0400 | [diff] [blame] | 274 | const int diff = dst[j] - src[j]; |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 275 | #endif |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 276 | const int error = diff * diff; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 277 | EXPECT_GE(1, error) << "Error: 32x32 IDCT has error " << error |
| 278 | << " at index " << j; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 279 | } |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
Paul Wilkins | 649be94 | 2013-02-11 12:35:28 +0000 | [diff] [blame] | 282 | |
James Zern | 0269df4 | 2016-03-29 21:04:38 -0700 | [diff] [blame] | 283 | class PartialTrans32x32Test |
| 284 | : public ::testing::TestWithParam< |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 285 | std::tr1::tuple<FwdTxfmFunc, aom_bit_depth_t> > { |
James Zern | 0269df4 | 2016-03-29 21:04:38 -0700 | [diff] [blame] | 286 | public: |
| 287 | virtual ~PartialTrans32x32Test() {} |
| 288 | virtual void SetUp() { |
| 289 | fwd_txfm_ = GET_PARAM(0); |
| 290 | bit_depth_ = GET_PARAM(1); |
| 291 | } |
| 292 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 293 | virtual void TearDown() { libaom_test::ClearSystemState(); } |
James Zern | 0269df4 | 2016-03-29 21:04:38 -0700 | [diff] [blame] | 294 | |
| 295 | protected: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 296 | aom_bit_depth_t bit_depth_; |
James Zern | 0269df4 | 2016-03-29 21:04:38 -0700 | [diff] [blame] | 297 | FwdTxfmFunc fwd_txfm_; |
| 298 | }; |
| 299 | |
| 300 | TEST_P(PartialTrans32x32Test, Extremes) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 301 | #if CONFIG_HIGHBITDEPTH |
James Zern | 0269df4 | 2016-03-29 21:04:38 -0700 | [diff] [blame] | 302 | const int16_t maxval = |
| 303 | static_cast<int16_t>(clip_pixel_highbd(1 << 30, bit_depth_)); |
| 304 | #else |
| 305 | const int16_t maxval = 255; |
| 306 | #endif |
| 307 | const int minval = -maxval; |
| 308 | DECLARE_ALIGNED(16, int16_t, input[kNumCoeffs]); |
| 309 | DECLARE_ALIGNED(16, tran_low_t, output[kNumCoeffs]); |
| 310 | |
| 311 | for (int i = 0; i < kNumCoeffs; ++i) input[i] = maxval; |
| 312 | output[0] = 0; |
| 313 | ASM_REGISTER_STATE_CHECK(fwd_txfm_(input, output, 32)); |
| 314 | EXPECT_EQ((maxval * kNumCoeffs) >> 3, output[0]); |
| 315 | |
| 316 | for (int i = 0; i < kNumCoeffs; ++i) input[i] = minval; |
| 317 | output[0] = 0; |
| 318 | ASM_REGISTER_STATE_CHECK(fwd_txfm_(input, output, 32)); |
| 319 | EXPECT_EQ((minval * kNumCoeffs) >> 3, output[0]); |
| 320 | } |
| 321 | |
James Zern | c98f8e0 | 2016-04-01 19:44:23 -0700 | [diff] [blame] | 322 | TEST_P(PartialTrans32x32Test, Random) { |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 323 | #if CONFIG_HIGHBITDEPTH |
James Zern | c98f8e0 | 2016-04-01 19:44:23 -0700 | [diff] [blame] | 324 | const int16_t maxval = |
| 325 | static_cast<int16_t>(clip_pixel_highbd(1 << 30, bit_depth_)); |
| 326 | #else |
| 327 | const int16_t maxval = 255; |
| 328 | #endif |
| 329 | DECLARE_ALIGNED(16, int16_t, input[kNumCoeffs]); |
| 330 | DECLARE_ALIGNED(16, tran_low_t, output[kNumCoeffs]); |
| 331 | ACMRandom rnd(ACMRandom::DeterministicSeed()); |
| 332 | |
| 333 | int sum = 0; |
| 334 | for (int i = 0; i < kNumCoeffs; ++i) { |
| 335 | const int val = (i & 1) ? -rnd(maxval + 1) : rnd(maxval + 1); |
| 336 | input[i] = val; |
| 337 | sum += val; |
| 338 | } |
| 339 | output[0] = 0; |
| 340 | ASM_REGISTER_STATE_CHECK(fwd_txfm_(input, output, 32)); |
| 341 | EXPECT_EQ(sum >> 3, output[0]); |
| 342 | } |
| 343 | |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 344 | using std::tr1::make_tuple; |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 345 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 346 | #if CONFIG_HIGHBITDEPTH |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 347 | INSTANTIATE_TEST_CASE_P( |
| 348 | C, Trans32x32Test, |
Frederic Barbier | c756e4d | 2017-04-25 17:26:28 +0200 | [diff] [blame] | 349 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, 0, |
| 350 | AOM_BITS_8), |
| 351 | make_tuple(&aom_fdct32x32_rd_c, &aom_idct32x32_1024_add_c, |
| 352 | 1, AOM_BITS_8))); |
Deb Mukherjee | 10783d4 | 2014-09-02 16:34:09 -0700 | [diff] [blame] | 353 | #else |
| 354 | INSTANTIATE_TEST_CASE_P( |
| 355 | C, Trans32x32Test, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 356 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_c, 0, |
| 357 | AOM_BITS_8), |
| 358 | make_tuple(&aom_fdct32x32_rd_c, &aom_idct32x32_1024_add_c, |
| 359 | 1, AOM_BITS_8))); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 360 | #endif // CONFIG_HIGHBITDEPTH |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 361 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 362 | #if HAVE_NEON && !CONFIG_HIGHBITDEPTH |
James Zern | a6effda | 2014-02-25 23:11:49 -0800 | [diff] [blame] | 363 | INSTANTIATE_TEST_CASE_P( |
| 364 | NEON, Trans32x32Test, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 365 | ::testing::Values(make_tuple(&aom_fdct32x32_c, &aom_idct32x32_1024_add_neon, |
| 366 | 0, AOM_BITS_8), |
| 367 | make_tuple(&aom_fdct32x32_rd_c, |
| 368 | &aom_idct32x32_1024_add_neon, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 369 | #endif // HAVE_NEON && !CONFIG_HIGHBITDEPTH |
James Zern | a6effda | 2014-02-25 23:11:49 -0800 | [diff] [blame] | 370 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 371 | #if HAVE_SSE2 && !CONFIG_HIGHBITDEPTH |
Jingning Han | 4ad52a8 | 2013-09-03 11:57:34 -0700 | [diff] [blame] | 372 | INSTANTIATE_TEST_CASE_P( |
| 373 | SSE2, Trans32x32Test, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 374 | ::testing::Values(make_tuple(&aom_fdct32x32_sse2, |
| 375 | &aom_idct32x32_1024_add_sse2, 0, AOM_BITS_8), |
| 376 | make_tuple(&aom_fdct32x32_rd_sse2, |
| 377 | &aom_idct32x32_1024_add_sse2, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 378 | #endif // HAVE_SSE2 && !CONFIG_HIGHBITDEPTH |
Peter de Rivaz | 7e40a55 | 2014-10-24 08:48:02 +0100 | [diff] [blame] | 379 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 380 | #if HAVE_SSE2 && CONFIG_HIGHBITDEPTH |
Peter de Rivaz | 7e40a55 | 2014-10-24 08:48:02 +0100 | [diff] [blame] | 381 | INSTANTIATE_TEST_CASE_P( |
| 382 | SSE2, Trans32x32Test, |
Frederic Barbier | c756e4d | 2017-04-25 17:26:28 +0200 | [diff] [blame] | 383 | ::testing::Values(make_tuple(&aom_fdct32x32_sse2, &aom_idct32x32_1024_add_c, |
| 384 | 0, AOM_BITS_8), |
| 385 | make_tuple(&aom_fdct32x32_rd_sse2, |
| 386 | &aom_idct32x32_1024_add_c, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 387 | #endif // HAVE_SSE2 && CONFIG_HIGHBITDEPTH |
levytamar82 | 8def766 | 2013-11-21 12:31:10 -0700 | [diff] [blame] | 388 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 389 | #if HAVE_AVX2 && !CONFIG_HIGHBITDEPTH |
levytamar82 | 8def766 | 2013-11-21 12:31:10 -0700 | [diff] [blame] | 390 | INSTANTIATE_TEST_CASE_P( |
| 391 | AVX2, Trans32x32Test, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 392 | ::testing::Values(make_tuple(&aom_fdct32x32_avx2, |
| 393 | &aom_idct32x32_1024_add_sse2, 0, AOM_BITS_8), |
| 394 | make_tuple(&aom_fdct32x32_rd_avx2, |
| 395 | &aom_idct32x32_1024_add_sse2, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 396 | #endif // HAVE_AVX2 && !CONFIG_HIGHBITDEPTH |
Parag Salasakar | 1601c13 | 2015-05-06 12:37:38 +0530 | [diff] [blame] | 397 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 398 | #if HAVE_AVX2 && CONFIG_HIGHBITDEPTH |
Yi Luo | 0c552df | 2016-10-24 16:30:55 -0700 | [diff] [blame] | 399 | INSTANTIATE_TEST_CASE_P( |
| 400 | AVX2, Trans32x32Test, |
| 401 | ::testing::Values(make_tuple(&aom_fdct32x32_avx2, |
| 402 | &aom_idct32x32_1024_add_sse2, 0, AOM_BITS_8), |
| 403 | make_tuple(&aom_fdct32x32_rd_avx2, |
| 404 | &aom_idct32x32_1024_add_sse2, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 405 | #endif // HAVE_AVX2 && CONFIG_HIGHBITDEPTH |
Yi Luo | 0c552df | 2016-10-24 16:30:55 -0700 | [diff] [blame] | 406 | |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 407 | #if HAVE_MSA && !CONFIG_HIGHBITDEPTH |
Parag Salasakar | 1601c13 | 2015-05-06 12:37:38 +0530 | [diff] [blame] | 408 | INSTANTIATE_TEST_CASE_P( |
| 409 | MSA, Trans32x32Test, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 410 | ::testing::Values(make_tuple(&aom_fdct32x32_msa, |
| 411 | &aom_idct32x32_1024_add_msa, 0, AOM_BITS_8), |
| 412 | make_tuple(&aom_fdct32x32_rd_msa, |
| 413 | &aom_idct32x32_1024_add_msa, 1, AOM_BITS_8))); |
Sebastien Alaiwan | c6a48a2 | 2017-04-20 10:12:43 +0200 | [diff] [blame] | 414 | #endif // HAVE_MSA && !CONFIG_HIGHBITDEPTH |
Ronald S. Bultje | c456b35 | 2012-12-07 14:45:05 -0800 | [diff] [blame] | 415 | } // namespace |