summaryrefslogtreecommitdiffstats
path: root/media/base/vector_math.cc
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 00:40:46 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-24 00:40:46 +0000
commit9c2b29e0d642712e780818dddab5a965b4fd96d4 (patch)
tree4d9ae01ab0c5c86cd1d7b4e2abbdd40db3ba1190 /media/base/vector_math.cc
parentb94ebd1f6e245d9f9f3d9a2fc933581eb8f508bc (diff)
downloadchromium_src-9c2b29e0d642712e780818dddab5a965b4fd96d4.zip
chromium_src-9c2b29e0d642712e780818dddab5a965b4fd96d4.tar.gz
chromium_src-9c2b29e0d642712e780818dddab5a965b4fd96d4.tar.bz2
Split AudioRendererMixer::VectorFMAC into VectorMath library.
Prepare the future home for more optimized vector math routines, specifically FMUL for volume adjustment. Additionally the FMAC operation will be used for browser side mixing as well as channel upmixing and downmixing. BUG=none TEST=unittests. Review URL: https://chromiumcodereview.appspot.com/10868037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/vector_math.cc')
-rw-r--r--media/base/vector_math.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/media/base/vector_math.cc b/media/base/vector_math.cc
new file mode 100644
index 0000000..edd95cd
--- /dev/null
+++ b/media/base/vector_math.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/vector_math.h"
+#include "media/base/vector_math_testing.h"
+
+#include "base/cpu.h"
+#include "base/logging.h"
+#include "build/build_config.h"
+
+#if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
+#include <xmmintrin.h>
+#endif
+
+namespace media {
+namespace vector_math {
+
+void FMAC(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));
+
+ // 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) && defined(__SSE__)
+ static const VectorFMACProc kVectorFMACProc =
+ base::CPU().has_sse() ? FMAC_SSE : FMAC_C;
+#else
+ static const VectorFMACProc kVectorFMACProc = FMAC_C;
+#endif
+
+ return kVectorFMACProc(src, scale, len, dest);
+}
+
+void FMAC_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_X86_FAMILY) && defined(__SSE__)
+void FMAC_SSE(const float src[], float scale, int len, float dest[]) {
+ __m128 m_scale = _mm_set_ps1(scale);
+ int rem = len % 4;
+ for (int i = 0; i < len - rem; i += 4) {
+ _mm_store_ps(dest + i, _mm_add_ps(_mm_load_ps(dest + i),
+ _mm_mul_ps(_mm_load_ps(src + i), m_scale)));
+ }
+
+ // Handle any remaining values that wouldn't fit in an SSE pass.
+ if (rem)
+ FMAC_C(src + len - rem, scale, rem, dest + len - rem);
+}
+#endif
+
+} // namespace vector_math
+} // namespace media