| OLD | NEW |
| (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 #include "media/base/vector_math_testing.h" |
| 7 |
| 8 #include "base/cpu.h" |
| 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" |
| 11 |
| 12 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| 13 #include <xmmintrin.h> |
| 14 #endif |
| 15 |
| 16 namespace vector_math { |
| 17 |
| 18 void FMAC(const float src[], float scale, int len, float dest[]) { |
| 19 // Ensure |src| and |dest| are 16-byte aligned. |
| 20 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(src) & (kRequiredAlignment - 1)); |
| 21 DCHECK_EQ(0u, reinterpret_cast<uintptr_t>(dest) & (kRequiredAlignment - 1)); |
| 22 |
| 23 // Rely on function level static initialization to keep VectorFMACProc |
| 24 // selection thread safe. |
| 25 typedef void (*VectorFMACProc)(const float src[], float scale, int len, |
| 26 float dest[]); |
| 27 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| 28 static const VectorFMACProc kVectorFMACProc = |
| 29 base::CPU().has_sse() ? FMAC_SSE : FMAC_C; |
| 30 #else |
| 31 static const VectorFMACProc kVectorFMACProc = FMAC_C; |
| 32 #endif |
| 33 |
| 34 return kVectorFMACProc(src, scale, len, dest); |
| 35 } |
| 36 |
| 37 void FMAC_C(const float src[], float scale, int len, float dest[]) { |
| 38 for (int i = 0; i < len; ++i) |
| 39 dest[i] += src[i] * scale; |
| 40 } |
| 41 |
| 42 #if defined(ARCH_CPU_X86_FAMILY) && defined(__SSE__) |
| 43 void FMAC_SSE(const float src[], float scale, int len, float dest[]) { |
| 44 __m128 m_scale = _mm_set_ps1(scale); |
| 45 int rem = len % 4; |
| 46 for (int i = 0; i < len - rem; i += 4) { |
| 47 _mm_store_ps(dest + i, _mm_add_ps(_mm_load_ps(dest + i), |
| 48 _mm_mul_ps(_mm_load_ps(src + i), m_scale))); |
| 49 } |
| 50 |
| 51 // Handle any remaining values that wouldn't fit in an SSE pass. |
| 52 if (rem) |
| 53 FMAC_C(src + len - rem, scale, rem, dest + len - rem); |
| 54 } |
| 55 #endif |
| 56 |
| 57 } // namespace media |
| OLD | NEW |