2 * Copyright (c) 2016 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
16 #include "third_party/googletest/src/include/gtest/gtest.h"
18 #include "./vpx_config.h"
19 #include "./vpx_dsp_rtcd.h"
20 #include "test/acm_random.h"
21 #include "test/clear_system_state.h"
22 #include "test/register_state_check.h"
23 #include "test/util.h"
24 #include "vpx_ports/mem.h"
26 using libvpx_test::ACMRandom;
29 const int kNumIterations = 10000;
31 typedef uint64_t (*SSI16Func)(const int16_t *src, int stride, int size);
32 typedef std::tuple<SSI16Func, SSI16Func> SumSquaresParam;
34 class SumSquaresTest : public ::testing::TestWithParam<SumSquaresParam> {
36 virtual ~SumSquaresTest() {}
37 virtual void SetUp() {
38 ref_func_ = GET_PARAM(0);
39 tst_func_ = GET_PARAM(1);
42 virtual void TearDown() { libvpx_test::ClearSystemState(); }
49 TEST_P(SumSquaresTest, OperationCheck) {
50 ACMRandom rnd(ACMRandom::DeterministicSeed());
51 DECLARE_ALIGNED(16, int16_t, src[256 * 256]);
52 const int msb = 11; // Up to 12 bit input
53 const int limit = 1 << (msb + 1);
55 for (int k = 0; k < kNumIterations; k++) {
56 const int size = 4 << rnd(6); // Up to 128x128
57 int stride = 4 << rnd(7); // Up to 256 stride
58 while (stride < size) { // Make sure it's valid
62 for (int i = 0; i < size; ++i) {
63 for (int j = 0; j < size; ++j) {
64 src[i * stride + j] = rnd(2) ? rnd(limit) : -rnd(limit);
68 const uint64_t res_ref = ref_func_(src, stride, size);
70 ASM_REGISTER_STATE_CHECK(res_tst = tst_func_(src, stride, size));
72 ASSERT_EQ(res_ref, res_tst) << "Error: Sum Squares Test"
73 << " C output does not match optimized output.";
77 TEST_P(SumSquaresTest, ExtremeValues) {
78 ACMRandom rnd(ACMRandom::DeterministicSeed());
79 DECLARE_ALIGNED(16, int16_t, src[256 * 256]);
80 const int msb = 11; // Up to 12 bit input
81 const int limit = 1 << (msb + 1);
83 for (int k = 0; k < kNumIterations; k++) {
84 const int size = 4 << rnd(6); // Up to 128x128
85 int stride = 4 << rnd(7); // Up to 256 stride
86 while (stride < size) { // Make sure it's valid
90 const int val = rnd(2) ? limit - 1 : -(limit - 1);
91 for (int i = 0; i < size; ++i) {
92 for (int j = 0; j < size; ++j) {
93 src[i * stride + j] = val;
97 const uint64_t res_ref = ref_func_(src, stride, size);
99 ASM_REGISTER_STATE_CHECK(res_tst = tst_func_(src, stride, size));
101 ASSERT_EQ(res_ref, res_tst) << "Error: Sum Squares Test"
102 << " C output does not match optimized output.";
106 using std::make_tuple;
109 INSTANTIATE_TEST_SUITE_P(
110 NEON, SumSquaresTest,
111 ::testing::Values(make_tuple(&vpx_sum_squares_2d_i16_c,
112 &vpx_sum_squares_2d_i16_neon)));
116 INSTANTIATE_TEST_SUITE_P(
117 SSE2, SumSquaresTest,
118 ::testing::Values(make_tuple(&vpx_sum_squares_2d_i16_c,
119 &vpx_sum_squares_2d_i16_sse2)));
123 INSTANTIATE_TEST_SUITE_P(
125 ::testing::Values(make_tuple(&vpx_sum_squares_2d_i16_c,
126 &vpx_sum_squares_2d_i16_msa)));