Chris@69: /* Copyright (c) 2007-2008 CSIRO Chris@69: Copyright (c) 2007-2009 Xiph.Org Foundation Chris@69: Copyright (c) 2007-2016 Jean-Marc Valin */ Chris@69: /* Chris@69: Redistribution and use in source and binary forms, with or without Chris@69: modification, are permitted provided that the following conditions Chris@69: are met: Chris@69: Chris@69: - Redistributions of source code must retain the above copyright Chris@69: notice, this list of conditions and the following disclaimer. Chris@69: Chris@69: - Redistributions in binary form must reproduce the above copyright Chris@69: notice, this list of conditions and the following disclaimer in the Chris@69: documentation and/or other materials provided with the distribution. Chris@69: Chris@69: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@69: ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@69: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@69: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER Chris@69: OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@69: EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@69: PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@69: PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@69: LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@69: NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@69: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@69: */ Chris@69: Chris@69: #ifdef HAVE_CONFIG_H Chris@69: #include "config.h" Chris@69: #endif Chris@69: Chris@69: #include Chris@69: #include Chris@69: #include "celt_lpc.h" Chris@69: #include "stack_alloc.h" Chris@69: #include "mathops.h" Chris@69: #include "vq.h" Chris@69: #include "x86cpu.h" Chris@69: Chris@69: Chris@69: #ifndef FIXED_POINT Chris@69: Chris@69: opus_val16 op_pvq_search_sse2(celt_norm *_X, int *iy, int K, int N, int arch) Chris@69: { Chris@69: int i, j; Chris@69: int pulsesLeft; Chris@69: float xy, yy; Chris@69: VARDECL(celt_norm, y); Chris@69: VARDECL(celt_norm, X); Chris@69: VARDECL(float, signy); Chris@69: __m128 signmask; Chris@69: __m128 sums; Chris@69: __m128i fours; Chris@69: SAVE_STACK; Chris@69: Chris@69: (void)arch; Chris@69: /* All bits set to zero, except for the sign bit. */ Chris@69: signmask = _mm_set_ps1(-0.f); Chris@69: fours = _mm_set_epi32(4, 4, 4, 4); Chris@69: ALLOC(y, N+3, celt_norm); Chris@69: ALLOC(X, N+3, celt_norm); Chris@69: ALLOC(signy, N+3, float); Chris@69: Chris@69: OPUS_COPY(X, _X, N); Chris@69: X[N] = X[N+1] = X[N+2] = 0; Chris@69: sums = _mm_setzero_ps(); Chris@69: for (j=0;j (N>>1)) Chris@69: { Chris@69: __m128i pulses_sum; Chris@69: __m128 yy4, xy4; Chris@69: __m128 rcp4; Chris@69: opus_val32 sum = _mm_cvtss_f32(sums); Chris@69: /* If X is too small, just replace it with a pulse at 0 */ Chris@69: /* Prevents infinities and NaNs from causing too many pulses Chris@69: to be allocated. 64 is an approximation of infinity here. */ Chris@69: if (!(sum > EPSILON && sum < 64)) Chris@69: { Chris@69: X[0] = QCONST16(1.f,14); Chris@69: j=1; do Chris@69: X[j]=0; Chris@69: while (++j=0); Chris@69: Chris@69: /* This should never happen, but just in case it does (e.g. on silence) Chris@69: we fill the first bin with pulses. */ Chris@69: if (pulsesLeft > N+3) Chris@69: { Chris@69: opus_val16 tmp = (opus_val16)pulsesLeft; Chris@69: yy = MAC16_16(yy, tmp, tmp); Chris@69: yy = MAC16_16(yy, tmp, y[0]); Chris@69: iy[0] += pulsesLeft; Chris@69: pulsesLeft=0; Chris@69: } Chris@69: Chris@69: for (i=0;i