Simd.h 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. {
  16. /// Template class that holds SIMD info for the math classes.
  17. template<typename T, U N>
  18. class MathSimd
  19. {
  20. public:
  21. using Type = T[N];
  22. static constexpr U ALIGNMENT = alignof(T);
  23. };
  24. #if ANKI_SIMD_SSE
  25. // Specialize for F32
  26. template<>
  27. class MathSimd<F32, 4>
  28. {
  29. public:
  30. using Type = __m128;
  31. static constexpr U ALIGNMENT = 16;
  32. };
  33. #elif ANKI_SIMD_NEON
  34. // Specialize for F32
  35. template<>
  36. class MathSimd<F32, 4>
  37. {
  38. public:
  39. using Type = float32x4_t;
  40. static constexpr U ALIGNMENT = 16;
  41. };
  42. #endif
  43. } // end namespace anki