diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-08 21:30:37 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-08 21:30:37 +0000 |
commit | 7ed91e9093602872c62eba397fc1be8741089157 (patch) | |
tree | 6c4c2c6878ed51ca2e90586f11ea3887835c5e8c /media/base/vector_math.cc | |
parent | 13bfbc41308953ebea4952ff504037a261cfdd3c (diff) | |
download | chromium_src-7ed91e9093602872c62eba397fc1be8741089157.zip chromium_src-7ed91e9093602872c62eba397fc1be8741089157.tar.gz chromium_src-7ed91e9093602872c62eba397fc1be8741089157.tar.bz2 |
Add vector_math::FMUL. Replace audio_util::AdjustVolume.
Removes the integer based volume adjustment code from the
melting pot that is audio_util in favor of an
AudioBus::AdjustVolume() method which works on float.
The driver behind the method is a new vector_math::FMUL
method which is SSE optimized. Benchmarks put it in line
with the vector_math::FMAC() method.
Benchmarking 200000 iterations:
FMUL_C took 1962.52ms.
FMUL_SSE (unaligned size) took 493.03ms; which is 3.98x faster than FMUL_C.
FMUL_SSE (aligned size) took 491.79ms; which is 3.99x faster than FMUL_C and 1.00x faster than FMUL_SSE (unaligned size).
BUG=120319, 171540, 226447
TEST=new media_unittests.
Review URL: https://chromiumcodereview.appspot.com/13726011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/vector_math.cc')
-rw-r--r-- | media/base/vector_math.cc | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/media/base/vector_math.cc b/media/base/vector_math.cc index 96f94d9..f534d92 100644 --- a/media/base/vector_math.cc +++ b/media/base/vector_math.cc @@ -16,14 +16,18 @@ 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 @@ -39,5 +43,37 @@ 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 +#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; +} + } // namespace vector_math } // namespace media |