CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
reg.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_reg_cc_h__
13#define __cxz_reg_cc_h__
14
15#include "reg.h"
16#include "xpr/pos_type.h"
17
18namespace CNORXZ
19{
20 template <typename T, class EPosT, SizeT... Is>
21 inline decltype(auto) vregi(const T* d, const EPosT& pos, std::index_sequence<Is...> is)
22 {
23 constexpr SizeT N = epos_size<EPosT>::value;
24 static_assert(N == sizeof...(Is), "got inconsistent index sequence");
25 return Consecutive<T,N> { d[pos.template get<Is>().val()]... };
26 }
27
28 template <typename T, class EPosT>
29 inline decltype(auto) vreg(const T* d, const EPosT& pos)
30 {
31 constexpr SizeT N = epos_size<EPosT>::value;
32 static_assert(is_epos_type<EPosT>::value, "got non-epos-type");
34 return *reinterpret_cast<const Consecutive<T,N>*>(d+pos.scal().val());
35 }
36 else {
37 return vregi(d, pos, std::make_index_sequence<N>{});
38 }
39 }
40
41 template <typename T, class EPosT>
42 inline decltype(auto) vreg(T* d, const EPosT& pos)
43 {
44 constexpr SizeT N = epos_size<EPosT>::value;
45 static_assert(is_epos_type<EPosT>::value, "got non-epos-type");
46 static_assert(pos_type_is_consecutive<EPosT>::value, "no write access for non-consecutive");
48 return *reinterpret_cast<Consecutive<T,N>*>(d+pos.scal().val());
49 }
50 else {
51 return vregi(d, pos, std::make_index_sequence<N>{});
52 }
53 }
54
55 template <SizeT I, typename T>
56 constexpr decltype(auto) consecGet(const T& a)
57 {
60 "consecutive index out of range");
61 return a.mD[I];
62 }
63 else {
64 return a;
65 }
66 }
67
68 template <SizeT I, typename T>
69 constexpr decltype(auto) consecGet(T& a)
70 {
73 "consecutive index out of range");
74 return a.mD[I];
75 }
76 else {
77 return a;
78 }
79 }
80
81 template <SizeT I, class F, typename... Args>
82 constexpr decltype(auto) consecApply(const F& f, const Args&... args)
83 {
84 return f( consecGet<I>(args)... );
85 }
86
87 template <SizeT I, class F, typename Dst, typename... Args>
88 constexpr Dst& consecAssign(const F& f, Dst& dst, const Args&... args)
89 {
91 return dst;
92 }
93
94 template <class F, typename... Args, SizeT... Is>
95 constexpr decltype(auto) consecFuncI(const F& f, const Args&... args,
96 std::index_sequence<Is...> is)
97 {
98 typedef decltype(consecApply<0>(f, args...)) OType;
99 constexpr SizeT N = sizeof...(Is);
100 return Consecutive<OType,N> { consecApply<Is>(f, args...) ... };
101 }
102
103 template <class F, typename Dst, typename... Args, SizeT... Is>
104 constexpr Dst& consecFuncAI(const F& f, Dst& dst, const Args&... args,
105 std::index_sequence<Is...> is)
106 {
107 ( consecAssign<Is>(f, dst, args...), ... );
108 return dst;
109 }
110
111 template <SizeT N, class F, typename... Args>
112 constexpr decltype(auto) consecFunc(const F& f, const Args&... args)
113 {
114 return consecFuncI<F,Args...>(f, args..., std::make_index_sequence<N>{});
115 }
116
117 template <SizeT N, class F, typename Dst, typename... Args>
118 constexpr Dst& consecFuncA(const F& f, Dst& dst, const Args&... args)
119 {
120 return consecFuncAI<F,Dst,Args...>(f, dst, args..., std::make_index_sequence<N>{});
121 }
122
123 /*============================+
124 | basic operations: plus |
125 +============================*/
126
127 template <typename T, typename U, SizeT N>
128 constexpr decltype(auto)
130 {
131 return consecFunc<N>( [](const auto& x, const auto& y) { return x + y; }, a, b );
132 }
133
134 template <typename T, typename U, SizeT N>
135 constexpr decltype(auto)
137 {
138 return consecFuncA<N>( [](auto& x, const auto& y) { return x += y; }, o, a );
139 }
140
141 template <typename T, typename X, SizeT N>
142 constexpr decltype(auto) PlusCX<T,X,N>::eval(const Consecutive<T,N>& a, const X& b)
143 {
144 return consecFunc<N>( [](const auto& x, const auto& y) { return x + y; }, a, b );
145 }
146
147 template <typename T, typename X, SizeT N>
148 constexpr decltype(auto) PlusCX<T,X,N>::eval(const X& a, const Consecutive<T,N>& b)
149 {
150 return consecFunc<N>( [](const auto& x, const auto& y) { return x + y; }, a, b );
151 }
152
153 template <typename T, typename X, SizeT N>
154 constexpr decltype(auto) PlusCX<T,X,N>::aeval(Consecutive<T,N>& o, const X& a)
155 {
156 return consecFuncA<N>( [](auto& x, const auto& y) { return x += y; }, o, a );
157 }
158
159 /*=============================+
160 | basic operations: minus |
161 +=============================*/
162
163 template <typename T, typename U, SizeT N>
164 constexpr decltype(auto) MinusCC<T,U,N>::eval(const Consecutive<T,N>& a, const Consecutive<U,N>& b)
165 {
166 return consecFunc<N>( [](const auto& x, const auto& y) { return x - y; }, a, b );
167 }
168
169 template <typename T, typename X, SizeT N>
170 constexpr decltype(auto) MinusCX<T,X,N>::eval(const Consecutive<T,N>& a, const X& b)
171 {
172 return consecFunc<N>( [](const auto& x, const auto& y) { return x - y; }, a, b );
173 }
174
175 template <typename T, typename X, SizeT N>
176 constexpr decltype(auto) MinusCX<T,X,N>::eval(const X& a, const Consecutive<T,N>& b)
177 {
178 return consecFunc<N>( [](const auto& x, const auto& y) { return x - y; }, a, b );
179 }
180
181 template <typename T, typename U, SizeT N>
182 constexpr decltype(auto) MinusCC<T,U,N>::aeval(Consecutive<T,N>& o, const Consecutive<U,N>& a)
183 {
184 return consecFuncA<N>( [](auto& x, const auto& y) { return x -= y; }, o, a );
185 }
186
187 template <typename T, typename X, SizeT N>
188 constexpr decltype(auto) MinusCX<T,X,N>::aeval(Consecutive<T,N>& o, const X& a)
189 {
190 return consecFuncA<N>( [](auto& x, const auto& y) { return x -= y; }, o, a );
191 }
192
193 /*=================================+
194 | basic operations: muliplies |
195 +=================================*/
196
197 template <typename T, typename U, SizeT N>
198 constexpr decltype(auto) MultipliesCC<T,U,N>::eval(const Consecutive<T,N>& a, const Consecutive<U,N>& b)
199 {
200 return consecFunc<N>( [](const auto& x, const auto& y) { return x * y; }, a, b );
201 }
202
203 template <typename T, typename X, SizeT N>
204 constexpr decltype(auto) MultipliesCX<T,X,N>::eval(const Consecutive<T,N>& a, const X& b)
205 {
206 return consecFunc<N>( [](const auto& x, const auto& y) { return x * y; }, a, b );
207 }
208
209 template <typename T, typename X, SizeT N>
210 constexpr decltype(auto) MultipliesCX<T,X,N>::eval(const X& a, const Consecutive<T,N>& b)
211 {
212 return consecFunc<N>( [](const auto& x, const auto& y) { return x * y; }, a, b );
213 }
214
215 template <typename T, typename U, SizeT N>
216 constexpr decltype(auto) MultipliesCC<T,U,N>::aeval(Consecutive<T,N>& o, const Consecutive<U,N>& a)
217 {
218 return consecFuncA<N>( [](const auto& x, const auto& y) { return x *= y; }, o, a );
219 }
220
221 template <typename T, typename X, SizeT N>
222 constexpr decltype(auto) MultipliesCX<T,X,N>::aeval(Consecutive<T,N>& o, const X& a)
223 {
224 return consecFuncA<N>( [](const auto& x, const auto& y) { return x *= y; }, o, a );
225 }
226
227 /*===============================+
228 | basic operations: divides |
229 +===============================*/
230
231 template <typename T, typename U, SizeT N>
232 constexpr decltype(auto) DividesCC<T,U,N>::eval(const Consecutive<T,N>& a, const Consecutive<U,N>& b)
233 {
234 return consecFunc<N>( [](const auto& x, const auto& y) { return x / y; }, a, b );
235 }
236
237 template <typename T, typename X, SizeT N>
238 constexpr decltype(auto) DividesCX<T,X,N>::eval(const Consecutive<T,N>& a, const X& b)
239 {
240 return consecFunc<N>( [](const auto& x, const auto& y) { return x / y; }, a, b );
241 }
242
243 template <typename T, typename X, SizeT N>
244 constexpr decltype(auto) DividesCX<T,X,N>::eval(const X& a, const Consecutive<T,N>& b)
245 {
246 return consecFunc<N>( [](const auto& x, const auto& y) { return x / y; }, a, b );
247 }
248
249 template <typename T, typename U, SizeT N>
250 constexpr decltype(auto) DividesCC<T,U,N>::aeval(Consecutive<T,N>& o, const Consecutive<U,N>& a)
251 {
252 return consecFuncA<N>( [](const auto& x, const auto& y) { return x /= y; }, o, a );
253 }
254
255 template <typename T, typename X, SizeT N>
256 constexpr decltype(auto) DividesCX<T,X,N>::aeval(Consecutive<T,N>& o, const X& a)
257 {
258 return consecFuncA<N>( [](const auto& x, const auto& y) { return x /= y; }, o, a );
259 }
260}
261
262#endif
constexpr decltype(auto) consecGet(const T &a)
Definition reg.cc.h:56
constexpr decltype(auto) consecFuncI(const F &f, const Args &... args, std::index_sequence< Is... > is)
Definition reg.cc.h:95
uint64_t SizeT
Definition types.h:38
constexpr decltype(auto) consecApply(const F &f, const Args &... args)
Definition reg.cc.h:82
decltype(auto) vregi(const T *d, const EPosT &pos, std::index_sequence< Is... > is)
Definition reg.cc.h:21
Sptr< Range > rangeCast(const RangePtr r)
constexpr decltype(auto) consecFunc(const F &f, const Args &... args)
Definition reg.cc.h:112
constexpr Dst & consecFuncAI(const F &f, Dst &dst, const Args &... args, std::index_sequence< Is... > is)
Definition reg.cc.h:104
constexpr Dst & consecAssign(const F &f, Dst &dst, const Args &... args)
Definition reg.cc.h:88
decltype(auto) vreg(const T *d, const EPosT &pos)
Definition reg.cc.h:29
constexpr Dst & consecFuncA(const F &f, Dst &dst, const Args &... args)
Definition reg.cc.h:118
Position types declarations.
Register type declaration.