vector_ops_FIX_sse.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <smmintrin.h>
  29. #include "main.h"
  30. #include "SigProc_FIX.h"
  31. #include "pitch.h"
  32. opus_int64 silk_inner_prod16_aligned_64_sse4_1(
  33. const opus_int16 *inVec1, /* I input vector 1 */
  34. const opus_int16 *inVec2, /* I input vector 2 */
  35. const opus_int len /* I vector lengths */
  36. )
  37. {
  38. opus_int i, dataSize8;
  39. opus_int64 sum;
  40. __m128i xmm_tempa;
  41. __m128i inVec1_76543210, acc1;
  42. __m128i inVec2_76543210, acc2;
  43. sum = 0;
  44. dataSize8 = len & ~7;
  45. acc1 = _mm_setzero_si128();
  46. acc2 = _mm_setzero_si128();
  47. for( i = 0; i < dataSize8; i += 8 ) {
  48. inVec1_76543210 = _mm_loadu_si128( (__m128i *)(&inVec1[i + 0] ) );
  49. inVec2_76543210 = _mm_loadu_si128( (__m128i *)(&inVec2[i + 0] ) );
  50. /* only when all 4 operands are -32768 (0x8000), this results in wrap around */
  51. inVec1_76543210 = _mm_madd_epi16( inVec1_76543210, inVec2_76543210 );
  52. xmm_tempa = _mm_cvtepi32_epi64( inVec1_76543210 );
  53. /* equal shift right 8 bytes */
  54. inVec1_76543210 = _mm_shuffle_epi32( inVec1_76543210, _MM_SHUFFLE( 0, 0, 3, 2 ) );
  55. inVec1_76543210 = _mm_cvtepi32_epi64( inVec1_76543210 );
  56. acc1 = _mm_add_epi64( acc1, xmm_tempa );
  57. acc2 = _mm_add_epi64( acc2, inVec1_76543210 );
  58. }
  59. acc1 = _mm_add_epi64( acc1, acc2 );
  60. /* equal shift right 8 bytes */
  61. acc2 = _mm_shuffle_epi32( acc1, _MM_SHUFFLE( 0, 0, 3, 2 ) );
  62. acc1 = _mm_add_epi64( acc1, acc2 );
  63. _mm_storel_epi64( (__m128i *)&sum, acc1 );
  64. for( ; i < len; i++ ) {
  65. sum = silk_SMLABB( sum, inVec1[ i ], inVec2[ i ] );
  66. }
  67. return sum;
  68. }