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