9
3

func_integer_simd.inl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../simd/integer.h"
  2. #if GLM_ARCH & GLM_ARCH_SSE2_BIT
  3. namespace glm{
  4. namespace detail
  5. {
  6. template<qualifier Q>
  7. struct compute_bitfieldReverseStep<4, uint, Q, true, true>
  8. {
  9. GLM_FUNC_QUALIFIER static vec<4, uint, Q> call(vec<4, uint, Q> const& v, uint Mask, uint Shift)
  10. {
  11. __m128i const set0 = v.data;
  12. __m128i const set1 = _mm_set1_epi32(static_cast<int>(Mask));
  13. __m128i const and1 = _mm_and_si128(set0, set1);
  14. __m128i const sft1 = _mm_slli_epi32(and1, Shift);
  15. __m128i const set2 = _mm_andnot_si128(set0, _mm_set1_epi32(-1));
  16. __m128i const and2 = _mm_and_si128(set0, set2);
  17. __m128i const sft2 = _mm_srai_epi32(and2, Shift);
  18. __m128i const or0 = _mm_or_si128(sft1, sft2);
  19. return or0;
  20. }
  21. };
  22. template<qualifier Q>
  23. struct compute_bitfieldBitCountStep<4, uint, Q, true, true>
  24. {
  25. GLM_FUNC_QUALIFIER static vec<4, uint, Q> call(vec<4, uint, Q> const& v, uint Mask, uint Shift)
  26. {
  27. __m128i const set0 = v.data;
  28. __m128i const set1 = _mm_set1_epi32(static_cast<int>(Mask));
  29. __m128i const and0 = _mm_and_si128(set0, set1);
  30. __m128i const sft0 = _mm_slli_epi32(set0, Shift);
  31. __m128i const and1 = _mm_and_si128(sft0, set1);
  32. __m128i const add0 = _mm_add_epi32(and0, and1);
  33. return add0;
  34. }
  35. };
  36. }//namespace detail
  37. # if GLM_ARCH & GLM_ARCH_AVX_BIT
  38. template<>
  39. GLM_FUNC_QUALIFIER int bitCount(uint x)
  40. {
  41. return _mm_popcnt_u32(x);
  42. }
  43. # if(GLM_MODEL == GLM_MODEL_64)
  44. template<>
  45. GLM_FUNC_QUALIFIER int bitCount(detail::uint64 x)
  46. {
  47. return static_cast<int>(_mm_popcnt_u64(x));
  48. }
  49. # endif//GLM_MODEL
  50. # endif//GLM_ARCH
  51. }//namespace glm
  52. #endif//GLM_ARCH & GLM_ARCH_SSE2_BIT