cnorxz/src/include/xpr/for.h

122 lines
2.3 KiB
C
Raw Normal View History

2022-10-16 00:55:14 +02:00
#ifndef __cxz_for_h__
#define __cxz_for_h__
#include "base/base.h"
#include "xpr_base.h"
namespace CNORXZ
{
2022-10-21 00:21:47 +02:00
template <SizeT L, class Xpr>
class For : public XprInterface<For<L,Xpr>>
2022-10-16 00:55:14 +02:00
{
public:
DEFAULT_MEMBERS(For);
2022-10-21 00:21:47 +02:00
constexpr For(SizeT size, const IndexId<L>& id, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
2022-10-21 00:21:47 +02:00
template <class PosT>
inline SizeT operator()(const PosT& last) const;
2022-10-16 00:55:14 +02:00
inline SizeT operator()() const;
2022-10-16 18:37:14 +02:00
template <SizeT I>
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
2022-10-16 00:55:14 +02:00
private:
SizeT mSize = 0;
2022-10-16 18:37:14 +02:00
IndexId<L> mId;
2022-10-16 00:55:14 +02:00
Xpr mXpr;
2022-10-16 23:05:48 +02:00
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
// unrolled loop:
2022-10-21 00:21:47 +02:00
template <SizeT N, SizeT L, class Xpr>
class SFor : public XprInterface<SFor<N,L,Xpr>>
2022-10-16 00:55:14 +02:00
{
public:
2022-10-16 23:05:48 +02:00
DEFAULT_MEMBERS(SFor);
2022-10-16 00:55:14 +02:00
2022-10-21 00:21:47 +02:00
constexpr SFor(const IndexId<L>& id, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
2022-10-21 00:21:47 +02:00
template <class PosT>
constexpr SizeT operator()(const PosT& last) const;
2022-10-16 00:55:14 +02:00
constexpr SizeT operator()() const;
2022-10-16 18:37:14 +02:00
template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
2022-10-16 00:55:14 +02:00
private:
2022-10-21 00:21:47 +02:00
template <SizeT I, class PosT>
constexpr SizeT exec(const PosT& last) const;
2022-10-16 00:55:14 +02:00
template <SizeT I>
constexpr SizeT exec() const;
2022-10-16 18:37:14 +02:00
IndexId<L> mId;
2022-10-16 00:55:14 +02:00
Xpr mXpr;
2022-10-16 23:05:48 +02:00
typedef decltype(mXpr.RootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
// multi-threading
2022-10-21 00:21:47 +02:00
template <SizeT L, class Xpr>
class TFor : public XprInterface<TFor<L,Xpr>>
2022-10-16 00:55:14 +02:00
{
public:
DEFAULT_MEMBERS(TFor);
2022-10-21 00:21:47 +02:00
constexpr TFor(SizeT size, const IndexId<L>& id, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
2022-10-21 00:21:47 +02:00
template <class PosT>
inline SizeT operator()(const PosT& last) const;
2022-10-16 00:55:14 +02:00
inline SizeT operator()() const;
2022-10-16 18:37:14 +02:00
template <SizeT I>
inline decltype(auto) rootSteps(const IndexId<I>& id) const;
2022-10-16 00:55:14 +02:00
private:
SizeT mSize = 0;
IndexId<L> mId;
2022-10-16 00:55:14 +02:00
Xpr mXpr;
2022-10-16 23:05:48 +02:00
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
// Extension For (Vectorization)
2022-10-21 00:21:47 +02:00
template <SizeT N, SizeT L, class Xpr>
class EFor : public XprInterface<EFor<N,L,Xpr>>
{
public:
DEFAULT_MEMBERS(EFor);
2022-10-21 00:21:47 +02:00
constexpr EFor(const IndexId<L>& id, const Xpr& xpr);
2022-10-21 00:21:47 +02:00
template <class PosT>
constexpr SizeT operator()(const PosT& last) const;
constexpr SizeT operator()() const;
template <SizeT I>
constexpr decltype(auto) rootSteps(const IndexId<I>& id) const;
private:
IndexId<L> mId;
Xpr mXpr;
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
};
2022-10-16 00:55:14 +02:00
}
#endif