Path: blob/master/dep/cubeb/subprojects/speex/resample_sse.h
4247 views
/* Copyright (C) 2007-2008 Jean-Marc Valin1* Copyright (C) 2008 Thorvald Natvig2*/3/**4@file resample_sse.h5@brief Resampler functions (SSE version)6*/7/*8Redistribution and use in source and binary forms, with or without9modification, are permitted provided that the following conditions10are met:1112- Redistributions of source code must retain the above copyright13notice, this list of conditions and the following disclaimer.1415- Redistributions in binary form must reproduce the above copyright16notice, this list of conditions and the following disclaimer in the17documentation and/or other materials provided with the distribution.1819- Neither the name of the Xiph.org Foundation nor the names of its20contributors may be used to endorse or promote products derived from21this software without specific prior written permission.2223THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS24``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT25LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR26A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR27CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,28EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,29PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR30PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF31LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING32NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS33SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.34*/3536#include <xmmintrin.h>3738#define OVERRIDE_INNER_PRODUCT_SINGLE39static inline float inner_product_single(const float *a, const float *b, unsigned int len)40{41int i;42float ret;43__m128 sum = _mm_setzero_ps();44for (i=0;i<len;i+=8)45{46sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+i), _mm_loadu_ps(b+i)));47sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+i+4), _mm_loadu_ps(b+i+4)));48}49sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));50sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));51_mm_store_ss(&ret, sum);52return ret;53}5455#define OVERRIDE_INTERPOLATE_PRODUCT_SINGLE56static inline float interpolate_product_single(const float *a, const float *b, unsigned int len, const spx_uint32_t oversample, float *frac) {57int i;58float ret;59__m128 sum = _mm_setzero_ps();60__m128 f = _mm_loadu_ps(frac);61for(i=0;i<len;i+=2)62{63sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a+i), _mm_loadu_ps(b+i*oversample)));64sum = _mm_add_ps(sum, _mm_mul_ps(_mm_load1_ps(a+i+1), _mm_loadu_ps(b+(i+1)*oversample)));65}66sum = _mm_mul_ps(f, sum);67sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum));68sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55));69_mm_store_ss(&ret, sum);70return ret;71}7273#ifdef _USE_SSE274#include <emmintrin.h>75#define OVERRIDE_INNER_PRODUCT_DOUBLE7677static inline double inner_product_double(const float *a, const float *b, unsigned int len)78{79int i;80double ret;81__m128d sum = _mm_setzero_pd();82__m128 t;83for (i=0;i<len;i+=8)84{85t = _mm_mul_ps(_mm_loadu_ps(a+i), _mm_loadu_ps(b+i));86sum = _mm_add_pd(sum, _mm_cvtps_pd(t));87sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));8889t = _mm_mul_ps(_mm_loadu_ps(a+i+4), _mm_loadu_ps(b+i+4));90sum = _mm_add_pd(sum, _mm_cvtps_pd(t));91sum = _mm_add_pd(sum, _mm_cvtps_pd(_mm_movehl_ps(t, t)));92}93sum = _mm_add_sd(sum, _mm_unpackhi_pd(sum, sum));94_mm_store_sd(&ret, sum);95return ret;96}9798#define OVERRIDE_INTERPOLATE_PRODUCT_DOUBLE99static inline double interpolate_product_double(const float *a, const float *b, unsigned int len, const spx_uint32_t oversample, float *frac) {100int i;101double ret;102__m128d sum;103__m128d sum1 = _mm_setzero_pd();104__m128d sum2 = _mm_setzero_pd();105__m128 f = _mm_loadu_ps(frac);106__m128d f1 = _mm_cvtps_pd(f);107__m128d f2 = _mm_cvtps_pd(_mm_movehl_ps(f,f));108__m128 t;109for(i=0;i<len;i+=2)110{111t = _mm_mul_ps(_mm_load1_ps(a+i), _mm_loadu_ps(b+i*oversample));112sum1 = _mm_add_pd(sum1, _mm_cvtps_pd(t));113sum2 = _mm_add_pd(sum2, _mm_cvtps_pd(_mm_movehl_ps(t, t)));114115t = _mm_mul_ps(_mm_load1_ps(a+i+1), _mm_loadu_ps(b+(i+1)*oversample));116sum1 = _mm_add_pd(sum1, _mm_cvtps_pd(t));117sum2 = _mm_add_pd(sum2, _mm_cvtps_pd(_mm_movehl_ps(t, t)));118}119sum1 = _mm_mul_pd(f1, sum1);120sum2 = _mm_mul_pd(f2, sum2);121sum = _mm_add_pd(sum1, sum2);122sum = _mm_add_sd(sum, _mm_unpackhi_pd(sum, sum));123_mm_store_sd(&ret, sum);124return ret;125}126127#endif128129130