File indexing completed on 2025-11-08 09:59:44
0001 #ifndef BOOST_QVM_VEC_TRAITS_GNUC_HPP_INCLUDED
0002 #define BOOST_QVM_VEC_TRAITS_GNUC_HPP_INCLUDED
0003
0004
0005
0006
0007
0008 #if defined(__GNUC__) && defined(__SSE2__)
0009
0010 #include <boost/qvm/config.hpp>
0011 #include <boost/qvm/assert.hpp>
0012 #include <boost/qvm/static_assert.hpp>
0013
0014 namespace boost { namespace qvm {
0015
0016 namespace
0017 qvm_detail
0018 {
0019 template <class V, class T, int D>
0020 struct
0021 vec_traits_gnuc_impl
0022 {
0023 typedef T scalar_type;
0024 static int const dim=D;
0025
0026 template <int I>
0027 static
0028 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0029 scalar_type
0030 read_element( V const & x )
0031 {
0032 BOOST_QVM_STATIC_ASSERT(I>=0);
0033 BOOST_QVM_STATIC_ASSERT(I<dim);
0034 return x[I];
0035 }
0036
0037 template <int I>
0038 static
0039 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0040 void
0041 write_element( V & x, scalar_type s )
0042 {
0043 BOOST_QVM_STATIC_ASSERT(I>=0);
0044 BOOST_QVM_STATIC_ASSERT(I<dim);
0045 x[I] = s;
0046 }
0047
0048 static
0049 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0050 scalar_type
0051 read_element_idx( int i, V const & x )
0052 {
0053 BOOST_QVM_ASSERT(i>=0);
0054 BOOST_QVM_ASSERT(i<dim);
0055 return x[i];
0056 }
0057
0058 static
0059 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0060 void
0061 write_element_idx( int i, V & x, scalar_type s )
0062 {
0063 BOOST_QVM_ASSERT(i>=0);
0064 BOOST_QVM_ASSERT(i<dim);
0065 x[i] = s;
0066 }
0067 };
0068 }
0069
0070 template <class> struct vec_traits;
0071 template <class> struct is_vec;
0072
0073 #define BOOST_QVM_GNUC_VEC_TYPE(T,D)\
0074 template <>\
0075 struct\
0076 vec_traits<T __attribute__((vector_size(sizeof(T)*D)))>:\
0077 qvm_detail::vec_traits_gnuc_impl<T __attribute__((vector_size(sizeof(T)*D))),T,D>\
0078 {\
0079 };\
0080 template <>\
0081 struct\
0082 is_vec<T __attribute__((vector_size(sizeof(T)*D)))>\
0083 {\
0084 enum { value = true };\
0085 };
0086
0087 BOOST_QVM_GNUC_VEC_TYPE(float,2)
0088 BOOST_QVM_GNUC_VEC_TYPE(float,4)
0089 BOOST_QVM_GNUC_VEC_TYPE(double,2)
0090 BOOST_QVM_GNUC_VEC_TYPE(double,4)
0091
0092 #undef BOOST_QVM_GNUC_VEC_TYPE
0093
0094 } }
0095
0096 #endif
0097
0098 #endif