| 1 | /* Copyright (C) 2002 Jean-Marc Valin |
| 2 | File: ltp.c |
| 3 | Lont-Term Prediction functions (SSE version) |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions |
| 7 | are met: |
| 8 | |
| 9 | - Redistributions of source code must retain the above copyright |
| 10 | notice, this list of conditions and the following disclaimer. |
| 11 | |
| 12 | - Redistributions in binary form must reproduce the above copyright |
| 13 | notice, this list of conditions and the following disclaimer in the |
| 14 | documentation and/or other materials provided with the distribution. |
| 15 | |
| 16 | - Neither the name of the Xiph.org Foundation nor the names of its |
| 17 | contributors may be used to endorse or promote products derived from |
| 18 | this software without specific prior written permission. |
| 19 | |
| 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #include <xmmintrin.h> |
| 34 | |
| 35 | static float inner_prod(const float *a, const float *b, int len) |
| 36 | { |
| 37 | int i; |
| 38 | float ret; |
| 39 | __m128 sum = _mm_setzero_ps(); |
| 40 | for (i=0;i<(len>>2);i+=2) |
| 41 | { |
| 42 | sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+0), _mm_loadu_ps(b+0))); |
| 43 | sum = _mm_add_ps(sum, _mm_mul_ps(_mm_loadu_ps(a+4), _mm_loadu_ps(b+4))); |
| 44 | a += 8; |
| 45 | b += 8; |
| 46 | } |
| 47 | sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum)); |
| 48 | sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55)); |
| 49 | _mm_store_ss(&ret, sum); |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | static void pitch_xcorr(const float *_x, const float *_y, float *corr, int len, int nb_pitch, char *stack) |
| 54 | { |
| 55 | int i, offset; |
| 56 | VARDECL(__m128 *x); |
| 57 | VARDECL(__m128 *y); |
| 58 | int N, L; |
| 59 | N = len>>2; |
| 60 | L = nb_pitch>>2; |
| 61 | ALLOC(x, N, __m128); |
| 62 | ALLOC(y, N+L, __m128); |
| 63 | for (i=0;i<N;i++) |
| 64 | x[i] = _mm_loadu_ps(_x+(i<<2)); |
| 65 | for (offset=0;offset<4;offset++) |
| 66 | { |
| 67 | for (i=0;i<N+L;i++) |
| 68 | y[i] = _mm_loadu_ps(_y+(i<<2)+offset); |
| 69 | for (i=0;i<L;i++) |
| 70 | { |
| 71 | int j; |
| 72 | __m128 sum, *xx, *yy; |
| 73 | sum = _mm_setzero_ps(); |
| 74 | yy = y+i; |
| 75 | xx = x; |
| 76 | for (j=0;j<N;j+=2) |
| 77 | { |
| 78 | sum = _mm_add_ps(sum, _mm_mul_ps(xx[0], yy[0])); |
| 79 | sum = _mm_add_ps(sum, _mm_mul_ps(xx[1], yy[1])); |
| 80 | xx += 2; |
| 81 | yy += 2; |
| 82 | } |
| 83 | sum = _mm_add_ps(sum, _mm_movehl_ps(sum, sum)); |
| 84 | sum = _mm_add_ss(sum, _mm_shuffle_ps(sum, sum, 0x55)); |
| 85 | _mm_store_ss(corr+nb_pitch-1-(i<<2)-offset, sum); |
| 86 | } |
| 87 | } |
| 88 | } |