diff options
author | Torne (Richard Coles) <torne@google.com> | 2013-05-09 18:35:53 +0100 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2013-05-13 13:57:14 +0100 |
commit | c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d (patch) | |
tree | 1dbdbb0624cc869ab25ee7f46971984c6fee3e7a /media/base/vector_math.cc | |
parent | 2d519ce2457219605d4f472da8d2ffd469796035 (diff) | |
download | chromium_org-c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d.tar.gz |
Merge from Chromium at DEPS revision r198571
This commit was generated by merge_to_master.py.
Change-Id: I951118a03836157090561764dd2627f0add8118f
Diffstat (limited to 'media/base/vector_math.cc')
-rw-r--r-- | media/base/vector_math.cc | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/media/base/vector_math.cc b/media/base/vector_math.cc index 96f94d95e4..603ae0b04f 100644 --- a/media/base/vector_math.cc +++ b/media/base/vector_math.cc @@ -7,6 +7,11 @@ #include "base/cpu.h" #include "base/logging.h" +#include "build/build_config.h" + +#if defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) +#include <arm_neon.h> +#endif namespace media { namespace vector_math { @@ -16,17 +21,23 @@ void FMAC(const float src[], float scale, int len, float dest[]) { DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1)); DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1)); - // Rely on function level static initialization to keep VectorFMACProc - // selection thread safe. typedef void (*VectorFMACProc)(const float src[], float scale, int len, float dest[]); -#if defined(ARCH_CPU_X86_FAMILY) + + // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse + // built library is non-trivial, so simply disable for now. iOS lies about + // its architecture, so we need to exclude it here. +#if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS) #if defined(__SSE__) static const VectorFMACProc kVectorFMACProc = FMAC_SSE; #else + // TODO(dalecurtis): Remove function level static initialization, it's not + // thread safe: http://crbug.com/224662. static const VectorFMACProc kVectorFMACProc = base::CPU().has_sse() ? FMAC_SSE : FMAC_C; #endif +#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) + static const VectorFMACProc kVectorFMACProc = FMAC_NEON; #else static const VectorFMACProc kVectorFMACProc = FMAC_C; #endif @@ -39,5 +50,67 @@ void FMAC_C(const float src[], float scale, int len, float dest[]) { dest[i] += src[i] * scale; } +void FMUL(const float src[], float scale, int len, float dest[]) { + // Ensure |src| and |dest| are 16-byte aligned. + DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1)); + DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1)); + + typedef void (*VectorFMULProc)(const float src[], float scale, int len, + float dest[]); + + // No NaCl code uses the SSE functionality of AudioBus and plumbing the -msse + // built library is non-trivial, so simply disable for now. iOS lies about + // its architecture, so we need to exclude it here. +#if defined(ARCH_CPU_X86_FAMILY) && !defined(OS_NACL) && !defined(OS_IOS) +#if defined(__SSE__) + static const VectorFMULProc kVectorFMULProc = FMUL_SSE; +#else + // TODO(dalecurtis): Remove function level static initialization, it's not + // thread safe: http://crbug.com/224662. + static const VectorFMULProc kVectorFMULProc = + base::CPU().has_sse() ? FMUL_SSE : FMUL_C; +#endif +#elif defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) + static const VectorFMULProc kVectorFMULProc = FMUL_NEON; +#else + static const VectorFMULProc kVectorFMULProc = FMUL_C; +#endif + + return kVectorFMULProc(src, scale, len, dest); +} + +void FMUL_C(const float src[], float scale, int len, float dest[]) { + for (int i = 0; i < len; ++i) + dest[i] = src[i] * scale; +} + +#if defined(ARCH_CPU_ARM_FAMILY) && defined(USE_NEON) +void FMAC_NEON(const float src[], float scale, int len, float dest[]) { + const int rem = len % 4; + const int last_index = len - rem; + float32x4_t m_scale = vmovq_n_f32(scale); + for (int i = 0; i < last_index; i += 4) { + vst1q_f32(dest + i, vmlaq_f32( + vld1q_f32(dest + i), vld1q_f32(src + i), m_scale)); + } + + // Handle any remaining values that wouldn't fit in an NEON pass. + for (int i = last_index; i < len; ++i) + dest[i] += src[i] * scale; +} + +void FMUL_NEON(const float src[], float scale, int len, float dest[]) { + const int rem = len % 4; + const int last_index = len - rem; + float32x4_t m_scale = vmovq_n_f32(scale); + for (int i = 0; i < last_index; i += 4) + vst1q_f32(dest + i, vmulq_f32(vld1q_f32(src + i), m_scale)); + + // Handle any remaining values that wouldn't fit in an NEON pass. + for (int i = last_index; i < len; ++i) + dest[i] = src[i] * scale; +} +#endif + } // namespace vector_math } // namespace media |