ltp_sse.h 3.1 KB

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