Simd.h 889 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Util/StdTypes.h>
  7. #if ANKI_SIMD_SSE
  8. # include <smmintrin.h>
  9. #elif ANKI_SIMD_NEON
  10. # include <arm_neon.h>
  11. #elif !ANKI_SIMD_NONE
  12. # error "See file"
  13. #endif
  14. namespace anki {
  15. /// Template class that holds SIMD info for the math classes.
  16. template<typename T, U N>
  17. class MathSimd
  18. {
  19. public:
  20. using Type = T[N];
  21. static constexpr U ALIGNMENT = alignof(T);
  22. };
  23. #if ANKI_SIMD_SSE
  24. // Specialize for F32
  25. template<>
  26. class MathSimd<F32, 4>
  27. {
  28. public:
  29. using Type = __m128;
  30. static constexpr U ALIGNMENT = 16;
  31. };
  32. #elif ANKI_SIMD_NEON
  33. // Specialize for F32
  34. template<>
  35. class MathSimd<F32, 4>
  36. {
  37. public:
  38. using Type = float32x4_t;
  39. static constexpr U ALIGNMENT = 16;
  40. };
  41. #endif
  42. } // end namespace anki