Chromium Code Reviews| Index: media/base/sinc_resampler_unittest.cc |
| diff --git a/media/base/sinc_resampler_unittest.cc b/media/base/sinc_resampler_unittest.cc |
| index 77a963e2ca5db9db11d1d08416abb804aac8caed..cae1d422d3eb4b8f7f6f8fa29ec56adb81ebc3fa 100644 |
| --- a/media/base/sinc_resampler_unittest.cc |
| +++ b/media/base/sinc_resampler_unittest.cc |
| @@ -12,7 +12,9 @@ |
| #include "base/command_line.h" |
| #include "base/logging.h" |
| #include "base/string_number_conversions.h" |
| +#include "base/stringize_macros.h" |
| #include "base/time.h" |
| +#include "build/build_config.h" |
| #include "media/base/sinc_resampler.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -89,13 +91,14 @@ TEST(SincResamplerTest, Flush) { |
| .Times(1).WillOnce(ClearBuffer()); |
| resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); |
| for (int i = 0; i < resampler.ChunkSize() / 2; ++i) |
| - ASSERT_EQ(resampled_destination[i], 0); |
| + ASSERT_FLOAT_EQ(resampled_destination[i], 0); |
| } |
| // Ensure various optimized Convolve() methods return the same value. Only run |
| // this test if other optimized methods exist, otherwise the default Convolve() |
| // will be tested by the parameterized SincResampler tests below. |
| -#if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| +#if (defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)) || \ |
| + (defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)) |
| TEST(SincResamplerTest, Convolve) { |
| // Initialize a dummy resampler. |
| MockSource mock_source; |
| @@ -112,18 +115,32 @@ TEST(SincResamplerTest, Convolve) { |
| double result = resampler.Convolve_C( |
| resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| double result2 = resampler.Convolve_SSE( |
| resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
| + double result2 = resampler.Convolve_NEON( |
| + resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| + resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#else |
| +#error This test should only be compiled when SSE or NEON is available. |
|
Ami GONE FROM CHROMIUM
2012/09/24 20:04:16
This'd be a lot clearer if the #if test was revers
Ami GONE FROM CHROMIUM
2012/09/24 20:04:16
I wonder if all our bots have one or the other. I
DaleCurtis
2012/09/24 20:13:50
I don't follow. Can you elaborate? You mean #if !n
DaleCurtis
2012/09/24 20:13:50
The #if || check @100 prevents any issues here :)
|
| +#endif |
| EXPECT_NEAR(result2, result, kEpsilon); |
| - // Test Convolve_SSE() w/ unaligned input pointer. |
| + // Test Convolve() w/ unaligned input pointer. |
| result = resampler.Convolve_C( |
| resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
|
Ami GONE FROM CHROMIUM
2012/09/24 20:04:16
you could avoid repeating these by defining an OPT
DaleCurtis
2012/09/24 20:22:27
Split out into a common section for clarity.
|
| result2 = resampler.Convolve_SSE( |
| resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#elif defined(ARCH_CPU_ARM_FAMILY) && defined(__ARM_NEON__) && defined(USE_NEON) |
|
Ami GONE FROM CHROMIUM
2012/09/24 20:04:16
drop arm_neon
DaleCurtis
2012/09/24 20:22:27
Done.
|
| + result2 = resampler.Convolve_NEON( |
| + resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
| + resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| +#endif |
| EXPECT_NEAR(result2, result, kEpsilon); |
| } |
| #endif |
| @@ -158,33 +175,44 @@ TEST(SincResamplerTest, ConvolveBenchmark) { |
| (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| printf("Convolve_C took %.2fms.\n", total_time_c_ms); |
| +#if (defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)) || \ |
| + (defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON)) |
| #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| - // Benchmark Convolve_SSE() with unaligned input pointer. |
| +#define CONVOLVE_FUNC Convolve_SSE |
| +#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) |
| +#define CONVOLVE_FUNC Convolve_NEON |
|
Ami GONE FROM CHROMIUM
2012/09/24 20:04:16
Could as well go in the first #if, to save repetit
DaleCurtis
2012/09/24 20:13:50
I don't see how, the first if is a || check. We do
|
| +#else |
| +#error This benchmark should only be compiled when SSE or NEON is available. |
| +#endif |
| + // Benchmark with unaligned input pointer. |
| start = base::TimeTicks::HighResNow(); |
| for (int j = 0; j < convolve_iterations; ++j) { |
| - resampler.Convolve_SSE( |
| + resampler.CONVOLVE_FUNC( |
| resampler.kernel_storage_.get() + 1, resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| } |
| - double total_time_sse_unaligned_ms = |
| + double total_time_optimized_unaligned_ms = |
| (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| - printf("Convolve_SSE (unaligned) took %.2fms; which is %.2fx faster than" |
| - " Convolve_C.\n", total_time_sse_unaligned_ms, |
| - total_time_c_ms / total_time_sse_unaligned_ms); |
| + printf(STRINGIZE(CONVOLVE_FUNC) "(unaligned) took %.2fms; which is %.2fx " |
| + "faster than Convolve_C.\n", total_time_optimized_unaligned_ms, |
| + total_time_c_ms / total_time_optimized_unaligned_ms); |
| - // Benchmark Convolve_SSE() with aligned input pointer. |
| + // Benchmark with aligned input pointer. |
| start = base::TimeTicks::HighResNow(); |
| for (int j = 0; j < convolve_iterations; ++j) { |
| - resampler.Convolve_SSE( |
| + resampler.CONVOLVE_FUNC( |
| resampler.kernel_storage_.get(), resampler.kernel_storage_.get(), |
| resampler.kernel_storage_.get(), kKernelInterpolationFactor); |
| } |
| - double total_time_sse_aligned_ms = |
| + double total_time_optimized_aligned_ms = |
| (base::TimeTicks::HighResNow() - start).InMillisecondsF(); |
| - printf("Convolve_SSE (aligned) took %.2fms; which is %.2fx faster than" |
| - " Convolve_C and %.2fx faster than Convolve_SSE (unaligned).\n", |
| - total_time_sse_aligned_ms, total_time_c_ms / total_time_sse_aligned_ms, |
| - total_time_sse_unaligned_ms / total_time_sse_aligned_ms); |
| + printf(STRINGIZE(CONVOLVE_FUNC) " (aligned) took %.2fms; which is %.2fx " |
| + "faster than Convolve_C and %.2fx faster than " |
| + STRINGIZE(CONVOLVE_FUNC) " (unaligned).\n", |
| + total_time_optimized_aligned_ms, |
| + total_time_c_ms / total_time_optimized_aligned_ms, |
| + total_time_optimized_unaligned_ms / total_time_optimized_aligned_ms); |
| +#undef CONVOLVE_FUNC |
| #endif |
| } |