1 /*
2 * Copyright (c) 2018, 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 "test/function_equivalence_test.h"
15 #include "test/register_state_check.h"
16
17 #include "config/aom_config.h"
18 #include "config/aom_dsp_rtcd.h"
19
20 #include "aom/aom_integer.h"
21 #include "av1/encoder/pickrst.h"
22 using libaom_test::FunctionEquivalenceTest;
23
24 #define MAX_DATA_BLOCK 384
25
26 namespace {
27 static const int kIterations = 100;
28
29 typedef int64_t (*lowbd_pixel_proj_error_func)(
30 const uint8_t *src8, int width, int height, int src_stride,
31 const uint8_t *dat8, int dat_stride, int32_t *flt0, int flt0_stride,
32 int32_t *flt1, int flt1_stride, int xq[2], const sgr_params_type *params);
33
34 typedef libaom_test::FuncParam<lowbd_pixel_proj_error_func> TestFuncs;
35
36 ////////////////////////////////////////////////////////////////////////////////
37 // 8 bit
38 ////////////////////////////////////////////////////////////////////////////////
39
40 typedef ::testing::tuple<const lowbd_pixel_proj_error_func>
41 PixelProjErrorTestParam;
42
43 class PixelProjErrorTest
44 : public ::testing::TestWithParam<PixelProjErrorTestParam> {
45 public:
SetUp()46 virtual void SetUp() {
47 target_func_ = GET_PARAM(0);
48 src_ = (uint8_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
49 sizeof(uint8_t)));
50 dgd_ = (uint8_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
51 sizeof(uint8_t)));
52 flt0_ = (int32_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
53 sizeof(int32_t)));
54 flt1_ = (int32_t *)(aom_malloc(MAX_DATA_BLOCK * MAX_DATA_BLOCK *
55 sizeof(int32_t)));
56 }
TearDown()57 virtual void TearDown() {
58 aom_free(src_);
59 aom_free(dgd_);
60 aom_free(flt0_);
61 aom_free(flt1_);
62 }
63 void runPixelProjErrorTest(int32_t run_times);
64 void runPixelProjErrorTest_ExtremeValues();
65
66 private:
67 lowbd_pixel_proj_error_func target_func_;
68 ACMRandom rng_;
69 uint8_t *src_;
70 uint8_t *dgd_;
71 int32_t *flt0_;
72 int32_t *flt1_;
73 };
74
runPixelProjErrorTest(int32_t run_times)75 void PixelProjErrorTest::runPixelProjErrorTest(int32_t run_times) {
76 int h_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
77 int v_end = run_times != 1 ? 128 : (rng_.Rand16() % MAX_DATA_BLOCK) + 1;
78 const int dgd_stride = MAX_DATA_BLOCK;
79 const int src_stride = MAX_DATA_BLOCK;
80 const int flt0_stride = MAX_DATA_BLOCK;
81 const int flt1_stride = MAX_DATA_BLOCK;
82 sgr_params_type params;
83 int xq[2];
84 const int iters = run_times == 1 ? kIterations : 4;
85 for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
86 int64_t err_ref = 0, err_test = 1;
87 for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
88 dgd_[i] = rng_.Rand8();
89 src_[i] = rng_.Rand8();
90 flt0_[i] = rng_.Rand15Signed();
91 flt1_[i] = rng_.Rand15Signed();
92 }
93 xq[0] = rng_.Rand8() % (1 << SGRPROJ_PRJ_BITS);
94 xq[1] = rng_.Rand8() % (1 << SGRPROJ_PRJ_BITS);
95 params.r[0] = run_times == 1 ? (rng_.Rand8() % MAX_RADIUS) : (iter % 2);
96 params.r[1] = run_times == 1 ? (rng_.Rand8() % MAX_RADIUS) : (iter / 2);
97 params.s[0] = run_times == 1 ? (rng_.Rand8() % MAX_RADIUS) : (iter % 2);
98 params.s[1] = run_times == 1 ? (rng_.Rand8() % MAX_RADIUS) : (iter / 2);
99 uint8_t *dgd = dgd_;
100 uint8_t *src = src_;
101
102 aom_usec_timer timer;
103 aom_usec_timer_start(&timer);
104 for (int i = 0; i < run_times; ++i) {
105 err_ref = av1_lowbd_pixel_proj_error_c(src, h_end, v_end, src_stride, dgd,
106 dgd_stride, flt0_, flt0_stride,
107 flt1_, flt1_stride, xq, ¶ms);
108 }
109 aom_usec_timer_mark(&timer);
110 const double time1 = static_cast<double>(aom_usec_timer_elapsed(&timer));
111 aom_usec_timer_start(&timer);
112 for (int i = 0; i < run_times; ++i) {
113 err_test =
114 target_func_(src, h_end, v_end, src_stride, dgd, dgd_stride, flt0_,
115 flt0_stride, flt1_, flt1_stride, xq, ¶ms);
116 }
117 aom_usec_timer_mark(&timer);
118 const double time2 = static_cast<double>(aom_usec_timer_elapsed(&timer));
119 if (run_times > 10) {
120 printf("r0 %d r1 %d %3dx%-3d:%7.2f/%7.2fns (%3.2f)\n", params.r[0],
121 params.r[1], h_end, v_end, time1, time2, time1 / time2);
122 }
123 ASSERT_EQ(err_ref, err_test);
124 }
125 }
126
runPixelProjErrorTest_ExtremeValues()127 void PixelProjErrorTest::runPixelProjErrorTest_ExtremeValues() {
128 const int h_start = 0;
129 int h_end = 192;
130 const int v_start = 0;
131 int v_end = 192;
132 const int dgd_stride = MAX_DATA_BLOCK;
133 const int src_stride = MAX_DATA_BLOCK;
134 const int flt0_stride = MAX_DATA_BLOCK;
135 const int flt1_stride = MAX_DATA_BLOCK;
136 sgr_params_type params;
137 int xq[2];
138 const int iters = kIterations;
139 for (int iter = 0; iter < iters && !HasFatalFailure(); ++iter) {
140 int64_t err_ref = 0, err_test = 1;
141 for (int i = 0; i < MAX_DATA_BLOCK * MAX_DATA_BLOCK; ++i) {
142 dgd_[i] = 0;
143 src_[i] = 255;
144 flt0_[i] = rng_.Rand15Signed();
145 flt1_[i] = rng_.Rand15Signed();
146 }
147 xq[0] = rng_.Rand8() % (1 << SGRPROJ_PRJ_BITS);
148 xq[1] = rng_.Rand8() % (1 << SGRPROJ_PRJ_BITS);
149 params.r[0] = rng_.Rand8() % MAX_RADIUS;
150 params.r[1] = rng_.Rand8() % MAX_RADIUS;
151 params.s[0] = rng_.Rand8() % MAX_RADIUS;
152 params.s[1] = rng_.Rand8() % MAX_RADIUS;
153 uint8_t *dgd = dgd_;
154 uint8_t *src = src_;
155
156 err_ref = av1_lowbd_pixel_proj_error_c(
157 src, h_end - h_start, v_end - v_start, src_stride, dgd, dgd_stride,
158 flt0_, flt0_stride, flt1_, flt1_stride, xq, ¶ms);
159
160 err_test = target_func_(src, h_end - h_start, v_end - v_start, src_stride,
161 dgd, dgd_stride, flt0_, flt0_stride, flt1_,
162 flt1_stride, xq, ¶ms);
163
164 ASSERT_EQ(err_ref, err_test);
165 }
166 }
167
TEST_P(PixelProjErrorTest,RandomValues)168 TEST_P(PixelProjErrorTest, RandomValues) { runPixelProjErrorTest(1); }
169
TEST_P(PixelProjErrorTest,ExtremeValues)170 TEST_P(PixelProjErrorTest, ExtremeValues) {
171 runPixelProjErrorTest_ExtremeValues();
172 }
173
TEST_P(PixelProjErrorTest,DISABLED_Speed)174 TEST_P(PixelProjErrorTest, DISABLED_Speed) { runPixelProjErrorTest(200000); }
175
176 #if HAVE_SSE4_1
177 INSTANTIATE_TEST_CASE_P(SSE4_1, PixelProjErrorTest,
178 ::testing::Values(av1_lowbd_pixel_proj_error_sse4_1));
179 #endif // HAVE_SSE4_1
180
181 #if HAVE_AVX2
182
183 INSTANTIATE_TEST_CASE_P(AVX2, PixelProjErrorTest,
184 ::testing::Values(av1_lowbd_pixel_proj_error_avx2));
185 #endif // HAVE_AVX2
186
187 } // namespace
188