mixer_sse3.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * OpenAL cross platform audio library, SSE3 mixer functions
  3. *
  4. * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
  5. * Copyright (C) 2015 by Chris Robinson <[email protected]>.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. * Or go to http://www.gnu.org/copyleft/lgpl.html
  22. */
  23. #include "config.h"
  24. #include <xmmintrin.h>
  25. #include <emmintrin.h>
  26. #include <pmmintrin.h>
  27. #include "alu.h"
  28. #include "mixer_defs.h"
  29. const ALfloat *Resample_fir4_32_SSE3(const InterpState* UNUSED(state),
  30. const ALfloat *restrict src, ALsizei frac, ALint increment,
  31. ALfloat *restrict dst, ALsizei numsamples)
  32. {
  33. const __m128i increment4 = _mm_set1_epi32(increment*4);
  34. const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
  35. union { alignas(16) ALint i[4]; float f[4]; } pos_;
  36. union { alignas(16) ALsizei i[4]; float f[4]; } frac_;
  37. __m128i frac4, pos4;
  38. ALint pos;
  39. ALsizei i;
  40. InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
  41. frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
  42. pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
  43. --src;
  44. for(i = 0;numsamples-i > 3;i += 4)
  45. {
  46. const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]);
  47. const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]);
  48. const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]);
  49. const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]);
  50. __m128 k0 = _mm_load_ps(sinc4Tab[frac_.i[0]]);
  51. __m128 k1 = _mm_load_ps(sinc4Tab[frac_.i[1]]);
  52. __m128 k2 = _mm_load_ps(sinc4Tab[frac_.i[2]]);
  53. __m128 k3 = _mm_load_ps(sinc4Tab[frac_.i[3]]);
  54. __m128 out;
  55. k0 = _mm_mul_ps(k0, val0);
  56. k1 = _mm_mul_ps(k1, val1);
  57. k2 = _mm_mul_ps(k2, val2);
  58. k3 = _mm_mul_ps(k3, val3);
  59. k0 = _mm_hadd_ps(k0, k1);
  60. k2 = _mm_hadd_ps(k2, k3);
  61. out = _mm_hadd_ps(k0, k2);
  62. _mm_store_ps(&dst[i], out);
  63. frac4 = _mm_add_epi32(frac4, increment4);
  64. pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
  65. frac4 = _mm_and_si128(frac4, fracMask4);
  66. _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
  67. _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4));
  68. }
  69. /* NOTE: These four elements represent the position *after* the last four
  70. * samples, so the lowest element is the next position to resample.
  71. */
  72. pos = pos_.i[0];
  73. frac = frac_.i[0];
  74. for(;i < numsamples;i++)
  75. {
  76. dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], frac);
  77. frac += increment;
  78. pos += frac>>FRACTIONBITS;
  79. frac &= FRACTIONMASK;
  80. }
  81. return dst;
  82. }