//Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. //Copyright (c) 2018 agate-pris //Distributed under the Boost Software License, Version 1.0. (See accompanying //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_QVM_DETAIL_VEC_REGISTER_IMPL_HPP #define BOOST_QVM_DETAIL_VEC_REGISTER_IMPL_HPP #include #include #include #include namespace boost { namespace qvm { namespace qvm_detail { template struct vec_register_common { typedef VecType vec_type; typedef ScalarType scalar_type; static int const dim = Dim; }; template struct vec_register_read { template static ScalarType read_element(VecType const& v); template struct read_element_idx_detail { static BOOST_QVM_INLINE_CRITICAL ScalarType impl(int const i, VecType const& v) { return I == i ? read_element(v) : read_element_idx_detail::impl(i, v); } }; template struct read_element_idx_detail { static BOOST_QVM_INLINE_TRIVIAL ScalarType impl(int, VecType const& v) { BOOST_QVM_ASSERT(0); return read_element<0>(v); } }; static BOOST_QVM_INLINE_CRITICAL ScalarType read_element_idx(int const i, VecType const& v) { return read_element_idx_detail<0, Dim>::impl(i, v); } }; template struct vec_register_write { template static ScalarType& write_element(VecType& v); template struct write_element_idx_detail { static BOOST_QVM_INLINE_CRITICAL ScalarType& impl(int const i, VecType& v) { return I == i ? write_element(v) : write_element_idx_detail::impl(i, v); } }; template struct write_element_idx_detail { static BOOST_QVM_INLINE_TRIVIAL ScalarType& impl(int, VecType& v) { BOOST_QVM_ASSERT(0); return write_element<0>(v); } }; static BOOST_QVM_INLINE_CRITICAL ScalarType& write_element_idx(int const i, VecType& v) { return write_element_idx_detail<0, Dim>::impl(i, v); } }; }}} #define BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_READ(VecType, ScalarType, Dim, I, Read) \ namespace boost { namespace qvm {namespace qvm_detail{ \ template<> \ template<> \ BOOST_QVM_INLINE_CRITICAL \ ScalarType vec_register_read::read_element(VecType const& v) \ { \ BOOST_QVM_STATIC_ASSERT(I>=0); \ BOOST_QVM_STATIC_ASSERT(I \ template<> \ BOOST_QVM_INLINE_CRITICAL \ ScalarType& vec_register_write::write_element(VecType& v) \ { \ BOOST_QVM_STATIC_ASSERT(I>=0); \ BOOST_QVM_STATIC_ASSERT(I \ struct vec_traits \ : qvm_detail::vec_register_common \ , qvm_detail::vec_register_read \ { \ }; \ }} #define BOOST_QVM_DETAIL_REGISTER_VEC_SPECIALIZE_VEC_TRAITS_READ_WRITE(VecType, ScalarType, Dim)\ namespace boost { namespace qvm { \ template<> \ struct vec_traits \ : qvm_detail::vec_register_common \ , qvm_detail::vec_register_read \ , qvm_detail::vec_register_write \ { \ }; \ }} #endif