pitch_sse2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (c) 2014, Cisco Systems, INC
  2. Written by XiangMingZhu WeiZhou MinPeng YanWang
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  12. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  13. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  14. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  15. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  20. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <xmmintrin.h>
  27. #include <emmintrin.h>
  28. #include "macros.h"
  29. #include "celt_lpc.h"
  30. #include "stack_alloc.h"
  31. #include "mathops.h"
  32. #include "pitch.h"
  33. #if defined(OPUS_X86_MAY_HAVE_SSE2) && defined(FIXED_POINT)
  34. opus_val32 celt_inner_prod_sse2(const opus_val16 *x, const opus_val16 *y,
  35. int N)
  36. {
  37. opus_int i, dataSize16;
  38. opus_int32 sum;
  39. __m128i inVec1_76543210, inVec1_FEDCBA98, acc1;
  40. __m128i inVec2_76543210, inVec2_FEDCBA98, acc2;
  41. sum = 0;
  42. dataSize16 = N & ~15;
  43. acc1 = _mm_setzero_si128();
  44. acc2 = _mm_setzero_si128();
  45. for (i=0;i<dataSize16;i+=16)
  46. {
  47. inVec1_76543210 = _mm_loadu_si128((__m128i *)(&x[i + 0]));
  48. inVec2_76543210 = _mm_loadu_si128((__m128i *)(&y[i + 0]));
  49. inVec1_FEDCBA98 = _mm_loadu_si128((__m128i *)(&x[i + 8]));
  50. inVec2_FEDCBA98 = _mm_loadu_si128((__m128i *)(&y[i + 8]));
  51. inVec1_76543210 = _mm_madd_epi16(inVec1_76543210, inVec2_76543210);
  52. inVec1_FEDCBA98 = _mm_madd_epi16(inVec1_FEDCBA98, inVec2_FEDCBA98);
  53. acc1 = _mm_add_epi32(acc1, inVec1_76543210);
  54. acc2 = _mm_add_epi32(acc2, inVec1_FEDCBA98);
  55. }
  56. acc1 = _mm_add_epi32( acc1, acc2 );
  57. if (N - i >= 8)
  58. {
  59. inVec1_76543210 = _mm_loadu_si128((__m128i *)(&x[i + 0]));
  60. inVec2_76543210 = _mm_loadu_si128((__m128i *)(&y[i + 0]));
  61. inVec1_76543210 = _mm_madd_epi16(inVec1_76543210, inVec2_76543210);
  62. acc1 = _mm_add_epi32(acc1, inVec1_76543210);
  63. i += 8;
  64. }
  65. acc1 = _mm_add_epi32(acc1, _mm_unpackhi_epi64( acc1, acc1));
  66. acc1 = _mm_add_epi32(acc1, _mm_shufflelo_epi16( acc1, 0x0E));
  67. sum += _mm_cvtsi128_si32(acc1);
  68. for (;i<N;i++) {
  69. sum = silk_SMLABB(sum, x[i], y[i]);
  70. }
  71. return sum;
  72. }
  73. #endif