Commit f8abdb03 authored by Steinar Midtskogen's avatar Steinar Midtskogen
Browse files

Improve unit tests for CDEF

Add boundary testing for both dering and CLPF.  Also add a CDEF prefix
to make it easy to select all CDEF tests.

Change-Id: Icd4fa4d778889cff1fd4a4e01c2b901703a431d3
parent bab3d6ac
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "./aom_config.h" #include "./aom_config.h"
#include "./av1_rtcd.h" #include "./av1_rtcd.h"
#include "aom_ports/aom_timer.h" #include "aom_ports/aom_timer.h"
#include "av1/common/od_dering.h"
#include "test/acm_random.h" #include "test/acm_random.h"
#include "test/clear_system_state.h" #include "test/clear_system_state.h"
#include "test/register_state_check.h" #include "test/register_state_check.h"
...@@ -33,9 +34,9 @@ typedef void (*clpf_block_t)(uint8_t *dst, const uint16_t *src, int dstride, ...@@ -33,9 +34,9 @@ typedef void (*clpf_block_t)(uint8_t *dst, const uint16_t *src, int dstride,
typedef std::tr1::tuple<clpf_block_t, clpf_block_t, int, int> typedef std::tr1::tuple<clpf_block_t, clpf_block_t, int, int>
clpf_block_param_t; clpf_block_param_t;
class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> { class CDEFClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> {
public: public:
virtual ~ClpfBlockTest() {} virtual ~CDEFClpfBlockTest() {}
virtual void SetUp() { virtual void SetUp() {
clpf = GET_PARAM(0); clpf = GET_PARAM(0);
ref_clpf = GET_PARAM(1); ref_clpf = GET_PARAM(1);
...@@ -52,7 +53,7 @@ class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> { ...@@ -52,7 +53,7 @@ class ClpfBlockTest : public ::testing::TestWithParam<clpf_block_param_t> {
clpf_block_t ref_clpf; clpf_block_t ref_clpf;
}; };
typedef ClpfBlockTest ClpfSpeedTest; typedef CDEFClpfBlockTest CDEFClpfSpeedTest;
#if CONFIG_AOM_HIGHBITDEPTH #if CONFIG_AOM_HIGHBITDEPTH
typedef void (*clpf_block_hbd_t)(uint16_t *dst, const uint16_t *src, typedef void (*clpf_block_hbd_t)(uint16_t *dst, const uint16_t *src,
...@@ -62,10 +63,10 @@ typedef void (*clpf_block_hbd_t)(uint16_t *dst, const uint16_t *src, ...@@ -62,10 +63,10 @@ typedef void (*clpf_block_hbd_t)(uint16_t *dst, const uint16_t *src,
typedef std::tr1::tuple<clpf_block_hbd_t, clpf_block_hbd_t, int, int> typedef std::tr1::tuple<clpf_block_hbd_t, clpf_block_hbd_t, int, int>
clpf_block_hbd_param_t; clpf_block_hbd_param_t;
class ClpfBlockHbdTest class CDEFClpfBlockHbdTest
: public ::testing::TestWithParam<clpf_block_hbd_param_t> { : public ::testing::TestWithParam<clpf_block_hbd_param_t> {
public: public:
virtual ~ClpfBlockHbdTest() {} virtual ~CDEFClpfBlockHbdTest() {}
virtual void SetUp() { virtual void SetUp() {
clpf = GET_PARAM(0); clpf = GET_PARAM(0);
ref_clpf = GET_PARAM(1); ref_clpf = GET_PARAM(1);
...@@ -82,7 +83,7 @@ class ClpfBlockHbdTest ...@@ -82,7 +83,7 @@ class ClpfBlockHbdTest
clpf_block_hbd_t ref_clpf; clpf_block_hbd_t ref_clpf;
}; };
typedef ClpfBlockHbdTest ClpfHbdSpeedTest; typedef CDEFClpfBlockHbdTest ClpfHbdSpeedTest;
#endif #endif
template <typename pixel> template <typename pixel>
...@@ -102,7 +103,7 @@ void test_clpf(int w, int h, int depth, int iterations, ...@@ -102,7 +103,7 @@ void test_clpf(int w, int h, int depth, int iterations,
memset(d, 0, size * size * sizeof(*d)); memset(d, 0, size * size * sizeof(*d));
int error = 0, pos = 0, strength = 0, xpos = 8, ypos = 8; int error = 0, pos = 0, strength = 0, xpos = 8, ypos = 8;
int bits, level, count, damp = 0; int bits, level, count, damp = 0, boundary = 0;
assert(size >= w + 16 && size >= h + 16); assert(size >= w + 16 && size >= h + 16);
...@@ -111,26 +112,53 @@ void test_clpf(int w, int h, int depth, int iterations, ...@@ -111,26 +112,53 @@ void test_clpf(int w, int h, int depth, int iterations,
// * Noise level around every value from 0 to (1<<depth)-1 // * Noise level around every value from 0 to (1<<depth)-1
// * All strengths // * All strengths
// * All dampings // * All dampings
// * Boundaries
// If clpf and ref_clpf are the same, we're just testing speed // If clpf and ref_clpf are the same, we're just testing speed
for (count = 0; count < iterations; count++) { for (boundary = 0; boundary < 16; boundary++) {
for (level = 0; level < (1 << depth) && !error; level++) { for (count = 0; count < iterations; count++) {
for (bits = 1; bits <= depth && !error; bits++) { for (level = 0; level < (1 << depth) && !error;
for (damp = 4; damp < depth - 1 && !error; damp++) { level += (1 + 4 * !!boundary) << (depth - 8)) {
for (int i = 0; i < size * size; i++) for (bits = 1; bits <= depth && !error; bits++) {
s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0, for (damp = 4; damp < depth - 1 && !error; damp++) {
(1 << depth) - 1); for (int i = 0; i < size * size; i++)
for (strength = depth - 8; strength < depth - 5 && !error; s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0,
strength += !error) { (1 << depth) - 1);
ref_clpf(ref_d + ypos * size + xpos, s + ypos * size + xpos, size, if (boundary) {
size, w, h, 1 << strength, damp); if (boundary & 1) { // Left
if (clpf != ref_clpf) for (int i = 0; i < size; i++)
ASM_REGISTER_STATE_CHECK(clpf(d + ypos * size + xpos, for (int j = 0; j < xpos; j++)
s + ypos * size + xpos, size, size, s[i * size + j] = OD_DERING_VERY_LARGE;
w, h, 1 << strength, damp));
if (ref_clpf != clpf)
for (pos = 0; pos < size * size && !error; pos++) {
error = ref_d[pos] != d[pos];
} }
if (boundary & 2) { // Right
for (int i = 0; i < size; i++)
for (int j = xpos + w; j < size; j++)
s[i * size + j] = OD_DERING_VERY_LARGE;
}
if (boundary & 4) { // Above
for (int i = 0; i < ypos; i++)
for (int j = 0; j < size; j++)
s[i * size + j] = OD_DERING_VERY_LARGE;
}
if (boundary & 8) { // Below
for (int i = ypos + h; i < size; i++)
for (int j = 0; j < size; j++)
s[i * size + j] = OD_DERING_VERY_LARGE;
}
}
for (strength = depth - 8; strength < depth - 5 && !error;
strength += !error) {
ref_clpf(ref_d + ypos * size + xpos, s + ypos * size + xpos, size,
size, w, h, 1 << strength, damp);
if (clpf != ref_clpf)
ASM_REGISTER_STATE_CHECK(clpf(d + ypos * size + xpos,
s + ypos * size + xpos, size,
size, w, h, 1 << strength, damp));
if (ref_clpf != clpf) {
for (pos = 0; pos < size * size && !error; pos++) {
error = ref_d[pos] != d[pos];
}
}
}
} }
} }
} }
...@@ -139,11 +167,13 @@ void test_clpf(int w, int h, int depth, int iterations, ...@@ -139,11 +167,13 @@ void test_clpf(int w, int h, int depth, int iterations,
pos--; pos--;
EXPECT_EQ(0, error) EXPECT_EQ(0, error)
<< "Error: ClpfBlockTest, SIMD and C mismatch." << std::endl << "Error: CDEFClpfBlockTest, SIMD and C mismatch." << std::endl
<< "First error at " << pos % size << "," << pos / size << " (" << "First error at " << pos % size << "," << pos / size << " ("
<< (int16_t)ref_d[pos] << " != " << (int16_t)d[pos] << ") " << std::endl << (int16_t)ref_d[pos] << " != " << (int16_t)d[pos] << ") " << std::endl
<< "strength: " << (1 << strength) << std::endl << "strength: " << (1 << strength) << std::endl
<< "damping: " << damp << std::endl << "damping: " << damp << std::endl
<< "depth: " << depth << std::endl
<< "boundary: " << boundary << std::endl
<< "w: " << w << std::endl << "w: " << w << std::endl
<< "h: " << h << std::endl << "h: " << h << std::endl
<< "A=" << (pos > 2 * size ? (int16_t)s[pos - 2 * size] : -1) << std::endl << "A=" << (pos > 2 * size ? (int16_t)s[pos - 2 * size] : -1) << std::endl
...@@ -188,26 +218,26 @@ void test_clpf_speed(int w, int h, int depth, int iterations, ...@@ -188,26 +218,26 @@ void test_clpf_speed(int w, int h, int depth, int iterations,
#endif #endif
EXPECT_GT(ref_elapsed_time, elapsed_time) EXPECT_GT(ref_elapsed_time, elapsed_time)
<< "Error: ClpfSpeedTest, SIMD slower than C." << std::endl << "Error: CDEFClpfSpeedTest, SIMD slower than C." << std::endl
<< "C time: " << ref_elapsed_time << " us" << std::endl << "C time: " << ref_elapsed_time << " us" << std::endl
<< "SIMD time: " << elapsed_time << " us" << std::endl; << "SIMD time: " << elapsed_time << " us" << std::endl;
} }
TEST_P(ClpfBlockTest, TestSIMDNoMismatch) { TEST_P(CDEFClpfBlockTest, TestSIMDNoMismatch) {
test_clpf(sizex, sizey, 8, 16, clpf, ref_clpf); test_clpf(sizex, sizey, 8, 1, clpf, ref_clpf);
} }
TEST_P(ClpfSpeedTest, DISABLED_TestSpeed) { TEST_P(CDEFClpfSpeedTest, DISABLED_TestSpeed) {
test_clpf_speed(sizex, sizey, 8, 256, clpf, ref_clpf); test_clpf_speed(sizex, sizey, 8, 16, clpf, ref_clpf);
} }
#if CONFIG_AOM_HIGHBITDEPTH #if CONFIG_AOM_HIGHBITDEPTH
TEST_P(ClpfBlockHbdTest, TestSIMDNoMismatch) { TEST_P(CDEFClpfBlockHbdTest, TestSIMDNoMismatch) {
test_clpf(sizex, sizey, 12, 1, clpf, ref_clpf); test_clpf(sizex, sizey, 12, 1, clpf, ref_clpf);
} }
TEST_P(ClpfHbdSpeedTest, DISABLED_TestSpeed) { TEST_P(ClpfHbdSpeedTest, DISABLED_TestSpeed) {
test_clpf_speed(sizex, sizey, 12, 1, clpf, ref_clpf); test_clpf_speed(sizex, sizey, 12, 4, clpf, ref_clpf);
} }
#endif #endif
...@@ -220,7 +250,7 @@ using std::tr1::make_tuple; ...@@ -220,7 +250,7 @@ using std::tr1::make_tuple;
// Test all supported architectures and block sizes // Test all supported architectures and block sizes
#if HAVE_SSE2 #if HAVE_SSE2
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, ClpfBlockTest, SSE2, CDEFClpfBlockTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 8), make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 4), make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 4),
...@@ -234,7 +264,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -234,7 +264,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_SSSE3 #if HAVE_SSSE3
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSSE3, ClpfBlockTest, SSSE3, CDEFClpfBlockTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_ssse3, &aom_clpf_block_c, 8, 8), make_tuple(&aom_clpf_block_ssse3, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_block_ssse3, &aom_clpf_block_c, 8, 4), make_tuple(&aom_clpf_block_ssse3, &aom_clpf_block_c, 8, 4),
...@@ -248,7 +278,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -248,7 +278,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_SSE4_1 #if HAVE_SSE4_1
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE4_1, ClpfBlockTest, SSE4_1, CDEFClpfBlockTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_sse4_1, &aom_clpf_block_c, 8, 8), make_tuple(&aom_clpf_block_sse4_1, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_block_sse4_1, &aom_clpf_block_c, 8, 4), make_tuple(&aom_clpf_block_sse4_1, &aom_clpf_block_c, 8, 4),
...@@ -262,7 +292,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -262,7 +292,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_NEON #if HAVE_NEON
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, ClpfBlockTest, NEON, CDEFClpfBlockTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 8), make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 4), make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 4),
...@@ -277,7 +307,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -277,7 +307,7 @@ INSTANTIATE_TEST_CASE_P(
#if CONFIG_AOM_HIGHBITDEPTH #if CONFIG_AOM_HIGHBITDEPTH
#if HAVE_SSE2 #if HAVE_SSE2
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, ClpfBlockHbdTest, SSE2, CDEFClpfBlockHbdTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_hbd_sse2, &aom_clpf_block_hbd_c, 8, 8), make_tuple(&aom_clpf_block_hbd_sse2, &aom_clpf_block_hbd_c, 8, 8),
make_tuple(&aom_clpf_block_hbd_sse2, &aom_clpf_block_hbd_c, 8, 4), make_tuple(&aom_clpf_block_hbd_sse2, &aom_clpf_block_hbd_c, 8, 4),
...@@ -291,7 +321,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -291,7 +321,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_SSSE3 #if HAVE_SSSE3
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSSE3, ClpfBlockHbdTest, SSSE3, CDEFClpfBlockHbdTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_hbd_ssse3, &aom_clpf_block_hbd_c, 8, 8), make_tuple(&aom_clpf_block_hbd_ssse3, &aom_clpf_block_hbd_c, 8, 8),
make_tuple(&aom_clpf_block_hbd_ssse3, &aom_clpf_block_hbd_c, 8, 4), make_tuple(&aom_clpf_block_hbd_ssse3, &aom_clpf_block_hbd_c, 8, 4),
...@@ -305,7 +335,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -305,7 +335,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_SSE4_1 #if HAVE_SSE4_1
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE4_1, ClpfBlockHbdTest, SSE4_1, CDEFClpfBlockHbdTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_hbd_sse4_1, &aom_clpf_block_hbd_c, 8, 8), make_tuple(&aom_clpf_block_hbd_sse4_1, &aom_clpf_block_hbd_c, 8, 8),
make_tuple(&aom_clpf_block_hbd_sse4_1, &aom_clpf_block_hbd_c, 8, 4), make_tuple(&aom_clpf_block_hbd_sse4_1, &aom_clpf_block_hbd_c, 8, 4),
...@@ -319,7 +349,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -319,7 +349,7 @@ INSTANTIATE_TEST_CASE_P(
#if HAVE_NEON #if HAVE_NEON
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, ClpfBlockHbdTest, NEON, CDEFClpfBlockHbdTest,
::testing::Values( ::testing::Values(
make_tuple(&aom_clpf_block_hbd_neon, &aom_clpf_block_hbd_c, 8, 8), make_tuple(&aom_clpf_block_hbd_neon, &aom_clpf_block_hbd_c, 8, 8),
make_tuple(&aom_clpf_block_hbd_neon, &aom_clpf_block_hbd_c, 8, 4), make_tuple(&aom_clpf_block_hbd_neon, &aom_clpf_block_hbd_c, 8, 4),
...@@ -335,14 +365,14 @@ INSTANTIATE_TEST_CASE_P( ...@@ -335,14 +365,14 @@ INSTANTIATE_TEST_CASE_P(
// Test speed for all supported architectures // Test speed for all supported architectures
#if HAVE_SSE2 #if HAVE_SSE2
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
SSE2, ClpfSpeedTest, SSE2, CDEFClpfSpeedTest,
::testing::Values(make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 8), ::testing::Values(make_tuple(&aom_clpf_block_sse2, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_hblock_sse2, &aom_clpf_hblock_c, 8, make_tuple(&aom_clpf_hblock_sse2, &aom_clpf_hblock_c, 8,
8))); 8)));
#endif #endif
#if HAVE_SSSE3 #if HAVE_SSSE3
INSTANTIATE_TEST_CASE_P(SSSE3, ClpfSpeedTest, INSTANTIATE_TEST_CASE_P(SSSE3, CDEFClpfSpeedTest,
::testing::Values(make_tuple(&aom_clpf_block_ssse3, ::testing::Values(make_tuple(&aom_clpf_block_ssse3,
&aom_clpf_block_c, 8, 8), &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_hblock_ssse3, make_tuple(&aom_clpf_hblock_ssse3,
...@@ -351,7 +381,7 @@ INSTANTIATE_TEST_CASE_P(SSSE3, ClpfSpeedTest, ...@@ -351,7 +381,7 @@ INSTANTIATE_TEST_CASE_P(SSSE3, ClpfSpeedTest,
#endif #endif
#if HAVE_SSE4_1 #if HAVE_SSE4_1
INSTANTIATE_TEST_CASE_P(SSE4_1, ClpfSpeedTest, INSTANTIATE_TEST_CASE_P(SSE4_1, CDEFClpfSpeedTest,
::testing::Values(make_tuple(&aom_clpf_block_sse4_1, ::testing::Values(make_tuple(&aom_clpf_block_sse4_1,
&aom_clpf_block_c, 8, 8), &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_hblock_sse4_1, make_tuple(&aom_clpf_hblock_sse4_1,
...@@ -362,7 +392,7 @@ INSTANTIATE_TEST_CASE_P(SSE4_1, ClpfSpeedTest, ...@@ -362,7 +392,7 @@ INSTANTIATE_TEST_CASE_P(SSE4_1, ClpfSpeedTest,
#if HAVE_NEON #if HAVE_NEON
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
NEON, ClpfSpeedTest, NEON, CDEFClpfSpeedTest,
::testing::Values(make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 8), ::testing::Values(make_tuple(&aom_clpf_block_neon, &aom_clpf_block_c, 8, 8),
make_tuple(&aom_clpf_hblock_neon, &aom_clpf_hblock_c, 8, make_tuple(&aom_clpf_hblock_neon, &aom_clpf_hblock_c, 8,
8))); 8)));
......
...@@ -32,9 +32,9 @@ typedef int (*dering_dir_t)(uint16_t *y, int ystride, const uint16_t *in, ...@@ -32,9 +32,9 @@ typedef int (*dering_dir_t)(uint16_t *y, int ystride, const uint16_t *in,
typedef std::tr1::tuple<dering_dir_t, dering_dir_t, int> dering_dir_param_t; typedef std::tr1::tuple<dering_dir_t, dering_dir_t, int> dering_dir_param_t;
class DeringDirTest : public ::testing::TestWithParam<dering_dir_param_t> { class CDEFDeringDirTest : public ::testing::TestWithParam<dering_dir_param_t> {
public: public:
virtual ~DeringDirTest() {} virtual ~CDEFDeringDirTest() {}
virtual void SetUp() { virtual void SetUp() {
dering = GET_PARAM(0); dering = GET_PARAM(0);
ref_dering = GET_PARAM(1); ref_dering = GET_PARAM(1);
...@@ -49,7 +49,7 @@ class DeringDirTest : public ::testing::TestWithParam<dering_dir_param_t> { ...@@ -49,7 +49,7 @@ class DeringDirTest : public ::testing::TestWithParam<dering_dir_param_t> {
dering_dir_t ref_dering; dering_dir_t ref_dering;
}; };
typedef DeringDirTest DeringSpeedTest; typedef CDEFDeringDirTest CDEFDeringSpeedTest;
void test_dering(int bsize, int iterations, void test_dering(int bsize, int iterations,
int (*dering)(uint16_t *y, int ystride, const uint16_t *in, int (*dering)(uint16_t *y, int ystride, const uint16_t *in,
...@@ -66,38 +66,66 @@ void test_dering(int bsize, int iterations, ...@@ -66,38 +66,66 @@ void test_dering(int bsize, int iterations,
memset(d, 0, sizeof(d)); memset(d, 0, sizeof(d));
int error = 0, threshold = 0, dir; int error = 0, threshold = 0, dir;
int depth, bits, level, count, errdepth = 0, errthreshold = 0; int boundary, depth, bits, level, count, errdepth = 0, errthreshold = 0,
errboundary = 0;
unsigned int pos = 0; unsigned int pos = 0;
int ref_res = 0, res = 0; int ref_res = 0, res = 0;
for (depth = 8; depth <= 12; depth += 2) { for (boundary = 0; boundary < 16; boundary++) {
for (count = 0; count < iterations; count++) { for (depth = 8; depth <= 12; depth += 2) {
for (level = 0; level < (1 << depth) && !error; for (count = 0; count < iterations; count++) {
level += 1 << (depth - 8)) { for (level = 0; level < (1 << depth) && !error;
for (bits = 1; bits <= depth && !error; bits++) { level += (1 + 4 * !!boundary) << (depth - 8)) {
for (unsigned int i = 0; i < sizeof(s) / sizeof(*s); i++) for (bits = 1; bits <= depth && !error; bits++) {
s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0, for (unsigned int i = 0; i < sizeof(s) / sizeof(*s); i++)
(1 << depth) - 1); s[i] = clamp((rnd.Rand16() & ((1 << bits) - 1)) + level, 0,
for (dir = 0; dir < 8; dir++) { (1 << depth) - 1);
for (threshold = 0; threshold < 64 << (depth - 8) && !error; if (boundary) {
threshold += !error << (depth - 8)) { if (boundary & 1) { // Left
ref_res = ref_dering( for (int i = 0; i < ysize; i++)
ref_d, size, for (int j = 0; j < OD_FILT_HBORDER; j++)
s + OD_FILT_HBORDER + OD_FILT_VBORDER * OD_FILT_BSTRIDE, s[i * OD_FILT_BSTRIDE + j] = OD_DERING_VERY_LARGE;
threshold, dir); }
// If dering and ref_dering are the same, we're just testing speed if (boundary & 2) { // Right
if (dering != ref_dering) for (int i = 0; i < ysize; i++)
ASM_REGISTER_STATE_CHECK( for (int j = OD_FILT_HBORDER + size; j < OD_FILT_BSTRIDE; j++)
res = dering(d, size, s + OD_FILT_HBORDER + s[i * OD_FILT_BSTRIDE + j] = OD_DERING_VERY_LARGE;
}
if (boundary & 4) { // Above
for (int i = 0; i < OD_FILT_VBORDER; i++)
for (int j = 0; j < OD_FILT_BSTRIDE; j++)
s[i * OD_FILT_BSTRIDE + j] = OD_DERING_VERY_LARGE;
}
if (boundary & 8) { // Below
for (int i = OD_FILT_VBORDER + size; i < ysize; i++)
for (int j = 0; j < OD_FILT_BSTRIDE; j++)
s[i * OD_FILT_BSTRIDE + j] = OD_DERING_VERY_LARGE;
}
}
for (dir = 0; dir < 8; dir++) {
for (threshold = 0; threshold < 64 << (depth - 8) && !error;
threshold += !error << (depth - 8)) {
ref_res = ref_dering(
ref_d, size,
s + OD_FILT_HBORDER + OD_FILT_VBORDER * OD_FILT_BSTRIDE,
threshold, dir);
// If dering and ref_dering are the same, we're just testing
// speed
if (dering != ref_dering)
ASM_REGISTER_STATE_CHECK(
res =
dering(d, size, s + OD_FILT_HBORDER +
OD_FILT_VBORDER * OD_FILT_BSTRIDE, OD_FILT_VBORDER * OD_FILT_BSTRIDE,
threshold, dir)); threshold, dir));
if (ref_dering != dering) { if (ref_dering != dering) {
for (pos = 0; pos < sizeof(d) / sizeof(*d) && !error; pos++) { for (pos = 0; pos < sizeof(d) / sizeof(*d) && !error; pos++) {
error = ref_d[pos] != d[pos]; error = ref_d[pos] != d[pos];
errdepth = depth; errdepth = depth;
errthreshold = threshold; errthreshold = threshold;
errboundary = boundary;
}
error |= res != ref_res;
} }
error |= res != ref_res;
} }
} }
} }
...@@ -107,7 +135,7 @@ void test_dering(int bsize, int iterations, ...@@ -107,7 +135,7 @@ void test_dering(int bsize, int iterations,
} }
pos--; pos--;
EXPECT_EQ(0, error) << "Error: DeringDirTest, SIMD and C mismatch." EXPECT_EQ(0, error) << "Error: CDEFDeringDirTest, SIMD and C mismatch."
<< std::endl << std::endl
<< "First error at " << pos % size << "," << pos / size << "First error at " << pos % size << "," << pos / size
<< " (" << (int16_t)ref_d[pos] << " : " << (int16_t)d[pos] << " (" << (int16_t)ref_d[pos] << " : " << (int16_t)d[pos]
...@@ -116,6 +144,7 @@ void test_dering(int bsize, int iterations, ...@@ -116,6 +144,7 @@ void test_dering(int bsize, int iterations,
<< "threshold: " << errthreshold << std::endl << "threshold: " << errthreshold << std::endl
<< "depth: " << errdepth << std::endl << "depth: " << errdepth << std::endl
<< "size: " << bsize << std::endl << "size: " << bsize << std::endl
<< "boundary: " << errboundary << std::endl
<< std::endl; << std::endl;
} }
...@@ -145,7 +174,7 @@ void test_dering_speed(int bsize, int iterations, ...@@ -145,7 +174,7 @@ void test_dering_speed(int bsize, int iterations,
#endif #endif
EXPECT_GT(ref_elapsed_time, elapsed_time) EXPECT_GT(ref_elapsed_time, elapsed_time)
<< "Error: DeringSpeedTest, SIMD slower than C." << std::endl << "Error: CDEFDeringSpeedTest, SIMD slower than C." << std::endl
<< "C time: " << ref_elapsed_time << " us" << std::endl << "C time: " << ref_elapsed_time << " us" << std::endl
<< "SIMD time: " << elapsed_time << " us" << std::endl; << "SIMD time: " << elapsed_time << " us" << std::endl;
} }
...@@ -155,9 +184,10 @@ typedef int (*find_dir_t)(const od_dering_in *img, int stride, int32_t *var, ...@@ -155,9 +184,10 @@ typedef int (*find_dir_t)(const od_dering_in *img, int stride, int32_t *var,
typedef std::tr1::tuple<find_dir_t, find_dir_t> find_dir_param_t; typedef std::tr1::tuple<find_dir_t, find_dir_t> find_dir_param_t;
class DeringFindDirTest : public ::testing::TestWithParam<find_dir_param_t> { class CDEFDeringFindDirTest
: public ::testing::TestWithParam<find_dir_param_t> {
public: public:
virtual ~DeringFindDirTest() {} virtual ~CDEFDeringFindDirTest() {}
virtual void SetUp() { virtual void SetUp() {
finddir = GET_PARAM(0); finddir = GET_PARAM(0);
ref_finddir = GET_PARAM(1); ref_finddir = GET_PARAM(1);
...@@ -170,7 +200,7 @@ class DeringFindDirTest : public ::testing::TestWithParam<find_dir_param_t> { ...@@ -170,7 +200,7 @@ class DeringFindDirTest : public ::testing::TestWithParam<find_dir_param_t> {
find_dir_t ref_finddir; find_dir_t ref_finddir;
}; };
typedef DeringFindDirTest DeringFindDirSpeedTest; typedef CDEFDeringFindDirTest CDEFDeringFindDirSpeedTest;
void test_finddir(int (*finddir)(const od_dering_in *img, int stride, void test_finddir(int (*finddir)(const od_dering_in *img, int stride,
int32_t *var, int coeff_shift), int32_t *var, int coeff_shift),
...@@ -206,7 +236,7 @@ void test_finddir(int (*finddir)(const od_dering_in *img, int stride, ...@@ -206,7 +236,7 @@ void test_finddir(int (*finddir)(const od_dering_in *img, int stride,
} }
} }
EXPECT_EQ(0, error) << "Error: DeringFindDirTest, SIMD and C mismatch." EXPECT_EQ(0, error) << "Error: CDEFDeringFindDirTest, SIMD and C mismatch."
<< std::endl << std::endl
<< "return: " << res << " : " << ref_res << std::endl << "return: " << res << " : " << ref_res << std::endl
<< "var: " << var << " : " << ref_var << std::endl << "var: " << var << " : " << ref_var << std::endl
...@@ -237,24 +267,24 @@ void test_finddir_speed(int (*finddir)(const od_dering_in *img, int stride, ...@@ -237,24 +267,24 @@ void test_finddir_speed(int (*finddir)(const od_dering_in *img, int stride,