| 1 |
/* |
| 2 |
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license |
| 5 |
* that can be found in the LICENSE file in the root of the source |
| 6 |
* tree. An additional intellectual property rights grant can be found |
| 7 |
* in the file PATENTS. All contributing project authors may |
| 8 |
* be found in the AUTHORS file in the root of the source tree. |
| 9 |
*/ |
| 10 |
|
| 11 |
// Modified from the Chromium original: |
| 12 |
// src/media/base/simd/sinc_resampler_sse.cc |
| 13 |
|
| 14 |
#include <stddef.h> |
| 15 |
#include <stdint.h> |
| 16 |
#include <xmmintrin.h> |
| 17 |
|
| 18 |
#include "common_audio/resampler/sinc_resampler.h" |
| 19 |
|
| 20 |
namespace webrtc { |
| 21 |
|
| 22 |
float SincResampler::Convolve_SSE(const float* input_ptr, |
| 23 |
const float* k1, |
| 24 |
const float* k2, |
| 25 |
double kernel_interpolation_factor) { |
| 26 |
__m128 m_input; |
| 27 |
__m128 m_sums1 = _mm_setzero_ps(); |
| 28 |
__m128 m_sums2 = _mm_setzero_ps(); |
| 29 |
|
| 30 |
// Based on |input_ptr| alignment, we need to use loadu or load. Unrolling |
| 31 |
// these loops hurt performance in local testing. |
| 32 |
if (reinterpret_cast<uintptr_t>(input_ptr) & 0x0F) { |
| 33 |
for (size_t i = 0; i < kKernelSize; i += 4) { |
| 34 |
m_input = _mm_loadu_ps(input_ptr + i); |
| 35 |
m_sums1 = _mm_add_ps(m_sums1, _mm_mul_ps(m_input, _mm_load_ps(k1 + i))); |
| 36 |
m_sums2 = _mm_add_ps(m_sums2, _mm_mul_ps(m_input, _mm_load_ps(k2 + i))); |
| 37 |
} |
| 38 |
} else { |
| 39 |
for (size_t i = 0; i < kKernelSize; i += 4) { |
| 40 |
m_input = _mm_load_ps(input_ptr + i); |
| 41 |
m_sums1 = _mm_add_ps(m_sums1, _mm_mul_ps(m_input, _mm_load_ps(k1 + i))); |
| 42 |
m_sums2 = _mm_add_ps(m_sums2, _mm_mul_ps(m_input, _mm_load_ps(k2 + i))); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
// Linearly interpolate the two "convolutions". |
| 47 |
m_sums1 = _mm_mul_ps( |
| 48 |
m_sums1, |
| 49 |
_mm_set_ps1(static_cast<float>(1.0 - kernel_interpolation_factor))); |
| 50 |
m_sums2 = _mm_mul_ps( |
| 51 |
m_sums2, _mm_set_ps1(static_cast<float>(kernel_interpolation_factor))); |
| 52 |
m_sums1 = _mm_add_ps(m_sums1, m_sums2); |
| 53 |
|
| 54 |
// Sum components together. |
| 55 |
float result; |
| 56 |
m_sums2 = _mm_add_ps(_mm_movehl_ps(m_sums1, m_sums1), m_sums1); |
| 57 |
_mm_store_ss(&result, |
| 58 |
_mm_add_ss(m_sums2, _mm_shuffle_ps(m_sums2, m_sums2, 1))); |
| 59 |
|
| 60 |
return result; |
| 61 |
} |
| 62 |
|
| 63 |
} // namespace webrtc |