Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: media/base/vector_math.cc

Issue 10868037: Split AudioRendererMixer::VectorFMAC into VectorMath library. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/vector_math.h"
6
7 #include "base/cpu.h"
8 #include "base/logging.h"
9 #include "build/build_config.h"
10
11 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
12 #include <xmmintrin.h>
13 #endif
14
15 namespace media {
16
17 void VectorMath::FMAC(const float src[], float scale, int len, float dest[]) {
18 // Rely on function level static initialization to keep VectorFMACProc
19 // selection thread safe.
20 typedef void (*VectorFMACProc)(const float src[], float scale, int len,
21 float dest[]);
22 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
23 static const VectorFMACProc kVectorFMACProc =
24 base::CPU().has_sse() ? FMAC_SSE : FMAC_C;
25 #else
26 static const VectorFMACProc kVectorFMACProc = FMAC_C;
27 #endif
28
29 return kVectorFMACProc(src, scale, len, dest);
30 }
31
32 void VectorMath::FMAC_C(const float src[], float scale, int len,
33 float dest[]) {
34 for (int i = 0; i < len; ++i)
35 dest[i] += src[i] * scale;
36 }
37
38 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__)
39 void VectorMath::FMAC_SSE(const float src[], float scale, int len,
40 float dest[]) {
41 // Ensure |src| and |dest| are 16-byte aligned.
42 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & 0x0F);
43 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & 0x0F);
Ami GONE FROM CHROMIUM 2012/08/23 17:28:12 Do these checks belong in FMAC() instead of here?
DaleCurtis 2012/08/23 19:59:54 Technically no, but since CPU selection is done at
44
45 __m128 m_scale = _mm_set_ps1(scale);
46 int rem = len % 4;
47 for (int i = 0; i < len - rem; i += 4) {
48 _mm_store_ps(dest + i, _mm_add_ps(_mm_load_ps(dest + i),
49 _mm_mul_ps(_mm_load_ps(src + i), m_scale)));
50 }
51
52 // Handle any remaining values that wouldn't fit in an SSE pass.
53 if (rem)
54 FMAC_C(src + len - rem, scale, rem, dest + len - rem);
55 }
56 #endif
57
58 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698