cnorxz/src/include/ranges/xpr/for.h

103 lines
2.1 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-16 23:05:48 +02:00
template <SizeT L, class PosT, class Xpr>
class For : public XprInterface<For<L,PosT,Xpr>>
2022-10-16 00:55:14 +02:00
{
public:
DEFAULT_MEMBERS(For);
2022-10-16 23:05:48 +02:00
constexpr For(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
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
PosT mStep; // one-dim
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
// unrolled loop:
2022-10-16 23:05:48 +02:00
template <SizeT N, SizeT L, class PosT, class Xpr>
class SFor : public XprInterface<SFor<N,L,PosT,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-16 23:05:48 +02:00
constexpr SFor(const IndexId<L>& id, const PosT& step, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
template <class PosT1, class PosT2>
constexpr SizeT operator()(const PosT1& mlast, const PosT2& last) const;
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:
template <SizeT I, class PosT1, class PosT2>
constexpr SizeT exec(const PosT1& mlast, const PosT2& last) const;
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
PosT mStep;
typedef decltype(mXpr.RootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
// multi-threading
2022-10-16 23:05:48 +02:00
template <SizeT L, class PosT, class Xpr>
class TFor : public XprInterface<TFor<L,PosT,Xpr>>
2022-10-16 00:55:14 +02:00
{
public:
DEFAULT_MEMBERS(TFor);
2022-10-16 23:05:48 +02:00
constexpr TFor(SizeT size, const IndexId<L>& id, const PosT& step, const Xpr& xpr);
2022-10-16 00:55:14 +02:00
template <class PosT1, class PosT2>
inline SizeT operator()(const PosT1& mlast, const PosT2& last) const;
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 = 0;
2022-10-16 00:55:14 +02:00
Xpr mXpr;
2022-10-16 23:05:48 +02:00
PosT mStep;
typedef decltype(mXpr.rootSteps(mId)) XPosT;
XPosT mExt;
2022-10-16 00:55:14 +02:00
};
}
#endif