]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/qvm/detail/vec_register_impl.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / qvm / detail / vec_register_impl.hpp
1 #ifndef BOOST_QVM_DETAIL_VEC_REGISTER_IMPL_HPP
2 #define BOOST_QVM_DETAIL_VEC_REGISTER_IMPL_HPP
3
4 // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
5 // Copyright 2018 agate-pris
6
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <boost/qvm/assert.hpp>
11 #include <boost/qvm/inline.hpp>
12 #include <boost/qvm/static_assert.hpp>
13 #include <boost/qvm/vec_traits.hpp>
14
15 namespace boost { namespace qvm { namespace qvm_detail {
16
17 template<class VecType, class ScalarType, int Dim>
18 struct vec_register_common
19 {
20 typedef VecType vec_type;
21 typedef ScalarType scalar_type;
22 static int const dim = Dim;
23 };
24
25 template<class VecType, class ScalarType, int Dim>
26 struct vec_register_read
27 {
28 template<int I> static ScalarType read_element(VecType const& v);
29
30 template<int I, int N> struct read_element_idx_detail
31 {
32 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL ScalarType impl(int const i, VecType const& v)
33 {
34 return I == i
35 ? read_element<I>(v)
36 : read_element_idx_detail<I + 1, N>::impl(i, v);
37 }
38 };
39
40 template<int N> struct read_element_idx_detail<N, N>
41 {
42 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL ScalarType impl(int, VecType const& v)
43 {
44 BOOST_QVM_ASSERT(0);
45 return read_element<0>(v);
46 }
47 };
48
49 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL ScalarType read_element_idx(int const i, VecType const& v)
50 {
51 return read_element_idx_detail<0, Dim>::impl(i, v);
52 }
53 };
54
55 template<class VecType, class ScalarType, int Dim>
56 struct vec_register_write
57 {
58 template<int I> static ScalarType& write_element(VecType& v);
59
60 template<int I, int N> struct write_element_idx_detail
61 {
62 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL ScalarType& impl(int const i, VecType& v)
63 {
64 return I == i
65 ? write_element<I>(v)
66 : write_element_idx_detail<I + 1, N>::impl(i, v);
67 }
68 };
69
70 template<int N> struct write_element_idx_detail<N, N>
71 {
72 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL ScalarType& impl(int, VecType& v)
73 {
74 BOOST_QVM_ASSERT(0);
75 return write_element<0>(v);
76 }
77 };
78
79 static BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL ScalarType& write_element_idx(int const i, VecType& v)
80 {
81 return write_element_idx_detail<0, Dim>::impl(i, v);
82 }
83 };
84
85 }}}
86
87 #define BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_READ(VecType, ScalarType, Dim, I, Read) \
88 namespace boost { namespace qvm {namespace qvm_detail{ \
89 template<> \
90 template<> \
91 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL \
92 ScalarType vec_register_read<VecType, ScalarType, Dim>::read_element<I>(VecType const& v) \
93 { \
94 BOOST_QVM_STATIC_ASSERT(I>=0); \
95 BOOST_QVM_STATIC_ASSERT(I<Dim); \
96 return v. Read; \
97 } \
98 }}}
99
100 #define BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_WRITE(VecType, ScalarType, Dim, I, Write) \
101 namespace boost { namespace qvm {namespace qvm_detail{ \
102 template<> \
103 template<> \
104 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL \
105 ScalarType& vec_register_write<VecType, ScalarType, Dim>::write_element<I>(VecType& v) \
106 { \
107 BOOST_QVM_STATIC_ASSERT(I>=0); \
108 BOOST_QVM_STATIC_ASSERT(I<Dim); \
109 return v. Write; \
110 }; \
111 }}}
112
113 #define BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_READ_WRITE(VecType, ScalarType, Dim, I, Read, Write)\
114 BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_READ(VecType, ScalarType, Dim, I, Read) \
115 BOOST_QVM_DETAIL_SPECIALIZE_QVM_DETAIL_VEC_REGISTER_WRITE(VecType, ScalarType, Dim, I, Write)
116
117 #define BOOST_QVM_DETAIL_REGISTER_VEC_SPECIALIZE_VEC_TRAITS_READ(VecType, ScalarType, Dim) \
118 namespace boost { namespace qvm { \
119 template<> \
120 struct vec_traits<VecType> \
121 : qvm_detail::vec_register_common<VecType, ScalarType, Dim> \
122 , qvm_detail::vec_register_read<VecType, ScalarType, Dim> \
123 { \
124 }; \
125 }}
126
127 #define BOOST_QVM_DETAIL_REGISTER_VEC_SPECIALIZE_VEC_TRAITS_READ_WRITE(VecType, ScalarType, Dim)\
128 namespace boost { namespace qvm { \
129 template<> \
130 struct vec_traits<VecType> \
131 : qvm_detail::vec_register_common<VecType, ScalarType, Dim> \
132 , qvm_detail::vec_register_read<VecType, ScalarType, Dim> \
133 , qvm_detail::vec_register_write<VecType, ScalarType, Dim> \
134 { \
135 }; \
136 }}
137
138 #endif