Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [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. |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 10 | */ |
| 11 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 12 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "./aom_config.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 15 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_dsp_rtcd.h" |
| 17 | #include "./av1_rtcd.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 18 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "aom_dsp/aom_dsp_common.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 20 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "av1/common/enums.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 22 | |
| 23 | #include "test/acm_random.h" |
| 24 | #include "test/function_equivalence_test.h" |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 25 | #include "test/register_state_check.h" |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 26 | |
| 27 | #define WEDGE_WEIGHT_BITS 6 |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 28 | #define MAX_MASK_VALUE (1 << (WEDGE_WEIGHT_BITS)) |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 29 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | using libaom_test::ACMRandom; |
| 31 | using libaom_test::FunctionEquivalenceTest; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 32 | |
| 33 | namespace { |
| 34 | |
| 35 | static const int16_t kInt13Max = (1 << 12) - 1; |
| 36 | |
| 37 | ////////////////////////////////////////////////////////////////////////////// |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | // av1_wedge_sse_from_residuals - functionality |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 39 | ////////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | class WedgeUtilsSSEFuncTest : public testing::Test { |
| 42 | protected: |
| 43 | WedgeUtilsSSEFuncTest() : rng_(ACMRandom::DeterministicSeed()) {} |
| 44 | |
| 45 | static const int kIterations = 1000; |
| 46 | |
| 47 | ACMRandom rng_; |
| 48 | }; |
| 49 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 50 | static void equiv_blend_residuals(int16_t *r, const int16_t *r0, |
| 51 | const int16_t *r1, const uint8_t *m, int N) { |
| 52 | for (int i = 0; i < N; i++) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 53 | const int32_t m0 = m[i]; |
| 54 | const int32_t m1 = MAX_MASK_VALUE - m0; |
| 55 | const int16_t R = m0 * r0[i] + m1 * r1[i]; |
| 56 | // Note that this rounding is designed to match the result |
| 57 | // you would get when actually blending the 2 predictors and computing |
| 58 | // the residuals. |
| 59 | r[i] = ROUND_POWER_OF_TWO(R - 1, WEDGE_WEIGHT_BITS); |
| 60 | } |
| 61 | } |
| 62 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 63 | static uint64_t equiv_sse_from_residuals(const int16_t *r0, const int16_t *r1, |
| 64 | const uint8_t *m, int N) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 65 | uint64_t acc = 0; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 66 | for (int i = 0; i < N; i++) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 67 | const int32_t m0 = m[i]; |
| 68 | const int32_t m1 = MAX_MASK_VALUE - m0; |
| 69 | const int16_t R = m0 * r0[i] + m1 * r1[i]; |
| 70 | const int32_t r = ROUND_POWER_OF_TWO(R - 1, WEDGE_WEIGHT_BITS); |
| 71 | acc += r * r; |
| 72 | } |
| 73 | return acc; |
| 74 | } |
| 75 | |
| 76 | TEST_F(WedgeUtilsSSEFuncTest, ResidualBlendingEquiv) { |
| 77 | DECLARE_ALIGNED(32, uint8_t, s[MAX_SB_SQUARE]); |
| 78 | DECLARE_ALIGNED(32, uint8_t, p0[MAX_SB_SQUARE]); |
| 79 | DECLARE_ALIGNED(32, uint8_t, p1[MAX_SB_SQUARE]); |
| 80 | DECLARE_ALIGNED(32, uint8_t, p[MAX_SB_SQUARE]); |
| 81 | |
| 82 | DECLARE_ALIGNED(32, int16_t, r0[MAX_SB_SQUARE]); |
| 83 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 84 | DECLARE_ALIGNED(32, int16_t, r_ref[MAX_SB_SQUARE]); |
| 85 | DECLARE_ALIGNED(32, int16_t, r_tst[MAX_SB_SQUARE]); |
| 86 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 87 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 88 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
| 89 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 90 | s[i] = rng_.Rand8(); |
| 91 | m[i] = rng_(MAX_MASK_VALUE + 1); |
| 92 | } |
| 93 | |
| 94 | const int w = 1 << (rng_(MAX_SB_SIZE_LOG2 + 1 - 3) + 3); |
| 95 | const int h = 1 << (rng_(MAX_SB_SIZE_LOG2 + 1 - 3) + 3); |
| 96 | const int N = w * h; |
| 97 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 98 | for (int j = 0; j < N; j++) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 99 | p0[j] = clamp(s[j] + rng_(33) - 16, 0, UINT8_MAX); |
| 100 | p1[j] = clamp(s[j] + rng_(33) - 16, 0, UINT8_MAX); |
| 101 | } |
| 102 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | aom_blend_a64_mask(p, w, p0, w, p1, w, m, w, h, w, 0, 0); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 104 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 105 | aom_subtract_block(h, w, r0, w, s, w, p0, w); |
| 106 | aom_subtract_block(h, w, r1, w, s, w, p1, w); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 107 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 108 | aom_subtract_block(h, w, r_ref, w, s, w, p, w); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 109 | equiv_blend_residuals(r_tst, r0, r1, m, N); |
| 110 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 111 | for (int i = 0; i < N; ++i) ASSERT_EQ(r_ref[i], r_tst[i]); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | uint64_t ref_sse = aom_sum_squares_i16(r_ref, N); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 114 | uint64_t tst_sse = equiv_sse_from_residuals(r0, r1, m, N); |
| 115 | |
| 116 | ASSERT_EQ(ref_sse, tst_sse); |
| 117 | } |
| 118 | } |
| 119 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 120 | static uint64_t sse_from_residuals(const int16_t *r0, const int16_t *r1, |
| 121 | const uint8_t *m, int N) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 122 | uint64_t acc = 0; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 123 | for (int i = 0; i < N; i++) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 124 | const int32_t m0 = m[i]; |
| 125 | const int32_t m1 = MAX_MASK_VALUE - m0; |
| 126 | const int32_t r = m0 * r0[i] + m1 * r1[i]; |
| 127 | acc += r * r; |
| 128 | } |
| 129 | return ROUND_POWER_OF_TWO(acc, 2 * WEDGE_WEIGHT_BITS); |
| 130 | } |
| 131 | |
| 132 | TEST_F(WedgeUtilsSSEFuncTest, ResidualBlendingMethod) { |
| 133 | DECLARE_ALIGNED(32, int16_t, r0[MAX_SB_SQUARE]); |
| 134 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 135 | DECLARE_ALIGNED(32, int16_t, d[MAX_SB_SQUARE]); |
| 136 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 137 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 138 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
| 139 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 140 | r1[i] = rng_(2 * INT8_MAX - 2 * INT8_MIN + 1) + 2 * INT8_MIN; |
| 141 | d[i] = rng_(2 * INT8_MAX - 2 * INT8_MIN + 1) + 2 * INT8_MIN; |
| 142 | m[i] = rng_(MAX_MASK_VALUE + 1); |
| 143 | } |
| 144 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 145 | const int N = 64 * (rng_(MAX_SB_SQUARE / 64) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 146 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 147 | for (int i = 0; i < N; i++) r0[i] = r1[i] + d[i]; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 148 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 149 | const uint64_t ref_res = sse_from_residuals(r0, r1, m, N); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 150 | const uint64_t tst_res = av1_wedge_sse_from_residuals(r1, d, m, N); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 151 | |
| 152 | ASSERT_EQ(ref_res, tst_res); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | ////////////////////////////////////////////////////////////////////////////// |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 157 | // av1_wedge_sse_from_residuals - optimizations |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 158 | ////////////////////////////////////////////////////////////////////////////// |
| 159 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 160 | typedef uint64_t (*FSSE)(const int16_t *r1, const int16_t *d, const uint8_t *m, |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 161 | int N); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | typedef libaom_test::FuncParam<FSSE> TestFuncsFSSE; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 163 | |
| 164 | class WedgeUtilsSSEOptTest : public FunctionEquivalenceTest<FSSE> { |
| 165 | protected: |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 166 | static const int kIterations = 10000; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | TEST_P(WedgeUtilsSSEOptTest, RandomValues) { |
| 170 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 171 | DECLARE_ALIGNED(32, int16_t, d[MAX_SB_SQUARE]); |
| 172 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 173 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 174 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
| 175 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 176 | r1[i] = rng_(2 * kInt13Max + 1) - kInt13Max; |
| 177 | d[i] = rng_(2 * kInt13Max + 1) - kInt13Max; |
| 178 | m[i] = rng_(MAX_MASK_VALUE + 1); |
| 179 | } |
| 180 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 181 | const int N = 64 * (rng_(MAX_SB_SQUARE / 64) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 182 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 183 | const uint64_t ref_res = params_.ref_func(r1, d, m, N); |
| 184 | uint64_t tst_res; |
| 185 | ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(r1, d, m, N)); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 186 | |
| 187 | ASSERT_EQ(ref_res, tst_res); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | TEST_P(WedgeUtilsSSEOptTest, ExtremeValues) { |
| 192 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 193 | DECLARE_ALIGNED(32, int16_t, d[MAX_SB_SQUARE]); |
| 194 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 195 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 196 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 197 | if (rng_(2)) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 198 | for (int i = 0; i < MAX_SB_SQUARE; ++i) r1[i] = kInt13Max; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 199 | } else { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 200 | for (int i = 0; i < MAX_SB_SQUARE; ++i) r1[i] = -kInt13Max; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | if (rng_(2)) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 204 | for (int i = 0; i < MAX_SB_SQUARE; ++i) d[i] = kInt13Max; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 205 | } else { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 206 | for (int i = 0; i < MAX_SB_SQUARE; ++i) d[i] = -kInt13Max; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 207 | } |
| 208 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 209 | for (int i = 0; i < MAX_SB_SQUARE; ++i) m[i] = MAX_MASK_VALUE; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 210 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 211 | const int N = 64 * (rng_(MAX_SB_SQUARE / 64) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 212 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 213 | const uint64_t ref_res = params_.ref_func(r1, d, m, N); |
| 214 | uint64_t tst_res; |
| 215 | ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(r1, d, m, N)); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 216 | |
| 217 | ASSERT_EQ(ref_res, tst_res); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | #if HAVE_SSE2 |
| 222 | INSTANTIATE_TEST_CASE_P( |
| 223 | SSE2, WedgeUtilsSSEOptTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 224 | ::testing::Values(TestFuncsFSSE(av1_wedge_sse_from_residuals_c, |
| 225 | av1_wedge_sse_from_residuals_sse2))); |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 226 | |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 227 | #endif // HAVE_SSE2 |
| 228 | |
| 229 | ////////////////////////////////////////////////////////////////////////////// |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 230 | // av1_wedge_sign_from_residuals |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 231 | ////////////////////////////////////////////////////////////////////////////// |
| 232 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 233 | typedef int (*FSign)(const int16_t *ds, const uint8_t *m, int N, int64_t limit); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | typedef libaom_test::FuncParam<FSign> TestFuncsFSign; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 235 | |
| 236 | class WedgeUtilsSignOptTest : public FunctionEquivalenceTest<FSign> { |
| 237 | protected: |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 238 | static const int kIterations = 10000; |
| 239 | static const int kMaxSize = 8196; // Size limited by SIMD implementation. |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | TEST_P(WedgeUtilsSignOptTest, RandomValues) { |
| 243 | DECLARE_ALIGNED(32, int16_t, r0[MAX_SB_SQUARE]); |
| 244 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 245 | DECLARE_ALIGNED(32, int16_t, ds[MAX_SB_SQUARE]); |
| 246 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 247 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 248 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
| 249 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 250 | r0[i] = rng_(2 * kInt13Max + 1) - kInt13Max; |
| 251 | r1[i] = rng_(2 * kInt13Max + 1) - kInt13Max; |
| 252 | m[i] = rng_(MAX_MASK_VALUE + 1); |
| 253 | } |
| 254 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 255 | const int maxN = AOMMIN(kMaxSize, MAX_SB_SQUARE); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 256 | const int N = 64 * (rng_(maxN / 64 - 1) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 257 | |
| 258 | int64_t limit; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 259 | limit = (int64_t)aom_sum_squares_i16(r0, N); |
| 260 | limit -= (int64_t)aom_sum_squares_i16(r1, N); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 261 | limit *= (1 << WEDGE_WEIGHT_BITS) / 2; |
| 262 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 263 | for (int i = 0; i < N; i++) |
| 264 | ds[i] = clamp(r0[i] * r0[i] - r1[i] * r1[i], INT16_MIN, INT16_MAX); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 265 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 266 | const int ref_res = params_.ref_func(ds, m, N, limit); |
| 267 | int tst_res; |
| 268 | ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(ds, m, N, limit)); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 269 | |
| 270 | ASSERT_EQ(ref_res, tst_res); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | TEST_P(WedgeUtilsSignOptTest, ExtremeValues) { |
| 275 | DECLARE_ALIGNED(32, int16_t, r0[MAX_SB_SQUARE]); |
| 276 | DECLARE_ALIGNED(32, int16_t, r1[MAX_SB_SQUARE]); |
| 277 | DECLARE_ALIGNED(32, int16_t, ds[MAX_SB_SQUARE]); |
| 278 | DECLARE_ALIGNED(32, uint8_t, m[MAX_SB_SQUARE]); |
| 279 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 280 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 281 | switch (rng_(4)) { |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 282 | case 0: |
| 283 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
| 284 | r0[i] = 0; |
| 285 | r1[i] = kInt13Max; |
| 286 | } |
| 287 | break; |
| 288 | case 1: |
| 289 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
| 290 | r0[i] = kInt13Max; |
| 291 | r1[i] = 0; |
| 292 | } |
| 293 | break; |
| 294 | case 2: |
| 295 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
| 296 | r0[i] = 0; |
| 297 | r1[i] = -kInt13Max; |
| 298 | } |
| 299 | break; |
| 300 | default: |
| 301 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
| 302 | r0[i] = -kInt13Max; |
| 303 | r1[i] = 0; |
| 304 | } |
| 305 | break; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 306 | } |
| 307 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 308 | for (int i = 0; i < MAX_SB_SQUARE; ++i) m[i] = MAX_MASK_VALUE; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 309 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 310 | const int maxN = AOMMIN(kMaxSize, MAX_SB_SQUARE); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 311 | const int N = 64 * (rng_(maxN / 64 - 1) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 312 | |
| 313 | int64_t limit; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 314 | limit = (int64_t)aom_sum_squares_i16(r0, N); |
| 315 | limit -= (int64_t)aom_sum_squares_i16(r1, N); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 316 | limit *= (1 << WEDGE_WEIGHT_BITS) / 2; |
| 317 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 318 | for (int i = 0; i < N; i++) |
| 319 | ds[i] = clamp(r0[i] * r0[i] - r1[i] * r1[i], INT16_MIN, INT16_MAX); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 320 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 321 | const int ref_res = params_.ref_func(ds, m, N, limit); |
| 322 | int tst_res; |
| 323 | ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(ds, m, N, limit)); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 324 | |
| 325 | ASSERT_EQ(ref_res, tst_res); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | #if HAVE_SSE2 |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 330 | |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 331 | INSTANTIATE_TEST_CASE_P( |
| 332 | SSE2, WedgeUtilsSignOptTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 333 | ::testing::Values(TestFuncsFSign(av1_wedge_sign_from_residuals_c, |
| 334 | av1_wedge_sign_from_residuals_sse2))); |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 335 | |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 336 | #endif // HAVE_SSE2 |
| 337 | |
| 338 | ////////////////////////////////////////////////////////////////////////////// |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 339 | // av1_wedge_compute_delta_squares |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 340 | ////////////////////////////////////////////////////////////////////////////// |
| 341 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 342 | typedef void (*FDS)(int16_t *d, const int16_t *a, const int16_t *b, int N); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 343 | typedef libaom_test::FuncParam<FDS> TestFuncsFDS; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 344 | |
| 345 | class WedgeUtilsDeltaSquaresOptTest : public FunctionEquivalenceTest<FDS> { |
| 346 | protected: |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 347 | static const int kIterations = 10000; |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | TEST_P(WedgeUtilsDeltaSquaresOptTest, RandomValues) { |
| 351 | DECLARE_ALIGNED(32, int16_t, a[MAX_SB_SQUARE]); |
| 352 | DECLARE_ALIGNED(32, int16_t, b[MAX_SB_SQUARE]); |
| 353 | DECLARE_ALIGNED(32, int16_t, d_ref[MAX_SB_SQUARE]); |
| 354 | DECLARE_ALIGNED(32, int16_t, d_tst[MAX_SB_SQUARE]); |
| 355 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 356 | for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) { |
| 357 | for (int i = 0; i < MAX_SB_SQUARE; ++i) { |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 358 | a[i] = rng_.Rand16(); |
| 359 | b[i] = rng_(2 * INT16_MAX + 1) - INT16_MAX; |
| 360 | } |
| 361 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 362 | const int N = 64 * (rng_(MAX_SB_SQUARE / 64) + 1); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 363 | |
| 364 | memset(&d_ref, INT16_MAX, sizeof(d_ref)); |
| 365 | memset(&d_tst, INT16_MAX, sizeof(d_tst)); |
| 366 | |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 367 | params_.ref_func(d_ref, a, b, N); |
| 368 | ASM_REGISTER_STATE_CHECK(params_.tst_func(d_tst, a, b, N)); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 369 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 370 | for (int i = 0; i < MAX_SB_SQUARE; ++i) ASSERT_EQ(d_ref[i], d_tst[i]); |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | #if HAVE_SSE2 |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 375 | |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 376 | INSTANTIATE_TEST_CASE_P( |
| 377 | SSE2, WedgeUtilsDeltaSquaresOptTest, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 378 | ::testing::Values(TestFuncsFDS(av1_wedge_compute_delta_squares_c, |
| 379 | av1_wedge_compute_delta_squares_sse2))); |
Geza Lore | a3f7ddc | 2016-07-12 15:26:36 +0100 | [diff] [blame] | 380 | |
Geza Lore | 2791d9d | 2016-06-21 20:29:21 +0100 | [diff] [blame] | 381 | #endif // HAVE_SSE2 |
| 382 | |
| 383 | } // namespace |