2016-02-12 19:04:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
|
2016-02-12 19:04:35 +03:00
|
|
|
#include "third_party/googletest/src/include/gtest/gtest.h"
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "./aom_config.h"
|
|
|
|
#include "./aom_dsp_rtcd.h"
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_ports/mem.h"
|
2016-06-10 09:38:31 +03:00
|
|
|
#include "test/acm_random.h"
|
|
|
|
#include "test/clear_system_state.h"
|
2016-06-01 15:57:47 +03:00
|
|
|
#include "test/register_state_check.h"
|
2016-06-10 09:38:31 +03:00
|
|
|
#include "test/util.h"
|
2016-06-21 22:23:13 +03:00
|
|
|
#include "test/function_equivalence_test.h"
|
2016-02-12 19:04:35 +03:00
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
using libaom_test::ACMRandom;
|
|
|
|
using libaom_test::FunctionEquivalenceTest;
|
2016-06-01 15:57:47 +03:00
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
namespace {
|
|
|
|
const int kNumIterations = 10000;
|
2016-02-12 19:04:35 +03:00
|
|
|
|
2016-06-21 22:23:13 +03:00
|
|
|
static const int16_t kInt13Max = (1 << 12) - 1;
|
|
|
|
|
2016-07-12 17:26:36 +03:00
|
|
|
typedef uint64_t (*SSI16Func)(const int16_t *src, int stride, int size);
|
2016-08-23 02:08:15 +03:00
|
|
|
typedef libaom_test::FuncParam<SSI16Func> TestFuncs;
|
2016-02-12 19:04:35 +03:00
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
class SumSquaresTest : public ::testing::TestWithParam<TestFuncs> {
|
2016-06-10 09:38:31 +03:00
|
|
|
public:
|
|
|
|
virtual ~SumSquaresTest() {}
|
2016-08-12 03:46:05 +03:00
|
|
|
virtual void SetUp() { params_ = this->GetParam(); }
|
2016-06-01 15:57:47 +03:00
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
virtual void TearDown() { libaom_test::ClearSystemState(); }
|
2016-06-01 15:57:47 +03:00
|
|
|
|
|
|
|
protected:
|
2016-07-12 17:26:36 +03:00
|
|
|
TestFuncs params_;
|
2016-06-01 15:57:47 +03:00
|
|
|
};
|
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
TEST_P(SumSquaresTest, OperationCheck) {
|
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
2016-08-12 03:46:05 +03:00
|
|
|
DECLARE_ALIGNED(16, int16_t, src[256 * 256]);
|
2016-06-01 15:57:47 +03:00
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
int failed = 0;
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
const int msb = 11; // Up to 12 bit input
|
|
|
|
const int limit = 1 << (msb + 1);
|
2016-06-10 09:38:31 +03:00
|
|
|
|
|
|
|
for (int k = 0; k < kNumIterations; k++) {
|
2016-08-12 03:46:05 +03:00
|
|
|
int size = 4 << rnd(6); // Up to 128x128
|
|
|
|
int stride = 4 << rnd(7); // Up to 256 stride
|
|
|
|
while (stride < size) { // Make sure it's valid
|
2016-06-10 09:38:31 +03:00
|
|
|
stride = 4 << rnd(7);
|
|
|
|
}
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
for (int ii = 0; ii < size; ii++) {
|
2016-06-10 09:38:31 +03:00
|
|
|
for (int jj = 0; jj < size; jj++) {
|
2016-08-12 03:46:05 +03:00
|
|
|
src[ii * stride + jj] = rnd(2) ? rnd(limit) : -rnd(limit);
|
2016-06-10 09:38:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 17:26:36 +03:00
|
|
|
const uint64_t res_ref = params_.ref_func(src, stride, size);
|
2016-06-10 09:38:31 +03:00
|
|
|
uint64_t res_tst;
|
2016-07-12 17:26:36 +03:00
|
|
|
ASM_REGISTER_STATE_CHECK(res_tst = params_.tst_func(src, stride, size));
|
2016-06-10 09:38:31 +03:00
|
|
|
|
|
|
|
if (!failed) {
|
|
|
|
failed = res_ref != res_tst;
|
|
|
|
EXPECT_EQ(res_ref, res_tst)
|
2016-08-12 03:46:05 +03:00
|
|
|
<< "Error: Sum Squares Test"
|
|
|
|
<< " C output does not match optimized output.";
|
2016-06-10 09:38:31 +03:00
|
|
|
}
|
2016-06-01 15:57:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
TEST_P(SumSquaresTest, ExtremeValues) {
|
|
|
|
ACMRandom rnd(ACMRandom::DeterministicSeed());
|
2016-08-12 03:46:05 +03:00
|
|
|
DECLARE_ALIGNED(16, int16_t, src[256 * 256]);
|
2016-06-01 15:57:47 +03:00
|
|
|
|
2016-06-10 09:38:31 +03:00
|
|
|
int failed = 0;
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
const int msb = 11; // Up to 12 bit input
|
|
|
|
const int limit = 1 << (msb + 1);
|
2016-06-10 09:38:31 +03:00
|
|
|
|
|
|
|
for (int k = 0; k < kNumIterations; k++) {
|
2016-08-12 03:46:05 +03:00
|
|
|
int size = 4 << rnd(6); // Up to 128x128
|
|
|
|
int stride = 4 << rnd(7); // Up to 256 stride
|
|
|
|
while (stride < size) { // Make sure it's valid
|
2016-06-10 09:38:31 +03:00
|
|
|
stride = 4 << rnd(7);
|
|
|
|
}
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
int val = rnd(2) ? limit - 1 : -(limit - 1);
|
|
|
|
for (int ii = 0; ii < size; ii++) {
|
2016-06-10 09:38:31 +03:00
|
|
|
for (int jj = 0; jj < size; jj++) {
|
2016-08-12 03:46:05 +03:00
|
|
|
src[ii * stride + jj] = val;
|
2016-06-10 09:38:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 17:26:36 +03:00
|
|
|
const uint64_t res_ref = params_.ref_func(src, stride, size);
|
2016-06-10 09:38:31 +03:00
|
|
|
uint64_t res_tst;
|
2016-07-12 17:26:36 +03:00
|
|
|
ASM_REGISTER_STATE_CHECK(res_tst = params_.tst_func(src, stride, size));
|
2016-06-10 09:38:31 +03:00
|
|
|
|
|
|
|
if (!failed) {
|
|
|
|
failed = res_ref != res_tst;
|
|
|
|
EXPECT_EQ(res_ref, res_tst)
|
2016-08-12 03:46:05 +03:00
|
|
|
<< "Error: Sum Squares Test"
|
|
|
|
<< " C output does not match optimized output.";
|
2016-06-10 09:38:31 +03:00
|
|
|
}
|
2016-06-01 15:57:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_SSE2
|
2016-06-10 09:38:31 +03:00
|
|
|
|
2016-06-01 15:57:47 +03:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
2016-06-10 09:38:31 +03:00
|
|
|
SSE2, SumSquaresTest,
|
2016-08-31 00:01:10 +03:00
|
|
|
::testing::Values(TestFuncs(&aom_sum_squares_2d_i16_c,
|
|
|
|
&aom_sum_squares_2d_i16_sse2)));
|
2016-07-12 17:26:36 +03:00
|
|
|
|
2016-06-01 15:57:47 +03:00
|
|
|
#endif // HAVE_SSE2
|
2016-06-21 22:23:13 +03:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 1D version
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef uint64_t (*F1D)(const int16_t *src, uint32_t N);
|
2016-08-23 02:08:15 +03:00
|
|
|
typedef libaom_test::FuncParam<F1D> TestFuncs1D;
|
2016-06-21 22:23:13 +03:00
|
|
|
|
|
|
|
class SumSquares1DTest : public FunctionEquivalenceTest<F1D> {
|
|
|
|
protected:
|
|
|
|
static const int kIterations = 1000;
|
|
|
|
static const int kMaxSize = 256;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(SumSquares1DTest, RandomValues) {
|
|
|
|
DECLARE_ALIGNED(16, int16_t, src[kMaxSize * kMaxSize]);
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
|
|
|
|
for (int i = 0; i < kMaxSize * kMaxSize; ++i)
|
2016-06-21 22:23:13 +03:00
|
|
|
src[i] = rng_(kInt13Max * 2 + 1) - kInt13Max;
|
|
|
|
|
|
|
|
const int N = rng_(2) ? rng_(kMaxSize * kMaxSize + 1 - kMaxSize) + kMaxSize
|
|
|
|
: rng_(kMaxSize) + 1;
|
|
|
|
|
2016-07-12 17:26:36 +03:00
|
|
|
const uint64_t ref_res = params_.ref_func(src, N);
|
|
|
|
uint64_t tst_res;
|
|
|
|
ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(src, N));
|
2016-06-21 22:23:13 +03:00
|
|
|
|
|
|
|
ASSERT_EQ(ref_res, tst_res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(SumSquares1DTest, ExtremeValues) {
|
|
|
|
DECLARE_ALIGNED(16, int16_t, src[kMaxSize * kMaxSize]);
|
|
|
|
|
2016-08-12 03:46:05 +03:00
|
|
|
for (int iter = 0; iter < kIterations && !HasFatalFailure(); ++iter) {
|
2016-06-21 22:23:13 +03:00
|
|
|
if (rng_(2)) {
|
2016-08-12 03:46:05 +03:00
|
|
|
for (int i = 0; i < kMaxSize * kMaxSize; ++i) src[i] = kInt13Max;
|
2016-06-21 22:23:13 +03:00
|
|
|
} else {
|
2016-08-12 03:46:05 +03:00
|
|
|
for (int i = 0; i < kMaxSize * kMaxSize; ++i) src[i] = -kInt13Max;
|
2016-06-21 22:23:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const int N = rng_(2) ? rng_(kMaxSize * kMaxSize + 1 - kMaxSize) + kMaxSize
|
|
|
|
: rng_(kMaxSize) + 1;
|
|
|
|
|
2016-07-12 17:26:36 +03:00
|
|
|
const uint64_t ref_res = params_.ref_func(src, N);
|
|
|
|
uint64_t tst_res;
|
|
|
|
ASM_REGISTER_STATE_CHECK(tst_res = params_.tst_func(src, N));
|
2016-06-21 22:23:13 +03:00
|
|
|
|
|
|
|
ASSERT_EQ(ref_res, tst_res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_SSE2
|
2016-08-12 03:46:05 +03:00
|
|
|
INSTANTIATE_TEST_CASE_P(SSE2, SumSquares1DTest,
|
|
|
|
::testing::Values(TestFuncs1D(
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_sum_squares_i16_c, aom_sum_squares_i16_sse2)));
|
2016-07-12 17:26:36 +03:00
|
|
|
|
2016-06-21 22:23:13 +03:00
|
|
|
#endif // HAVE_SSE2
|
2016-02-12 19:04:35 +03:00
|
|
|
} // namespace
|