vec_traits_gnuc.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef BOOST_QVM_VEC_TRAITS_GNUC_HPP_INCLUDED
  2. #define BOOST_QVM_VEC_TRAITS_GNUC_HPP_INCLUDED
  3. // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #if defined(__GNUC__) && defined(__SSE2__)
  7. #include <boost/qvm/config.hpp>
  8. #include <boost/qvm/assert.hpp>
  9. #include <boost/qvm/static_assert.hpp>
  10. namespace boost { namespace qvm {
  11. namespace
  12. qvm_detail
  13. {
  14. template <class V, class T, int D>
  15. struct
  16. vec_traits_gnuc_impl
  17. {
  18. typedef T scalar_type;
  19. static int const dim=D;
  20. template <int I>
  21. static
  22. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  23. scalar_type
  24. read_element( V const & x )
  25. {
  26. BOOST_QVM_STATIC_ASSERT(I>=0);
  27. BOOST_QVM_STATIC_ASSERT(I<dim);
  28. return x[I];
  29. }
  30. template <int I>
  31. static
  32. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  33. void
  34. write_element( V & x, scalar_type s )
  35. {
  36. BOOST_QVM_STATIC_ASSERT(I>=0);
  37. BOOST_QVM_STATIC_ASSERT(I<dim);
  38. x[I] = s;
  39. }
  40. static
  41. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  42. scalar_type
  43. read_element_idx( int i, V const & x )
  44. {
  45. BOOST_QVM_ASSERT(i>=0);
  46. BOOST_QVM_ASSERT(i<dim);
  47. return x[i];
  48. }
  49. static
  50. BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
  51. void
  52. write_element_idx( int i, V & x, scalar_type s )
  53. {
  54. BOOST_QVM_ASSERT(i>=0);
  55. BOOST_QVM_ASSERT(i<dim);
  56. x[i] = s;
  57. }
  58. };
  59. }
  60. template <class> struct vec_traits;
  61. template <class> struct is_vec;
  62. #define BOOST_QVM_GNUC_VEC_TYPE(T,D)\
  63. template <>\
  64. struct\
  65. vec_traits<T __attribute__((vector_size(sizeof(T)*D)))>:\
  66. qvm_detail::vec_traits_gnuc_impl<T __attribute__((vector_size(sizeof(T)*D))),T,D>\
  67. {\
  68. };\
  69. template <>\
  70. struct\
  71. is_vec<T __attribute__((vector_size(sizeof(T)*D)))>\
  72. {\
  73. enum { value = true };\
  74. };
  75. BOOST_QVM_GNUC_VEC_TYPE(float,2)
  76. BOOST_QVM_GNUC_VEC_TYPE(float,4)
  77. BOOST_QVM_GNUC_VEC_TYPE(double,2)
  78. BOOST_QVM_GNUC_VEC_TYPE(double,4)
  79. #undef BOOST_QVM_GNUC_VEC_TYPE
  80. } }
  81. #endif
  82. #endif