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