mixer_sse.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include "config.h"
  2. #ifdef HAVE_XMMINTRIN_H
  3. #ifdef IN_IDE_PARSER
  4. /* KDevelop's parser won't recognize these defines that get added by the -msse
  5. * switch used to compile this source. Without them, xmmintrin.h fails to
  6. * declare anything. */
  7. #define __MMX__
  8. #define __SSE__
  9. #endif
  10. #include <xmmintrin.h>
  11. #endif
  12. #include "AL/al.h"
  13. #include "AL/alc.h"
  14. #include "alMain.h"
  15. #include "alu.h"
  16. #include "alSource.h"
  17. #include "alAuxEffectSlot.h"
  18. #include "mixer_defs.h"
  19. static inline void ApplyCoeffsStep(const ALuint IrSize,
  20. ALfloat (*restrict Coeffs)[2],
  21. const ALfloat (*restrict CoeffStep)[2])
  22. {
  23. __m128 coeffs, deltas;
  24. ALuint i;
  25. for(i = 0;i < IrSize;i += 2)
  26. {
  27. coeffs = _mm_load_ps(&Coeffs[i][0]);
  28. deltas = _mm_load_ps(&CoeffStep[i][0]);
  29. coeffs = _mm_add_ps(coeffs, deltas);
  30. _mm_store_ps(&Coeffs[i][0], coeffs);
  31. }
  32. }
  33. static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
  34. const ALuint IrSize,
  35. ALfloat (*restrict Coeffs)[2],
  36. ALfloat left, ALfloat right)
  37. {
  38. const __m128 lrlr = { left, right, left, right };
  39. __m128 vals = _mm_setzero_ps();
  40. __m128 coeffs;
  41. ALuint i;
  42. if((Offset&1))
  43. {
  44. const ALuint o0 = Offset&HRIR_MASK;
  45. const ALuint o1 = (Offset+IrSize-1)&HRIR_MASK;
  46. __m128 imp0, imp1;
  47. coeffs = _mm_load_ps(&Coeffs[0][0]);
  48. vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
  49. imp0 = _mm_mul_ps(lrlr, coeffs);
  50. vals = _mm_add_ps(imp0, vals);
  51. _mm_storel_pi((__m64*)&Values[o0][0], vals);
  52. for(i = 1;i < IrSize-1;i += 2)
  53. {
  54. const ALuint o2 = (Offset+i)&HRIR_MASK;
  55. coeffs = _mm_load_ps(&Coeffs[i+1][0]);
  56. vals = _mm_load_ps(&Values[o2][0]);
  57. imp1 = _mm_mul_ps(lrlr, coeffs);
  58. imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
  59. vals = _mm_add_ps(imp0, vals);
  60. _mm_store_ps(&Values[o2][0], vals);
  61. imp0 = imp1;
  62. }
  63. vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
  64. imp0 = _mm_movehl_ps(imp0, imp0);
  65. vals = _mm_add_ps(imp0, vals);
  66. _mm_storel_pi((__m64*)&Values[o1][0], vals);
  67. }
  68. else
  69. {
  70. for(i = 0;i < IrSize;i += 2)
  71. {
  72. const ALuint o = (Offset + i)&HRIR_MASK;
  73. coeffs = _mm_load_ps(&Coeffs[i][0]);
  74. vals = _mm_load_ps(&Values[o][0]);
  75. vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
  76. _mm_store_ps(&Values[o][0], vals);
  77. }
  78. }
  79. }
  80. #define SUFFIX SSE
  81. #include "mixer_inc.c"
  82. #undef SUFFIX
  83. void MixDirect_SSE(const DirectParams *params, const ALfloat *restrict data, ALuint srcchan,
  84. ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
  85. {
  86. ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
  87. ALfloat *restrict ClickRemoval = params->ClickRemoval;
  88. ALfloat *restrict PendingClicks = params->PendingClicks;
  89. ALfloat DrySend;
  90. __m128 gain;
  91. ALuint pos;
  92. ALuint c;
  93. for(c = 0;c < MaxChannels;c++)
  94. {
  95. DrySend = params->Gains[srcchan][c];
  96. if(!(DrySend > GAIN_SILENCE_THRESHOLD))
  97. continue;
  98. if(OutPos == 0)
  99. ClickRemoval[c] -= data[0]*DrySend;
  100. gain = _mm_set1_ps(DrySend);
  101. for(pos = 0;BufferSize-pos > 3;pos += 4)
  102. {
  103. const __m128 val4 = _mm_load_ps(&data[pos]);
  104. __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
  105. dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain));
  106. _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
  107. }
  108. for(;pos < BufferSize;pos++)
  109. OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
  110. if(OutPos+pos == SamplesToDo)
  111. PendingClicks[c] += data[pos]*DrySend;
  112. }
  113. }
  114. void MixSend_SSE(const SendParams *params, const ALfloat *restrict data,
  115. ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
  116. {
  117. ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
  118. ALfloat *restrict ClickRemoval = params->ClickRemoval;
  119. ALfloat *restrict PendingClicks = params->PendingClicks;
  120. ALfloat WetGain;
  121. __m128 gain;
  122. ALuint pos;
  123. WetGain = params->Gain;
  124. if(!(WetGain > GAIN_SILENCE_THRESHOLD))
  125. return;
  126. if(OutPos == 0)
  127. ClickRemoval[0] -= data[0] * WetGain;
  128. gain = _mm_set1_ps(WetGain);
  129. for(pos = 0;BufferSize-pos > 3;pos += 4)
  130. {
  131. const __m128 val4 = _mm_load_ps(&data[pos]);
  132. __m128 wet4 = _mm_load_ps(&OutBuffer[0][OutPos+pos]);
  133. wet4 = _mm_add_ps(wet4, _mm_mul_ps(val4, gain));
  134. _mm_store_ps(&OutBuffer[0][OutPos+pos], wet4);
  135. }
  136. for(;pos < BufferSize;pos++)
  137. OutBuffer[0][OutPos+pos] += data[pos] * WetGain;
  138. if(OutPos+pos == SamplesToDo)
  139. PendingClicks[0] += data[pos] * WetGain;
  140. }